libyui-qt  2.47.1.1
YQLabel.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: YQLabel.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #include <qlabel.h>
27 
28 #define YUILogComponent "qt-ui"
29 #include <yui/YUILog.h>
30 
31 #include "utf8.h"
32 #include "YQUI.h"
33 #include "YQApplication.h"
34 #include "YQLabel.h"
35 
36 
37 YQLabel::YQLabel( YWidget * parent,
38  const std::string & text,
39  bool isHeading,
40  bool isOutputField )
41  : QLabel( (QWidget *) parent->widgetRep() )
42  , YLabel( parent, text, isHeading, isOutputField )
43 {
44  setWidgetRep( this );
45 
46  setTextFormat( Qt::PlainText );
47  QLabel::setText( fromUTF8( text ) );
48  setIndent(0);
49 
50  if ( isHeading )
51  {
52  setFont( YQUI::yqApp()->headingFont() );
53  }
54  else if ( isOutputField )
55  {
56  setFrameStyle ( QFrame::Panel | QFrame::Sunken );
57  setLineWidth(2);
58  setMidLineWidth(2);
59  }
60 
61  setMargin( YQWidgetMargin );
62  setAlignment( Qt::AlignLeft | Qt::AlignTop );
63 }
64 
65 
67 {
68  // NOP
69 }
70 
71 
72 void YQLabel::setText( const std::string & newText )
73 {
74  YLabel::setText( newText );
75  QLabel::setText( fromUTF8( newText ) );
76 }
77 
78 
79 void YQLabel::setUseBoldFont( bool useBold )
80 {
81  setFont( useBold ?
82  YQUI::yqApp()->boldFont() :
83  YQUI::yqApp()->currentFont() );
84 
85  YLabel::setUseBoldFont( useBold );
86 }
87 
88 
89 void YQLabel::setEnabled( bool enabled )
90 {
91  QLabel::setEnabled( enabled );
92  YWidget::setEnabled( enabled );
93 }
94 
95 
97 {
98  return sizeHint().width();
99 }
100 
101 
103 {
104  return sizeHint().height();
105 }
106 
107 
108 void YQLabel::setSize( int newWidth, int newHeight )
109 {
110  resize( newWidth, newHeight );
111 }
112 
113 
114 #include "YQLabel.moc"
virtual void setText(const std::string &newText)
Set the text the widget displays.
Definition: YQLabel.cc:72
static YQApplication * yqApp()
Return the global YApplication object as YQApplication.
Definition: YQUI.cc:282
virtual ~YQLabel()
Destructor.
Definition: YQLabel.cc:66
YQLabel(YWidget *parent, const std::string &text, bool isHeading=false, bool isOutputField=false)
Constructor.
Definition: YQLabel.cc:37
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQLabel.cc:102
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQLabel.cc:96
virtual void setUseBoldFont(bool bold)
Switch bold font on or off.
Definition: YQLabel.cc:79
virtual void setEnabled(bool enabled)
Set enabled / disabled state.
Definition: YQLabel.cc:89
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQLabel.cc:108