Subversion Repositories Scribus

Rev

Rev 1769 | Rev 1804 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1803 subik 1
/* $Id: cwdialog.cpp 1803 2005-03-30 13:15:05Z 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
        colorWheel->paintWheel(QValueVector<QPoint>());
36
 
1769 subik 37
        previewLabel = new QLabel(this, "previewLabel");
38
        previewLabel->setFrameShape(QFrame::Box);
39
        previewLabel->setMinimumSize(QSize(300, 120));
40
        previewLabel->setMaximumSize(QSize(300, 120));
41
        wheelLayout->addWidget(previewLabel);
1767 subik 42
 
1803 subik 43
        spacer1 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
1767 subik 44
        wheelLayout->addItem(spacer1);
45
        mainLayout->addLayout(wheelLayout);
46
 
1803 subik 47
        listLayout = new QVBoxLayout(0, 0, 6, "listLayout");
1767 subik 48
 
49
        typeLabel = new QLabel(this, "typeLabel");
50
        listLayout->addWidget(typeLabel);
1803 subik 51
        typeCombo = new QComboBox(FALSE, this, "typeCombo");
1767 subik 52
        listLayout->addWidget(typeCombo);
53
 
1769 subik 54
        angleLabel = new QLabel(this, "angleLabel");
1803 subik 55
        angleLayout = new QHBoxLayout(0, 0, 6, "angleLayout");
1769 subik 56
        angleLayout->addWidget(angleLabel);
57
 
58
        angleSpin = new QSpinBox(this, "angleSpin");
59
        angleSpin->setValue(15);
60
        angleSpin->setMinValue(0);
61
        angleSpin->setMaxValue(365);
62
        angleLayout->addWidget(angleSpin);
63
        listLayout->addLayout(angleLayout);
64
 
1803 subik 65
        colorList = new QListView(this, "colorList");
1767 subik 66
        listLayout->addWidget(colorList);
67
 
1803 subik 68
        buttonLayout = new QHBoxLayout(0, 0, 6, "buttonLayout");
1767 subik 69
        addButton = new QPushButton(this, "addButton");
70
        buttonLayout->addWidget(addButton);
71
        cancelButton = new QPushButton(this, "cancelButton");
72
        buttonLayout->addWidget(cancelButton);
73
 
74
        listLayout->addLayout(buttonLayout);
75
        mainLayout->addLayout(listLayout);
76
        formLayout->addLayout(mainLayout, 0, 0);
77
 
78
        languageChange();
1803 subik 79
        resize(QSize(600, 480).expandedTo(minimumSizeHint()));
80
        clearWState(WState_Polished);
1767 subik 81
 
82
        // setup combobox
83
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Monochromatic), colorWheel->Monochromatic);
84
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Analogous), colorWheel->Analogous);
85
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Complementary), colorWheel->Complementary);
86
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Split), colorWheel->Split);
87
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Triadic), colorWheel->Triadic);
88
        typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Tetradic), colorWheel->Tetradic);
1803 subik 89
 
90
        // preferences
91
        prefs = prefsFile->getPluginContext("colorwheel");
92
        typeCombo->setCurrentItem(prefs->getInt("cw_type", 0));
93
        angleSpin->setValue(prefs->getInt("cw_angle", 15));
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"));
147
 
148
}
149
 
150
void ColorWheelDialog::fillColorList()
151
{
152
        colorList->clear();
1803 subik 153
        for (ColorList::iterator it = colorWheel->colorList.begin(); it != colorWheel->colorList.end(); ++it)
1767 subik 154
        {
1803 subik 155
                int c, m, y, k;
1767 subik 156
                QListViewItem *item = new QListViewItem(colorList);
1769 subik 157
                item->setPixmap(0, colorWheel->sample(it.data().getRGBColor()));
1803 subik 158
                item->setText(1, it.key());
159
                it.data().getCMYK(&c, &m, &y, &k);
160
                item->setText(2, QString("%1").arg(c));
161
                item->setText(3, QString("%1").arg(m));
162
                item->setText(4, QString("%1").arg(y));
163
                item->setText(5, QString("%1").arg(k));
1767 subik 164
        }
165
}
166
 
167
void ColorWheelDialog::typeCombo_activated(int index)
168
{
169
        colorList->clear();
170
        if (index == colorWheel->Monochromatic)
171
        {
172
                angleSpin->setEnabled(false);
1769 subik 173
                angleLabel->setEnabled(false);
1767 subik 174
                colorWheel->makeMonochromatic();
175
        }
176
        if (index == colorWheel->Analogous)
177
        {
178
                angleSpin->setEnabled(true);
1769 subik 179
                angleLabel->setEnabled(true);
1767 subik 180
                colorWheel->makeAnalogous();
181
        }
182
        if (index == colorWheel->Complementary)
183
        {
184
                angleSpin->setEnabled(false);
1769 subik 185
                angleLabel->setEnabled(false);
1767 subik 186
                colorWheel->makeComplementary();
187
        }
188
        if (index == colorWheel->Split)
189
        {
190
                angleSpin->setEnabled(true);
1769 subik 191
                angleLabel->setEnabled(true);
1767 subik 192
                colorWheel->makeSplit();
193
        }
194
        if (index == colorWheel->Triadic)
195
        {
196
                angleSpin->setEnabled(false); //TODO
1769 subik 197
                angleLabel->setEnabled(false);
1767 subik 198
                colorWheel->makeTriadic();
199
        }
200
        if (index == colorWheel->Tetradic)
201
        {
202
                angleSpin->setEnabled(false); //TODO
1769 subik 203
                angleLabel->setEnabled(false);
1767 subik 204
                colorWheel->makeTetradic();
205
        }
206
        fillColorList();
1769 subik 207
        setPreview();
1767 subik 208
}
209
 
210
void ColorWheelDialog::colorWheel_clicked(int, const QPoint&)
211
{
212
        typeCombo_activated(typeCombo->currentItem());
213
}
214
 
215
void ColorWheelDialog::angleSpin_valueChanged(int value)
216
{
217
        colorWheel->angle = value;
218
        typeCombo_activated(typeCombo->currentItem());
219
}
220
 
221
void ColorWheelDialog::addButton_clicked()
222
{
1803 subik 223
        QString status("<qt><h2>" + tr("Merging colors") + "</h2><p>");
224
        for (ColorList::iterator it = colorWheel->colorList.begin(); it != colorWheel->colorList.end(); ++it)
225
        {
226
                if (ScApp->doc->PageColors.contains(it.key()))
227
                        status += "<b>" + tr("Error: ") + "</b>" + tr(QString("Color %1 exists already!").arg(it.key())) + "<br/>";
228
                else
229
                {
230
                        status += tr(QString("Color %1 appended.").arg(it.key())) + "<br/>";
231
                        ScApp->doc->PageColors[it.key()] = it.data();
232
                }
233
        }
234
        status += "<p>" + tr("Use <i>Edit/Colors...</i> for more color management.") + "</p></qt>";
235
        QMessageBox::information(this, tr("Color Merging"), status);
1767 subik 236
        accept();
237
}
238
 
239
 
240
void ColorWheelDialog::cancelButton_clicked()
241
{
242
        reject();
243
}
1769 subik 244
 
245
void ColorWheelDialog::setPreview()
246
{
247
        int x = previewLabel->width();
248
        int y = previewLabel->height();
249
        QValueList<CMYKColor> cols = colorWheel->colorList.values();
250
        int xstep = x / cols.count();
251
        QPixmap pm = QPixmap(x, y);
252
        QPainter *p = new QPainter(&pm);
253
        QFontMetrics fm = p->fontMetrics();
254
 
255
        pm.fill(Qt::white);
256
        p->setPen(Qt::white);
257
        p->drawRect(0, 0, x, y);
258
        for (uint i = 0; i < cols.count(); ++i)
259
        {
260
                p->setPen(cols[i].getRGBColor());
261
                p->setBrush(cols[i].getRGBColor());
262
                p->drawRect(i * xstep, 0, xstep, y);
263
        }
264
        p->setPen(Qt::black);
265
        p->setBrush(Qt::black);
266
        p->drawText(15, 5 + fm.height(), "Lorem ipsum dolor sit amet");
267
        p->setPen(Qt::white);
268
        p->setBrush(Qt::white);
269
        p->drawText(25, y - 5 - fm.height(), "Lorem ipsum dolor sit amet");
270
        p->end();
271
        delete(p);
272
        previewLabel->clear();
273
        previewLabel->setPixmap(pm);
274
}