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