source: subversion/applications/editors/merkaartor/PaintStyle/PaintStyleEditor.cpp @ 13989

Last change on this file since 13989 was 13048, checked in by richardbrinkman, 11 years ago

Removed last compiler warnings with Q_UNUSED.

File size: 15.1 KB
Line 
1#include "PaintStyle/PaintStyleEditor.h"
2#include "PaintStyle/PaintStyle.h"
3#include "MainWindow.h"
4#include "Map/MapDocument.h"
5
6#include <QtGui/QCheckBox>
7#include <QtGui/QColorDialog>
8#include <QtGui/QDoubleSpinBox>
9#include <QtGui/QIcon>
10#include <QtGui/QListWidget>
11#include <QtGui/QPainter>
12#include <QtGui/QPixmap>
13#include <QtGui/QToolButton>
14
15static void makeBoundaryIcon(QToolButton* bt, QColor C)
16{
17        QPixmap pm(36, 18);
18        pm.fill(QColor(255, 255, 255));
19        QPainter p(&pm);
20        p.setPen(C);
21        p.setBrush(C);
22        p.drawRect(0, 6, 36, 6);
23        bt->setIcon(pm);
24}
25
26PaintStyleEditor::PaintStyleEditor(QWidget *aParent, const GlobalPainter& aGlobalPainter, const QVector<FeaturePainter>& aPainters)
27                : QDialog(aParent), theGlobalPainter(aGlobalPainter), thePainters(aPainters), FreezeUpdate(true)
28{
29        setupUi(this);
30        BackgroundColor->setIconSize(QSize(36, 18));
31        ForegroundColor->setIconSize(QSize(36, 18));
32        TouchupColor->setIconSize(QSize(36, 18));
33        FillColor->setIconSize(QSize(36, 18));
34        LabelColor->setIconSize(QSize(36, 18));
35        LabelBackgroundlColor->setIconSize(QSize(36, 18));
36        GlobalBackgroundColor->setIconSize(QSize(36, 18));
37
38        for (int i = 0; i < thePainters.size(); ++i)
39                PaintList->addItem(thePainters[i].userName());
40        PaintList->setCurrentRow(0);
41        LowerZoomBoundary->setSpecialValueText(tr("Always"));
42        UpperZoomBoundary->setSpecialValueText(tr("Always"));
43
44        DrawGlobalBackground->setChecked(theGlobalPainter.getDrawBackground());
45        makeBoundaryIcon(GlobalBackgroundColor, theGlobalPainter.getBackgroundColor());
46        on_PaintList_itemClicked(PaintList->item(PaintList->currentRow()));
47
48        FreezeUpdate = false;
49
50        resize(1, 1);
51}
52
53void PaintStyleEditor::on_AddButton_clicked()
54{
55        thePainters.push_back(FeaturePainter());
56        PaintList->addItem(thePainters[thePainters.size()-1].userName());
57        PaintList->setCurrentRow(thePainters.size() - 1);
58        on_PaintList_itemClicked(PaintList->item(PaintList->currentRow()));
59}
60
61void PaintStyleEditor::on_DuplicateButton_clicked()
62{
63        int idx = PaintList->currentRow();
64        if (idx >= thePainters.size())
65                return;
66        //QVector<FeaturePainter>::iterator theIterator = thePainters.begin();
67        thePainters.insert(thePainters.begin() + idx, FeaturePainter(thePainters[idx]));
68        idx++;
69        PaintList->insertItem(idx, thePainters[idx].userName());
70        PaintList->setCurrentRow(idx);
71        on_PaintList_itemClicked(PaintList->item(PaintList->currentRow()));
72}
73
74void PaintStyleEditor::on_RemoveButton_clicked()
75{
76        FreezeUpdate = true;
77        int idx = PaintList->currentRow();
78        if (idx >= thePainters.size())
79                return;
80        thePainters.erase(thePainters.begin() + idx);
81        delete PaintList->takeItem(idx);
82        if (idx && (idx >= thePainters.size()))
83                --idx;
84        PaintList->setCurrentRow(idx);
85        on_PaintList_itemClicked(PaintList->item(PaintList->currentRow()));
86}
87
88void PaintStyleEditor::on_btUp_clicked()
89{
90        unsigned int idx = static_cast<unsigned int>(PaintList->currentRow());
91        if (idx <= 0)
92                return;
93        FeaturePainter fp = thePainters[idx-1];
94        thePainters[idx-1] = thePainters[idx];
95        thePainters[idx] = fp;
96        PaintList->item(idx-1)->setText(thePainters[idx-1].userName());
97        PaintList->item(idx)->setText(thePainters[idx].userName());
98        PaintList->setCurrentRow(idx-1);
99}
100
101void PaintStyleEditor::on_btDown_clicked()
102{
103        int idx = PaintList->currentRow();
104        if (idx >= thePainters.size())
105                return;
106        FeaturePainter fp = thePainters[idx+1];
107        thePainters[idx+1] = thePainters[idx];
108        thePainters[idx] = fp;
109        PaintList->item(idx+1)->setText(thePainters[idx+1].userName());
110        PaintList->item(idx)->setText(thePainters[idx].userName());
111        PaintList->setCurrentRow(idx+1);
112}
113
114void PaintStyleEditor::on_PaintList_itemClicked(QListWidgetItem* it)
115{
116        Q_UNUSED(it)
117                       
118        FreezeUpdate = true;
119        int idx = PaintList->currentRow();
120        if (idx >= thePainters.size())
121                return;
122        FeaturePainter& FP(thePainters[idx]);
123        TagSelection->setText(FP.userName());
124        if (FP.zoomBoundaries().first == 0)
125                LowerZoomBoundary->setValue(0);
126        else
127                LowerZoomBoundary->setValue(1 / FP.zoomBoundaries().first);
128        if ((FP.zoomBoundaries().second == 0) || (FP.zoomBoundaries().second > 10e5))
129                UpperZoomBoundary->setValue(0);
130        else
131                UpperZoomBoundary->setValue(1 / FP.zoomBoundaries().second);
132        DrawBackground->setChecked(FP.backgroundBoundary().Draw);
133        ProportionalBackground->setValue(FP.backgroundBoundary().Proportional);
134        FixedBackground->setValue(FP.backgroundBoundary().Fixed);
135        makeBoundaryIcon(BackgroundColor, FP.backgroundBoundary().Color);
136        DrawForeground->setChecked(FP.foregroundBoundary().Draw);
137        ProportionalForeground->setValue(FP.foregroundBoundary().Proportional);
138        FixedForeground->setValue(FP.foregroundBoundary().Fixed);
139        makeBoundaryIcon(ForegroundColor, FP.foregroundBoundary().Color);
140        ForegroundDashed->setChecked(FP.foregroundBoundary().Dashed);
141        ForegroundDashOn->setValue(FP.foregroundBoundary().DashOn);
142        ForegroundDashOff->setValue(FP.foregroundBoundary().DashOff);
143        DrawTouchup->setChecked(FP.touchupBoundary().Draw);
144        ProportionalTouchup->setValue(FP.touchupBoundary().Proportional);
145        FixedTouchup->setValue(FP.touchupBoundary().Fixed);
146        makeBoundaryIcon(TouchupColor, FP.touchupBoundary().Color);
147        TouchupDashed->setChecked(FP.touchupBoundary().Dashed);
148        TouchupDashOn->setValue(FP.touchupBoundary().DashOn);
149        TouchupDashOff->setValue(FP.touchupBoundary().DashOff);
150        DrawFill->setChecked(FP.fillColor().isValid());
151        makeBoundaryIcon(FillColor, FP.fillColor());
152        DrawIcon->setChecked(FP.icon().Draw);
153        IconName->setText(FP.icon().Name);
154        ProportionalIcon->setValue(FP.icon().Proportional);
155        FixedIcon->setValue(FP.icon().Fixed);
156        DrawLabel->setChecked(FP.labelBoundary().Draw);
157        makeBoundaryIcon(LabelColor, FP.labelBoundary().Color);
158        ProportionalLabel->setValue(FP.labelBoundary().Proportional);
159        FixedLabel->setValue(FP.labelBoundary().Fixed);
160        DrawLabelBackground->setChecked(FP.labelBackgroundColor().isValid());
161        makeBoundaryIcon(LabelBackgroundlColor, FP.labelBackgroundColor());
162        LabelFont->setCurrentFont(FP.getLabelFont());
163        LabelTag->setText(FP.getLabelTag());
164        LabelBackgroundTag->setText(FP.getLabelBackgroundTag());
165        LabelHalo->setChecked(FP.getLabelHalo());
166        LabelArea->setChecked(FP.getLabelArea());
167       
168        FreezeUpdate = false;
169}
170
171void PaintStyleEditor::on_TagSelection_editingFinished()
172{
173        updatePaintList();
174}
175
176void PaintStyleEditor::on_LowerZoomBoundary_valueChanged()
177{
178        if (FreezeUpdate)
179                return;
180        int idx = PaintList->currentRow();
181        if (idx >= thePainters.size())
182                return;
183        FeaturePainter& FP(thePainters[idx]);
184        std::pair<double, double> Result(0, 0);
185        if (LowerZoomBoundary->value() > 10e-6)
186                Result.first = 1 / LowerZoomBoundary->value();
187        if (UpperZoomBoundary->value() > 10e-6)
188                Result.second = 1 / UpperZoomBoundary->value();
189        else
190                Result.second = 10e6;
191        FP.zoomBoundary(Result.first, Result.second);
192}
193
194void PaintStyleEditor::on_UpperZoomBoundary_valueChanged()
195{
196        on_LowerZoomBoundary_valueChanged();
197}
198
199void PaintStyleEditor::on_DrawGlobalBackground_clicked(bool b)
200{
201        theGlobalPainter.backgroundActive(b);
202}
203
204void PaintStyleEditor::on_GlobalBackgroundColor_clicked()
205{
206        bool OK = false;
207        QRgb rgb = QColorDialog::getRgba(theGlobalPainter.getBackgroundColor().rgba(), &OK, this);
208        if (OK) {
209                makeBoundaryIcon(GlobalBackgroundColor, QColor::fromRgba(rgb));
210                theGlobalPainter.background(QColor::fromRgba(rgb));
211        }
212}
213
214void PaintStyleEditor::on_DrawBackground_clicked(bool b)
215{
216        int idx = PaintList->currentRow();
217        if (idx >= thePainters.size())
218                return;
219        thePainters[idx].backgroundActive(b);
220}
221
222void PaintStyleEditor::on_BackgroundColor_clicked()
223{
224        int idx = PaintList->currentRow();
225        if (idx >= thePainters.size())
226                return;
227        FeaturePainter& FP(thePainters[idx]);
228        bool OK = false;
229        QRgb rgb = QColorDialog::getRgba(FP.backgroundBoundary().Color.rgba(), &OK, this);
230        if (OK) {
231                makeBoundaryIcon(BackgroundColor, QColor::fromRgba(rgb));
232                FP.background(QColor::fromRgba(rgb), ProportionalBackground->value(), FixedBackground->value());
233        }
234}
235
236void PaintStyleEditor::on_ProportionalBackground_valueChanged()
237{
238        if (FreezeUpdate)
239                return;
240        int idx = PaintList->currentRow();
241        if (idx >= thePainters.size())
242                return;
243        FeaturePainter& FP(thePainters[idx]);
244        FP.background(FP.backgroundBoundary().Color, ProportionalBackground->value(), FixedBackground->value());
245}
246
247void PaintStyleEditor::on_FixedBackground_valueChanged()
248{
249        on_ProportionalBackground_valueChanged();
250}
251
252void PaintStyleEditor::on_DrawForeground_clicked(bool b)
253{
254        int idx = PaintList->currentRow();
255        if (idx >= thePainters.size())
256                return;
257        thePainters[idx].foregroundActive(b);
258}
259
260
261void PaintStyleEditor::on_ForegroundColor_clicked()
262{
263        int idx = PaintList->currentRow();
264        if (idx >= thePainters.size())
265                return;
266        FeaturePainter& FP(thePainters[idx]);
267        bool OK = false;
268        QRgb rgb = QColorDialog::getRgba(FP.foregroundBoundary().Color.rgba(), &OK, this);
269        if (OK) {
270                makeBoundaryIcon(ForegroundColor, QColor::fromRgba(rgb));
271                FP.foreground(QColor::fromRgba(rgb), ProportionalForeground->value(), FixedForeground->value());
272        }
273}
274
275void PaintStyleEditor::on_ProportionalForeground_valueChanged()
276{
277        if (FreezeUpdate)
278                return;
279        int idx = PaintList->currentRow();
280        if (idx >= thePainters.size())
281                return;
282        FeaturePainter& FP(thePainters[idx]);
283        FP.foreground(FP.foregroundBoundary().Color, ProportionalForeground->value(), FixedForeground->value());
284}
285
286void PaintStyleEditor::on_FixedForeground_valueChanged()
287{
288        on_ProportionalForeground_valueChanged();
289}
290
291
292void PaintStyleEditor::on_ForegroundDashed_clicked()
293{
294        if (FreezeUpdate)
295                return;
296        int idx = PaintList->currentRow();
297        if (idx >= thePainters.size())
298                return;
299        FeaturePainter& FP(thePainters[idx]);
300        if (ForegroundDashed->isChecked())
301                FP.foregroundDash(ForegroundDashOn->value(), ForegroundDashOff->value());
302        else
303                FP.clearForegroundDash();
304}
305
306void PaintStyleEditor::on_ForegroundDashOff_valueChanged()
307{
308        on_ForegroundDashed_clicked();
309}
310
311void PaintStyleEditor::on_ForegroundDashOn_valueChanged()
312{
313        on_ForegroundDashed_clicked();
314}
315
316void PaintStyleEditor::on_DrawTouchup_clicked(bool b)
317{
318        int idx = PaintList->currentRow();
319        if (idx >= thePainters.size())
320                return;
321        thePainters[idx].touchupActive(b);
322}
323
324void PaintStyleEditor::on_TouchupColor_clicked()
325{
326        int idx = PaintList->currentRow();
327        if (idx >= thePainters.size())
328                return;
329        FeaturePainter& FP(thePainters[idx]);
330        bool OK = false;
331        QRgb rgb = QColorDialog::getRgba(FP.touchupBoundary().Color.rgba(), &OK, this);
332        if (OK) {
333                makeBoundaryIcon(TouchupColor, QColor::fromRgba(rgb));
334                FP.touchup(QColor::fromRgba(rgb), ProportionalTouchup->value(), FixedTouchup->value());
335        }
336}
337
338void PaintStyleEditor::on_ProportionalTouchup_valueChanged()
339{
340        if (FreezeUpdate)
341                return;
342        int idx = PaintList->currentRow();
343        if (idx >= thePainters.size())
344                return;
345        FeaturePainter& FP(thePainters[idx]);
346        FP.touchup(FP.touchupBoundary().Color, ProportionalTouchup->value(), FixedTouchup->value());
347}
348
349void PaintStyleEditor::on_FixedTouchup_valueChanged()
350{
351        on_ProportionalTouchup_valueChanged();
352}
353
354
355void PaintStyleEditor::on_TouchupDashed_clicked()
356{
357        if (FreezeUpdate)
358                return;
359        int idx = PaintList->currentRow();
360        if (idx >= thePainters.size())
361                return;
362        FeaturePainter& FP(thePainters[idx]);
363        if (TouchupDashed->isChecked())
364                FP.touchupDash(TouchupDashOn->value(), TouchupDashOff->value());
365        else
366                FP.clearTouchupDash();
367}
368
369void PaintStyleEditor::on_TouchupDashOff_valueChanged()
370{
371        on_TouchupDashed_clicked();
372}
373
374void PaintStyleEditor::on_TouchupDashOn_valueChanged()
375{
376        on_TouchupDashed_clicked();
377}
378
379void PaintStyleEditor::on_DrawFill_clicked(bool b)
380{
381        int idx = PaintList->currentRow();
382        if (idx >= thePainters.size())
383                return;
384        thePainters[idx].fillActive(b);
385}
386
387void PaintStyleEditor::on_FillColor_clicked()
388{
389        int idx = PaintList->currentRow();
390        if (idx >= thePainters.size())
391                return;
392        FeaturePainter& FP(thePainters[idx]);
393        bool OK = false;
394        QRgb rgb = QColorDialog::getRgba(FP.fillColor().rgba(), &OK, this);
395        if (OK) {
396                makeBoundaryIcon(FillColor, QColor::fromRgba(rgb));
397                FP.foregroundFill(QColor::fromRgba(rgb));
398        }
399}
400
401void PaintStyleEditor::on_DrawIcon_clicked(bool b)
402{
403        int idx = PaintList->currentRow();
404        if (idx >= thePainters.size())
405                return;
406        thePainters[idx].iconActive(b);
407}
408
409void PaintStyleEditor::on_IconName_textEdited()
410{
411        if (FreezeUpdate)
412                return;
413        int idx = PaintList->currentRow();
414        if (idx >= thePainters.size())
415                return;
416        FeaturePainter& FP(thePainters[idx]);
417        FP.setIcon(IconName->text(), ProportionalIcon->value(), FixedIcon->value());
418}
419
420void PaintStyleEditor::on_ProportionalIcon_valueChanged()
421{
422        on_IconName_textEdited();
423}
424
425void PaintStyleEditor::on_FixedIcon_valueChanged()
426{
427        on_IconName_textEdited();
428}
429
430void PaintStyleEditor::on_DrawLabel_clicked(bool b)
431{
432        int idx = PaintList->currentRow();
433        if (idx >= thePainters.size())
434                return;
435        thePainters[idx].labelActive(b);
436}
437
438void PaintStyleEditor::on_LabelHalo_clicked(bool b)
439{
440        int idx = PaintList->currentRow();
441        if (idx >= thePainters.size())
442                return;
443        thePainters[idx].labelHalo(b);
444}
445
446void PaintStyleEditor::on_LabelArea_clicked(bool b)
447{
448        int idx = PaintList->currentRow();
449        if (idx >= thePainters.size())
450                return;
451        thePainters[idx].labelArea(b);
452}
453
454void PaintStyleEditor::on_LabelTag_textEdited()
455{
456        int idx = PaintList->currentRow();
457        if (idx >= thePainters.size())
458                return;
459        thePainters[idx].labelTag(LabelTag->text());
460}
461
462void PaintStyleEditor::on_LabelBackgroundTag_textEdited()
463{
464        int idx = PaintList->currentRow();
465        if (idx >= thePainters.size())
466                return;
467        thePainters[idx].labelBackgroundTag(LabelBackgroundTag->text());
468}
469
470void PaintStyleEditor::on_LabelColor_clicked()
471{
472        int idx = PaintList->currentRow();
473        if (idx >= thePainters.size())
474                return;
475        FeaturePainter& FP(thePainters[idx]);
476        bool OK = false;
477        QRgb rgb = QColorDialog::getRgba(FP.labelBoundary().Color.rgba(), &OK, this);
478        if (OK) {
479                makeBoundaryIcon(LabelColor, QColor::fromRgba(rgb));
480                FP.label(QColor::fromRgba(rgb), ProportionalLabel->value(), FixedLabel->value());
481        }
482}
483
484void PaintStyleEditor::on_ProportionalLabel_valueChanged()
485{
486        if (FreezeUpdate)
487                return;
488        int idx = PaintList->currentRow();
489        if (idx >= thePainters.size())
490                return;
491        FeaturePainter& FP(thePainters[idx]);
492        FP.label(FP.labelBoundary().Color, ProportionalLabel->value(), FixedLabel->value());
493}
494
495void PaintStyleEditor::on_FixedLabel_valueChanged()
496{
497        on_ProportionalLabel_valueChanged();
498}
499
500void PaintStyleEditor::on_DrawLabelBackground_clicked(bool b)
501{
502        int idx = PaintList->currentRow();
503        if (idx >= thePainters.size())
504                return;
505        thePainters[idx].labelBackgroundActive(b);
506}
507
508void PaintStyleEditor::on_LabelBackgroundlColor_clicked()
509{
510        int idx = PaintList->currentRow();
511        if (idx >= thePainters.size())
512                return;
513        FeaturePainter& FP(thePainters[idx]);
514        bool OK = false;
515        QRgb rgb = QColorDialog::getRgba(FP.labelBackgroundColor().rgba(), &OK, this);
516        if (OK) {
517                makeBoundaryIcon(LabelBackgroundlColor, QColor::fromRgba(rgb));
518                FP.labelBackground(QColor::fromRgba(rgb));
519        }
520}
521
522void PaintStyleEditor::on_LabelFont_currentFontChanged(const QFont & font)
523{
524        int idx = PaintList->currentRow();
525        if (idx >= thePainters.size())
526                return;
527        thePainters[idx].setLabelFont(font.toString());
528}
529
530void PaintStyleEditor::updatePaintList()
531{
532        int idx = PaintList->currentRow();
533        if (idx >= thePainters.size())
534                return;
535        FeaturePainter& FP(thePainters[idx]);
536        FP.setSelector(TagSelection->text());
537        PaintList->currentItem()->setText(FP.userName());
538}
539
540void PaintStyleEditor::on_buttonBox_clicked(QAbstractButton * button)
541{
542        if (buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole) {
543                emit(stylesApplied(&thePainters));
544        }
545}
546
Note: See TracBrowser for help on using the repository browser.