1/*
2This file is part of KDE
3
4 Copyright (C) 1998-2000 Waldo Bastian (bastian@kde.org)
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*/
23
24#include <iostream>
25
26#include <kapplication.h>
27#include <kcmdlineargs.h>
28#include <kaboutdata.h>
29#include <klocale.h>
30
31#include <kcolordialog.h>
32#include <kcolormimedata.h>
33#include <khelpmenu.h>
34
35#include <QtGui/QClipboard>
36
37static const char description[] =
38 I18N_NOOP("KDE Color Chooser");
39
40static const char version[] = "v1.0.1";
41
42
43int main(int argc, char *argv[])
44{
45 KAboutData aboutData("kcolorchooser", 0, ki18n("KColorChooser"),
46 version, ki18n(description), KAboutData::License_BSD,
47 ki18n("(c) 2000, Waldo Bastian"));
48 aboutData.addAuthor(ki18n("Waldo Bastian"),KLocalizedString(), "bastian@kde.org");
49 aboutData.setProductName("kdelibs/kdeui");
50 KCmdLineArgs::init( argc, argv, &aboutData );
51
52 KCmdLineOptions options;
53 options.add("print", ki18n("Print the selected color to stdout"));
54 options.add("color <color>", ki18n("Set initially selected color"));
55 KCmdLineArgs::addCmdLineOptions( options );
56
57 KApplication app;
58
59 KColorDialog dlg;
60
61 KHelpMenu *help = new KHelpMenu(&dlg, &aboutData);
62
63 QColor color = KColorMimeData::fromMimeData( QApplication::clipboard()->mimeData( QClipboard::Clipboard ));
64 if (!color.isValid()) {
65 color = Qt::blue; // Just a color
66 }
67 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
68 if (args->isSet("color")) {
69 QColor c = QColor(args->getOption("color"));
70 if (c.isValid())
71 color = c;
72 }
73 dlg.setButtons(KDialog::Help | KDialog::Close);
74 dlg.setButtonMenu(KDialog::Help, (QMenu *)(help->menu()));
75 dlg.setColor(color);
76
77 app.connect(&dlg, SIGNAL(finished()), SLOT(quit()));
78
79 dlg.show();
80 app.exec();
81
82 const QColor c = dlg.color();
83 if ( args->isSet("print") && c.isValid() ) {
84 std::cout << c.name().toUtf8().constData() << std::endl;
85 }
86 args->clear();
87}
88