lib

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#include <koffice_export.h>
27
28class TQPopupMenu;
29
30class KOFFICEUI_EXPORT KoColorPanel : public TQWidget
31{
32 TQ_OBJECT
33
34public:
35 KoColorPanel( TQWidget* parent = 0, const char* name = 0 );
36 virtual ~KoColorPanel();
37
38 virtual TQSize sizeHint() const;
39 virtual TQSize minimumSizeHint() const;
40
41 enum MenuStyle { Plain, CustomColors };
42 static TQPopupMenu* createColorPopup( MenuStyle style, const TQColor& defaultColor,
43 const TQObject* receiver, const char* slot,
44 TQWidget* parent, const char* name );
45
46public slots:
47 void clear();
48 void insertColor( const TQColor& color );
49 void insertColor( const TQColor& color, const TQString& toolTip );
50 void insertDefaultColors();
51
52signals:
53 void colorSelected( const TQColor& color );
54
55protected:
56 virtual void mousePressEvent( TQMouseEvent* e );
57 virtual void mouseReleaseEvent( TQMouseEvent* e );
58 virtual void mouseMoveEvent( TQMouseEvent* e );
59 virtual void paintEvent( TQPaintEvent* e );
60 virtual void keyPressEvent( TQKeyEvent* e );
61 virtual void focusInEvent( TQFocusEvent* e );
62 virtual void dragEnterEvent( TQDragEnterEvent* e );
63 virtual void dropEvent( TQDropEvent* e );
64
65private:
66 // The position of the 16x16 tiles in "tile steps"
67 struct Position {
68 Position() : x( -1 ), y( -1 ) {}
69 Position( short x_, short y_ ) : x( x_ ), y( y_ ) {}
70
71 short x;
72 short y;
73 };
74 friend bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
75
76 void finalizeInsertion( const Position& pos );
77 bool insertColor( const TQColor& color, bool checking );
78 bool insertColor( const TQColor& color, const TQString& toolTip, bool checking );
79 bool isAvailable( const TQColor& color );
80
81 Position mapToPosition( const TQPoint& point ) const;
82 TQColor mapToColor( const TQPoint& point ) const;
83 TQColor mapToColor( const Position& position ) const;
84 TQRect mapFromPosition( const Position& position ) const;
85 Position validPosition( const Position& position );
86
87 int lines() const;
88 void paintArea( const TQRect& rect, int& startRow, int& endRow, int& startCol, int& endCol ) const;
89 void updateFocusPosition( const Position& newPosition );
90 void paint( const Position& position );
91 void init();
92
93 Position m_nextPosition, m_focusPosition;
94 TQMap<Position, TQColor> m_colorMap;
95 TQPoint m_pressedPos;
96 bool m_defaultsAdded;
97};
98
99// Needed for the use of KoColorPanel::Position in TQMap
100bool operator<( const KoColorPanel::Position& lhs, const KoColorPanel::Position& rhs );
101
102
103// A tiny class needed to emit the correct signal when the default
104// color item in the color-panel popup is activated. Additionally
105// it's used to provide the color select dialog and manages the recent
106// colors... hacky
107class KOFFICEUI_EXPORT KoColorPopupProxy : public TQObject
108{
109 TQ_OBJECT
110
111public:
112 KoColorPopupProxy( const TQColor& defaultColor, KoColorPanel* recentColors, TQObject* parent, const char* name );
113 virtual ~KoColorPopupProxy() {}
114
115 void setRecentColorPanel( KoColorPanel* recentColors );
116
117public slots:
118 void slotDefaultColor();
119 void slotMoreColors();
120
121signals:
122 void colorSelected( const TQColor& color );
123
124private:
125 TQColor m_defaultColor;
126 KoColorPanel* m_recentColors;
127};
128
129
130// Parts of the code are from TDEToolBarButton
131class KOFFICEUI_EXPORT KoToolButton : public TDEToolBarButton
132{
133 TQ_OBJECT
134
135public:
147 KoToolButton( const TQString& icon, int id, TQWidget* parent,
148 const char* name = 0L, const TQString& txt = TQString(),
149 TDEInstance* _instance = TDEGlobal::instance() );
150
162 KoToolButton( const TQPixmap& pixmap, int id, TQWidget* parent,
163 const char* name = 0L, const TQString& txt = TQString() );
164
165 virtual ~KoToolButton();
166
167 virtual TQSize sizeHint() const;
168 virtual TQSize minimumSizeHint() const;
169 virtual TQSize minimumSize() const;
170
171public slots:
172 void colorSelected( const TQColor& color );
173
174protected:
175 virtual void drawButton(TQPainter *p);
176 virtual bool eventFilter( TQObject* o, TQEvent* e );
177
178private:
179 void init();
180 void buttonShift( int& dx, int& dy );
181 bool hitArrow( const TQPoint& pos );
182
183 TQPopupMenu* m_popup;
184 bool m_arrowPressed;
185};
186
187#endif // _kotoolbutton_h_
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)