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