From 4918c52f39ab6459d1c48e9456a7fbd01a4e91f6 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 27 Feb 2021 15:28:40 +0900 Subject: [PATCH] Keys color can now be changed without the need to restart the application. Signed-off-by: Michele Calgaro (cherry picked from commit 64d40d992ecb290a7d395b14e5d3b81e4ed074d2) --- src/MainWidget.cpp | 30 +++++++++++++++++++++++------- src/MainWidget.h | 12 ++++-------- src/VButton.cpp | 32 ++++++++++++++++++++++++++------ 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