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

« back to all changes in this revision

Viewing changes to ksysguard/gui/SensorDisplayLib/FancyPlotterSettings.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 <kcolordialog.h>
 
24
#include <klineedit.h>
 
25
#include <klocale.h>
 
26
#include <knuminput.h>
 
27
 
 
28
#include <QtCore/QAbstractTableModel>
 
29
#include <QtCore/QList>
 
30
#include <QtGui/QCheckBox>
 
31
#include <QtGui/QDoubleSpinBox>
 
32
#include <QtGui/QFormLayout>
 
33
#include <QtGui/QGridLayout>
 
34
#include <QtGui/QGroupBox>
 
35
#include <QtGui/QHeaderView>
 
36
#include <QtGui/QImage>
 
37
#include <QtGui/QLabel>
 
38
#include <QtGui/QLayout>
 
39
#include <QtGui/QPixmap>
 
40
#include <QtGui/QPushButton>
 
41
#include <QtGui/QTreeView>
 
42
 
 
43
#include <limits>
 
44
 
 
45
#include "FancyPlotterSettings.h"
 
46
 
 
47
FancyPlotterSettings::FancyPlotterSettings( QWidget* parent, bool locked )
 
48
  : KPageDialog( parent ), mModel( new SensorModel( this ) )
 
49
{
 
50
  setFaceType( Tabbed );
 
51
  setCaption( i18n( "Plotter Settings" ) );
 
52
  setButtons( Ok | Apply | Cancel );
 
53
  setObjectName( "FancyPlotterSettings" );
 
54
  setModal( false );
 
55
 
 
56
  QFrame *page = 0;
 
57
  QGridLayout *pageLayout = 0;
 
58
  QGridLayout *boxLayout = 0;
 
59
  QGroupBox *groupBox = 0;
 
60
  QLabel *label = 0;
 
61
 
 
62
  // Style page
 
63
  page = new QFrame();
 
64
  addPage( page, i18n( "General" ) );
 
65
  pageLayout = new QGridLayout( page );
 
66
  pageLayout->setSpacing( spacingHint() );
 
67
  pageLayout->setMargin( 0 );
 
68
 
 
69
  label = new QLabel( i18n( "Title:" ), page );
 
70
  pageLayout->addWidget( label, 0, 0 );
 
71
 
 
72
  mTitle = new KLineEdit( page );
 
73
  mTitle->setWhatsThis( i18n( "Enter the title of the display here." ) );
 
74
  pageLayout->addWidget( mTitle, 0, 1 );
 
75
  label->setBuddy( mTitle );
 
76
 
 
77
  mStackBeams = new QCheckBox( i18n("Stack the beams on top of each other"), page);
 
78
  mStackBeams->setWhatsThis( i18n("The beams are stacked on top of each other, and the area is drawn filled in. So if one beam has a value of 2 and another beam has a value of 3, the first beam will be drawn at value 2 and the other beam drawn at 2+3=5.") );
 
79
  pageLayout->addWidget( mStackBeams, 1, 0,1,2);
 
80
 
 
81
  pageLayout->setRowStretch( 2, 1 );
 
82
 
 
83
  // Scales page
 
84
  page = new QFrame();
 
85
  addPage( page, i18n( "Scales" ) );
 
86
  pageLayout = new QGridLayout( page );
 
87
  pageLayout->setSpacing( spacingHint() );
 
88
  pageLayout->setMargin( 0 );
 
89
 
 
90
  groupBox = new QGroupBox( i18n( "Vertical scale" ), page );
 
91
  boxLayout = new QGridLayout;
 
92
  groupBox->setLayout( boxLayout );
 
93
  boxLayout->setSpacing( spacingHint() );
 
94
  boxLayout->setColumnStretch( 2, 1 );
 
95
 
 
96
  mManualRange = new QCheckBox( i18n( "Specify graph range:" ), groupBox );
 
97
  mManualRange->setWhatsThis( i18n( "Check this box if you want the display range to adapt dynamically to the currently displayed values; if you do not check this, you have to specify the range you want in the fields below." ) );
 
98
  mManualRange->setChecked(true);
 
99
  boxLayout->addWidget( mManualRange, 0, 0, 1, 5 );
 
100
 
 
101
  mMinValueLabel = new QLabel( i18n( "Minimum value:" ), groupBox );
 
102
  boxLayout->addWidget( mMinValueLabel, 1, 0 );
 
103
 
 
104
  mMinValue = new QDoubleSpinBox( groupBox );
 
105
  mMinValue->setMaximum( std::numeric_limits<long long>::max());
 
106
  mMinValue->setMinimum( std::numeric_limits<long long>::min());
 
107
  mMinValue->setWhatsThis( i18n( "Enter the minimum value for the display here." ) );
 
108
  mMinValue->setSingleStep(10);
 
109
  boxLayout->addWidget( mMinValue, 1, 1 );
 
110
  mMinValueLabel->setBuddy( mMinValue );
 
111
 
 
112
  mMaxValueLabel = new QLabel( i18n( "Maximum value:" ), groupBox );
 
113
  boxLayout->addWidget( mMaxValueLabel, 1, 3 );
 
114
 
 
115
  mMaxValue = new QDoubleSpinBox( groupBox);
 
116
  mMaxValue->setMaximum( std::numeric_limits<long long>::max());
 
117
  mMaxValue->setMinimum( std::numeric_limits<long long>::min());
 
118
  mMaxValue->setWhatsThis( i18n( "Enter the soft maximum value for the display here. The upper range will not be reduced below this value, but will still go above this number for values above this value." ) );
 
119
  mMaxValue->setSingleStep(10);
 
120
  boxLayout->addWidget( mMaxValue, 1, 4 );
 
121
  mMaxValueLabel->setBuddy( mMaxValue );
 
122
 
 
123
  pageLayout->addWidget( groupBox, 0, 0 );
 
124
 
 
125
  groupBox = new QGroupBox( i18n( "Horizontal scale" ), page );
 
126
  QFormLayout *formLayout = new QFormLayout(groupBox);
 
127
 
 
128
  mHorizontalScale = new KIntNumInput( 1, groupBox );
 
129
  mHorizontalScale->setMinimum( 1 );
 
130
  mHorizontalScale->setMaximum( 50 );
 
131
 
 
132
  formLayout->addRow( i18n("Pixels per time period:"), mHorizontalScale );
 
133
 
 
134
 
 
135
  pageLayout->addWidget( groupBox, 1, 0 );
 
136
 
 
137
  // Grid page
 
138
  page = new QFrame( );
 
139
  addPage( page, i18n( "Grid" ) );
 
140
  pageLayout = new QGridLayout( page );
 
141
  pageLayout->setSpacing( spacingHint() );
 
142
  pageLayout->setMargin( 0 );
 
143
 
 
144
  groupBox = new QGroupBox( i18n( "Lines" ), page );
 
145
  boxLayout = new QGridLayout;
 
146
  groupBox->setLayout( boxLayout );
 
147
  boxLayout->setSpacing( spacingHint() );
 
148
  boxLayout->setColumnStretch( 1, 1 );
 
149
 
 
150
  mShowVerticalLines = new QCheckBox( i18n( "Vertical lines" ), groupBox );
 
151
  mShowVerticalLines->setWhatsThis( i18n( "Check this to activate the vertical lines if display is large enough." ) );
 
152
  boxLayout->addWidget( mShowVerticalLines, 0, 0 );
 
153
 
 
154
  label = new QLabel( i18n( "Distance:" ), groupBox );
 
155
  boxLayout->addWidget( label, 0, 2 );
 
156
 
 
157
  mVerticalLinesDistance = new KIntNumInput( 0, groupBox );
 
158
  mVerticalLinesDistance->setMinimum( 10 );
 
159
  mVerticalLinesDistance->setMaximum( 120 );
 
160
  mVerticalLinesDistance->setWhatsThis( i18n( "Enter the distance between two vertical lines here." ) );
 
161
  boxLayout->addWidget( mVerticalLinesDistance , 0, 3 );
 
162
  label->setBuddy( mVerticalLinesDistance );
 
163
 
 
164
  mVerticalLinesScroll = new QCheckBox( i18n( "Vertical lines scroll" ), groupBox );
 
165
  boxLayout->addWidget( mVerticalLinesScroll, 1, 0, 1, -1 );
 
166
 
 
167
  mShowHorizontalLines = new QCheckBox( i18n( "Horizontal lines" ), groupBox );
 
168
  mShowHorizontalLines->setWhatsThis( i18n( "Check this to enable horizontal lines if display is large enough." ) );
 
169
  boxLayout->addWidget( mShowHorizontalLines, 2, 0, 1, -1 );
 
170
 
 
171
  pageLayout->addWidget( groupBox, 0, 0, 1, 2 );
 
172
 
 
173
  groupBox = new QGroupBox( i18n( "Text" ), page );
 
174
  boxLayout = new QGridLayout;
 
175
  groupBox->setLayout( boxLayout );
 
176
  boxLayout->setSpacing( spacingHint() );
 
177
  boxLayout->setColumnStretch( 1, 1 );
 
178
 
 
179
  mShowAxis = new QCheckBox( i18n( "Show axis labels" ), groupBox );
 
180
  mShowAxis->setWhatsThis( i18n( "Check this box if horizontal lines should be decorated with the values they mark." ) );
 
181
  boxLayout->addWidget( mShowAxis, 0, 0, 1, -1 );
 
182
 
 
183
  label = new QLabel( i18n( "Font size:" ), groupBox );
 
184
  boxLayout->addWidget( label, 1, 0 );
 
185
 
 
186
  mFontSize = new KIntNumInput( 8, groupBox );
 
187
  mFontSize->setMinimum( 1 );
 
188
  mFontSize->setMaximum( 1000 );
 
189
  boxLayout->addWidget( mFontSize, 1, 1 );
 
190
  label->setBuddy( mFontSize );
 
191
 
 
192
  pageLayout->addWidget( groupBox, 1, 0 );
 
193
 
 
194
  pageLayout->setRowStretch( 2, 1 );
 
195
 
 
196
  // Sensors page
 
197
  page = new QFrame( );
 
198
  addPage( page, i18n( "Sensors" ) );
 
199
  pageLayout = new QGridLayout( page );
 
200
  pageLayout->setSpacing( spacingHint() );
 
201
  pageLayout->setMargin( 0 );
 
202
  pageLayout->setRowStretch( 2, 1 );
 
203
  pageLayout->setRowStretch( 5, 1 );
 
204
 
 
205
  mView = new QTreeView( page );
 
206
  mView->header()->setStretchLastSection( false );
 
207
  mView->setRootIsDecorated( false );
 
208
  mView->setItemsExpandable( false );
 
209
  mView->setModel( mModel );
 
210
  mView->header()->setResizeMode(QHeaderView::ResizeToContents);
 
211
  bool hideFirstColumn = true;
 
212
  for(int i = 0; i < mModel->rowCount(); i++)
 
213
    if(mModel->data(mModel->index(i, 0)) != "localhost") {
 
214
      hideFirstColumn = false;
 
215
      break;
 
216
    }
 
217
  if(hideFirstColumn)
 
218
    mView->hideColumn(0);
 
219
 
 
220
  pageLayout->addWidget( mView, 0, 0, 6, 1 );
 
221
  connect(mView,SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(editSensor()));
 
222
 
 
223
  mEditButton = new QPushButton( i18n( "Set Color..." ), page );
 
224
  mEditButton->setWhatsThis( i18n( "Push this button to configure the color of the sensor in the diagram." ) );
 
225
  pageLayout->addWidget( mEditButton, 0, 1 );
 
226
 
 
227
  mRemoveButton = 0;
 
228
  mMoveUpButton = 0;
 
229
  mMoveDownButton = 0;
 
230
  if ( !locked ) {
 
231
    mRemoveButton = new QPushButton( i18n( "Delete" ), page );
 
232
    mRemoveButton->setWhatsThis( i18n( "Push this button to delete the sensor." ) );
 
233
    pageLayout->addWidget( mRemoveButton, 1, 1 );
 
234
    connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeSensor() ) );
 
235
 
 
236
    mMoveUpButton = new QPushButton( i18n( "Move Up" ), page );
 
237
    mMoveUpButton->setEnabled( false );
 
238
    pageLayout->addWidget( mMoveUpButton, 2, 1 );
 
239
    connect( mMoveUpButton, SIGNAL( clicked() ), SLOT( moveUpSensor() ) );
 
240
 
 
241
    mMoveDownButton = new QPushButton( i18n( "Move Down" ), page );
 
242
    mMoveDownButton->setEnabled( false );
 
243
    pageLayout->addWidget( mMoveDownButton, 3, 1 );
 
244
    connect( mMoveDownButton, SIGNAL( clicked() ), SLOT( moveDownSensor() ) );
 
245
 
 
246
    connect(mView->selectionModel(), SIGNAL(currentRowChanged( const QModelIndex &, const QModelIndex &)), this, SLOT( selectionChanged(const QModelIndex &)));
 
247
 
 
248
  }
 
249
 
 
250
  connect( mManualRange, SIGNAL( toggled( bool ) ), mMinValue,
 
251
           SLOT( setEnabled( bool ) ) );
 
252
  connect( mManualRange, SIGNAL( toggled( bool ) ), mMaxValue,
 
253
           SLOT( setEnabled( bool ) ) );
 
254
  connect( mManualRange, SIGNAL( toggled( bool ) ), mMinValueLabel,
 
255
           SLOT( setEnabled( bool ) ) );
 
256
  connect( mManualRange, SIGNAL( toggled( bool ) ), mMaxValueLabel,
 
257
           SLOT( setEnabled( bool ) ) );
 
258
 
 
259
  connect( mShowVerticalLines, SIGNAL( toggled( bool ) ), mVerticalLinesDistance,
 
260
           SLOT( setEnabled( bool ) ) );
 
261
  connect( mShowVerticalLines, SIGNAL( toggled( bool ) ), mVerticalLinesScroll,
 
262
           SLOT( setEnabled( bool ) ) );
 
263
 
 
264
  connect( mEditButton, SIGNAL( clicked() ), SLOT( editSensor() ) );
 
265
 
 
266
  KAcceleratorManager::manage( this );
 
267
}
 
268
 
 
269
FancyPlotterSettings::~FancyPlotterSettings()
 
270
{
 
271
}
 
272
 
 
273
void FancyPlotterSettings::setStackBeams( bool stack )
 
274
{
 
275
  mStackBeams->setChecked(stack);
 
276
}
 
277
bool FancyPlotterSettings::stackBeams() const {
 
278
  return mStackBeams->isChecked();
 
279
}
 
280
void FancyPlotterSettings::moveUpSensor()
 
281
{
 
282
  mModel->moveUpSensor(mView->selectionModel()->currentIndex());
 
283
  selectionChanged(mView->selectionModel()->currentIndex());
 
284
}
 
285
void FancyPlotterSettings::moveDownSensor()
 
286
{
 
287
  mModel->moveDownSensor(mView->selectionModel()->currentIndex());
 
288
  selectionChanged(mView->selectionModel()->currentIndex());
 
289
}
 
290
void FancyPlotterSettings::selectionChanged(const QModelIndex &newCurrent)
 
291
{
 
292
  mMoveUpButton->setEnabled(newCurrent.isValid() && newCurrent.row() > 0);
 
293
  mMoveDownButton->setEnabled(newCurrent.isValid() && newCurrent.row() < mModel->rowCount() -1 );
 
294
  mEditButton->setEnabled(newCurrent.isValid());
 
295
  mRemoveButton->setEnabled(newCurrent.isValid());
 
296
}
 
297
 
 
298
void FancyPlotterSettings::setTitle( const QString &title )
 
299
{
 
300
  mTitle->setText( title );
 
301
}
 
302
 
 
303
QString FancyPlotterSettings::title() const
 
304
{
 
305
  return mTitle->text();
 
306
}
 
307
 
 
308
void FancyPlotterSettings::setRangeUnits( const QString & units )
 
309
{
 
310
  mMinValue->setSuffix(' ' + units);
 
311
  mMaxValue->setSuffix(' ' + units);
 
312
}
 
313
 
 
314
void FancyPlotterSettings::setUseManualRange( bool value )
 
315
{
 
316
  mManualRange->setChecked( value );
 
317
}
 
318
 
 
319
bool FancyPlotterSettings::useManualRange() const
 
320
{
 
321
  return mManualRange->isChecked();
 
322
}
 
323
 
 
324
void FancyPlotterSettings::setMinValue( double min )
 
325
{
 
326
  mMinValue->setValue( min );
 
327
}
 
328
 
 
329
double FancyPlotterSettings::minValue() const
 
330
{
 
331
  return mMinValue->value();
 
332
}
 
333
 
 
334
void FancyPlotterSettings::setMaxValue( double max )
 
335
{
 
336
  mMaxValue->setValue( max );
 
337
}
 
338
 
 
339
void FancyPlotterSettings::setHasIntegerRange( bool hasIntegerRange )
 
340
{
 
341
    mMaxValue->setDecimals( hasIntegerRange?0:2 );
 
342
    mMinValue->setDecimals( hasIntegerRange?0:2 );
 
343
}
 
344
double FancyPlotterSettings::maxValue() const
 
345
{
 
346
  return mMaxValue->value();
 
347
}
 
348
 
 
349
void FancyPlotterSettings::setHorizontalScale( int scale )
 
350
{
 
351
  mHorizontalScale->setValue( scale );
 
352
}
 
353
 
 
354
int FancyPlotterSettings::horizontalScale() const
 
355
{
 
356
  return mHorizontalScale->value();
 
357
}
 
358
 
 
359
void FancyPlotterSettings::setShowVerticalLines( bool value )
 
360
{
 
361
  mShowVerticalLines->setChecked( value );
 
362
  mVerticalLinesDistance->setEnabled(  value );
 
363
  mVerticalLinesScroll->setEnabled( value );
 
364
}
 
365
 
 
366
bool FancyPlotterSettings::showVerticalLines() const
 
367
{
 
368
  return mShowVerticalLines->isChecked();
 
369
}
 
370
 
 
371
void FancyPlotterSettings::setVerticalLinesDistance( int distance )
 
372
{
 
373
  mVerticalLinesDistance->setValue( distance );
 
374
}
 
375
 
 
376
int FancyPlotterSettings::verticalLinesDistance() const
 
377
{
 
378
  return mVerticalLinesDistance->value();
 
379
}
 
380
 
 
381
void FancyPlotterSettings::setVerticalLinesScroll( bool value )
 
382
{
 
383
  mVerticalLinesScroll->setChecked( value );
 
384
}
 
385
 
 
386
bool FancyPlotterSettings::verticalLinesScroll() const
 
387
{
 
388
  return mVerticalLinesScroll->isChecked();
 
389
}
 
390
 
 
391
void FancyPlotterSettings::setShowHorizontalLines( bool value )
 
392
{
 
393
  mShowHorizontalLines->setChecked( value );
 
394
 
 
395
}
 
396
 
 
397
bool FancyPlotterSettings::showHorizontalLines() const
 
398
{
 
399
  return mShowHorizontalLines->isChecked();
 
400
}
 
401
 
 
402
void FancyPlotterSettings::setShowAxis( bool value )
 
403
{
 
404
  mShowAxis->setChecked( value );
 
405
}
 
406
 
 
407
bool FancyPlotterSettings::showAxis() const
 
408
{
 
409
  return mShowAxis->isChecked();
 
410
}
 
411
 
 
412
void FancyPlotterSettings::setShowTopBar( bool value )
 
413
{
 
414
  mShowTopBar->setChecked( value );
 
415
}
 
416
 
 
417
bool FancyPlotterSettings::showTopBar() const
 
418
{
 
419
  return mShowTopBar->isChecked();
 
420
}
 
421
 
 
422
void FancyPlotterSettings::setFontSize( int size )
 
423
{
 
424
  mFontSize->setValue( size );
 
425
}
 
426
 
 
427
int FancyPlotterSettings::fontSize() const
 
428
{
 
429
  return mFontSize->value();
 
430
}
 
431
void FancyPlotterSettings::setSensors( const SensorModelEntry::List &list )
 
432
{
 
433
  mModel->setSensors( list );
 
434
 
 
435
  mView->selectionModel()->setCurrentIndex( mModel->index( 0, 0 ), QItemSelectionModel::SelectCurrent |
 
436
                                                                   QItemSelectionModel::Rows );
 
437
}
 
438
 
 
439
SensorModelEntry::List FancyPlotterSettings::sensors() const
 
440
{
 
441
  return mModel->sensors();
 
442
}
 
443
 
 
444
void FancyPlotterSettings::editSensor()
 
445
{
 
446
  if ( !mView->selectionModel() )
 
447
    return;
 
448
 
 
449
  const QModelIndex index = mView->selectionModel()->currentIndex();
 
450
  if ( !index.isValid() )
 
451
    return;
 
452
 
 
453
  SensorModelEntry sensor = mModel->sensor( index );
 
454
 
 
455
  KColorDialog dialog(this, true);
 
456
  connect(&dialog, SIGNAL(colorSelected(const QColor &)), this, SLOT(setColorForSelectedItem(const QColor &)));
 
457
  QColor color = sensor.color();
 
458
  dialog.setColor(color);
 
459
  int result = dialog.exec();
 
460
 
 
461
  if ( result == KColorDialog::Accepted )
 
462
    sensor.setColor( dialog.color() );
 
463
  //If it's not accepted, make sure we set the color back to how it was
 
464
  mModel->setSensor( sensor, index );
 
465
}
 
466
 
 
467
void FancyPlotterSettings::setColorForSelectedItem(const QColor &color)
 
468
{
 
469
    const QModelIndex index = mView->selectionModel()->currentIndex();
 
470
    if ( !index.isValid() )
 
471
        return;
 
472
 
 
473
    SensorModelEntry sensor = mModel->sensor( index );
 
474
 
 
475
    sensor.setColor( color );
 
476
    mModel->setSensor( sensor, index );
 
477
}
 
478
 
 
479
void FancyPlotterSettings::removeSensor()
 
480
{
 
481
  if ( !mView->selectionModel() )
 
482
    return;
 
483
 
 
484
  const QModelIndex index = mView->selectionModel()->currentIndex();
 
485
  if ( !index.isValid() )
 
486
    return;
 
487
  mModel->removeSensor( index );
 
488
  selectionChanged( mView->selectionModel()->currentIndex() );
 
489
}
 
490
 
 
491
void FancyPlotterSettings::clearDeleted()
 
492
{
 
493
  mModel->clearDeleted();
 
494
}
 
495
 
 
496
QList<int> FancyPlotterSettings::deleted() const
 
497
{
 
498
  return mModel->deleted();
 
499
}
 
500
 
 
501
QList<int> FancyPlotterSettings::order() const
 
502
{
 
503
  return mModel->order();
 
504
}
 
505
 
 
506
void FancyPlotterSettings::resetOrder()
 
507
{
 
508
  mModel->resetOrder();
 
509
}
 
510
 
 
511
 
 
512
 
 
513
#include "FancyPlotterSettings.moc"