Add TQColorDialog

To enable user to select their own colours for the keyboard and/or keys/buttons.
Save the selected colours to the configuration file and load them when Kvkbd is restarted.
Needs a restart when the key colour is changed.

Signed-off-by: Ray-V <ray-v@inbox.lv>
pull/9/head
Ray-V 4 years ago
parent 559d223032
commit 8371e74692

@ -37,8 +37,7 @@
#include <tqfontdialog.h>
#include <tdeconfig.h>
#include <tdeapplication.h>
#include <ntqcolordialog.h>
#define R1LEN 13
#define R2LEN 10
@ -77,7 +76,11 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
int sty=15;
extent_visible=false;
setPaletteBackgroundColor ( TQColor("#cdc0b0") );
TDEConfig *cfg = TDEApplication::kApplication()->config();
// if "kbColor" entry doesn't exist - either because it hasn't been saved
// or kvkbdrc doesn't exist, default to "#cdc0b0"
TQColor bc = cfg->readEntry ("kbColor","#cdc0b0");
setPaletteBackgroundColor ( TQColor(bc) );
setFocusPolicy ( TQ_NoFocus );
// resize ( 550,235 );
@ -522,6 +525,12 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
bool fnt_autores = cfg->readBoolEntry("autoresfont",true);
m->setItemChecked(mnu_autores, fnt_autores);
m->insertSeparator();
m->insertItem ( i18n ("Keyboard color"), this, TQT_SLOT ( Colorb() ) );
m->insertItem ( i18n ("Key color (restart if changed)"), this, TQT_SLOT ( Colork() ) );
m->insertSeparator();
mnu_dock = m->insertItem ( i18n ("Dock widget"), this, TQT_SLOT ( showDock() ) );
bool show_dock = cfg->readBoolEntry("showdock",false);
@ -571,7 +580,30 @@ MainWidget::MainWidget ( TDEAboutData *about, bool tren, TQWidget *parent, const
}
void MainWidget::Colorb() // keyboard colour chosen through the configuration menu
{
TDEConfig *cfg = TDEApplication::kApplication()->config();
// if "kbColor" entry exists, start with that, otherwise start with the default "#cdc0b0"
TQColor bc = cfg->readEntry ("kbColor","#cdc0b0");
TQColor b = TQColorDialog::getColor( TQColor( bc ) );
// if the selection of the new colour is cancelled, b will be invalid
// otherwise the new value is written to kvkbdrc - this must be in the #rrggbb format
// and as writeEntry produces rrr,ggg,bbb format, .name() is required to convert to #rrggbb
if ( b.isValid() ) {
cfg->writeEntry ("kbColor", b.name() );
cfg->sync();
setPaletteBackgroundColor ( TQColor( b ) ); }
}
void MainWidget::Colork() // key/button colour chosen through the configuration menu
{
TDEConfig *cfg = TDEApplication::kApplication()->config();
TQColor kc = cfg->readEntry ("keyColor","#f0f0f0");
TQColor k = TQColorDialog::getColor( TQColor( kc ) );
if ( k.isValid() ) {
cfg->writeEntry ("keyColor", k.name() );
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();
@ -597,7 +629,7 @@ void MainWidget::restorePosition()
int d_width=553;
int d_height=235;
TQRect dflt_geom(screen_geom.width()-d_width,screen_geom.height()-d_height,d_width,d_height);
TQRect dflt_geom(screen_geom.width()-d_width-150,screen_geom.height()-d_height-50,d_width,d_height);
TDEConfig *cfg = 0;
cfg = TDEApplication::kApplication()->config();

@ -68,6 +68,8 @@ public slots:
// void shutDown();
void saveState();
void toggleLock();
void Colorb();
void Colork();
protected:
void resizeEvent(TQResizeEvent *e);

@ -1,6 +1,8 @@
#include "VButton.h"
#include <tqvbox.h>
#include <tqfont.h>
#include <tdeconfig.h>
#include <tdeapplication.h>
double VButton::pw=552.0;
double VButton::ph=235.0;
@ -9,8 +11,14 @@ VButton::VButton(TQWidget *parent, const char *name): TQPushButton (parent,name)
{
//connect(this,TQT_SIGNAL(clicked()),this,TQT_SLOT(sendKey()));
setPaletteBackgroundColor ( TQColor("#f0f0f0") );
TDEConfig *cfg = TDEApplication::kApplication()->config();
// if "keyColor" entry doesn't exist - either because it hasn't been saved
// or kvkbdrc doesn't exist, default to "#f0f0f0"
TQColor kc = cfg->readEntry ("keyColor","#f0f0f0");
setPaletteBackgroundColor ( TQColor(kc) );
setFocusPolicy(TQ_NoFocus);
resize(30,30);
press=false;

Loading…
Cancel
Save