Skip to content

Commit

Permalink
Merge pull request #96 from OpenBangla/commit-raw-text
Browse files Browse the repository at this point in the history
Make the commit raw text key customizable.
  • Loading branch information
mominul committed Mar 2, 2019
2 parents 65dc837 + 82eeae2 commit 1e62bdd
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 51 deletions.
5 changes: 3 additions & 2 deletions src/engine/ibus/ibus_engine.cpp
Expand Up @@ -185,8 +185,9 @@ gboolean ibus_process_key_event_cb(IBusEngine *engine,
}
}

// Commit the preedit buffer when the `Ctrl + B` key is pressed.
if(kctrl && key == VC_B && !suggestions.isEmpty()) {
// Commit the preedit buffer(raw text) when the user configured key is pressed.
int rawTextKey = gLayout->commitRawTextKey();
if(kctrl && rawTextKey != 0 && key == rawTextKey && !suggestions.isEmpty()) {
commit_text(suggestions.auxiliaryText);
return TRUE;
}
Expand Down
4 changes: 4 additions & 0 deletions src/engine/libengine/Layout.cpp
Expand Up @@ -124,3 +124,7 @@ bool Layout::isCandidateWinHorizontal() {
void Layout::updateEngine() {
mth->updateEngine();
}

int Layout::commitRawTextKey() {
return gSettings->getCommitRaw();
}
5 changes: 4 additions & 1 deletion src/engine/libengine/Layout.h
Expand Up @@ -140,11 +140,14 @@ class Layout {
* @index index of the candidate string that was commited */
void candidateCommited(int index);

/* Checks is the candidate window horizontal */
/* Checks if the candidate window is horizontal */
bool isCandidateWinHorizontal();

/* Update internal suggestion making mechanism */
void updateEngine();

/* Returns the user configured key for commiting raw text. */
int commitRawTextKey();
};

/* Global */
Expand Down
44 changes: 44 additions & 0 deletions src/frontend/SettingsDialog.cpp
Expand Up @@ -19,6 +19,7 @@
#include "SettingsDialog.h"
#include "ui_SettingsDialog.h"
#include "Settings.h"
#include "keycode.h"

SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
Expand All @@ -27,6 +28,37 @@ SettingsDialog::SettingsDialog(QWidget *parent) :

this->setFixedSize(QSize(this->width(), this->height()));
ui->cmbOrientation->insertItems(0, {"Horizontal", "Vertical"});
ui->cmbRawTxt->addItem("None");
rawTextKeys = {
{"Ctrl + Q", VC_Q},
{"Ctrl + W", VC_W},
{"Ctrl + E", VC_E},
{"Ctrl + R", VC_R},
{"Ctrl + T", VC_T},
{"Ctrl + Y", VC_Y},
{"Ctrl + U", VC_U},
{"Ctrl + I", VC_I},
{"Ctrl + O", VC_O},
{"Ctrl + P", VC_P},
{"Ctrl + A", VC_A},
{"Ctrl + S", VC_S},
{"Ctrl + D", VC_D},
{"Ctrl + F", VC_F},
{"Ctrl + G", VC_G},
{"Ctrl + H", VC_H},
{"Ctrl + J", VC_J},
{"Ctrl + K", VC_K},
{"Ctrl + L", VC_L},
{"Ctrl + Z", VC_Z},
{"Ctrl + X", VC_X},
{"Ctrl + C", VC_C},
{"Ctrl + V", VC_V},
{"Ctrl + B", VC_B},
{"Ctrl + V", VC_V},
{"Ctrl + N", VC_N},
{"Ctrl + M", VC_M},
};
ui->cmbRawTxt->addItems(rawTextKeys.keys());
updateSettings();
}

Expand All @@ -39,13 +71,25 @@ void SettingsDialog::updateSettings() {
ui->btnShowPrevWin->setChecked(gSettings->getShowCWPhonetic());
ui->cmbOrientation->setCurrentIndex(gSettings->getCandidateWinHorizontal() ? 0 : 1);
ui->btnCheckUpdate->setChecked(gSettings->getUpdateCheck());
int rawTextKey = gSettings->getCommitRaw();
if(rawTextKey == 0) {
ui->cmbRawTxt->setCurrentText("None");
} else {
ui->cmbRawTxt->setCurrentText(rawTextKeys.keys(rawTextKey).first());
}
}

void SettingsDialog::on_buttonBox_accepted() {
gSettings->setEnterKeyClosesPrevWin(ui->btnClosePrevWin->isChecked());
gSettings->setShowCWPhonetic(ui->btnShowPrevWin->isChecked());
gSettings->setCandidateWinHorizontal((ui->cmbOrientation->currentIndex() == 0));
gSettings->setUpdateCheck(ui->btnCheckUpdate->isChecked());
QString rawTextKey = ui->cmbRawTxt->currentText();
if(rawTextKey == "None") {
gSettings->setCommitRaw(0);
} else {
gSettings->setCommitRaw(rawTextKeys.value(rawTextKey));
}
}

void SettingsDialog::on_buttonBox_rejected() {
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/SettingsDialog.h
Expand Up @@ -20,6 +20,7 @@
#define SETTINGSDIALOG_H

#include <QDialog>
#include <QMap>

namespace Ui {
class SettingsDialog;
Expand Down Expand Up @@ -49,6 +50,7 @@ private slots:

private:
Ui::SettingsDialog *ui;
QMap<QString, int> rawTextKeys;
};

#endif // SETTINGSDIALOG_H
100 changes: 52 additions & 48 deletions src/frontend/SettingsDialog.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>483</width>
<height>224</height>
<width>475</width>
<height>260</height>
</rect>
</property>
<property name="sizePolicy">
Expand All @@ -20,24 +20,23 @@
<string>Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>40</number>
</property>
<property name="verticalSpacing">
<number>10</number>
</property>
<item row="0" column="1">
<widget class="QPushButton" name="btnClosePrevWin">
<property name="text">
<string>Off</string>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="checkable">
<bool>true</bool>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter/Return key only closes preview
window:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;
</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="btnCheckUpdate">
<item row="0" column="1">
<widget class="QPushButton" name="btnClosePrevWin">
<property name="text">
<string>Off</string>
</property>
Expand All @@ -46,19 +45,16 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cmbOrientation"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Automatically check for updates:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show Preview Window in Phonetic mode:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
Expand All @@ -72,54 +68,62 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Enter/Return key only closes preview
window:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;
</string>
<string>Suggestion List Orientation:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<item row="2" column="1">
<widget class="QComboBox" name="cmbOrientation"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Suggestion List Orientation:</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Automatically check for updates:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="3" column="1">
<widget class="QPushButton" name="btnCheckUpdate">
<property name="text">
<string>Off</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Show Preview Window in Phonetic mode:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Commit Raw Text:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="cmbRawTxt"/>
</item>
<item row="5" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
Expand Down
10 changes: 10 additions & 0 deletions src/shared/Settings.cpp
Expand Up @@ -161,3 +161,13 @@ bool Settings::getUpdateCheck() {
setting->sync();
return setting->value("settings/UpdateCheck", true).toBool();
}

void Settings::setCommitRaw(int key) {
setting->setValue("settings/CommitRaw", key);
setting->sync();
}

int Settings::getCommitRaw() {
setting->sync();
return setting->value("settings/CommitRaw", 0xA0C7).toInt(); // Default: Ctrl + T
}
4 changes: 4 additions & 0 deletions src/shared/Settings.h
Expand Up @@ -83,6 +83,10 @@ class Settings {
void setUpdateCheck(bool b);

bool getUpdateCheck();

void setCommitRaw(int key);

int getCommitRaw();
};

/* Global */
Expand Down

0 comments on commit 1e62bdd

Please sign in to comment.