krita

kis_double_widget.cc

00001 /*
00002  *  kis_double_widget.cc - part of Krita
00003  *
00004  *  Copyright (c) 1999 Carsten Pfeiffer <pfeiffer@kde.org>
00005  *  Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  */
00021 
00022 #include <qhbox.h>
00023 #include <qlayout.h>
00024 #include <qslider.h>
00025 
00026 #include <knuminput.h>
00027 
00028 #include "kis_double_widget.h"
00029 
00030 KisDoubleWidget::KisDoubleWidget(QWidget* parent, const char* name)
00031   : super(parent, name)
00032 {
00033     init(0, 1);
00034 }
00035 
00036 KisDoubleWidget::KisDoubleWidget(double min, double max, QWidget* parent, const char* name)
00037   : super(parent, name)
00038 {
00039     init(min, max);
00040 }
00041 
00042 KisDoubleWidget::~KisDoubleWidget()
00043 {
00044 }
00045 
00046 void KisDoubleWidget::init(double min, double max)
00047 {
00048     m_spinBox = new KDoubleSpinBox(min, max, 0.05, 0, 2, this, "spinbox");
00049     connect(m_spinBox, SIGNAL(valueChanged(double)), this, SLOT(setSliderValue(double)));
00050 
00051     m_slider = new QSlider(static_cast<int>(min * 100 + 0.5), static_cast<int>(max * 100 + 0.5), 1, 0, QSlider::Horizontal, this, "sld");
00052     connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(sliderValueChanged(int)));
00053     connect(m_slider, SIGNAL(sliderPressed()), SIGNAL(sliderPressed()));
00054     connect(m_slider, SIGNAL(sliderReleased()), SIGNAL(sliderReleased()));
00055 
00056     m_layout = new QHBoxLayout(this, 0, -1, "hbox layout");
00057 
00058     m_layout->addWidget(m_slider);
00059     m_layout->addSpacing(5);
00060     m_layout->addWidget(m_spinBox);
00061     m_layout->addItem(new QSpacerItem(5,1,QSizePolicy::Expanding, QSizePolicy::Minimum));
00062 }
00063 
00064 double KisDoubleWidget::value() const
00065 {
00066     return m_spinBox->value();
00067 }
00068 
00069 void KisDoubleWidget::setValue(double value)
00070 {
00071     int intValue;
00072 
00073     if (value < 0) {
00074         intValue = static_cast<int>(value * 100 - 0.5);
00075     } else {
00076         intValue = static_cast<int>(value * 100 + 0.5);
00077     }
00078     m_slider->setValue(intValue);
00079 }
00080 
00081 void KisDoubleWidget::setRange(double min, double max)
00082 {
00083     m_spinBox->setRange(min, max);
00084     m_slider->setRange(static_cast<int>(min * 100 + 0.5), static_cast<int>(max * 100 + 0.5));
00085 }
00086 
00087 void KisDoubleWidget::setTickmarks(QSlider::TickSetting tickSetting)
00088 {
00089     m_slider->setTickmarks(tickSetting);
00090 }
00091 
00092 void KisDoubleWidget::setTickInterval(double value)
00093 {
00094     m_slider->setTickInterval(static_cast<int>(value * 100 + 0.5));
00095 }
00096 
00097 double KisDoubleWidget::tickInterval() const
00098 {
00099     return m_slider->tickInterval() / 100.0;
00100 }
00101 
00102 void KisDoubleWidget::setSliderValue(double value)
00103 {
00104     int intValue;
00105 
00106     if (value < 0) {
00107         intValue = static_cast<int>(value * 100 - 0.5);
00108     } else {
00109         intValue = static_cast<int>(value * 100 + 0.5);
00110     }
00111     m_slider->setValue(intValue);
00112     emit valueChanged(value);
00113 }
00114 
00115 void KisDoubleWidget::sliderValueChanged(int value)
00116 {
00117     m_spinBox->setValue(value / 100.0);
00118 }
00119 
00120 void KisDoubleWidget::setPrecision(int precision)
00121 {
00122     m_spinBox->setPrecision(precision);
00123 }
00124 
00125 void KisDoubleWidget::setLineStep(double step)
00126 {
00127     m_spinBox->setLineStep(step);
00128     m_slider->setLineStep(static_cast<int>(step * 100));
00129 }
00130 
00131 void KisDoubleWidget::setPageStep(double step)
00132 {
00133     m_slider->setPageStep(static_cast<int>(step * 100));
00134 }
00135 
00136 void KisDoubleWidget::setTracking(bool tracking)
00137 {
00138     m_slider->setTracking(tracking);
00139 }
00140 
00141 bool KisDoubleWidget::tracking() const
00142 {
00143     return m_slider->tracking();
00144 }
00145 
00146 #include "kis_double_widget.moc"
00147 
KDE Home | KDE Accessibility Home | Description of Access Keys