File indexing completed on 2025-02-16 13:11:53
0001 /* 0002 This file is part of the KDE Libraries 0003 SPDX-FileCopyrightText: 2007 David Jarvie <djarvie@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "kcolorcombotest.h" 0009 0010 #include <QApplication> 0011 #include <QDebug> 0012 #include <QHBoxLayout> 0013 #include <QLabel> 0014 #include <QPushButton> 0015 #include <QVBoxLayout> 0016 #include <kcolorcombo.h> 0017 0018 KColorComboTest::KColorComboTest(QWidget *widget) 0019 : QWidget(widget) 0020 { 0021 QVBoxLayout *vbox = new QVBoxLayout(this); 0022 QHBoxLayout *hboxLayout = new QHBoxLayout(this); 0023 0024 // Standard color list 0025 QLabel *lbl = new QLabel(QStringLiteral("&Standard colors:"), this); 0026 lbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); 0027 0028 mStandard = new KColorCombo(this); 0029 mStandard->setObjectName(QStringLiteral("StandardColors")); 0030 lbl->setBuddy(mStandard); 0031 QLabel *lblPreset = new QLabel(QStringLiteral("Preset to green (0,255,0)"), this); 0032 0033 // add to box layout 0034 hboxLayout->addWidget(lbl); 0035 hboxLayout->addWidget(mStandard); 0036 hboxLayout->addWidget(lblPreset); 0037 vbox->addLayout(hboxLayout); 0038 0039 hboxLayout = new QHBoxLayout(this); 0040 0041 // Custom color list 0042 lbl = new QLabel(QStringLiteral("&Reds, greens, blues:"), this); 0043 lbl->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); 0044 0045 mCustom = new KColorCombo(this); 0046 mCustom->setObjectName(QStringLiteral("CustomColors")); 0047 lbl->setBuddy(mCustom); 0048 lblPreset = new QLabel(QStringLiteral("Preset to green (0,192,0)"), this); 0049 0050 // add to box layout 0051 hboxLayout->addWidget(lbl); 0052 hboxLayout->addWidget(mCustom); 0053 hboxLayout->addWidget(lblPreset); 0054 vbox->addLayout(hboxLayout); 0055 0056 // Create an exit button 0057 mExit = new QPushButton(QStringLiteral("E&xit"), this); 0058 QObject::connect(mExit, &QAbstractButton::clicked, this, &KColorComboTest::quitApp); 0059 0060 vbox->addWidget(mExit); 0061 0062 // Populate the custom list 0063 QList<QColor> standardList; 0064 standardList << Qt::red << Qt::green << Qt::blue << Qt::cyan << Qt::magenta << Qt::yellow << Qt::darkRed << Qt::darkGreen << Qt::darkBlue << Qt::darkCyan 0065 << Qt::darkMagenta << Qt::darkYellow << Qt::white << Qt::lightGray << Qt::gray << Qt::darkGray << Qt::black; 0066 QList<QColor> list; 0067 list << QColor(255, 0, 0) << QColor(192, 0, 0) << QColor(128, 0, 0) << QColor(64, 0, 0) << QColor(0, 255, 0) << QColor(0, 192, 0) << QColor(0, 128, 0) 0068 << QColor(0, 64, 0) << QColor(0, 0, 255) << QColor(0, 0, 192) << QColor(0, 0, 128) << QColor(0, 0, 64); 0069 mCustom->setColors(list); 0070 if (mCustom->colors() != list) { 0071 qCritical() << "Custom combo: setColors() != colors()"; 0072 } 0073 mCustom->setColors(QList<QColor>()); 0074 if (mCustom->colors() != standardList) { 0075 qCritical() << "Custom combo: setColors(empty) != standard colors"; 0076 } 0077 mCustom->setColors(list); 0078 if (mCustom->colors() != list) { 0079 qCritical() << "Custom combo: setColors() != colors()"; 0080 } 0081 0082 if (mStandard->colors() != standardList) { 0083 qCritical() << "Standard combo: colors()"; 0084 } 0085 0086 QColor col = QColor(1, 2, 3); 0087 mStandard->setColor(col); 0088 if (mStandard->color() != col) { 0089 qCritical() << "Standard combo: set custom color -> " << mStandard->color().red() << "," << mStandard->color().green() << "," 0090 << mStandard->color().blue(); 0091 } 0092 if (!mStandard->isCustomColor()) { 0093 qCritical() << "Standard combo: custom color: isCustomColor() -> false"; 0094 } 0095 mStandard->setColor(Qt::green); 0096 if (mStandard->color() != Qt::green) { 0097 qCritical() << "Standard combo: color() -> " << mStandard->color().red() << "," << mStandard->color().green() << "," << mStandard->color().blue(); 0098 } 0099 if (mStandard->isCustomColor()) { 0100 qCritical() << "Standard combo: standard color: isCustomColor() -> true"; 0101 } 0102 0103 col = QColor(1, 2, 3); 0104 mCustom->setColor(col); 0105 if (mCustom->color() != col) { 0106 qCritical() << "Custom combo: set custom color -> " << mCustom->color().red() << "," << mCustom->color().green() << "," << mCustom->color().blue(); 0107 } 0108 if (!mCustom->isCustomColor()) { 0109 qCritical() << "Custom combo: custom color: isCustomColor() -> false"; 0110 } 0111 col = QColor(0, 192, 0); 0112 mCustom->setColor(col); 0113 if (mCustom->color() != col) { 0114 qCritical() << "Custom combo: color() -> " << mCustom->color().red() << "," << mCustom->color().green() << "," << mCustom->color().blue(); 0115 } 0116 if (mCustom->isCustomColor()) { 0117 qCritical() << "Custom combo: standard color: isCustomColor() -> true"; 0118 } 0119 } 0120 0121 KColorComboTest::~KColorComboTest() 0122 { 0123 } 0124 0125 void KColorComboTest::quitApp() 0126 { 0127 qApp->closeAllWindows(); 0128 } 0129 0130 int main(int argc, char **argv) 0131 { 0132 QApplication a(argc, argv); 0133 a.setAttribute(Qt::AA_UseHighDpiPixmaps, true); 0134 0135 KColorComboTest *t = new KColorComboTest; 0136 t->show(); 0137 return a.exec(); 0138 } 0139 0140 #include "moc_kcolorcombotest.cpp"