add more spacing
[personal-kdebase.git] / workspace / ksysguard / gui / SensorDisplayLib / FancyPlotterSettings.cc
blob07785e43b74fc6dfca0f6d56c4610a0af42040f4
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 <kcolordialog.h>
25 #include <klineedit.h>
26 #include <klocale.h>
27 #include <knuminput.h>
29 #include <QtCore/QAbstractTableModel>
30 #include <QtCore/QList>
31 #include <QtGui/QCheckBox>
32 #include <QtGui/QGridLayout>
33 #include <QtGui/QGroupBox>
34 #include <QtGui/QHeaderView>
35 #include <QtGui/QImage>
36 #include <QtGui/QLabel>
37 #include <QtGui/QLayout>
38 #include <QtGui/QPixmap>
39 #include <QtGui/QPushButton>
40 #include <QtGui/QTreeView>
41 #include <QDoubleValidator>
43 #include "FancyPlotterSettings.h"
45 FancyPlotterSettings::FancyPlotterSettings( QWidget* parent, bool locked )
46 : KPageDialog( parent ), mModel( new SensorModel( this ) )
48 setFaceType( Tabbed );
49 setCaption( i18n( "Signal Plotter Settings" ) );
50 setButtons( Ok | Apply | Cancel );
51 setObjectName( "FancyPlotterSettings" );
52 setModal( false );
53 showButtonSeparator( false );
55 QFrame *page = 0;
56 QGridLayout *pageLayout = 0;
57 QGridLayout *boxLayout = 0;
58 QGroupBox *groupBox = 0;
59 QLabel *label = 0;
61 // Style page
62 page = new QFrame();
63 addPage( page, i18n( "General" ) );
64 pageLayout = new QGridLayout( page );
65 pageLayout->setSpacing( spacingHint() );
66 pageLayout->setMargin( 0 );
68 label = new QLabel( i18n( "Title:" ), page );
69 pageLayout->addWidget( label, 0, 0 );
71 mTitle = new KLineEdit( page );
72 mTitle->setWhatsThis( i18n( "Enter the title of the display here." ) );
73 pageLayout->addWidget( mTitle, 0, 1 );
74 label->setBuddy( mTitle );
76 mStackBeams = new QCheckBox( i18n("Stack the beams on top of each other"), page);
77 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.") );
78 pageLayout->addWidget( mStackBeams, 1, 0,1,2);
80 pageLayout->setRowStretch( 2, 1 );
82 // Scales page
83 page = new QFrame();
84 addPage( page, i18n( "Scales" ) );
85 pageLayout = new QGridLayout( page );
86 pageLayout->setSpacing( spacingHint() );
87 pageLayout->setMargin( 0 );
89 groupBox = new QGroupBox( i18n( "Vertical Scale" ), page );
90 boxLayout = new QGridLayout;
91 groupBox->setLayout( boxLayout );
92 boxLayout->setSpacing( spacingHint() );
93 boxLayout->setColumnStretch( 2, 1 );
95 mUseAutoRange = new QCheckBox( i18n( "Automatic range detection" ), groupBox );
96 mUseAutoRange->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." ) );
97 boxLayout->addWidget( mUseAutoRange, 0, 0, 1, 5 );
99 label = new QLabel( i18n( "Minimum value:" ), groupBox );
100 boxLayout->addWidget( label, 1, 0 );
102 mMinValue = new KLineEdit( groupBox );
103 mMinValue->setValidator(new QDoubleValidator(mMinValue));
104 mMinValue->setAlignment( Qt::AlignRight );
105 mMinValue->setEnabled( false );
106 mMinValue->setWhatsThis( i18n( "Enter the minimum value for the display here. If both values are 0, automatic range detection is enabled." ) );
107 boxLayout->addWidget( mMinValue, 1, 1 );
108 label->setBuddy( mMinValue );
110 label = new QLabel( i18n( "Maximum value:" ), groupBox );
111 boxLayout->addWidget( label, 1, 3 );
113 mMaxValue = new KLineEdit( groupBox );
114 mMaxValue->setAlignment( Qt::AlignRight );
115 mMaxValue->setValidator(new QDoubleValidator(mMaxValue));
116 mMaxValue->setEnabled( false );
117 mMaxValue->setWhatsThis( i18n( "Enter the maximum value for the display here. If both values are 0, automatic range detection is enabled." ) );
118 boxLayout->addWidget( mMaxValue, 1, 4 );
119 label->setBuddy( mMaxValue );
121 pageLayout->addWidget( groupBox, 0, 0 );
123 groupBox = new QGroupBox( i18n( "Horizontal Scale" ), page );
124 boxLayout = new QGridLayout;
125 groupBox->setLayout( boxLayout );
126 boxLayout->setSpacing( spacingHint() );
127 boxLayout->setRowStretch( 1, 1 );
129 mHorizontalScale = new KIntNumInput( 1, groupBox );
130 mHorizontalScale->setMinimum( 1 );
131 mHorizontalScale->setMaximum( 50 );
132 boxLayout->addWidget( mHorizontalScale, 0, 0 );
134 label = new QLabel( i18n( "pixels per time period" ), groupBox );
135 boxLayout->addWidget( label, 0, 1 );
137 pageLayout->addWidget( groupBox, 1, 0 );
139 // Grid page
140 page = new QFrame( );
141 addPage( page, i18n( "Grid" ) );
142 pageLayout = new QGridLayout( page );
143 pageLayout->setSpacing( spacingHint() );
144 pageLayout->setMargin( 0 );
146 groupBox = new QGroupBox( i18n( "Lines" ), page );
147 boxLayout = new QGridLayout;
148 groupBox->setLayout( boxLayout );
149 boxLayout->setSpacing( spacingHint() );
150 boxLayout->setColumnStretch( 1, 1 );
152 mShowVerticalLines = new QCheckBox( i18n( "Vertical lines" ), groupBox );
153 mShowVerticalLines->setWhatsThis( i18n( "Check this to activate the vertical lines if display is large enough." ) );
154 boxLayout->addWidget( mShowVerticalLines, 0, 0 );
156 label = new QLabel( i18n( "Distance:" ), groupBox );
157 boxLayout->addWidget( label, 0, 2 );
159 mVerticalLinesDistance = new KIntNumInput( 0, groupBox );
160 mVerticalLinesDistance->setMinimum( 10 );
161 mVerticalLinesDistance->setMaximum( 120 );
162 mVerticalLinesDistance->setWhatsThis( i18n( "Enter the distance between two vertical lines here." ) );
163 boxLayout->addWidget( mVerticalLinesDistance , 0, 3 );
164 label->setBuddy( mVerticalLinesDistance );
166 mVerticalLinesScroll = new QCheckBox( i18n( "Vertical lines scroll" ), groupBox );
167 boxLayout->addWidget( mVerticalLinesScroll, 1, 0, 1, -1 );
169 mShowHorizontalLines = new QCheckBox( i18n( "Horizontal lines" ), groupBox );
170 mShowHorizontalLines->setWhatsThis( i18n( "Check this to enable horizontal lines if display is large enough." ) );
171 boxLayout->addWidget( mShowHorizontalLines, 2, 0, 1, -1 );
173 pageLayout->addWidget( groupBox, 0, 0, 1, 2 );
175 groupBox = new QGroupBox( i18n( "Text" ), page );
176 boxLayout = new QGridLayout;
177 groupBox->setLayout( boxLayout );
178 boxLayout->setSpacing( spacingHint() );
179 boxLayout->setColumnStretch( 1, 1 );
181 mShowAxis = new QCheckBox( i18n( "Show axis labels" ), groupBox );
182 mShowAxis->setWhatsThis( i18n( "Check this box if horizontal lines should be decorated with the values they mark." ) );
183 boxLayout->addWidget( mShowAxis, 0, 0, 1, -1 );
185 label = new QLabel( i18n( "Font size:" ), groupBox );
186 boxLayout->addWidget( label, 1, 0 );
188 mFontSize = new KIntNumInput( 8, groupBox );
189 mFontSize->setMinimum( 5 );
190 mFontSize->setMaximum( 24 );
191 boxLayout->addWidget( mFontSize, 1, 1 );
192 label->setBuddy( mFontSize );
194 mShowTopBar = new QCheckBox( i18n( "Top bar" ), groupBox );
195 mShowTopBar->setWhatsThis( i18n( "Check this to active the display title bar. This is probably only useful for applet displays. The bar is only visible if the display is large enough." ) );
196 boxLayout->addWidget( mShowTopBar, 1, 0 );
198 boxLayout->setRowStretch( 2, 1 );
200 pageLayout->addWidget( groupBox, 1, 0 );
202 groupBox = new QGroupBox( i18n( "Colors" ), page );
203 boxLayout = new QGridLayout;
204 groupBox->setLayout( boxLayout );
205 boxLayout->setSpacing( spacingHint() );
207 label = new QLabel( i18n( "Font:" ), groupBox );
208 boxLayout->addWidget( label, 0, 0 );
209 mFontColor = new KColorButton( groupBox );
210 boxLayout->addWidget( mFontColor, 0, 1 );
211 label->setBuddy( mFontColor );
214 label = new QLabel( i18n( "Grid lines:" ), groupBox );
215 boxLayout->addWidget( label, 1, 0 );
216 mGridLinesColor = new KColorButton( groupBox );
217 boxLayout->addWidget( mGridLinesColor, 1, 1 );
218 label->setBuddy( mGridLinesColor );
220 label = new QLabel( i18n( "Background:" ), groupBox );
221 boxLayout->addWidget( label, 2, 0 );
223 mBackgroundColor = new KColorButton( groupBox );
224 boxLayout->addWidget( mBackgroundColor, 2, 1 );
225 label->setBuddy( mBackgroundColor );
227 boxLayout->setRowStretch( 3, 1 );
229 pageLayout->addWidget( groupBox, 1, 1 );
231 pageLayout->setRowStretch( 2, 1 );
233 // Sensors page
234 page = new QFrame( );
235 addPage( page, i18n( "Sensors" ) );
236 pageLayout = new QGridLayout( page );
237 pageLayout->setSpacing( spacingHint() );
238 pageLayout->setMargin( 0 );
239 pageLayout->setRowStretch( 2, 1 );
240 pageLayout->setRowStretch( 5, 1 );
242 mView = new QTreeView( page );
243 mView->header()->setStretchLastSection( true );
244 mView->setRootIsDecorated( false );
245 mView->setItemsExpandable( false );
246 mView->setModel( mModel );
247 pageLayout->addWidget( mView, 0, 0, 6, 1 );
248 connect(mView,SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(editSensor()));
250 mEditButton = new QPushButton( i18n( "Set Color..." ), page );
251 mEditButton->setWhatsThis( i18n( "Push this button to configure the color of the sensor in the diagram." ) );
252 pageLayout->addWidget( mEditButton, 0, 1 );
254 mRemoveButton = 0;
255 mMoveUpButton = 0;
256 mMoveDownButton = 0;
257 if ( !locked ) {
258 mRemoveButton = new QPushButton( i18n( "Delete" ), page );
259 mRemoveButton->setWhatsThis( i18n( "Push this button to delete the sensor." ) );
260 pageLayout->addWidget( mRemoveButton, 1, 1 );
261 connect( mRemoveButton, SIGNAL( clicked() ), SLOT( removeSensor() ) );
263 mMoveUpButton = new QPushButton( i18n( "Move Up" ), page );
264 mMoveUpButton->setEnabled( false );
265 pageLayout->addWidget( mMoveUpButton, 2, 1 );
266 connect( mMoveUpButton, SIGNAL( clicked() ), SLOT( moveUpSensor() ) );
268 mMoveDownButton = new QPushButton( i18n( "Move Down" ), page );
269 mMoveDownButton->setEnabled( false );
270 pageLayout->addWidget( mMoveDownButton, 3, 1 );
271 connect( mMoveDownButton, SIGNAL( clicked() ), SLOT( moveDownSensor() ) );
273 connect(mView->selectionModel(), SIGNAL(currentRowChanged( const QModelIndex &, const QModelIndex &)), this, SLOT( selectionChanged(const QModelIndex &)));
277 connect( mUseAutoRange, SIGNAL( toggled( bool ) ), mMinValue,
278 SLOT( setDisabled( bool ) ) );
279 connect( mUseAutoRange, SIGNAL( toggled( bool ) ), mMaxValue,
280 SLOT( setDisabled( bool ) ) );
281 connect( mShowVerticalLines, SIGNAL( toggled( bool ) ), mVerticalLinesDistance,
282 SLOT( setEnabled( bool ) ) );
283 connect( mShowVerticalLines, SIGNAL( toggled( bool ) ), mVerticalLinesScroll,
284 SLOT( setEnabled( bool ) ) );
286 connect( mEditButton, SIGNAL( clicked() ), SLOT( editSensor() ) );
288 KAcceleratorManager::manage( this );
291 FancyPlotterSettings::~FancyPlotterSettings()
295 void FancyPlotterSettings::setStackBeams( bool stack )
297 mStackBeams->setChecked(stack);
299 bool FancyPlotterSettings::stackBeams() const {
300 return mStackBeams->isChecked();
302 void FancyPlotterSettings::moveUpSensor()
304 mModel->moveUpSensor(mView->selectionModel()->currentIndex());
305 selectionChanged(mView->selectionModel()->currentIndex());
307 void FancyPlotterSettings::moveDownSensor()
309 mModel->moveDownSensor(mView->selectionModel()->currentIndex());
310 selectionChanged(mView->selectionModel()->currentIndex());
312 void FancyPlotterSettings::selectionChanged(const QModelIndex &newCurrent)
314 mMoveUpButton->setEnabled(newCurrent.isValid() && newCurrent.row() > 0);
315 mMoveDownButton->setEnabled(newCurrent.isValid() && newCurrent.row() < mModel->rowCount() -1 );
316 mEditButton->setEnabled(newCurrent.isValid());
317 mRemoveButton->setEnabled(newCurrent.isValid());
320 void FancyPlotterSettings::setTitle( const QString &title )
322 mTitle->setText( title );
325 QString FancyPlotterSettings::title() const
327 return mTitle->text();
330 void FancyPlotterSettings::setUseAutoRange( bool value )
332 mUseAutoRange->setChecked( value );
333 mMinValue->setEnabled( !value );
334 mMaxValue->setEnabled( !value );
337 bool FancyPlotterSettings::useAutoRange() const
339 return mUseAutoRange->isChecked();
342 void FancyPlotterSettings::setMinValue( double min )
344 mMinValue->setText( QString::number( min ) );
347 double FancyPlotterSettings::minValue() const
349 return mMinValue->text().toDouble();
352 void FancyPlotterSettings::setMaxValue( double max )
354 mMaxValue->setText( QString::number( max ) );
357 double FancyPlotterSettings::maxValue() const
359 return mMaxValue->text().toDouble();
362 void FancyPlotterSettings::setHorizontalScale( int scale )
364 mHorizontalScale->setValue( scale );
367 int FancyPlotterSettings::horizontalScale() const
369 return mHorizontalScale->value();
372 void FancyPlotterSettings::setShowVerticalLines( bool value )
374 mShowVerticalLines->setChecked( value );
375 mVerticalLinesDistance->setEnabled( value );
376 mVerticalLinesScroll->setEnabled( value );
379 bool FancyPlotterSettings::showVerticalLines() const
381 return mShowVerticalLines->isChecked();
384 void FancyPlotterSettings::setGridLinesColor( const QColor &color )
386 mGridLinesColor->setColor( color );
389 QColor FancyPlotterSettings::gridLinesColor() const
391 return mGridLinesColor->color();
394 void FancyPlotterSettings::setVerticalLinesDistance( int distance )
396 mVerticalLinesDistance->setValue( distance );
399 int FancyPlotterSettings::verticalLinesDistance() const
401 return mVerticalLinesDistance->value();
404 void FancyPlotterSettings::setVerticalLinesScroll( bool value )
406 mVerticalLinesScroll->setChecked( value );
409 bool FancyPlotterSettings::verticalLinesScroll() const
411 return mVerticalLinesScroll->isChecked();
414 void FancyPlotterSettings::setShowHorizontalLines( bool value )
416 mShowHorizontalLines->setChecked( value );
420 bool FancyPlotterSettings::showHorizontalLines() const
422 return mShowHorizontalLines->isChecked();
425 void FancyPlotterSettings::setShowAxis( bool value )
427 mShowAxis->setChecked( value );
430 bool FancyPlotterSettings::showAxis() const
432 return mShowAxis->isChecked();
435 void FancyPlotterSettings::setShowTopBar( bool value )
437 mShowTopBar->setChecked( value );
440 bool FancyPlotterSettings::showTopBar() const
442 return mShowTopBar->isChecked();
445 void FancyPlotterSettings::setFontSize( int size )
447 mFontSize->setValue( size );
450 int FancyPlotterSettings::fontSize() const
452 return mFontSize->value();
454 void FancyPlotterSettings::setFontColor( const QColor &color )
456 mFontColor->setColor( color );
459 QColor FancyPlotterSettings::fontColor() const
461 return mFontColor->color();
463 void FancyPlotterSettings::setBackgroundColor( const QColor &color )
465 mBackgroundColor->setColor( color );
468 QColor FancyPlotterSettings::backgroundColor() const
470 return mBackgroundColor->color();
473 void FancyPlotterSettings::setSensors( const SensorModelEntry::List &list )
475 mModel->setSensors( list );
477 mView->selectionModel()->setCurrentIndex( mModel->index( 0, 0 ), QItemSelectionModel::SelectCurrent |
478 QItemSelectionModel::Rows );
481 SensorModelEntry::List FancyPlotterSettings::sensors() const
483 return mModel->sensors();
486 void FancyPlotterSettings::editSensor()
488 if ( !mView->selectionModel() )
489 return;
491 const QModelIndex index = mView->selectionModel()->currentIndex();
492 if ( !index.isValid() )
493 return;
495 SensorModelEntry sensor = mModel->sensor( index );
497 QColor color = sensor.color();
498 int result = KColorDialog::getColor( color, parentWidget() );
499 if ( result == KColorDialog::Accepted ) {
500 sensor.setColor( color );
501 mModel->setSensor( sensor, index );
505 void FancyPlotterSettings::removeSensor()
507 if ( !mView->selectionModel() )
508 return;
510 const QModelIndex index = mView->selectionModel()->currentIndex();
511 if ( !index.isValid() )
512 return;
513 mModel->removeSensor( index );
514 selectionChanged( mView->selectionModel()->currentIndex() );
517 void FancyPlotterSettings::clearDeleted()
519 mModel->clearDeleted();
522 QList<int> FancyPlotterSettings::deleted() const
524 return mModel->deleted();
527 QList<int> FancyPlotterSettings::order() const
529 return mModel->order();
532 void FancyPlotterSettings::resetOrder()
534 mModel->resetOrder();
539 #include "FancyPlotterSettings.moc"