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