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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/* This file is part of the KDE project
Copyright (C) 2002 Werner Trobin <trobin@kde.org>
This library 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 library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _kotoolbutton_h_
#define _kotoolbutton_h_
#include <tdetoolbarbutton.h>
#include <tqmap.h>
#include <tqpoint.h>
class TQPopupMenu;
class KoColorPanel : public TQWidget
{
Q_OBJECT
public:
KoColorPanel( TQWidget* parent = 0, const char* name = 0 );
virtual ~KoColorPanel();
virtual TQSize sizeHint() const;
virtual TQSize minimumSizeHint() const;
enum MenuStyle { Plain, CustomColors };
static TQPopupMenu* createColorPopup( MenuStyle style, const TQColor& defaultColor,
const TQObject* receiver, const char* slot,
TQWidget* parent, const char* name );
public slots:
void clear();
void insertColor( const TQColor& color );
void insertColor( const TQColor& color, const TQString& toolTip );
void insertDefaultColors();
signals:
void colorSelected( const TQColor& color );
protected:
virtual void mousePressEvent( TQMouseEvent* e );
virtual void mouseReleaseEvent( TQMouseEvent* e );
virtual void mouseMoveEvent( TQMouseEvent* e );
virtual void paintEvent( TQPaintEvent* e );
virtual void keyPressEvent( TQKeyEvent* e );
virtual void focusInEvent( TQFocusEvent* e );
virtual void dragEnterEvent( TQDragEnterEvent* e );
virtual void dropEvent( TQDropEvent* e );
private:
// The position of the 16x16 tiles in "tile steps"
struct Position {
Position() : x( -1 ), y( -1 ) {}
Position( short x_, short y_ ) : x( x_ ), y( y_ ) {}
short x;
short y;
};
friend bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
void finalizeInsertion( const Position& pos );
bool insertColor( const TQColor& color, bool checking );
bool insertColor( const TQColor& color, const TQString& toolTip, bool checking );
bool isAvailable( const TQColor& color );
Position mapToPosition( const TQPoint& point ) const;
TQColor mapToColor( const TQPoint& point ) const;
TQColor mapToColor( const Position& position ) const;
TQRect mapFromPosition( const Position& position ) const;
Position validPosition( const Position& position );
int lines() const;
void paintArea( const TQRect& rect, int& startRow, int& endRow, int& startCol, int& endCol ) const;
void updateFocusPosition( const Position& newPosition );
void paint( const Position& position );
void init();
Position m_nextPosition, m_focusPosition;
TQMap<Position, TQColor> m_colorMap;
TQPoint m_pressedPos;
bool m_defaultsAdded;
};
// Needed for the use of KoColorPanel::Position in TQMap
bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
// A tiny class needed to emit the correct signal when the default
// color item in the color-panel popup is activated. Additionally
// it's used to provide the color select dialog and manages the recent
// colors... hacky
class KoColorPopupProxy : public TQObject
{
Q_OBJECT
public:
KoColorPopupProxy( const TQColor& defaultColor, KoColorPanel* recentColors, TQObject* parent, const char* name );
virtual ~KoColorPopupProxy() {}
void setRecentColorPanel( KoColorPanel* recentColors );
public slots:
void slotDefaultColor();
void slotMoreColors();
signals:
void colorSelected( const TQColor& color );
private:
TQColor m_defaultColor;
KoColorPanel* m_recentColors;
};
// Parts of the code are from TDEToolBarButton
class KoToolButton : public TDEToolBarButton
{
Q_OBJECT
public:
/**
* Construct a button with an icon loaded by the button itself.
* This will trust the button to load the correct icon with the
* correct size.
*
* @param icon Name of icon to load (may be absolute or relative)
* @param id Id of this button
* @param parent This button's parent
* @param name This button's internal name
* @param txt This button's text (in a tooltip or otherwise)
*/
KoToolButton( const TQString& icon, int id, TQWidget* parent,
const char* name = 0L, const TQString& txt = TQString(),
TDEInstance* _instance = TDEGlobal::instance() );
/**
* Construct a button with an existing pixmap. It is not
* recommended that you use this as the internal icon loading code
* will almost always get it "right".
*
* @param icon Name of icon to load (may be absolute or relative)
* @param id Id of this button
* @param parent This button's parent
* @param name This button's internal name
* @param txt This button's text (in a tooltip or otherwise)
*/
KoToolButton( const TQPixmap& pixmap, int id, TQWidget* parent,
const char* name = 0L, const TQString& txt = TQString() );
virtual ~KoToolButton();
virtual TQSize sizeHint() const;
virtual TQSize minimumSizeHint() const;
virtual TQSize minimumSize() const;
public slots:
void colorSelected( const TQColor& color );
protected:
virtual void drawButton(TQPainter *p);
virtual bool eventFilter( TQObject* o, TQEvent* e );
private:
void init();
void buttonShift( int& dx, int& dy );
bool hitArrow( const TQPoint& pos );
TQPopupMenu* m_popup;
bool m_arrowPressed;
};
#endif // _kotoolbutton_h_
|