KoTooluButton.h
1/* This file is part of the KDE project
2 Copyright (C) 2002 Werner Trobin <trobin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef _kotoolbutton_h_
21#define _kotoolbutton_h_
22
23#include <tdetoolbarbutton.h>
24#include <tqmap.h>
25#include <tqpoint.h>
26
27class TQPopupMenu;
28
29class KoColorPanel : public TQWidget
30{
31 TQ_OBJECT
32
33public:
34 KoColorPanel( TQWidget* parent = 0, const char* name = 0 );
35 virtual ~KoColorPanel();
36
37 virtual TQSize sizeHint() const;
38 virtual TQSize minimumSizeHint() const;
39
40 enum MenuStyle { Plain, CustomColors };
41 static TQPopupMenu* createColorPopup( MenuStyle style, const TQColor& defaultColor,
42 const TQObject* receiver, const char* slot,
43 TQWidget* parent, const char* name );
44
45public slots:
46 void clear();
47 void insertColor( const TQColor& color );
48 void insertColor( const TQColor& color, const TQString& toolTip );
49 void insertDefaultColors();
50
51signals:
52 void colorSelected( const TQColor& color );
53
54protected:
55 virtual void mousePressEvent( TQMouseEvent* e );
56 virtual void mouseReleaseEvent( TQMouseEvent* e );
57 virtual void mouseMoveEvent( TQMouseEvent* e );
58 virtual void paintEvent( TQPaintEvent* e );
59 virtual void keyPressEvent( TQKeyEvent* e );
60 virtual void focusInEvent( TQFocusEvent* e );
61 virtual void dragEnterEvent( TQDragEnterEvent* e );
62 virtual void dropEvent( TQDropEvent* e );
63
64private:
65 // The position of the 16x16 tiles in "tile steps"
66 struct Position {
67 Position() : x( -1 ), y( -1 ) {}
68 Position( short x_, short y_ ) : x( x_ ), y( y_ ) {}
69
70 short x;
71 short y;
72 };
73 friend bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
74
75 void finalizeInsertion( const Position& pos );
76 bool insertColor( const TQColor& color, bool checking );
77 bool insertColor( const TQColor& color, const TQString& toolTip, bool checking );
78 bool isAvailable( const TQColor& color );
79
80 Position mapToPosition( const TQPoint& point ) const;
81 TQColor mapToColor( const TQPoint& point ) const;
82 TQColor mapToColor( const Position& position ) const;
83 TQRect mapFromPosition( const Position& position ) const;
84 Position validPosition( const Position& position );
85
86 int lines() const;
87 void paintArea( const TQRect& rect, int& startRow, int& endRow, int& startCol, int& endCol ) const;
88 void updateFocusPosition( const Position& newPosition );
89 void paint( const Position& position );
90 void init();
91
92 Position m_nextPosition, m_focusPosition;
93 TQMap<Position, TQColor> m_colorMap;
94 TQPoint m_pressedPos;
95 bool m_defaultsAdded;
96};
97
98// Needed for the use of KoColorPanel::Position in TQMap
99bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
100
101
102// A tiny class needed to emit the correct signal when the default
103// color item in the color-panel popup is activated. Additionally
104// it's used to provide the color select dialog and manages the recent
105// colors... hacky
106class KoColorPopupProxy : public TQObject
107{
108 TQ_OBJECT
109
110public:
111 KoColorPopupProxy( const TQColor& defaultColor, KoColorPanel* recentColors, TQObject* parent, const char* name );
112 virtual ~KoColorPopupProxy() {}
113
114 void setRecentColorPanel( KoColorPanel* recentColors );
115
116public slots:
117 void slotDefaultColor();
118 void slotMoreColors();
119
120signals:
121 void colorSelected( const TQColor& color );
122
123private:
124 TQColor m_defaultColor;
125 KoColorPanel* m_recentColors;
126};
127
128
129// Parts of the code are from TDEToolBarButton
130class KoToolButton : public TDEToolBarButton
131{
132 TQ_OBJECT
133
134public:
146 KoToolButton( const TQString& icon, int id, TQWidget* parent,
147 const char* name = 0L, const TQString& txt = TQString(),
148 TDEInstance* _instance = TDEGlobal::instance() );
149
161 KoToolButton( const TQPixmap& pixmap, int id, TQWidget* parent,
162 const char* name = 0L, const TQString& txt = TQString() );
163
164 virtual ~KoToolButton();
165
166 virtual TQSize sizeHint() const;
167 virtual TQSize minimumSizeHint() const;
168 virtual TQSize minimumSize() const;
169
170public slots:
171 void colorSelected( const TQColor& color );
172
173protected:
174 virtual void drawButton(TQPainter *p);
175 virtual bool eventFilter( TQObject* o, TQEvent* e );
176
177private:
178 void init();
179 void buttonShift( int& dx, int& dy );
180 bool hitArrow( const TQPoint& pos );
181
182 TQPopupMenu* m_popup;
183 bool m_arrowPressed;
184};
185
186#endif // _kotoolbutton_h_
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)