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