From 9834ca330b758a9e5b3ae89fff39f6f912163b77 Mon Sep 17 00:00:00 2001
From: Ray-V <ray-v@inbox.lv>
Date: Fri, 26 Feb 2021 13:02:18 +0900
Subject: Added functionality to select keyboard background and keys colors. A
 restart of the application is required if the keys color is changed.

Signed-off-by: Ray-V <ray-v@inbox.lv>
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit dd8d52708461bcd9d5fd11f62fc59f18fcfc542e)
---
 src/MainWidget.cpp | 39 ++++++++++++++++++++++++++++++++++-----
 src/MainWidget.h   |  3 ++-
 src/VButton.cpp    |  9 ++++++---
 3 files changed, 42 insertions(+), 9 deletions(-)

(limited to 'src')

diff --git a/src/MainWidget.cpp b/src/MainWidget.cpp
index e57ff39..ff7dc62 100644
--- a/src/MainWidget.cpp
+++ b/src/MainWidget.cpp
@@ -38,7 +38,7 @@
 #include <tqfontdialog.h>
 #include <tdeconfig.h>
 #include <tdeapplication.h>
-
+#include <tqcolordialog.h>
 
 
 #define R1LEN 13
@@ -73,15 +73,15 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
 	int stx=15;
 	int sty=15;
 	extent_visible=false;
+
 	TDEConfig *cfg = TDEApplication::kApplication()->config();
 	if (cfg)
 	{
 		extent_visible = cfg->readBoolEntry("numpad_visible", false);
+		TQString backgroundC = cfg->readEntry("keyboardBackgroundColor", "#cdc0b0");
+		setPaletteBackgroundColor(TQColor(backgroundC));
 	}
 
-// 	resize ( 550,235 );
-// 	move(0,0);
-
 	VButton *esc = new VButton ( this,"" );
 	esc->setKeyCode ( 9 );
 	esc->move ( stx,sty );
@@ -409,7 +409,6 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
 	connect ( t, TQT_SIGNAL ( timeout() ), this, TQT_SLOT ( queryModState() ) );
 	t->start ( 500, FALSE );
 
-	setPaletteBackgroundColor ( TQt::black );
 	setFocusPolicy ( TQ_NoFocus );
 
 	int padx= 550;
@@ -525,6 +524,10 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
 		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->insertSeparator();
 		mnu_dock = m->insertItem ( "Dock widget", this, TQT_SLOT ( showDock() ) );
 		bool show_dock = cfg->readBoolEntry("showdock",false);
 		m->setItemChecked(mnu_dock, show_dock);
@@ -572,6 +575,32 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
 	}
 }
 
+void MainWidget::chooseBackgroundColor()
+{
+	TDEConfig *cfg = TDEApplication::kApplication()->config();
+	TQString backgroundC = cfg->readEntry("keyboardBackgroundColor", "#cdc0b0");
+	TQColor newBackgroundC = TQColorDialog::getColor(TQColor(backgroundC));
+	if (newBackgroundC.isValid())
+	{
+		cfg->writeEntry("keyboardBackgroundColor", newBackgroundC.name()); // save as #rrbbgg
+		cfg->sync();
+		setPaletteBackgroundColor(newBackgroundC);
+	}
+}
+
+void MainWidget::chooseKeysColor()
+{
+	TDEConfig *cfg = TDEApplication::kApplication()->config();
+	TQString keysC = cfg->readEntry("keysColor", "#f0f0f0");
+	TQColor newkeysC = TQColorDialog::getColor(TQColor(keysC));
+	if (newkeysC.isValid())
+	{
+		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
+	}
+}
+
 void MainWidget::finishInit()
 {
 	TDEConfig *cfg = TDEApplication::kApplication()->config();
diff --git a/src/MainWidget.h b/src/MainWidget.h
index e2eb947..ff77d27 100644
--- a/src/MainWidget.h
+++ b/src/MainWidget.h
@@ -61,12 +61,13 @@ public slots:
 	
 	void quitClicked();
 	void chooseFont();
+	void chooseBackgroundColor();
+	void chooseKeysColor();
 	void toggleNumericPad();
 	void toggleFontAutoRes();
 	void toggleLock();
 	void restorePosition();
 	void showConfigMenu();
-// 	void shutDown();
  	void saveState();
 
 protected:
diff --git a/src/VButton.cpp b/src/VButton.cpp
index 48c7cf7..58b2a1b 100644
--- a/src/VButton.cpp
+++ b/src/VButton.cpp
@@ -1,18 +1,21 @@
 #include "VButton.h"
 #include <tqvbox.h>
 #include <tqfont.h>
+#include <tdeconfig.h>
+#include <tdeapplication.h>
 
 double VButton::pw=550.0;
 double VButton::ph=235.0;
 
 VButton::VButton(TQWidget *parent, const char *name): TQPushButton (parent,name)
 {
-	
-	//connect(this,TQT_SIGNAL(clicked()),this,TQT_SLOT(sendKey()));
+	TDEConfig *cfg = TDEApplication::kApplication()->config();
+	TQString keysC = cfg->readEntry("keysColor", "#f0f0f0");
+	setPaletteBackgroundColor(TQColor(keysC));
+
 	setFocusPolicy(TQ_NoFocus);
 	resize(30,30);
 	press=false;
-
 }
 VButton::~VButton()
 {
-- 
cgit v1.2.1