libyui-qt  2.52.2
YQRichText.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  Copyright (C) 2019 SUSE LLC
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as
6  published by the Free Software Foundation; either version 2.1 of the
7  License, or (at your option) version 3.0 of the License. This library
8  is distributed in the hope that it will be useful, but WITHOUT ANY
9  WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11  License for more details. You should have received a copy of the GNU
12  Lesser General Public License along with this library; if not, write
13  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14  Floor, Boston, MA 02110-1301 USA
15 */
16 
17 
18 /*-/
19 
20  File: YQRichText.h
21 
22  Author: Stefan Hundhammer <sh@suse.de>
23 
24 /-*/
25 
26 
27 #ifndef YQRichText_h
28 #define YQRichText_h
29 
30 #include <QFrame>
31 #include <QTextBrowser>
32 #include <yui/YRichText.h>
33 
34 using std::string;
35 
36 
37 class YQTextBrowser;
38 
39 class YQRichText : public QFrame, public YRichText
40 {
41  Q_OBJECT
42 
43 public:
44 
45  /**
46  * Constructor.
47  **/
48  YQRichText( YWidget * parent,
49  const std::string & text,
50  bool plainTextMode = false );
51 
52  /**
53  * Destructor.
54  **/
55  virtual ~YQRichText();
56 
57  /**
58  * Change the text content of the RichText widget.
59  *
60  * Reimplemented from YRichText.
61  **/
62  virtual void setValue( const std::string & newValue ) override;
63 
64  /**
65  * Set this RichText widget's "plain text" mode on or off.
66  *
67  * Reimplemented from YRichText.
68  **/
69  virtual void setPlainTextMode( bool on = true );
70 
71  /**
72  * Set this RichText widget's "auto scroll down" mode on or off.
73  *
74  * Reimplemented from YRichText.
75  **/
76  virtual void setAutoScrollDown( bool on = true );
77 
78  /**
79  * Preferred width of the widget.
80  *
81  * Reimplemented from YWidget.
82  **/
83  virtual int preferredWidth();
84 
85  /**
86  * Preferred height of the widget.
87  *
88  * Reimplemented from YWidget.
89  **/
90  virtual int preferredHeight();
91 
92  /**
93  * Set the new size of the widget.
94  *
95  * Reimplemented from YWidget.
96  **/
97  virtual void setSize( int newWidth, int newHeight );
98 
99  /**
100  * Set enabled/disabled state.
101  *
102  * Reimplemented from YWidget.
103  **/
104  virtual void setEnabled( bool enabled );
105 
106  /**
107  * Accept the keyboard focus.
108  *
109  * Reimplemented from YWidget.
110  **/
111  virtual bool setKeyboardFocus();
112 
113  /**
114  * Event filter.
115  *
116  * Reimplemented from QWidget.
117  **/
118  virtual bool eventFilter( QObject * obj, QEvent * ev );
119 
120  /**
121  * Returns 'true' if the current text of this RichText widget contains
122  * hyperlinks.
123  **/
124  bool haveHyperLinks();
125 
126  /**
127  * Get the vertical scrollbar position.
128  *
129  * Reimplemented from YRichText.
130  **/
131  virtual std::string vScrollValue() const override;
132 
133  /**
134  * Set the vertical scrollbar position.
135  *
136  * Reimplemented from YRichText.
137  **/
138  virtual void setVScrollValue( const std::string & newValue ) override;
139 
140  /**
141  * Get the horizontal scrollbar position.
142  *
143  * Reimplemented from YRichText.
144  **/
145  virtual std::string hScrollValue() const override;
146 
147  /**
148  * Set the horizontal scrollbar position.
149  *
150  * Reimplemented from YRichText.
151  **/
152  virtual void setHScrollValue( const std::string & newValue ) override;
153 
154  /**
155  * Derived classes should implement this, method is used to trigger event
156  * like user has clicked link in the RichText
157  **/
158  virtual void activateLink( const std::string & url );
159 
160 protected slots:
161 
162  /**
163  * Notification that a hyperlink is clicked.
164  **/
165  void linkClicked( const QUrl & url );
166 
167 protected:
168 
169  YQTextBrowser * _textBrowser;
170 
171 private:
172 
173  /**
174  * to avoid big suprises, we remember if the stylesheet specified a
175  * color before we replace color= with class=
176  **/
177  bool *_colors_specified;
178 
179  /**
180  * Helper function to get (vertical or horizontal) scrollbar position.
181  */
182  std::string scrollValue( QScrollBar* scrollBar ) const;
183 
184  /**
185  * Helper function to set (vertical or horizontal) scrollbar position.
186  */
187  void setScrollValue( QScrollBar* scrollBar, const std::string & newValue );
188 
189 };
190 
191 
192 /**
193  * Helper class - needed to have the benefits of both QVBox as the base class
194  * for YQRichText so uniform margins can be implemented (outside, not inside
195  * the scroll window as QTextBrowser normally does it) and QTextBrowser's
196  * featurs (enable hyperlinks) without removing the text each time the user
197  * clicks.
198  *
199  * This class is required only to overwrite setSource().
200  **/
201 class YQTextBrowser: public QTextBrowser
202 {
203  Q_OBJECT
204 
205 
206 public:
207 
208  /**
209  * Constructor
210  **/
211  YQTextBrowser( QWidget * parent = 0 )
212  : QTextBrowser( parent )
213  {}
214 
215 public slots:
216 
217  /**
218  * Get the document pointed to by a hyperlink.
219  *
220  * Reimplemented from QTextBrowser to avoid having an empty text each time
221  * the user clicks on a hyperlink.
222  **/
223  virtual void setSource( const QUrl & name );
224 };
225 
226 
227 #endif // YQRichText_h
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQRichText.cc:228
YQRichText(YWidget *parent, const std::string &text, bool plainTextMode=false)
Constructor.
Definition: YQRichText.cc:49
virtual std::string vScrollValue() const override
Get the vertical scrollbar position.
Definition: YQRichText.cc:236
virtual void setHScrollValue(const std::string &newValue) override
Set the horizontal scrollbar position.
Definition: YQRichText.cc:254
virtual void setValue(const std::string &newValue) override
Change the text content of the RichText widget.
Definition: YQRichText.cc:105
virtual bool eventFilter(QObject *obj, QEvent *ev)
Event filter.
Definition: YQRichText.cc:170
bool haveHyperLinks()
Returns &#39;true&#39; if the current text of this RichText widget contains hyperlinks.
Definition: YQRichText.cc:194
YQTextBrowser(QWidget *parent=0)
Constructor.
Definition: YQRichText.h:211
virtual ~YQRichText()
Destructor.
Definition: YQRichText.cc:99
Helper class - needed to have the benefits of both QVBox as the base class for YQRichText so uniform ...
Definition: YQRichText.h:201
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQRichText.cc:215
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQRichText.cc:203
virtual void setPlainTextMode(bool on=true)
Set this RichText widget&#39;s "plain text" mode on or off.
Definition: YQRichText.cc:137
virtual void setSource(const QUrl &name)
Get the document pointed to by a hyperlink.
Definition: YQRichText.cc:288
virtual void setAutoScrollDown(bool on=true)
Set this RichText widget&#39;s "auto scroll down" mode on or off.
Definition: YQRichText.cc:148
virtual std::string hScrollValue() const override
Get the horizontal scrollbar position.
Definition: YQRichText.cc:248
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQRichText.cc:209
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQRichText.cc:221
virtual void setVScrollValue(const std::string &newValue) override
Set the vertical scrollbar position.
Definition: YQRichText.cc:242
virtual void activateLink(const std::string &url)
Derived classes should implement this, method is used to trigger event like user has clicked link in ...
Definition: YQRichText.cc:157
void linkClicked(const QUrl &url)
Notification that a hyperlink is clicked.
Definition: YQRichText.cc:163