Add web color QLineEdit to QColorDialog.
This web color QLineEdit shows the hex number of the selected color. Besides, it can be edited and accepts 3 and 6 digit hex numbers. Change-Id: Idf629fbdc203fc099d446b31cbb49f2ff56be810 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
This commit is contained in:
parent
c886491ad0
commit
24466d3542
@ -918,6 +918,8 @@ signals:
|
|||||||
private slots:
|
private slots:
|
||||||
void rgbEd();
|
void rgbEd();
|
||||||
void hsvEd();
|
void hsvEd();
|
||||||
|
void htmlEd();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void showCurrentColor();
|
void showCurrentColor();
|
||||||
int hue, sat, val;
|
int hue, sat, val;
|
||||||
@ -929,6 +931,7 @@ private:
|
|||||||
QLabel *lblRed;
|
QLabel *lblRed;
|
||||||
QLabel *lblGreen;
|
QLabel *lblGreen;
|
||||||
QLabel *lblBlue;
|
QLabel *lblBlue;
|
||||||
|
QLabel *lblHtml;
|
||||||
QColSpinBox *hEd;
|
QColSpinBox *hEd;
|
||||||
QColSpinBox *sEd;
|
QColSpinBox *sEd;
|
||||||
QColSpinBox *vEd;
|
QColSpinBox *vEd;
|
||||||
@ -937,6 +940,7 @@ private:
|
|||||||
QColSpinBox *bEd;
|
QColSpinBox *bEd;
|
||||||
QColSpinBox *alphaEd;
|
QColSpinBox *alphaEd;
|
||||||
QLabel *alphaLab;
|
QLabel *alphaLab;
|
||||||
|
QLineEdit *htEd;
|
||||||
QColorShowLabel *lab;
|
QColorShowLabel *lab;
|
||||||
bool rgbOriginal;
|
bool rgbOriginal;
|
||||||
QColorDialog *colorDialog;
|
QColorDialog *colorDialog;
|
||||||
@ -1228,6 +1232,19 @@ QColorShower::QColorShower(QColorDialog *parent)
|
|||||||
#endif
|
#endif
|
||||||
alphaEd->hide();
|
alphaEd->hide();
|
||||||
alphaLab->hide();
|
alphaLab->hide();
|
||||||
|
lblHtml = new QLabel(this);
|
||||||
|
htEd = new QLineEdit(this);
|
||||||
|
#ifndef QT_NO_SHORTCUT
|
||||||
|
lblHtml->setBuddy(htEd);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QRegularExpression regExp(QStringLiteral("#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})"));
|
||||||
|
QRegularExpressionValidator *validator = new QRegularExpressionValidator(regExp, this);
|
||||||
|
htEd->setValidator(validator);
|
||||||
|
|
||||||
|
lblHtml->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
||||||
|
gl->addWidget(lblHtml, 5, 1);
|
||||||
|
gl->addWidget(htEd, 5, 2);
|
||||||
|
|
||||||
connect(hEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));
|
connect(hEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));
|
||||||
connect(sEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));
|
connect(sEd, SIGNAL(valueChanged(int)), this, SLOT(hsvEd()));
|
||||||
@ -1237,6 +1254,7 @@ QColorShower::QColorShower(QColorDialog *parent)
|
|||||||
connect(gEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
|
connect(gEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
|
||||||
connect(bEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
|
connect(bEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
|
||||||
connect(alphaEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
|
connect(alphaEd, SIGNAL(valueChanged(int)), this, SLOT(rgbEd()));
|
||||||
|
connect(htEd, SIGNAL(textEdited(QString)), this, SLOT(htmlEd()));
|
||||||
|
|
||||||
retranslateStrings();
|
retranslateStrings();
|
||||||
}
|
}
|
||||||
@ -1271,6 +1289,8 @@ void QColorShower::rgbEd()
|
|||||||
sEd->setValue(sat);
|
sEd->setValue(sat);
|
||||||
vEd->setValue(val);
|
vEd->setValue(val);
|
||||||
|
|
||||||
|
htEd->setText(QColor(curCol).name());
|
||||||
|
|
||||||
showCurrentColor();
|
showCurrentColor();
|
||||||
emit newCol(currentColor());
|
emit newCol(currentColor());
|
||||||
updateQColor();
|
updateQColor();
|
||||||
@ -1291,6 +1311,31 @@ void QColorShower::hsvEd()
|
|||||||
gEd->setValue(qGreen(currentColor()));
|
gEd->setValue(qGreen(currentColor()));
|
||||||
bEd->setValue(qBlue(currentColor()));
|
bEd->setValue(qBlue(currentColor()));
|
||||||
|
|
||||||
|
htEd->setText(c.name());
|
||||||
|
|
||||||
|
showCurrentColor();
|
||||||
|
emit newCol(currentColor());
|
||||||
|
updateQColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QColorShower::htmlEd()
|
||||||
|
{
|
||||||
|
QColor c;
|
||||||
|
QString t = htEd->text();
|
||||||
|
c.setNamedColor(t);
|
||||||
|
if (!c.isValid())
|
||||||
|
return;
|
||||||
|
curCol = qRgba(c.red(), c.green(), c.blue(), currentAlpha());
|
||||||
|
rgb2hsv(curCol, hue, sat, val);
|
||||||
|
|
||||||
|
hEd->setValue(hue);
|
||||||
|
sEd->setValue(sat);
|
||||||
|
vEd->setValue(val);
|
||||||
|
|
||||||
|
rEd->setValue(qRed(currentColor()));
|
||||||
|
gEd->setValue(qGreen(currentColor()));
|
||||||
|
bEd->setValue(qBlue(currentColor()));
|
||||||
|
|
||||||
showCurrentColor();
|
showCurrentColor();
|
||||||
emit newCol(currentColor());
|
emit newCol(currentColor());
|
||||||
updateQColor();
|
updateQColor();
|
||||||
@ -1311,6 +1356,8 @@ void QColorShower::setRgb(QRgb rgb)
|
|||||||
gEd->setValue(qGreen(currentColor()));
|
gEd->setValue(qGreen(currentColor()));
|
||||||
bEd->setValue(qBlue(currentColor()));
|
bEd->setValue(qBlue(currentColor()));
|
||||||
|
|
||||||
|
htEd->setText(QColor(rgb).name());
|
||||||
|
|
||||||
showCurrentColor();
|
showCurrentColor();
|
||||||
updateQColor();
|
updateQColor();
|
||||||
}
|
}
|
||||||
@ -1334,6 +1381,8 @@ void QColorShower::setHsv(int h, int s, int v)
|
|||||||
gEd->setValue(qGreen(currentColor()));
|
gEd->setValue(qGreen(currentColor()));
|
||||||
bEd->setValue(qBlue(currentColor()));
|
bEd->setValue(qBlue(currentColor()));
|
||||||
|
|
||||||
|
htEd->setText(c.name());
|
||||||
|
|
||||||
showCurrentColor();
|
showCurrentColor();
|
||||||
updateQColor();
|
updateQColor();
|
||||||
}
|
}
|
||||||
@ -1347,6 +1396,7 @@ void QColorShower::retranslateStrings()
|
|||||||
lblGreen->setText(QColorDialog::tr("&Green:"));
|
lblGreen->setText(QColorDialog::tr("&Green:"));
|
||||||
lblBlue->setText(QColorDialog::tr("Bl&ue:"));
|
lblBlue->setText(QColorDialog::tr("Bl&ue:"));
|
||||||
alphaLab->setText(QColorDialog::tr("A&lpha channel:"));
|
alphaLab->setText(QColorDialog::tr("A&lpha channel:"));
|
||||||
|
lblHtml->setText(QColorDialog::tr("&HTML:"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void QColorShower::updateQColor()
|
void QColorShower::updateQColor()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user