summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-02-04 16:20:01 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-07 01:22:40 +0100
commitee317360e305c75b8a0050b9344895eb6990cfff (patch)
tree094d901ed3e081e8b5d5c7092cb6bd68bdc04a4f
parent0de3ea6554bbf19aec66498e4c9345d5777d9edc (diff)
QColorDialog manual test: add initial color selection
Change-Id: I956404af728ef0d70977f6c69b1059b3656edd91 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r--tests/manual/dialogs/colordialogpanel.cpp74
-rw-r--r--tests/manual/dialogs/colordialogpanel.h2
2 files changed, 74 insertions, 2 deletions
diff --git a/tests/manual/dialogs/colordialogpanel.cpp b/tests/manual/dialogs/colordialogpanel.cpp
index 95683b2a63..695e37a4c7 100644
--- a/tests/manual/dialogs/colordialogpanel.cpp
+++ b/tests/manual/dialogs/colordialogpanel.cpp
@@ -47,9 +47,41 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMessageBox>
+#include <QSortFilterProxyModel>
+#include <QComboBox>
#include <QTimer>
#include <QDebug>
+// SVG color keyword names provided by the World Wide Web Consortium
+static inline QStringList svgColorNames()
+{
+ return QStringList()
+ << "aliceblue" << "antiquewhite" << "aqua" << "aquamarine" << "azure" << "beige" << "bisque"
+ << "black" << "blanchedalmond" << "blue" << "blueviolet" << "brown" << "burlywood" << "cadetblue"
+ << "chartreuse" << "chocolate" << "coral" << "cornflowerblue" << "cornsilk" << "crimson" << "cyan"
+ << "darkblue" << "darkcyan" << "darkgoldenrod" << "darkgray" << "darkgreen" << "darkgrey"
+ << "darkkhaki" << "darkmagenta" << "darkolivegreen" << "darkorange" << "darkorchid" << "darkred"
+ << "darksalmon" << "darkseagreen" << "darkslateblue" << "darkslategray" << "darkslategrey"
+ << "darkturquoise" << "darkviolet" << "deeppink" << "deepskyblue" << "dimgray" << "dimgrey"
+ << "dodgerblue" << "firebrick" << "floralwhite" << "forestgreen" << "fuchsia" << "gainsboro"
+ << "ghostwhite" << "gold" << "goldenrod" << "gray" << "grey" << "green" << "greenyellow"
+ << "honeydew" << "hotpink" << "indianred" << "indigo" << "ivory" << "khaki" << "lavender"
+ << "lavenderblush" << "lawngreen" << "lemonchiffon" << "lightblue" << "lightcoral" << "lightcyan"
+ << "lightgoldenrodyellow" << "lightgray" << "lightgreen" << "lightgrey" << "lightpink"
+ << "lightsalmon" << "lightseagreen" << "lightskyblue" << "lightslategray" << "lightslategrey"
+ << "lightsteelblue" << "lightyellow" << "lime" << "limegreen" << "linen" << "magenta"
+ << "maroon" << "mediumaquamarine" << "mediumblue" << "mediumorchid" << "mediumpurple"
+ << "mediumseagreen" << "mediumslateblue" << "mediumspringgreen" << "mediumturquoise"
+ << "mediumvioletred" << "midnightblue" << "mintcream" << "mistyrose" << "moccasin"
+ << "navajowhite" << "navy" << "oldlace" << "olive" << "olivedrab" << "orange" << "orangered"
+ << "orchid" << "palegoldenrod" << "palegreen" << "paleturquoise" << "palevioletred"
+ << "papayawhip" << "peachpuff" << "peru" << "pink" << "plum" << "powderblue" << "purple" << "red"
+ << "rosybrown" << "royalblue" << "saddlebrown" << "salmon" << "sandybrown" << "seagreen"
+ << "seashell" << "sienna" << "silver" << "skyblue" << "slateblue" << "slategray" << "slategrey"
+ << "snow" << "springgreen" << "steelblue" << "tan" << "teal" << "thistle" << "tomato"
+ << "turquoise" << "violet" << "wheat" << "white" << "whitesmoke" << "yellow" << "yellowgreen";
+}
+
static inline QPushButton *addButton(const QString &description, QVBoxLayout *layout,
QObject *receiver, const char *slotFunc)
{
@@ -59,8 +91,28 @@ static inline QPushButton *addButton(const QString &description, QVBoxLayout *la
return button;
}
+class ColorProxyModel : public QSortFilterProxyModel
+{
+public:
+ ColorProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent)
+ {
+ }
+
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const
+ {
+ if (role == Qt::DisplayRole) {
+ QString name = data(index, Qt::EditRole).toString();
+ return tr("%1 (%2)").arg(name, QColor(name).name());
+ }
+ if (role == Qt::DecorationRole)
+ return QColor(data(index, Qt::EditRole).toString());
+ return QSortFilterProxyModel::data(index, role);
+ }
+};
+
ColorDialogPanel::ColorDialogPanel(QWidget *parent)
: QWidget(parent)
+ , m_colorComboBox(new QComboBox)
, m_showAlphaChannel(new QCheckBox(tr("Show alpha channel")))
, m_noButtons(new QCheckBox(tr("Don't display OK/Cancel buttons")))
, m_dontUseNativeDialog(new QCheckBox(tr("Don't use native dialog")))
@@ -71,7 +123,19 @@ ColorDialogPanel::ColorDialogPanel(QWidget *parent)
optionsLayout->addWidget(m_showAlphaChannel);
optionsLayout->addWidget(m_noButtons);
optionsLayout->addWidget(m_dontUseNativeDialog);
- optionsLayout->addStretch();
+
+ // Color
+ QGroupBox *colorGroupBox = new QGroupBox(tr("Color"), this);
+ QVBoxLayout *colorLayout = new QVBoxLayout(colorGroupBox);
+ colorLayout->addWidget(m_colorComboBox);
+ m_colorComboBox->addItems(svgColorNames());
+ m_colorComboBox->setEditable(true);
+
+ QAbstractItemModel *sourceModel = m_colorComboBox->model();
+ ColorProxyModel* proxyModel = new ColorProxyModel(m_colorComboBox);
+ proxyModel->setSourceModel(sourceModel);
+ sourceModel->setParent(proxyModel);
+ m_colorComboBox->setModel(proxyModel);
// Buttons
QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show"));
@@ -88,9 +152,14 @@ ColorDialogPanel::ColorDialogPanel(QWidget *parent)
// Main layout
QHBoxLayout *mainLayout = new QHBoxLayout(this);
- mainLayout->addWidget(optionsGroupBox);
+ QVBoxLayout *leftLayout = new QVBoxLayout;
+ leftLayout->addWidget(optionsGroupBox);
+ leftLayout->addWidget(colorGroupBox);
+ leftLayout->addStretch();
+ mainLayout->addLayout(leftLayout);
mainLayout->addWidget(buttonsGroupBox);
+ enableDeleteModalDialogButton();
enableDeleteNonModalDialogButton();
restoreDefaults();
}
@@ -188,4 +257,5 @@ void ColorDialogPanel::applySettings(QColorDialog *d) const
d->setOption(QColorDialog::ShowAlphaChannel, m_showAlphaChannel->isChecked());
d->setOption(QColorDialog::NoButtons, m_noButtons->isChecked());
d->setOption(QColorDialog::DontUseNativeDialog, m_dontUseNativeDialog->isChecked());
+ d->setCurrentColor(QColor(m_colorComboBox->itemData(m_colorComboBox->currentIndex(), Qt::EditRole).toString()));
}
diff --git a/tests/manual/dialogs/colordialogpanel.h b/tests/manual/dialogs/colordialogpanel.h
index 2aa06b98d4..bcd2cf6e52 100644
--- a/tests/manual/dialogs/colordialogpanel.h
+++ b/tests/manual/dialogs/colordialogpanel.h
@@ -45,6 +45,7 @@
#include <QPointer>
#include <QColorDialog>
+class QComboBox;
class QCheckBox;
class QPushButton;
@@ -71,6 +72,7 @@ private slots:
private:
void applySettings(QColorDialog *d) const;
+ QComboBox *m_colorComboBox;
QCheckBox *m_showAlphaChannel;
QCheckBox *m_noButtons;
QCheckBox *m_dontUseNativeDialog;