chalk

kis_color_cup.cpp
1/*
2 * This file is part of Chalk
3 *
4 * Copyright (c) 1999 Matthias Elter (me@kde.org)
5 * Copyright (c) 2001-2002 Igor Jansen (rm@kde.org)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20*/
21
22#include <tqpushbutton.h>
23#include <tqapplication.h>
24#include <tqclipboard.h>
25#include <tqcolor.h>
26#include <tqdrawutil.h>
27#include <tqhbox.h>
28#include <tqlabel.h>
29#include <tqlayout.h>
30#include <tqpainter.h>
31#include <tqspinbox.h>
32#include <tqstyle.h>
33#include <tqtooltip.h>
34#include <tqwidget.h>
35#include <tqframe.h>
36
37#include <kcolordialog.h>
38#include <tdelocale.h>
39#include <knuminput.h>
40#include <koFrameButton.h>
41
42#include <kis_canvas_subject.h>
43#include <kis_color.h>
44#include <kis_color_cup.h>
45
46KisColorPopup::KisColorPopup(TQColor c, TQWidget * parent, const char * name)
47 : TQFrame(parent, name, WType_Popup | WStyle_Customize | WStyle_NoBorder)
48{
49 m_color = c;
50 setMargin(4);
51 setFocusPolicy(TQWidget::StrongFocus);
52 TQHBoxLayout * l = new TQHBoxLayout(this);
53 l->add(m_khsSelector = new KHSSelector(this));
54 m_khsSelector->setMinimumSize(140, 7);
55 l->add(m_valueSelector = new KValueSelector(this));
56 m_valueSelector->setMinimumSize(26, 70);
57 m_khsSelector->show();
58 m_valueSelector->show();
59
60}
61
62KisColorCup::KisColorCup(TQWidget * parent, const char * name)
63 : TQPushButton(parent, name)
64{
65 m_color = TQt::black;
66 m_popup = new KisColorPopup(m_color, this, "colorpopup");
67 connect(this, TQ_SIGNAL(clicked()), this, TQ_SLOT(slotClicked()));
68 connect(m_popup, TQ_SIGNAL(changed( const TQColor &)), this, TQ_SLOT(setColor(const TQColor &)));
69}
70
71void KisColorCup::setColor(const TQColor & c)
72{
73 m_color = c;
74 emit changed(c);
75}
76
77void KisColorCup::slotClicked()
78{
79// m_popup->move(this->mapToGlobal( this->rect().topRight() ) );
80// m_popup->show();
81 emit changed(m_color);
82}
83
84TQSize KisColorCup::sizeHint() const
85{
86 return style().sizeFromContents(TQStyle::CT_PushButton, this, TQSize(24, 24)).
87 expandedTo(TQApplication::globalStrut());
88}
89
90void KisColorCup::drawButtonLabel( TQPainter *painter )
91{
92 int x, y, w, h;
93 TQRect r = style().subRect( TQStyle::SR_PushButtonContents, this );
94 r.rect(&x, &y, &w, &h);
95
96 int margin = 2; //style().pixelMetric( TQStyle::PM_ButtonMargin, this );
97 x += margin;
98 y += margin;
99 w -= 2*margin;
100 h -= 2*margin;
101
102 if (isOn() || isDown()) {
103 x += style().pixelMetric( TQStyle::PM_ButtonShiftHorizontal, this );
104 y += style().pixelMetric( TQStyle::PM_ButtonShiftVertical, this );
105 }
106
107 qDrawShadePanel( painter, x, y, w, h, colorGroup(), true, 1, NULL);
108 if ( m_color.isValid() )
109 painter->fillRect( x+1, y+1, w-2, h-2, m_color );
110
111 if ( hasFocus() ) {
112 TQRect focusRect = style().subRect( TQStyle::SR_PushButtonFocusRect, this );
113 style().drawPrimitive( TQStyle::PE_FocusRect, painter, focusRect, colorGroup() );
114 }
115
116}
117
118#include "kis_color_cup.moc"