karbon

vcolorslider.cpp
1/* This file is part of the KDE project
2 Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr)
3 Copyright (C) 2002, The Karbon Developers
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21/* vcolorslider.cpp */
22
23#include <tqlayout.h>
24#include <tqlabel.h>
25#include <knuminput.h>
26#include <tdeselect.h>
27
28#include "vcolorslider.h"
29
30VColorSlider::VColorSlider( TQWidget* parent, const char* name )
31 : TQWidget( parent, name )
32{
33 init();
34}
35
36// Label, left color, right color, min, max, value ...
37VColorSlider::VColorSlider( const TQString& label, const TQColor& col1,
38 const TQColor& col2, int min, int max, int value, TQWidget* parent, const char* name )
39 : TQWidget( parent, name )
40{
41 init();
42 setLabel( label );
43 setColors( col1, col2 );
44 setMinValue( min );
45 setMaxValue( max );
46 setValue( value );
47}
48
52
53void VColorSlider::init()
54{
55 m_isDragging = false;
56 TQHBoxLayout *layout = new TQHBoxLayout( this, 3 );
57
58 m_label = new TQLabel( this );
59 m_gradientSelect = new KGradientSelector( TQt::Horizontal, this );
60 m_spinBox = new KIntSpinBox( this );
61
62 layout->addWidget( m_label );
63 layout->addWidget( m_gradientSelect, 2 );
64 layout->addWidget( m_spinBox );
65
66 setValue( 0 );
67 setMinValue( 0 );
68 setMaxValue( 255 );
69
70 connect( m_spinBox, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateFrom_spinBox( int ) ) );
71 connect( m_gradientSelect, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateFrom_gradientSelect( int ) ) );
72
73 m_gradientSelect->installEventFilter( this );
74
75 layout->activate();
76}
77
78void VColorSlider::setLabel( const TQString& label )
79{
80 m_label->setText( label );
81}
82
83void VColorSlider::setColors( const TQColor& color1, const TQColor& color2 )
84{
85 m_gradientSelect->setColors( color1, color2 );
86}
87
89{
90 m_spinBox->setValue( value );
91 m_gradientSelect->setValue( (m_maxValue - value) + m_minValue );
92}
93
95{
96 m_minValue = value;
97 m_spinBox->setMinValue( value );
98 m_gradientSelect->setMinValue( value );
99}
100
102{
103 m_maxValue = value;
104 m_spinBox->setMaxValue( value );
105 m_gradientSelect->setMaxValue( value );
106}
107
109{
110 return( m_spinBox->value() );
111}
112
113void VColorSlider::updateFrom_spinBox( int value )
114{
115 if ( value != m_gradientSelect->value() )
116 {
117 disconnect( m_gradientSelect, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateFrom_gradientSelect( int ) ) );
118 m_gradientSelect->setValue( (m_maxValue - value) + m_minValue );
119 connect( m_gradientSelect, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateFrom_gradientSelect( int ) ) );
120 emit valueChanged( value );
121 }
122}
123
124void VColorSlider::updateFrom_gradientSelect( int value )
125{
126 value = (m_maxValue - value) + m_minValue;
127 if ( value != m_spinBox->value() )
128 {
129 disconnect( m_spinBox, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateFrom_spinBox( int ) ) );
130 m_spinBox->setValue( value );
131 connect( m_spinBox, TQ_SIGNAL( valueChanged ( int ) ), this, TQ_SLOT( updateFrom_spinBox( int ) ) );
132 emit valueChanged( value );
133 }
134}
135
136bool VColorSlider::eventFilter( TQObject *obj, TQEvent *ev )
137{
138 if( obj == m_gradientSelect )
139 {
140 if ( ev->type() == TQEvent::MouseButtonPress )
141 m_isDragging = true;
142 else if( ev->type() == TQEvent::MouseButtonRelease )
143 m_isDragging = false;
144 }
145 return false;
146}
147
148#include "vcolorslider.moc"
149
virtual void setMinValue(int value)
Sets the minimum value of the spinbox and slider.
virtual void setValue(int value)
Sets the value of the spinbox (and the value of the vcolorslider).
virtual void setMaxValue(int value)
Sets the maximum value of the spinbox and slider.
virtual void setColors(const TQColor &color1, const TQColor &color2)
Sets the colors for the slider.
virtual void setLabel(const TQString &label)
Sets the description of the slider.
VColorSlider(TQWidget *parent=0L, const char *name=0L)
Constructs a new color slider.
void valueChanged(int value)
Is emitted whenever the slider or spinbox value has changed.
int value()
Retrieves the actual value of the spinbox and slider.
~VColorSlider()
Destroys the color slider.