chalk

kis_double_widget.cpp
1/*
2 * kis_double_widget.cpp - part of Chalk
3 *
4 * Copyright (c) 1999 Carsten Pfeiffer <pfeiffer@kde.org>
5 * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22#include <tqhbox.h>
23#include <tqlayout.h>
24#include <tqslider.h>
25
26#include <knuminput.h>
27
28#include "kis_double_widget.h"
29
30KisDoubleWidget::KisDoubleWidget(TQWidget* parent, const char* name)
31 : super(parent, name)
32{
33 init(0, 1);
34}
35
36KisDoubleWidget::KisDoubleWidget(double min, double max, TQWidget* parent, const char* name)
37 : super(parent, name)
38{
39 init(min, max);
40}
41
42KisDoubleWidget::~KisDoubleWidget()
43{
44}
45
46void KisDoubleWidget::init(double min, double max)
47{
48 m_spinBox = new KDoubleSpinBox(min, max, 0.05, 0, 2, this, "spinbox");
49 connect(m_spinBox, TQ_SIGNAL(valueChanged(double)), this, TQ_SLOT(setSliderValue(double)));
50
51 m_slider = new TQSlider(static_cast<int>(min * 100 + 0.5), static_cast<int>(max * 100 + 0.5), 1, 0, TQt::Horizontal, this, "sld");
52 connect(m_slider, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(sliderValueChanged(int)));
53 connect(m_slider, TQ_SIGNAL(sliderPressed()), TQ_SIGNAL(sliderPressed()));
54 connect(m_slider, TQ_SIGNAL(sliderReleased()), TQ_SIGNAL(sliderReleased()));
55
56 m_layout = new TQHBoxLayout(this, 0, -1, "hbox layout");
57
58 m_layout->addWidget(m_slider);
59 m_layout->addSpacing(5);
60 m_layout->addWidget(m_spinBox);
61 m_layout->addItem(new TQSpacerItem(5,1,TQSizePolicy::Expanding, TQSizePolicy::Minimum));
62}
63
64double KisDoubleWidget::value() const
65{
66 return m_spinBox->value();
67}
68
69void KisDoubleWidget::setValue(double value)
70{
71 int intValue;
72
73 if (value < 0) {
74 intValue = static_cast<int>(value * 100 - 0.5);
75 } else {
76 intValue = static_cast<int>(value * 100 + 0.5);
77 }
78 m_slider->setValue(intValue);
79}
80
81void KisDoubleWidget::setRange(double min, double max)
82{
83 m_spinBox->setRange(min, max);
84 m_slider->setRange(static_cast<int>(min * 100 + 0.5), static_cast<int>(max * 100 + 0.5));
85}
86
87void KisDoubleWidget::setTickmarks(TQSlider::TickSetting tickSetting)
88{
89 m_slider->setTickmarks(tickSetting);
90}
91
92void KisDoubleWidget::setTickInterval(double value)
93{
94 m_slider->setTickInterval(static_cast<int>(value * 100 + 0.5));
95}
96
97double KisDoubleWidget::tickInterval() const
98{
99 return m_slider->tickInterval() / 100.0;
100}
101
102void KisDoubleWidget::setSliderValue(double value)
103{
104 int intValue;
105
106 if (value < 0) {
107 intValue = static_cast<int>(value * 100 - 0.5);
108 } else {
109 intValue = static_cast<int>(value * 100 + 0.5);
110 }
111 m_slider->setValue(intValue);
112 emit valueChanged(value);
113}
114
115void KisDoubleWidget::sliderValueChanged(int value)
116{
117 m_spinBox->setValue(value / 100.0);
118}
119
120void KisDoubleWidget::setPrecision(int precision)
121{
122 m_spinBox->setPrecision(precision);
123}
124
125void KisDoubleWidget::setLineStep(double step)
126{
127 m_spinBox->setLineStep(step);
128 m_slider->setLineStep(static_cast<int>(step * 100));
129}
130
131void KisDoubleWidget::setPageStep(double step)
132{
133 m_slider->setPageStep(static_cast<int>(step * 100));
134}
135
136void KisDoubleWidget::setTracking(bool tracking)
137{
138 m_slider->setTracking(tracking);
139}
140
141bool KisDoubleWidget::tracking() const
142{
143 return m_slider->tracking();
144}
145
146#include "kis_double_widget.moc"
147