1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2006-2009 Licq developers
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #include "colorbutton.h"
21 
22 #ifndef USE_KDE
23 #include <QColorDialog>
24 #endif
25 
26 using namespace LicqQtGui;
27 
ColorButton(QWidget * parent)28 ColorButton::ColorButton(QWidget* parent)
29   : COLORBUTTON_BASE(parent)
30 {
31 #ifndef USE_KDE
32   setFixedSize(40, 20);
33   connect(this, SIGNAL(clicked()), SLOT(selectColor()));
34 #endif
35 }
36 
colorName() const37 QString ColorButton::colorName() const
38 {
39   return color().name();
40 }
41 
42 #ifndef USE_KDE
color() const43 QColor ColorButton::color() const
44 {
45   return palette().color(backgroundRole());
46 }
47 
selectColor()48 void ColorButton::selectColor()
49 {
50   QColor color = QColorDialog::getColor(palette().color(backgroundRole()), this);
51   if (color.isValid())
52     setColor(color);
53 }
54 
setColor(const QColor & color)55 void ColorButton::setColor(const QColor& color)
56 {
57   QPalette pal(palette());
58   pal.setColor(backgroundRole(), color);
59   setPalette(pal);
60   emit changed(color);
61 }
62 #endif
63