summaryrefslogtreecommitdiffstats
path: root/lib/kofficeui/tktoolbarbutton.h
blob: 0e74b7e38fe1ae561cf6ba258f7a42477fb06382 (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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 * Kivio - Visual Modelling and Flowcharting
 * Copyright (C) 2000 theKompany.com
 *
 * 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.
 */
#ifndef TKTOOLBARBUTTON_H
#define TKTOOLBARBUTTON_H

#include <tkaction.h>

#include <tqpixmap.h>
#include <tqtoolbutton.h>
#include <kglobal.h>

class KToolBar;
class TDEInstance;
class TQPopupMenu;
class TQPainter;

class TKToolBarButton : public TQToolButton
{ Q_OBJECT
  
public:
  TKToolBarButton(const TQString& icon, const TQString& txt,
                     TQWidget* parent = 0, const char *name=0L,
                     TDEInstance *_instance = TDEGlobal::instance());

  TKToolBarButton(const TQPixmap&, const TQString&, TQWidget* parent=0, const char* name=0);
  ~TKToolBarButton();

  void setIconMode(TK::IconMode);
  void setRaised(bool);
  void setAutoRaised(bool);

  /**
   * Enable/Disable this button
   *
   * @param enable Defaults to true
   */
  void setEnabled(bool enable = true);

  /**
   * Set the pixmap directly for this button.  This pixmap should be
   * the active one... the dimmed and disabled pixmaps are constructed
   * based on this one.  However, don't use this function unless you
   * are positive that you don't want to use @ref setIcon.
   *
   * @param pixmap The active pixmap
   */
  virtual void setPixmap(const TQPixmap &pixmap);

  /**
   * Set the pixmap directly for this button.  This pixmap should be
   * the active one.. however, the disabled and default pixmaps will
   * only be constructed if @ref #generate is true.  In any event,
   * don't use this function unless you are positive that you don't
   * want to use @ref setIcon.
   *
   * @param pixmap   The active pixmap
   * @param generate If true, then the other pixmaps will be
   *                 automatically generated using configurable effects
   */
  virtual void setPixmap(const TQPixmap &pixmap, bool generate);

  /**
   * Force the button to use this pixmap as the default one rather
   * then generating it using effects.
   *
   * @param pixmap The pixmap to use as the default (normal) one
   */
  virtual void setDefaultPixmap(const TQPixmap& pixmap);

  /**
   * Force the button to use this pixmap when disabled one rather then
   * generating it using effects.
   *
   * @param pixmap The pixmap to use when disabled
   */
  virtual void setDisabledPixmap(const TQPixmap& pixmap);

  /**
   * Set the text for this button.  The text will be either used as a
   * tooltip (IconOnly) or will be along side the icon
   *
   * @param text The button (or tooltip) text
   */
  virtual void setText(const TQString &text);
  TQString text();

  /**
   * Set the icon for this button.  This icon should be the active
   * one... the dimmed and disabled icons are constructed based on
   * this one.  The actual pixmap will be loaded internally.  This
   * function is preferred over @ref setPixmap
   *
   * @param icon The name of the active pixmap
   */
  virtual void setIcon(const TQString &icon);

  /**
   * Force the button to use this icon as the default one rather
   * then generating it using effects.
   *
   * @param icon The icon to use as the default (normal) one
   */
  virtual void setDefaultIcon(const TQString& icon);

  /**
   * Force the button to use this icon when disabled one rather then
   * generating it using effects.
   *
   * @param icon The icon to use when disabled
   */
  virtual void setDisabledIcon(const TQString& icon);

  /**
   * Turn this button on or off
   *
   * @param flag true or false
   */
  void on(bool flag = true);

  /**
   * Toggle this button
   */
  void toggle();

  /**
   * Turn this button into a toggle button or disable the toggle
   * aspects of it.  This does not toggle the button itself.  Use @ref
   * toggle for that.
   *
   * @param toggle true or false
   */
  void setToggle(bool toggle = true);

  /**
   * Return a pointer to this button's popup menu (if it exists)
   */
  TQPopupMenu *popup();

  /**
   * Give this button a popup menu.  There will not be a delay when
   * you press the button.  Use @ref setDelayedPopup if you want that
   * behavior
   *
   * @param p The new popup menu
   */
  void setPopup (TQPopupMenu *p);

  /**
   * Gives this button a delayed popup menu.
   *
   * This function allows you to add a delayed popup menu to the button.
   * The popup menu is then only displayed when the button is pressed and
   * held down for about half a second.  You can also make the poup-menu
   * "sticky", i.e. visible until a selection is made or the mouse is
   * clikced elsewhere, by simply setting the second argument to true.
   * This "sticky" button feature allows you to make a selection without
   * having to press and hold down the mouse while making a selection.
   *
   * @param p the new popup menu
   * @param toggle if true, makes the button "sticky" (toggled)
   */
  void setDelayedPopup(TQPopupMenu *p, bool toggle = false);

  TQPixmap getActivePixmap() const;

  virtual TQSize sizeHint() const;
  virtual TQSize minimumSizeHint() const;

signals:
  void buttonClicked();
  void buttonPressed();
  void buttonReleased();
  void buttonToggled();

public slots:
  void modeChange();

protected:
  void paletteChange(const TQPalette &);
  void leaveEvent(TQEvent *e);
  void enterEvent(TQEvent *e);
  void drawButton(TQPainter *p);
  bool eventFilter (TQObject *o, TQEvent *e);
  void showMenu();

  void makeDefaultPixmap();
  void makeDisabledPixmap();
  bool arrowPressed( const TQPoint& pos ) {
	int x = pos.x();
	int y = pos.y();
	return (x > width() - 12 && x <= width() && y > 0 && y < height());
  }

private:
  TQPixmap defaultPixmap;
  TQPixmap activePixmap;
  TQPixmap disabledPixmap;
  virtual void setIcon(const TQPixmap &p) { TQButton::setIcon(p); }
  class TKToolBarButtonPrivate;
  TKToolBarButtonPrivate *d;


protected slots:
  void slotClicked();
  void slotPressed();
  void slotReleased();
  void slotToggled();
  void slotDelayTimeout();
};

#endif