summaryrefslogtreecommitdiffstats
path: root/chalk/ui/kis_color_cup.cpp
blob: ae0ddfacba0dc68491aa061946128126ca0e9f58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * This file is part of Chalk
 *
 * Copyright (c) 1999 Matthias Elter (me@kde.org)
 * Copyright (c) 2001-2002 Igor Jansen (rm@kde.org)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <tqpushbutton.h>
#include <tqapplication.h>
#include <tqclipboard.h>
#include <tqcolor.h>
#include <tqdrawutil.h>
#include <tqhbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpainter.h>
#include <tqspinbox.h>
#include <tqstyle.h>
#include <tqtooltip.h>
#include <tqwidget.h>
#include <tqframe.h>

#include <kcolordialog.h>
#include <tdelocale.h>
#include <knuminput.h>
#include <koFrameButton.h>

#include <kis_canvas_subject.h>
#include <kis_color.h>
#include <kis_color_cup.h>

KisColorPopup::KisColorPopup(TQColor c, TQWidget * parent, const char * name)
    : TQFrame(parent, name, WType_Popup | WStyle_Customize | WStyle_NoBorder)
{
    m_color = c;
    setMargin(4);
    setFocusPolicy(TQ_StrongFocus);
    TQHBoxLayout * l  = new TQHBoxLayout(this);
    l->add(m_khsSelector = new KHSSelector(this));
    m_khsSelector->setMinimumSize(140, 7);
    l->add(m_valueSelector = new KValueSelector(this));
    m_valueSelector->setMinimumSize(26, 70);
    m_khsSelector->show();
    m_valueSelector->show();

}

KisColorCup::KisColorCup(TQWidget * parent, const char * name)
    : TQPushButton(parent, name)
{
    m_color = TQt::black;
    m_popup = new KisColorPopup(m_color, this, "colorpopup");
    connect(this, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotClicked()));
    connect(m_popup, TQT_SIGNAL(changed( const TQColor &)), this, TQT_SLOT(setColor(const TQColor &)));
}

void KisColorCup::setColor(const TQColor & c)
{
    m_color = c;
    emit changed(c);
}

void KisColorCup::slotClicked()
{    
//    m_popup->move(this->mapToGlobal( this->rect().topRight() ) );
//    m_popup->show();
    emit changed(m_color);
}

TQSize KisColorCup::sizeHint() const
{
    return style().tqsizeFromContents(TQStyle::CT_PushButton, this, TQSize(24, 24)).
            expandedTo(TQApplication::globalStrut());
}

void KisColorCup::drawButtonLabel( TQPainter *painter )
{
    int x, y, w, h;
    TQRect r = style().subRect( TQStyle::SR_PushButtonContents, this );
    r.rect(&x, &y, &w, &h);

    int margin = 2; //style().pixelMetric( TQStyle::PM_ButtonMargin, this );
    x += margin;
    y += margin;
    w -= 2*margin;
    h -= 2*margin;

    if (isOn() || isDown()) {
        x += style().pixelMetric( TQStyle::PM_ButtonShiftHorizontal, this );
        y += style().pixelMetric( TQStyle::PM_ButtonShiftVertical, this );
    }

    qDrawShadePanel( painter, x, y, w, h, colorGroup(), true, 1, NULL);
    if ( m_color.isValid() )
        painter->fillRect( x+1, y+1, w-2, h-2, m_color );

    if ( hasFocus() ) {
        TQRect focusRect = style().subRect( TQStyle::SR_PushButtonFocusRect, this );
        style().tqdrawPrimitive( TQStyle::PE_FocusRect, painter, focusRect, colorGroup() );
    }

}

#include "kis_color_cup.moc"