summaryrefslogtreecommitdiffabout
path: root/microkde/kdeui/kjanuswidget.h
Unidiff
Diffstat (limited to 'microkde/kdeui/kjanuswidget.h') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdeui/kjanuswidget.h565
1 files changed, 565 insertions, 0 deletions
diff --git a/microkde/kdeui/kjanuswidget.h b/microkde/kdeui/kjanuswidget.h
new file mode 100644
index 0000000..6d3f23d
--- a/dev/null
+++ b/microkde/kdeui/kjanuswidget.h
@@ -0,0 +1,565 @@
1/* This file is part of the KDE Libraries
2 * Copyright (C) 1999-2000 Espen Sand (espen@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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20#ifndef _KJANUS_WIDGET_H_
21#define _KJANUS_WIDGET_H_
22
23#include <qptrlist.h>
24#include <qwidget.h>
25#include <qmap.h>
26#include <qgrid.h>
27#include <klistbox.h>
28
29/*US
30#include <qptrlist.h>
31#include <qpixmap.h>
32#include <qsplitter.h>
33
34#include <qstringlist.h>
35#include <qmap.h>
36
37*/
38
39class KSeparator;
40class KListView;
41class QWidgetStack;
42class QLabel;
43class QTabWidget;
44class QListViewItem;
45class QVBox;
46class QHBox;
47
48/**
49 * Provides a number of ready to use layouts (faces). It is used
50 * as an internal widget in @ref KDialogBase, but can also used as a
51 * widget of its own.
52 *
53 * It provides TreeList, IconList, Tabbed, Plain and Swallow layouts.
54 *
55 * The TreeList face provides a list in the left area and pages in the
56 * right. The area are separated by a movable splitter. The style is somewhat
57 * similar to the layout in the Control Center. A page is raised by
58 * selecting the corresponding tree list item.
59 *
60 * The IconList face provides an icon list in the left area and pages in the
61 * right. For each entry the Icon is on top with the text below. The style
62 * is somewhat similar to the layout of the Eudora configuation dialog box.
63 * A page is raised by selecting the corresponding icon list item. The
64 * preferred icon size is 32x32 pixels.
65 *
66 * The Tabbed face is a common tabbed widget. The procedure for creating a
67 * page is similar for creating a TreeList. This has the advantage that if
68 * your widget contain too many pages it is trivial to convert it into a
69 * TreeList. Just change the face in the KJanusWidget constructor to
70 * KJanusWidget::TreeList and you have a tree list layout instead.
71 *
72 * The Plain face provides an empty widget (QFrame) where you can place your
73 * widgets. The KJanusWidget makes no assumptions regarding the contents so
74 * you are free to add whatever you want.
75 *
76 * The Swallow face is provided in order to simplify the usage of existing
77 * widgets and to allow changing the visible widget. You specify the widget
78 * to be displayed by @ref #setSwallowedWidget(). Your widget will be
79 * reparented inside the widget. You can specify a Null (0) widget. A empty
80 * space is then displayed.
81 *
82 * For all modes it is important that you specify the @ref QWidget::minimumSize()
83 * on the page, plain widget or the swallowed widget. If you use a QLayout
84 * on the page, plain widget or the swallowed widget this will be taken care
85 * of automatically. The size is used when the KJanusWidget determines its
86 * own minimum size. You get the minimum size by using the
87 * @ref #minimumSizeHint() or @ref #sizeHint() methods.
88 *
89 * Pages that have been added in TreeList, IconList or Tabbed mode can be
90 * removed by simply deleting the page. However, it would be preferable to use
91 * the QObject::deleteLater() function on the page as the main event loop
92 * may have optimized UI update events of the page by scheduling them for later.
93 *
94 * @short Easy to use widget with many layouts
95 * @author Espen Sand (espen@kde.org)
96 */
97class KJanusWidget : public QWidget
98{
99 Q_OBJECT
100
101 private:
102 class IconListBox : public KListBox
103 {
104 public:
105 IconListBox( QWidget *parent=0, const char *name=0, WFlags f=0 );
106 void updateMinimumHeight();
107 void updateWidth();
108 void invalidateHeight();
109 void invalidateWidth();
110 void setShowAll( bool showAll );
111
112 private:
113 bool mShowAll;
114 bool mHeightValid;
115 bool mWidthValid;
116 };
117
118 public:
119 enum Face
120 {
121 TreeList = 0,
122 Tabbed,
123 Plain,
124 Swallow,
125 IconList
126 };
127
128 public:
129
130 /**
131 * Constructor where you specify the face.
132 *
133 * @param parent Parent of the widget.
134 * @param name Widget name.
135 * @param int face The kind of dialog, Use TreeList, Tabbed, Plain or
136 * Swallow.
137 */
138 KJanusWidget( QWidget *parent=0, const char *name=0, int face=Plain );
139
140 /**
141 * Destructor.
142 */
143 ~KJanusWidget();
144
145 /**
146 * Raises the page which was added by @ref addPage().
147 *
148 * @param index The index of the page you want to raise.
149 */
150 virtual bool showPage( int index );
151
152 /**
153 * Returns the index of the page that are currently displayed.
154 *
155 * @return The index or -1 if the face is not Tabbed, TreeList or
156 * IconList.
157 */
158 virtual int activePageIndex() const;
159
160 /**
161 * Use this to verify
162 * that no memory allocation failed.
163 *
164 * @return true if the widget was properly created.
165 */
166 virtual bool isValid() const;
167
168 /**
169 * Returns the face type.
170 *
171 * @return The face type.
172 */
173 virtual int face() const;
174
175 /**
176 * Returns the minimum size that must be made available for the widget
177 * so that UIs can be displayed properly
178 *
179 * @return The minimum size.
180 */
181 virtual QSize minimumSizeHint() const;
182
183 /**
184 * Returns the recommended size for the widget in order to be displayed
185 * properly.
186 *
187 * @return The recommended size.
188 */
189 virtual QSize sizeHint() const;
190
191 /**
192 * Returns the empty widget that is available in Plain mode.
193 *
194 * @return The widget or 0 if the face in not Plain.
195 */
196 virtual QFrame *plainPage();
197
198 /**
199 * Add a new page when the class is used in TreeList, IconList or Tabbed
200 * mode. The returned widget is empty and you must add your widgets
201 * as children to this widget. In most cases you must create a layout
202 * manager and associate it with this widget as well.
203 *
204 * Deleting the returned frame will cause the listitem or tab to be
205 * removed (you can re-add a page with the same name later.
206 *
207 * @param item String used in the list or Tab item.
208 * @param header A longer string used in TreeList and IconList mode to
209 * describe the contents of a page. If empty, the item string
210 * will be used instead.
211 * @param pixmap Used in IconList mode or in TreeList mode. You should
212 * prefer a pixmap with size 32x32 pixels.
213 *
214 * @return The empty page or 0 if the face is not TreeList, IconList or
215 * Tabbed.
216 */
217 virtual QFrame *addPage(const QString &item,const QString &header=QString::null,
218 const QPixmap &pixmap=QPixmap() );
219
220 /**
221 * This is like addPage just above, with the difference that the first
222 * element is a list of strings. These strings are used to form a path
223 * of folders down to the given page. The initial elements are names
224 * for the folders, while the last element is the name of the page.
225 * Note: This does yet only work for the TreeList face. Later this may
226 * be added for the IconList face too. In other faces than the
227 * TreeList, all the strings except the last one is ignored.
228 * Deleting the returned frame will cause the listitem or tab to be
229 * removed (you can re-add a page with the same name later.
230 *
231 * Deleting the returned frame will cause the listitem or tab to be
232 * removed (you can re-add a page with the same name later.
233 **/
234 virtual QFrame *addPage(const QStringList &items, const QString &header=QString::null,
235 const QPixmap &pixmap=QPixmap() );
236
237 /**
238 * Add a new page when the class is used in TreeList, IconList or Tabbed
239 * mode. The returned widget is empty and you must add your widgets
240 * as children to this widget. The returned widget is a @ref QVBox
241 * so it contains a QVBoxLayout layout that lines up the child widgets
242 * are vertically.
243 *
244 * Deleting the returned frame will cause the listitem or tab to be
245 * removed (you can re-add a page with the same name later.
246 *
247 * @param item String used in the list or Tab item.
248 * @param header A longer string used in TreeList and IconList mode to
249 * describe the contents of a page. If empty, the item string
250 * will be used instead.
251 * @param pixmap Used in IconList mode or in TreeList mode. You should
252 * prefer a pixmap with size 32x32 pixels.
253 *
254 * @return The empty page or 0 if the face is not TreeList, IconList or
255 * Tabbed. */
256 virtual QVBox *addVBoxPage( const QString &item,
257 const QString &header=QString::null,
258 const QPixmap &pixmap=QPixmap() );
259
260 /**
261 * This is like addVBoxPage just above, with the difference that the first
262 * element is a list of strings. These strings are used to form a path
263 * of folders down to the given page. The initial elements are names
264 * for the folders, while the last element is the name of the page.
265 * Note: This does yet only work for the TreeList face. Later this may
266 * be added for the IconList face too. In other faces than the
267 * TreeList, all the strings except the last one is ignored.
268 *
269 * Deleting the returned frame will cause the listitem or tab to be
270 * removed (you can re-add a page with the same name later.
271 **/
272 virtual QVBox *addVBoxPage( const QStringList &items,
273 const QString &header=QString::null,
274 const QPixmap &pixmap=QPixmap() );
275
276 /**
277 * Add a new page when the class is used in TreeList, IconList or Tabbed
278 * mode. The returned widget is empty and you must add your widgets
279 * as children to this widget. The returned widget is a @ref QHBox
280 * so it contains a QHBoxLayout layout that lines up the child widgets
281 * are horizontally.
282 *
283 * Deleting the returned frame will cause the listitem or tab to be
284 * removed (you can re-add a page with the same name later.
285 *
286 * @param item String used in the list or Tab item.
287 * @param header A longer string used in TreeList and IconList mode to
288 * describe the contents of a page. If empty, the item string
289 * will be used instead.
290 * @param pixmap Used in IconList mode or in TreeList mode. You should
291 * prefer a pixmap with size 32x32 pixels.
292 *
293 * @return The empty page or 0 if the face is not TreeList, IconList or
294 * Tabbed.
295 */
296 virtual QHBox *addHBoxPage( const QString &itemName,
297 const QString &header=QString::null,
298 const QPixmap &pixmap=QPixmap() );
299
300 /**
301 * This is like addHBoxPage just above, with the difference that the first
302 * element is a list of strings. These strings are used to form a path
303 * of folders down to the given page. The initial elements are names
304 * for the folders, while the last element is the name of the page.
305 * Note: This does yet only work for the TreeList face. Later this may
306 * be added for the IconList face too. In other faces than the
307 * TreeList, all the strings except the last one is ignored.
308 *
309 * Deleting the returned frame will cause the listitem or tab to be
310 * removed (you can re-add a page with the same name later.
311 **/
312 virtual QHBox *addHBoxPage( const QStringList &items,
313 const QString &header=QString::null,
314 const QPixmap &pixmap=QPixmap() );
315
316 /**
317 * Add a new page when the class is used in either TreeList or Tabbed
318 * mode. The returned widget is empty and you must add your widgets
319 * as children to this widget. The returned widget is a @ref QGrid
320 * so it contains a QGridLayout layout that places up the child widgets
321 * in a grid.
322 *
323 * Deleting the returned frame will cause the listitem or tab to be
324 * removed (you can re-add a page with the same name later.
325 *
326 * @param n Specifies the number of columns if 'dir' is QGrid::Horizontal
327 * or the number of rows if 'dir' is QGrid::Vertical.
328 * @param dir Can be QGrid::Horizontal or QGrid::Vertical.
329 * @param item String used in the list or Tab item.
330 * @param header A longer string used in TreeList and IconList mode to
331 * describe the contents of a page. If empty, the item string
332 * will be used instead.
333 * @param pixmap Used in IconList mode or in TreeList mode. You should
334 * prefer a pixmap with size 32x32 pixels.
335 *
336 * @return The empty page or 0 if the face is not TreeList, IconList or
337 * Tabbed.
338 */
339//US changed Orientation into Direction for compatibility
340 virtual QGrid *addGridPage( int n, QGrid::Direction dir,
341 const QString &itemName,
342 const QString &header=QString::null,
343 const QPixmap &pixmap=QPixmap() );
344
345 /**
346 * This is like addGridPage just above, with the difference that the first
347 * element is a list of strings. These strings are used to form a path
348 * of folders down to the given page. The initial elements are names
349 * for the folders, while the last element is the name of the page.
350 * Note: This does yet only work for the TreeList face. Later this may
351 * be added for the IconList face too. In other faces than the
352 * TreeList, all the strings except the last one is ignored.
353 *
354 * Deleting the returned frame will cause the listitem or tab to be
355 * removed (you can re-add a page with the same name later.
356 **/
357//US changed Orientation into Direction for compatibility
358 virtual QGrid *addGridPage( int n, QGrid::Direction dir,
359 const QStringList &items,
360 const QString &header=QString::null,
361 const QPixmap &pixmap=QPixmap() );
362
363 /**
364 * @short Removes a page created with @ref addPage, @ref addVBoxPage,
365 * @ref addHBoxPage or @ref addGridPage. If the page has already
366 * been deleted or has already been removed, nothing happens. The widget
367 * itself is not deleted.
368 *
369 * @param page The widget returned by @ref addPage , @ref addVBoxPage ,
370 * @ref addHBoxPage or @ref addGridPage .
371 */
372 void removePage( QWidget *page );
373
374
375 /**
376 * Returns the index of a page created with @ref addPage ,
377 * @ref addVBoxPage , @ref addHBoxPage or @ref addGridPage .
378 * You can can compare this index with the value returned from
379 * @ref activePageIndex if you need to do some page specific actions
380 * in your code.
381 *
382 * The returned index will never change so you can safely use this
383 * function once and save the value.
384 *
385 * @param widget The widget returned by @ref addPage , @ref addVBoxPage ,
386 * @ref addHBoxPage or @ref addGridPage .
387 *
388 * @return The index or -1 if the face is not Tabbed, TreeList or
389 * IconList
390 */
391 virtual int pageIndex( QWidget *widget ) const;
392
393 /**
394 * Defines the widget to be swallowed.
395 *
396 * This method can be used several
397 * times. Only the latest defined widget will be shown.
398 *
399 * @param widget The widget to be swallowed. If 0, then an empty rectangle
400 * is displayed.
401 */
402 virtual bool setSwallowedWidget( QWidget *widget );
403
404 /**
405 * This function has only effect in TreeList mode.
406 *
407 * Defines how the tree list is resized when the widget is resized
408 * horizontally. By default the tree list keeps its width when the
409 * widget becomes wider.
410 *
411 * @param state The resize mode. If false (default) the TreeList keeps
412 * its current width when the widget becomes wider.
413 */
414 virtual void setTreeListAutoResize( bool state );
415
416 /**
417 * This function has only effect in TreeList mode.
418 *
419 * This tells the widgets whether the icons given in the @ref addPage,
420 * @ref addVBoxPage, @ref addHBoxPage, or @ref addGridPage methods should
421 * be shown in the TreeList.
422 *
423 * Note: This method must be called before calling any of the methods
424 * which add icons to the page.
425 *
426 * @param state If true the icons are shown.
427 **/
428 virtual void setShowIconsInTreeList(bool state);
429
430 /**
431 * This function has only effect in TreeList mode.
432 *
433 * This tells the widgets whether the root should be decorated.
434 * For details see @ref QListView::setRootIsDecorated
435 *
436 * @param state Root will be decorated if true.
437 **/
438 virtual void setRootIsDecorated( bool state );
439
440 /**
441 * This function has only effect in TreeList mode.
442 *
443 * This tells the TreeList to unfold the whole tree so that all entries
444 * are visible.
445 *
446 * If the list is empty when you call this method newly created entries
447 * will not automatically be opened. If the @p persist flag is set opened
448 * entries cannot be closed again, though.
449 *
450 * @param persist If true the tree always stays unfolded.
451 * @since 3.2
452 */
453 /*virtual*/ void unfoldTreeList( bool persist = false ); //### KDE4 BIC add virtual
454
455 /**
456 * This function has only effect in IconList mode.
457 *
458 * Defines how the icon list widget is displayed. By default it is
459 * the widgets in the pages that decide the minimum height
460 * of the toplevel widget. A vertical scrollbar can be used in
461 * the icon list area.
462 *
463 * @param state The visibility mode. If true, the minimum height is
464 * adjusted so that every icon in the list is visible at the
465 * same time. The vertical scrollbar will never be visible.
466 */
467 virtual void setIconListAllVisible( bool state );
468
469 /**
470 * Sets the icon used in TreeList Mode for the given path.
471 * @param path The path for which this icon should be shown.
472 * @param pixmap The icon used.
473 **/
474 virtual void setFolderIcon(const QStringList &path, const QPixmap &pixmap);
475 /**
476 * Returns the title string associated with a page index in TreeList or IconList mode.
477 * @param index The index of the page or null if there is no such page.
478 * @see @ref #pageIndex()
479 * @since 3.2
480 */
481 /*virtual*/ QString pageTitle(int index) const;
482 /**
483 * Returns the page widget associated with a page index or null if there is
484 * no such page.
485 * @param index The index of the page.
486 * @see @ref #pageIndex()
487 * @since 3.2
488 */
489 /*virtual*/ QWidget *pageWidget(int index) const;
490
491 signals:
492 void aboutToShowPage(QWidget *page);
493
494 public slots:
495 /**
496 * Give the keyboard input focus to the widget.
497 */
498 virtual void setFocus();
499
500 protected:
501 /**
502 * Reimplemented to handle the splitter width when the the face
503 * is TreeList
504 */
505 virtual void showEvent( QShowEvent * );
506
507 /**
508 * This function is used internally when in IconList mode. If you
509 * reimplement this class a make your own event filter, make sure to
510 * call this function from your filter.
511 *
512 * @param o Object that has received an event.
513 * @param e The event.
514 */
515 virtual bool eventFilter( QObject *o, QEvent *e );
516
517 private slots:
518 bool slotShowPage();
519//US not yet implemented void slotFontChanged();
520 void slotItemClicked(QListViewItem *it);
521 void pageGone( QObject *obj); // signal from the added page's "destroyed" signal
522 void slotReopen(QListViewItem *item);
523
524 protected:
525 bool showPage( QWidget *w );
526 void addPageWidget( QFrame *page, const QStringList &items,
527 const QString &header, const QPixmap &pixmap );
528 void InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page);
529 QWidget *FindParent();
530
531 private:
532 bool mValid;
533
534 // Obsolete members. Remove in KDE 4.
535 QPtrList<QWidget> *mPageList;
536 QStringList *mTitleList;
537
538 int mFace;
539 KListView *mTreeList;
540 IconListBox *mIconList;
541 QWidgetStack *mPageStack;
542 QLabel *mTitleLabel;
543 QTabWidget *mTabControl;
544 QFrame *mPlainPage;
545 QWidget *mSwallowPage;
546 QWidget *mActivePageWidget;
547 KSeparator *mTitleSep;
548//US QSplitter::ResizeMode mTreeListResizeMode;
549 bool mShowIconsInTreeList;
550 QMap<QListViewItem *, QWidget *> mTreeListToPageStack;
551 QMap<QListBoxItem *, QWidget *> mIconListToPageStack;
552 QMap<QString, QPixmap> mFolderIconMap;
553 QMap<QString, QStringList> mChildrenNames;
554 QMap<QString, QWidget *> mChildPages;
555
556 public:
557 class IconListItem;
558 protected:
559 virtual void virtual_hook( int id, void* data );
560 private:
561 class KJanusWidgetPrivate;
562 KJanusWidgetPrivate *d;
563};
564
565#endif