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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/*
KSysGuard, the KDE System Guard
Copyright (c) 1999 - 2001 Chris Schlaeger <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of version 2 of the GNU General Public
License as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
KSysGuard is currently maintained by Chris Schlaeger <[email protected]>.
Please do not commit any changes without consulting me first. Thanks!
*/
#include <qimage.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlistbox.h>
#include <qpixmap.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qtabwidget.h>
#include <kaccelmanager.h>
#include <kcolorbutton.h>
#include <kcolordialog.h>
#include <klocale.h>
#include "StyleSettings.h"
StyleSettings::StyleSettings( QWidget *parent, const char *name )
: KDialogBase( Tabbed, i18n( "Global Style Settings" ), Help | Ok | Apply |
Cancel, Ok, parent, name, true, true )
{
QFrame *page = addPage( i18n( "Display Style" ) );
QGridLayout *layout = new QGridLayout( page, 6, 2, 0, spacingHint() );
QLabel *label = new QLabel( i18n( "First foreground color:" ), page );
layout->addWidget( label, 0, 0 );
mFirstForegroundColor = new KColorButton( page );
layout->addWidget( mFirstForegroundColor, 0, 1 );
label->setBuddy( mFirstForegroundColor );
label = new QLabel( i18n( "Second foreground color:" ), page );
layout->addWidget( label, 1, 0 );
mSecondForegroundColor = new KColorButton( page );
layout->addWidget( mSecondForegroundColor, 1, 1 );
label->setBuddy( mSecondForegroundColor );
label = new QLabel( i18n( "Alarm color:" ), page );
layout->addWidget( label, 2, 0 );
mAlarmColor = new KColorButton( page );
layout->addWidget( mAlarmColor, 2, 1 );
label->setBuddy( mAlarmColor );
label = new QLabel( i18n( "Background color:" ), page );
layout->addWidget( label, 3, 0 );
mBackgroundColor = new KColorButton( page );
layout->addWidget( mBackgroundColor, 3, 1 );
label->setBuddy( mBackgroundColor );
label = new QLabel( i18n( "Font size:" ), page );
layout->addWidget( label, 4, 0 );
mFontSize = new QSpinBox( 7, 48, 1, page );
mFontSize->setValue( 8 );
layout->addWidget( mFontSize, 4, 1 );
label->setBuddy( mFontSize );
layout->setRowStretch( 5, 1 );
page = addPage( i18n( "Sensor Colors" ) );
layout = new QGridLayout( page, 1, 2, 0, spacingHint() );
mColorListBox = new QListBox( page );
layout->addWidget( mColorListBox, 0, 0 );
mEditColorButton = new QPushButton( i18n( "Change Color..." ), page );
mEditColorButton->setEnabled( false );
layout->addWidget( mEditColorButton, 0, 1, Qt::AlignTop );
connect( mColorListBox, SIGNAL( selectionChanged( QListBoxItem* ) ),
SLOT( selectionChanged( QListBoxItem* ) ) );
connect( mColorListBox, SIGNAL( doubleClicked( QListBoxItem* ) ),
SLOT( editSensorColor() ) );
connect( mEditColorButton, SIGNAL( clicked() ),
SLOT( editSensorColor() ) );
KAcceleratorManager::manage( this );
}
StyleSettings::~StyleSettings()
{
}
void StyleSettings::setFirstForegroundColor( const QColor &color )
{
mFirstForegroundColor->setColor( color );
}
QColor StyleSettings::firstForegroundColor() const
{
return mFirstForegroundColor->color();
}
void StyleSettings::setSecondForegroundColor( const QColor &color )
{
mSecondForegroundColor->setColor( color );
}
QColor StyleSettings::secondForegroundColor() const
{
return mSecondForegroundColor->color();
}
void StyleSettings::setAlarmColor( const QColor &color )
{
mAlarmColor->setColor( color );
}
QColor StyleSettings::alarmColor() const
{
return mAlarmColor->color();
}
void StyleSettings::setBackgroundColor( const QColor &color )
{
mBackgroundColor->setColor( color );
}
QColor StyleSettings::backgroundColor() const
{
return mBackgroundColor->color();
}
void StyleSettings::setFontSize( uint size )
{
mFontSize->setValue( size );
}
uint StyleSettings::fontSize() const
{
return mFontSize->value();
}
void StyleSettings::setSensorColors( const QValueList<QColor> &list )
{
mColorListBox->clear();
for ( uint i = 0; i < list.count(); ++i ) {
QPixmap pm( 12, 12 );
pm.fill( *list.at( i ) );
mColorListBox->insertItem( pm, i18n( "Color %1" ).arg( i ) );
}
}
QValueList<QColor> StyleSettings::sensorColors()
{
QValueList<QColor> list;
for ( uint i = 0; i < mColorListBox->count(); ++i )
list.append( QColor( mColorListBox->pixmap( i )->convertToImage().pixel( 1, 1 ) ) );
return list;
}
void StyleSettings::editSensorColor()
{
int pos = mColorListBox->currentItem();
if ( pos < 0 )
return;
QColor color = mColorListBox->pixmap( pos )->convertToImage().pixel( 1, 1 );
if ( KColorDialog::getColor( color ) == KColorDialog::Accepted ) {
QPixmap pm( 12, 12 );
pm.fill( color );
mColorListBox->changeItem( pm, mColorListBox->text( pos ), pos );
}
}
void StyleSettings::selectionChanged( QListBoxItem *item )
{
mEditColorButton->setEnabled( item != 0 );
}
#include "StyleSettings.moc"
|