libyui-qt  2.43.5
 All Classes Functions Variables
QY2HelpDialog.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: QY2HelpDialog.cc
20 
21  Author: Stephan Kulow <coolo@suse.de>
22 
23  Textdomain "qt"
24 
25 /-*/
26 
27 #include "QY2HelpDialog.h"
28 #include "ui_QHelpDialog.h"
29 #include <QDebug>
30 #include <QTextObject>
31 #include "YQi18n.h"
32 #include "YQUI.h"
33 #include "QY2Styler.h"
34 
35 
36 #include "icons/viewmag.xpm"
37 
38 #ifdef TEXTDOMAIN
39 # undef TEXTDOMAIN
40 #endif
41 
42 #define TEXTDOMAIN "qt"
43 
44 
45 QY2HelpDialog::QY2HelpDialog( const QString& helpText, QWidget *parent )
46  : QDialog( parent )
47 {
48  _ui = new Ui_QHelpDialog();
49  _ui->setupUi( this );
50  _ui->textBrowser->setText( helpText );
51 
52  _ui->label->setPixmap ( QPixmap( viewmag ) );
53  connect( _ui->lineEdit, SIGNAL( textEdited( QString ) ),
54  SLOT( searchStringChanged( QString ) ) );
55 
56  _ui->lineEdit->setFocus( Qt::OtherFocusReason );
57  _ui->pushButton->setAutoDefault(false);
58 
59  YQUI::setTextdomain( TEXTDOMAIN );
60 
61  // Window title for help wizard window
62  setWindowTitle( _( "Help" ) );
63 
64  // Close button for wizard help window
65  _ui->pushButton->setText( _( "&Close" ) );
66 
67  QY2Styler::styler()->registerWidget( this );
68 }
69 
70 void QY2HelpDialog::setHelpText( const QString& helpText )
71 {
72  _ui->textBrowser->setText( helpText );
73  _ui->lineEdit->setText( QString() );
74  _ui->lineEdit->setFocus( Qt::OtherFocusReason );
75 }
76 
77 QY2HelpDialog::~QY2HelpDialog()
78 {
79  QY2Styler::styler()->unregisterWidget( this );
80  delete _ui;
81 }
82 
83 void QY2HelpDialog::searchStringChanged( QString text )
84 {
85  QTextCharFormat fmt;
86  fmt.setBackground( Qt::yellow );
87  QTextDocument *d = _ui->textBrowser->document();
88 
89  QTextCursor all(d);
90  all.select ( QTextCursor::Document);
91  all.setCharFormat( QTextCharFormat() );
92 
93  _marks.clear();
94 
95  QTextCursor c( d );
96 
97  while ( true )
98  {
99  c = d->find( text, c );
100  if ( c.isNull() )
101  break;
102  c.setCharFormat( fmt );
103  c.select( QTextCursor::WordUnderCursor );
104  _marks.push_back( c );
105  }
106 }
107 
108 void QY2HelpDialog::retranslate()
109 {
110  setWindowTitle( _( "Help" ) );
111  _ui->pushButton->setText( _( "&Close" ) );
112 }
113 
114 
115 #include "QY2HelpDialog.moc"
static void setTextdomain(const char *domain)
Definition: YQUI.cc:496