Changeset View
Changeset View
Standalone View
Standalone View
libs/widgets/KisDlgInternalColorSelector.cpp
Context not available. | |||||
30 | #include "KoColorSpaceRegistry.h" | 30 | #include "KoColorSpaceRegistry.h" | ||
---|---|---|---|---|---|
31 | #include <KoColorSet.h> | 31 | #include <KoColorSet.h> | ||
32 | #include <KisPaletteModel.h> | 32 | #include <KisPaletteModel.h> | ||
33 | #include <KisColorsetChooser.h> | 33 | #include <KisPaletteListWidget.h> | ||
34 | #include <kis_palette_view.h> | 34 | #include <kis_palette_view.h> | ||
35 | #include <KoResourceServerProvider.h> | 35 | #include <KoResourceServerProvider.h> | ||
36 | #include <KoResourceServer.h> | 36 | #include <KoResourceServer.h> | ||
Context not available. | |||||
62 | const KoColorDisplayRendererInterface *displayRenderer; | 62 | const KoColorDisplayRendererInterface *displayRenderer; | ||
63 | KisHexColorInput *hexColorInput = 0; | 63 | KisHexColorInput *hexColorInput = 0; | ||
64 | KisPaletteModel *paletteModel = 0; | 64 | KisPaletteModel *paletteModel = 0; | ||
65 | KisColorsetChooser *colorSetChooser = 0; | 65 | KisPaletteListWidget *paletteChooser = 0; | ||
66 | KisScreenColorPickerBase *screenColorPicker = 0; | 66 | KisScreenColorPickerBase *screenColorPicker = 0; | ||
67 | }; | 67 | }; | ||
68 | 68 | | |||
Context not available. | |||||
71 | , m_d(new Private) | 71 | , m_d(new Private) | ||
72 | { | 72 | { | ||
73 | setModal(config.modal); | 73 | setModal(config.modal); | ||
74 | this->setFocusPolicy(Qt::ClickFocus); | 74 | setFocusPolicy(Qt::ClickFocus); | ||
75 | m_ui = new Ui_WdgDlgInternalColorSelector(); | 75 | m_ui = new Ui_WdgDlgInternalColorSelector(); | ||
76 | m_ui->setupUi(this); | 76 | m_ui->setupUi(this); | ||
77 | 77 | | |||
Context not available. | |||||
94 | m_ui->visualSelector->hide(); | 94 | m_ui->visualSelector->hide(); | ||
95 | } | 95 | } | ||
96 | 96 | | |||
97 | if (!m_d->paletteModel) { | 97 | m_d->paletteChooser = new KisPaletteListWidget(this); | ||
98 | m_d->paletteModel = new KisPaletteModel(this); | 98 | m_d->paletteModel = new KisPaletteModel(this); | ||
99 | m_ui->paletteBox->setPaletteModel(m_d->paletteModel); | 99 | m_ui->bnPaletteChooser->setIcon(KisIconUtils::loadIcon("hi16-palette_library")); | ||
100 | } | 100 | m_ui->paletteBox->setPaletteModel(m_d->paletteModel); | ||
101 | m_ui->bnColorsetChooser->setIcon(KisIconUtils::loadIcon("hi16-palette_library")); | 101 | m_ui->paletteBox->setDisplayRenderer(displayRenderer); | ||
102 | m_ui->cmbNameList->setCompanionView(m_ui->paletteBox); | ||||
103 | connect(m_d->paletteChooser, SIGNAL(sigPaletteSelected(KoColorSet*)), this, SLOT(slotChangePalette(KoColorSet*))); | ||||
104 | connect(m_ui->cmbNameList, SIGNAL(sigColorSelected(KoColor)), SLOT(slotColorUpdated(KoColor))); | ||||
105 | | ||||
102 | // For some bizare reason, the modal dialog doesn't like having the colorset set, so let's not. | 106 | // For some bizare reason, the modal dialog doesn't like having the colorset set, so let's not. | ||
103 | if (config.paletteBox) { | 107 | if (config.paletteBox) { | ||
104 | //TODO: Add disable signal as well. Might be not necessary...? | 108 | //TODO: Add disable signal as well. Might be not necessary...? | ||
Context not available. | |||||
117 | } | 121 | } | ||
118 | } | 122 | } | ||
119 | 123 | | |||
120 | connect(m_ui->paletteBox, SIGNAL(entrySelected(KoColorSetEntry)), this, SLOT(slotSetColorFromColorSetEntry(KoColorSetEntry))); | 124 | connect(m_ui->paletteBox, SIGNAL(sigColorSelected(KoColor)), this, | ||
121 | connect(m_ui->cmbNameList, SIGNAL(currentIndexChanged(int)), this, SLOT(slotSetColorFromColorList())); | 125 | SLOT(slotColorUpdated(KoColor))); | ||
122 | //m_ui->paletteBox->setDisplayRenderer(displayRenderer); | 126 | m_ui->bnPaletteChooser->setPopupWidget(m_d->paletteChooser); | ||
123 | m_d->colorSetChooser = new KisColorsetChooser(this); | | |||
124 | connect(m_d->colorSetChooser, SIGNAL(paletteSelected(KoColorSet*)), this, SLOT(slotChangePalette(KoColorSet*))); | | |||
125 | | ||||
126 | m_ui->bnColorsetChooser->setPopupWidget(m_d->colorSetChooser); | | |||
127 | | ||||
128 | } else { | 127 | } else { | ||
129 | m_ui->paletteBox->setEnabled(false); | 128 | m_ui->paletteBox->setEnabled(false); | ||
130 | m_ui->cmbNameList->setEnabled(false); | 129 | m_ui->cmbNameList->setEnabled(false); | ||
131 | m_ui->bnColorsetChooser->setEnabled(false); | 130 | m_ui->bnPaletteChooser->setEnabled(false); | ||
132 | } | 131 | } | ||
133 | 132 | | |||
134 | if (config.prevNextButtons) { | 133 | if (config.prevNextButtons) { | ||
Context not available. | |||||
222 | m_ui->visualSelector->setDisplayRenderer(displayRenderer); | 221 | m_ui->visualSelector->setDisplayRenderer(displayRenderer); | ||
223 | m_ui->currentColor->setDisplayRenderer(displayRenderer); | 222 | m_ui->currentColor->setDisplayRenderer(displayRenderer); | ||
224 | m_ui->previousColor->setDisplayRenderer(displayRenderer); | 223 | m_ui->previousColor->setDisplayRenderer(displayRenderer); | ||
225 | //m_ui->paletteBox->setDisplayRenderer(displayRenderer); | 224 | m_ui->paletteBox->setDisplayRenderer(displayRenderer); | ||
226 | } else { | 225 | } else { | ||
227 | m_d->displayRenderer = KoDumbColorDisplayRenderer::instance(); | 226 | m_d->displayRenderer = KoDumbColorDisplayRenderer::instance(); | ||
228 | } | 227 | } | ||
Context not available. | |||||
284 | m_d->hexColorInput->update(); | 283 | m_d->hexColorInput->update(); | ||
285 | } | 284 | } | ||
286 | 285 | | |||
286 | if (source != m_ui->paletteBox) { | ||||
287 | m_ui->paletteBox->selectClosestColor(m_d->currentColor); | ||||
288 | } | ||||
289 | | ||||
287 | m_ui->previousColor->setColor(m_d->previousColor); | 290 | m_ui->previousColor->setColor(m_d->previousColor); | ||
288 | 291 | | |||
289 | m_ui->currentColor->setColor(m_d->currentColor); | 292 | m_ui->currentColor->setColor(m_d->currentColor); | ||
Context not available. | |||||
330 | if (!set) { | 333 | if (!set) { | ||
331 | return; | 334 | return; | ||
332 | } | 335 | } | ||
333 | m_d->paletteModel->setColorSet(set); | 336 | m_d->paletteModel->setPalette(set); | ||
334 | m_ui->cmbNameList->clear(); | | |||
335 | for (quint32 i = 0; i< set->nColors(); i++) { | | |||
336 | KoColorSetEntry entry = set->getColorGlobal(i); | | |||
337 | QPixmap colorSquare = QPixmap(32, 32); | | |||
338 | if (entry.spotColor()) { | | |||
339 | QImage img = QImage(32, 32, QImage::Format_ARGB32); | | |||
340 | QPainter circlePainter; | | |||
341 | img.fill(Qt::transparent); | | |||
342 | circlePainter.begin(&img); | | |||
343 | QBrush brush = QBrush(Qt::SolidPattern); | | |||
344 | brush.setColor(entry.color().toQColor()); | | |||
345 | circlePainter.setBrush(brush); | | |||
346 | QPen pen = circlePainter.pen(); | | |||
347 | pen.setColor(Qt::transparent); | | |||
348 | pen.setWidth(0); | | |||
349 | circlePainter.setPen(pen); | | |||
350 | circlePainter.drawEllipse(0, 0, 32, 32); | | |||
351 | circlePainter.end(); | | |||
352 | colorSquare = QPixmap::fromImage(img); | | |||
353 | } else { | | |||
354 | colorSquare.fill(entry.color().toQColor()); | | |||
355 | } | | |||
356 | QString name = entry.name(); | | |||
357 | if (!entry.id().isEmpty()){ | | |||
358 | name = entry.id() + " - " + entry.name(); | | |||
359 | } | | |||
360 | m_ui->cmbNameList->addSqueezedItem(QIcon(colorSquare), name); | | |||
361 | } | | |||
362 | QCompleter *completer = new QCompleter(m_ui->cmbNameList->model()); | | |||
363 | completer->setCompletionMode(QCompleter::PopupCompletion); | | |||
364 | completer->setCaseSensitivity(Qt::CaseInsensitive); | | |||
365 | completer->setFilterMode(Qt::MatchContains); | | |||
366 | m_ui->cmbNameList->setCompleter(completer); | | |||
367 | } | | |||
368 | | ||||
369 | void KisDlgInternalColorSelector::slotSetColorFromColorList() | | |||
370 | { | | |||
371 | int index = m_ui->cmbNameList->currentIndex(); | | |||
372 | if (m_d->paletteModel) { | | |||
373 | slotSetColorFromColorSetEntry(m_d->paletteModel->colorSet()->getColorGlobal(index)); | | |||
374 | m_ui->paletteBox->blockSignals(true); | | |||
375 | m_ui->paletteBox->selectionModel()->clearSelection(); | | |||
376 | m_ui->paletteBox->selectionModel()->setCurrentIndex(m_d->paletteModel->indexFromId(index), QItemSelectionModel::Select); | | |||
377 | m_ui->paletteBox->blockSignals(false); | | |||
378 | } | | |||
379 | } | | |||
380 | | ||||
381 | void KisDlgInternalColorSelector::slotSetColorFromColorSetEntry(KoColorSetEntry entry) | | |||
382 | { | | |||
383 | slotColorUpdated(entry.color()); | | |||
384 | } | 337 | } | ||
385 | 338 | | |||
386 | void KisDlgInternalColorSelector::showEvent(QShowEvent *event) | 339 | void KisDlgInternalColorSelector::showEvent(QShowEvent *event) | ||
Context not available. |