1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the qtconfig application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "colorbutton.h"
31
#include <qapplication.h>
33
#include <qcolordialog.h>
35
#include <q3dragobject.h>
37
#include <qstyleoption.h>
39
ColorButton::ColorButton(QWidget *parent)
40
: QAbstractButton(parent), mousepressed(false)
44
connect(this, SIGNAL(clicked()), SLOT(changeColor()));
48
ColorButton::ColorButton(const QColor &c, QWidget *parent)
49
: QAbstractButton(parent)
53
connect(this, SIGNAL(clicked()), SLOT(changeColor()));
57
void ColorButton::setColor(const QColor &c)
64
void ColorButton::changeColor()
66
QColor c = QColorDialog::getColor(col, qApp->activeWindow());
70
emit colorChanged(color());
75
QSize ColorButton::sizeHint() const
81
QSize ColorButton::minimumSizeHint() const
87
void ColorButton::drawButton(QPainter *p)
89
QStyleOptionButton buttonOptions;
90
buttonOptions.init(this);
91
buttonOptions.features = QStyleOptionButton::None;
92
buttonOptions.rect = rect();
93
buttonOptions.palette = palette();
94
buttonOptions.state = (isDown() ? QStyle::State_Sunken : QStyle::State_Raised);
95
style()->drawPrimitive(QStyle::PE_PanelButtonBevel, &buttonOptions, p, this);
101
QStyleOptionFocusRect frectOptions;
102
frectOptions.init(this);
103
frectOptions.rect = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &buttonOptions, this);
105
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &frectOptions, p, this);
109
void ColorButton::drawButtonLabel(QPainter *p)
111
QPalette::ColorGroup cg =
112
(isEnabled() ? (hasFocus() ? QPalette::Active : QPalette::Inactive) : QPalette::Disabled);
114
p->setPen(palette().color(cg, QPalette::ButtonText));
116
p->drawRect(width() / 4, height() / 4, width() / 2 - 1, height() / 2 - 1);
120
void ColorButton::dragEnterEvent(QDragEnterEvent *e)
122
if (! Q3ColorDrag::canDecode(e)) {
129
void ColorButton::dragMoveEvent(QDragMoveEvent *e)
131
if (! Q3ColorDrag::canDecode(e)) {
140
void ColorButton::dropEvent(QDropEvent *e)
142
if (! Q3ColorDrag::canDecode(e)) {
148
Q3ColorDrag::decode(e, c);
150
emit colorChanged(color());
154
void ColorButton::mousePressEvent(QMouseEvent *e)
158
QAbstractButton::mousePressEvent(e);
162
void ColorButton::mouseReleaseEvent(QMouseEvent *e)
164
mousepressed = false;
165
QAbstractButton::mouseReleaseEvent(e);
169
void ColorButton::mouseMoveEvent(QMouseEvent *e)
174
if ((presspos - e->pos()).manhattanLength() > QApplication::startDragDistance()) {
175
mousepressed = false;
178
Q3ColorDrag *cd = new Q3ColorDrag(color(), this);
183
void ColorButton::paintEvent(QPaintEvent *)