All Classes Namespaces Functions Variables Enumerations Properties Pages
colorpalettewidget.cpp
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 #include "colorpalettewidget.h"
18 #include "ui_colorpalette.h"
19 
20 // Standard libraries
21 #include <cmath>
22 
23 // Qt
24 #include <QDebug>
25 #include <QListWidgetItem>
26 #include <QInputDialog>
27 #include <QColorDialog>
28 #include <QMessageBox>
29 #include <QPushButton>
30 #include <QSettings>
31 #include <QMenu>
32 #include <QtMath>
33 #include <QScrollBar>
34 #include <QAbstractItemModel>
35 #include <QPainter>
36 
37 // Project
38 #include "colorref.h"
39 #include "object.h"
40 #include "editor.h"
41 #include "layerbitmap.h"
42 #include "colormanager.h"
43 
44 
45 ColorPaletteWidget::ColorPaletteWidget(QWidget* parent) :
46  BaseDockWidget(parent),
47  ui(new Ui::ColorPalette)
48 {
49  ui->setupUi(this);
50 }
51 
52 ColorPaletteWidget::~ColorPaletteWidget()
53 {
54  delete ui;
55 }
56 
57 void ColorPaletteWidget::initUI()
58 {
59  QSettings settings(PENCIL2D, PENCIL2D);
60  int colorGridSize = settings.value("PreferredColorGridSize", 34).toInt();
61  mFitSwatches = settings.value("FitSwatchSize", false).toBool();
62  if (mFitSwatches)
63  {
64  fitSwatchSize();
65  }
66 
67  mIconSize = QSize(colorGridSize, colorGridSize);
68 
69  ui->colorListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
70 
71  QString sViewMode = settings.value("ColorPaletteViewMode", "ListMode").toString();
72  if (sViewMode == "ListMode")
73  setListMode();
74  else
75  setGridMode();
76 
77  buttonStylesheet = "::menu-indicator{ image: none; }"
78  "QPushButton { border: 0px; }"
79  "QPushButton:pressed { border: 1px solid #ADADAD; border-radius: 2px; background-color: #D5D5D5; }"
80  "QPushButton:checked { border: 1px solid #ADADAD; border-radius: 2px; background-color: #D5D5D5; }";
81 
82  ui->addColorButton->setStyleSheet(buttonStylesheet);
83  ui->removeColorButton->setStyleSheet(buttonStylesheet);
84  ui->colorDialogButton->setStyleSheet(buttonStylesheet);
85 
86  palettePreferences();
87 
88  connect(ui->colorListWidget, &QListWidget::itemClicked, this, &ColorPaletteWidget::clickColorListItem);
89  connect(ui->colorListWidget->model(), &QAbstractItemModel::rowsMoved, this, &ColorPaletteWidget::onRowsMoved);
90 
91  connect(ui->colorListWidget, &QListWidget::itemDoubleClicked, this, &ColorPaletteWidget::changeColorName);
92  connect(ui->colorListWidget, &QListWidget::itemChanged, this, &ColorPaletteWidget::onItemChanged);
93 
94  connect(ui->addColorButton, &QPushButton::clicked, this, &ColorPaletteWidget::clickAddColorButton);
95  connect(ui->colorDialogButton, &QPushButton::clicked, this, &ColorPaletteWidget::clickColorDialogButton);
96  connect(ui->removeColorButton, &QPushButton::clicked, this, &ColorPaletteWidget::clickRemoveColorButton);
97  connect(ui->colorListWidget, &QListWidget::customContextMenuRequested, this, &ColorPaletteWidget::showContextMenu);
98 
99  connect(editor(), &Editor::objectLoaded, this, &ColorPaletteWidget::updateUI);
100 }
101 
102 void ColorPaletteWidget::updateUI()
103 {
104  mObject = mEditor->object();
105  refreshColorList();
106  updateGridUI();
107 }
108 
109 void ColorPaletteWidget::setCore(Editor* editor)
110 {
111  mEditor = editor;
112  mObject = mEditor->object();
113 }
114 
115 void ColorPaletteWidget::showContextMenu(const QPoint& pos)
116 {
117  QPoint globalPos = ui->colorListWidget->mapToGlobal(pos);
118 
119  QMenu* menu = new QMenu;
121 
122  menu->addAction(tr("Add"), this, &ColorPaletteWidget::addItem, 0);
123  menu->addAction(tr("Replace"), this, &ColorPaletteWidget::replaceItem, 0);
124  menu->addAction(tr("Remove"), this, &ColorPaletteWidget::removeItem, 0);
125 
126  menu->exec(globalPos);
127 }
128 
129 void ColorPaletteWidget::addItem()
130 {
131  QSignalBlocker b(ui->colorListWidget);
132  QColor newColor = mEditor->color()->frontColor(false);
133 
134  ColorRef ref(newColor);
135 
136  const int colorIndex = ui->colorListWidget->count();
137  mObject->addColorAtIndex(colorIndex, ref);
138 
139  refreshColorList();
140 
141  if (mFitSwatches)
142  {
143  fitSwatchSize();
144  }
145 
146  QListWidgetItem* item = ui->colorListWidget->item(colorIndex);
147  ui->colorListWidget->editItem(item);
148  ui->colorListWidget->scrollToItem(item);
149 }
150 
151 void ColorPaletteWidget::replaceItem()
152 {
153  QSignalBlocker b(ui->colorListWidget);
154  int index = ui->colorListWidget->currentRow();
155 
156  QColor newColor = mEditor->color()->frontColor(false);
157 
158  if (index < 0 ) { return; }
159 
160  updateItemColor(index, newColor);
161  emit colorNumberChanged(index);
162  ui->colorListWidget->setCurrentRow(index);
163 }
164 
165 void ColorPaletteWidget::removeItem()
166 {
167  QSignalBlocker b(ui->colorListWidget);
168  clickRemoveColorButton();
169 }
170 
171 void ColorPaletteWidget::selectColorNumber(int colorNumber) const
172 {
173  ui->colorListWidget->setCurrentRow(colorNumber);
174 }
175 
176 int ColorPaletteWidget::currentColorNumber()
177 {
178  if (ui->colorListWidget->currentRow() < 0)
179  {
180  ui->colorListWidget->setCurrentRow(0);
181  }
182  return ui->colorListWidget->currentRow();
183 }
184 
185 void ColorPaletteWidget::refreshColorList()
186 {
187  QSignalBlocker b(ui->colorListWidget);
188  if (ui->colorListWidget->count() > 0)
189  {
190  ui->colorListWidget->clear();
191  }
192 
193  int colorCount = editor()->object()->getColorCount();
194 
195  for (int i = 0; i < colorCount; i++)
196  {
197  addSwatch(i);
198  }
199 
200  selectColorNumber(editor()->color()->frontColorNumber());
201  updateGridUI();
202  update();
203 }
204 
205 void ColorPaletteWidget::addSwatch(int colorIndex) const
206 {
207  QPixmap originalColorSwatch(mIconSize);
208  QPainter painter(&originalColorSwatch);
209  painter.drawTiledPixmap(0, 0, mIconSize.width(), mIconSize.height(), QPixmap(":/background/checkerboard.png"));
210  painter.end();
211 
212  QPen borderShadow(QColor(0, 0, 0, 200), 1, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin);
213  QVector<qreal> dashPattern{ 4, 4 };
214  borderShadow.setDashPattern(dashPattern);
215 
216  QPen borderHighlight(borderShadow);
217  borderHighlight.setColor(QColor(255, 255, 255, 200));
218  borderHighlight.setDashOffset(4);
219 
220  const ColorRef colorRef = mObject->getColor(colorIndex);
221  QListWidgetItem* colorItem = new QListWidgetItem(ui->colorListWidget);
222 
223  if (ui->colorListWidget->viewMode() != QListView::IconMode)
224  {
225  colorItem->setText(colorRef.name);
226  }
227  else
228  {
229  colorItem->setToolTip(colorRef.name);
230  }
231 
232  QPixmap colorSwatch = originalColorSwatch;
233  QPainter swatchPainter(&colorSwatch);
234  swatchPainter.fillRect(0, 0, mIconSize.width(), mIconSize.height(), colorRef.color);
235 
236  QIcon swatchIcon;
237  swatchIcon.addPixmap(colorSwatch, QIcon::Normal);
238 
239  // Draw selection border
240  if (ui->colorListWidget->viewMode() == QListView::IconMode)
241  {
242  swatchPainter.setPen(borderHighlight);
243  swatchPainter.drawRect(0, 0, mIconSize.width() - 1, mIconSize.height() - 1);
244  swatchPainter.setPen(borderShadow);
245  swatchPainter.drawRect(0, 0, mIconSize.width() - 1, mIconSize.height() - 1);
246  }
247  swatchIcon.addPixmap(colorSwatch, QIcon::Selected);
248 
249  colorItem->setIcon(swatchIcon);
251 
252  ui->colorListWidget->addItem(colorItem);
253 }
254 
255 void ColorPaletteWidget::changeColorName(QListWidgetItem* item)
256 {
257  Q_ASSERT(item != nullptr);
258 
259  if (ui->colorListWidget->viewMode() == QListView::IconMode)
260  {
261  int colorNumber = ui->colorListWidget->row(item);
262  if (colorNumber > -1)
263  {
264  bool ok;
265  QString text = QInputDialog::getText(this,
266  tr("Color name"),
267  tr("Color name"),
269  mObject->getColor(colorNumber).name,
270  &ok);
271  if (ok && !text.isEmpty())
272  {
273  mObject->renameColor(colorNumber, text);
274  refreshColorList();
275  }
276  }
277  }
278 }
279 
280 void ColorPaletteWidget::onItemChanged(QListWidgetItem* item)
281 {
282  int index = ui->colorListWidget->row(item);
283  QString newColorName = item->text();
284  mObject->renameColor(index, newColorName);
285 }
286 
287 void ColorPaletteWidget::onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
288 {
289  Q_UNUSED(parent)
290  Q_UNUSED(destination)
291  Q_UNUSED(end)
292 
293  int startIndex, endIndex;
294  if (start < row)
295  {
296  row -= 1; // TODO: Is this a bug?
297  if (start == row) { return; }
298 
299  startIndex = start;
300  endIndex = row;
301 
302  mObject->movePaletteColor(startIndex, endIndex);
303 
304  mObject->addColor(mObject->getColor(startIndex));
305  mObject->moveVectorColor(startIndex, mObject->getColorCount() - 1);
306  for (int i = startIndex; i < endIndex; i++)
307  {
308  mObject->moveVectorColor(i + 1, i);
309  }
310  mObject->moveVectorColor(mObject->getColorCount() - 1, endIndex);
311  }
312  else
313  {
314  if (start == row) { return; }
315 
316  startIndex = start;
317  endIndex = row;
318 
319  mObject->movePaletteColor(startIndex, endIndex);
320 
321  mObject->addColor(mObject->getColor(startIndex));
322  mObject->moveVectorColor(startIndex, mObject->getColorCount() - 1);
323  for (int i = startIndex; i > endIndex; i--)
324  {
325  mObject->moveVectorColor(i - 1, i);
326  }
327  mObject->moveVectorColor(mObject->getColorCount() - 1, endIndex);
328  }
329 
330  mObject->removeColor(mObject->getColorCount() - 1);
331 
332  refreshColorList();
333 }
334 
335 void ColorPaletteWidget::clickColorListItem(QListWidgetItem* currentItem)
336 {
337  auto modifiers = qApp->keyboardModifiers();
338 
339  // to avoid conflicts with multiple selections
340  // ie. will be seen as selected twice and cause problems
341  if (modifiers & Qt::ShiftModifier || modifiers & Qt::ControlModifier) { return; }
342 
343  int colorIndex = ui->colorListWidget->row(currentItem);
344 
345  emit colorNumberChanged(colorIndex);
346 }
347 
348 void ColorPaletteWidget::palettePreferences()
349 {
350  ui->colorListWidget->setMinimumWidth(ui->colorListWidget->sizeHintForColumn(0));
351 
352  // Let's pretend this button is a separator
353  mSeparator = new QAction("", this);
354  mSeparator->setSeparator(true);
355 
356  buttonStylesheet = "::menu-indicator{ image: none; }"
357  "QToolButton { border: 0px; }"
358  "QToolButton:pressed { border: 1px solid #ADADAD; border-radius: 2px; background-color: #D5D5D5; }"
359  "QToolButton:checked { border: 1px solid #ADADAD; border-radius: 2px; background-color: #D5D5D5; }";
360 
361 
362  // Add to UI
363  ui->palettePref->setIcon(QIcon(":/app/icons/new/svg/more_options.svg"));
364  ui->palettePref->setIconSize(QSize(15,15));
365  ui->palettePref->setArrowType(Qt::ArrowType::NoArrow);
366  ui->palettePref->setStyleSheet(buttonStylesheet);
367  ui->palettePref->addAction(ui->listModeAction);
368  ui->palettePref->addAction(ui->gridModeAction);
369 
370  ui->palettePref->addAction(mSeparator);
371  ui->palettePref->addAction(ui->smallSwatchAction);
372  ui->palettePref->addAction(ui->mediumSwatchAction);
373  ui->palettePref->addAction(ui->largeSwatchAction);
374  ui->palettePref->addAction(ui->fitSwatchAction);
375 
376  if (mFitSwatches) ui->fitSwatchAction->setChecked(true);
377  else if (mIconSize.width() > MEDIUM_ICON_SIZE) ui->largeSwatchAction->setChecked(true);
378  else if (mIconSize.width() > MIN_ICON_SIZE) ui->mediumSwatchAction->setChecked(true);
379  else ui->smallSwatchAction->setChecked(true);
380 
381  if (ui->colorListWidget->viewMode() == QListView::ListMode)
382  ui->listModeAction->setChecked(true);
383  else
384  ui->gridModeAction->setChecked(true);
385 
386  connect(ui->listModeAction, &QAction::triggered, this, &ColorPaletteWidget::setListMode);
387  connect(ui->gridModeAction, &QAction::triggered, this, &ColorPaletteWidget::setGridMode);
388  connect(ui->fitSwatchAction, &QAction::triggered, this, &ColorPaletteWidget::fitSwatchSize);
389  connect(ui->smallSwatchAction, &QAction::triggered, this, &ColorPaletteWidget::setSwatchSizeSmall);
390  connect(ui->mediumSwatchAction, &QAction::triggered, this, &ColorPaletteWidget::setSwatchSizeMedium);
391  connect(ui->largeSwatchAction, &QAction::triggered, this, &ColorPaletteWidget::setSwatchSizeLarge);
392 }
393 
394 void ColorPaletteWidget::setListMode()
395 {
396  ui->colorListWidget->setViewMode(QListView::ListMode);
397  ui->colorListWidget->setDragDropMode(QAbstractItemView::InternalMove);
398  ui->colorListWidget->setGridSize(QSize(-1, -1));
399  if (mFitSwatches)
400  {
401  fitSwatchSize();
402  }
403  updateUI();
404 
405  QSettings settings(PENCIL2D, PENCIL2D);
406  settings.setValue("ColorPaletteViewMode", "ListMode");
407 }
408 
409 void ColorPaletteWidget::setGridMode()
410 {
411  ui->colorListWidget->setViewMode(QListView::IconMode);
412  ui->colorListWidget->setMovement(QListView::Static); // TODO: update swatch index on move
413  ui->colorListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
414  ui->colorListWidget->setGridSize(QSize(mIconSize.width() + 1, mIconSize.height() + 1));
415  if (mFitSwatches)
416  {
417  fitSwatchSize();
418  }
419  updateUI();
420 
421  QSettings settings(PENCIL2D, PENCIL2D);
422  settings.setValue("ColorPaletteViewMode", "GridMode");
423 }
424 
425 void ColorPaletteWidget::setSwatchSizeSmall()
426 {
427  if (mIconSize.width() > MIN_ICON_SIZE)
428  {
429  mIconSize = QSize(MIN_ICON_SIZE, MIN_ICON_SIZE);
430  updateUI();
431 
432  mFitSwatches = false;
433  QSettings settings(PENCIL2D, PENCIL2D);
434  settings.setValue("PreferredColorGridSize", MIN_ICON_SIZE);
435  settings.setValue("FitSwatchSize", false);
436  }
437 }
438 
439 void ColorPaletteWidget::setSwatchSizeMedium()
440 {
441  if (mIconSize.width() != MEDIUM_ICON_SIZE)
442  {
443  mIconSize = QSize(MEDIUM_ICON_SIZE, MEDIUM_ICON_SIZE);
444  updateUI();
445 
446  mFitSwatches = false;
447  QSettings settings(PENCIL2D, PENCIL2D);
448  settings.setValue("PreferredColorGridSize", MEDIUM_ICON_SIZE);
449  settings.setValue("FitSwatchSize", false);
450  }
451 }
452 
453 void ColorPaletteWidget::setSwatchSizeLarge()
454 {
455  if (mIconSize.width() < MAX_ICON_SIZE)
456  {
457  mIconSize = QSize(MAX_ICON_SIZE, MAX_ICON_SIZE);
458  updateUI();
459 
460  mFitSwatches = false;
461  QSettings settings(PENCIL2D, PENCIL2D);
462  settings.setValue("PreferredColorGridSize", MAX_ICON_SIZE);
463  settings.setValue("FitSwatchSize", false);
464  }
465 }
466 
467 void ColorPaletteWidget::adjustSwatches()
468 {
469  if (mFitSwatches)
470  fitSwatchSize();
471 }
472 
473 void ColorPaletteWidget::fitSwatchSize()
474 {
475  int height = ui->colorListWidget->height();
476  int width = ui->colorListWidget->width();
477  int hScrollBar = ui->colorListWidget->horizontalScrollBar()->geometry().height() + 6;
478  int vScrollBar = ui->colorListWidget->verticalScrollBar()->geometry().width() * 2;
479  int colorCount = editor()->object()->getColorCount();
480  int size;
481 
482  if (ui->colorListWidget->viewMode() == QListView::ListMode)
483  {
484  size = qFloor((height - hScrollBar - (4 * colorCount)) / colorCount);
485  if (size < MIN_ICON_SIZE) size = MIN_ICON_SIZE;
486  if (size > MAX_ICON_SIZE) size = MAX_ICON_SIZE;
487  }
488  else
489  {
490  bool proceed = true;
491  size = MIN_ICON_SIZE;
492  while (proceed)
493  {
494  int columns = (width - vScrollBar) / size;
495  int rows = static_cast<int>(qCeil(colorCount / columns));
496  if (height - hScrollBar > rows * (size + 6))
497  {
498  size++;
499  if (size == MAX_ICON_SIZE)
500  {
501  proceed = false;
502  }
503  }
504  else
505  {
506  proceed = false;
507  }
508  }
509  }
510  mIconSize = QSize(size, size);
511 
512  updateUI();
513 
514  mFitSwatches = true;
515  QSettings settings(PENCIL2D, PENCIL2D);
516  settings.setValue("PreferredColorGridSize", size);
517  settings.setValue("FitSwatchSize", true);
518 }
519 
520 void ColorPaletteWidget::resizeEvent(QResizeEvent* event)
521 {
522  updateUI();
523  if (mFitSwatches)
524  {
525  fitSwatchSize();
526  }
527  QWidget::resizeEvent(event);
528 }
529 
530 void ColorPaletteWidget::updateGridUI()
531 {
532  if (ui->colorListWidget->viewMode() == QListView::IconMode) {
533  // Find the value to divide with
534  for (int i = 1; i < 75; i++)
535  {
536  int size = (ui->colorListWidget->width() - 18) / i; // subtract scrollbar width
537  if (size >= mIconSize.width() && size <= mIconSize.width() + 8)
538  {
539  stepper = size;
540  }
541  }
542  QSize tempSize = QSize(stepper, mIconSize.height());
543 
544  ui->colorListWidget->setIconSize(QSize(tempSize.width(), mIconSize.height()));
545  ui->colorListWidget->setGridSize(QSize(tempSize.width(), mIconSize.height() + 2));
546  mIconSize.setWidth(mIconSize.width());
547  }
548  else
549  {
550  ui->colorListWidget->setIconSize(mIconSize);
551  ui->colorListWidget->setGridSize(QSize(-1, -1));
552  }
553 }
554 
555 void ColorPaletteWidget::clickColorDialogButton()
556 {
557  mIsColorDialog = true;
558  clickAddColorButton();
559  mIsColorDialog = false;
560 }
561 
562 void ColorPaletteWidget::clickAddColorButton()
563 {
564  QColor prevColor = Qt::white;
565 
566  QColor newColor;
567 
568  if (mIsColorDialog)
569  newColor = QColorDialog::getColor(prevColor.rgba(), this, QString(), QColorDialog::ShowAlphaChannel);
570  else
571  newColor = mEditor->color()->frontColor(false);
572 
573  if (!newColor.isValid())
574  {
575  return; // User canceled operation
576  }
577 
578  int colorIndex = mObject->getColorCount();
579  ColorRef ref(newColor);
580 
581  mObject->addColor(ref);
582  refreshColorList();
583 
584  editor()->color()->setColorNumber(colorIndex);
585  editor()->color()->setIndexedColor(ref.color);
586  if (mFitSwatches)
587  {
588  fitSwatchSize();
589  }
590 }
591 
592 void ColorPaletteWidget::clickRemoveColorButton()
593 {
594  for (auto item : ui->colorListWidget->selectedItems())
595  {
596  int index = ui->colorListWidget->row(item);
597 
598  // items are not deleted by qt, it has to be done manually
599  // delete should happen before removing the color from from palette
600  // as the palette will be one ahead and crash otherwise
601 
602  if (mObject->getColorCount() == 1)
603  {
604  showPaletteReminder();
605  break;
606  }
607 
608  bool colorRemoved = false;
609  if (mObject->isColorInUse(index))
610  {
611  bool accepted = false;
612  if (!mMultipleSelected)
613  accepted = showPaletteWarning();
614 
615  if ((accepted || mMultipleSelected) && mObject->getColorCount() > 1)
616  {
617  delete item;
618  mObject->removeColor(index);
619  colorRemoved = true;
620  }
621  }
622  else if (mObject->getColorCount() > 1)
623  {
624  delete item;
625  mObject->removeColor(index);
626  colorRemoved = true;
627  }
628 
629  if (colorRemoved) {
630  int newIndex = qBound(0, index-1, mObject->getColorCount() - 1);
631  emit colorNumberChanged(newIndex);
632  }
633  }
634  mMultipleSelected = false;
635  if (mFitSwatches)
636  {
637  fitSwatchSize();
638  }
639  mEditor->updateCurrentFrame();
640 }
641 
642 bool ColorPaletteWidget::showPaletteWarning()
643 {
644  QMessageBox msgBox;
645  msgBox.setText(tr("The color(s) you are about to delete are currently being used by one or multiple strokes."));
646  msgBox.addButton(tr("Cancel"), QMessageBox::RejectRole);
647  QPushButton* removeButton = msgBox.addButton(tr("Delete"), QMessageBox::AcceptRole);
648 
649  msgBox.exec();
650  if (msgBox.clickedButton() == removeButton)
651  {
652  if (ui->colorListWidget->selectedItems().size() > 1)
653  {
654  mMultipleSelected = true;
655  }
656  return true;
657  }
658  return false;
659 }
660 
661 void ColorPaletteWidget::showPaletteReminder()
662 {
663  QMessageBox::warning(nullptr, tr("Palette Restriction"),
664  tr("The palette requires at least one swatch to remain functional"));
665 }
666 
667 void ColorPaletteWidget::updateItemColor(int itemIndex, QColor newColor)
668 {
669  QPixmap colorSwatch(mIconSize);
670  QPainter swatchPainter(&colorSwatch);
671  swatchPainter.drawTiledPixmap(0, 0, mIconSize.width(), mIconSize.height(), QPixmap(":/background/checkerboard.png"));
672  swatchPainter.fillRect(0, 0, mIconSize.width(), mIconSize.height(), newColor);
673 
674  QPen borderShadow(QColor(0, 0, 0, 200), 1, Qt::DotLine, Qt::FlatCap, Qt::MiterJoin);
675  QVector<qreal> dashPattern;
676  dashPattern << 4 << 4;
677  borderShadow.setDashPattern(dashPattern);
678  QPen borderHighlight(borderShadow);
679  borderHighlight.setColor(QColor(255, 255, 255, 200));
680  borderHighlight.setDashOffset(4);
681 
682  QIcon swatchIcon;
683  swatchIcon.addPixmap(colorSwatch, QIcon::Normal);
684 
685  if(ui->colorListWidget->viewMode() == QListView::IconMode)
686  {
687  // Draw selection border
688  swatchPainter.setPen(borderHighlight);
689  swatchPainter.drawRect(0, 0, mIconSize.width() - 1, mIconSize.height() - 1);
690  swatchPainter.setPen(borderShadow);
691  swatchPainter.drawRect(0, 0, mIconSize.width() - 1, mIconSize.height() - 1);
692  }
693  swatchIcon.addPixmap(colorSwatch, QIcon::Selected);
694 
695  ui->colorListWidget->item(itemIndex)->setIcon(swatchIcon);
696  editor()->object()->setColor(itemIndex, newColor);
697 
698  // Make sure to update grid in grid mode
699  if (ui->colorListWidget->viewMode() == QListView::IconMode)
700  {
701  updateGridUI();
702  }
703 }
void customContextMenuRequested(const QPoint &pos)
ScrollBarAlwaysOn
int colorCount() const const
ShiftModifier
void triggered(bool checked)
int width() const const
void setSeparator(bool b)
void triggered(QAction *action)
QString tr(const char *sourceText, const char *disambiguation, int n)
QAction * addAction(const QString &text)
void update()
CustomContextMenu
QAbstractButton * clickedButton() const const
int width() const const
QSize size() const const
void rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
void setToolTip(const QString &toolTip)
void setWidth(int width)
void setFlags(Qt::ItemFlags flags)
bool isEmpty() const const
void setText(const QString &text)
void clicked(bool checked)
void addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
void deleteLater()
void itemClicked(QListWidgetItem *item)
QAction * exec()
void setIndexedColor(const QColor &newColor)
Set color for current index.
QString getText(QWidget *parent, const QString &title, const QString &label, QLineEdit::EchoMode mode, const QString &text, bool *ok, Qt::WindowFlags flags, Qt::InputMethodHints inputMethodHints)
virtual int exec() override
void setIcon(const QIcon &icon)
MiterJoin
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QColorDialog::ColorDialogOptions options)
QColor frontColor(bool useIndexedColor=true)
frontColor
void itemChanged(QListWidgetItem *item)
int height() const const
QMessageBox::StandardButton warning(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
void addButton(QAbstractButton *button, QMessageBox::ButtonRole role)
virtual void resizeEvent(QResizeEvent *event)
Definition: editor.h:55
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void updateCurrentFrame()
Will call update() and update the canvas Only call this directly If you need the cache to be intact a...
Definition: editor.cpp:1057
QString text() const const
int height() const const
QRgb rgba() const const
void itemDoubleClicked(QListWidgetItem *item)
void setText(const QString &text)
ItemIsSelectable