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