summaryrefslogtreecommitdiffstats
path: root/deco/config/colorpicker.cpp
blob: 7f1e6773877484781546047644b71053dbd0da68 (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
#include "colorpicker.h"
#include <tqcolor.h>
#include <tqlayout.h>
#include <tqslider.h>
#include <tqspinbox.h>

ColorPicker::ColorPicker(TQWidget* parent, const char* name) : TQGroupBox( parent, name){
//    box = new TQGroupBox(parent);
//     setFrameShape(TQFrame::GroupBoxPanel);
//     setFrameShadow(TQFrame::Sunken);
    setColumnLayout(0, TQt::Vertical );
    layout()->setSpacing( 6 );
    layout()->setMargin( 11 );
    
    TQVBoxLayout *vLayout = new TQVBoxLayout(layout());
//     gridLayout->setAlignment( TQt::AlignTop );
    
    TQHBoxLayout *redLayout = new TQHBoxLayout();
    redSlider = new TQSlider(0, 255, 1, 0, TQt::Horizontal, this, "redSlider");
    redLayout->addWidget(redSlider);
    
    redValue = new TQSpinBox(0,255,1,this);
    redValue->setValue(0);
    redLayout->addWidget(redValue);
    
    vLayout->addLayout(redLayout);
    
    TQHBoxLayout *greenLayout = new TQHBoxLayout();
    greenSlider = new TQSlider(0, 255, 1, 0, TQt::Horizontal, this, "greenSlider");
    greenLayout->addWidget(greenSlider);
    
    greenValue = new TQSpinBox(0,255,1,this);
    greenValue->setValue(0);
    greenLayout->addWidget(greenValue);
    
    vLayout->addLayout(greenLayout);
    
    TQHBoxLayout *blueLayout = new TQHBoxLayout();
    blueSlider = new TQSlider(0, 255, 1, 0, TQt::Horizontal, this, "blueSlider");
    blueLayout->addWidget(blueSlider);
    
    blueValue = new TQSpinBox(0,255,1,this);
    blueValue->setValue(0);
    blueLayout->addWidget(blueValue);
    
    vLayout->addLayout(blueLayout);
    
//     resize( TQSize(350, 100).expandedTo(minimumSizeHint()) );
    
    //connections
    connect(redSlider, TQ_SIGNAL(valueChanged (int)), this, TQ_SLOT(setRed(int)));
    connect(greenSlider, TQ_SIGNAL(valueChanged (int)), this, TQ_SLOT(setGreen(int)));
    connect(blueSlider, TQ_SIGNAL(valueChanged (int)), this, TQ_SLOT(setBlue(int)));
    connect(redValue, TQ_SIGNAL(valueChanged (int)), this, TQ_SLOT(setRed(int)));
    connect(greenValue, TQ_SIGNAL(valueChanged (int)), this, TQ_SLOT(setGreen(int)));
    connect(blueValue, TQ_SIGNAL(valueChanged (int)), this, TQ_SLOT(setBlue(int)));
}

ColorPicker::~ColorPicker(){
}

void ColorPicker::setColor(TQColor color){
    redSlider->blockSignals(true);
    redSlider->setValue( color.red() );
    redSlider->blockSignals(false);
    redValue->blockSignals(true);
    redValue->setValue(redSlider->value());
    redValue->blockSignals(false);
    greenSlider->blockSignals(true);
    greenSlider->setValue( color.green() );
    greenSlider->blockSignals(false);
    greenValue->blockSignals(true);
    greenValue->setValue(greenSlider->value());
    greenValue->blockSignals(false);
    blueSlider->blockSignals(true);
    blueSlider->setValue( color.blue() );
    blueSlider->blockSignals(false);
    blueValue->blockSignals(true);
    blueValue->setValue(blueSlider->value());
    blueValue->blockSignals(false);
    emit colorChanged(color);
}

void ColorPicker::setRed(int red){
    redSlider->blockSignals(true);
    redSlider->setValue( red );
    redSlider->blockSignals(false);
    redValue->blockSignals(true);
    redValue->setValue(red);
    redValue->blockSignals(false);
    emit colorChanged(TQColor(red, greenSlider->value(), blueSlider->value()));
}

void ColorPicker::setGreen(int green){
    greenSlider->blockSignals(true);
    greenSlider->setValue( green );
    greenSlider->blockSignals(false);
    greenValue->blockSignals(true);
    greenValue->setValue(green);
    greenValue->blockSignals(false);
    emit colorChanged(TQColor(redSlider->value(), green, blueSlider->value()));
}

void ColorPicker::setBlue(int blue){
    blueSlider->blockSignals(true);
    blueSlider->setValue( blue );
    blueSlider->blockSignals(false);
    blueValue->blockSignals(true);
    blueValue->setValue(blue);
    blueValue->blockSignals(false);
    emit colorChanged(TQColor(redSlider->value(), greenSlider->value(), blue));
}

TQColor ColorPicker::Color(){
    return TQColor(redSlider->value(), greenSlider->value(), blueSlider->value());
}

void ColorPicker::reset(){
    setColor(color_);
}

void ColorPicker::init(){
    color_ = Color();
}

#include "colorpicker.moc"