libyui-qt  2.49.16
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 #ifdef TEXTDOMAIN
36 # undef TEXTDOMAIN
37 #endif
38 
39 #define TEXTDOMAIN "qt"
40 
41 
42 QY2HelpDialog::QY2HelpDialog( const QString& helpText, QWidget *parent )
43  : QDialog( parent )
44  , _searchResultForeground(Qt::black)
45  , _searchResultBackground(Qt::yellow)
46 {
47  _ui = new Ui_QHelpDialog();
48  _ui->setupUi( this );
49  _ui->textBrowser->setText( helpText );
50  Q_INIT_RESOURCE(qt_icons);
51  QIcon icon = QIcon::fromTheme( "edit-find", QIcon( ":/edit-find" ) );
52  _ui->label->setPixmap ( icon.pixmap( QSize( 16, 16 ) ) );
53  connect( _ui->lineEdit, &pclass(_ui->lineEdit)::textEdited,
54  this, &pclass(this)::searchStringChanged );
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(getSearchResultBackground());
87  fmt.setForeground(getSearchResultForeground());
88  QTextDocument *d = _ui->textBrowser->document();
89 
90  QTextCursor all(d);
91  all.select ( QTextCursor::Document);
92  all.setCharFormat( QTextCharFormat() );
93 
94  _marks.clear();
95 
96  QTextCursor c( d );
97 
98  while ( true )
99  {
100  c = d->find( text, c );
101  if ( c.isNull() )
102  break;
103  c.setCharFormat( fmt );
104  c.select( QTextCursor::WordUnderCursor );
105  _marks.push_back( c );
106  }
107 }
108 
109 void QY2HelpDialog::retranslate()
110 {
111  setWindowTitle( _( "Help" ) );
112  _ui->pushButton->setText( _( "&Close" ) );
113 }
114 
115 
116 QColor QY2HelpDialog::getSearchResultForeground()
117 {
118  return _searchResultForeground;
119 }
120 
121 void QY2HelpDialog::setSearchResultForeground( QColor pen )
122 {
123  _searchResultForeground = pen;
124 }
125 
126 QColor QY2HelpDialog::getSearchResultBackground()
127 {
128  return _searchResultBackground;
129 }
130 
131 void QY2HelpDialog::setSearchResultBackground( QColor pen )
132 {
133  _searchResultBackground = pen;
134 }
135 
136 
137 
138 
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:489