libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/YQWidgetCaption.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:       YQWidgetCaption.cc
00020 
00021   Author:     Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #define YUILogComponent "qt-ui"
00027 #include <yui/YUILog.h>
00028 
00029 #include "YQWidgetCaption.h"
00030 #include "utf8.h"
00031 
00032 
00033 YQWidgetCaption::YQWidgetCaption( QWidget * parent,
00034                                   const std::string &  text )
00035     : QLabel( fromUTF8( text ), parent )
00036 {
00037     setTextFormat( Qt::PlainText );
00038     handleVisibility( text );
00039 }
00040 
00041 
00042 YQWidgetCaption::YQWidgetCaption( QWidget * parent, const QString & text )
00043     : QLabel( text, parent )
00044 {
00045     setTextFormat( Qt::PlainText );
00046     handleVisibility( text );
00047 }
00048 
00049 
00050 YQWidgetCaption::~YQWidgetCaption()
00051 {
00052     // NOP
00053 }
00054 
00055 
00056 void YQWidgetCaption::setText ( const std::string  & newText )
00057 {
00058     setText( fromUTF8( newText ) );
00059 }
00060 
00061 
00062 void YQWidgetCaption::setText ( const QString & newText )
00063 {
00064     QLabel::setText( newText );
00065     handleVisibility( newText.isEmpty() );
00066 }
00067 
00068 
00069 void YQWidgetCaption::handleVisibility( const std::string  & text )
00070 {
00071     handleVisibility( text.empty() );
00072 }
00073 
00074 
00075 void YQWidgetCaption::handleVisibility( const QString & text )
00076 {
00077     handleVisibility( text.isEmpty() );
00078 }
00079 
00080 
00081 void YQWidgetCaption::handleVisibility( bool textIsEmpty )
00082 {
00083     if ( textIsEmpty )
00084     {
00085         if ( !isHidden() )
00086             hide();
00087     }
00088     else
00089     {
00090         if ( isHidden() )
00091             show();
00092     }
00093 }
00094 
00095 
00096 #include "YQWidgetCaption.moc"
 All Classes Functions Variables