libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/QY2HelpDialog.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         QY2HelpDialog.cc
00020 
00021   Author:       Stephan Kulow <coolo@suse.de>
00022 
00023   Textdomain    "qt"
00024 
00025 /-*/
00026 
00027 #include "QY2HelpDialog.h"
00028 #include "ui_QHelpDialog.h"
00029 #include <QDebug>
00030 #include <QTextObject>
00031 #include "YQi18n.h"
00032 #include "YQUI.h"
00033 #include "QY2Styler.h"
00034 
00035 
00036 #include "icons/viewmag.xpm"
00037 
00038 #ifdef TEXTDOMAIN
00039 #    undef TEXTDOMAIN
00040 #endif
00041 
00042 #define TEXTDOMAIN "qt"
00043 
00044 
00045 QY2HelpDialog::QY2HelpDialog( const QString& helpText, QWidget *parent )
00046     : QDialog( parent )
00047 {
00048     _ui = new Ui_QHelpDialog();
00049     _ui->setupUi( this );
00050     _ui->textBrowser->setText( helpText );
00051 
00052     _ui->label->setPixmap ( QPixmap( viewmag ) );
00053     connect( _ui->lineEdit, SIGNAL( textEdited( QString ) ),
00054              SLOT( searchStringChanged( QString ) ) );
00055 
00056     _ui->lineEdit->setFocus( Qt::OtherFocusReason );
00057     _ui->pushButton->setAutoDefault(false);
00058 
00059     YQUI::setTextdomain( TEXTDOMAIN );
00060 
00061     // Window title for help wizard window
00062     setWindowTitle( _( "Help" ) );
00063 
00064     // Close button for wizard help window
00065     _ui->pushButton->setText( _( "&Close" ) );
00066 
00067     QY2Styler::styler()->registerWidget( this );
00068 }
00069 
00070 void QY2HelpDialog::setHelpText( const QString& helpText )
00071 {
00072     _ui->textBrowser->setText( helpText );
00073     _ui->lineEdit->setText( QString() );
00074     _ui->lineEdit->setFocus( Qt::OtherFocusReason );
00075 }
00076 
00077 QY2HelpDialog::~QY2HelpDialog()
00078 {
00079     QY2Styler::styler()->unregisterWidget( this );
00080     delete _ui;
00081 }
00082 
00083 void QY2HelpDialog::searchStringChanged( QString text )
00084 {
00085     QTextCharFormat fmt;
00086     fmt.setBackground( Qt::yellow );
00087     QTextDocument *d = _ui->textBrowser->document();
00088 
00089     QTextCursor all(d);
00090     all.select ( QTextCursor::Document);
00091     all.setCharFormat( QTextCharFormat() );
00092 
00093     _marks.clear();
00094 
00095     QTextCursor c( d );
00096 
00097     while ( true )
00098     {
00099         c = d->find( text, c );
00100         if ( c.isNull() )
00101             break;
00102         c.setCharFormat( fmt );
00103         c.select( QTextCursor::WordUnderCursor );
00104         _marks.push_back( c );
00105     }
00106 }
00107 
00108 void QY2HelpDialog::retranslate()
00109 {
00110     setWindowTitle( _( "Help" ) );
00111     _ui->pushButton->setText( _( "&Close" ) );
00112 }
00113 
00114 
00115 #include "QY2HelpDialog.moc"
 All Classes Functions Variables