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 <kcolordialog.h>
24
#include <klineedit.h>
26
#include <knuminput.h>
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>
45
#include "FancyPlotterSettings.h"
47
FancyPlotterSettings::FancyPlotterSettings( QWidget* parent, bool locked )
48
: KPageDialog( parent ), mModel( new SensorModel( this ) )
50
setFaceType( Tabbed );
51
setCaption( i18n( "Plotter Settings" ) );
52
setButtons( Ok | Apply | Cancel );
53
setObjectName( "FancyPlotterSettings" );
57
QGridLayout *pageLayout = 0;
58
QGridLayout *boxLayout = 0;
59
QGroupBox *groupBox = 0;
64
addPage( page, i18n( "General" ) );
65
pageLayout = new QGridLayout( page );
66
pageLayout->setSpacing( spacingHint() );
67
pageLayout->setMargin( 0 );
69
label = new QLabel( i18n( "Title:" ), page );
70
pageLayout->addWidget( label, 0, 0 );
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 );
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);
81
pageLayout->setRowStretch( 2, 1 );
85
addPage( page, i18n( "Scales" ) );
86
pageLayout = new QGridLayout( page );
87
pageLayout->setSpacing( spacingHint() );
88
pageLayout->setMargin( 0 );
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 );
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 );
101
mMinValueLabel = new QLabel( i18n( "Minimum value:" ), groupBox );
102
boxLayout->addWidget( mMinValueLabel, 1, 0 );
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 );
112
mMaxValueLabel = new QLabel( i18n( "Maximum value:" ), groupBox );
113
boxLayout->addWidget( mMaxValueLabel, 1, 3 );
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 );
123
pageLayout->addWidget( groupBox, 0, 0 );
125
groupBox = new QGroupBox( i18n( "Horizontal scale" ), page );
126
QFormLayout *formLayout = new QFormLayout(groupBox);
128
mHorizontalScale = new KIntNumInput( 1, groupBox );
129
mHorizontalScale->setMinimum( 1 );
130
mHorizontalScale->setMaximum( 50 );
132
formLayout->addRow( i18n("Pixels per time period:"), mHorizontalScale );
135
pageLayout->addWidget( groupBox, 1, 0 );
138
page = new QFrame( );
139
addPage( page, i18n( "Grid" ) );
140
pageLayout = new QGridLayout( page );
141
pageLayout->setSpacing( spacingHint() );
142
pageLayout->setMargin( 0 );
144
groupBox = new QGroupBox( i18n( "Lines" ), page );
145
boxLayout = new QGridLayout;
146
groupBox->setLayout( boxLayout );
147
boxLayout->setSpacing( spacingHint() );
148
boxLayout->setColumnStretch( 1, 1 );
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 );
154
label = new QLabel( i18n( "Distance:" ), groupBox );
155
boxLayout->addWidget( label, 0, 2 );
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 );
164
mVerticalLinesScroll = new QCheckBox( i18n( "Vertical lines scroll" ), groupBox );
165
boxLayout->addWidget( mVerticalLinesScroll, 1, 0, 1, -1 );
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 );
171
pageLayout->addWidget( groupBox, 0, 0, 1, 2 );
173
groupBox = new QGroupBox( i18n( "Text" ), page );
174
boxLayout = new QGridLayout;
175
groupBox->setLayout( boxLayout );
176
boxLayout->setSpacing( spacingHint() );
177
boxLayout->setColumnStretch( 1, 1 );
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 );
183
label = new QLabel( i18n( "Font size:" ), groupBox );
184
boxLayout->addWidget( label, 1, 0 );
186
mFontSize = new KIntNumInput( 8, groupBox );
187
mFontSize->setMinimum( 1 );
188
mFontSize->setMaximum( 1000 );
189
boxLayout->addWidget( mFontSize, 1, 1 );
190
label->setBuddy( mFontSize );
192
pageLayout->addWidget( groupBox, 1, 0 );
194
pageLayout->setRowStretch( 2, 1 );
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 );
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;
218
mView->hideColumn(0);
220
pageLayout->addWidget( mView, 0, 0, 6, 1 );
221
connect(mView,SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(editSensor()));
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 );
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() ) );
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() ) );
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() ) );
246
connect(mView->selectionModel(), SIGNAL(currentRowChanged( const QModelIndex &, const QModelIndex &)), this, SLOT( selectionChanged(const QModelIndex &)));
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 ) ) );
259
connect( mShowVerticalLines, SIGNAL( toggled( bool ) ), mVerticalLinesDistance,
260
SLOT( setEnabled( bool ) ) );
261
connect( mShowVerticalLines, SIGNAL( toggled( bool ) ), mVerticalLinesScroll,
262
SLOT( setEnabled( bool ) ) );
264
connect( mEditButton, SIGNAL( clicked() ), SLOT( editSensor() ) );
266
KAcceleratorManager::manage( this );
269
FancyPlotterSettings::~FancyPlotterSettings()
273
void FancyPlotterSettings::setStackBeams( bool stack )
275
mStackBeams->setChecked(stack);
277
bool FancyPlotterSettings::stackBeams() const {
278
return mStackBeams->isChecked();
280
void FancyPlotterSettings::moveUpSensor()
282
mModel->moveUpSensor(mView->selectionModel()->currentIndex());
283
selectionChanged(mView->selectionModel()->currentIndex());
285
void FancyPlotterSettings::moveDownSensor()
287
mModel->moveDownSensor(mView->selectionModel()->currentIndex());
288
selectionChanged(mView->selectionModel()->currentIndex());
290
void FancyPlotterSettings::selectionChanged(const QModelIndex &newCurrent)
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());
298
void FancyPlotterSettings::setTitle( const QString &title )
300
mTitle->setText( title );
303
QString FancyPlotterSettings::title() const
305
return mTitle->text();
308
void FancyPlotterSettings::setRangeUnits( const QString & units )
310
mMinValue->setSuffix(' ' + units);
311
mMaxValue->setSuffix(' ' + units);
314
void FancyPlotterSettings::setUseManualRange( bool value )
316
mManualRange->setChecked( value );
319
bool FancyPlotterSettings::useManualRange() const
321
return mManualRange->isChecked();
324
void FancyPlotterSettings::setMinValue( double min )
326
mMinValue->setValue( min );
329
double FancyPlotterSettings::minValue() const
331
return mMinValue->value();
334
void FancyPlotterSettings::setMaxValue( double max )
336
mMaxValue->setValue( max );
339
void FancyPlotterSettings::setHasIntegerRange( bool hasIntegerRange )
341
mMaxValue->setDecimals( hasIntegerRange?0:2 );
342
mMinValue->setDecimals( hasIntegerRange?0:2 );
344
double FancyPlotterSettings::maxValue() const
346
return mMaxValue->value();
349
void FancyPlotterSettings::setHorizontalScale( int scale )
351
mHorizontalScale->setValue( scale );
354
int FancyPlotterSettings::horizontalScale() const
356
return mHorizontalScale->value();
359
void FancyPlotterSettings::setShowVerticalLines( bool value )
361
mShowVerticalLines->setChecked( value );
362
mVerticalLinesDistance->setEnabled( value );
363
mVerticalLinesScroll->setEnabled( value );
366
bool FancyPlotterSettings::showVerticalLines() const
368
return mShowVerticalLines->isChecked();
371
void FancyPlotterSettings::setVerticalLinesDistance( int distance )
373
mVerticalLinesDistance->setValue( distance );
376
int FancyPlotterSettings::verticalLinesDistance() const
378
return mVerticalLinesDistance->value();
381
void FancyPlotterSettings::setVerticalLinesScroll( bool value )
383
mVerticalLinesScroll->setChecked( value );
386
bool FancyPlotterSettings::verticalLinesScroll() const
388
return mVerticalLinesScroll->isChecked();
391
void FancyPlotterSettings::setShowHorizontalLines( bool value )
393
mShowHorizontalLines->setChecked( value );
397
bool FancyPlotterSettings::showHorizontalLines() const
399
return mShowHorizontalLines->isChecked();
402
void FancyPlotterSettings::setShowAxis( bool value )
404
mShowAxis->setChecked( value );
407
bool FancyPlotterSettings::showAxis() const
409
return mShowAxis->isChecked();
412
void FancyPlotterSettings::setShowTopBar( bool value )
414
mShowTopBar->setChecked( value );
417
bool FancyPlotterSettings::showTopBar() const
419
return mShowTopBar->isChecked();
422
void FancyPlotterSettings::setFontSize( int size )
424
mFontSize->setValue( size );
427
int FancyPlotterSettings::fontSize() const
429
return mFontSize->value();
431
void FancyPlotterSettings::setSensors( const SensorModelEntry::List &list )
433
mModel->setSensors( list );
435
mView->selectionModel()->setCurrentIndex( mModel->index( 0, 0 ), QItemSelectionModel::SelectCurrent |
436
QItemSelectionModel::Rows );
439
SensorModelEntry::List FancyPlotterSettings::sensors() const
441
return mModel->sensors();
444
void FancyPlotterSettings::editSensor()
446
if ( !mView->selectionModel() )
449
const QModelIndex index = mView->selectionModel()->currentIndex();
450
if ( !index.isValid() )
453
SensorModelEntry sensor = mModel->sensor( index );
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();
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 );
467
void FancyPlotterSettings::setColorForSelectedItem(const QColor &color)
469
const QModelIndex index = mView->selectionModel()->currentIndex();
470
if ( !index.isValid() )
473
SensorModelEntry sensor = mModel->sensor( index );
475
sensor.setColor( color );
476
mModel->setSensor( sensor, index );
479
void FancyPlotterSettings::removeSensor()
481
if ( !mView->selectionModel() )
484
const QModelIndex index = mView->selectionModel()->currentIndex();
485
if ( !index.isValid() )
487
mModel->removeSensor( index );
488
selectionChanged( mView->selectionModel()->currentIndex() );
491
void FancyPlotterSettings::clearDeleted()
493
mModel->clearDeleted();
496
QList<int> FancyPlotterSettings::deleted() const
498
return mModel->deleted();
501
QList<int> FancyPlotterSettings::order() const
503
return mModel->order();
506
void FancyPlotterSettings::resetOrder()
508
mModel->resetOrder();
513
#include "FancyPlotterSettings.moc"