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