-rw-r--r-- | microkde/kdeui/ktoolbar.h | 1107 |
1 files changed, 1107 insertions, 0 deletions
diff --git a/microkde/kdeui/ktoolbar.h b/microkde/kdeui/ktoolbar.h new file mode 100644 index 0000000..2c061b5 --- a/dev/null +++ b/microkde/kdeui/ktoolbar.h | |||
@@ -0,0 +1,1107 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 2000 Reginald Stadlbauer (reggie@kde.org) | ||
3 | (C) 1997, 1998 Stephan Kulow (coolo@kde.org) | ||
4 | (C) 1997, 1998 Sven Radej (radej@kde.org) | ||
5 | (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) | ||
6 | (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org) | ||
7 | (C) 1999, 2000 Kurt Granroth (granroth@kde.org) | ||
8 | |||
9 | This library is free software; you can redistribute it and/or | ||
10 | modify it under the terms of the GNU Library General Public | ||
11 | License version 2 as published by the Free Software Foundation. | ||
12 | |||
13 | This library is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | Library General Public License for more details. | ||
17 | |||
18 | You should have received a copy of the GNU Library General Public License | ||
19 | along with this library; see the file COPYING.LIB. If not, write to | ||
20 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
21 | Boston, MA 02111-1307, USA. | ||
22 | */ | ||
23 | |||
24 | #ifndef KTOOLBAR_H | ||
25 | #define KTOOLBAR_H | ||
26 | |||
27 | #ifndef DESKTOP_VERSION | ||
28 | #define private public | ||
29 | #include <qtoolbar.h> | ||
30 | #undef private | ||
31 | #include <qpe/qpetoolbar.h> | ||
32 | #else | ||
33 | #include <qtoolbar.h> | ||
34 | #endif | ||
35 | |||
36 | |||
37 | #include <qmainwindow.h> | ||
38 | #include <qcombobox.h> | ||
39 | #include <qmap.h> | ||
40 | #include <qptrlist.h> | ||
41 | #include <kglobal.h> | ||
42 | #include <qguardedptr.h> | ||
43 | #include <qframe.h> | ||
44 | #include <qiconset.h> | ||
45 | |||
46 | class QDomElement; | ||
47 | class QSize; | ||
48 | class QPixmap; | ||
49 | class QPopupMenu; | ||
50 | class QStringList; | ||
51 | class QDomDocument; | ||
52 | class QTimer; | ||
53 | |||
54 | class KLineEdit; | ||
55 | class KToolBar; | ||
56 | class KToolBarButton; | ||
57 | class KToolBoxManager; | ||
58 | //US class KAnimWidget; | ||
59 | //US class KPopupMenu; | ||
60 | //US class KInstance; | ||
61 | class KComboBox; | ||
62 | class KXMLGUIClient; | ||
63 | |||
64 | class KToolBarPrivate; | ||
65 | |||
66 | class KToolBarSeparator : public QFrame | ||
67 | { | ||
68 | Q_OBJECT | ||
69 | public: | ||
70 | KToolBarSeparator( Orientation, bool l, QToolBar *parent, const char* name=0 ); | ||
71 | |||
72 | QSize sizeHint() const; | ||
73 | Orientation orientation() const { return orient; } | ||
74 | QSizePolicy sizePolicy() const; | ||
75 | bool showLine() const { return line; } | ||
76 | public slots: | ||
77 | void setOrientation( Orientation ); | ||
78 | protected: | ||
79 | void styleChange( QStyle& ); | ||
80 | private: | ||
81 | Orientation orient; | ||
82 | bool line; | ||
83 | }; | ||
84 | |||
85 | |||
86 | /** | ||
87 | * A KDE-style toolbar. | ||
88 | * | ||
89 | * KToolBar can be dragged around in and between different docks. | ||
90 | * | ||
91 | * A KToolBar can contain all sorts of widgets. | ||
92 | * | ||
93 | * KToolBar can be used as a standalone widget, but @ref KMainWindow | ||
94 | * provides easy factories and management of one or more toolbars. | ||
95 | * Once you have a KToolBar object, you can insert items into it with the | ||
96 | * insert... methods, or remove them with the @ref removeItem() method. This | ||
97 | * can be done at any time; the toolbar will be automatically updated. | ||
98 | * There are also many methods to set per-child properties like alignment | ||
99 | * and toggle behaviour. | ||
100 | * | ||
101 | * KToolBar uses a global config group to load toolbar settings on | ||
102 | * construction. It will reread this config group on a | ||
103 | * @ref KApplication::appearanceChanged() signal. | ||
104 | * | ||
105 | * @short Floatable toolbar with auto resize. | ||
106 | * @version $Id$ | ||
107 | * @author Reginald Stadlbauer <reggie@kde.org>, Stephan Kulow <coolo@kde.org>, Sven Radej <radej@kde.org>. | ||
108 | */ | ||
109 | |||
110 | // strange things are happening ... so I have to use strange define methods ... | ||
111 | // porting KToolBar back to Qt2 really needs some strange hacks | ||
112 | |||
113 | #ifndef DESKTOP_VERSION | ||
114 | #define QToolBar QPEToolBar | ||
115 | #endif | ||
116 | |||
117 | class KToolBar : public QToolBar | ||
118 | { | ||
119 | Q_OBJECT | ||
120 | |||
121 | |||
122 | Q_ENUMS( IconText BarPosition ) | ||
123 | |||
124 | Q_PROPERTY( IconText iconText READ iconText WRITE setIconText ) | ||
125 | Q_PROPERTY( BarPosition barPos READ barPos WRITE setBarPos ) | ||
126 | Q_PROPERTY( bool fullSize READ fullSize WRITE setFullSize ) | ||
127 | Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize ) | ||
128 | Q_PROPERTY( QString text READ text WRITE setText ) | ||
129 | #ifndef DESKTOP_VERSION | ||
130 | #undef QToolBar | ||
131 | #endif | ||
132 | public: | ||
133 | enum IconText{IconOnly = 0, IconTextRight, TextOnly, IconTextBottom}; | ||
134 | /** | ||
135 | * The state of the status bar. | ||
136 | * @deprecated | ||
137 | **/ | ||
138 | enum BarStatus{Toggle, Show, Hide}; | ||
139 | /** | ||
140 | * Possible bar positions. | ||
141 | **/ | ||
142 | enum BarPosition{ Unmanaged, Floating, Top, Bottom, Right, Left, Flat}; | ||
143 | |||
144 | /** | ||
145 | * Constructor. | ||
146 | * This constructor is used by the XML-GUI. If you use it, you need | ||
147 | * to call QMainWindow::addToolBar to specify the position of the toolbar. | ||
148 | * So it's simpler to use the other constructor. | ||
149 | * | ||
150 | * The toolbar will read in various global config settings for | ||
151 | * things like icon size and text position, etc. However, some of | ||
152 | * the settings will be honored only if @ref #_honor_mode is set to | ||
153 | * true. All other toolbars will be IconOnly and use Medium icons. | ||
154 | * | ||
155 | * @param parent The standard toolbar parent (usually a | ||
156 | * @ref KMainWindow) | ||
157 | * @param name The standard internal name | ||
158 | * @param honor_style If true, then global settings for IconSize and IconText will be honored | ||
159 | * @param readConfig whether to apply the configuration (global and application-specific) | ||
160 | */ | ||
161 | KToolBar( QWidget *parent, const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE ); | ||
162 | |||
163 | /** | ||
164 | * Constructor for non-XML-GUI applications. | ||
165 | * | ||
166 | * The toolbar will read in various global config settings for | ||
167 | * things like icon size and text position, etc. However, some of | ||
168 | * the settings will be honored only if @ref #_honor_mode is set to | ||
169 | * true. All other toolbars will be IconOnly and use Medium icons. | ||
170 | * | ||
171 | * @param parentWindow The window that should be the parent of this toolbar | ||
172 | * @param dock The position of the toolbar. Usually QMainWindow::Top. | ||
173 | * @param newLine If true, start a new line in the dock for this toolbar. | ||
174 | * @param name The standard internal name | ||
175 | * @param honor_style If true, then global settings for IconSize and IconText will be honored | ||
176 | * @param readConfig whether to apply the configuration (global and application-specific) | ||
177 | */ | ||
178 | KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock /*= QMainWindow::Top*/, bool newLine = false, | ||
179 | const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE ); | ||
180 | |||
181 | /** | ||
182 | * Constructor for non-XML-GUI applications. | ||
183 | * | ||
184 | * The toolbar will read in various global config settings for | ||
185 | * things like icon size and text position, etc. However, some of | ||
186 | * the settings will be honored only if @ref #_honor_mode is set to | ||
187 | * true. All other toolbars will be IconOnly and use Medium icons. | ||
188 | * | ||
189 | * @param parentWindow The window that should be the parent of this toolbar | ||
190 | * @param dock Another widget than the mainwindow to dock toolbar to. | ||
191 | * @param newLine If true, start a new line in the dock for this toolbar. | ||
192 | * @param name The standard internal name | ||
193 | * @param honor_style If true, then global settings for IconSize and IconText will be honored | ||
194 | * @param readConfig whether to apply the configuration (global and application-specific) | ||
195 | */ | ||
196 | KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine = false, | ||
197 | const char *name = 0, bool honor_style = FALSE, bool readConfig = TRUE ); | ||
198 | |||
199 | virtual ~KToolBar(); | ||
200 | |||
201 | /** | ||
202 | * Insert a button (a @ref KToolBarButton) with a pixmap. The | ||
203 | * pixmap is loaded by the button itself based on the global icon | ||
204 | * settings. | ||
205 | * | ||
206 | * You should connect to one or more signals in KToolBar: | ||
207 | * @ref clicked() , @ref pressed() , @ref released() , or | ||
208 | * @ref highlighted() and if the button is a toggle button | ||
209 | * (@ref setToggle() ) @ref toggled() . Those signals have @p id | ||
210 | * of a button that caused the signal. If you want to bind a popup | ||
211 | * to button, see @ref setButton(). | ||
212 | * | ||
213 | * @param icon The name of the icon to use as the active pixmap | ||
214 | * @param id The id of this button | ||
215 | * @param enabled Enable or disable the button at startup | ||
216 | * @param text The tooltip or toolbar text (depending on state) | ||
217 | * @param index The position of the button. (-1 = at end). | ||
218 | * | ||
219 | * @return The item index. | ||
220 | */ | ||
221 | int insertButton(const QString& icon, int id, bool enabled = true, | ||
222 | const QString& text = QString::null, int index=-1/*US , | ||
223 | KInstance *_instance = KGlobal::instance()*/); | ||
224 | |||
225 | /** | ||
226 | * This is the same as above, but with specified signals and | ||
227 | * slots to which this button will be connected. | ||
228 | * | ||
229 | * You can add more signals with @ref addConnection(). | ||
230 | * | ||
231 | * @param icon The name of the icon to use as the active pixmap | ||
232 | * @param id The id of this button | ||
233 | * @param signal The signal to connect to | ||
234 | * @param receiver The slot's parent | ||
235 | * @param enabled Enable or disable the button at startup | ||
236 | * @param text The tooltip or toolbar text (depending on state) | ||
237 | * @param index The position of the button. (-1 = at end). | ||
238 | * | ||
239 | * @return The item index. | ||
240 | */ | ||
241 | int insertButton(const QString& icon, int id, const char *signal, | ||
242 | const QObject *receiver, const char *slot, | ||
243 | bool enabled = true, const QString& text = QString::null, | ||
244 | int index=-1/*US, KInstance *_instance = KGlobal::instance()*/ ); | ||
245 | |||
246 | /** | ||
247 | * Inserts a button (a @ref KToolBarButton) with the specified | ||
248 | * pixmap. This pixmap will be used as the "active" one and the | ||
249 | * disabled and default ones will be autogenerated. | ||
250 | * | ||
251 | * It is recommended that you use the insertButton function that | ||
252 | * allows you to specify the icon name rather then the pixmap | ||
253 | * itself. Specifying the icon name is much more flexible. | ||
254 | * | ||
255 | * You should connect to one or more signals in KToolBar: | ||
256 | * @ref clicked() , @ref pressed() , @ref released() , or | ||
257 | * @ref highlighted() and if the button is a toggle button | ||
258 | * (@ref setToggle() ) @ref toggled() . Those signals have @p id | ||
259 | * of a button that caused the signal. If you want to bind a popup | ||
260 | * to button, see @ref setButton(). | ||
261 | * | ||
262 | * @param pixmap The active pixmap | ||
263 | * @param id The id of this button | ||
264 | * @param enabled Enable or disable the button at startup | ||
265 | * @param text The tooltip or toolbar text (depending on state) | ||
266 | * @param index The position of the button. (-1 = at end). | ||
267 | * | ||
268 | * @return The item index. | ||
269 | */ | ||
270 | int insertButton(const QPixmap& pixmap, int id, bool enabled = true, | ||
271 | const QString& text = QString::null, int index=-1 ); | ||
272 | |||
273 | /** | ||
274 | * This is the same as above, but with specified signals and | ||
275 | * slots to which this button will be connected. | ||
276 | * | ||
277 | * You can add more signals with @ref addConnection(). | ||
278 | * | ||
279 | * @param icon The name of the icon to use as the active pixmap | ||
280 | * @param id The id of this button | ||
281 | * @param signal The signal to connect to | ||
282 | * @param receiver The slot's parent | ||
283 | * @param enabled Enable or disable the button at startup | ||
284 | * @param text The tooltip or toolbar text (depending on state) | ||
285 | * @param index The position of the button. (-1 = at end). | ||
286 | * | ||
287 | * @return The item index. | ||
288 | */ | ||
289 | int insertButton(const QPixmap& pixmap, int id, const char *signal, | ||
290 | const QObject *receiver, const char *slot, | ||
291 | bool enabled = true, const QString& text = QString::null, | ||
292 | int index=-1 ); | ||
293 | |||
294 | /** | ||
295 | * Inserts a button with popupmenu. | ||
296 | * | ||
297 | * Button will have small | ||
298 | * triangle. You have to connect to popup's signals. The | ||
299 | * signals @ref KButton::pressed(), @ref KButton::released(), | ||
300 | * @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not | ||
301 | * emmited by | ||
302 | * this button (see @ref setDelayedPopup() for that). | ||
303 | * You can add custom popups which inherit @ref QPopupMenu to get popups | ||
304 | * with tables, drawings etc. Just don't fiddle with events there. | ||
305 | */ | ||
306 | int insertButton(const QString& icon, int id, QPopupMenu *popup, | ||
307 | bool enabled, const QString&_text, int index=-1); | ||
308 | |||
309 | /** | ||
310 | * Inserts a button with popupmenu. | ||
311 | * | ||
312 | * Button will have small | ||
313 | * triangle. You have to connect to popup's signals. The | ||
314 | * signals @ref KButton::pressed(), @ref KButton::released(), | ||
315 | * @ref KButton::clicked() or @ref KButton::doubleClicked() are @p not | ||
316 | * emmited by | ||
317 | * this button (see @ref setDelayedPopup() for that). | ||
318 | * You can add custom popups which inherit @ref QPopupMenu to get popups | ||
319 | * with tables, drawings etc. Just don't fiddle with events there. | ||
320 | */ | ||
321 | int insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup, | ||
322 | bool enabled, const QString&_text, int index=-1); | ||
323 | |||
324 | /** | ||
325 | * Inserts a @ref KLineEdit. You have to specify signals and slots to | ||
326 | * which KLineEdit will be connected. KLineEdit has all slots QLineEdit | ||
327 | * has, plus signals @ref KLineEdit::completion and @ref KLineEdit::textRotation | ||
328 | * KLineEdit can be set to autoresize itself to full free width | ||
329 | * in toolbar, that is to last right aligned item. For that, | ||
330 | * toolbar must be set to full width (which it is by default). | ||
331 | * @see setFullWidth() | ||
332 | * @see setItemAutoSized() | ||
333 | * @see KLineEdit | ||
334 | * @return Item index. | ||
335 | */ | ||
336 | int insertLined (const QString& text, int id, | ||
337 | const char *signal, | ||
338 | const QObject *receiver, const char *slot, | ||
339 | bool enabled = true, | ||
340 | const QString& toolTipText = QString::null, | ||
341 | int size = 70, int index =-1); | ||
342 | |||
343 | /** | ||
344 | * Inserts a @ref KComboBox with list. | ||
345 | * | ||
346 | * Can be writable, but cannot contain | ||
347 | * pixmaps. By default inserting policy is AtBottom, i.e. typed items | ||
348 | * are placed at the bottom of the list. Can be autosized. If the size | ||
349 | * argument is specified as -1, the width of the combobox is automatically | ||
350 | * computed. | ||
351 | * | ||
352 | * @see setFullWidth() | ||
353 | * @see setItemAutoSized() | ||
354 | * @see KComboBox | ||
355 | * @return Item index. | ||
356 | */ | ||
357 | int insertCombo (const QStringList &list, int id, bool writable, | ||
358 | const char *signal, const QObject *receiver, | ||
359 | const char *slot, bool enabled=true, | ||
360 | const QString& tooltiptext=QString::null, | ||
361 | int size=70, int index=-1, | ||
362 | QComboBox::Policy policy = QComboBox::AtBottom); | ||
363 | |||
364 | /** | ||
365 | * Insert a @ref KComboBox with text. | ||
366 | * | ||
367 | * The rest is the same as above. | ||
368 | * @see setItemAutoSized() | ||
369 | * | ||
370 | * @see KComboBox | ||
371 | * @return Item index. | ||
372 | */ | ||
373 | int insertCombo (const QString& text, int id, bool writable, | ||
374 | const char *signal, QObject *recevier, | ||
375 | const char *slot, bool enabled=true, | ||
376 | const QString& tooltiptext=QString::null, | ||
377 | int size=70, int index=-1, | ||
378 | QComboBox::Policy policy = QComboBox::AtBottom); | ||
379 | |||
380 | /** | ||
381 | * Inserts a separator into the toolbar with the given id. | ||
382 | * Returns the separator's index | ||
383 | */ | ||
384 | int insertSeparator( int index = -1, int id = -1 ); | ||
385 | |||
386 | /** | ||
387 | * Inserts a line separator into the toolbar with the given id. | ||
388 | * Returns the separator's index | ||
389 | */ | ||
390 | int insertLineSeparator( int index = -1, int id = -1 ); | ||
391 | |||
392 | /** | ||
393 | * Inserts a user-defined widget. The widget @p must have this | ||
394 | * toolbar as its parent. | ||
395 | * | ||
396 | * Widget must have a QWidget for base class. Widget can be | ||
397 | * autosized to full width. If you forget about it, you can get a | ||
398 | * pointer to this widget with @ref getWidget(). | ||
399 | * @see setItemAutoSized() | ||
400 | * @return Item index. | ||
401 | */ | ||
402 | int insertWidget(int id, int width, QWidget *_widget, int index=-1); | ||
403 | |||
404 | /** | ||
405 | * Inserts an animated widget. A @ref KAnimWidget will be created | ||
406 | * internally using the icon name you provide. | ||
407 | * This will emit a signal (clicked()) whenever the | ||
408 | * animation widget is clicked. | ||
409 | * | ||
410 | * @see animatedWidget() | ||
411 | * | ||
412 | * @param id The id for this toolbar item | ||
413 | * @param receiver The parent of your slot | ||
414 | * @param slot The slot to receive the clicked() signal | ||
415 | * @param icons The name of the animation icon group to use | ||
416 | * @param index The item index | ||
417 | * | ||
418 | * @return The item index | ||
419 | */ | ||
420 | /*US | ||
421 | int insertAnimatedWidget(int id, QObject *receiver, const char *slot, | ||
422 | const QString& icons, int index = -1); | ||
423 | */ | ||
424 | /** | ||
425 | * This will return a pointer to the given animated widget, if it | ||
426 | * exists. | ||
427 | * | ||
428 | * @see insertAnimatedWidget | ||
429 | * | ||
430 | * @param id The id for the widget you want to get a pointer to | ||
431 | * | ||
432 | * @return A pointer to the current animated widget or 0L | ||
433 | */ | ||
434 | //US KAnimWidget *animatedWidget( int id ); | ||
435 | |||
436 | /** | ||
437 | * Adds connections to items. | ||
438 | * | ||
439 | * It is important that you | ||
440 | * know the @p id of particular item. Nothing happens if you forget @p id. | ||
441 | */ | ||
442 | void addConnection (int id, const char *signal, | ||
443 | const QObject *receiver, const char *slot); | ||
444 | /** | ||
445 | * Enables/disables item. | ||
446 | */ | ||
447 | void setItemEnabled( int id, bool enabled ); | ||
448 | |||
449 | /** | ||
450 | * Sets the icon for a button. | ||
451 | * | ||
452 | * Can be used while button is visible. | ||
453 | */ | ||
454 | void setButtonIcon( int id, const QString& _icon ); | ||
455 | |||
456 | /** | ||
457 | * Sets button pixmap. | ||
458 | * | ||
459 | * Can be used while button is visible. | ||
460 | */ | ||
461 | void setButtonPixmap( int id, const QPixmap& _pixmap ); | ||
462 | |||
463 | /** | ||
464 | * Sets a button icon from a QIconSet. | ||
465 | * | ||
466 | * Can be used while button is visible. | ||
467 | */ | ||
468 | void setButtonIconSet( int id, const QIconSet& iconset ); | ||
469 | |||
470 | /** | ||
471 | * Sets a delayed popup for a button. | ||
472 | * | ||
473 | * Delayed popup is what you see in | ||
474 | * Netscape Navigator's Previous and Next buttons: If you click them you | ||
475 | * go back | ||
476 | * or forth. If you press them long enough, you get a history-menu. | ||
477 | * This is exactly what we do here. | ||
478 | * | ||
479 | * You will insert normal a button with connection (or use signals from | ||
480 | * toolbar): | ||
481 | * <pre> | ||
482 | * bar->insertButton(icon, id, SIGNAL(clicked ()), this, | ||
483 | * SLOT (slotClick()), true, "click or wait for popup"); | ||
484 | * </pre> And then add a delayed popup: | ||
485 | * <pre> | ||
486 | * bar->setDelayedPopup (id, historyPopup); </pre> | ||
487 | * | ||
488 | * Don't add delayed popups to buttons which have normal popups. | ||
489 | * | ||
490 | * You may add popups which are derived from @ref QPopupMenu. You may | ||
491 | * add popups that are already in the menu bar or are submenus of | ||
492 | * other popups. | ||
493 | */ | ||
494 | void setDelayedPopup (int id , QPopupMenu *_popup, bool toggle = false); | ||
495 | |||
496 | /** | ||
497 | * Turns a button into an autorepeat button. | ||
498 | * | ||
499 | * Toggle buttons, buttons with menus, or | ||
500 | * buttons with delayed menus cannot be made into autorepeat buttons. | ||
501 | * Moreover, you can and will receive | ||
502 | * only the signal clicked(), but not pressed() or released(). | ||
503 | * When the user presses this button, you will receive the signal clicked(), | ||
504 | * and if the button is still pressed after some time, | ||
505 | * you will receive more clicked() signals separated by regular | ||
506 | * intervals. Since this uses @ref QButton::setAutoRepeat() , | ||
507 | * I can't quantify 'some'. | ||
508 | */ | ||
509 | void setAutoRepeat (int id, bool flag=true); | ||
510 | |||
511 | |||
512 | /** | ||
513 | * Turns button into a toggle button if @p flag is true. | ||
514 | */ | ||
515 | void setToggle (int id, bool flag = true); | ||
516 | |||
517 | /** | ||
518 | * Toggles a togglebutton. | ||
519 | * | ||
520 | * If the button is a toggle button (see @ref setToggle()) | ||
521 | * the button state will be toggled. This will also cause the toolbar to | ||
522 | * emit the signal @ref KButton::toggled() with parameter @p id. You must connect to | ||
523 | * this signal, or use @ref addConnection() to connect directly to the | ||
524 | * button signal @ref KButton::toggled(). | ||
525 | */ | ||
526 | void toggleButton (int id); | ||
527 | |||
528 | /** | ||
529 | * Sets a toggle button state. | ||
530 | * | ||
531 | * If the button is a toggle button (see @ref setToggle()) | ||
532 | * this will set its state flag. This will also emit the signal | ||
533 | * @ref KButton::toggled(). | ||
534 | * | ||
535 | * @see setToggle() | ||
536 | */ | ||
537 | void setButton (int id, bool flag); | ||
538 | |||
539 | /** | ||
540 | * @return @p true if button is on, @p false if button is off or if the | ||
541 | * button is not a toggle button. | ||
542 | * @see setToggle() | ||
543 | */ | ||
544 | bool isButtonOn (int id) const; | ||
545 | |||
546 | /** | ||
547 | * Sets the text of a line editor. | ||
548 | * | ||
549 | * Cursor is set at end of text. | ||
550 | */ | ||
551 | void setLinedText (int id, const QString& text); | ||
552 | |||
553 | /** | ||
554 | * Returns a line editor text. | ||
555 | */ | ||
556 | QString getLinedText (int id) const; | ||
557 | |||
558 | /** | ||
559 | * Inserts @p text in combobox @p id at position @p index. | ||
560 | */ | ||
561 | void insertComboItem (int id, const QString& text, int index); | ||
562 | |||
563 | /** | ||
564 | * Inserts @p list in combobox @p id at position @p index. | ||
565 | */ | ||
566 | void insertComboList (int id, const QStringList &list, int index); | ||
567 | |||
568 | /** | ||
569 | * Removes item @p index from combobox @p id. | ||
570 | */ | ||
571 | void removeComboItem (int id, int index); | ||
572 | |||
573 | /** | ||
574 | * Sets item @p index to be current item in combobox @p id. | ||
575 | */ | ||
576 | void setCurrentComboItem (int id, int index); | ||
577 | |||
578 | /** | ||
579 | * Changes item @p index in combobox @p id to text. | ||
580 | * | ||
581 | * @p index = -1 refers current item (one displayed in the button). | ||
582 | */ | ||
583 | void changeComboItem (int id, const QString& text, int index=-1); | ||
584 | |||
585 | /** | ||
586 | * Clears the combobox @p id. | ||
587 | * | ||
588 | * Does not delete it or hide it. | ||
589 | */ | ||
590 | void clearCombo (int id); | ||
591 | |||
592 | /** | ||
593 | * Returns text of item @p index from combobox @p id. | ||
594 | * | ||
595 | * @p index = -1 refers to current item. | ||
596 | */ | ||
597 | |||
598 | QString getComboItem (int id, int index=-1) const; | ||
599 | |||
600 | /** | ||
601 | * Returns a pointer to the combobox. | ||
602 | * | ||
603 | * Example: | ||
604 | * <pre> | ||
605 | * KComboBox *combo = toolbar->getCombo(combo_id); | ||
606 | * </pre> | ||
607 | * That way you can get access to other public methods | ||
608 | * that @ref KComboBox provides. | ||
609 | */ | ||
610 | KComboBox * getCombo(int id); | ||
611 | |||
612 | /** | ||
613 | * Returns a pointer to KToolBarLined. | ||
614 | * | ||
615 | * Example: | ||
616 | * <pre> | ||
617 | * KLineEdit * lined = toolbar->getKToolBarLined(lined_id); | ||
618 | * </pre> | ||
619 | * That way you can get access to other public methods | ||
620 | * that @ref KLineEdit provides. @ref KLineEdit is the same thing | ||
621 | * as @ref QLineEdit plus completion signals. | ||
622 | */ | ||
623 | KLineEdit * getLined (int id); | ||
624 | |||
625 | /** | ||
626 | * Returns a pointer to KToolBarButton. | ||
627 | * | ||
628 | * Example: | ||
629 | * <pre> | ||
630 | * KToolBarButton * button = toolbar->getButton(button_id); | ||
631 | * </pre> | ||
632 | * That way you can get access to other public methods | ||
633 | * that @ref KToolBarButton provides. | ||
634 | * | ||
635 | * Using this method is not recommended. | ||
636 | */ | ||
637 | KToolBarButton * getButton (int id); | ||
638 | |||
639 | /** | ||
640 | * Align item to the right. | ||
641 | * | ||
642 | * This works only if toolbar is set to full width. | ||
643 | * @see setFullWidth() | ||
644 | */ | ||
645 | void alignItemRight (int id, bool right = true); | ||
646 | |||
647 | /** | ||
648 | * Returns a pointer to an inserted widget. | ||
649 | * | ||
650 | * Wrong ids are not tested. | ||
651 | * You can do with this whatever you want, | ||
652 | * except change its height (hardcoded). If you change its width | ||
653 | * you will probably have to call QToolBar::updateRects(true) | ||
654 | * @see QWidget | ||
655 | * @see updateRects() | ||
656 | * | ||
657 | * KDE4: make this const! | ||
658 | */ | ||
659 | QWidget *getWidget (int id); | ||
660 | |||
661 | /** | ||
662 | * Set item autosized. | ||
663 | * | ||
664 | * This works only if the toolbar is set to full width. | ||
665 | * Only @p one item can be autosized, and it has to be | ||
666 | * the last left-aligned item. Items that come after this must be right | ||
667 | * aligned. Items that can be right aligned are Lineds, Frames, Widgets and | ||
668 | * Combos. An autosized item will resize itself whenever the toolbar geometry | ||
669 | * changes to the last right-aligned item (or to end of toolbar if there | ||
670 | * are no right-aligned items.) | ||
671 | * @see setFullWidth() | ||
672 | * @see alignItemRight() | ||
673 | */ | ||
674 | void setItemAutoSized (int id, bool yes = true); | ||
675 | |||
676 | /** | ||
677 | * Remove all items. | ||
678 | * | ||
679 | * The toolbar is redrawn after it. | ||
680 | */ | ||
681 | void clear (); | ||
682 | |||
683 | /** | ||
684 | * Remove item @p id. | ||
685 | * | ||
686 | * Item is deleted. Toolbar is redrawn after it. | ||
687 | */ | ||
688 | void removeItem (int id); | ||
689 | |||
690 | /** | ||
691 | * Remove item @p id. | ||
692 | * | ||
693 | * Item is deleted when toolbar is redrawn. | ||
694 | */ | ||
695 | void removeItemDelayed (int id); | ||
696 | |||
697 | /** | ||
698 | * Hide item. | ||
699 | */ | ||
700 | void hideItem (int id); | ||
701 | |||
702 | /** | ||
703 | * Show item. | ||
704 | */ | ||
705 | void showItem (int id); | ||
706 | |||
707 | /** | ||
708 | * Returns the index of the given item. | ||
709 | * | ||
710 | * KDE4: make this const! | ||
711 | */ | ||
712 | int itemIndex (int id); | ||
713 | |||
714 | /** | ||
715 | * Set toolbar to full parent size (default). | ||
716 | * | ||
717 | * In full size mode the bar | ||
718 | * extends over the parent's full width or height. If the mode is disabled | ||
719 | * the toolbar tries to take as much space as it needs without wrapping, but | ||
720 | * it does not exceed the parent box. You can force a certain width or | ||
721 | * height with @ref setMaxWidth() or @ref setMaxHeight(). | ||
722 | * | ||
723 | * If you want to use right-aligned items or auto-sized items you must use | ||
724 | * full size mode. | ||
725 | */ | ||
726 | void setFullSize(bool flag = true); | ||
727 | |||
728 | /** | ||
729 | * @return @p true if the full-size mode is enabled. Otherwise | ||
730 | * it returns @false. | ||
731 | */ | ||
732 | bool fullSize() const; | ||
733 | |||
734 | /** | ||
735 | * @deprecated use setMovingEnabled(bool) instead. | ||
736 | * Enable or disable moving of toolbar. | ||
737 | */ | ||
738 | void enableMoving(bool flag = true); | ||
739 | |||
740 | /** | ||
741 | * Set position of toolbar. | ||
742 | * @see BarPosition() | ||
743 | */ | ||
744 | void setBarPos (BarPosition bpos); | ||
745 | |||
746 | /** | ||
747 | * Returns position of toolbar. | ||
748 | */ | ||
749 | BarPosition barPos(); | ||
750 | |||
751 | /** | ||
752 | * @deprecated | ||
753 | * Show, hide, or toggle toolbar. | ||
754 | * | ||
755 | * This method is provided for compatibility only, | ||
756 | * please use show() and/or hide() instead. | ||
757 | * @see BarStatus | ||
758 | */ | ||
759 | bool enable(BarStatus stat); | ||
760 | |||
761 | /** | ||
762 | * @deprecated | ||
763 | * Use setMaximumHeight() instead. | ||
764 | */ | ||
765 | void setMaxHeight (int h); // Set max height for vertical toolbars | ||
766 | |||
767 | /** | ||
768 | * @deprecated | ||
769 | * Use maximumHeight() instead. | ||
770 | * Returns the value that was set with @ref setMaxHeight(). | ||
771 | */ | ||
772 | int maxHeight(); | ||
773 | |||
774 | /** | ||
775 | * @deprecated | ||
776 | * Use setMaximumWidth() instead. | ||
777 | * Set maximal width of horizontal (top or bottom) toolbar. | ||
778 | */ | ||
779 | void setMaxWidth (int dw); | ||
780 | |||
781 | /** | ||
782 | * @deprecated | ||
783 | * Use maximumWidth() instead. | ||
784 | * Returns the value that was set with @ref setMaxWidth(). | ||
785 | */ | ||
786 | int maxWidth(); | ||
787 | |||
788 | /** | ||
789 | * Set title for toolbar when it floats. | ||
790 | * | ||
791 | * Titles are however not (yet) | ||
792 | * visible. You can't change toolbar's title while it's floating. | ||
793 | */ | ||
794 | void setTitle (const QString& _title); | ||
795 | |||
796 | /** | ||
797 | * @deprecated | ||
798 | * Use enableMoving() instead. | ||
799 | */ | ||
800 | void enableFloating (bool arrrrrrgh); | ||
801 | |||
802 | /** | ||
803 | * Set the kind of painting for buttons. | ||
804 | * | ||
805 | * Choose from: | ||
806 | * @li IconOnly (only icons), | ||
807 | * @li IconTextRight (icon and text, text is left from icons), | ||
808 | * @li TextOnly (only text), | ||
809 | * @li IconTextBottom (icons and text, text is under icons). | ||
810 | * @see IconText | ||
811 | * | ||
812 | */ | ||
813 | void setIconText(IconText it); | ||
814 | // Note: don't merge with the next one, it breaks Qt properties | ||
815 | |||
816 | /** | ||
817 | * Similar to @ref setIconText(IconText it) but allows you to | ||
818 | * disable or enable updating. If @p update is false, then the | ||
819 | * buttons will not be updated. This is useful only if you know | ||
820 | * that you will be forcing an update later. | ||
821 | */ | ||
822 | void setIconText(IconText it, bool update); | ||
823 | |||
824 | /** | ||
825 | * @return The current text style for buttons. | ||
826 | */ | ||
827 | IconText iconText() const; | ||
828 | |||
829 | /** | ||
830 | * Set the icon size to load. Usually you should not call | ||
831 | * this, the icon size is taken care of by KIconLoader | ||
832 | * and globally configured. | ||
833 | * By default, the toolbar will load icons of size 32 for main | ||
834 | * toolbars and 22 for other toolbars | ||
835 | * @see KIconLoader. | ||
836 | * | ||
837 | * @param size The size to use | ||
838 | */ | ||
839 | void setIconSize(int size); | ||
840 | // Note: don't merge with the next one, it breaks Qt properties | ||
841 | |||
842 | /** | ||
843 | * Same as @ref setIconText(int size) but allows you | ||
844 | * to disable the toolbar update. | ||
845 | * | ||
846 | * @param size The size to use | ||
847 | * @param update If true, then the toolbar will be updated after | ||
848 | * this | ||
849 | */ | ||
850 | void setIconSize(int size, bool update); | ||
851 | |||
852 | /** | ||
853 | * @return The current icon size for buttons. | ||
854 | */ | ||
855 | int iconSize() const; | ||
856 | |||
857 | /** | ||
858 | * This allows you to enable or disable the context menu. | ||
859 | * | ||
860 | * @param enable If false, then the context menu will be disabled | ||
861 | */ | ||
862 | void setEnableContextMenu(bool enable = true); | ||
863 | |||
864 | /** | ||
865 | * Returns whether or not the context menu is disabled | ||
866 | * | ||
867 | * @return The context menu state | ||
868 | */ | ||
869 | bool contextMenuEnabled() const; | ||
870 | |||
871 | /** | ||
872 | * This will inform a toolbar button to ignore certain style | ||
873 | * changes. Specifically, it will ignore IconText (always IconOnly) | ||
874 | * and will not allow image effects to apply. | ||
875 | * | ||
876 | * @param id The button to exclude from styles | ||
877 | * @param no_style If true, then it is excluded (default: true). | ||
878 | */ | ||
879 | void setItemNoStyle(int id, bool no_style = true); | ||
880 | |||
881 | void setFlat (bool flag); | ||
882 | |||
883 | /** | ||
884 | * @return the number of items in the toolbar | ||
885 | */ | ||
886 | int count() const; | ||
887 | |||
888 | /** | ||
889 | * Instruct the toolbar to save it's current state to either the app | ||
890 | * config file or to the XML-GUI resource file (whichever has | ||
891 | * precedence). | ||
892 | */ | ||
893 | void saveState(); | ||
894 | |||
895 | /** | ||
896 | * Save the toolbar settings to group @p configGroup in @p config. | ||
897 | */ | ||
898 | void saveSettings(KConfig *config, const QString &configGroup); | ||
899 | |||
900 | /** | ||
901 | * Read the toolbar settings from group @p configGroup in @p config | ||
902 | * and apply them. | ||
903 | */ | ||
904 | void applySettings(KConfig *config, const QString &configGroup); | ||
905 | |||
906 | /** | ||
907 | * Tell the toolbar what XML-GUI resource file it should use to save | ||
908 | * it's state. The state of the toolbar (position, size, etc) is | ||
909 | * saved in KConfig files if the application does not use XML-GUI.. | ||
910 | * but if the app does, then it's saved the XML file. This function | ||
911 | * allows this to happen. | ||
912 | * | ||
913 | * @param xmlfile The XML-GUI resource file to write to | ||
914 | * @param xml The DOM document for the XML-GUI building | ||
915 | */ | ||
916 | // void setXML(const QString& xmlfile, const QDomDocument& xml); | ||
917 | /* @internal */ | ||
918 | void setXMLGUIClient( KXMLGUIClient *client ); | ||
919 | |||
920 | /** | ||
921 | * Assign a (translated) text to this toolbar. This is used | ||
922 | * for the tooltip on the handle, and when listing the toolbars. | ||
923 | */ | ||
924 | void setText( const QString & txt ); | ||
925 | |||
926 | /** | ||
927 | * @return the toolbar's text. | ||
928 | */ | ||
929 | QString text() const; | ||
930 | |||
931 | void setStretchableWidget( QWidget *w ); | ||
932 | QSizePolicy sizePolicy() const; | ||
933 | bool highlight() const; | ||
934 | QSize sizeHint() const; | ||
935 | QSize minimumSizeHint() const; | ||
936 | QSize minimumSize() const; | ||
937 | |||
938 | void hide(); | ||
939 | void show(); | ||
940 | |||
941 | void updateRects( bool = FALSE ) {} | ||
942 | |||
943 | //US void loadState( const QDomElement &e ); | ||
944 | //US void saveState( QDomElement &e ); | ||
945 | |||
946 | /** | ||
947 | * @internal | ||
948 | */ | ||
949 | void positionYourself( bool force = false); | ||
950 | |||
951 | signals: | ||
952 | /** | ||
953 | * Emitted when button @p id is clicked. | ||
954 | */ | ||
955 | void clicked(int id); | ||
956 | |||
957 | /** | ||
958 | * Emitted when button @p id is double-clicked. | ||
959 | * | ||
960 | * Note: you will always | ||
961 | * recive two @ref clicked() , @ref pressed() and @ref released() signals. | ||
962 | * There is no way to avoid it - at least no easy way. | ||
963 | * If you need to resolve this all you can do is set up timers | ||
964 | * which wait for @ref QApplication::doubleClickInterval() to expire. | ||
965 | * If in that time you don't get this signal, you may belive that | ||
966 | * button was only clicked and not double-clicked. | ||
967 | * And please note that butons with popup menus do not emit this signal, | ||
968 | * but those with delayed popup do. | ||
969 | */ | ||
970 | void doubleClicked (int id); | ||
971 | |||
972 | /** | ||
973 | * Emitted when button @p id is pressed. | ||
974 | */ | ||
975 | void pressed(int); | ||
976 | |||
977 | /** | ||
978 | * Emits when button @p id is released. | ||
979 | */ | ||
980 | void released(int); | ||
981 | |||
982 | /** | ||
983 | * Emitted when a toggle button changes state. | ||
984 | * | ||
985 | * Emitted also if you change state | ||
986 | * with @ref setButton() or @ref toggleButton() | ||
987 | * If you make a button normal again, with | ||
988 | * setToggle(false), this signal won't | ||
989 | * be emitted. | ||
990 | */ | ||
991 | void toggled(int); | ||
992 | |||
993 | /** | ||
994 | * This signal is emitted when item id gets highlighted/unhighlighted | ||
995 | * (i.e when mouse enters/exits). | ||
996 | * | ||
997 | * Note that this signal is emitted from | ||
998 | * all buttons (normal, disabled and toggle) even when there is no visible | ||
999 | * change in buttons (i.e., buttons do not raise when mouse enters). | ||
1000 | * The parameter @p isHighlighted is @p true when mouse enters and @p false when | ||
1001 | * mouse exits. | ||
1002 | */ | ||
1003 | void highlighted(int id, bool isHighlighted); | ||
1004 | |||
1005 | /** | ||
1006 | * This signal is emitted when item id gets highlighted/unhighlighted | ||
1007 | * (i.e when mouse enters/exits). | ||
1008 | * | ||
1009 | * Note that this signal is emitted from | ||
1010 | * all buttons (normal, disabled and toggle) even when there is no visible | ||
1011 | * change in buttons (i.e., buttons do not raise when mouse enters). | ||
1012 | */ | ||
1013 | void highlighted(int id ); | ||
1014 | |||
1015 | /** | ||
1016 | * Emitted when toolbar changes position, or when | ||
1017 | * an item is removed from toolbar. | ||
1018 | * | ||
1019 | * If you subclass @ref KMainWindow and reimplement | ||
1020 | * @ref KMainWindow::resizeEvent() be sure to connect to | ||
1021 | * this signal. Note: You can connect this signal to a slot that | ||
1022 | * doesn't take parameter. | ||
1023 | */ | ||
1024 | void moved( BarPosition ); | ||
1025 | |||
1026 | /** | ||
1027 | * @internal | ||
1028 | * This signal is emitted when toolbar detects changing of | ||
1029 | * following parameters: | ||
1030 | * highlighting, button-size, button-mode. This signal is | ||
1031 | * internal, aimed to buttons. | ||
1032 | */ | ||
1033 | void modechange (); | ||
1034 | |||
1035 | /** | ||
1036 | * This signal is emitted when the toolbar is getting deleted, | ||
1037 | * and before ~KToolbar finishes (so it's still time to remove | ||
1038 | * widgets from the toolbar). | ||
1039 | * Used by KWidgetAction. | ||
1040 | * @since 3.2 | ||
1041 | */ | ||
1042 | void toolbarDestroyed(); | ||
1043 | |||
1044 | public: | ||
1045 | /** | ||
1046 | * @return global setting for "Highlight buttons under mouse" | ||
1047 | */ | ||
1048 | static bool highlightSetting(); | ||
1049 | |||
1050 | /** | ||
1051 | * @return global setting for "Toolbars transparent when moving" | ||
1052 | */ | ||
1053 | static bool transparentSetting(); | ||
1054 | |||
1055 | /** | ||
1056 | * @return global setting for "Icon Text" | ||
1057 | */ | ||
1058 | static IconText iconTextSetting(); | ||
1059 | |||
1060 | public slots: | ||
1061 | virtual void setIconText( const QString &txt ) | ||
1062 | { QToolBar::setIconText( txt ); } | ||
1063 | |||
1064 | protected: | ||
1065 | void mousePressEvent( QMouseEvent * ); | ||
1066 | void childEvent( QChildEvent *e ); | ||
1067 | void showEvent( QShowEvent *e ); | ||
1068 | void resizeEvent( QResizeEvent *e ); | ||
1069 | bool event( QEvent *e ); | ||
1070 | void applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal = false); | ||
1071 | QString settingsGroup(); | ||
1072 | |||
1073 | private slots: | ||
1074 | void rebuildLayout(); | ||
1075 | void slotReadConfig (); | ||
1076 | void slotAppearanceChanged(); | ||
1077 | void slotIconChanged(int); | ||
1078 | void slotRepaint(); | ||
1079 | void toolBarPosChanged( QToolBar *tb ); | ||
1080 | void slotContextAboutToShow(); | ||
1081 | void widgetDestroyed(); | ||
1082 | |||
1083 | private: | ||
1084 | void init( bool readConfig = true, bool honorStyle = false ); | ||
1085 | void doConnections( KToolBarButton *button ); | ||
1086 | void insertWidgetInternal( QWidget *w, int &index, int id ); | ||
1087 | void removeWidgetInternal( QWidget *w ); | ||
1088 | void getAttributes( QString &position, QString &icontext, int &index ); | ||
1089 | //US KPopupMenu *contextMenu(); | ||
1090 | QPopupMenu *contextMenu(); | ||
1091 | |||
1092 | QMap<QWidget*, int > widget2id; | ||
1093 | typedef QMap<int, QWidget* > Id2WidgetMap; | ||
1094 | Id2WidgetMap id2widget; | ||
1095 | //US KPopupMenu *context; | ||
1096 | QPopupMenu *context; | ||
1097 | QPtrList<QWidget> widgets; | ||
1098 | QTimer *layoutTimer; | ||
1099 | QGuardedPtr<QWidget> stretchableWidget, rightAligned; | ||
1100 | protected: | ||
1101 | virtual void virtual_hook( int id, void* data ); | ||
1102 | private: | ||
1103 | KToolBarPrivate *d; | ||
1104 | bool inshutdownprocess; | ||
1105 | }; | ||
1106 | |||
1107 | #endif | ||