Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / ksysguard / gui / SensorDisplayLib / DancingBarsSettings.cc
blob77d2d4e20773bccb360f22012f82d1e82e283e38
1 /*
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>
26 #include <klocale.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 );
46 setModal( false );
47 showButtonSeparator( true );
49 mModel->setHasLabel( true );
51 // Range page
52 QFrame *page = new QFrame( this );
53 addPage( page, i18n( "Range" ) );
54 QGridLayout *pageLayout = new QGridLayout( page );
55 pageLayout->setSpacing( spacingHint() );
56 pageLayout->setMargin( 0 );
58 QGroupBox *groupBox = new QGroupBox( i18n( "Title" ), page );
59 QGridLayout *boxLayout = new QGridLayout;
60 groupBox->setLayout( boxLayout );
62 mTitle = new KLineEdit( groupBox );
63 mTitle->setWhatsThis( i18n( "Enter the title of the display here." ) );
64 boxLayout->addWidget( mTitle, 0, 0 );
66 pageLayout->addWidget( groupBox, 0, 0 );
68 groupBox = new QGroupBox( i18n( "Display Range" ), page );
69 boxLayout = new QGridLayout;
70 groupBox->setLayout( boxLayout );
71 boxLayout->setColumnStretch( 2, 1 );
73 QLabel *label = new QLabel( i18n( "Minimum value:" ), groupBox );
74 boxLayout->addWidget( label, 0, 0 );
76 mMinValue = new QDoubleSpinBox(groupBox);
77 mMinValue->setRange(0, 10000);
78 mMinValue->setSingleStep(0.5);
79 mMinValue->setValue(0);
80 mMinValue->setDecimals(2);
81 mMinValue->setWhatsThis( i18n( "Enter the minimum value for the display here. If both values are 0, automatic range detection is enabled." ) );
82 boxLayout->addWidget( mMinValue, 0, 1 );
83 label->setBuddy( mMinValue );
85 label = new QLabel( i18n( "Maximum value:" ), groupBox );
86 boxLayout->addWidget( label, 0, 3 );
88 mMaxValue = new QDoubleSpinBox( groupBox);
89 mMaxValue->setRange(0, 100);
90 mMaxValue->setSingleStep(0.5);
91 mMaxValue->setValue(100);
92 mMaxValue->setDecimals(2);
93 mMaxValue->setWhatsThis( i18n( "Enter the maximum value for the display here. If both values are 0, automatic range detection is enabled." ) );
94 boxLayout->addWidget( mMaxValue, 0, 4 );
95 label->setBuddy( mMaxValue );
97 pageLayout->addWidget( groupBox, 1, 0 );
99 pageLayout->setRowStretch( 2, 1 );
101 // Alarm page
102 page = new QFrame( this );
103 addPage( page, i18n( "Alarms" ) );
104 pageLayout = new QGridLayout( page );
105 pageLayout->setSpacing( spacingHint() );
106 pageLayout->setMargin( 0 );
108 groupBox = new QGroupBox( i18n( "Alarm for Minimum Value" ), page );
109 boxLayout = new QGridLayout;
110 groupBox->setLayout( boxLayout );
111 boxLayout->setColumnStretch( 1, 1 );
113 mUseLowerLimit = new QCheckBox( i18n( "Enable alarm" ), groupBox );
114 mUseLowerLimit->setWhatsThis( i18n( "Enable the minimum value alarm." ) );
115 boxLayout->addWidget( mUseLowerLimit, 0, 0 );
117 label = new QLabel( i18n( "Lower limit:" ), groupBox );
118 boxLayout->addWidget( label, 0, 2 );
120 mLowerLimit = new QDoubleSpinBox(groupBox);
121 mLowerLimit->setRange(0, 100);
122 mLowerLimit->setSingleStep(0.5);
123 mLowerLimit->setValue(0);
124 mLowerLimit->setDecimals(2);
125 mLowerLimit->setEnabled( false );
126 boxLayout->addWidget( mLowerLimit, 0, 3 );
127 label->setBuddy( mLowerLimit );
129 pageLayout->addWidget( groupBox, 0, 0 );
131 groupBox = new QGroupBox( i18n( "Alarm for Maximum Value" ), page );
132 boxLayout = new QGridLayout;
133 groupBox->setLayout( boxLayout );
134 boxLayout->setColumnStretch( 1, 1 );
136 mUseUpperLimit = new QCheckBox( i18n( "Enable alarm" ), groupBox );
137 mUseUpperLimit->setWhatsThis( i18n( "Enable the maximum value alarm." ) );
138 boxLayout->addWidget( mUseUpperLimit, 0, 0 );
140 label = new QLabel( i18n( "Upper limit:" ), groupBox );
141 boxLayout->addWidget( label, 0, 2 );
143 mUpperLimit = new QDoubleSpinBox( groupBox);
144 mUpperLimit->setRange(0, 1000);
145 mUpperLimit->setSingleStep(0.5);
146 mUpperLimit->setDecimals(2);
147 mUpperLimit->setEnabled( false );
148 boxLayout->addWidget( mUpperLimit, 0, 3 );
149 label->setBuddy( mUpperLimit );
151 pageLayout->addWidget( groupBox, 1, 0 );
153 pageLayout->setRowStretch( 2, 1 );
155 // Look page
156 page = new QFrame( this );
157 addPage( page, i18n( "Look" ) );
158 pageLayout = new QGridLayout( page );
159 pageLayout->setSpacing( spacingHint() );
160 pageLayout->setMargin( 0 );
162 label = new QLabel( i18n( "Normal bar color:" ), page );
163 pageLayout->addWidget( label, 0, 0 );
165 mForegroundColor = new KColorButton( page );
166 pageLayout->addWidget( mForegroundColor, 0, 1 );
167 label->setBuddy( mForegroundColor );
169 label = new QLabel( i18n( "Out-of-range color:" ), page );
170 pageLayout->addWidget( label, 1, 0 );
172 mAlarmColor = new KColorButton( page );
173 pageLayout->addWidget( mAlarmColor, 1, 1 );
174 label->setBuddy( mAlarmColor );
176 label = new QLabel( i18n( "Background color:" ), page );
177 pageLayout->addWidget( label, 2, 0 );
179 mBackgroundColor = new KColorButton( page );
180 pageLayout->addWidget( mBackgroundColor, 2, 1 );
181 label->setBuddy( mBackgroundColor );
183 label = new QLabel( i18n( "Font size:" ), page );
184 pageLayout->addWidget( label, 3, 0 );
186 mFontSize = new KIntNumInput( 9, page );
187 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." ) );
188 pageLayout->addWidget( mFontSize, 3, 1 );
189 label->setBuddy( mFontSize );
191 pageLayout->setRowStretch( 4, 1 );
193 // Sensor page
194 page = new QFrame( this );
195 addPage( page, i18n( "Sensors" ) );
196 pageLayout = new QGridLayout( page );
197 pageLayout->setSpacing( spacingHint() );
198 pageLayout->setMargin( 0 );
199 pageLayout->setRowStretch( 2, 1 );
201 mView = new QTreeView( page );
202 mView->header()->setStretchLastSection( true );
203 mView->setRootIsDecorated( false );
204 mView->setItemsExpandable( false );
205 mView->setModel( mModel );
206 pageLayout->addWidget( mView, 0, 0, 3, 1);
208 mEditButton = new QPushButton( i18n( "Edit..." ), page );
209 mEditButton->setWhatsThis( i18n( "Push this button to configure the label." ) );
210 pageLayout->addWidget( mEditButton, 0, 1 );
212 mRemoveButton = new QPushButton( i18n( "Delete" ), page );
213 mRemoveButton->setWhatsThis( i18n( "Push this button to delete the sensor." ) );
214 pageLayout->addWidget( mRemoveButton, 1, 1 );
216 connect( mUseLowerLimit, SIGNAL( toggled( bool ) ),
217 mLowerLimit, SLOT( setEnabled( bool ) ) );
218 connect( mUseUpperLimit, SIGNAL( toggled( bool ) ),
219 mUpperLimit, SLOT( setEnabled( bool ) ) );
220 connect( mEditButton, SIGNAL( clicked() ), SLOT( editSensor() ) );
221 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeSensor() ) );
223 KAcceleratorManager::manage( this );
225 mTitle->setFocus();
228 DancingBarsSettings::~DancingBarsSettings()
232 void DancingBarsSettings::setTitle( const QString& title )
234 mTitle->setText( title );
237 QString DancingBarsSettings::title() const
239 return mTitle->text();
242 void DancingBarsSettings::setMinValue( double min )
244 mMinValue->setValue( min );
247 double DancingBarsSettings::minValue() const
249 return mMinValue->value();
252 void DancingBarsSettings::setMaxValue( double max )
254 mMaxValue->setValue( max );
257 double DancingBarsSettings::maxValue() const
259 return mMaxValue->value();
262 void DancingBarsSettings::setUseLowerLimit( bool value )
264 mUseLowerLimit->setChecked( value );
267 bool DancingBarsSettings::useLowerLimit() const
269 return mUseLowerLimit->isChecked();
272 void DancingBarsSettings::setLowerLimit( double limit )
274 mLowerLimit->setValue( limit );
277 double DancingBarsSettings::lowerLimit() const
279 return mLowerLimit->value();
282 void DancingBarsSettings::setUseUpperLimit( bool value )
284 mUseUpperLimit->setChecked( value );
287 bool DancingBarsSettings::useUpperLimit() const
289 return mUseUpperLimit->isChecked();
292 void DancingBarsSettings::setUpperLimit( double limit )
294 mUpperLimit->setValue( limit );
297 double DancingBarsSettings::upperLimit() const
299 return mUpperLimit->value();
302 void DancingBarsSettings::setForegroundColor( const QColor &color )
304 mForegroundColor->setColor( color );
307 QColor DancingBarsSettings::foregroundColor() const
309 return mForegroundColor->color();
312 void DancingBarsSettings::setAlarmColor( const QColor &color )
314 mAlarmColor->setColor( color );
317 QColor DancingBarsSettings::alarmColor() const
319 return mAlarmColor->color();
322 void DancingBarsSettings::setBackgroundColor( const QColor &color )
324 mBackgroundColor->setColor( color );
327 QColor DancingBarsSettings::backgroundColor() const
329 return mBackgroundColor->color();
332 void DancingBarsSettings::setFontSize( int size )
334 mFontSize->setValue( size );
337 int DancingBarsSettings::fontSize() const
339 return mFontSize->value();
342 void DancingBarsSettings::setSensors( const SensorModelEntry::List &list )
344 mModel->setSensors( list );
346 mView->selectionModel()->setCurrentIndex( mModel->index( 0, 0 ), QItemSelectionModel::SelectCurrent |
347 QItemSelectionModel::Rows );
350 SensorModelEntry::List DancingBarsSettings::sensors() const
352 return mModel->sensors();
355 void DancingBarsSettings::editSensor()
357 if ( !mView->selectionModel() )
358 return;
360 const QModelIndex index = mView->selectionModel()->currentIndex();
361 if ( !index.isValid() )
362 return;
364 SensorModelEntry sensor = mModel->sensor( index );
366 bool ok;
367 const QString name = KInputDialog::getText( i18n( "Label of Bar Graph" ),
368 i18n( "Enter new label:" ), sensor.label(), &ok, this );
369 if ( ok ) {
370 sensor.setLabel( name );
371 mModel->setSensor( sensor, index );
375 void DancingBarsSettings::removeSensor()
377 if ( !mView->selectionModel() )
378 return;
380 const QModelIndex index = mView->selectionModel()->currentIndex();
381 if ( !index.isValid() )
382 return;
384 mModel->removeSensor( index );
387 #include "DancingBarsSettings.moc"