]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/pkg/YQPkgTextDialog.h
don't create QObjects in ycp thread - make timeouts work
[duncan/yast2-qt4.git] / src / pkg / YQPkgTextDialog.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQPkgTextDialog.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQPkgTextDialog_h
21 #define YQPkgTextDialog_h
22
23 #include "YQZypp.h"
24 #include <QDialog>
25 #include <QEvent>
26 #include <zypp/ResObject.h>
27
28 class QPushButton;
29 class QTextBrowser;
30
31 using std::string;
32
33
34 /**
35  * @short Dialog that shows a scrolled (HTML) text.
36  **/
37 class YQPkgTextDialog: public QDialog
38 {
39     Q_OBJECT
40
41 public:
42
43     /**
44      * Constructor.
45      *
46      * Creates a dialog with a text browser and two buttons.
47      * This does not pop up a dialog yet.
48      * Use 'exec()' (inherited from QDialog).
49      * Or, better yet, use the static confirmText() method.
50      *
51      **/
52     YQPkgTextDialog( const QString &    text,
53                      QWidget *          parent,
54                      const QString &    acceptButtonLabel,
55                      const QString &    rejectButtonLabel );
56     /**
57      * Constructor.
58      *
59      * Creates a dialog with a text browser and an "OK" button.
60      * This does not pop up a dialog yet.
61      * Use 'exec()' (inherited from QDialog).
62      * Or, better yet, use the static showText() method.
63      **/
64     YQPkgTextDialog( const QString & text, QWidget * parent );
65
66     /**
67      * Destructor.
68      **/
69     virtual ~YQPkgTextDialog();
70
71     /**
72      * Reimplemented from QWidget:
73      * Reserve a reasonable amount of space.
74      **/
75     virtual QSize sizeHint() const;
76
77     /**
78      * Show a text and wait until the user confirmed with 'OK'.
79      **/
80     static void showText( QWidget * parent, const QString & text );
81
82     /**
83      * Show a text with a headline identifying a selectable (name+summary).
84      **/
85     static void showText( QWidget *             parent,
86                           ZyppSel               selectable,
87                           const string &        text );
88
89     /**
90      * Let the user confirm a text. Returns "true" if the user clicked the
91      * accept button, false if he clicked the reject button.
92      **/
93     static bool confirmText( QWidget *  parent,
94                              const QString &    text,
95                              const QString &    acceptButtonLabel,
96                              const QString &    rejectButtonLabel );
97
98     /**
99      * Let the use confirm a text with buttons "Accept" and "Cancel".
100      * Returns "true" if the user clicked "Accept", "false" on "Cancel".
101      **/
102     static bool confirmText( QWidget * parent, const QString & text );
103     static bool confirmText( QWidget * parent, const char * text );
104
105     /**
106      * Let the use confirm a text with a headline identifying a selectable
107      * (name+summary) with buttons "Accept" and "Cancel".
108      * Returns "true" if the user clicked "Accept", "false" on "Cancel".
109      **/
110     static bool confirmText( QWidget *                  parent,
111                              ZyppSel    selectable,
112                              const string &             text );
113
114     /**
115      * Simple HTML formatting: Wrap paragraphs in <p>...</p>
116      * Paragraphs are delimited by empty lines.
117      * Return unformatted text if it contains "<!-- DT:Rich -->".
118      **/
119     static QString htmlParagraphs( const string & rawText );
120
121     /**
122      * Returns a uniform heading in HTML format.
123      **/
124     static QString htmlHeading( const QString & text );
125
126     /**
127      * Returns a uniform heading in HTML format for the specified selectable:
128      * name and summary
129      **/
130     static QString htmlHeading( ZyppSel selectable );
131
132     /**
133      * Escapes characters special to HTML in a ( plain text ) string, such as:
134      * '<'   ->   '&lt;'
135      * '>'   ->   '&gt;'
136      * '&'   ->   '&amp;'
137      *
138      * Returns the escaped string.
139      **/
140     static QString htmlEscape( const QString & plainText );
141
142
143 public slots:
144
145     /**
146      * Set the text contents.
147      **/
148     void setText( const QString & text );
149     void setText( const string & text );
150
151     /**
152      * Show a text with a headline identifying a zypp::ResObject ( name+summary ).
153      **/
154     void setText( ZyppSel selectable,
155                   const string & text );
156
157 protected:
158
159     /**
160      * Create the dialog. Called from all constructors.
161      **/
162     void buildDialog( const QString &   text,
163                       QWidget *         parent,
164                       const QString &   acceptButtonLabel,
165                       const QString &   rejectButtonLabel = "" );
166     /**
167      * Grab [Return] press events and close dialog.
168      * Inherited from QObject.
169      **/
170     bool eventFilter( QObject * obj, QEvent * ev );
171
172
173     // Data members
174
175     QPushButton *       _acceptButton;
176     QPushButton *       _rejectButton;
177     QTextBrowser *      _textBrowser;
178 };
179
180
181
182 #endif // ifndef YQPkgTextDialog_h