moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kmplot / kmplot / ksliderwindow.cpp
blobda38dc84ab88a590b68a35ee2505a6733182cd41
1 /*
2 * KmPlot - a math. function plotter for the KDE-Desktop
4 * Copyright (C) 2005 Fredrik Edemar
5 * f_edemar@linux.se
7 * This file is part of the KDE Project.
8 * KmPlot is part of the KDE-EDU Project.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 // Qt includes
26 #include <qcursor.h>
27 #include <qslider.h>
28 #include <qtooltip.h>
29 #include <qwhatsthis.h>
31 // KDE includes
32 #include <kaction.h>
33 #include <kconfig.h>
34 #include <kdebug.h>
35 #include <kinputdialog.h>
36 #include <klocale.h>
38 #include <limits.h>
39 #include <math.h>
40 #include <stdlib.h>
42 // local includes
43 #include "ksliderwindow.h"
45 KSliderWindow::KSliderWindow(QWidget* parent, int num ) :
46 SliderWindow( parent, "", false, Qt::WStyle_Tool-Qt::WStyle_Maximize ), m_num(num)
48 setCaption(i18n( "Slider %1" ).arg( num+1 ) );
49 QToolTip::add( slider, i18n( "Slider no. %1" ).arg( num+1 ));
50 QWhatsThis::add( this, i18n( "Move slider to change the parameter of the function plot connected to this slider." ) );
52 // load the min and max value + the current value
53 KConfig config( "kmplotrc" );
54 config.setGroup( "slider" + QString::number(num) );
55 slider->setMinValue( config.readNumEntry( "min", 0) );
56 slider->setMaxValue( config.readNumEntry( "max", 100) );
57 slider->setValue( config.readNumEntry( "value", 50) );
58 slider->setPageStep( (int)ceil((abs(slider->minValue()) + abs(slider->maxValue()))/10.) );
60 slider->installEventFilter(this);
61 installEventFilter(this);
63 m_popupmenu = new KPopupMenu(this);
64 KAction *mnuMinValue = new KAction(i18n("&Change minimum value") ,0,this, SLOT( mnuMinValue_clicked() ),0);
65 mnuMinValue->plug(m_popupmenu);
66 KAction *mnuMaxValue = new KAction(i18n("&Change maximum value") ,0,this, SLOT( mnuMaxValue_clicked() ),0 );
67 mnuMaxValue->plug(m_popupmenu);
70 KSliderWindow::~KSliderWindow()
72 // save the min and max value + the current value
73 KConfig config( "kmplotrc" );
74 config.setGroup( "slider" + QString::number(m_num) );
75 config.writeEntry( "min", slider->minValue() );
76 config.writeEntry( "max", slider->maxValue() );
77 config.writeEntry( "value", slider->value() );
80 bool KSliderWindow::eventFilter( QObject *obj, QEvent *ev )
82 if (ev->type() == QEvent::MouseButtonPress)
84 QMouseEvent *e = (QMouseEvent *)ev;
85 if (e->button() != Qt::RightButton)
86 return SliderWindow::eventFilter( obj, ev );
87 m_popupmenu->exec(QCursor::pos());
88 return true;
90 return SliderWindow::eventFilter( obj, ev );
93 void KSliderWindow::closeEvent( QCloseEvent * e)
95 emit windowClosed(m_num);
96 e->accept();
99 void KSliderWindow::mnuMinValue_clicked()
101 bool ok;
102 int const result = KInputDialog::getInteger(i18n("Change minimum value"), i18n("Type a new minimum value for the slider:"), slider->minValue(), INT_MIN, INT_MAX, 1, 10, &ok);
103 if (!ok)
104 return;
105 slider->setMinValue(result);
106 slider->setPageStep( (int)ceil((abs(slider->maxValue()) + abs(result))/10.) );
107 setFocus();
110 void KSliderWindow::mnuMaxValue_clicked()
112 bool ok;
113 int const result = KInputDialog::getInteger(i18n("Change maximum value"), i18n("Type a new maximum value for the slider:"), slider->maxValue(), INT_MIN, INT_MAX, 1, 10, &ok);
114 if (!ok)
115 return;
116 slider->setMaxValue(result);
117 slider->setPageStep( (int)ceil((abs(slider->minValue()) + abs(result))/10.) );
118 setFocus();
121 #include "ksliderwindow.moc"