2
KSysGuard, the KDE System Guard
4
Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
6
This program is free software; you can redistribute it and/or
7
modify it under the terms of the GNU General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
#include <kacceleratormanager.h>
23
#include <kcolorbutton.h>
24
#include <klineedit.h>
25
#include <kinputdialog.h>
27
#include <knuminput.h>
29
#include <QtGui/QCheckBox>
30
#include <QtGui/QGroupBox>
31
#include <QtGui/QHeaderView>
32
#include <QtGui/QLabel>
33
#include <QtGui/QLayout>
34
#include <QtGui/QPushButton>
35
#include <QtGui/QTreeView>
37
#include "DancingBarsSettings.h"
39
DancingBarsSettings::DancingBarsSettings( QWidget* parent, const char* name )
40
: KPageDialog( parent ), mModel( new SensorModel( this ) )
42
setFaceType( Tabbed );
43
setCaption( i18n( "Edit BarGraph Preferences" ) );
44
setButtons( Ok | Cancel );
45
setObjectName( name );
48
mModel->setHasLabel( true );
51
QFrame *page = new QFrame( this );
52
addPage( page, i18n( "Range" ) );
53
QGridLayout *pageLayout = new QGridLayout( page );
54
pageLayout->setSpacing( spacingHint() );
55
pageLayout->setMargin( 0 );
57
QGroupBox *groupBox = new QGroupBox( i18n( "Title" ), page );
58
QGridLayout *boxLayout = new QGridLayout;
59
groupBox->setLayout( boxLayout );
61
mTitle = new KLineEdit( groupBox );
62
mTitle->setWhatsThis( i18n( "Enter the title of the display here." ) );
63
boxLayout->addWidget( mTitle, 0, 0 );
65
pageLayout->addWidget( groupBox, 0, 0 );
67
groupBox = new QGroupBox( i18n( "Display Range" ), page );
68
boxLayout = new QGridLayout;
69
groupBox->setLayout( boxLayout );
70
boxLayout->setColumnStretch( 2, 1 );
72
QLabel *label = new QLabel( i18n( "Minimum value:" ), groupBox );
73
boxLayout->addWidget( label, 0, 0 );
75
mMinValue = new QDoubleSpinBox(groupBox);
76
mMinValue->setRange(0, 10000);
77
mMinValue->setSingleStep(0.5);
78
mMinValue->setValue(0);
79
mMinValue->setDecimals(2);
80
mMinValue->setWhatsThis( i18n( "Enter the minimum value for the display here. If both values are 0, automatic range detection is enabled." ) );
81
boxLayout->addWidget( mMinValue, 0, 1 );
82
label->setBuddy( mMinValue );
84
label = new QLabel( i18n( "Maximum value:" ), groupBox );
85
boxLayout->addWidget( label, 0, 3 );
87
mMaxValue = new QDoubleSpinBox( groupBox);
88
mMaxValue->setRange(0, 100);
89
mMaxValue->setSingleStep(0.5);
90
mMaxValue->setValue(100);
91
mMaxValue->setDecimals(2);
92
mMaxValue->setWhatsThis( i18n( "Enter the maximum value for the display here. If both values are 0, automatic range detection is enabled." ) );
93
boxLayout->addWidget( mMaxValue, 0, 4 );
94
label->setBuddy( mMaxValue );
96
pageLayout->addWidget( groupBox, 1, 0 );
98
pageLayout->setRowStretch( 2, 1 );
101
page = new QFrame( this );
102
addPage( page, i18n( "Alarms" ) );
103
pageLayout = new QGridLayout( page );
104
pageLayout->setSpacing( spacingHint() );
105
pageLayout->setMargin( 0 );
107
groupBox = new QGroupBox( i18n( "Alarm for Minimum Value" ), page );
108
boxLayout = new QGridLayout;
109
groupBox->setLayout( boxLayout );
110
boxLayout->setColumnStretch( 1, 1 );
112
mUseLowerLimit = new QCheckBox( i18n( "Enable alarm" ), groupBox );
113
mUseLowerLimit->setWhatsThis( i18n( "Enable the minimum value alarm." ) );
114
boxLayout->addWidget( mUseLowerLimit, 0, 0 );
116
label = new QLabel( i18n( "Lower limit:" ), groupBox );
117
boxLayout->addWidget( label, 0, 2 );
119
mLowerLimit = new QDoubleSpinBox(groupBox);
120
mLowerLimit->setRange(0, 100);
121
mLowerLimit->setSingleStep(0.5);
122
mLowerLimit->setValue(0);
123
mLowerLimit->setDecimals(2);
124
mLowerLimit->setEnabled( false );
125
boxLayout->addWidget( mLowerLimit, 0, 3 );
126
label->setBuddy( mLowerLimit );
128
pageLayout->addWidget( groupBox, 0, 0 );
130
groupBox = new QGroupBox( i18n( "Alarm for Maximum Value" ), page );
131
boxLayout = new QGridLayout;
132
groupBox->setLayout( boxLayout );
133
boxLayout->setColumnStretch( 1, 1 );
135
mUseUpperLimit = new QCheckBox( i18n( "Enable alarm" ), groupBox );
136
mUseUpperLimit->setWhatsThis( i18n( "Enable the maximum value alarm." ) );
137
boxLayout->addWidget( mUseUpperLimit, 0, 0 );
139
label = new QLabel( i18n( "Upper limit:" ), groupBox );
140
boxLayout->addWidget( label, 0, 2 );
142
mUpperLimit = new QDoubleSpinBox( groupBox);
143
mUpperLimit->setRange(0, 1000);
144
mUpperLimit->setSingleStep(0.5);
145
mUpperLimit->setDecimals(2);
146
mUpperLimit->setEnabled( false );
147
boxLayout->addWidget( mUpperLimit, 0, 3 );
148
label->setBuddy( mUpperLimit );
150
pageLayout->addWidget( groupBox, 1, 0 );
152
pageLayout->setRowStretch( 2, 1 );
155
page = new QFrame( this );
156
addPage( page, i18nc( "@title:tab Appearance of the bar graph", "Look" ) );
157
pageLayout = new QGridLayout( page );
158
pageLayout->setSpacing( spacingHint() );
159
pageLayout->setMargin( 0 );
161
label = new QLabel( i18n( "Normal bar color:" ), page );
162
pageLayout->addWidget( label, 0, 0 );
164
mForegroundColor = new KColorButton( page );
165
pageLayout->addWidget( mForegroundColor, 0, 1 );
166
label->setBuddy( mForegroundColor );
168
label = new QLabel( i18n( "Out-of-range color:" ), page );
169
pageLayout->addWidget( label, 1, 0 );
171
mAlarmColor = new KColorButton( page );
172
pageLayout->addWidget( mAlarmColor, 1, 1 );
173
label->setBuddy( mAlarmColor );
175
label = new QLabel( i18n( "Background color:" ), page );
176
pageLayout->addWidget( label, 2, 0 );
178
mBackgroundColor = new KColorButton( page );
179
pageLayout->addWidget( mBackgroundColor, 2, 1 );
180
label->setBuddy( mBackgroundColor );
182
label = new QLabel( i18n( "Font size:" ), page );
183
pageLayout->addWidget( label, 3, 0 );
185
mFontSize = new KIntNumInput( 9, page );
186
mFontSize->setWhatsThis( i18n( "This determines the size of the font used to print a label underneath the bars. Bars are automatically suppressed if text becomes too large, so it is advisable to use a small font size here." ) );
187
pageLayout->addWidget( mFontSize, 3, 1 );
188
label->setBuddy( mFontSize );
190
pageLayout->setRowStretch( 4, 1 );
193
page = new QFrame( this );
194
addPage( page, i18n( "Sensors" ) );
195
pageLayout = new QGridLayout( page );
196
pageLayout->setSpacing( spacingHint() );
197
pageLayout->setMargin( 0 );
198
pageLayout->setRowStretch( 2, 1 );
200
mView = new QTreeView( page );
201
mView->header()->setStretchLastSection( true );
202
mView->setRootIsDecorated( false );
203
mView->setItemsExpandable( false );
204
mView->setModel( mModel );
205
pageLayout->addWidget( mView, 0, 0, 3, 1);
207
mEditButton = new QPushButton( i18n( "Edit..." ), page );
208
mEditButton->setWhatsThis( i18n( "Push this button to configure the label." ) );
209
pageLayout->addWidget( mEditButton, 0, 1 );
211
mRemoveButton = new QPushButton( i18n( "Delete" ), page );
212
mRemoveButton->setWhatsThis( i18n( "Push this button to delete the sensor." ) );
213
pageLayout->addWidget( mRemoveButton, 1, 1 );
215
connect( mUseLowerLimit, SIGNAL( toggled( bool ) ),
216
mLowerLimit, SLOT( setEnabled( bool ) ) );
217
connect( mUseUpperLimit, SIGNAL( toggled( bool ) ),
218
mUpperLimit, SLOT( setEnabled( bool ) ) );
219
connect( mEditButton, SIGNAL( clicked() ), SLOT( editSensor() ) );
220
connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeSensor() ) );
222
KAcceleratorManager::manage( this );
227
DancingBarsSettings::~DancingBarsSettings()
231
void DancingBarsSettings::setTitle( const QString& title )
233
mTitle->setText( title );
236
QString DancingBarsSettings::title() const
238
return mTitle->text();
241
void DancingBarsSettings::setMinValue( double min )
243
mMinValue->setValue( min );
246
double DancingBarsSettings::minValue() const
248
return mMinValue->value();
251
void DancingBarsSettings::setMaxValue( double max )
253
mMaxValue->setValue( max );
256
double DancingBarsSettings::maxValue() const
258
return mMaxValue->value();
261
void DancingBarsSettings::setUseLowerLimit( bool value )
263
mUseLowerLimit->setChecked( value );
266
bool DancingBarsSettings::useLowerLimit() const
268
return mUseLowerLimit->isChecked();
271
void DancingBarsSettings::setLowerLimit( double limit )
273
mLowerLimit->setValue( limit );
276
double DancingBarsSettings::lowerLimit() const
278
return mLowerLimit->value();
281
void DancingBarsSettings::setUseUpperLimit( bool value )
283
mUseUpperLimit->setChecked( value );
286
bool DancingBarsSettings::useUpperLimit() const
288
return mUseUpperLimit->isChecked();
291
void DancingBarsSettings::setUpperLimit( double limit )
293
mUpperLimit->setValue( limit );
296
double DancingBarsSettings::upperLimit() const
298
return mUpperLimit->value();
301
void DancingBarsSettings::setForegroundColor( const QColor &color )
303
mForegroundColor->setColor( color );
306
QColor DancingBarsSettings::foregroundColor() const
308
return mForegroundColor->color();
311
void DancingBarsSettings::setAlarmColor( const QColor &color )
313
mAlarmColor->setColor( color );
316
QColor DancingBarsSettings::alarmColor() const
318
return mAlarmColor->color();
321
void DancingBarsSettings::setBackgroundColor( const QColor &color )
323
mBackgroundColor->setColor( color );
326
QColor DancingBarsSettings::backgroundColor() const
328
return mBackgroundColor->color();
331
void DancingBarsSettings::setFontSize( int size )
333
mFontSize->setValue( size );
336
int DancingBarsSettings::fontSize() const
338
return mFontSize->value();
341
void DancingBarsSettings::setSensors( const SensorModelEntry::List &list )
343
mModel->setSensors( list );
345
mView->selectionModel()->setCurrentIndex( mModel->index( 0, 0 ), QItemSelectionModel::SelectCurrent |
346
QItemSelectionModel::Rows );
349
SensorModelEntry::List DancingBarsSettings::sensors() const
351
return mModel->sensors();
354
void DancingBarsSettings::editSensor()
356
if ( !mView->selectionModel() )
359
const QModelIndex index = mView->selectionModel()->currentIndex();
360
if ( !index.isValid() )
363
SensorModelEntry sensor = mModel->sensor( index );
366
const QString name = KInputDialog::getText( i18n( "Label of Bar Graph" ),
367
i18n( "Enter new label:" ), sensor.label(), &ok, this );
369
sensor.setLabel( name );
370
mModel->setSensor( sensor, index );
374
void DancingBarsSettings::removeSensor()
376
if ( !mView->selectionModel() )
379
const QModelIndex index = mView->selectionModel()->currentIndex();
380
if ( !index.isValid() )
383
mModel->removeSensor( index );
386
#include "DancingBarsSettings.moc"