summaryrefslogtreecommitdiffstats
path: root/lib/widgets/propeditor/pcolorbutton.cpp
blob: 4b6ae5c4d39e32edb4814dfecbbf48b61fbeae7c (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
119
120
/***************************************************************************
 *   Copyright (C) 2004 by Alexander Dymo                                  *
 *   cloudtemple@mskat.net                                                 *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library 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 Library 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 "pcolorbutton.h"

#include <tqlayout.h>
#include <tqpainter.h>

#ifndef PURE_QT
#include <kcolorbutton.h>
#else
#include <tqpushbutton.h>
#include <tqpixmap.h>
#include <tqiconset.h>
#endif
#include <tqcolordialog.h>

namespace PropertyLib {

PColorButton::PColorButton(MultiProperty* property, TQWidget* parent, const char* name)
    :PropertyWidget(property, parent, name)
{
    TQHBoxLayout *l = new TQHBoxLayout(this, 0, 0);
#ifndef PURE_QT
    m_edit = new KColorButton(this);
    connect(m_edit, TQT_SIGNAL(changed(const TQColor&)), this, TQT_SLOT(updateProperty(const TQColor&)));
#else
    m_edit = new TQPushButton(this);
    connect(m_edit, TQT_SIGNAL(clicked()), this, TQT_SLOT(changeColor()));
#endif

    m_edit->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding);
    l->addWidget(m_edit);
}

TQVariant PColorButton::value() const
{
#ifndef PURE_QT
    return TQVariant(m_edit->color());
#else
    return TQVariant(m_color);
#endif
}

void PColorButton::drawViewer(TQPainter* p, const TQColorGroup& cg, const TQRect& r, const TQVariant& value)
{
/*    p->setBrush(value.toColor());
    p->setPen(TQt::NoPen);
    p->drawRect(r);*/
    p->setPen(TQt::NoPen);
    p->setBrush(cg.background());
    p->drawRect(r);

    p->setBrush(value.toColor());
    p->setPen(TQt::SolidLine);
    TQRect r2(r);
    r2.setTopLeft(r.topLeft() + TQPoint(5,5));
    r2.setBottomRight(r.bottomRight() - TQPoint(5,5));
    p->drawRect(r2);
}

void PColorButton::setValue(const TQVariant& value, bool emitChange)
{
#ifndef PURE_QT
    disconnect(m_edit, TQT_SIGNAL(changed(const TQColor&)), this, TQT_SLOT(updateProperty(const TQColor&)));
    m_edit->setColor(value.toColor());
    connect(m_edit, TQT_SIGNAL(changed(const TQColor&)), this, TQT_SLOT(updateProperty(const TQColor&)));
#else
    m_color = value.toColor();
    m_edit->setText(m_color.name());
    TQPixmap px;
    px.resize(14,14);
    px.fill(m_color);
    m_edit->setIconSet(px);
#endif
    if (emitChange)
        emit propertyChanged(m_property, value);

}

void PColorButton::updateProperty(const TQColor &// color
                                  )
{
    emit propertyChanged(m_property, value());
}

void PColorButton::changeColor()
{
#ifdef PURE_QT
   m_color = TQColorDialog::getColor(m_color,this);
   updateProperty(m_color);
   m_edit->setText(m_color.name());
   TQPixmap px;
   px.resize(14,14);
   px.fill(m_color);
   m_edit->setIconSet(px);

#endif
}

}
#ifndef PURE_QT
#include "pcolorbutton.moc"
#endif