diff options
author | Michele Calgaro <[email protected]> | 2021-02-27 15:28:40 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2021-02-27 15:28:40 +0900 |
commit | 64d40d992ecb290a7d395b14e5d3b81e4ed074d2 (patch) | |
tree | 620066cb47066d1919c7fdfba8dba5f544c97f0b | |
parent | 43425b84f70794eeb975f6811b7dacc3cec01cd2 (diff) | |
download | kvkbd-64d40d992ecb290a7d395b14e5d3b81e4ed074d2.tar.gz kvkbd-64d40d992ecb290a7d395b14e5d3b81e4ed074d2.zip |
Keys color can now be changed without the need to restart the
application.
Signed-off-by: Michele Calgaro <[email protected]>
-rw-r--r-- | src/MainWidget.cpp | 30 | ||||
-rw-r--r-- | src/MainWidget.h | 12 | ||||
-rw-r--r-- | src/VButton.cpp | 32 | ||||
-rw-r--r-- | src/VButton.h | 16 |
4 files changed, 62 insertions, 28 deletions
diff --git a/src/MainWidget.cpp b/src/MainWidget.cpp index ff7dc62..ee9c1df 100644 --- a/src/MainWidget.cpp +++ b/src/MainWidget.cpp @@ -511,27 +511,27 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const { tray = new KbdTray ( this ); tray->setPixmap ( UserIcon ( "tray" ) ); - + TDEConfig *cfg = TDEApplication::kApplication()->config(); - + TDEPopupMenu *m = tray->contextMenu(); m->setCheckable ( true ); - + KHelpMenu *h = new KHelpMenu ( tray, about ); m->insertItem ( "Font ...", this, TQT_SLOT ( chooseFont() ) ); mnu_autores = m->insertItem( "Auto resize font",this, TQT_SLOT ( toggleFontAutoRes() ) ); bool fnt_autores = cfg->readBoolEntry("autoresfont",true); m->setItemChecked(mnu_autores, fnt_autores); - + m->insertItem ( i18n ("Background color"), this, TQT_SLOT ( chooseBackgroundColor() ) ); - m->insertItem ( i18n ("Keys color (requires restart)"), this, TQT_SLOT ( chooseKeysColor() ) ); + m->insertItem ( i18n ("Keys color"), this, TQT_SLOT ( chooseKeysColor() ) ); m->insertSeparator(); mnu_dock = m->insertItem ( "Dock widget", this, TQT_SLOT ( showDock() ) ); bool show_dock = cfg->readBoolEntry("showdock",false); m->setItemChecked(mnu_dock, show_dock); - + mnu_lock = m->insertItem(i18n("Lock on screen"), this, TQT_SLOT(toggleLock())); locked = cfg->readBoolEntry("locked", false); m->setItemChecked(mnu_lock, locked); @@ -597,7 +597,23 @@ void MainWidget::chooseKeysColor() { cfg->writeEntry("keysColor", newkeysC.name()); // save as #rrbbgg cfg->sync(); - // can't set PaletteBackgroundColor because it's in VButton::VButton - needs restart to read configuration entry + + for (unsigned idx = 0; idx < btns.size(); ++idx) + { + btns[idx]->setColor(newkeysC); + } + for (unsigned idx = 0; idx < mod_keys.size(); ++idx) + { + mod_keys[idx]->setColor(newkeysC); + } + for (unsigned idx = 0; idx < other_keys.size(); ++idx) + { + other_keys[idx]->setColor(newkeysC); + } + for (unsigned idx = 0; idx < numl_keys.size(); ++idx) + { + numl_keys[idx]->setColor(newkeysC); + } } } diff --git a/src/MainWidget.h b/src/MainWidget.h index ff77d27..f476c67 100644 --- a/src/MainWidget.h +++ b/src/MainWidget.h @@ -50,25 +50,21 @@ public: public slots: void keyPress(unsigned int keycode); - void toggleCaps(); void toggleNumlock(); - void toggleShift(); - + void toggleNumericPad(); + void toggleFontAutoRes(); + void toggleLock(); void queryModState(); void showDock(); - - void quitClicked(); void chooseFont(); void chooseBackgroundColor(); void chooseKeysColor(); - void toggleNumericPad(); - void toggleFontAutoRes(); - void toggleLock(); void restorePosition(); void showConfigMenu(); void saveState(); + void quitClicked(); protected: void resizeEvent(TQResizeEvent *e); diff --git a/src/VButton.cpp b/src/VButton.cpp index 58b2a1b..c5763ab 100644 --- a/src/VButton.cpp +++ b/src/VButton.cpp @@ -11,16 +11,16 @@ VButton::VButton(TQWidget *parent, const char *name): TQPushButton (parent,name) { TDEConfig *cfg = TDEApplication::kApplication()->config(); TQString keysC = cfg->readEntry("keysColor", "#f0f0f0"); - setPaletteBackgroundColor(TQColor(keysC)); - + setColor(TQColor(keysC)); setFocusPolicy(TQ_NoFocus); resize(30,30); press=false; } + VButton::~VButton() { - } + void VButton::shiftPressed(bool press) { if (press==true){ @@ -32,12 +32,12 @@ void VButton::shiftPressed(bool press) else{ TQPushButton::setText(tu); } - } else{ TQPushButton::setText(l); } } + void VButton::capsPressed(bool press) { if (press==true){ @@ -59,20 +59,40 @@ void VButton::setText(const TQString& text) TQPushButton::setText(text); l=text; } + void VButton::setShiftText(const TQString& text) { u=text; } +void VButton::setColor(const TQColor &color) +{ + setPaletteBackgroundColor(color); + // Need to set TQColorGroup::Button color as well, otherwise the actual + // color of the key does not change until the next restart of the application. + TQPalette plt = palette(); + TQColorGroup cg = plt.active(); + cg.setColor(TQColorGroup::Button, color); + plt.setActive(cg); + cg = plt.inactive(); + cg.setColor(TQColorGroup::Button, color); + plt.setInactive(cg); + cg = plt.disabled(); + cg.setColor(TQColorGroup::Button, color); + plt.setDisabled(cg); + setPalette(plt); +} + void VButton::setKeyCode(unsigned int keycode) { this->keycode=keycode; - } + unsigned int VButton::getKeyCode() { return this->keycode; } + void VButton::sendKey() { emit keyClick(keycode); @@ -86,8 +106,8 @@ void VButton::reposition(int width, int height) double sdy=ph/orig_size.height(); move((int)(width/dx),(int)(height/dy)); resize((int)(width/sdx), (int)(height/sdy)); - } + void VButton::res() { orig_size=geometry(); diff --git a/src/VButton.h b/src/VButton.h index 7f04fd0..2f916ff 100644 --- a/src/VButton.h +++ b/src/VButton.h @@ -11,15 +11,17 @@ Q_OBJECT public: VButton(TQWidget *parent=0, const char *name=0); ~VButton(); - void setKeyCode(unsigned int keycode); + unsigned int getKeyCode(); - void setText(const TQString& text); - void setShiftText(const TQString& text); + void setKeyCode(unsigned int keycode); + void setText(const TQString &text); + void setShiftText(const TQString &text); + void setColor(const TQColor &color); void capsPressed(bool press); - - + void reposition(int width, int height); void res(); + static double pw; static double ph; @@ -32,7 +34,8 @@ protected: TQString u; TQString l; TQRect orig_size; - void timerEvent ( TQTimerEvent * ); + + void timerEvent ( TQTimerEvent * ); public slots: void sendKey(); @@ -44,7 +47,6 @@ protected slots: signals: void keyClick(unsigned int keycode); - }; #endif |