diff options
| author | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2012-09-22 00:13:53 +0200 |
|---|---|---|
| committer | nils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910> | 2012-09-22 00:13:53 +0200 |
| commit | ed602e79103fb80af2fa8f83cf63d145895cd629 (patch) | |
| tree | 868b8fa32075930d219b5662ddd1d6105a6a90f2 /findwidget.cpp | |
| parent | added findwidget files (diff) | |
| download | gpg4usb-ed602e79103fb80af2fa8f83cf63d145895cd629.tar.gz gpg4usb-ed602e79103fb80af2fa8f83cf63d145895cd629.zip | |
beautifying findwidget
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@962 34ebc366-c3a9-4b3c-9f84-69acf7962910
Diffstat (limited to 'findwidget.cpp')
| -rw-r--r-- | findwidget.cpp | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/findwidget.cpp b/findwidget.cpp index 343ee5e..8f8afdf 100644 --- a/findwidget.cpp +++ b/findwidget.cpp @@ -15,27 +15,48 @@ FindWidget::FindWidget(QWidget *parent, QTextEdit *edit) : connect(findEdit,SIGNAL(textChanged(QString)),this,SLOT(find())); connect(findEdit,SIGNAL(returnPressed()),this,SLOT(findNext())); + // The timer is necessary for setting the focus QTimer::singleShot(0, findEdit, SLOT(setFocus())); - haveHit = false; + cursorFormat = cursor.charFormat(); + cursorFormat.setBackground(QBrush(Qt::yellow)); + cursor.setCharFormat(cursorFormat); + } void FindWidget::findNext() { + // set background of previous selection back to white + cursorFormat.setBackground(QBrush(Qt::white)); + cursor.setCharFormat(cursorFormat); + cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively); - qDebug() << "cursor: " << cursor.position(); - qDebug() << "anchor: " << cursor.anchor(); + // if end of document is reached, restart search from beginning + if (cursor.position() == -1) { + cursor.setPosition(0); + cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively); + } + + // set background of current selection to yellow + cursorFormat.setBackground(QBrush(Qt::yellow)); + cursor.setCharFormat(cursorFormat); } void FindWidget::find() { + // set background of previous selection back to white + cursorFormat.setBackground(QBrush(Qt::white)); + cursor.setCharFormat(cursorFormat); + if (cursor.anchor() == -1) { cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively); } else { cursor = mTextpage->document()->find(findEdit->text(), cursor.anchor(), QTextDocument::FindCaseSensitively); } - qDebug() << "cursor: " << cursor.position(); - qDebug() << "anchor: " << cursor.anchor(); + + // set background of current selection to yellow + cursorFormat.setBackground(QBrush(Qt::yellow)); + cursor.setCharFormat(cursorFormat); } void FindWidget::keyPressEvent( QKeyEvent* e ) @@ -43,6 +64,32 @@ void FindWidget::keyPressEvent( QKeyEvent* e ) switch ( e->key() ) { case Qt::Key_Escape: + mTextpage->setFocus(); this->close(); } } + +//QPalette bgPalette( findEdit->palette() ); +/* if ( start == -1 ) { + haveHit =true; + // set background of lineedit to red + bgPalette.setColor( QPalette::Base, "#ececba"); + QTextCharFormat format = cursor.charFormat(); + format.setBackground(QBrush(Qt::white)); + cursor.setCharFormat(format); + qDebug() << "cursor: " <<cursor.position(); +} else { + haveHit =true; + // set background of lineedit to white + bgPalette.setColor( QPalette::Base, QColor(Qt::white) ); + cursor.setPosition(start); + cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, findEdit->text().length()); + + qDebug() << "cursor: " <<cursor.position(); + + QTextCharFormat format = cursor.charFormat(); + format.setBackground(QBrush(Qt::yellow)); + cursor.setCharFormat(format); +} +findEdit->setPalette(bgPalette); +*/ |
