libyui-qt  2.53.0
YQWidgetCaption.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQWidgetCaption.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "qt-ui"
27 #include <yui/YUILog.h>
28 
29 #include "YQWidgetCaption.h"
30 #include "utf8.h"
31 
32 using std::string;
33 
34 
35 
37  const string & text )
38  : QLabel( fromUTF8( text ), parent )
39 {
40  setTextFormat( Qt::PlainText );
41  handleVisibility( text );
42 }
43 
44 
45 YQWidgetCaption::YQWidgetCaption( QWidget * parent, const QString & text )
46  : QLabel( text, parent )
47 {
48  setTextFormat( Qt::PlainText );
49  handleVisibility( text );
50 }
51 
52 
54 {
55  // NOP
56 }
57 
58 
59 void YQWidgetCaption::setText ( const string & newText )
60 {
61  setText( fromUTF8( newText ) );
62 }
63 
64 
65 void YQWidgetCaption::setText ( const QString & newText )
66 {
67  QLabel::setText( newText );
68  handleVisibility( newText.isEmpty() );
69 }
70 
71 
72 void YQWidgetCaption::handleVisibility( const string & text )
73 {
74  handleVisibility( text.empty() );
75 }
76 
77 
78 void YQWidgetCaption::handleVisibility( const QString & text )
79 {
80  handleVisibility( text.isEmpty() );
81 }
82 
83 
84 void YQWidgetCaption::handleVisibility( bool textIsEmpty )
85 {
86  if ( textIsEmpty )
87  {
88  if ( !isHidden() )
89  hide();
90  }
91  else
92  {
93  if ( isHidden() )
94  show();
95  }
96 }
YQWidgetCaption::~YQWidgetCaption
virtual ~YQWidgetCaption()
Destructor.
Definition: YQWidgetCaption.cc:53
YQWidgetCaption::setText
virtual void setText(const std::string &newText)
Change the text and handle visibility: If the new text is empty, hide this widget.
Definition: YQWidgetCaption.cc:59
YQWidgetCaption::YQWidgetCaption
YQWidgetCaption(QWidget *parent, const std::string &text)
Constuctors.
Definition: YQWidgetCaption.cc:36