Commit 73eb12ee authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Add a little combobox that allows you to search the palette colornames

If I was better with regexp it might've been a bit smoother, but at the least you can now type in a colorname to select it quickly.

Ref T2438
parent 68c2c8ed
......@@ -63,6 +63,9 @@ void KoColorSetWidget::KoColorSetWidgetPrivate::fillColors()
}
colorSetContainer->setMinimumWidth(columns*12+6);
colorSetContainer->setLayout(colorSetLayout);
patchWidgetList.clear();
colornames.clear();
colorNameCmb->clear();
if (colorSet) {
for( int i = 0, p= 0; i < colorSet->nColors(); i++) {
......@@ -75,11 +78,16 @@ void KoColorSetWidget::KoColorSetWidgetPrivate::fillColors()
colorSetLayout->addWidget(patch, p/columns, p%columns);
patch->setDisplayRenderer(displayRenderer);
patchWidgetList.append(patch);
colornames.append(colorSet->getColor(i).name);
QPixmap colorsquare = QPixmap(12,12);
colorsquare.fill(colorSet->getColor(i).color.toQColor());
colorNameCmb->addItem(QIcon(colorsquare), colorSet->getColor(i).name);
++p;
}
}
scrollArea->setWidget(colorSetContainer);
connect(colorNameCmb, SIGNAL(activated(QString)), thePublic, SLOT(setColorFromString(QString)), Qt::UniqueConnection);
}
void KoColorSetWidget::KoColorSetWidgetPrivate::addRemoveColors()
......@@ -178,8 +186,13 @@ KoColorSetWidget::KoColorSetWidget(QWidget *parent)
d->scrollArea = new QScrollArea();
d->scrollArea->setBackgroundRole(QPalette::Dark);
d->mainLayout->addWidget(d->scrollArea);
d->colorNameCmb = new QComboBox(this);
d->colorNameCmb->setEditable(true);
d->colorNameCmb->setInsertPolicy(QComboBox::NoInsert);
d->mainLayout->addWidget(d->colorNameCmb);
d->fillColors();
d->addRemoveButton = new QToolButton(this);
d->addRemoveButton->setText(i18n("Add / Remove Colors..."));
d->addRemoveButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
......@@ -219,6 +232,13 @@ void KoColorSetWidget::KoColorSetWidgetPrivate::colorTriggered(KoColorPatch *pat
addRecent(patch->color());
}
void KoColorSetWidget::KoColorSetWidgetPrivate::setColorFromString(QString s)
{
int i = colornames.indexOf(QRegExp(s+"|Fixed"));
i = qMax(i,0);
colorTriggered(patchWidgetList.at(i));
}
void KoColorSetWidget::setColorSet(KoColorSet *colorSet)
{
if (colorSet == d->colorSet) return;
......
......@@ -98,6 +98,7 @@ Q_SIGNALS:
private:
Q_PRIVATE_SLOT(d, void colorTriggered(KoColorPatch *))
Q_PRIVATE_SLOT(d, void addRemoveColors())
Q_PRIVATE_SLOT(d, void setColorFromString(QString s))
class KoColorSetWidgetPrivate;
KoColorSetWidgetPrivate * const d;
......
......@@ -36,6 +36,7 @@
#include <QDir>
#include <QPointer>
#include <QScrollArea>
#include <QComboBox>
#include <klocalizedstring.h>
#include <WidgetsDebug.h>
......@@ -58,6 +59,8 @@ public:
QHBoxLayout *recentsLayout;
KoColorPatch *recentPatches[6];
QToolButton *addRemoveButton;
QComboBox *colorNameCmb;
QStringList colornames;
int numRecents;
void colorTriggered(KoColorPatch *patch);
......@@ -65,6 +68,7 @@ public:
void activateRecent(int i);
void fillColors();
void addRemoveColors();
void setColorFromString(QString s);
QList<KoColorPatch*> patchWidgetList;
const KoColorDisplayRendererInterface *displayRenderer;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment