libyui-qt-pkg  2.45.28
YQPkgTextDialog.h
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: YQPkgTextDialog.h
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38 /-*/
39 
40 
41 #ifndef YQPkgTextDialog_h
42 #define YQPkgTextDialog_h
43 
44 #include "YQZypp.h"
45 #include <QDialog>
46 #include <QEvent>
47 #include <zypp/ResObject.h>
48 
49 class QPushButton;
50 class QTextBrowser;
51 
52 using std::string;
53 
54 
55 /**
56  * @short Dialog that shows a scrolled (HTML) text.
57  **/
58 class YQPkgTextDialog: public QDialog
59 {
60  Q_OBJECT
61 
62 public:
63 
64  /**
65  * Constructor.
66  *
67  * Creates a dialog with a text browser and two buttons.
68  * This does not pop up a dialog yet.
69  * Use 'exec()' (inherited from QDialog).
70  * Or, better yet, use the static confirmText() method.
71  *
72  **/
73  YQPkgTextDialog( const QString & text,
74  QWidget * parent,
75  const QString & acceptButtonLabel,
76  const QString & rejectButtonLabel );
77  /**
78  * Constructor.
79  *
80  * Creates a dialog with a text browser and an "OK" button.
81  * This does not pop up a dialog yet.
82  * Use 'exec()' (inherited from QDialog).
83  * Or, better yet, use the static showText() method.
84  **/
85  YQPkgTextDialog( const QString & text, QWidget * parent );
86 
87  /**
88  * Destructor.
89  **/
90  virtual ~YQPkgTextDialog();
91 
92  /**
93  * Reimplemented from QWidget:
94  * Reserve a reasonable amount of space.
95  **/
96  virtual QSize sizeHint() const;
97 
98  /**
99  * Show a text and wait until the user confirmed with 'OK'.
100  **/
101  static void showText( QWidget * parent, const QString & text );
102 
103  /**
104  * Show a text with a headline identifying a selectable (name+summary).
105  **/
106  static void showText( QWidget * parent,
107  ZyppSel selectable,
108  const string & text );
109 
110  /**
111  * Let the user confirm a text. Returns "true" if the user clicked the
112  * accept button, false if he clicked the reject button.
113  **/
114  static bool confirmText( QWidget * parent,
115  const QString & text,
116  const QString & acceptButtonLabel,
117  const QString & rejectButtonLabel );
118 
119  /**
120  * Let the use confirm a text with buttons "Accept" and "Cancel".
121  * Returns "true" if the user clicked "Accept", "false" on "Cancel".
122  **/
123  static bool confirmText( QWidget * parent, const QString & text );
124  static bool confirmText( QWidget * parent, const char * text );
125 
126  /**
127  * Let the use confirm a text with a headline identifying a selectable
128  * (name+summary) with buttons "Accept" and "Cancel".
129  * Returns "true" if the user clicked "Accept", "false" on "Cancel".
130  **/
131  static bool confirmText( QWidget * parent,
132  ZyppSel selectable,
133  const string & text );
134 
135  /**
136  * Simple HTML formatting: Wrap paragraphs in <p>...</p>
137  * Paragraphs are delimited by empty lines.
138  * Return unformatted text if it contains "<!-- DT:Rich -->".
139  **/
140  static QString htmlParagraphs( const string & rawText );
141 
142  /**
143  * Returns a uniform heading in HTML format.
144  **/
145  static QString htmlHeading( const QString & text );
146 
147  /**
148  * Returns a uniform heading in HTML format for the specified selectable:
149  * name and summary
150  **/
151  static QString htmlHeading( ZyppSel selectable );
152 
153  /**
154  * Escapes characters special to HTML in a ( plain text ) string, such as:
155  * '<' -> '&lt;'
156  * '>' -> '&gt;'
157  * '&' -> '&amp;'
158  *
159  * Returns the escaped string.
160  **/
161  static QString htmlEscape( const QString & plainText );
162 
163 
164 public slots:
165 
166  /**
167  * Set the text contents.
168  **/
169  void setText( const QString & text );
170  void setText( const string & text );
171 
172  /**
173  * Show a text with a headline identifying a zypp::ResObject ( name+summary ).
174  **/
175  void setText( ZyppSel selectable,
176  const string & text );
177 
178 protected:
179 
180  /**
181  * Create the dialog. Called from all constructors.
182  **/
183  void buildDialog( const QString & text,
184  QWidget * parent,
185  const QString & acceptButtonLabel,
186  const QString & rejectButtonLabel = "" );
187  /**
188  * Grab [Return] press events and close dialog.
189  * Inherited from QObject.
190  **/
191  bool eventFilter( QObject * obj, QEvent * ev );
192 
193 
194  // Data members
195 
196  QPushButton * _acceptButton;
197  QPushButton * _rejectButton;
198  QTextBrowser * _textBrowser;
199 };
200 
201 
202 
203 #endif // ifndef YQPkgTextDialog_h
virtual ~YQPkgTextDialog()
Destructor.
bool eventFilter(QObject *obj, QEvent *ev)
Grab [Return] press events and close dialog.
static bool confirmText(QWidget *parent, const QString &text, const QString &acceptButtonLabel, const QString &rejectButtonLabel)
Let the user confirm a text.
void buildDialog(const QString &text, QWidget *parent, const QString &acceptButtonLabel, const QString &rejectButtonLabel="")
Create the dialog.
static void showText(QWidget *parent, const QString &text)
Show a text and wait until the user confirmed with &#39;OK&#39;.
static QString htmlParagraphs(const string &rawText)
Simple HTML formatting: Wrap paragraphs in.
YQPkgTextDialog(const QString &text, QWidget *parent, const QString &acceptButtonLabel, const QString &rejectButtonLabel)
Constructor.
static QString htmlHeading(const QString &text)
Returns a uniform heading in HTML format.
void setText(const QString &text)
Set the text contents.
Dialog that shows a scrolled (HTML) text.
static QString htmlEscape(const QString &plainText)
Escapes characters special to HTML in a ( plain text ) string, such as: &#39;<&#39; -> &#39;<&#39; &#39;>&#39; -> &#39;>&#39; &#39;&&#39; -> ...
virtual QSize sizeHint() const
Reimplemented from QWidget: Reserve a reasonable amount of space.