Subversion Repositories Scribus

Rev

Rev 1769 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1767 subik 1
#include "cwdialog.h"
2
 
3
#include <qvariant.h>
4
#include <qcombobox.h>
5
#include <qheader.h>
6
#include <qlistview.h>
7
#include <qlayout.h>
8
#include <qtooltip.h>
9
#include <qwhatsthis.h>
10
#include <qpushbutton.h>
11
#include <qspinbox.h>
12
 
13
/*
14
 *  Constructs a ColorWheel as a child of 'parent', with the
15
 *  name 'name' and widget flags set to 'f'.
16
 *
17
 *  The dialog will by default be modeless, unless you set 'modal' to
18
 *  TRUE to construct a modal dialog.
19
 */
20
ColorWheelDialog::ColorWheelDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
21
        : QDialog( parent, name, modal, fl )
22
{
23
        if ( !name )
24
                setName( "ColorWheelDialog" );
25
 
26
        formLayout = new QGridLayout( this, 1, 1, 11, 6, "formLayout");
27
        mainLayout = new QHBoxLayout( 0, 0, 6, "mainLayout");
28
        wheelLayout = new QVBoxLayout( 0, 0, 6, "wheelLayout");
29
 
30
        colorWheel = new ColorWheel( this, "colorWheel" );
31
        colorWheel->setFrameShape(QFrame::Box);
32
        colorWheel->setMinimumSize(QSize(300, 300));
33
        colorWheel->setMaximumSize(QSize(300, 300));
34
        wheelLayout->addWidget(colorWheel);
35
        colorWheel->paintWheel(QValueVector<QPoint>());
36
 
37
        angleLabel = new QLabel(this, "angleLabel");
38
 
39
        angleLayout = new QHBoxLayout( 0, 0, 6, "angleLayout");
40
        angleLayout->addWidget(angleLabel);
41
 
42
        angleSpin = new QSpinBox(this, "angleSpin");
43
        angleSpin->setValue(15);
44
        angleSpin->setMinValue(0);
45
        angleSpin->setMaxValue(365);
46
        angleLayout->addWidget(angleSpin);
47
        wheelLayout->addLayout(angleLayout);
48
 
49
        brightnessLabel = new QLabel(this, "brightnessLabel");
50
 
51
        brightnessLayout = new QHBoxLayout( 0, 0, 6, "brightnessLayout");
52
        brightnessLayout->addWidget(brightnessLabel);
53
 
54
        brightnessSpin = new QSpinBox(this, "brightnessSpin");
55
        brightnessSpin->setMinValue(0);
56
        brightnessSpin->setMaxValue(255);
57
        brightnessSpin->setValue(255);
58
        brightnessLayout->addWidget(brightnessSpin);
59
        wheelLayout->addLayout(brightnessLayout);
60
 
61
        spacer1 = new QSpacerItem( 20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding );
62
        wheelLayout->addItem(spacer1);
63
        mainLayout->addLayout(wheelLayout);
64
 
65
        listLayout = new QVBoxLayout( 0, 0, 6, "listLayout");
66
 
67
        typeLabel = new QLabel(this, "typeLabel");
68
        listLayout->addWidget(typeLabel);
69
        typeCombo = new QComboBox( FALSE, this, "typeCombo" );
70
        listLayout->addWidget(typeCombo);
71
 
72
        colorList = new QListView( this, "colorList" );
73
        listLayout->addWidget(colorList);
74
 
75
        buttonLayout = new QHBoxLayout( 0, 0, 6, "buttonLayout");
76
        addButton = new QPushButton(this, "addButton");
77
        buttonLayout->addWidget(addButton);
78
        cancelButton = new QPushButton(this, "cancelButton");
79
        buttonLayout->addWidget(cancelButton);
80
 
81
        listLayout->addLayout(buttonLayout);
82
        mainLayout->addLayout(listLayout);
83
        formLayout->addLayout(mainLayout, 0, 0);
84
 
85
        languageChange();
86
        resize( QSize(600, 480).expandedTo(minimumSizeHint()) );
87
        clearWState( WState_Polished );
88
 
89
        // setup combobox
90
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Monochromatic), colorWheel->Monochromatic);
91
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Analogous), colorWheel->Analogous);
92
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Complementary), colorWheel->Complementary);
93
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Split), colorWheel->Split);
94
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Triadic), colorWheel->Triadic);
95
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Tetradic), colorWheel->Tetradic);
96
        typeCombo_activated(typeCombo->currentItem());
97
 
98
    // signals and slots connections
99
        connect(typeCombo, SIGNAL(activated(int)), this, SLOT(typeCombo_activated(int)));
100
        connect(colorWheel, SIGNAL(clicked(int, const QPoint&)), this, SLOT(colorWheel_clicked(int, const QPoint&)));
101
        colorWheel_clicked(0, QPoint(0, 0));
102
        connect(angleSpin, SIGNAL(valueChanged(int)), this, SLOT(angleSpin_valueChanged(int)));
103
        connect(brightnessSpin, SIGNAL(valueChanged(int)), this, SLOT(brightnessSpin_valueChanged(int)));
104
        connect(addButton, SIGNAL(clicked()), this, SLOT(addButton_clicked()));
105
        connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelButton_clicked()));
106
}
107
 
108
/*
109
 *  Destroys the object and frees any allocated resources
110
 */
111
ColorWheelDialog::~ColorWheelDialog()
112
{
113
    // no need to delete child widgets, Qt does it all for us
114
}
115
 
116
/*
117
 *  Sets the strings of the subwidgets using the current
118
 *  language.
119
 */
120
void ColorWheelDialog::languageChange()
121
{
122
        setCaption(tr("Color Wheel"));
123
        colorList->addColumn(tr("Color"));
124
        colorList->addColumn(tr("Value"));
125
        colorList->addColumn(tr("Name"));
126
        typeLabel->setText(tr("Select Method:"));
127
        angleLabel->setText(tr("Angle (0 - 365 degrees):"));
128
        brightnessLabel->setText(tr("Brightness (0 - 255):"));
129
        addButton->setText(tr("&Add Colors"));
130
        cancelButton->setText(tr("&Cancel"));
131
 
132
}
133
 
134
void ColorWheelDialog::fillColorList()
135
{
136
        colorList->clear();
137
        for (QMap<QString,CMYKColor>::iterator it = colorWheel->colorList.begin(); it != colorWheel->colorList.end(); ++it )
138
        {
139
                QListViewItem *item = new QListViewItem(colorList);
140
                item->setPixmap(0, colorWheel->sample(it.data().getShadeColorProof(brightnessSpin->value())));
141
                item->setText(1, it.data().name());
142
                item->setText(2, it.key());
143
        }
144
}
145
 
146
void ColorWheelDialog::typeCombo_activated(int index)
147
{
148
        colorList->clear();
149
        if (index == colorWheel->Monochromatic)
150
        {
151
                angleSpin->setEnabled(false);
152
                colorWheel->makeMonochromatic();
153
        }
154
        if (index == colorWheel->Analogous)
155
        {
156
                angleSpin->setEnabled(true);
157
                colorWheel->makeAnalogous();
158
        }
159
        if (index == colorWheel->Complementary)
160
        {
161
                angleSpin->setEnabled(false);
162
                colorWheel->makeComplementary();
163
        }
164
        if (index == colorWheel->Split)
165
        {
166
                angleSpin->setEnabled(true);
167
                colorWheel->makeSplit();
168
        }
169
        if (index == colorWheel->Triadic)
170
        {
171
                angleSpin->setEnabled(false); //TODO
172
                colorWheel->makeTriadic();
173
        }
174
        if (index == colorWheel->Tetradic)
175
        {
176
                angleSpin->setEnabled(false); //TODO
177
                colorWheel->makeTetradic();
178
        }
179
        fillColorList();
180
}
181
 
182
void ColorWheelDialog::colorWheel_clicked(int, const QPoint&)
183
{
184
        typeCombo_activated(typeCombo->currentItem());
185
        //fillColorList();
186
}
187
 
188
void ColorWheelDialog::angleSpin_valueChanged(int value)
189
{
190
        colorWheel->angle = value;
191
        typeCombo_activated(typeCombo->currentItem());
192
}
193
 
194
void ColorWheelDialog::brightnessSpin_valueChanged(int value)
195
{
196
        for (QMap<QString,CMYKColor>::iterator it = colorWheel->colorList.begin(); it != colorWheel->colorList.end(); ++it )
197
        {
198
                CMYKColor c = CMYKColor();
199
                c.fromQColor(it.data().getShadeColorProof(value));
200
                it.data() = c;
201
        }
202
        fillColorList();
203
 
204
}
205
 
206
void ColorWheelDialog::addButton_clicked()
207
{
208
        qDebug("TODO: implement ColorWheel::addButton_clicked");
209
        accept();
210
}
211
 
212
 
213
void ColorWheelDialog::cancelButton_clicked()
214
{
215
        qDebug("TODO: implement ColorWheel::cancelButton_clicked");
216
        reject();
217
}