libyui-qt  2.47.1.1
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 
34  const std::string & text )
35  : QLabel( fromUTF8( text ), parent )
36 {
37  setTextFormat( Qt::PlainText );
38  handleVisibility( text );
39 }
40 
41 
42 YQWidgetCaption::YQWidgetCaption( QWidget * parent, const QString & text )
43  : QLabel( text, parent )
44 {
45  setTextFormat( Qt::PlainText );
46  handleVisibility( text );
47 }
48 
49 
51 {
52  // NOP
53 }
54 
55 
56 void YQWidgetCaption::setText ( const std::string & newText )
57 {
58  setText( fromUTF8( newText ) );
59 }
60 
61 
62 void YQWidgetCaption::setText ( const QString & newText )
63 {
64  QLabel::setText( newText );
65  handleVisibility( newText.isEmpty() );
66 }
67 
68 
69 void YQWidgetCaption::handleVisibility( const std::string & text )
70 {
71  handleVisibility( text.empty() );
72 }
73 
74 
75 void YQWidgetCaption::handleVisibility( const QString & text )
76 {
77  handleVisibility( text.isEmpty() );
78 }
79 
80 
81 void YQWidgetCaption::handleVisibility( bool textIsEmpty )
82 {
83  if ( textIsEmpty )
84  {
85  if ( !isHidden() )
86  hide();
87  }
88  else
89  {
90  if ( isHidden() )
91  show();
92  }
93 }
94 
95 
96 #include "YQWidgetCaption.moc"
virtual void setText(const std::string &newText)
Change the text and handle visibility: If the new text is empty, hide this widget.
virtual ~YQWidgetCaption()
Destructor.
YQWidgetCaption(QWidget *parent, const std::string &text)
Constuctors.