libyui-qt  2.49.2
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  , _searchResultForeground(Qt::black)
48  , _searchResultBackground(Qt::yellow)
49 {
50  _ui = new Ui_QHelpDialog();
51  _ui->setupUi( this );
52  _ui->textBrowser->setText( helpText );
53  _ui->label->setPixmap ( QPixmap( viewmag ) );
54  connect( _ui->lineEdit, &pclass(_ui->lineEdit)::textEdited,
55  this, &pclass(this)::searchStringChanged );
56 
57  _ui->lineEdit->setFocus( Qt::OtherFocusReason );
58  _ui->pushButton->setAutoDefault(false);
59 
60  YQUI::setTextdomain( TEXTDOMAIN );
61 
62  // Window title for help wizard window
63  setWindowTitle( _( "Help" ) );
64 
65  // Close button for wizard help window
66  _ui->pushButton->setText( _( "&Close" ) );
67 
68  QY2Styler::styler()->registerWidget( this );
69 }
70 
71 void QY2HelpDialog::setHelpText( const QString& helpText )
72 {
73  _ui->textBrowser->setText( helpText );
74  _ui->lineEdit->setText( QString() );
75  _ui->lineEdit->setFocus( Qt::OtherFocusReason );
76 }
77 
78 QY2HelpDialog::~QY2HelpDialog()
79 {
80  QY2Styler::styler()->unregisterWidget( this );
81  delete _ui;
82 }
83 
84 void QY2HelpDialog::searchStringChanged( QString text )
85 {
86  QTextCharFormat fmt;
87  fmt.setBackground(getSearchResultBackground());
88  fmt.setForeground(getSearchResultForeground());
89  QTextDocument *d = _ui->textBrowser->document();
90 
91  QTextCursor all(d);
92  all.select ( QTextCursor::Document);
93  all.setCharFormat( QTextCharFormat() );
94 
95  _marks.clear();
96 
97  QTextCursor c( d );
98 
99  while ( true )
100  {
101  c = d->find( text, c );
102  if ( c.isNull() )
103  break;
104  c.setCharFormat( fmt );
105  c.select( QTextCursor::WordUnderCursor );
106  _marks.push_back( c );
107  }
108 }
109 
110 void QY2HelpDialog::retranslate()
111 {
112  setWindowTitle( _( "Help" ) );
113  _ui->pushButton->setText( _( "&Close" ) );
114 }
115 
116 
117 QColor QY2HelpDialog::getSearchResultForeground()
118 {
119  return _searchResultForeground;
120 }
121 
122 void QY2HelpDialog::setSearchResultForeground( QColor pen )
123 {
124  _searchResultForeground = pen;
125 }
126 
127 QColor QY2HelpDialog::getSearchResultBackground()
128 {
129  return _searchResultBackground;
130 }
131 
132 void QY2HelpDialog::setSearchResultBackground( QColor pen )
133 {
134  _searchResultBackground = pen;
135 }
136 
137 
138 
139 #include "QY2HelpDialog.moc"
void registerWidget(QWidget *widget)
Registers a widget and applies the style sheet.
Definition: QY2Styler.cc:268
void unregisterWidget(QWidget *widget)
Unregisters a widget.
Definition: QY2Styler.cc:277
static void setTextdomain(const char *domain)
Initialize and set a textdomain for gettext()
Definition: YQUI.cc:488