-
Notifications
You must be signed in to change notification settings - Fork 4
/
ccColorScaleEditorWidget.cpp
794 lines (655 loc) · 19.5 KB
/
ccColorScaleEditorWidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
//##########################################################################
//# #
//# CLOUDCOMPARE #
//# #
//# This program is free software; you can redistribute it and/or modify #
//# it under the terms of the GNU General Public License as published by #
//# the Free Software Foundation; version 2 of the License. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU General Public License for more details. #
//# #
//# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
//# #
//##########################################################################
//Inspired from ccColorScaleEditorWidget by Richard Steffen (LGPL 2.1)
#include "ccColorScaleEditorWidget.h"
//Qt
#include <QColorDialog>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPainter>
#include <QMouseEvent>
//System
#include <assert.h>
static const int DEFAULT_SLIDER_SYMBOL_SIZE = 8;
static const int DEFAULT_MARGIN = DEFAULT_SLIDER_SYMBOL_SIZE/2+1;
static const int DEFAULT_TEXT_MARGIN = 2;
static const int DEFAULT_LABEL_HEIGHT = 12;
/*******************************/
/*** ColorScaleElementSlider ***/
/*******************************/
ColorScaleElementSlider::ColorScaleElementSlider(double relativePos/*=0.0*/, QColor color/*=Qt::black*/, QWidget* parent/*=0*/, Qt::Orientation orientation/*=Qt::Horizontal*/)
: QWidget(parent)
, ccColorScaleElement(relativePos,color)
, m_selected(false)
, m_orientation(orientation)
{
if (m_orientation == Qt::Horizontal)
setFixedSize(DEFAULT_SLIDER_SYMBOL_SIZE, 2*DEFAULT_SLIDER_SYMBOL_SIZE);
else
setFixedSize(2*DEFAULT_SLIDER_SYMBOL_SIZE, DEFAULT_SLIDER_SYMBOL_SIZE);
}
void ColorScaleElementSlider::paintEvent(QPaintEvent* e)
{
QPainter painter(this);
painter.setPen(m_selected ? Qt::red : Qt::black);
painter.setBrush(m_color);
QRect box(0,0,DEFAULT_SLIDER_SYMBOL_SIZE-1,DEFAULT_SLIDER_SYMBOL_SIZE-1);
QPolygon pointyHead;
if (m_orientation == Qt::Horizontal)
{
box.moveTop(DEFAULT_SLIDER_SYMBOL_SIZE-1);
pointyHead << QPoint(0,DEFAULT_SLIDER_SYMBOL_SIZE-1) << QPoint(DEFAULT_SLIDER_SYMBOL_SIZE/2,0) << QPoint(DEFAULT_SLIDER_SYMBOL_SIZE-1,DEFAULT_SLIDER_SYMBOL_SIZE-1);
}
else
{
box.moveLeft(DEFAULT_SLIDER_SYMBOL_SIZE-1);
pointyHead << QPoint(DEFAULT_SLIDER_SYMBOL_SIZE-1,0) << QPoint(0,DEFAULT_SLIDER_SYMBOL_SIZE/2) << QPoint(DEFAULT_SLIDER_SYMBOL_SIZE-1,DEFAULT_SLIDER_SYMBOL_SIZE-1);
}
painter.drawRect(box);
painter.drawPolygon(pointyHead, Qt::OddEvenFill);
}
/********************************/
/*** ColorScaleElementSliders ***/
/********************************/
void ColorScaleElementSliders::addSlider(ColorScaleElementSlider* slider)
{
assert(slider);
if (slider)
{
push_back(slider);
sort();
}
}
void ColorScaleElementSliders::sort()
{
qSort(begin(), end(), ColorScaleElementSlider::IsSmaller);
}
void ColorScaleElementSliders::clear()
{
while (!isEmpty())
{
back()->setParent(0);
delete back();
pop_back();
}
}
void ColorScaleElementSliders::removeAt(int i)
{
if (i < 0 || i >= size())
{
assert(false);
return;
}
ColorScaleElementSlider* slider = at(i);
if (slider)
{
slider->setParent(0);
delete slider;
slider = 0;
}
QList<ColorScaleElementSlider*>::removeAt(i);
}
int ColorScaleElementSliders::selected() const
{
for (int i=0; i<size(); ++i)
if (at(i)->isSelected())
return i;
return -1;
}
int ColorScaleElementSliders::indexOf(ColorScaleElementSlider* slider)
{
for (int i=0; i<size(); ++i)
if (at(i) == slider)
return i;
return -1;
}
/**********************/
/*** ColorBarWidget ***/
/**********************/
ColorBarWidget::ColorBarWidget(SharedColorScaleElementSliders sliders, QWidget* parent/*=0*/, Qt::Orientation orientation/*=Qt::Horizontal*/)
: ColorScaleEditorBaseWidget(sliders, orientation, DEFAULT_MARGIN, parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setContentsMargins(0,0,0,0);
setMinimumSize(DEFAULT_MARGIN*3,DEFAULT_MARGIN*3);
}
void ColorBarWidget::mousePressEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton)
{
QRect contentRect = contentsRect();
if (m_orientation == Qt::Horizontal)
contentRect.adjust(m_margin,0,-m_margin,0);
else
contentRect.adjust(0,m_margin,0,-m_margin);
if (contentRect.contains(e->pos(), true))
{
double relativePos = -1.0;
if (m_orientation == Qt::Horizontal)
{
relativePos = static_cast<double>(e->pos().x()-contentRect.left())/contentRect.width();
}
else
{
relativePos = static_cast<double>(e->pos().y()-contentRect.top())/contentRect.height();
}
emit pointClicked(relativePos);
e->accept();
return;
}
}
e->ignore();
}
void ColorBarWidget::paintEvent(QPaintEvent* e)
{
if (m_sliders && m_sliders->size() >= 2)
{
QPainter painter(this);
painter.setPen(Qt::black);
QRect contentRect = contentsRect();
if (m_orientation == Qt::Horizontal)
contentRect.adjust(m_margin,0,-m_margin,-1);
else
contentRect.adjust(0,m_margin,-1,-m_margin);
assert(m_sliders->front()->getRelativePos() == 0.0 && m_sliders->back()->getRelativePos() == 1.0);
//color gradient
{
QLinearGradient gradient;
if (m_orientation == Qt::Horizontal)
gradient = QLinearGradient(contentRect.left(), 0, contentRect.right(), 0);
else
gradient = QLinearGradient(0, contentRect.bottom(), 0, contentRect.top());
//fill gradient with sliders
{
for (int i=0; i<m_sliders->size(); i++)
{
gradient.setColorAt(m_sliders->at(i)->getRelativePos(), m_sliders->at(i)->getColor());
}
}
painter.fillRect(contentRect, gradient);
painter.drawRect(contentRect);
}
//draw a line for each slider position (apart from the first and the last one)
{
QPoint A = contentRect.topLeft();
QPoint B = contentRect.bottomRight();
for (int i=0; i<m_sliders->size(); i++)
{
double relativePos = m_sliders->at(i)->getRelativePos();
if (m_orientation == Qt::Horizontal)
{
int pos = contentRect.left() + (int)(relativePos * (double)contentRect.width());
A.setX(pos);
B.setX(pos);
}
else
{
int pos = contentRect.top() + (int)(relativePos * (double)contentRect.height());
A.setY(pos);
B.setY(pos);
}
painter.drawLine(A,B);
}
}
}
QWidget::paintEvent(e);
}
/*********************/
/*** SlidersWidget ***/
/*********************/
SlidersWidget::SlidersWidget(SharedColorScaleElementSliders sliders, QWidget* parent/*=0*/, Qt::Orientation orientation/*=Qt::Horizontal*/)
: ColorScaleEditorBaseWidget(sliders,orientation,DEFAULT_MARGIN,parent)
{
setContentsMargins(0,0,0,0);
if (m_orientation == Qt::Horizontal)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
setMinimumSize(0,2*DEFAULT_SLIDER_SYMBOL_SIZE);
}
else
{
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
setMinimumSize(2*DEFAULT_SLIDER_SYMBOL_SIZE,0);
}
}
void SlidersWidget::select(int index, bool silent/*=false*/)
{
assert(m_sliders);
//look for previously selected slider
int activeSliderIndex = m_sliders->selected();
if (index == activeSliderIndex) //nothing to do
return;
//deselect old one (if any)
if (activeSliderIndex >= 0)
m_sliders->at(activeSliderIndex)->setSelected(false);
//select new one (if any)
if (index >= 0)
m_sliders->at(index)->setSelected(true);
if (!silent)
emit sliderSelected(index);
}
ColorScaleElementSlider* SlidersWidget::addNewSlider(double relativePos, QColor color)
{
select(-1); //be sure to deselect any selected slider before modifying the global set contents!
ColorScaleElementSlider* slider = new ColorScaleElementSlider(relativePos, color, this, m_orientation);
m_sliders->addSlider(slider);
int pos = (int)((double)length() * relativePos);
if (m_orientation == Qt::Horizontal)
{
pos += DEFAULT_MARGIN - slider->width()/2;
slider->move(pos,0);
}
else
{
pos += DEFAULT_MARGIN - slider->height()/2;
slider->move(0,pos);
}
slider->setVisible(true);
return slider;
}
void SlidersWidget::resizeEvent(QResizeEvent* e)
{
updateAllSlidersPos();
}
void SlidersWidget::updateAllSlidersPos()
{
if (!m_sliders || m_sliders->size() < 2)
return;
int rectLength = length();
for (ColorScaleElementSliders::iterator it = m_sliders->begin(); it != m_sliders->end(); ++it)
{
ColorScaleElementSlider* slider = *it;
int pos = (int)(slider->getRelativePos() * (double)rectLength);
if (m_orientation == Qt::Horizontal)
{
pos += DEFAULT_MARGIN - slider->width()/2;
slider->move(pos,0);
}
else
{
pos += DEFAULT_MARGIN - slider->height()/2;
slider->move(0,pos);
}
}
}
void SlidersWidget::updateSliderPos(int index)
{
if (!m_sliders || m_sliders->size() < 2 || index < 0)
return;
ColorScaleElementSlider* slider = m_sliders->at(index);
int pos = static_cast<int>(slider->getRelativePos() * (double)length());
if (m_orientation == Qt::Horizontal)
{
pos += DEFAULT_MARGIN - slider->width()/2;
slider->move(pos,0);
}
else
{
pos += DEFAULT_MARGIN - slider->height()/2;
slider->move(0,pos);
}
}
void SlidersWidget::mousePressEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton)
{
if (!m_sliders || m_sliders->size() < 2)
return;
for (int i=0; i<m_sliders->size(); i++)
{
QRect rect = m_sliders->at(i)->geometry();
if (rect.contains(e->pos(), true))
{
select(i);
e->accept();
break;
}
}
}
}
void SlidersWidget::mouseMoveEvent(QMouseEvent* e)
{
if (!m_sliders || m_sliders->size() <= 2)
return;
int pos = (m_orientation == Qt::Horizontal ? e->pos().x() : e->pos().y());
double relativePos = (double)(pos-DEFAULT_MARGIN)/(double)length();
if (relativePos > 0.0 && relativePos < 1.0)
{
int activeSliderIndex = m_sliders->selected();
if (activeSliderIndex > 0 && activeSliderIndex+1 < m_sliders->size()) //first and last sliders can't move!
{
ColorScaleElementSlider* slider = m_sliders->at(activeSliderIndex);
assert(slider && slider->isSelected());
if (m_orientation == Qt::Horizontal)
slider->move(pos - slider->width()/2, 0);
else
slider->move(0,pos - slider->height()/2);
slider->setRelativePos(relativePos);
m_sliders->sort();
emit sliderModified(activeSliderIndex);
e->accept();
//update();
}
}
}
//void SlidersWidget::mouseReleaseEvent(QMouseEvent* e)
//{
//}
void SlidersWidget::mouseDoubleClickEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton)
{
for (int i=0; i< m_sliders->size(); i++)
{
QRect rect = m_sliders->at(i)->geometry();
if (rect.contains(e->pos(), true))
{
select(i);
ColorScaleElementSlider* slider = m_sliders->at(i);
assert(slider && slider->isSelected());
//spawn a color choosing dialog?
QColor newColor = QColorDialog::getColor(m_sliders->at(i)->getColor(),this);
if (newColor.isValid() && newColor != slider->getColor())
{
slider->setColor(newColor);
emit sliderModified(i);
}
break;
}
}
}
}
/*************************/
/*** SliderLabelWidget ***/
/*************************/
SliderLabelWidget::SliderLabelWidget(SharedColorScaleElementSliders sliders, QWidget* parent/*=0*/, Qt::Orientation orientation/*=Qt::Horizontal*/)
: ColorScaleEditorBaseWidget(sliders,orientation,DEFAULT_MARGIN,parent)
, m_textColor(Qt::black)
, m_precision(6)
{
setContentsMargins(0,0,0,0);
}
void SliderLabelWidget::paintEvent(QPaintEvent* e)
{
if (m_sliders)
{
QPainter painter(this);
QFont font = painter.font();
font.setPixelSize(8);
painter.setFont(font);
painter.setPen(m_textColor);
painter.setBrush(m_textColor);
QFontMetrics fm(font);
if (m_orientation == Qt::Horizontal)
{
int labelHeight = fm.height()+DEFAULT_TEXT_MARGIN;
//adjust height if necessary
setMinimumSize(0,labelHeight);
for (int i=0; i<m_sliders->size(); i++)
{
int pos = m_sliders->at(i)->pos().x();
double val = m_sliders->at(i)->getRelativePos();
QString label = QString("%1 %").arg(val*100.0, 0, 'f', std::max(m_precision-2,0)); //display as a percentage
int labelWidth = fm.width(label);
if (pos+labelWidth > width())
pos -= (labelWidth - m_sliders->at(i)->width());
painter.drawText(pos, labelHeight, label);
}
}
else
{
//adjust width if necessary
{
QString firstLabel = QString::number(m_sliders->first()->getRelativePos(), 'f', m_precision);
QString lastLabel = QString::number(m_sliders->last()->getRelativePos(), 'f', m_precision);
int labelWidth = std::max(fm.width(firstLabel),fm.width(lastLabel))+2*DEFAULT_TEXT_MARGIN;
setMinimumSize(labelWidth,0);
}
// draw the text for vertical orientation
for (int i=0; i<m_sliders->size(); i++)
{
int pos = m_sliders->at(i)->pos().y();
double val = m_sliders->at(i)->getRelativePos();
QString label = QString("%1 %").arg(val*100.0, 0, 'f', std::max(m_precision-2,0)); //display as a percentage
painter.drawText(DEFAULT_TEXT_MARGIN, pos + m_sliders->at(i)->height(), label);
}
}
}
QWidget::paintEvent(e);
}
/********************************/
/*** ccColorScaleEditorWidget ***/
/********************************/
ccColorScaleEditorWidget::ccColorScaleEditorWidget(QWidget* parent/*=0*/, Qt::Orientation orientation/*=Qt::Horizontal*/)
: ColorScaleEditorBaseWidget(SharedColorScaleElementSliders(new ColorScaleElementSliders), orientation, 0, parent)
{
//size and margin
setMinimumSize(40,40);
setContentsMargins(0,0,0,0);
//layout
setLayout(m_orientation == Qt::Horizontal ? static_cast<QLayout*>(new QVBoxLayout()) : static_cast<QLayout*>(new QHBoxLayout()));
layout()->setMargin(0);
layout()->setSpacing(0);
layout()->setContentsMargins(0,0,0,0);
//color bar
{
m_colorBarWidget = new ColorBarWidget(m_sliders,parent,orientation);
m_colorBarWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_colorBarWidget->setContentsMargins(0,0,0,0);
layout()->addWidget(m_colorBarWidget);
connect(m_colorBarWidget, SIGNAL(pointClicked(double)), this, SLOT(onPointClicked(double)));
}
//sliders widget
{
m_slidersWidget = new SlidersWidget(m_sliders,parent,orientation);
m_slidersWidget->setContentsMargins(0,0,0,0);
layout()->addWidget(m_slidersWidget);
//add default min and max elements
m_slidersWidget->addNewSlider(0.0,Qt::blue);
m_slidersWidget->addNewSlider(1.0,Qt::red);
connect(m_slidersWidget, SIGNAL(sliderModified(int)), this, SLOT(onSliderModified(int)));
connect(m_slidersWidget, SIGNAL(sliderSelected(int)), this, SLOT(onSliderSelected(int)));
}
//Labels widget
{
m_labelsWidget = new SliderLabelWidget(m_sliders,parent,orientation);
if (m_orientation == Qt::Horizontal)
{
m_labelsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_labelsWidget->setFixedHeight(DEFAULT_LABEL_HEIGHT);
}
else
{
m_labelsWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
m_labelsWidget->setFixedWidth(DEFAULT_LABEL_HEIGHT);
}
layout()->addWidget(m_labelsWidget);
m_labelsWidget->setVisible(false); //hidden by default
}
}
ccColorScaleEditorWidget::~ccColorScaleEditorWidget()
{
//Qt will take care of its sibliings!
}
void ccColorScaleEditorWidget::onPointClicked(double relativePos)
{
assert(relativePos>= 0.0 && relativePos <= 1.0);
assert(m_colorBarWidget && m_slidersWidget);
if (!m_sliders)
return;
//look first if this position corresponds to an already existing slider
const double maxDist = static_cast<double>(DEFAULT_SLIDER_SYMBOL_SIZE)/m_colorBarWidget->length();
for (int i=0; i<m_sliders->size(); ++i)
{
if (fabs(m_sliders->at(i)->getRelativePos() - relativePos) < maxDist)
{
m_slidersWidget->select(i);
return;
}
}
//determine the new slider defaut color
QColor color = Qt::white;
if (m_sliders->size() > 1)
{
QLinearGradient gradient(0,0,256,0);
//fill gradient with sliders
for (int i=0; i<m_sliders->size(); i++)
{
gradient.setColorAt(m_sliders->at(i)->getRelativePos(), m_sliders->at(i)->getColor());
}
//generate fake color bar (1 pixel high)
QPixmap pix(256,1);
QPainter painter(&pix);
painter.fillRect(pix.rect(), gradient);
color = pix.toImage().pixel(static_cast<int>(relativePos*255),0);
}
ColorScaleElementSlider* slider = m_slidersWidget->addNewSlider(relativePos, color);
if (slider)
{
int pos = m_sliders->indexOf(slider);
if (pos >= 0)
{
m_slidersWidget->select(pos);
onSliderModified(pos);
}
}
update();
}
void ccColorScaleEditorWidget::onSliderModified(int sliderIndex)
{
if (sliderIndex < 0)
{
assert(false);
return;
}
if (m_colorBarWidget)
m_colorBarWidget->update();
if (m_slidersWidget)
m_slidersWidget->update();
if (m_labelsWidget)
m_labelsWidget->update();
emit stepModified(sliderIndex);
}
void ccColorScaleEditorWidget::setSliders(SharedColorScaleElementSliders sliders)
{
if (m_sliders)
{
//onSliderSelected(-1);
//release all previously defined sliders
m_sliders->clear();
}
for (int i=0; i<sliders->size(); ++i)
m_slidersWidget->addNewSlider(sliders->at(i)->getRelativePos(),sliders->at(i)->getColor());
update();
}
void ccColorScaleEditorWidget::onSliderSelected(int sliderIndex)
{
if (m_slidersWidget)
m_slidersWidget->update();
emit stepSelected(sliderIndex);
}
void ccColorScaleEditorWidget::importColorScale(ccColorScale::Shared scale)
{
m_sliders->clear();
if (scale)
{
assert(scale->stepCount() >= 2);
for (int i=0; i<scale->stepCount(); ++i)
{
double relativePos = scale->step(i).getRelativePos();
const QColor& color = scale->step(i).getColor();
m_slidersWidget->addNewSlider(relativePos,color);
}
}
update();
}
void ccColorScaleEditorWidget::exportColorScale(ccColorScale::Shared& destScale) const
{
if (!destScale)
return;
destScale->clear();
for (int i=0; i<m_sliders->size(); ++i)
destScale->insert(*m_sliders->at(i),false);
destScale->update();
}
void ccColorScaleEditorWidget::showLabels(bool state)
{
if (m_labelsWidget)
{
m_labelsWidget->setVisible(state);
m_labelsWidget->update();
}
}
void ccColorScaleEditorWidget::setLabelColor(QColor color)
{
if (m_labelsWidget)
{
m_labelsWidget->setTextColor(color);
m_labelsWidget->update();
}
}
void ccColorScaleEditorWidget::setLabelPrecision(int precision)
{
if (m_labelsWidget)
{
m_labelsWidget->setPrecision(precision);
m_labelsWidget->update();
}
}
void ccColorScaleEditorWidget::deleteStep(int index)
{
assert(m_sliders);
if (index >= 0)
{
if (m_sliders->at(index)->isSelected())
onSliderSelected(-1);
m_sliders->removeAt(index);
update();
}
}
void ccColorScaleEditorWidget::setSelectedStepIndex(int index, bool silent/*=false*/)
{
if (m_slidersWidget)
m_slidersWidget->select(index,silent);
}
void ccColorScaleEditorWidget::setStepColor(int index, QColor color)
{
if (index < 0)
return;
m_sliders->at(index)->setColor(color);
onSliderModified(index);
}
void ccColorScaleEditorWidget::setStepRelativePosition(int index, double relativePos)
{
if (index < 0)
return;
m_sliders->at(index)->setRelativePos(relativePos);
if (m_slidersWidget)
{
if (index == 0 || index+1 == m_sliders->size())
{
//update all sliders!
m_slidersWidget->updateAllSlidersPos();
}
else
{
//update only the selected one
m_slidersWidget->updateSliderPos(index);
}
}
onSliderModified(index);
}