Subversion Repositories Scribus

Rev

Rev 1804 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1803 subik 1
/* $Id: cwdialog.cpp 1805 2005-03-30 15:34:04Z subik $ */
1767 subik 2
#include "cwdialog.h"
3
 
4
#include <qvariant.h>
5
#include <qcombobox.h>
6
#include <qheader.h>
7
#include <qlistview.h>
8
#include <qlayout.h>
9
#include <qtooltip.h>
10
#include <qwhatsthis.h>
11
#include <qpushbutton.h>
12
#include <qspinbox.h>
1769 subik 13
#include <qpainter.h>
1767 subik 14
 
1803 subik 15
#include <prefsfile.h>
16
 
17
extern PrefsFile *prefsFile;
18
extern ScribusApp *ScApp;
19
 
20
ColorWheelDialog::ColorWheelDialog(QWidget* parent, const char* name, bool modal, WFlags fl)
21
        : QDialog(parent, name, modal, fl)
1767 subik 22
{
1803 subik 23
        if (!name)
24
                setName("ColorWheelDialog");
1767 subik 25
 
1803 subik 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");
1767 subik 29
 
1803 subik 30
        colorWheel = new ColorWheel(this, "colorWheel");
1767 subik 31
        colorWheel->setFrameShape(QFrame::Box);
32
        colorWheel->setMinimumSize(QSize(300, 300));
33
        colorWheel->setMaximumSize(QSize(300, 300));
34
        wheelLayout->addWidget(colorWheel);
35
 
1769 subik 36
        previewLabel = new QLabel(this, "previewLabel");
37
        previewLabel->setFrameShape(QFrame::Box);
38
        previewLabel->setMinimumSize(QSize(300, 120));
39
        previewLabel->setMaximumSize(QSize(300, 120));
40
        wheelLayout->addWidget(previewLabel);
1767 subik 41
 
1803 subik 42
        spacer1 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
1767 subik 43
        wheelLayout->addItem(spacer1);
44
        mainLayout->addLayout(wheelLayout);
45
 
1803 subik 46
        listLayout = new QVBoxLayout(0, 0, 6, "listLayout");
1767 subik 47
 
48
        typeLabel = new QLabel(this, "typeLabel");
49
        listLayout->addWidget(typeLabel);
1803 subik 50
        typeCombo = new QComboBox(FALSE, this, "typeCombo");
1767 subik 51
        listLayout->addWidget(typeCombo);
52
 
1769 subik 53
        angleLabel = new QLabel(this, "angleLabel");
1803 subik 54
        angleLayout = new QHBoxLayout(0, 0, 6, "angleLayout");
1769 subik 55
        angleLayout->addWidget(angleLabel);
56
 
57
        angleSpin = new QSpinBox(this, "angleSpin");
58
        angleSpin->setValue(15);
59
        angleSpin->setMinValue(0);
60
        angleSpin->setMaxValue(365);
61
        angleLayout->addWidget(angleSpin);
62
        listLayout->addLayout(angleLayout);
63
 
1803 subik 64
        colorList = new QListView(this, "colorList");
1767 subik 65
        listLayout->addWidget(colorList);
66
 
1803 subik 67
        buttonLayout = new QHBoxLayout(0, 0, 6, "buttonLayout");
1767 subik 68
        addButton = new QPushButton(this, "addButton");
69
        buttonLayout->addWidget(addButton);
70
        cancelButton = new QPushButton(this, "cancelButton");
71
        buttonLayout->addWidget(cancelButton);
72
 
73
        listLayout->addLayout(buttonLayout);
74
        mainLayout->addLayout(listLayout);
75
        formLayout->addLayout(mainLayout, 0, 0);
76
 
77
        languageChange();
1803 subik 78
        resize(QSize(600, 480).expandedTo(minimumSizeHint()));
79
        clearWState(WState_Polished);
1767 subik 80
 
81
        // setup combobox
82
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Monochromatic), colorWheel->Monochromatic);
83
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Analogous), colorWheel->Analogous);
84
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Complementary), colorWheel->Complementary);
85
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Split), colorWheel->Split);
86
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Triadic), colorWheel->Triadic);
87
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Tetradic), colorWheel->Tetradic);
1803 subik 88
 
89
        // preferences
90
        prefs = prefsFile->getPluginContext("colorwheel");
91
        typeCombo->setCurrentItem(prefs->getInt("cw_type", 0));
92
        angleSpin->setValue(prefs->getInt("cw_angle", 15));
1804 subik 93
        colorWheel->angle = angleSpin->value();
1803 subik 94
        QValueVector<QPoint> vp;
95
        int x = prefs->getInt("cw_x", 0);
96
        int y = prefs->getInt("cw_y", 0);
97
        vp.append(QPoint(x, y));
98
        colorWheel->actualPoint = QPoint(x, y);
99
        colorWheel->actualRgb = QColor(prefs->getInt("cw_r", 0), prefs->getInt("cw_g", 0), prefs->getInt("cw_b", 0)).rgb();
100
        colorWheel->paintWheel(vp);
101
 
102
        // actions
1767 subik 103
        typeCombo_activated(typeCombo->currentItem());
1803 subik 104
        // signals and slots connections
1767 subik 105
        connect(typeCombo, SIGNAL(activated(int)), this, SLOT(typeCombo_activated(int)));
106
        connect(colorWheel, SIGNAL(clicked(int, const QPoint&)), this, SLOT(colorWheel_clicked(int, const QPoint&)));
107
        colorWheel_clicked(0, QPoint(0, 0));
108
        connect(angleSpin, SIGNAL(valueChanged(int)), this, SLOT(angleSpin_valueChanged(int)));
109
        connect(addButton, SIGNAL(clicked()), this, SLOT(addButton_clicked()));
110
        connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelButton_clicked()));
111
}
112
 
113
/*
114
 *  Destroys the object and frees any allocated resources
115
 */
116
ColorWheelDialog::~ColorWheelDialog()
117
{
1803 subik 118
        // no need to delete child widgets, Qt does it all for us
119
        // preferences
120
        prefs->set("cw_type", typeCombo->currentItem());
121
        prefs->set("cw_angle", angleSpin->value());
122
        prefs->set("cw_x", colorWheel->actualPoint.x());
123
        prefs->set("cw_y", colorWheel->actualPoint.y());
124
        prefs->set("cw_r", qRed(colorWheel->actualRgb));
125
        prefs->set("cw_g", qGreen(colorWheel->actualRgb));
126
        prefs->set("cw_b", qBlue(colorWheel->actualRgb));
1767 subik 127
}
128
 
129
/*
130
 *  Sets the strings of the subwidgets using the current
131
 *  language.
132
 */
133
void ColorWheelDialog::languageChange()
134
{
135
        setCaption(tr("Color Wheel"));
136
        colorList->addColumn(tr("Color"));
137
        colorList->addColumn(tr("Name"));
1803 subik 138
        colorList->addColumn(tr("C"));
139
        colorList->addColumn(tr("M"));
140
        colorList->addColumn(tr("Y"));
141
        colorList->addColumn(tr("K"));
142
        colorList->setSorting(1);
1767 subik 143
        typeLabel->setText(tr("Select Method:"));
144
        angleLabel->setText(tr("Angle (0 - 365 degrees):"));
145
        addButton->setText(tr("&Add Colors"));
146
        cancelButton->setText(tr("&Cancel"));
1804 subik 147
        // tips
148
        QToolTip::add(addButton, "<qt>" + tr("Appends created colors into socument colors") + "</qt>");
149
        QToolTip::add(cancelButton, "<qt>" + tr("Leave colors untouched") + "</qt>");
150
        QToolTip::add(angleSpin, "<qt>" + tr("Difference between selected value and counted ones. See documentation for more info") + "</qt>");
151
        QToolTip::add(colorWheel, "<qt>" + tr("Click the wheel to get base color") + "</qt>");
152
        QToolTip::add(previewLabel, "<qt>" + tr("Here you have the sample color schema") + "</qt>");
153
        QToolTip::add(typeCombo, "<qt>" + tr("Select one of the method to create color schema. See documentation for more info") + "</qt>");
154
        QToolTip::add(colorList, "<qt>" + tr("Here you have the color of your chosen color schema") + "</qt>");
1767 subik 155
}
156
 
157
void ColorWheelDialog::fillColorList()
158
{
159
        colorList->clear();
1803 subik 160
        for (ColorList::iterator it = colorWheel->colorList.begin(); it != colorWheel->colorList.end(); ++it)
1767 subik 161
        {
1803 subik 162
                int c, m, y, k;
1767 subik 163
                QListViewItem *item = new QListViewItem(colorList);
1769 subik 164
                item->setPixmap(0, colorWheel->sample(it.data().getRGBColor()));
1803 subik 165
                item->setText(1, it.key());
166
                it.data().getCMYK(&c, &m, &y, &k);
167
                item->setText(2, QString("%1").arg(c));
168
                item->setText(3, QString("%1").arg(m));
169
                item->setText(4, QString("%1").arg(y));
170
                item->setText(5, QString("%1").arg(k));
1767 subik 171
        }
172
}
173
 
174
void ColorWheelDialog::typeCombo_activated(int index)
175
{
176
        colorList->clear();
177
        if (index == colorWheel->Monochromatic)
178
        {
179
                angleSpin->setEnabled(false);
1769 subik 180
                angleLabel->setEnabled(false);
1767 subik 181
                colorWheel->makeMonochromatic();
182
        }
183
        if (index == colorWheel->Analogous)
184
        {
185
                angleSpin->setEnabled(true);
1769 subik 186
                angleLabel->setEnabled(true);
1767 subik 187
                colorWheel->makeAnalogous();
188
        }
189
        if (index == colorWheel->Complementary)
190
        {
191
                angleSpin->setEnabled(false);
1769 subik 192
                angleLabel->setEnabled(false);
1767 subik 193
                colorWheel->makeComplementary();
194
        }
195
        if (index == colorWheel->Split)
196
        {
197
                angleSpin->setEnabled(true);
1769 subik 198
                angleLabel->setEnabled(true);
1767 subik 199
                colorWheel->makeSplit();
200
        }
201
        if (index == colorWheel->Triadic)
202
        {
203
                angleSpin->setEnabled(false); //TODO
1769 subik 204
                angleLabel->setEnabled(false);
1767 subik 205
                colorWheel->makeTriadic();
206
        }
207
        if (index == colorWheel->Tetradic)
208
        {
209
                angleSpin->setEnabled(false); //TODO
1769 subik 210
                angleLabel->setEnabled(false);
1767 subik 211
                colorWheel->makeTetradic();
212
        }
213
        fillColorList();
1769 subik 214
        setPreview();
1767 subik 215
}
216
 
217
void ColorWheelDialog::colorWheel_clicked(int, const QPoint&)
218
{
219
        typeCombo_activated(typeCombo->currentItem());
220
}
221
 
222
void ColorWheelDialog::angleSpin_valueChanged(int value)
223
{
224
        colorWheel->angle = value;
225
        typeCombo_activated(typeCombo->currentItem());
226
}
227
 
228
void ColorWheelDialog::addButton_clicked()
229
{
1803 subik 230
        QString status("<qt><h2>" + tr("Merging colors") + "</h2><p>");
231
        for (ColorList::iterator it = colorWheel->colorList.begin(); it != colorWheel->colorList.end(); ++it)
232
        {
233
                if (ScApp->doc->PageColors.contains(it.key()))
234
                        status += "<b>" + tr("Error: ") + "</b>" + tr(QString("Color %1 exists already!").arg(it.key())) + "<br/>";
235
                else
236
                {
237
                        status += tr(QString("Color %1 appended.").arg(it.key())) + "<br/>";
238
                        ScApp->doc->PageColors[it.key()] = it.data();
239
                }
240
        }
241
        status += "<p>" + tr("Use <i>Edit/Colors...</i> for more color management.") + "</p></qt>";
242
        QMessageBox::information(this, tr("Color Merging"), status);
1767 subik 243
        accept();
244
}
245
 
246
 
247
void ColorWheelDialog::cancelButton_clicked()
248
{
249
        reject();
250
}
1769 subik 251
 
252
void ColorWheelDialog::setPreview()
253
{
254
        int x = previewLabel->width();
255
        int y = previewLabel->height();
256
        QValueList<CMYKColor> cols = colorWheel->colorList.values();
257
        int xstep = x / cols.count();
258
        QPixmap pm = QPixmap(x, y);
259
        QPainter *p = new QPainter(&pm);
260
        QFontMetrics fm = p->fontMetrics();
261
 
262
        pm.fill(Qt::white);
263
        p->setPen(Qt::white);
264
        p->drawRect(0, 0, x, y);
265
        for (uint i = 0; i < cols.count(); ++i)
266
        {
267
                p->setPen(cols[i].getRGBColor());
268
                p->setBrush(cols[i].getRGBColor());
269
                p->drawRect(i * xstep, 0, xstep, y);
270
        }
271
        p->setPen(Qt::black);
272
        p->setBrush(Qt::black);
273
        p->drawText(15, 5 + fm.height(), "Lorem ipsum dolor sit amet");
274
        p->setPen(Qt::white);
275
        p->setBrush(Qt::white);
276
        p->drawText(25, y - 5 - fm.height(), "Lorem ipsum dolor sit amet");
277
        p->end();
278
        delete(p);
279
        previewLabel->clear();
280
        previewLabel->setPixmap(pm);
281
}