• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • colors
kcolordialog.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 Copyright (C) 2007 Roberto Raggi (roberto@kdevelop.org)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20//-----------------------------------------------------------------------------
21// KDE color selection dialog.
22//
23// 1999-09-27 Espen Sand <espensa@online.no>
24// KColorDialog is now subclassed from KDialog. I have also extended
25// KColorDialog::getColor() so that it contains a parent argument. This
26// improves centering capability.
27//
28// layout management added Oct 1997 by Mario Weilguni
29// <mweilguni@sime.com>
30//
31
32#include "kcolordialog.h"
33#include "kcolordialog_p.h"
34
35
36#include <stdio.h>
37#include <stdlib.h>
38
39#include <QtGui/QButtonGroup>
40#include <QtGui/QCheckBox>
41#include <QtGui/QDesktopWidget>
42#include <QtGui/QRadioButton>
43#include <QtGui/qdrawutil.h>
44#include <QtGui/QActionEvent>
45#include <QtCore/QFile>
46#include <QtGui/QHeaderView>
47#include <QtGui/QImage>
48#include <QtGui/QStyledItemDelegate>
49#include <QtGui/QLabel>
50#include <QtGui/QLayout>
51#include <QtGui/QPainter>
52#include <QtGui/QPushButton>
53#include <QtGui/QScrollBar>
54#include <QtCore/QTimer>
55
56#include <kapplication.h>
57#include <kcombobox.h>
58#include <kconfig.h>
59#include <kglobal.h>
60#include <kglobalsettings.h>
61#include <khbox.h>
62#include <kiconloader.h>
63#include <klineedit.h>
64#include <klistwidget.h>
65#include <klocale.h>
66#include <kmessagebox.h>
67#include <knuminput.h>
68#include <kseparator.h>
69#include <kstandarddirs.h>
70#include <kcolorcollection.h>
71#include <kcolorutils.h>
72
73#include "kcolormimedata.h"
74#include <config.h>
75#include <kdebug.h>
76
77#include "kcolorchoosermode_p.h"
78#include "kcolorhelpers_p.h"
79#include "kselector.h"
80#include "kcolorvalueselector.h"
81#include "khuesaturationselect.h"
82#include "kxyselector.h"
83#include <kconfiggroup.h>
84
85#ifdef Q_WS_X11
86#include <X11/Xlib.h>
87#include <X11/Xutil.h>
88#include <QX11Info>
89#include <fixx11h.h>
90#endif
91
92using namespace KDEPrivate;
93
94using KDEPrivate::KColorTable;
95
96struct ColorCollectionNameType {
97 const char* const m_fileName;
98 const char* const m_displayName;
99};
100
101static const ColorCollectionNameType colorCollectionName[] = {
102 { "Recent_Colors", I18N_NOOP2("palette name", "* Recent Colors *") },
103 { "Custom_Colors", I18N_NOOP2("palette name", "* Custom Colors *") },
104 { "40.colors", I18N_NOOP2("palette name", "Forty Colors") },
105 { "Oxygen.colors", I18N_NOOP2("palette name", "Oxygen Colors") },
106 { "Rainbow.colors", I18N_NOOP2("palette name", "Rainbow Colors") },
107 { "Royal.colors", I18N_NOOP2("palette name", "Royal Colors") },
108 { "Web.colors", I18N_NOOP2("palette name", "Web Colors") },
109 { 0, 0 } // end of data
110};
111
112enum ColorCollectionIndices
113{
114 recentColorIndex,
115 customColorIndex,
116 fortyColorIndex
117};
118
119//-----------------------------------------------------------------------------
120
121class KColorCells::KColorCellsPrivate
122{
123public:
124 KColorCellsPrivate(KColorCells *q): q(q) {
125 inMouse = false;
126 selected = -1;
127 shade = false;
128 }
129
130 KColorCells *q;
131 QPoint mousePos;
132 int selected;
133 bool shade;
134 bool inMouse;
135};
136
137class KColorCellsItemDelegate: public QStyledItemDelegate
138{
139public:
140 KColorCellsItemDelegate(KColorCells *parent): QStyledItemDelegate(parent) {}
141 virtual void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
142 {
143 QStyleOptionViewItemV4 opt(option);
144 initStyleOption(&opt,index);
145
146 //Get the current cell color
147 QColor backgroundColor = index.data(Qt::BackgroundRole).value<QColor>();
148 if (backgroundColor.isValid()) {
149 //Paint the general background
150 painter->fillRect(opt.rect, backgroundColor);
151 //Paint the selection mark (circle)
152 if (opt.state & QStyle::State_Selected) {
153 //Use black or white, depending on the contrast
154 QColor color = QColor(0, 0, 0, 220);
155 if (KColorUtils::contrastRatio(color, backgroundColor) < 5) {
156 color = QColor(255, 255, 255, 220);
157 }
158 //Draw the selection (radiobutton-like) circle
159 painter->save();
160 painter->setRenderHint(QPainter::Antialiasing, true);
161 painter->setRenderHint(QPainter::HighQualityAntialiasing, true);
162 painter->setPen(QPen(color, 1.2, Qt::SolidLine));
163 painter->setBrush(QBrush());
164 painter->drawEllipse(opt.rect.adjusted(2,2,-2,-2));
165 painter->restore();
166 }
167 } else {
168 //Paint the "X" (missing) cross on empty background color
169 backgroundColor = opt.palette.color(QPalette::Window);
170 painter->fillRect(opt.rect, backgroundColor);
171 painter->save();
172 QColor crossColor = qGray(backgroundColor.rgb()) > 192 ? backgroundColor.darker(106) :
173 backgroundColor.lighter(106);
174 painter->setPen(QPen(crossColor, 1.5));
175 painter->drawLine(opt.rect.topLeft(), opt.rect.bottomRight());
176 painter->drawLine(opt.rect.topRight(), opt.rect.bottomLeft());
177 painter->restore();
178 }
179 }
180};
181
182KColorCells::KColorCells(QWidget *parent, int rows, int cols)
183 : QTableWidget(parent), d(new KColorCellsPrivate(this))
184{
185 setItemDelegate(new KColorCellsItemDelegate(this));
186
187 setFrameShape(QFrame::NoFrame);
188 d->shade = true;
189 setRowCount(rows);
190 setColumnCount(cols);
191
192 verticalHeader()->hide();
193 horizontalHeader()->hide();
194
195 d->selected = 0;
196 d->inMouse = false;
197
198 // Drag'n'Drop
199 setAcceptDrops(true);
200
201 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
202 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
203 viewport()->setBackgroundRole(QPalette::Background);
204 setBackgroundRole(QPalette::Background);
205
206
207 setSelectionMode(QAbstractItemView::SingleSelection);
208 setDragEnabled(false);
209}
210
211KColorCells::~KColorCells()
212{
213 delete d;
214}
215
216QColor KColorCells::color(int index) const
217{
218 QTableWidgetItem * tmpItem = item(index / columnCount(), index % columnCount());
219
220 if (tmpItem != 0)
221 return tmpItem->data(Qt::BackgroundRole).value<QColor>();
222
223 return QColor();
224}
225
226int KColorCells::count() const
227{
228 return rowCount() * columnCount();
229}
230
231void KColorCells::setShading(bool _shade)
232{
233 d->shade = _shade;
234}
235
236bool KColorCells::shading() const
237{
238 return d->shade;
239}
240
241void KColorCells::setAcceptDrags(bool _acceptDrags)
242{
243 this->setDragEnabled(_acceptDrags);
244}
245
246bool KColorCells::acceptDrags() const
247{
248 return this->dragEnabled();
249}
250
251void KColorCells::setSelected(int index)
252{
253 Q_ASSERT(index >= 0 && index < count());
254
255 d->selected = index;
256}
257
258int KColorCells::selectedIndex() const
259{
260 return d->selected;
261}
262
263void KColorCells::setColor(int column, const QColor &color)
264{
265 const int tableRow = column / columnCount();
266 const int tableColumn = column % columnCount();
267
268 Q_ASSERT(tableRow >= 0 && tableRow < rowCount());
269 Q_ASSERT(tableColumn >= 0 && tableColumn < columnCount());
270
271 QTableWidgetItem * tableItem = item(tableRow, tableColumn);
272
273 if (tableItem == 0) {
274 tableItem = new QTableWidgetItem();
275 setItem(tableRow, tableColumn, tableItem);
276 }
277
278 tableItem->setData(Qt::BackgroundRole , color);
279}
280
281/*void KColorCells::paintCell( QPainter *painter, int row, int col )
282{
283 painter->setRenderHint( QPainter::Antialiasing , true );
284
285 QBrush brush;
286 int w = 1;
287
288 if (shade)
289 {
290 qDrawShadePanel( painter, 1, 1, cellWidth()-2,
291 cellHeight()-2, palette(), true, 1, &brush );
292 w = 2;
293 }
294 QColor color = colors[ row * numCols() + col ];
295 if (!color.isValid())
296 {
297 if (!shade) return;
298 color = palette().color(backgroundRole());
299 }
300
301 const QRect colorRect( w, w, cellWidth()-w*2, cellHeight()-w*2 );
302 painter->fillRect( colorRect, color );
303
304 if ( row * numCols() + col == selected ) {
305 painter->setPen( qGray(color.rgb())>=127 ? Qt::black : Qt::white );
306 painter->drawLine( colorRect.topLeft(), colorRect.bottomRight() );
307 painter->drawLine( colorRect.topRight(), colorRect.bottomLeft() );
308 }
309}*/
310
311void KColorCells::resizeEvent(QResizeEvent*)
312{
313 // According to the Qt doc:
314 // If you need to set the width of a given column to a fixed value, call
315 // QHeaderView::resizeSection() on the table's {horizontal,vertical}
316 // header.
317 // Therefore we iterate over each row and column and set the header section
318 // size, as the sizeHint does indeed appear to be ignored in favor of a
319 // minimum size that is larger than what we want.
320 for (int index = 0 ; index < columnCount() ; index++)
321 horizontalHeader()->resizeSection(index, sizeHintForColumn(index));
322 for (int index = 0 ; index < rowCount() ; index++)
323 verticalHeader()->resizeSection(index, sizeHintForRow(index));
324}
325
326int KColorCells::sizeHintForColumn(int /*column*/) const
327{
328 return width() / columnCount() ;
329}
330
331int KColorCells::sizeHintForRow(int /*row*/) const
332{
333 return height() / rowCount() ;
334}
335
336void KColorCells::mousePressEvent(QMouseEvent *e)
337{
338 d->inMouse = true;
339 d->mousePos = e->pos();
340
341 QTableWidget::mousePressEvent(e);
342}
343
344
345int KColorCells::positionToCell(const QPoint &pos, bool ignoreBorders) const
346{
347 //TODO ignoreBorders not yet handled
348 Q_UNUSED(ignoreBorders)
349
350 QTableWidgetItem* tableItem = itemAt(pos);
351
352 if (!tableItem)
353 return -1;
354
355 const int itemRow = row(tableItem);
356 const int itemColumn = column(tableItem);
357 int cell = itemRow * columnCount() + itemColumn;
358
359 /*if (!ignoreBorders)
360 {
361 int border = 2;
362 int x = pos.x() - col * cellWidth();
363 int y = pos.y() - row * cellHeight();
364 if ( (x < border) || (x > cellWidth()-border) ||
365 (y < border) || (y > cellHeight()-border))
366 return -1;
367 }*/
368
369 return cell;
370}
371
372void KColorCells::mouseMoveEvent(QMouseEvent *e)
373{
374 if (this->dragEnabled() || this->acceptDrops()) {
375 if (!(e->buttons() & Qt::LeftButton)) return;
376
377 if (d->inMouse) {
378 int delay = KGlobalSettings::dndEventDelay();
379 if (e->x() > d->mousePos.x() + delay || e->x() < d->mousePos.x() - delay ||
380 e->y() > d->mousePos.y() + delay || e->y() < d->mousePos.y() - delay) {
381 // Drag color object
382 QTableWidgetItem * tableItem = itemAt(d->mousePos);
383
384 if (tableItem) {
385 QVariant var = tableItem->data(Qt::BackgroundRole);
386 QColor tmpCol = var.value<QColor>();
387 if (tmpCol.isValid())
388 KColorMimeData::createDrag(tmpCol, this)->start();
389 }
390 }
391 }
392 } else
393 QTableWidget::mouseMoveEvent(e);
394}
395
396void KColorCells::dragEnterEvent(QDragEnterEvent *event)
397{
398 kDebug() << "KColorCells::dragEnterEvent() acceptDrags="
399 << this->dragEnabled()
400 << " canDecode=" << KColorMimeData::canDecode(event->mimeData())
401 << endl;
402 event->setAccepted(this->dragEnabled() && KColorMimeData::canDecode(event->mimeData()));
403}
404
405// Reimplemented to override QTableWidget's override. Else dropping doesn't work.
406void KColorCells::dragMoveEvent(QDragMoveEvent *event)
407{
408 kDebug() << "KColorCells::dragMoveEvent() acceptDrags="
409 << this->dragEnabled()
410 << " canDecode=" << KColorMimeData::canDecode(event->mimeData())
411 << endl;
412 event->setAccepted(this->dragEnabled() && KColorMimeData::canDecode(event->mimeData()));
413}
414
415void KColorCells::dropEvent(QDropEvent *event)
416{
417 QColor c = KColorMimeData::fromMimeData(event->mimeData());
418
419 kDebug() << "KColorCells::dropEvent() color.isValid=" << c.isValid();
420 if (c.isValid()) {
421 QTableWidgetItem * tableItem = itemAt(event->pos());
422
423 if (tableItem)
424 tableItem->setData(Qt::BackgroundRole , c);
425 }
426}
427
428void KColorCells::mouseReleaseEvent(QMouseEvent *e)
429{
430 if (selectionMode() != QAbstractItemView::NoSelection) {
431 int cell = positionToCell(d->mousePos);
432 int currentCell = positionToCell(e->pos());
433
434 // If we release the mouse in another cell and we don't have
435 // a drag we should ignore this event.
436 if (currentCell != cell)
437 cell = -1;
438
439 if ((cell != -1) && (d->selected != cell)) {
440 d->selected = cell;
441
442 const int newRow = cell / columnCount();
443 const int newColumn = cell % columnCount();
444
445 clearSelection(); // we do not want old violet selected cells
446
447 item(newRow, newColumn)->setSelected(true);
448 }
449
450 d->inMouse = false;
451 if (cell != -1)
452 emit colorSelected(cell , color(cell));
453 }
454
455 QTableWidget::mouseReleaseEvent(e);
456}
457
458void KColorCells::mouseDoubleClickEvent(QMouseEvent * /*e*/)
459{
460 int cell = positionToCell(d->mousePos);
461
462 if (cell != -1)
463 emit colorDoubleClicked(cell , color(cell));
464}
465
466
467//-----------------------------------------------------------------------------
468
469class KColorPatch::KColorPatchPrivate
470{
471public:
472 KColorPatchPrivate(KColorPatch *q): q(q) {}
473
474 KColorPatch *q;
475 QColor color;
476};
477
478KColorPatch::KColorPatch(QWidget *parent) : QFrame(parent), d(new KColorPatchPrivate(this))
479{
480 setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
481 setAcceptDrops(true);
482 setMinimumSize(12, 12);
483}
484
485KColorPatch::~KColorPatch()
486{
487 delete d;
488}
489
490QColor KColorPatch::color() const
491{
492 return d->color;
493}
494
495void KColorPatch::setColor(const QColor &col)
496{
497 d->color = col.toRgb();
498
499 update();
500}
501
502void KColorPatch::paintEvent(QPaintEvent* pe)
503{
504 QFrame::paintEvent(pe);
505 QPainter painter(this);
506
507 fillOpaqueRect(&painter, contentsRect(), d->color);
508}
509
510void KColorPatch::mouseMoveEvent(QMouseEvent *e)
511{
512 // Drag color object
513 if (!(e->buttons() & Qt::LeftButton))
514 return;
515 KColorMimeData::createDrag(d->color, this)->start();
516}
517
518void KColorPatch::dragEnterEvent(QDragEnterEvent *event)
519{
520 event->setAccepted(KColorMimeData::canDecode(event->mimeData()));
521}
522
523void KColorPatch::dropEvent(QDropEvent *event)
524{
525 QColor c = KColorMimeData::fromMimeData(event->mimeData());
526 if (c.isValid()) {
527 setColor(c);
528 emit colorChanged(c);
529 }
530}
531
532class KColorTable::KColorTablePrivate
533{
534public:
535 KColorTablePrivate(KColorTable *q): q(q) {}
536
537 void slotColorCellSelected(int index , const QColor&);
538 void slotColorCellDoubleClicked(int index , const QColor&);
539 void slotColorTextSelected(const QString &colorText);
540 void slotSetColors(const QString &_collectionName);
541 void slotShowNamedColorReadError(void);
542
543 KColorTable *q;
544 QString i18n_namedColors;
545 KComboBox *combo;
546 KColorCells *cells;
547 QScrollArea *sv;
548 KListWidget *mNamedColorList;
549 KColorCollection *mPalette;
550 int mMinWidth;
551 int mCols;
552 QMap<QString, QColor> m_namedColorMap;
553};
554
555KColorTable::KColorTable(QWidget *parent, int minWidth, int cols)
556 : QWidget(parent), d(new KColorTablePrivate(this))
557{
558 d->cells = 0;
559 d->mPalette = 0;
560 d->mMinWidth = minWidth;
561 d->mCols = cols;
562 d->i18n_namedColors = i18n("Named Colors");
563
564 QStringList diskPaletteList = KColorCollection::installedCollections();
565 QStringList paletteList;
566
567 // We must replace the untranslated file names by translate names (of course only for KDE's standard palettes)
568 for (int i = 0; colorCollectionName[i].m_fileName; ++i) {
569 diskPaletteList.removeAll(colorCollectionName[i].m_fileName);
570 paletteList.append(i18nc("palette name", colorCollectionName[i].m_displayName));
571 }
572 paletteList += diskPaletteList;
573 paletteList.append(d->i18n_namedColors);
574
575 QVBoxLayout *layout = new QVBoxLayout(this);
576
577 d->combo = new KComboBox(this);
578 d->combo->setEditable(false);
579 d->combo->addItems(paletteList);
580 layout->addWidget(d->combo);
581
582 d->sv = new QScrollArea(this);
583 QSize cellSize = QSize(d->mMinWidth, 120);
584 d->sv->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
585 d->sv->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
586 QSize minSize = QSize(d->sv->verticalScrollBar()->sizeHint().width(), 0);
587 minSize += QSize(d->sv->frameWidth() * 2, 0);
588 minSize += QSize(cellSize);
589 d->sv->setFixedSize(minSize);
590 layout->addWidget(d->sv);
591
592 d->mNamedColorList = new KListWidget(this);
593 d->mNamedColorList->setObjectName("namedColorList");
594 d->mNamedColorList->setFixedSize(minSize);
595 d->mNamedColorList->hide();
596 layout->addWidget(d->mNamedColorList);
597 connect(d->mNamedColorList, SIGNAL(currentTextChanged(QString)),
598 this, SLOT(slotColorTextSelected(QString)));
599
600 setFixedSize(sizeHint());
601 connect(d->combo, SIGNAL(activated(QString)),
602 this, SLOT(slotSetColors(QString)));
603}
604
605KColorTable::~KColorTable()
606{
607 delete d->mPalette;
608 delete d;
609}
610
611QString
612KColorTable::name() const
613{
614 return d->combo->currentText();
615}
616
617
618static const char * const *namedColorFilePath(void)
619{
620 //
621 // 2000-02-05 Espen Sand.
622 // Add missing filepaths here. Make sure the last entry is 0, 0!
623 //
624 // 2009-06-16 Pino Toscano
625 //
626 // You can specify either absolute paths or relative locations
627 // wrt KStandardDirs resources. In either way, there should be two
628 // "strings" for each path.
629 // - absolute path: specify it directly, then add 0 as second item
630 // * example: "/usr/share/X11/rgb.txt", 0,
631 // - KStandardDirs location: specify the filename as first item,
632 // then add the resource as second
633 // * example: "kdeui/rgb.txt", "data",
634 //
635 static const char * const path[] = {
636#ifdef Q_WS_X11
637#ifdef X11_RGBFILE
638 X11_RGBFILE, 0,
639#endif
640 "/usr/share/X11/rgb.txt", 0,
641 "/usr/X11R6/lib/X11/rgb.txt", 0,
642 "/usr/openwin/lib/X11/rgb.txt", 0, // for Solaris.
643#else /* systems without X11 */
644 "kdeui/rgb.txt", "data",
645#endif
646 0, 0
647 };
648 return path;
649}
650
651
652
653
654void
655KColorTable::readNamedColor(void)
656{
657 if (d->mNamedColorList->count() != 0) {
658 return; // Strings already present
659 }
660
661 KGlobal::locale()->insertCatalog("kdelibs_colors4");
662
663 //
664 // Code somewhat inspired by KColorCollection.
665 //
666
667 const char * const *path = namedColorFilePath();
668 for (int i = 0; path[i]; i += 2) {
669 QString file;
670 if (path[i + 1]) {
671 file = KStandardDirs::locate(path[i + 1], QString::fromLatin1(path[i]));
672 if (file.isEmpty()) {
673 continue;
674 }
675 } else {
676 file = QString::fromLatin1(path[i]);
677 }
678
679 QFile paletteFile(file);
680 if (!paletteFile.open(QIODevice::ReadOnly)) {
681 continue;
682 }
683
684 QByteArray line;
685 QStringList list;
686 while (!paletteFile.atEnd()) {
687 line = paletteFile.readLine();
688
689 int red, green, blue;
690 int pos = 0;
691
692 if (sscanf(line, "%d %d %d%n", &red, &green, &blue, &pos) == 3) {
693 //
694 // Remove duplicates. Every name with a space and every name
695 // that start with "gray".
696 //
697 QString name = line.mid(pos).trimmed();
698 QByteArray s1 = line.mid(pos);
699 if (name.isNull() || name.indexOf(' ') != -1 ||
700 name.indexOf("gray") != -1 || name.indexOf("grey") != -1) {
701 continue;
702 }
703
704 const QColor color(red, green, blue);
705 if (color.isValid()) {
706 const QString colorName(i18nc("color", name.toLatin1().data()));
707 list.append(colorName);
708 d->m_namedColorMap[ colorName ] = color;
709 }
710 }
711 }
712
713 list.sort();
714 d->mNamedColorList->addItems(list);
715 break;
716 }
717
718 if (d->mNamedColorList->count() == 0) {
719 //
720 // Give the error dialog box a chance to center above the
721 // widget (or dialog). If we had displayed it now we could get a
722 // situation where the (modal) error dialog box pops up first
723 // preventing the real dialog to become visible until the
724 // error dialog box is removed (== bad UI).
725 //
726 QTimer::singleShot(10, this, SLOT(slotShowNamedColorReadError()));
727 }
728}
729
730
731void
732KColorTable::KColorTablePrivate::slotShowNamedColorReadError(void)
733{
734 if (mNamedColorList->count() == 0) {
735 QString pathMsg;
736 int pathCount = 0;
737
738 const char * const *path = namedColorFilePath();
739 for (int i = 0; path[i]; i += 2, ++pathCount) {
740 if (path[i + 1]) {
741 pathMsg += QLatin1String(path[i + 1]) + ", " + QString::fromLatin1(path[i]);
742 } else {
743 pathMsg += QLatin1String(path[i]);
744 }
745 pathMsg += '\n';
746 }
747
748 QString finalMsg = i18ncp("%1 is the number of paths, %2 is the list of paths (with newlines between them)",
749 "Unable to read X11 RGB color strings. The following "
750 "file location was examined:\n%2",
751 "Unable to read X11 RGB color strings. The following "
752 "file locations were examined:\n%2",
753 pathCount, pathMsg );
754
755 KMessageBox::sorry(q, finalMsg);
756 }
757}
758
759
760//
761// 2000-02-12 Espen Sand
762// Set the color in two steps. The setColors() slot will not emit a signal
763// with the current color setting. The reason is that setColors() is used
764// by the color selector dialog on startup. In the color selector dialog
765// we normally want to display a startup color which we specify
766// when the dialog is started. The slotSetColors() slot below will
767// set the palette and then use the information to emit a signal with the
768// new color setting. It is only used by the combobox widget.
769//
770void
771KColorTable::KColorTablePrivate::slotSetColors(const QString &_collectionName)
772{
773 q->setColors(_collectionName);
774 if (mNamedColorList->count() && mNamedColorList->isVisible()) {
775 int item = mNamedColorList->currentRow();
776 mNamedColorList->setCurrentRow(item < 0 ? 0 : item);
777 slotColorTextSelected(mNamedColorList->currentItem()->text());
778 } else {
779 slotColorCellSelected(0, QColor()); // FIXME: We need to save the current value!!
780 }
781}
782
783
784void
785KColorTable::setColors(const QString &_collectionName)
786{
787 QString collectionName(_collectionName);
788
789 if (d->combo->currentText() != collectionName) {
790 bool found = false;
791 for (int i = 0; i < d->combo->count(); i++) {
792 if (d->combo->itemText(i) == collectionName) {
793 d->combo->setCurrentIndex(i);
794 found = true;
795 break;
796 }
797 }
798 if (!found) {
799 d->combo->addItem(collectionName);
800 d->combo->setCurrentIndex(d->combo->count() - 1);
801 }
802 }
803
804 // We must again find the file name of the palette from the eventual translation
805 for (int i = 0; colorCollectionName[i].m_fileName; ++i) {
806 if (collectionName == i18nc("palette name", colorCollectionName[i].m_displayName)) {
807 collectionName = colorCollectionName[i].m_fileName;
808 break;
809 }
810 }
811
812
813 //
814 // 2000-02-12 Espen Sand
815 // The palette mode "i18n_namedColors" does not use the KColorCollection
816 // class. In fact, 'mPalette' and 'cells' are 0 when in this mode. The reason
817 // for this is maninly that KColorCollection reads from and writes to files
818 // using "locate()". The colors used in "i18n_namedColors" mode comes from
819 // the X11 diretory and is not writable. I don't think this fit in
820 // KColorCollection.
821 //
822 if (!d->mPalette || d->mPalette->name() != collectionName) {
823 if (collectionName == d->i18n_namedColors) {
824 d->sv->hide();
825 d->mNamedColorList->show();
826 readNamedColor();
827
828 delete d->cells; d->cells = 0;
829 delete d->mPalette; d->mPalette = 0;
830 } else {
831 d->mNamedColorList->hide();
832 d->sv->show();
833
834 delete d->cells;
835 delete d->mPalette;
836 d->mPalette = new KColorCollection(collectionName);
837 int rows = (d->mPalette->count() + d->mCols - 1) / d->mCols;
838 if (rows < 1) rows = 1;
839 d->cells = new KColorCells(d->sv->viewport(), rows, d->mCols);
840 d->cells->setShading(false);
841 d->cells->setAcceptDrags(false);
842 QSize cellSize = QSize(d->mMinWidth, d->mMinWidth * rows / d->mCols);
843 d->cells->setFixedSize(cellSize);
844 for (int i = 0; i < d->mPalette->count(); i++) {
845 d->cells->setColor(i, d->mPalette->color(i));
846 }
847 connect(d->cells, SIGNAL(colorSelected(int,QColor)),
848 SLOT(slotColorCellSelected(int,QColor)));
849 connect(d->cells, SIGNAL(colorDoubleClicked(int,QColor)),
850 SLOT(slotColorCellDoubleClicked(int,QColor)));
851 d->sv->setWidget(d->cells);
852 d->cells->show();
853
854 //d->sv->updateScrollBars();
855 }
856 }
857}
858
859
860
861void
862KColorTable::KColorTablePrivate::slotColorCellSelected(int index , const QColor& /*color*/)
863{
864 if (!mPalette || (index >= mPalette->count()))
865 return;
866 emit q->colorSelected(mPalette->color(index), mPalette->name(index));
867}
868
869void
870KColorTable::KColorTablePrivate::slotColorCellDoubleClicked(int index , const QColor& /*color*/)
871{
872 if (!mPalette || (index >= mPalette->count()))
873 return;
874 emit q->colorDoubleClicked(mPalette->color(index), mPalette->name(index));
875}
876
877
878void
879KColorTable::KColorTablePrivate::slotColorTextSelected(const QString &colorText)
880{
881 emit q->colorSelected(m_namedColorMap[ colorText ], colorText);
882}
883
884
885void
886KColorTable::addToCustomColors(const QColor &color)
887{
888 setColors(i18nc("palette name", colorCollectionName[customColorIndex].m_displayName));
889 d->mPalette->addColor(color);
890 d->mPalette->save();
891 delete d->mPalette;
892 d->mPalette = 0;
893 setColors(i18nc("palette name", colorCollectionName[customColorIndex].m_displayName));
894}
895
896void
897KColorTable::addToRecentColors(const QColor &color)
898{
899 //
900 // 2000-02-12 Espen Sand.
901 // The 'mPalette' is always 0 when current mode is i18n_namedColors
902 //
903 bool recentIsSelected = false;
904 if (d->mPalette && d->mPalette->name() == colorCollectionName[ recentColorIndex ].m_fileName) {
905 delete d->mPalette;
906 d->mPalette = 0;
907 recentIsSelected = true;
908 }
909 KColorCollection *recentPal = new KColorCollection(colorCollectionName[ recentColorIndex ].m_fileName);
910 if (recentPal->findColor(color) == -1) {
911 recentPal->addColor(color);
912 recentPal->save();
913 }
914 delete recentPal;
915 if (recentIsSelected)
916 setColors(i18nc("palette name", colorCollectionName[ recentColorIndex ].m_displayName));
917}
918
919class KCDPickerFilter;
920
921class KColorDialog::KColorDialogPrivate
922{
923public:
924 KColorDialogPrivate(KColorDialog *q): q(q) {}
925
926 void setRgbEdit(const QColor &col);
927 void setHsvEdit(const QColor &col);
928 void setHtmlEdit(const QColor &col);
929 void _setColor(const QColor &col, const QString &name = QString());
930 void showColor(const QColor &color, const QString &name);
931
932 void slotRGBChanged(void);
933 void slotAlphaChanged(void);
934 void slotHSVChanged(void);
935 void slotHtmlChanged(void);
936 void slotHSChanged(int, int);
937 void slotVChanged(int);
938 void slotAChanged(int);
939 void slotModeChanged(int);
940
941 void slotColorSelected(const QColor &col);
942 void slotColorSelected(const QColor &col, const QString &name);
943 void slotColorDoubleClicked(const QColor &col, const QString &name);
944 void slotColorPicker();
945 void slotAddToCustomColors();
946 void slotDefaultColorClicked();
950 void slotWriteSettings();
951
955 KColorChooserMode chooserMode();
956
960 void setChooserMode(KColorChooserMode c);
961
962 KColorDialog *q;
963 KColorTable *table;
964 QString originalPalette;
965 bool bRecursion;
966 bool bEditRgb;
967 bool bEditHsv;
968 bool bEditHtml;
969 bool bColorPicking;
970 bool bAlphaEnabled;
971 QLabel *colorName;
972 KLineEdit *htmlName;
973 KIntSpinBox *hedit;
974 KIntSpinBox *sedit;
975 KIntSpinBox *vedit;
976 KIntSpinBox *redit;
977 KIntSpinBox *gedit;
978 KIntSpinBox *bedit;
979 QWidget *alphaLabel;
980 KIntSpinBox *aedit;
981
982 KColorPatch *patch;
983 KColorPatch *comparePatch;
984
985 KColorChooserMode _mode;
986 QButtonGroup *modeGroup;
987
988 KHueSaturationSelector *hsSelector;
989 KColorCollection *palette;
990 KColorValueSelector *valuePal;
991 KGradientSelector *alphaSelector;
992 QVBoxLayout* l_right;
993 QGridLayout* tl_layout;
994 QCheckBox *cbDefaultColor;
995 QColor defaultColor;
996 QColor selColor;
997#ifdef Q_WS_X11
998 KCDPickerFilter* filter;
999#endif
1000};
1001
1002#ifdef Q_WS_X11
1003class KCDPickerFilter: public QWidget
1004{
1005public:
1006 KCDPickerFilter(QWidget* parent): QWidget(parent) {}
1007
1008 virtual bool x11Event(XEvent* event) {
1009 if (event->type == ButtonRelease) {
1010 QMouseEvent e(QEvent::MouseButtonRelease, QPoint(),
1011 QPoint(event->xmotion.x_root, event->xmotion.y_root) , Qt::NoButton, Qt::NoButton, Qt::NoModifier);
1012 QApplication::sendEvent(parentWidget(), &e);
1013 return true;
1014 } else return false;
1015 }
1016};
1017
1018#endif
1019
1020
1021KColorDialog::KColorDialog(QWidget *parent, bool modal)
1022 : KDialog(parent), d(new KColorDialogPrivate(this))
1023{
1024 setCaption(i18n("Select Color"));
1025 setButtons(modal ? Ok | Cancel : Close);
1026 setModal(modal);
1027 d->bRecursion = true;
1028 d->bColorPicking = false;
1029 d->bAlphaEnabled = false;
1030#ifdef Q_WS_X11
1031 d->filter = 0;
1032#endif
1033 d->cbDefaultColor = 0L;
1034 d->_mode = ChooserClassic;
1035 connect(this, SIGNAL(okClicked()), this, SLOT(slotWriteSettings()));
1036 connect(this, SIGNAL(closeClicked()), this, SLOT(slotWriteSettings()));
1037
1038 QLabel *label;
1039
1040 //
1041 // Create the top level page and its layout
1042 //
1043 QWidget *page = new QWidget(this);
1044 setMainWidget(page);
1045
1046 QGridLayout *tl_layout = new QGridLayout(page);
1047 tl_layout->setMargin(0);
1048 d->tl_layout = tl_layout;
1049 tl_layout->addItem(new QSpacerItem(spacingHint()*2, 0), 0, 1);
1050
1051 //
1052 // the more complicated part: the left side
1053 // add a V-box
1054 //
1055 QVBoxLayout *l_left = new QVBoxLayout();
1056 tl_layout->addLayout(l_left, 0, 0);
1057
1058 //
1059 // add a H-Box for the XY-Selector and a grid for the
1060 // entry fields
1061 //
1062 QHBoxLayout *l_ltop = new QHBoxLayout();
1063 l_left->addLayout(l_ltop);
1064
1065 //
1066 // the palette and value selector go into the H-box
1067 //
1068 d->hsSelector = new KHueSaturationSelector(page);
1069 d->hsSelector->setMinimumSize(256, 256);
1070 l_ltop->addWidget(d->hsSelector, 8);
1071 connect(d->hsSelector, SIGNAL(valueChanged(int,int)),
1072 SLOT(slotHSChanged(int,int)));
1073
1074 d->valuePal = new KColorValueSelector(page);
1075 d->valuePal->setMinimumSize(26, 70);
1076 d->valuePal->setIndent(false);
1077 d->valuePal->setArrowDirection(Qt::RightArrow);
1078 l_ltop->addWidget(d->valuePal, 1);
1079 connect(d->valuePal, SIGNAL(valueChanged(int)),
1080 SLOT(slotVChanged(int)));
1081
1082 d->alphaSelector = new KGradientSelector(Qt::Horizontal, page);
1083 d->alphaSelector->setFixedSize(256, 26);
1084 d->alphaSelector->setIndent(false);
1085 d->alphaSelector->setArrowDirection(Qt::DownArrow);
1086 d->alphaSelector->setRange(0, 255);
1087 l_left->addWidget(d->alphaSelector, 1);
1088 connect(d->alphaSelector, SIGNAL(valueChanged(int)),
1089 SLOT(slotAChanged(int)));
1090
1091 // a little space between
1092 l_left->addSpacing(10); // FIXME: remove hardcoded values
1093
1094 QGridLayout *l_lbot = new QGridLayout();
1095 l_left->addLayout(l_lbot);
1096
1097 // button group that manages the radio buttons
1098 QRadioButton *modeButton;
1099 d->modeGroup = new QButtonGroup(page);
1100 connect(d->modeGroup, SIGNAL(buttonClicked(int)), SLOT(slotModeChanged(int)));
1101
1102 //
1103 // add the HSV fields
1104 //
1105 l_lbot->setColumnStretch(2, 10);
1106
1107 modeButton = new QRadioButton(i18n("Hue:"), page);
1108 l_lbot->addWidget(modeButton, 0, 0);
1109 d->modeGroup->addButton(modeButton, ChooserHue);
1110
1111 d->hedit = new KIntSpinBox(page);
1112 d->hedit->setMaximum(359);
1113 d->hedit->setSuffix(i18nc("The angular degree unit (for hue)", "\302\260")); // U+00B0 DEGREE SIGN
1114 l_lbot->addWidget(d->hedit, 0, 1);
1115 connect(d->hedit, SIGNAL(valueChanged(int)),
1116 SLOT(slotHSVChanged()));
1117
1118 modeButton = new QRadioButton(i18n("Saturation:"), page);
1119 l_lbot->addWidget(modeButton, 1, 0);
1120 d->modeGroup->addButton(modeButton, ChooserSaturation);
1121
1122 d->sedit = new KIntSpinBox(page);
1123 d->sedit->setMaximum(255);
1124 l_lbot->addWidget(d->sedit, 1, 1);
1125 connect(d->sedit, SIGNAL(valueChanged(int)),
1126 SLOT(slotHSVChanged()));
1127
1128 modeButton = new QRadioButton(i18nc("This is the V of HSV", "Value:"), page);
1129 l_lbot->addWidget(modeButton, 2, 0);
1130 d->modeGroup->addButton(modeButton, ChooserValue);
1131
1132 d->vedit = new KIntSpinBox(page);
1133 d->vedit->setMaximum(255);
1134 l_lbot->addWidget(d->vedit, 2, 1);
1135 connect(d->vedit, SIGNAL(valueChanged(int)),
1136 SLOT(slotHSVChanged()));
1137
1138
1139 //
1140 // add the RGB fields
1141 //
1142 modeButton = new QRadioButton(i18n("Red:"), page);
1143 l_lbot->addWidget(modeButton, 0, 3);
1144 d->modeGroup->addButton(modeButton, ChooserRed);
1145
1146 d->redit = new KIntSpinBox(page);
1147 d->redit->setMaximum(255);
1148 l_lbot->addWidget(d->redit, 0, 4);
1149 connect(d->redit, SIGNAL(valueChanged(int)),
1150 SLOT(slotRGBChanged()));
1151
1152 modeButton = new QRadioButton(i18n("Green:"), page);
1153 l_lbot->addWidget(modeButton, 1, 3);
1154 d->modeGroup->addButton(modeButton, ChooserGreen);
1155
1156 d->gedit = new KIntSpinBox(page);
1157 d->gedit->setMaximum(255);
1158 l_lbot->addWidget(d->gedit, 1, 4);
1159 connect(d->gedit, SIGNAL(valueChanged(int)),
1160 SLOT(slotRGBChanged()));
1161
1162 modeButton = new QRadioButton(i18n("Blue:"), page);
1163 l_lbot->addWidget(modeButton, 2, 3);
1164 d->modeGroup->addButton(modeButton, ChooserBlue);
1165
1166 d->bedit = new KIntSpinBox(page);
1167 d->bedit->setMaximum(255);
1168 l_lbot->addWidget(d->bedit, 2, 4);
1169 connect(d->bedit, SIGNAL(valueChanged(int)),
1170 SLOT(slotRGBChanged()));
1171
1172 d->alphaLabel = new KHBox(page);
1173 QWidget *spacer = new QWidget(d->alphaLabel);
1174 label = new QLabel(i18n("Alpha:"), d->alphaLabel);
1175 QStyleOptionButton option;
1176 option.initFrom(modeButton);
1177 QRect labelRect = modeButton->style()->subElementRect(QStyle::SE_RadioButtonContents, &option, modeButton);
1178 int indent = layoutDirection() == Qt::LeftToRight ? labelRect.left() : modeButton->geometry().right() - labelRect.right();
1179 spacer->setFixedWidth(indent);
1180 l_lbot->addWidget(d->alphaLabel, 3, 3);
1181
1182 d->aedit = new KIntSpinBox(page);
1183 d->aedit->setMaximum(255);
1184 label->setBuddy(d->aedit);
1185 l_lbot->addWidget(d->aedit, 3, 4);
1186 connect(d->aedit, SIGNAL(valueChanged(int)),
1187 SLOT(slotAlphaChanged()));
1188
1189 d->aedit->setVisible(false);
1190 d->alphaLabel->setVisible(false);
1191 d->alphaSelector->setVisible(false);
1192
1193 //
1194 // add a layout for the right side
1195 //
1196 d->l_right = new QVBoxLayout;
1197 tl_layout->addLayout(d->l_right, 0, 2);
1198
1199 //
1200 // Add the palette table
1201 //
1202 d->table = new KColorTable(page);
1203 d->l_right->addWidget(d->table, 10);
1204
1205 connect(d->table, SIGNAL(colorSelected(QColor,QString)),
1206 SLOT(slotColorSelected(QColor,QString)));
1207
1208 connect(
1209 d->table,
1210 SIGNAL(colorDoubleClicked(QColor,QString)),
1211 SLOT(slotColorDoubleClicked(QColor,QString))
1212 );
1213 // Store the default value for saving time.
1214 d->originalPalette = d->table->name();
1215
1216 //
1217 // a little space between
1218 //
1219 d->l_right->addSpacing(10);
1220
1221 QHBoxLayout *l_hbox = new QHBoxLayout();
1222 d->l_right->addItem(l_hbox);
1223
1224 //
1225 // The add to custom colors button
1226 //
1227 QPushButton *addButton = new QPushButton(page);
1228 addButton->setText(i18n("&Add to Custom Colors"));
1229 l_hbox->addWidget(addButton, 0, Qt::AlignLeft);
1230 connect(addButton, SIGNAL(clicked()), SLOT(slotAddToCustomColors()));
1231
1232 //
1233 // The color picker button
1234 //
1235 QPushButton* button = new QPushButton(page);
1236 button->setIcon(KIcon("color-picker"));
1237 int commonHeight = addButton->sizeHint().height();
1238 button->setFixedSize(commonHeight, commonHeight);
1239 l_hbox->addWidget(button, 0, Qt::AlignHCenter);
1240 connect(button, SIGNAL(clicked()), SLOT(slotColorPicker()));
1241
1242 //
1243 // a little space between
1244 //
1245 d->l_right->addSpacing(10);
1246
1247 //
1248 // and now the entry fields and the patch (=colored box)
1249 //
1250 QGridLayout *l_grid = new QGridLayout();
1251 d->l_right->addLayout(l_grid);
1252
1253 l_grid->setColumnStretch(2, 1);
1254
1255 label = new QLabel(page);
1256 label->setText(i18n("Name:"));
1257 l_grid->addWidget(label, 0, 1, Qt::AlignLeft);
1258
1259 d->colorName = new QLabel(page);
1260 l_grid->addWidget(d->colorName, 0, 2, Qt::AlignLeft);
1261
1262 label = new QLabel(page);
1263 label->setText(i18n("HTML:"));
1264 l_grid->addWidget(label, 1, 1, Qt::AlignLeft);
1265
1266 d->htmlName = new KLineEdit(page);
1267 d->htmlName->setMaxLength(13); // Qt's QColor allows 12 hexa-digits
1268 d->htmlName->setText("#FFFFFF"); // But HTML uses only 6, so do not worry about the size
1269 int w = d->htmlName->fontMetrics().width(QLatin1String("#DDDDDDD"));
1270 d->htmlName->setFixedWidth(w);
1271 l_grid->addWidget(d->htmlName, 1, 2, Qt::AlignLeft);
1272
1273 connect(d->htmlName, SIGNAL(textChanged(QString)),
1274 SLOT(slotHtmlChanged()));
1275
1276 d->patch = new KColorPatch(page);
1277 d->patch->setFixedSize(48, 48);
1278 l_grid->addWidget(d->patch, 0, 0, 2, 1, Qt::AlignHCenter | Qt::AlignVCenter);
1279 connect(d->patch, SIGNAL(colorChanged(QColor)),
1280 SLOT(setColor(QColor)));
1281
1282 //
1283 // chain fields together
1284 //
1285 setTabOrder(d->hedit, d->sedit);
1286 setTabOrder(d->sedit, d->vedit);
1287 setTabOrder(d->vedit, d->redit);
1288 setTabOrder(d->redit, d->gedit);
1289 setTabOrder(d->gedit, d->bedit);
1290 setTabOrder(d->bedit, d->aedit);
1291
1292 tl_layout->activate();
1293 page->setMinimumSize(page->sizeHint());
1294
1295 readSettings();
1296 d->bRecursion = false;
1297 d->bEditHsv = false;
1298 d->bEditRgb = false;
1299 d->bEditHtml = false;
1300
1301 setFixedSize(sizeHint());
1302 QColor col;
1303 col.setHsv(0, 0, 255);
1304 d->_setColor(col);
1305
1306// FIXME: with enabled event filters, it crashes after ever enter of a drag.
1307// better disable drag and drop than crashing it...
1308// d->htmlName->installEventFilter(this);
1309// d->hsSelector->installEventFilter(this);
1310 d->hsSelector->setAcceptDrops(true);
1311
1312 d->setChooserMode(ChooserValue);
1313}
1314
1315KColorDialog::~KColorDialog()
1316{
1317#ifdef Q_WS_X11
1318 if (d->bColorPicking && kapp)
1319 kapp->removeX11EventFilter(d->filter);
1320#endif
1321 delete d;
1322}
1323
1324bool
1325KColorDialog::eventFilter(QObject *obj, QEvent *ev)
1326{
1327 if ((obj == d->htmlName) || (obj == d->hsSelector))
1328 switch (ev->type()) {
1329 case QEvent::DragEnter:
1330 case QEvent::DragMove:
1331 case QEvent::DragLeave:
1332 case QEvent::Drop:
1333 case QEvent::DragResponse:
1334 qApp->sendEvent(d->patch, ev);
1335 return true;
1336 default:
1337 break;
1338 }
1339 return KDialog::eventFilter(obj, ev);
1340}
1341
1342void
1343KColorDialog::setDefaultColor(const QColor& col)
1344{
1345 if (!d->cbDefaultColor) {
1346 //
1347 // a little space between
1348 //
1349 d->l_right->addSpacing(10);
1350
1351 //
1352 // and the "default color" checkbox, under all items on the right side
1353 //
1354 d->cbDefaultColor = new QCheckBox(i18n("Default color"), mainWidget());
1355
1356 d->l_right->addWidget(d->cbDefaultColor);
1357
1358 mainWidget()->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); // cancel setFixedSize()
1359 d->tl_layout->activate();
1360 mainWidget()->setMinimumSize(mainWidget()->sizeHint());
1361 setFixedSize(sizeHint());
1362
1363 connect(d->cbDefaultColor, SIGNAL(clicked()), SLOT(slotDefaultColorClicked()));
1364 }
1365
1366 d->defaultColor = col;
1367
1368 d->slotDefaultColorClicked();
1369}
1370
1371QColor KColorDialog::defaultColor() const
1372{
1373 return d->defaultColor;
1374}
1375
1376void KColorDialog::setAlphaChannelEnabled(bool alpha)
1377{
1378 if (d->bAlphaEnabled != alpha) {
1379 d->bAlphaEnabled = alpha;
1380 d->aedit->setVisible(d->bAlphaEnabled);
1381 d->alphaLabel->setVisible(d->bAlphaEnabled);
1382 d->alphaSelector->setVisible(d->bAlphaEnabled);
1383
1384 mainWidget()->setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); // cancel setFixedSize()
1385 d->tl_layout->activate();
1386 mainWidget()->setMinimumSize(mainWidget()->sizeHint());
1387 setFixedSize(sizeHint());
1388 }
1389}
1390
1391bool KColorDialog::isAlphaChannelEnabled() const
1392{
1393 return d->bAlphaEnabled;
1394}
1395
1396
1397void KColorDialog::KColorDialogPrivate::setChooserMode(KColorChooserMode c)
1398{
1399 _mode = c;
1400 hsSelector->setChooserMode(c);
1401 valuePal->setChooserMode(c);
1402
1403 modeGroup->button(valuePal->chooserMode())->setChecked(true);
1404 valuePal->updateContents();
1405 hsSelector->updateContents();
1406 valuePal->update();
1407 hsSelector->update();
1408 slotHSVChanged();
1409}
1410
1411
1412KColorChooserMode KColorDialog::KColorDialogPrivate::chooserMode()
1413{
1414 return _mode;
1415}
1416
1417void KColorDialog::KColorDialogPrivate::slotDefaultColorClicked()
1418{
1419 if (cbDefaultColor->isChecked()) {
1420 selColor = defaultColor;
1421 showColor(selColor, i18n("-default-"));
1422 } else {
1423 showColor(selColor, QString());
1424 }
1425 emit q->colorSelected(selColor);
1426}
1427
1428void
1429KColorDialog::KColorDialogPrivate::slotModeChanged(int id)
1430{
1431 setChooserMode(KColorChooserMode(id));
1432}
1433
1434void
1435KColorDialog::readSettings()
1436{
1437 KConfigGroup group(KGlobal::config(), "Colors");
1438
1439 QString collectionName = group.readEntry("CurrentPalette");
1440 if (collectionName.isEmpty()) {
1441 collectionName = i18nc("palette name", colorCollectionName[fortyColorIndex].m_displayName);
1442 } else {
1443 for (int i = 0; colorCollectionName[i].m_fileName; ++i) {
1444 if (collectionName == colorCollectionName[i].m_displayName) {
1445 collectionName = i18nc("palette name", colorCollectionName[i].m_displayName);
1446 break;
1447 }
1448 }
1449 }
1450
1451 d->table->setColors(collectionName);
1452}
1453
1454void
1455KColorDialog::KColorDialogPrivate::slotWriteSettings()
1456{
1457 KConfigGroup group(KGlobal::config(), "Colors");
1458
1459 QString collectionName = table->name();
1460 if (!group.hasDefault("CurrentPalette") && table->name() == originalPalette) {
1461 group.revertToDefault("CurrentPalette");
1462 } else {
1463 QString collectionName(table->name());
1464 for (int i = 0; colorCollectionName[i].m_fileName; ++i) {
1465 if (collectionName == i18nc("palette name", colorCollectionName[i].m_displayName)) {
1466 collectionName = colorCollectionName[i].m_displayName;
1467 break;
1468 }
1469 }
1470 group.writeEntry("CurrentPalette", collectionName); //Make sure the untranslated name is saved, assuming there is one
1471 }
1472}
1473
1474QColor
1475KColorDialog::color() const
1476{
1477 if (d->cbDefaultColor && d->cbDefaultColor->isChecked())
1478 return QColor();
1479 if (d->selColor.isValid())
1480 d->table->addToRecentColors(d->selColor);
1481 return d->selColor;
1482}
1483
1484void KColorDialog::setColor(const QColor &col)
1485{
1486 d->_setColor(col);
1487}
1488
1489//
1490// static function to display dialog and return color
1491//
1492int KColorDialog::getColor(QColor &theColor, QWidget *parent)
1493{
1494 KColorDialog dlg(parent, true);
1495 dlg.setObjectName("Color Selector");
1496 if (theColor.isValid())
1497 dlg.setColor(theColor);
1498 int result = dlg.exec();
1499
1500 if (result == Accepted) {
1501 theColor = dlg.color();
1502 }
1503
1504 return result;
1505}
1506
1507//
1508// static function to display dialog and return color
1509//
1510int KColorDialog::getColor(QColor &theColor, const QColor& defaultCol, QWidget *parent)
1511{
1512 KColorDialog dlg(parent, true);
1513 dlg.setObjectName("Color Selector");
1514 dlg.setDefaultColor(defaultCol);
1515 dlg.setColor(theColor);
1516 int result = dlg.exec();
1517
1518 if (result == Accepted)
1519 theColor = dlg.color();
1520
1521 return result;
1522}
1523
1524void KColorDialog::KColorDialogPrivate::slotRGBChanged(void)
1525{
1526 if (bRecursion) return;
1527 int red = redit->value();
1528 int grn = gedit->value();
1529 int blu = bedit->value();
1530
1531 if (red > 255 || red < 0) return;
1532 if (grn > 255 || grn < 0) return;
1533 if (blu > 255 || blu < 0) return;
1534
1535 QColor col;
1536 col.setRgb(red, grn, blu, aedit->value());
1537 bEditRgb = true;
1538 _setColor(col);
1539 bEditRgb = false;
1540}
1541
1542void KColorDialog::KColorDialogPrivate::slotAlphaChanged(void)
1543{
1544 if (bRecursion) return;
1545 int alpha = aedit->value();
1546
1547 if (alpha > 255 || alpha < 0) return;
1548
1549 QColor col = selColor;
1550 col.setAlpha(alpha);
1551 _setColor(col);
1552}
1553
1554void KColorDialog::KColorDialogPrivate::slotHtmlChanged(void)
1555{
1556 if (bRecursion || htmlName->text().isEmpty()) return;
1557
1558 QString strColor(htmlName->text());
1559
1560 // Assume that a user does not want to type the # all the time
1561 if (strColor[0] != '#') {
1562 bool signalsblocked = htmlName->blockSignals(true);
1563 strColor.prepend("#");
1564 htmlName->setText(strColor);
1565 htmlName->blockSignals(signalsblocked);
1566 }
1567
1568 const QColor color(strColor);
1569
1570 if (color.isValid()) {
1571 QColor col(color);
1572 bEditHtml = true;
1573 _setColor(col);
1574 bEditHtml = false;
1575 }
1576}
1577
1578void KColorDialog::KColorDialogPrivate::slotHSVChanged(void)
1579{
1580 if (bRecursion) return;
1581 int hue = hedit->value();
1582 int sat = sedit->value();
1583 int val = vedit->value();
1584
1585 if (hue > 359 || hue < 0) return;
1586 if (sat > 255 || sat < 0) return;
1587 if (val > 255 || val < 0) return;
1588
1589 QColor col;
1590 col.setHsv(hue, sat, val, aedit->value());
1591 bEditHsv = true;
1592 _setColor(col);
1593 bEditHsv = false;
1594}
1595
1596void KColorDialog::KColorDialogPrivate::slotHSChanged(int x, int y)
1597{
1598 QColor col = selColor;
1599 KColorChooserMode xMode = chooserXMode(chooserMode());
1600 KColorChooserMode yMode = chooserYMode(chooserMode());
1601 setComponentValue(col, xMode, x / (xMode == ChooserHue ? 360.0 : 255.0));
1602 setComponentValue(col, yMode, y / (yMode == ChooserHue ? 360.0 : 255.0));
1603 _setColor(col);
1604}
1605
1606void KColorDialog::KColorDialogPrivate::slotVChanged(int v)
1607{
1608 QColor col = selColor;
1609 setComponentValue(col, chooserMode(), v / (chooserMode() == ChooserHue ? 360.0 : 255.0));
1610 _setColor(col);
1611}
1612
1613void KColorDialog::KColorDialogPrivate::slotAChanged(int value)
1614{
1615 QColor col = selColor;
1616 col.setAlpha(value);
1617 _setColor(col);
1618}
1619
1620void KColorDialog::KColorDialogPrivate::slotColorSelected(const QColor &color)
1621{
1622 _setColor(color);
1623}
1624
1625void KColorDialog::KColorDialogPrivate::slotAddToCustomColors()
1626{
1627 table->addToCustomColors(selColor);
1628}
1629
1630void KColorDialog::KColorDialogPrivate::slotColorSelected(const QColor &color, const QString &name)
1631{
1632 _setColor(color, name);
1633}
1634
1635void KColorDialog::KColorDialogPrivate::slotColorDoubleClicked
1636(
1637 const QColor & color,
1638 const QString & name
1639)
1640{
1641 _setColor(color, name);
1642 q->accept();
1643}
1644
1645void KColorDialog::KColorDialogPrivate::_setColor(const QColor &color, const QString &name)
1646{
1647 if (color.isValid()) {
1648 if (cbDefaultColor && cbDefaultColor->isChecked())
1649 cbDefaultColor->setChecked(false);
1650 selColor = color;
1651 } else {
1652 if (cbDefaultColor && cbDefaultColor->isChecked())
1653 cbDefaultColor->setChecked(true);
1654 selColor = defaultColor;
1655 }
1656
1657 showColor(selColor, name);
1658
1659 emit q->colorSelected(selColor);
1660}
1661
1662// show but don't set into selColor, nor emit colorSelected
1663void KColorDialog::KColorDialogPrivate::showColor(const QColor &color, const QString &name)
1664{
1665 bRecursion = true;
1666
1667 if (name.isEmpty())
1668 colorName->setText(i18n("-unnamed-"));
1669 else
1670 colorName->setText(name);
1671
1672 patch->setColor(color);
1673
1674 setRgbEdit(color);
1675 setHsvEdit(color);
1676 setHtmlEdit(color);
1677 aedit->setValue(color.alpha());
1678
1679 QColor rgbColor = color.toRgb();
1680 bool ltr = q->layoutDirection() == Qt::LeftToRight;
1681 rgbColor.setAlpha(ltr ? 0 : 255);
1682 alphaSelector->setFirstColor(rgbColor);
1683 rgbColor.setAlpha(ltr ? 255 : 0);
1684 alphaSelector->setSecondColor(rgbColor);
1685 alphaSelector->setValue(color.alpha());
1686
1687 KColorChooserMode xMode = chooserXMode(chooserMode());
1688 KColorChooserMode yMode = chooserYMode(chooserMode());
1689 int xValue = qRound(getComponentValue(color, xMode) * (xMode == ChooserHue ? 360.0 : 255.0));
1690 int yValue = qRound(getComponentValue(color, yMode) * (yMode == ChooserHue ? 360.0 : 255.0));
1691 int value = qRound(getComponentValue(color, chooserMode()) * (chooserMode() == ChooserHue ? 360.0 : 255.0));
1692 hsSelector->setValues(xValue, yValue);
1693 valuePal->setValue(value);
1694
1695 bool blocked = valuePal->blockSignals(true);
1696
1697 valuePal->setHue(color.hue());
1698 valuePal->setSaturation(color.saturation());
1699 valuePal->setColorValue(color.value());
1700 valuePal->updateContents();
1701 valuePal->blockSignals(blocked);
1702 valuePal->update();
1703
1704 blocked = hsSelector->blockSignals(true);
1705
1706 hsSelector->setHue(color.hue());
1707 hsSelector->setSaturation(color.saturation());
1708 hsSelector->setColorValue(color.value());
1709 hsSelector->updateContents();
1710 hsSelector->blockSignals(blocked);
1711 hsSelector->update();
1712
1713 bRecursion = false;
1714}
1715
1716
1717
1718void
1719KColorDialog::KColorDialogPrivate::slotColorPicker()
1720{
1721 bColorPicking = true;
1722#ifdef Q_WS_X11
1723 filter = new KCDPickerFilter(q);
1724 kapp->installX11EventFilter(filter);
1725#endif
1726 q->grabMouse(Qt::CrossCursor);
1727 q->grabKeyboard();
1728}
1729
1730void
1731KColorDialog::mouseMoveEvent(QMouseEvent *e)
1732{
1733 if (d->bColorPicking) {
1734 d->_setColor(grabColor(e->globalPos()));
1735 return;
1736 }
1737
1738 KDialog::mouseMoveEvent(e);
1739}
1740
1741void
1742KColorDialog::mouseReleaseEvent(QMouseEvent *e)
1743{
1744 if (d->bColorPicking) {
1745 d->bColorPicking = false;
1746#ifdef Q_WS_X11
1747 kapp->removeX11EventFilter(d->filter);
1748 delete d->filter; d->filter = 0;
1749#endif
1750 releaseMouse();
1751 releaseKeyboard();
1752 d->_setColor(grabColor(e->globalPos()));
1753 return;
1754 }
1755 KDialog::mouseReleaseEvent(e);
1756}
1757
1758QColor
1759KColorDialog::grabColor(const QPoint &p)
1760{
1761#ifdef Q_WS_X11
1762 // we use the X11 API directly in this case as we are not getting back a valid
1763 // return from QPixmap::grabWindow in the case where the application is using
1764 // an argb visual
1765 if( !qApp->desktop()->geometry().contains( p ))
1766 return QColor();
1767 Window root = RootWindow(QX11Info::display(), QX11Info::appScreen());
1768 XImage *ximg = XGetImage(QX11Info::display(), root, p.x(), p.y(), 1, 1, -1, ZPixmap);
1769 unsigned long xpixel = XGetPixel(ximg, 0, 0);
1770 XDestroyImage(ximg);
1771 XColor xcol;
1772 xcol.pixel = xpixel;
1773 xcol.flags = DoRed | DoGreen | DoBlue;
1774 XQueryColor(QX11Info::display(),
1775 DefaultColormap(QX11Info::display(), QX11Info::appScreen()),
1776 &xcol);
1777 return QColor::fromRgbF(xcol.red / 65535.0, xcol.green / 65535.0, xcol.blue / 65535.0);
1778#else
1779 QWidget *desktop = QApplication::desktop();
1780 QPixmap pm = QPixmap::grabWindow(desktop->winId(), p.x(), p.y(), 1, 1);
1781 QImage i = pm.toImage();
1782 return i.pixel(0, 0);
1783#endif
1784}
1785
1786void
1787KColorDialog::keyPressEvent(QKeyEvent *e)
1788{
1789 if (d->bColorPicking) {
1790 if (e->key() == Qt::Key_Escape) {
1791 d->bColorPicking = false;
1792#ifdef Q_WS_X11
1793 kapp->removeX11EventFilter(d->filter);
1794 delete d->filter; d->filter = 0;
1795#endif
1796 releaseMouse();
1797 releaseKeyboard();
1798 }
1799 e->accept();
1800 return;
1801 }
1802 KDialog::keyPressEvent(e);
1803}
1804
1805void KColorDialog::KColorDialogPrivate::setRgbEdit(const QColor &col)
1806{
1807 if (bEditRgb) return;
1808 int r, g, b;
1809 col.getRgb(&r, &g, &b);
1810
1811 redit->setValue(r);
1812 gedit->setValue(g);
1813 bedit->setValue(b);
1814}
1815
1816void KColorDialog::KColorDialogPrivate::setHtmlEdit(const QColor &col)
1817{
1818 if (bEditHtml) return;
1819 int r, g, b;
1820 col.getRgb(&r, &g, &b);
1821 QString num;
1822
1823 num.sprintf("#%02X%02X%02X", r, g, b);
1824 htmlName->setText(num);
1825}
1826
1827
1828void KColorDialog::KColorDialogPrivate::setHsvEdit(const QColor &col)
1829{
1830 if (bEditHsv) return;
1831 int h, s, v;
1832 col.getHsv(&h, &s, &v);
1833
1834 hedit->setValue(h);
1835 sedit->setValue(s);
1836 vedit->setValue(v);
1837}
1838
1839#include "kcolordialog.moc"
1840#include "kcolordialog_p.moc"
KColorCells
A table of editable color cells.
Definition: kcolordialog.h:41
KColorCells::setAcceptDrags
void setAcceptDrags(bool acceptDrags)
Definition: kcolordialog.cpp:241
KColorCells::colorDoubleClicked
void colorDoubleClicked(int index, const QColor &color)
Emitted when a color in the table is double-clicked.
KColorCells::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *)
Definition: kcolordialog.cpp:428
KColorCells::~KColorCells
~KColorCells()
Definition: kcolordialog.cpp:211
KColorCells::mousePressEvent
virtual void mousePressEvent(QMouseEvent *)
Definition: kcolordialog.cpp:336
KColorCells::setSelected
void setSelected(int index)
Sets the currently selected cell to index.
Definition: kcolordialog.cpp:251
KColorCells::mouseDoubleClickEvent
virtual void mouseDoubleClickEvent(QMouseEvent *)
Definition: kcolordialog.cpp:458
KColorCells::color
QColor color(int index) const
Returns the color at a given index in the table.
Definition: kcolordialog.cpp:216
KColorCells::KColorCells
KColorCells(QWidget *parent, int rows, int columns)
Constructs a new table of color cells, consisting of rows * columns colors.
Definition: kcolordialog.cpp:182
KColorCells::colorSelected
void colorSelected(int index, const QColor &color)
Emitted when a color is selected in the table.
KColorCells::setShading
void setShading(bool shade)
Definition: kcolordialog.cpp:231
KColorCells::positionToCell
int positionToCell(const QPoint &pos, bool ignoreBorders=false) const
Definition: kcolordialog.cpp:345
KColorCells::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *)
Definition: kcolordialog.cpp:372
KColorCells::count
int count() const
Returns the total number of color cells in the table.
Definition: kcolordialog.cpp:226
KColorCells::sizeHintForRow
virtual int sizeHintForRow(int column) const
Definition: kcolordialog.cpp:331
KColorCells::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *)
Definition: kcolordialog.cpp:396
KColorCells::shading
bool shading
Definition: kcolordialog.h:44
KColorCells::sizeHintForColumn
virtual int sizeHintForColumn(int column) const
Definition: kcolordialog.cpp:326
KColorCells::acceptDrags
bool acceptDrags
Definition: kcolordialog.h:43
KColorCells::selectedIndex
int selectedIndex() const
Returns the index of the cell which is currently selected.
Definition: kcolordialog.cpp:258
KColorCells::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
Definition: kcolordialog.cpp:311
KColorCells::setColor
void setColor(int index, const QColor &col)
Sets the color in the given index in the table.
Definition: kcolordialog.cpp:263
KColorCells::dragMoveEvent
virtual void dragMoveEvent(QDragMoveEvent *)
Definition: kcolordialog.cpp:406
KColorCells::dropEvent
virtual void dropEvent(QDropEvent *)
Definition: kcolordialog.cpp:415
KColorCollection
Class for handling color collections ("palettes").
Definition: kcolorcollection.h:43
KColorCollection::installedCollections
static QStringList installedCollections()
Query which KDE color collections are installed.
Definition: kcolorcollection.cpp:108
KColorCollection::findColor
int findColor(const QColor &color) const
Find index by color.
Definition: kcolorcollection.cpp:221
KColorCollection::addColor
int addColor(const QColor &newColor, const QString &newColorName=QString())
Add a color.
Definition: kcolorcollection.cpp:246
KColorCollection::save
bool save()
Save the collection.
Definition: kcolorcollection.cpp:141
KColorDialog
A color selection dialog.
Definition: kcolordialog.h:211
KColorDialog::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *)
Definition: kcolordialog.cpp:1742
KColorDialog::setAlphaChannelEnabled
void setAlphaChannelEnabled(bool alpha)
When set to true, the user is allowed to change the alpha component of the color.
Definition: kcolordialog.cpp:1376
KColorDialog::getColor
static int getColor(QColor &theColor, QWidget *parent=0L)
Creates a modal color dialog, let the user choose a color, and returns when the dialog is closed.
Definition: kcolordialog.cpp:1492
KColorDialog::defaultColor
QColor defaultColor
Definition: kcolordialog.h:214
KColorDialog::grabColor
static QColor grabColor(const QPoint &p)
Gets the color from the pixel at point p on the screen.
Definition: kcolordialog.cpp:1759
KColorDialog::color
QColor color
Definition: kcolordialog.h:215
KColorDialog::KColorDialog
KColorDialog(QWidget *parent=0L, bool modal=false)
Constructs a color selection dialog.
Definition: kcolordialog.cpp:1021
KColorDialog::colorSelected
void colorSelected(const QColor &col)
Emitted when a color is selected.
KColorDialog::~KColorDialog
~KColorDialog()
Destroys the color selection dialog.
Definition: kcolordialog.cpp:1315
KColorDialog::setColor
void setColor(const QColor &col)
Preselects a color.
Definition: kcolordialog.cpp:1484
KColorDialog::isAlphaChannelEnabled
bool isAlphaChannelEnabled
Definition: kcolordialog.h:213
KColorDialog::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *)
Definition: kcolordialog.cpp:1731
KColorDialog::eventFilter
virtual bool eventFilter(QObject *obj, QEvent *ev)
Definition: kcolordialog.cpp:1325
KColorDialog::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Definition: kcolordialog.cpp:1787
KColorDialog::setDefaultColor
void setDefaultColor(const QColor &defaultCol)
Call this to make the dialog show a "Default Color" checkbox.
Definition: kcolordialog.cpp:1343
KColorPatch
A color displayer.
Definition: kcolordialog.h:117
KColorPatch::colorChanged
void colorChanged(const QColor &)
This signal is emitted whenever the current color changes due to a drop event.
KColorPatch::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *)
Definition: kcolordialog.cpp:510
KColorPatch::dropEvent
virtual void dropEvent(QDropEvent *)
Definition: kcolordialog.cpp:523
KColorPatch::color
QColor color
Definition: kcolordialog.h:119
KColorPatch::~KColorPatch
virtual ~KColorPatch()
Definition: kcolordialog.cpp:485
KColorPatch::paintEvent
virtual void paintEvent(QPaintEvent *pe)
Definition: kcolordialog.cpp:502
KColorPatch::setColor
void setColor(const QColor &col)
Set the color to display and update the display.
Definition: kcolordialog.cpp:495
KColorPatch::KColorPatch
KColorPatch(QWidget *parent)
Definition: kcolordialog.cpp:478
KColorPatch::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *)
Definition: kcolordialog.cpp:518
KColorValueSelector
Definition: kcolorvalueselector.h:29
KComboBox
An enhanced combo box.
Definition: kcombobox.h:149
KConfigGroup
KDialog
A dialog base class with standard buttons and predefined layouts.
Definition: kdialog.h:129
KDialog::mainWidget
QWidget * mainWidget()
Definition: kdialog.cpp:351
KDialog::setMainWidget
void setMainWidget(QWidget *widget)
Sets the main widget of the dialog.
Definition: kdialog.cpp:338
KDialog::button
KPushButton * button(ButtonCode id) const
Returns the button that corresponds to the id.
Definition: kdialog.cpp:655
KDialog::sizeHint
virtual QSize sizeHint() const
Reimplemented from QDialog.
Definition: kdialog.cpp:359
KDialog::closeClicked
void closeClicked()
The Close button was pressed.
KDialog::keyPressEvent
virtual void keyPressEvent(QKeyEvent *)
Definition: kdialog.cpp:384
KDialog::spacingHint
static int spacingHint()
Returns the number of pixels that should be used between widgets inside a dialog according to the KDE...
Definition: kdialog.cpp:432
KDialog::setButtons
void setButtons(ButtonCodes buttonMask)
Creates (or recreates) the button box and all the buttons in it.
Definition: kdialog.cpp:206
KDialog::Ok
@ Ok
Show Ok button. (this button accept()s the dialog; result set to QDialog::Accepted)
Definition: kdialog.h:141
KDialog::Cancel
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition: kdialog.h:144
KDialog::Close
@ Close
Show Close-button. (this button closes the dialog)
Definition: kdialog.h:145
KDialog::buttonClicked
void buttonClicked(KDialog::ButtonCode button)
A button has been pressed.
KDialog::okClicked
void okClicked()
The OK button was pressed.
KDialog::setCaption
virtual void setCaption(const QString &caption)
Make a KDE compliant caption.
Definition: kdialog.cpp:469
KGlobalSettings::dndEventDelay
static int dndEventDelay()
Returns a threshold in pixels for drag & drop operations.
Definition: kglobalsettings.cpp:227
KGradientSelector
The KGradientSelector widget allows the user to choose from a one-dimensional range of colors which i...
Definition: kselector.h:133
KHBox
A container widget which arranges its children horizontally.
Definition: khbox.h:41
KHueSaturationSelector
Definition: khuesaturationselect.h:29
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:41
KIntSpinBox
A QSpinBox with support for arbitrary base numbers.
Definition: knuminput.h:718
KLineEdit
An enhanced QLineEdit widget for inputting text.
Definition: klineedit.h:150
KListWidget
A variant of QListWidget that honors KDE's system-wide settings.
Definition: klistwidget.h:41
KLocale::insertCatalog
void insertCatalog(const QString &catalog)
KMessageBox::sorry
static void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
Display an "Sorry" dialog.
Definition: kmessagebox.cpp:904
KStandardDirs::locate
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
QFrame
QLabel
QMap
QObject
QPushButton
QTableWidget
QWidget
fixx11h.h
kDebug
#define kDebug
kapplication.h
kapp
#define kapp
Definition: kapplication.h:56
KColorChooserMode
KColorChooserMode
Definition: kcolorchoosermode.h:23
ChooserHue
@ ChooserHue
Definition: kcolorchoosermode.h:25
ChooserBlue
@ ChooserBlue
Definition: kcolorchoosermode.h:30
ChooserGreen
@ ChooserGreen
Definition: kcolorchoosermode.h:29
ChooserClassic
@ ChooserClassic
Definition: kcolorchoosermode.h:24
ChooserValue
@ ChooserValue
Definition: kcolorchoosermode.h:27
ChooserSaturation
@ ChooserSaturation
Definition: kcolorchoosermode.h:26
ChooserRed
@ ChooserRed
Definition: kcolorchoosermode.h:28
kcolorcollection.h
ColorCollectionIndices
ColorCollectionIndices
Definition: kcolordialog.cpp:113
fortyColorIndex
@ fortyColorIndex
Definition: kcolordialog.cpp:116
customColorIndex
@ customColorIndex
Definition: kcolordialog.cpp:115
recentColorIndex
@ recentColorIndex
Definition: kcolordialog.cpp:114
colorCollectionName
static const ColorCollectionNameType colorCollectionName[]
Definition: kcolordialog.cpp:101
namedColorFilePath
static const char *const * namedColorFilePath(void)
Definition: kcolordialog.cpp:618
kcolordialog.h
kcolormimedata.h
kcolorutils.h
kcolorvalueselector.h
kcombobox.h
kconfig.h
indent
QString indent(QString text, int spaces)
kconfiggroup.h
kdebug.h
kglobal.h
kglobalsettings.h
khbox.h
khuesaturationselect.h
kiconloader.h
klineedit.h
klistwidget.h
klocale.h
i18n
QString i18n(const char *text)
i18nc
QString i18nc(const char *ctxt, const char *text)
i18ncp
QString i18ncp(const char *ctxt, const char *sing, const char *plur, const A1 &a1)
kmessagebox.h
knuminput.h
kselector.h
kseparator.h
kstandarddirs.h
I18N_NOOP2
#define I18N_NOOP2(comment, x)
We need to remember the context to get the correct translation.
Definition: kstandardshortcut.cpp:68
kxyselector.h
KColorMimeData::createDrag
QDrag * createDrag(const QColor &color, QWidget *dragsource)
Creates a color drag object.
Definition: kcolormimedata.cpp:61
KColorMimeData::fromMimeData
QColor fromMimeData(const QMimeData *mimeData)
Decodes the MIME data mimeData and returns the resulting color.
Definition: kcolormimedata.cpp:50
KColorMimeData::canDecode
bool canDecode(const QMimeData *mimeData)
Returns true if the MIME data mimeData contains a color object.
Definition: kcolormimedata.cpp:36
KColorUtils::shade
QColor shade(const QColor &, qreal lumaAmount, qreal chromaAmount=0.0)
Adjust the luma and chroma components of a color.
Definition: kcolorutils.cpp:71
KColorUtils::contrastRatio
qreal contrastRatio(const QColor &, const QColor &)
Calculate the contrast ratio between two colors, according to the W3C/WCAG2.0 algorithm,...
Definition: kcolorutils.cpp:50
KDEPrivate
Definition: kcolorchoosermode.cpp:24
KDEPrivate::getComponentValue
qreal getComponentValue(const QColor &color, KColorChooserMode chooserMode)
Definition: kcolorchoosermode.cpp:26
KDEPrivate::setComponentValue
void setComponentValue(QColor &color, KColorChooserMode chooserMode, qreal value)
Definition: kcolorchoosermode.cpp:44
KDEPrivate::fillOpaqueRect
void fillOpaqueRect(QPainter *painter, const QRect &rect, const QBrush &brush)
Definition: kcolorhelpers.cpp:28
KGlobal::locale
KLocale * locale()
KGlobal::config
KSharedConfigPtr config()
group
group
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
Window
Window
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal