]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQWidgetCaption.h
picking up branches/tmp/sh/qt4-port/, merging it with trunk
[duncan/yast2-qt4.git] / src / YQWidgetCaption.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQWidgetCaption.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQWidgetCaption_h
21 #define YQWidgetCaption_h
22
23 #include <qlabel.h>
24 #include <string>
25 using std::string;
26
27
28 /**
29  * Helper class for captions (labels) above a widget: Takes care of hiding
30  * itself when its text is empty and showing when its text becomes non-empty.
31  **/
32 class YQWidgetCaption: public QLabel
33 {
34     Q_OBJECT
35
36 public:
37
38     /**
39      * Constuctors.
40      *
41      * If the text is empty, the widget will be created, but hidden right
42      * away. It can later be made visible again with setText() with a non-empty
43      * text.
44      **/
45     YQWidgetCaption( QWidget * parent, const string  & text );
46     YQWidgetCaption( QWidget * parent, const QString & text );
47
48     /**
49      * Destructor.
50      **/
51     virtual ~YQWidgetCaption();
52
53     /**
54      * Change the text and handle visibility:
55      * If the new text is empty, hide this widget.
56      * If the new text is non-empty, show this widget.
57      **/
58     virtual void setText ( const string  & newText );
59     virtual void setText ( const QString & newText );
60
61 private:
62
63     /**
64      * Make the widget visible if the text is non-empty or hide it if it is
65      * empty. 
66      **/
67     void handleVisibility( const string  & text );
68     void handleVisibility( const QString & text );
69     void handleVisibility( bool textIsEmpty );
70 };
71
72
73 #endif // YQWidgetCaption_h