libyui  3.10.0
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  * Return 'true' if automatic word wrapping is enabled.
127  **/
128  bool autoWrap() const;
129 
130  /**
131  * Enable or disable automatic word wrapping.
132  *
133  * This has implications for geometry management: An auto-wrapping label
134  * does not have any reasonable preferred size; it needs to be put into a
135  * parent widget (like a MinSize) that enforces a reasonable width. The
136  * height can be then be calculated from that width.
137  *
138  * Changing this setting takes only effect after the next layout geometry
139  * calculation.
140  *
141  * Derived classes should overwrite this, but call this base class function
142  * in the overwritten function.
143  **/
144  virtual void setAutoWrap( bool autoWrap = true );
145 
146  /**
147  * Set a property.
148  * Reimplemented from YWidget.
149  *
150  * This method may throw exceptions, for example
151  * - if there is no property with that name
152  * - if the expected type and the type mismatch
153  * - if the value is out of range
154  *
155  * This function returns 'true' if the value was successfully set and
156  * 'false' if that value requires special handling (not in error cases:
157  * those are covered by exceptions).
158  **/
159  virtual bool setProperty( const std::string & propertyName,
160  const YPropertyValue & val );
161 
162  /**
163  * Get a property.
164  * Reimplemented from YWidget.
165  *
166  * This method may throw exceptions, for example
167  * - if there is no property with that name
168  **/
169  virtual YPropertyValue getProperty( const std::string & propertyName );
170 
171  /**
172  * Return this class's property set.
173  * This also initializes the property set upon the first call.
174  *
175  * Reimplemented from YWidget.
176  **/
177  virtual const YPropertySet & propertySet();
178 
179  /**
180  * Returns a descriptive label of this widget instance for debugging.
181  *
182  * Reimplemented from YWidget since a YLabel doesn't have a shortcut
183  * property.
184  **/
185  virtual std::string debugLabel() const;
186 
187 protected:
188 
189  /**
190  * Convenience method for the parent dialog's layoutPass():
191  * Return the number of the current layout pass.
192  * 0: No layout going on right now
193  * 1: First pass
194  * 2: Second pass of a multi-pass layout
195  **/
196  int layoutPass();
197 
198 private:
199 
201 };
202 
203 
204 typedef YLabel YHeading;
205 typedef YLabel YOutputField;
206 
207 
208 #endif // YLabel_h
YWidget::parent
YWidget * parent() const
Return this widget's parent or 0 if it doesn't have a parent.
Definition: YWidget.cc:271
YLabel::useBoldFont
bool useBoldFont() const
Return 'true' if a bold font should be used.
Definition: YLabel.cc:102
YWidget
Abstract base class of all UI widgets.
Definition: YWidget.h:54
YLabel::setProperty
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YLabel.cc:169
YPropertySet
A set of properties to check names and types against.
Definition: YProperty.h:197
YLabel::~YLabel
virtual ~YLabel()
Destructor.
Definition: YLabel.cc:72
YLabel::text
std::string text() const
Return the text the widget displays.
Definition: YLabel.cc:78
YLabel::value
std::string value() const
Aliases for text().
Definition: YLabel.h:79
YLabel::layoutPass
int layoutPass()
Convenience method for the parent dialog's layoutPass(): Return the number of the current layout pass...
Definition: YLabel.cc:137
YLabel::setValue
void setValue(const std::string &newValue)
Aliases for setText().
Definition: YLabel.h:93
ImplPtr< YLabelPrivate >
YLabel::isHeading
bool isHeading() const
Return 'true' if this is a Heading widget, i.e., it should display its text in a bold and/or larger f...
Definition: YLabel.cc:90
YLabel::YLabel
YLabel(YWidget *parent, const std::string &text, bool isHeading=false, bool isOutputField=false)
Constructor.
Definition: YLabel.cc:61
YLabel::widgetClass
virtual const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YLabel.cc:222
YLabelPrivate
Definition: YLabel.cc:38
YLabel
Implementation of the Label, Heading and OutputField widgets.
Definition: YLabel.h:38
YLabel::setText
virtual void setText(const std::string &newText)
Set the text the widget displays.
Definition: YLabel.cc:84
YLabel::isOutputField
bool isOutputField() const
Return 'true' if this is an OutputField widget, i.e., it should display its text similar to an InputF...
Definition: YLabel.cc:96
YPropertyValue
Transport class for the value of simple properties.
Definition: YProperty.h:104
YLabel::debugLabel
virtual std::string debugLabel() const
Returns a descriptive label of this widget instance for debugging.
Definition: YLabel.cc:200
YLabel::setAutoWrap
virtual void setAutoWrap(bool autoWrap=true)
Enable or disable automatic word wrapping.
Definition: YLabel.cc:120
YLabel::autoWrap
bool autoWrap() const
Return 'true' if automatic word wrapping is enabled.
Definition: YLabel.cc:114
YLabel::getProperty
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YLabel.cc:186
YLabel::setUseBoldFont
virtual void setUseBoldFont(bool bold=true)
Switch bold font on or off.
Definition: YLabel.cc:108
YLabel::propertySet
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YLabel.cc:146