libyui  3.3.1
YLabel.h
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: YLabel.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YLabel_h
26 #define YLabel_h
27 
28 #include "YWidget.h"
29 #include <string>
30 #include "ImplPtr.h"
31 
32 
33 class YLabelPrivate;
34 
35 /**
36  * Implementation of the Label, Heading and OutputField widgets
37  **/
38 class YLabel : public YWidget
39 {
40 public:
41 
42  /**
43  * Constructor.
44  *
45  * 'isHeading' indicates if this should be displayed as a Heading widget,
46  * i.e. with a bold and/or larger font.
47  * This cannot be changed after creating the widget.
48  *
49  * 'isOutputField' indicates if this should be displayed as an OutputField
50  * widget, i.e. similar to an InputField the user can't change.
51  * This cannot be changed after creating the widget.
52  **/
54  const std::string & text,
55  bool isHeading = false,
56  bool isOutputField = false );
57 
58  /**
59  * Destructor.
60  **/
61  virtual ~YLabel();
62 
63  /**
64  * Returns a descriptive name of this widget class for logging,
65  * debugging etc.
66  *
67  * Reimplemented from YWidget.
68  **/
69  virtual const char * widgetClass() const;
70 
71  /**
72  * Return the text the widget displays.
73  **/
74  std::string text() const;
75 
76  /**
77  * Aliases for text().
78  **/
79  std::string value() const { return text(); }
80  std::string label() const { return text(); }
81 
82  /**
83  * Set the text the widget displays.
84  *
85  * Derived classes should overwrite this, but call this base class function
86  * in the overwritten function.
87  **/
88  virtual void setText( const std::string & newText );
89 
90  /**
91  * Aliases for setText().
92  **/
93  void setValue( const std::string & newValue ) { setText( newValue ); }
94  void setLabel( const std::string & newLabel ) { setText( newLabel ); }
95 
96  /**
97  * Return 'true' if this is a Heading widget, i.e., it should display its
98  * text in a bold and/or larger font.
99  *
100  * This cannot be changed after creating the widget.
101  **/
102  bool isHeading() const;
103 
104  /**
105  * Return 'true' if this is an OutputField widget, i.e., it should display
106  * its text similar to an InputField the user can't change.
107  *
108  * This cannot be changed after creating the widget.
109  **/
110  bool isOutputField() const;
111 
112  /**
113  * Return 'true' if a bold font should be used.
114  **/
115  bool useBoldFont() const;
116 
117  /**
118  * Switch bold font on or off.
119  *
120  * Derived classes should overwrite this, but call this base class function
121  * in the overwritten function.
122  **/
123  virtual void setUseBoldFont( bool bold = true );
124 
125  /**
126  * Set a property.
127  * Reimplemented from YWidget.
128  *
129  * This method may throw exceptions, for example
130  * - if there is no property with that name
131  * - if the expected type and the type mismatch
132  * - if the value is out of range
133  *
134  * This function returns 'true' if the value was successfully set and
135  * 'false' if that value requires special handling (not in error cases:
136  * those are covered by exceptions).
137  **/
138  virtual bool setProperty( const std::string & propertyName,
139  const YPropertyValue & val );
140 
141  /**
142  * Get a property.
143  * Reimplemented from YWidget.
144  *
145  * This method may throw exceptions, for example
146  * - if there is no property with that name
147  **/
148  virtual YPropertyValue getProperty( const std::string & propertyName );
149 
150  /**
151  * Return this class's property set.
152  * This also initializes the property set upon the first call.
153  *
154  * Reimplemented from YWidget.
155  **/
156  virtual const YPropertySet & propertySet();
157 
158  /**
159  * Returns a descriptive label of this widget instance for debugging.
160  *
161  * Reimplemented from YWidget since a YLabel doesn't have a shortcut
162  * property.
163  **/
164  virtual std::string debugLabel() const;
165 
166 private:
167 
169 };
170 
171 
172 typedef YLabel YHeading;
173 typedef YLabel YOutputField;
174 
175 
176 #endif // YLabel_h
bool isOutputField() const
Return &#39;true&#39; if this is an OutputField widget, i.e., it should display its text similar to an InputF...
Definition: YLabel.cc:91
virtual void setText(const std::string &newText)
Set the text the widget displays.
Definition: YLabel.cc:79
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YLabel.cc:133
bool useBoldFont() const
Return &#39;true&#39; if a bold font should be used.
Definition: YLabel.cc:97
Implementation of the Label, Heading and OutputField widgets.
Definition: YLabel.h:38
Transport class for the value of simple properties.
Definition: YProperty.h:104
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YLabel.cc:150
A set of properties to check names and types against.
Definition: YProperty.h:197
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
std::string text() const
Return the text the widget displays.
Definition: YLabel.cc:73
bool isHeading() const
Return &#39;true&#39; if this is a Heading widget, i.e., it should display its text in a bold and/or larger f...
Definition: YLabel.cc:85
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YLabel.cc:110
YLabel(YWidget *parent, const std::string &text, bool isHeading=false, bool isOutputField=false)
Constructor.
Definition: YLabel.cc:56
std::string value() const
Aliases for text().
Definition: YLabel.h:79
void setValue(const std::string &newValue)
Aliases for setText().
Definition: YLabel.h:93
virtual const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YLabel.cc:186
virtual void setUseBoldFont(bool bold=true)
Switch bold font on or off.
Definition: YLabel.cc:103
virtual ~YLabel()
Destructor.
Definition: YLabel.cc:67
virtual std::string debugLabel() const
Returns a descriptive label of this widget instance for debugging.
Definition: YLabel.cc:164
Abstract base class of all UI widgets.
Definition: YWidget.h:54