summaryrefslogtreecommitdiffstats
path: root/chalk/ui/kis_int_spinbox.h
blob: ea80a80d3d860185d229c07a66c077e6cc3424cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
 *  Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
 *  Copyright (c) 2006 Casper Boemann <cbr@boemann.dk>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */
#ifndef KIS_INT_SPINBOX_H_
#define KIS_INT_SPINBOX_H_

#include <tqwidget.h>
#include <tqspinbox.h>
#include <tqslider.h>
#include <tqpopupmenu.h>

#include <knumvalidator.h>

class TQLabel;
class TQLineEdit;
class TQLayout;
class TQValidator;

class KisPopupSlider : public TQPopupMenu {
    Q_OBJECT
  

public:

    KisPopupSlider(int minValue, int maxValue, int pageStep, int value, Qt::Orientation orientation, TQWidget * parent, const char * name = 0) 
        : TQPopupMenu(parent, name)
    {
        m_slider = new TQSlider(minValue, maxValue, pageStep, value, orientation, this, name);
        //m_slider->setTracking(false);
        insertItem(m_slider);
        connect(m_slider, TQT_SIGNAL(valueChanged(int)), TQT_SIGNAL(valueChanged(int)));
    }
    void setTickInterval(int i) { m_slider->setTickInterval(i); }
    void setRange(int minValue, int maxValue) { m_slider->setRange(minValue, maxValue); }
    void setValue(int val) { m_slider->setValue(val); }
    void setTickmarks(TQSlider::TickSetting t) { m_slider->setTickmarks(t); }
    int lineStep () const{ return m_slider->lineStep(); }
    int minValue () const{ return m_slider->minValue(); }
    int maxValue () const{ return m_slider->maxValue(); }
    int value () const{ return m_slider->value(); }
    TQSlider *m_slider;

signals:
    void valueChanged(int);

};

/**
 * @short An input widget for integer numbers, consisting of a spinbox and
 * a dropdown slider.
 *
 * KisIntSpinbox combines a TQSpinBox and a dropdown TQSlider
 * to make an easy to use control for setting some integer
 * parameter.
 *
 *
 */
class KisIntSpinbox : public TQWidget
{

    Q_OBJECT
  
    TQ_PROPERTY( int value READ value WRITE setValue )
    TQ_PROPERTY( int minValue READ minValue WRITE setMinValue )
    TQ_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )

public:

    /**
     * Constructs an input control for integer values
     * with base 10 and initial value 0.
     * 
     * @param parent parent TQWidget
     * @param name   internal name for this widget
     */
    KisIntSpinbox(TQWidget *parent=0, const char *name=0);
    /**
     * Constructor
     * It constructs a TQSpinBox that allows the input of integer numbers
     * in the range of -INT_MAX to +INT_MAX. 
     * To enforce the value being in a range, use setRange().
     *
     * @param label the tabel (may contain &, and my be empty)
     * @param value  initial value for the control
     * @param parent parent TQWidget
     * @param name   internal name for this widget
     */
    KisIntSpinbox(const TQString & label, int value, TQWidget* parent=0, const char *name=0);

    /**
     * Destructor
     *
     *
     */
    virtual ~KisIntSpinbox();
    
   /**
     * @return the current value.
     */
    int value() const;

    /**
     * @param min  minimum value
     * @param max  maximum value
     * @param step step size for the TQSlider
     */
    void setRange(int min, int max, int step=1);
    /**
     * Sets the minimum value.
     */
    void setMinValue(int min);
    /**
     * @return the minimum value.
     */
    int minValue() const;
    /**
     * Sets the maximum value.
     */
    void setMaxValue(int max);
    /**
     * @return the maximum value.
     */
    int maxValue() const;

    /**
     * Sets the spacing of tickmarks for the slider.
     *
     * @param minor Minor tickmark separation.
     * @param major Major tickmark separation.
     */
    void setSteps(int minor, int major);

    void setLabel(const TQString & label);

public slots:
    /**
     * Sets the value of the control.
     */
    void setValue(int);


    void spinboxValueChanged(int val);
    void sliderValueChanged(int val);

    void slotTimeout();
    
signals:

    /**
     * Emitted every time the value changes (by calling setValue() or
     * by user interaction).
     * @param value the new opacity
     */
    void valueChanged(int value);

    /**
     * Emitted every time the value changes (by calling setValue() or
     * by user interaction).
     * @param value the new opacity
     * @param withSlider whether the value was set by dragging the slider
     */
    void valueChanged(int value, bool withSlider);

    /**
     * Emitted after the slider has been hidden, if the value was changed while it was shown.
     * @param previous the value before the slider was shown
     * @param value the value after the slider was hidden
     */
    void finishedChanging(int previous, int value);

private slots:
    void slotAboutToShow();
    void slotAboutToHide();

private:
    void init(int val);

private:

    class KisIntSpinboxPrivate;
    KisIntSpinboxPrivate *d;
};

#endif