Subversion Repositories Scribus

Rev

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