File indexing completed on 2024-05-26 12:32:18

0001 // SPDX-FileCopyrightText: Lukas Sommer <sommerluk@gmail.com>
0002 // SPDX-License-Identifier: BSD-2-Clause OR MIT
0003 
0004 #include "absolutecolor.h" // IWYU pragma: keep
0005 #include "asyncimageprovider.h" // IWYU pragma: keep
0006 #include "asyncimageproviderbase.h" // IWYU pragma: keep
0007 #include "chromalightnessimageparameters.h" // IWYU pragma: keep
0008 #include "colordialog.h" // IWYU pragma: keep
0009 #include "colordialog_p.h" // IWYU pragma: keep
0010 #include "colorpatch.h" // IWYU pragma: keep
0011 #include "colorpatch_p.h" // IWYU pragma: keep
0012 #include "constpropagatinguniquepointer.h" // IWYU pragma: keep
0013 #include "csscolor.h" // IWYU pragma: keep
0014 #include "genericcolor.h" // IWYU pragma: keep
0015 #include "helper.h" // IWYU pragma: keep
0016 #include "helperconstants.h" // IWYU pragma: keep
0017 #include "helperconversion.h" // IWYU pragma: keep
0018 #include "helpermath.h" // IWYU pragma: keep
0019 #include "helperposixmath.h" // IWYU pragma: keep
0020 #include "initializetranslation.h" // IWYU pragma: keep
0021 #include "oklchvalues.h" // IWYU pragma: keep
0022 #include "perceptualsettings.h" // IWYU pragma: keep
0023 #include "polarpointf.h" // IWYU pragma: keep
0024 #include "rgbcolorspace.h" // IWYU pragma: keep
0025 #include "rgbcolorspacefactory.h" // IWYU pragma: keep
0026 #include "setting.h" // IWYU pragma: keep
0027 #include "settingbase.h" // IWYU pragma: keep
0028 #include "settings.h" // IWYU pragma: keep
0029 #include "version.h" // IWYU pragma: keep
0030 #include <qapplication.h> // IWYU pragma: keep
0031 #include <qcolor.h> // IWYU pragma: keep
0032 #include <qcolordialog.h> // IWYU pragma: keep
0033 #include <qcommonstyle.h> // IWYU pragma: keep
0034 #include <qcontainerfwd.h> // IWYU pragma: keep
0035 #include <qcoreapplication.h> // IWYU pragma: keep
0036 #include <qcoreevent.h> // IWYU pragma: keep
0037 #include <qdebug.h> // IWYU pragma: keep
0038 #include <qdialogbuttonbox.h> // IWYU pragma: keep
0039 #include <qfileinfo.h> // IWYU pragma: keep
0040 #include <qfontdatabase.h> // IWYU pragma: keep
0041 #include <qgenericmatrix.h> // IWYU pragma: keep
0042 #include <qglobal.h> // IWYU pragma: keep
0043 #include <qhash.h> // IWYU pragma: keep
0044 #include <qlabel.h> // IWYU pragma: keep
0045 #include <qlayout.h> // IWYU pragma: keep
0046 #include <qlibraryinfo.h> // IWYU pragma: keep
0047 #include <qlineedit.h> // IWYU pragma: keep
0048 #include <qlist.h> // IWYU pragma: keep
0049 #include <qlocale.h> // IWYU pragma: keep
0050 #include <qmath.h> // IWYU pragma: keep
0051 #include <qmetaobject.h> // IWYU pragma: keep
0052 #include <qnamespace.h> // IWYU pragma: keep
0053 #include <qobject.h> // IWYU pragma: keep
0054 #include <qpixmap.h> // IWYU pragma: keep
0055 #include <qpluginloader.h> // IWYU pragma: keep
0056 #include <qpointer.h> // IWYU pragma: keep
0057 #include <qrect.h> // IWYU pragma: keep
0058 #include <qregularexpression.h> // IWYU pragma: keep
0059 #include <qscopedpointer.h> // IWYU pragma: keep
0060 #include <qsettings.h> // IWYU pragma: keep
0061 #include <qsharedpointer.h> // IWYU pragma: keep
0062 #include <qsize.h> // IWYU pragma: keep
0063 #include <qsizepolicy.h> // IWYU pragma: keep
0064 #include <qstring.h> // IWYU pragma: keep
0065 #include <qstringlist.h> // IWYU pragma: keep
0066 #include <qstringliteral.h> // IWYU pragma: keep
0067 #include <qstyle.h> // IWYU pragma: keep
0068 #include <qstylefactory.h> // IWYU pragma: keep
0069 #include <qthread.h> // IWYU pragma: keep
0070 #include <qtimer.h> // IWYU pragma: keep
0071 #include <qtranslator.h> // IWYU pragma: keep
0072 #include <utility> // IWYU pragma: keep
0073 
0074 using namespace PerceptualColor;
0075 
0076 // This is just a program for testing purposes.
0077 int main(int argc, char *argv[])
0078 {
0079 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0080     // Prepare configuration before instantiating the application object
0081     QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
0082 #endif
0083 
0084     // Instantiate the application object
0085     QApplication app(argc, argv);
0086 
0087     // QLocale::setDefault(QLocale::Bengali);
0088     // QLocale::setDefault(QLocale(QLocale::German, QLocale::Country::Germany));
0089     // QLocale::setDefault(QLocale(QLocale::Georgian));
0090     QLocale::setDefault(QLocale::English);
0091     // QLocale::setDefault(QLocale::French);
0092     // QLocale::setDefault(QLocale::Spanish);
0093     // QLocale::setDefault(QLocale::Ukrainian);
0094     // QLocale::setDefault(QLocale::Turkish);
0095     // QLocale::setDefault(QLocale::Chinese);
0096 
0097     PerceptualColor::initializeTranslation(QCoreApplication::instance(), //
0098                                            QLocale().uiLanguages());
0099 
0100     app.setLayoutDirection(Qt::RightToLeft);
0101 
0102     // Initialize the color dialog
0103 
0104     auto myColorSpace = //
0105         PerceptualColor::RgbColorSpaceFactory::createFromFile(
0106             // QStringLiteral("/usr/share/color/icc/colord/WideGamutRGB.icc") //
0107             // QStringLiteral("/usr/share/color/icc/test/PhotoGamutRGB_avg6c.icc")
0108             // QStringLiteral("WideGamutRGB.icc") //
0109             // QStringLiteral("/usr/share/color/icc/compatibleWithAdobeRGB1998.icc")
0110             QStringLiteral("invalid")
0111             // QStringLiteral("/usr/share/color/icc/sRGB.icc")
0112             // QStringLiteral("/usr/share/color/icc/krita/Rec2020-elle-V4-g10.icc") //
0113             // QStringLiteral("/usr/share/color/icc/krita/LargeRGB-elle-V2-g22.icc") //
0114             // QStringLiteral("/usr/share/color/icc/krita/WideRGB-elle-V2-g22.icc") //
0115             // QStringLiteral("/usr/share/color/icc/krita/XYZ-D50-Identity-elle-V4.icc") //
0116             // QStringLiteral("/usr/share/color/icc/krita/ACEScg-elle-V4-g10.icc") //
0117             // QStringLiteral("/usr/share/color/icc/krita/cmyk.icm") //
0118             // QStringLiteral("/usr/share/color/icc/krita/ITUR_2100_PQ_FULL.ICC") //
0119             // QStringLiteral("/usr/share/color/icc/ECI-RGB.V1.0.icc") //
0120         );
0121     if (myColorSpace.isNull()) {
0122         myColorSpace = PerceptualColor::RgbColorSpaceFactory::createSrgb();
0123     }
0124 
0125     PerceptualColor::ColorDialog m_colorDialog(myColorSpace);
0126     // For session management, according to https://doc.qt.io/qt-6/session.html
0127     //     “you must identify your top level widgets with
0128     //      unique application-wide object names”
0129     m_colorDialog.setObjectName(QStringLiteral("Percptual color dialog"));
0130     m_colorDialog.setOption(QColorDialog::ColorDialogOption::ShowAlphaChannel, true);
0131     QColor myColor = QColor(Qt::yellow);
0132     myColor.setAlphaF(0.5);
0133     // m_colorDialog.setCurrentColor(myColor);
0134     // m_colorDialog.setOption(QColorDialog::ColorDialogOption::NoButtons);
0135     // m_colorDialog.setLayoutDimensions(PerceptualColor::ColorDialog::DialogLayoutDimensions::Expanded);
0136     // m_colorDialog.setEnabled(false);
0137     // m_colorDialog.setStyleSheet("background: yellow; color: red; border: 15px solid #FF0000;");
0138     m_colorDialog.show();
0139 
0140     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("kvantum")));
0141     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("gtk2")));
0142     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("QtCurve")));
0143     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
0144     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("cde")));
0145     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("Cleanlooks")));
0146     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("IaOra"))); // https://store.kde.org/p/1183616
0147     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("motif")));
0148     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("Plastik"))); // From https://github.com/MartinF99/PlastikStyle (Qt5 + Qt6)
0149     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("Plastique")));
0150     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("Oxygen")));
0151     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("Breeze")));
0152     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("Windows")));
0153     // QApplication::setStyle(QStyleFactory::create(QStringLiteral("chameleon"))); // From package dde-qt5integration (deepin desktop environment)
0154 
0155     // QScopedPointer<QStyle> tempStyle(QStyleFactory::create(QStringLiteral("Fusion")));
0156     // qDebug() << tempStyle->standardPalette();
0157     // m_colorDialog.setPalette(tempStyle->standardPalette());
0158 
0159     /*
0160     m_colorDialog.setStyleSheet(
0161         QStringLiteral(" QDialog {"
0162                        "   background-color: green; "
0163                        "   border-radius: 30px; "
0164                        "   border: 1px solid black;"
0165                        "   border: 2px groove gray;"
0166                        " }"
0167 
0168                        " PerceptualColor--MultiSpinBox {"
0169                        "   background-color: red;"
0170                        "   border-radius: 3px; "
0171                        "   border: 10px solid black;"
0172                        "   border: 20px groove gray;"
0173                        "}"
0174 
0175                        " PerceptualColor--ColorDialog {"
0176                        "   background-color: yellow;"
0177                        "   border-radius: 30px; "
0178                        "   border: 1px solid black;"
0179                        "   border: 2px groove gray;"
0180                        "}"
0181 
0182                        " QFrameX {"
0183                        "   background-color: red;"
0184                        // "   border-radius: 30px; "
0185                        // "   border: 10px solid black;"
0186                        // "   border: 20px groove gray;"
0187                        "}"
0188 
0189                        " QPushButton {"
0190                        "   background-color: blue;"
0191                        // "   border-radius: 30px; "
0192                        // "   border: 10px solid black;"
0193                        // "   border: 20px groove gray;"
0194                        "}"
0195 
0196                        " PerceptualColor--ChromaHueDiagram {"
0197                        "   background-color: red;"
0198                        "   border-radius: 30px; "
0199                        // "   border: 10px solid black;"
0200                        "   border: 50px solid gray;"
0201                        "}"
0202 
0203                        " PerceptualColor--WheelColorPicker {"
0204                        "   background-color: red;"
0205                        "   border-radius: 30px; "
0206                        "   border: 1px solid black;"
0207                        "   border: 2px groove gray;"
0208                        "}"
0209 
0210                        " PerceptualColor--ColorPatchX {"
0211                        "   background-color: green;"
0212                        "   border-radius: 40px; "
0213                        "   border: 5px solid black;"
0214                        "   border: 10px groove gray;"
0215                        "}"
0216                        // " *:hover { background: red; }"
0217                        ));
0218     */
0219 
0220     /*
0221     QColorDialog *defaultColorDialog = new QColorDialog;
0222     defaultColorDialog->setOption(QColorDialog::ShowAlphaChannel);
0223     // For session management, according to https://doc.qt.io/qt-6/session.html
0224     //     “you must identify your top level widgets with
0225     //      unique application-wide object names”
0226     defaultColorDialog->setObjectName(QStringLiteral("Default Qt color dialog"));
0227     defaultColorDialog->show();
0228     */
0229 
0230     /*
0231     QScopedPointer<QTranslator> myTranslator;
0232     QTimer::singleShot(5000, // delay in milliseconds
0233                        QCoreApplication::instance(), // context object
0234                        [defaultColorDialog, &myTranslator]() {
0235                            // lambda to be executed
0236                            QLocale::setDefault(QLocale::German);
0237                            PerceptualColor::initializeTranslation( //
0238                                QCoreApplication::instance(), //
0239                                QLocale().uiLanguages());
0240                            myTranslator.reset(new QTranslator);
0241                            const bool hasBeenLoaded = myTranslator->load( //
0242                                QLocale(), //
0243                                QStringLiteral("qtbase"), //
0244                                QStringLiteral("_"), //
0245                                QStringLiteral("/usr/share/qt5/translations/"));
0246                            qDebug() << "Qt translation for" //
0247                                     << QLocale() //
0248                                     << "loaded?" //
0249                                     << hasBeenLoaded;
0250                            QCoreApplication::installTranslator( //
0251                                 myTranslator.data());
0252                            QEvent languageChangeEvent(QEvent::LanguageChange);
0253                            QCoreApplication::sendEvent(defaultColorDialog, //
0254                                                        &languageChangeEvent);
0255                        } //
0256     );
0257     QTimer::singleShot(10000, // delay in milliseconds
0258                        QCoreApplication::instance(), // context object
0259                        [defaultColorDialog, &myTranslator]() {
0260                            // lambda to be executed
0261                            QLocale::setDefault(QLocale::German);
0262                            PerceptualColor::initializeTranslation( //
0263                                QCoreApplication::instance(), //
0264                                QLocale().uiLanguages());
0265                            myTranslator.reset(new QTranslator);
0266                            const bool hasBeenLoaded = myTranslator->load( //
0267                                QLocale(), //
0268                                QStringLiteral("qtbase"), //
0269                                QStringLiteral("_"), //
0270                                QStringLiteral("/usr/share/qt5/translations/"));
0271                            qDebug() << "Qt translation for" //
0272                                     << QLocale() //
0273                                     << "loaded?" //
0274                                     << hasBeenLoaded;
0275                            QCoreApplication::installTranslator( //
0276                                 myTranslator.data());
0277                            QEvent languageChangeEvent(QEvent::LanguageChange);
0278                            QCoreApplication::sendEvent(defaultColorDialog, //
0279                                                        &languageChangeEvent);
0280                        } //
0281     );
0282     */
0283 
0284     auto &mySettings = PerceptualSettings::instance();
0285     mySettings.customColors.setValue(PerceptualSettings::ColorList({Qt::black, Qt::green}));
0286 
0287 #ifndef MSVC_DLL
0288     // Just for testing purpose: Miss-use the customColor property to
0289     // synchronize the current color of ColorDialog between various instances.
0290     QObject::connect(&m_colorDialog, //
0291                      &ColorDialog::currentColorChanged,
0292                      &mySettings,
0293                      [&](const QColor &color) {
0294                          mySettings.customColors.setValue(PerceptualSettings::ColorList({color}));
0295                      });
0296     QObject::connect(&mySettings.customColors, //
0297                      &SettingBase::valueChanged,
0298                      &m_colorDialog,
0299                      [&]() {
0300                          m_colorDialog.setCurrentColor( //
0301                              mySettings.customColors.value().value(0));
0302                      });
0303 #endif
0304 
0305     m_colorDialog.setCurrentColor(QColor(50, 127, 206));
0306 
0307     // Run
0308     return app.exec();
0309 }
0310 
0311 #include "testapp.moc"