Warning, file /graphics/kcolorchooser/kcolorchooser.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002 This file is part of KDE 
0003 
0004   Copyright (C) 1998-2000 Waldo Bastian (bastian@kde.org)
0005 
0006 Permission is hereby granted, free of charge, to any person obtaining a copy
0007 of this software and associated documentation files (the "Software"), to deal
0008 in the Software without restriction, including without limitation the rights
0009 to use, copy, modify, merge, publish, distribute, and/or sell
0010 copies of the Software, and to permit persons to whom the Software is
0011 furnished to do so, subject to the following conditions:
0012 
0013 The above copyright notice and this permission notice shall be included in
0014 all copies or substantial portions of the Software.
0015 
0016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
0019 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
0020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0022 */
0023 
0024 #include "kcolorchooser_version.h"
0025 
0026 #include <KAboutData>
0027 #include <KLocalizedString>
0028 #include <KHelpMenu>
0029 
0030 #include <QApplication>
0031 #include <QClipboard>
0032 #include <QColorDialog>
0033 #include <QCommandLineParser>
0034 #include <QDialogButtonBox>
0035 #include <QMenu>
0036 #include <QMimeData>
0037 #include <QPushButton>
0038 
0039 #include <iostream>
0040 
0041 int main(int argc, char *argv[])
0042 {
0043     QApplication app(argc, argv);
0044 
0045     KLocalizedString::setApplicationDomain("kcolorchooser");
0046 
0047     KAboutData aboutData(QStringLiteral("kcolorchooser"),
0048                          i18n("KColorChooser"),
0049                          QStringLiteral(KCOLORCHOOSER_VERSION_STRING),
0050                          i18n("KDE Color Chooser"),
0051                          KAboutLicense::BSDL,
0052                          i18n("(c) 2000, Waldo Bastian"));
0053     aboutData.addAuthor(i18n("Waldo Bastian"), QString(), QStringLiteral("bastian@kde.org"));
0054     aboutData.addAuthor(i18n("Hugo Parente Lima"),i18n("KF5 port"), QStringLiteral("hugo.pl@gmail.com"));
0055     aboutData.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
0056     KAboutData::setApplicationData(aboutData);
0057 
0058     QCommandLineParser parser;
0059     parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
0060     aboutData.setupCommandLine(&parser);
0061     QCommandLineOption print(QStringLiteral("print"), i18n("Print the selected color to stdout."));
0062     parser.addOption(print);
0063     QCommandLineOption color(QStringLiteral("color"), i18n("Set initially selected color."), QStringLiteral("color"));
0064     parser.addOption(color);
0065     parser.process(app);
0066     aboutData.processCommandLine(&parser);
0067 
0068     QColorDialog dlg;
0069     dlg.setOption(QColorDialog::DontUseNativeDialog);
0070     QDialogButtonBox *box = dlg.findChild<QDialogButtonBox*>();
0071     if (!box) {
0072         return 1;
0073     }
0074 
0075     box->addButton(QDialogButtonBox::Help);
0076 
0077     KHelpMenu *help = new KHelpMenu(&dlg, aboutData, false);
0078     help->menu();
0079     delete help->action(KHelpMenu::menuHelpContents);
0080     QObject::connect(box, &QDialogButtonBox::helpRequested, [=] () {
0081         QPushButton *button = box->button(QDialogButtonBox::Help);
0082         QPoint pos = button->pos();
0083         pos.ry() += button->height();
0084         pos = box->mapToGlobal(pos);
0085         help->menu()->exec(pos);
0086     });
0087 
0088     if (parser.isSet(color)) {
0089         dlg.setCurrentColor(QColor(parser.value(color)));
0090     } else {
0091         const QMimeData *mimeData = QApplication::clipboard()->mimeData(QClipboard::Clipboard);
0092         if (mimeData) {
0093             QColor clipboardColor = mimeData->colorData().value<QColor>();
0094             if (clipboardColor.isValid()) {
0095                 dlg.setCurrentColor(clipboardColor);
0096             }
0097         }
0098     }
0099 
0100     dlg.show();
0101     app.exec();
0102 
0103     const  QColor c = dlg.currentColor();
0104     if (parser.isSet(print) && c.isValid()) {
0105         std::cout << c.name().toUtf8().constData() << std::endl;
0106     }
0107 }