summaryrefslogtreecommitdiffstats
path: root/src/palettecfg.cpp
blob: 2c2fef303d8fda054c6909dba443ca4777223842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/***************************************************************************
                          palettecfg.cpp  -  description
                             -------------------
    begin                : lun abr 15 2002
    copyright            : (C) 2002 by Miguel Novas
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "palettecfg.h"
#include "lmsensorswidget.h"

#include <ntqlabel.h>
#include <ntqpalette.h>
#include <ntqcombobox.h>
#include <kcolorbutton.h>

PaletteCfg::PaletteCfg(TQWidget *parent, const char *name): PaletteCfgDesign(parent,name)
{
 groupName= 0;
 slotComboSelected(0);
 connect( comboSelect,SIGNAL(activated(int)),this,SLOT(slotComboSelected(int)) );
 connect( buttonColor,SIGNAL(changed(const TQColor &)),this,SLOT(slotColorChanged(const TQColor &)) );
 connect( buttonDefaultPalette, SIGNAL(clicked()),this,SLOT(slotPaletteDefault()) );
}

PaletteCfg::~PaletteCfg()
{
}

void PaletteCfg::slotComboSelected(int index)
{
 TQColorGroup colors= framePanel->palette().active();
 TQColor color;
 switch(index) {
  case 0: color= colors.background(); break;
  case 1: color= colors.dark();       break;
  case 2: color= colors.text();       break;
  case 3: color= colors.foreground(); break;
 }
 buttonColor->blockSignals(true);
 buttonColor->setColor(color);
 buttonColor->blockSignals(false);
}

void PaletteCfg::slotColorChanged(const TQColor &newColor)
{
 TQPalette pal= framePanel->palette();
 switch(comboSelect->currentItem()) {
  case 0: pal.setColor(TQColorGroup::Background,newColor);
          pal.setColor(TQColorGroup::Light     ,newColor); break;
  case 1: pal.setColor(TQColorGroup::Dark      ,newColor); break;
  case 2: pal.setColor(TQColorGroup::Text      ,newColor); break;
  case 3: pal.setColor(TQColorGroup::Foreground,newColor); break;
  default: return;
 }
 setPanelPalette(pal,false);
 palDefault= false;
}

void PaletteCfg::slotPaletteDefault()
{
 palDefault= true;
 TQPalette pal;
 if(groupName) {
   LMSensorsWidget::cfgReadPalette(pal,"General",true);
 } else {
   LMSensorsWidget::getDefaultPalette(pal);
 }
 setPanelPalette(pal,true);
}

void PaletteCfg::setPanelPalette(const TQPalette &pal, bool updateColorButton)
{
 labelTitle->unsetPalette();
 framePanel->setPalette(pal);
 labelTitle->setPaletteForegroundColor(pal.active().text());
 if(updateColorButton) slotComboSelected(comboSelect->currentItem());
}

void PaletteCfg::readPalette(const char *name)
{
 groupName= name;
 TQPalette pal;
 palDefault= !LMSensorsWidget::cfgReadPalette(pal,name,false);
 if(palDefault) LMSensorsWidget::cfgReadPalette(pal,"General",true);
 setPanelPalette(pal,true);
}

void PaletteCfg::savePalette()
{
 if(palDefault) LMSensorsWidget::cfgUnsetPalette(groupName);
 else           LMSensorsWidget::cfgWritePalette(framePanel->palette(),groupName);
}

#include "palettecfg.moc"