~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksysguard/gui/SensorDisplayLib/DancingBarsSettings.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    KSysGuard, the KDE System Guard
 
3
 
 
4
    Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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.
 
19
 
 
20
*/
 
21
 
 
22
#include <kacceleratormanager.h>
 
23
#include <kcolorbutton.h>
 
24
#include <klineedit.h>
 
25
#include <kinputdialog.h>
 
26
#include <klocale.h>
 
27
#include <knuminput.h>
 
28
 
 
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>
 
36
 
 
37
#include "DancingBarsSettings.h"
 
38
 
 
39
DancingBarsSettings::DancingBarsSettings( QWidget* parent, const char* name )
 
40
  : KPageDialog( parent ), mModel( new SensorModel( this ) )
 
41
{
 
42
  setFaceType( Tabbed );
 
43
  setCaption( i18n( "Edit BarGraph Preferences" ) );
 
44
  setButtons( Ok | Cancel );
 
45
  setObjectName( name );
 
46
  setModal( false );
 
47
 
 
48
  mModel->setHasLabel( true );
 
49
 
 
50
  // Range page
 
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 );
 
56
 
 
57
  QGroupBox *groupBox = new QGroupBox( i18n( "Title" ), page );
 
58
  QGridLayout *boxLayout = new QGridLayout;
 
59
  groupBox->setLayout( boxLayout );
 
60
 
 
61
  mTitle = new KLineEdit( groupBox );
 
62
  mTitle->setWhatsThis( i18n( "Enter the title of the display here." ) );
 
63
  boxLayout->addWidget( mTitle, 0, 0 );
 
64
 
 
65
  pageLayout->addWidget( groupBox, 0, 0 );
 
66
 
 
67
  groupBox = new QGroupBox( i18n( "Display Range" ), page );
 
68
  boxLayout = new QGridLayout;
 
69
  groupBox->setLayout( boxLayout );
 
70
  boxLayout->setColumnStretch( 2, 1 );
 
71
 
 
72
  QLabel *label = new QLabel( i18n( "Minimum value:" ), groupBox );
 
73
  boxLayout->addWidget( label, 0, 0 );
 
74
 
 
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 );
 
83
 
 
84
  label = new QLabel( i18n( "Maximum value:" ), groupBox );
 
85
  boxLayout->addWidget( label, 0, 3 );
 
86
 
 
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 );
 
95
 
 
96
  pageLayout->addWidget( groupBox, 1, 0 );
 
97
 
 
98
  pageLayout->setRowStretch( 2, 1 );
 
99
 
 
100
  // Alarm page
 
101
  page = new QFrame( this );
 
102
  addPage( page, i18n( "Alarms" ) );
 
103
  pageLayout = new QGridLayout( page );
 
104
  pageLayout->setSpacing( spacingHint() );
 
105
  pageLayout->setMargin( 0 );
 
106
 
 
107
  groupBox = new QGroupBox( i18n( "Alarm for Minimum Value" ), page );
 
108
  boxLayout = new QGridLayout;
 
109
  groupBox->setLayout( boxLayout );
 
110
  boxLayout->setColumnStretch( 1, 1 );
 
111
 
 
112
  mUseLowerLimit = new QCheckBox( i18n( "Enable alarm" ), groupBox );
 
113
  mUseLowerLimit->setWhatsThis( i18n( "Enable the minimum value alarm." ) );
 
114
  boxLayout->addWidget( mUseLowerLimit, 0, 0 );
 
115
 
 
116
  label = new QLabel( i18n( "Lower limit:" ), groupBox );
 
117
  boxLayout->addWidget( label, 0, 2 );
 
118
 
 
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 );
 
127
 
 
128
  pageLayout->addWidget( groupBox, 0, 0 );
 
129
 
 
130
  groupBox = new QGroupBox( i18n( "Alarm for Maximum Value" ), page );
 
131
  boxLayout = new QGridLayout;
 
132
  groupBox->setLayout( boxLayout );
 
133
  boxLayout->setColumnStretch( 1, 1 );
 
134
 
 
135
  mUseUpperLimit = new QCheckBox( i18n( "Enable alarm" ), groupBox );
 
136
  mUseUpperLimit->setWhatsThis( i18n( "Enable the maximum value alarm." ) );
 
137
  boxLayout->addWidget( mUseUpperLimit, 0, 0 );
 
138
 
 
139
  label = new QLabel( i18n( "Upper limit:" ), groupBox );
 
140
  boxLayout->addWidget( label, 0, 2 );
 
141
 
 
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 );
 
149
 
 
150
  pageLayout->addWidget( groupBox, 1, 0 );
 
151
 
 
152
  pageLayout->setRowStretch( 2, 1 );
 
153
 
 
154
  // Look page
 
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 );
 
160
 
 
161
  label = new QLabel( i18n( "Normal bar color:" ), page );
 
162
  pageLayout->addWidget( label, 0, 0 );
 
163
 
 
164
  mForegroundColor = new KColorButton( page );
 
165
  pageLayout->addWidget( mForegroundColor, 0, 1 );
 
166
  label->setBuddy( mForegroundColor );
 
167
 
 
168
  label = new QLabel( i18n( "Out-of-range color:" ), page );
 
169
  pageLayout->addWidget( label, 1, 0 );
 
170
 
 
171
  mAlarmColor = new KColorButton( page );
 
172
  pageLayout->addWidget( mAlarmColor, 1, 1 );
 
173
  label->setBuddy( mAlarmColor );
 
174
 
 
175
  label = new QLabel( i18n( "Background color:" ), page );
 
176
  pageLayout->addWidget( label, 2, 0 );
 
177
 
 
178
  mBackgroundColor = new KColorButton( page );
 
179
  pageLayout->addWidget( mBackgroundColor, 2, 1 );
 
180
  label->setBuddy( mBackgroundColor );
 
181
 
 
182
  label = new QLabel( i18n( "Font size:" ), page );
 
183
  pageLayout->addWidget( label, 3, 0 );
 
184
 
 
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 );
 
189
 
 
190
  pageLayout->setRowStretch( 4, 1 );
 
191
 
 
192
  // Sensor page
 
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 );
 
199
 
 
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);
 
206
 
 
207
  mEditButton = new QPushButton( i18n( "Edit..." ), page );
 
208
  mEditButton->setWhatsThis( i18n( "Push this button to configure the label." ) );
 
209
  pageLayout->addWidget( mEditButton, 0, 1 );
 
210
 
 
211
  mRemoveButton = new QPushButton( i18n( "Delete" ), page );
 
212
  mRemoveButton->setWhatsThis( i18n( "Push this button to delete the sensor." ) );
 
213
  pageLayout->addWidget( mRemoveButton, 1, 1 );
 
214
 
 
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() ) );
 
221
 
 
222
  KAcceleratorManager::manage( this );
 
223
 
 
224
  mTitle->setFocus();
 
225
}
 
226
 
 
227
DancingBarsSettings::~DancingBarsSettings()
 
228
{
 
229
}
 
230
 
 
231
void DancingBarsSettings::setTitle( const QString& title )
 
232
{
 
233
  mTitle->setText( title );
 
234
}
 
235
 
 
236
QString DancingBarsSettings::title() const
 
237
{
 
238
  return mTitle->text();
 
239
}
 
240
 
 
241
void DancingBarsSettings::setMinValue( double min )
 
242
{
 
243
  mMinValue->setValue( min );
 
244
}
 
245
 
 
246
double DancingBarsSettings::minValue() const
 
247
{
 
248
  return mMinValue->value();
 
249
}
 
250
 
 
251
void DancingBarsSettings::setMaxValue( double max )
 
252
{
 
253
  mMaxValue->setValue( max );
 
254
}
 
255
 
 
256
double DancingBarsSettings::maxValue() const
 
257
{
 
258
  return mMaxValue->value();
 
259
}
 
260
 
 
261
void DancingBarsSettings::setUseLowerLimit( bool value )
 
262
{
 
263
  mUseLowerLimit->setChecked( value );
 
264
}
 
265
 
 
266
bool DancingBarsSettings::useLowerLimit() const
 
267
{
 
268
  return mUseLowerLimit->isChecked();
 
269
}
 
270
 
 
271
void DancingBarsSettings::setLowerLimit( double limit )
 
272
{
 
273
  mLowerLimit->setValue( limit );
 
274
}
 
275
 
 
276
double DancingBarsSettings::lowerLimit() const
 
277
{
 
278
  return mLowerLimit->value();
 
279
}
 
280
 
 
281
void DancingBarsSettings::setUseUpperLimit( bool value )
 
282
{
 
283
  mUseUpperLimit->setChecked( value );
 
284
}
 
285
 
 
286
bool DancingBarsSettings::useUpperLimit() const
 
287
{
 
288
  return mUseUpperLimit->isChecked();
 
289
}
 
290
 
 
291
void DancingBarsSettings::setUpperLimit( double limit )
 
292
{
 
293
  mUpperLimit->setValue( limit );
 
294
}
 
295
 
 
296
double DancingBarsSettings::upperLimit() const
 
297
{
 
298
  return mUpperLimit->value();
 
299
}
 
300
 
 
301
void DancingBarsSettings::setForegroundColor( const QColor &color )
 
302
{
 
303
  mForegroundColor->setColor( color );
 
304
}
 
305
 
 
306
QColor DancingBarsSettings::foregroundColor() const
 
307
{
 
308
  return mForegroundColor->color();
 
309
}
 
310
 
 
311
void DancingBarsSettings::setAlarmColor( const QColor &color )
 
312
{
 
313
  mAlarmColor->setColor( color );
 
314
}
 
315
 
 
316
QColor DancingBarsSettings::alarmColor() const
 
317
{
 
318
  return mAlarmColor->color();
 
319
}
 
320
 
 
321
void DancingBarsSettings::setBackgroundColor( const QColor &color )
 
322
{
 
323
  mBackgroundColor->setColor( color );
 
324
}
 
325
 
 
326
QColor DancingBarsSettings::backgroundColor() const
 
327
{
 
328
  return mBackgroundColor->color();
 
329
}
 
330
 
 
331
void DancingBarsSettings::setFontSize( int size )
 
332
{
 
333
  mFontSize->setValue( size );
 
334
}
 
335
 
 
336
int DancingBarsSettings::fontSize() const
 
337
{
 
338
  return mFontSize->value();
 
339
}
 
340
 
 
341
void DancingBarsSettings::setSensors( const SensorModelEntry::List &list )
 
342
{
 
343
  mModel->setSensors( list );
 
344
 
 
345
  mView->selectionModel()->setCurrentIndex( mModel->index( 0, 0 ), QItemSelectionModel::SelectCurrent |
 
346
                                                                   QItemSelectionModel::Rows );
 
347
}
 
348
 
 
349
SensorModelEntry::List DancingBarsSettings::sensors() const
 
350
{
 
351
  return mModel->sensors();
 
352
}
 
353
 
 
354
void DancingBarsSettings::editSensor()
 
355
{
 
356
  if ( !mView->selectionModel() )
 
357
    return;
 
358
 
 
359
  const QModelIndex index = mView->selectionModel()->currentIndex();
 
360
  if ( !index.isValid() )
 
361
    return;
 
362
 
 
363
  SensorModelEntry sensor = mModel->sensor( index );
 
364
 
 
365
  bool ok;
 
366
  const QString name = KInputDialog::getText( i18n( "Label of Bar Graph" ),
 
367
                                              i18n( "Enter new label:" ), sensor.label(), &ok, this );
 
368
  if ( ok ) {
 
369
    sensor.setLabel( name );
 
370
    mModel->setSensor( sensor, index );
 
371
  }
 
372
}
 
373
 
 
374
void DancingBarsSettings::removeSensor()
 
375
{
 
376
  if ( !mView->selectionModel() )
 
377
    return;
 
378
 
 
379
  const QModelIndex index = mView->selectionModel()->currentIndex();
 
380
  if ( !index.isValid() )
 
381
    return;
 
382
 
 
383
  mModel->removeSensor( index );
 
384
}
 
385
 
 
386
#include "DancingBarsSettings.moc"