42 #define YUILogComponent "qt-pkg" 46 #include <QTextBrowser> 47 #include <QPushButton> 50 #include <QHBoxLayout> 54 #include <QApplication> 56 #include "YQPkgTextDialog.h" 58 #include "QY2LayoutUtils.h" 62 #define SPACING 6 // between subwidgets 63 #define MARGIN 4 // around the widget 77 const QString & acceptButtonLabel,
78 const QString & rejectButtonLabel )
81 buildDialog( text, parent, acceptButtonLabel, rejectButtonLabel );
93 const QString & acceptButtonLabel,
94 const QString & rejectButtonLabel )
97 setSizeGripEnabled(
true );
100 setWindowTitle( _(
"YaST" ) );
104 QVBoxLayout * layout =
new QVBoxLayout();
105 Q_CHECK_PTR( layout );
107 layout->setMargin ( MARGIN );
108 layout->setSpacing( SPACING );
112 _textBrowser =
new QTextBrowser(
this );
113 Q_CHECK_PTR( _textBrowser );
114 layout->addWidget( _textBrowser );
115 layout->addSpacing( 2 );
116 _textBrowser->document()->setHtml( text );
117 _textBrowser->scrollToAnchor(
"top" );
118 _textBrowser->installEventFilter(
this );
123 QHBoxLayout * buttonBox =
new QHBoxLayout();
124 Q_CHECK_PTR( buttonBox );
125 buttonBox->setSpacing( SPACING );
126 buttonBox->setMargin ( MARGIN );
127 layout->addLayout( buttonBox );
128 buttonBox->addStretch();
132 _acceptButton =
new QPushButton( acceptButtonLabel,
this );
133 buttonBox->addWidget(_acceptButton);
134 Q_CHECK_PTR( _acceptButton );
135 _acceptButton->setDefault(
true );
137 connect( _acceptButton, SIGNAL( clicked() ),
138 this, SLOT ( accept() ) );
140 buttonBox->addStretch();
142 if ( ! rejectButtonLabel.isEmpty() )
146 _rejectButton =
new QPushButton( rejectButtonLabel,
this );
147 buttonBox->addWidget(_rejectButton);
148 Q_CHECK_PTR( _rejectButton );
149 _rejectButton->setDefault(
true );
151 connect( _rejectButton, SIGNAL( clicked() ),
152 this, SLOT ( reject() ) );
154 buttonBox->addStretch();
168 return limitToScreenSize(
this, 500, 450 );
175 if ( ev && ev->type() == QEvent::KeyPress )
177 QKeyEvent * keyEvent =
dynamic_cast<QKeyEvent *
> (ev);
181 if ( keyEvent->key() == Qt::Key_Return ||
182 keyEvent->key() == Qt::Key_Enter )
184 _acceptButton->animateClick();
187 else if ( keyEvent->key() == Qt::Key_Escape )
191 _rejectButton->animateClick();
204 _textBrowser->document()->setHtml( text );
215 const string & text )
232 const string & text )
239 const QString & text,
240 const QString & acceptButtonLabel,
241 const QString & rejectButtonLabel )
248 bool confirmed = ( dia->exec() == QDialog::Accepted );
258 return confirmText( parent, text, _(
"&Accept" ), _(
"&Cancel" ) );
270 const string & text )
282 QString html = plainText;
285 html.replace( QRegExp(
"&" ),
"&" );
286 html.replace( QRegExp(
"<" ),
"<" );
287 html.replace( QRegExp(
">" ),
">" );
297 QString text = fromUTF8( rawText );
299 if ( text.contains(
"<!-- DT:Rich -->" ) )
303 text.replace(
"\n\n",
"</p><p>" );
304 text.prepend(
"<p>" );
305 text.append (
"</p>" );
318 +
"</b></td></tr></table><br>";
330 ZyppObj zyppObj = selectable->theObj();
335 QString summary = fromUTF8( zyppObj->summary() );
339 + fromUTF8( zyppObj->name() )
342 if ( ! summary.isEmpty() )
343 html +=
" - " + summary;
345 html +=
"</td></tr></table><br>";
353 #include "YQPkgTextDialog.moc" 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 'OK'.
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: '<' -> '<' '>' -> '>' '&' -> ...
virtual QSize sizeHint() const
Reimplemented from QWidget: Reserve a reasonable amount of space.