libyui-qt  2.49.2
YQRichText.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: YQRichText.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQRichText_h
27 #define YQRichText_h
28 
29 #include <QFrame>
30 #include <QTextBrowser>
31 #include <yui/YRichText.h>
32 
33 using std::string;
34 
35 
36 class YQTextBrowser;
37 
38 class YQRichText : public QFrame, public YRichText
39 {
40  Q_OBJECT
41 
42 public:
43 
44  /**
45  * Constructor.
46  **/
47  YQRichText( YWidget * parent,
48  const std::string & text,
49  bool plainTextMode = false );
50 
51  /**
52  * Destructor.
53  **/
54  virtual ~YQRichText();
55 
56  /**
57  * Change the text content of the RichText widget.
58  *
59  * Reimplemented from YRichText.
60  **/
61  virtual void setValue( const std::string & newValue );
62 
63  /**
64  * Set this RichText widget's "plain text" mode on or off.
65  *
66  * Reimplemented from YRichText.
67  **/
68  virtual void setPlainTextMode( bool on = true );
69 
70  /**
71  * Set this RichText widget's "auto scroll down" mode on or off.
72  *
73  * Reimplemented from YRichText.
74  **/
75  virtual void setAutoScrollDown( bool on = true );
76 
77  /**
78  * Preferred width of the widget.
79  *
80  * Reimplemented from YWidget.
81  **/
82  virtual int preferredWidth();
83 
84  /**
85  * Preferred height of the widget.
86  *
87  * Reimplemented from YWidget.
88  **/
89  virtual int preferredHeight();
90 
91  /**
92  * Set the new size of the widget.
93  *
94  * Reimplemented from YWidget.
95  **/
96  virtual void setSize( int newWidth, int newHeight );
97 
98  /**
99  * Set enabled/disabled state.
100  *
101  * Reimplemented from YWidget.
102  **/
103  virtual void setEnabled( bool enabled );
104 
105  /**
106  * Accept the keyboard focus.
107  *
108  * Reimplemented from YWidget.
109  **/
110  virtual bool setKeyboardFocus();
111 
112  /**
113  * Event filter.
114  *
115  * Reimplemented from QWidget.
116  **/
117  virtual bool eventFilter( QObject * obj, QEvent * ev );
118 
119  /**
120  * Returns 'true' if the current text of this RichText widget contains
121  * hyperlinks.
122  **/
123  bool haveHyperLinks();
124 
125 
126 protected slots:
127 
128  /**
129  * Notification that a hyperlink is clicked.
130  **/
131  void linkClicked( const QUrl & url );
132 
133 
134 protected:
135 
136  YQTextBrowser * _textBrowser;
137 
138 private:
139  /**
140  * to avoid big suprises, we remember if the stylesheet specified a
141  * color before we replace color= with class=
142  **/
143  bool *_colors_specified;
144 };
145 
146 
147 /**
148  * Helper class - needed to have the benefits of both QVBox as the base class
149  * for YQRichText so uniform margins can be implemented (outside, not inside
150  * the scroll window as QTextBrowser normally does it) and QTextBrowser's
151  * featurs (enable hyperlinks) without removing the text each time the user
152  * clicks.
153  *
154  * This class is required only to overwrite setSource().
155  **/
156 class YQTextBrowser: public QTextBrowser
157 {
158  Q_OBJECT
159 
160 
161 public:
162 
163  /**
164  * Constructor
165  **/
166  YQTextBrowser( QWidget * parent = 0 ):
167  QTextBrowser( parent ) {}
168 
169 public slots:
170 
171  /**
172  * Get the document pointed to by a hyperlink.
173  *
174  * Reimplemented from QTextBrowser to avoid having an empty text each time
175  * the user clicks on a hyperlink.
176  **/
177  virtual void setSource( const QUrl & name );
178 };
179 
180 
181 #endif // YQRichText_h
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQRichText.cc:215
YQRichText(YWidget *parent, const std::string &text, bool plainTextMode=false)
Constructor.
Definition: YQRichText.cc:44
virtual bool eventFilter(QObject *obj, QEvent *ev)
Event filter.
Definition: YQRichText.cc:157
bool haveHyperLinks()
Returns &#39;true&#39; if the current text of this RichText widget contains hyperlinks.
Definition: YQRichText.cc:181
YQTextBrowser(QWidget *parent=0)
Constructor.
Definition: YQRichText.h:166
virtual ~YQRichText()
Destructor.
Definition: YQRichText.cc:92
Helper class - needed to have the benefits of both QVBox as the base class for YQRichText so uniform ...
Definition: YQRichText.h:156
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQRichText.cc:202
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQRichText.cc:190
virtual void setPlainTextMode(bool on=true)
Set this RichText widget&#39;s "plain text" mode on or off.
Definition: YQRichText.cc:130
virtual void setSource(const QUrl &name)
Get the document pointed to by a hyperlink.
Definition: YQRichText.cc:222
virtual void setAutoScrollDown(bool on=true)
Set this RichText widget&#39;s "auto scroll down" mode on or off.
Definition: YQRichText.cc:141
virtual void setValue(const std::string &newValue)
Change the text content of the RichText widget.
Definition: YQRichText.cc:98
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQRichText.cc:196
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQRichText.cc:208
void linkClicked(const QUrl &url)
Notification that a hyperlink is clicked.
Definition: YQRichText.cc:150