aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2012-09-21 22:13:53 +0000
committernils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2012-09-21 22:13:53 +0000
commited602e79103fb80af2fa8f83cf63d145895cd629 (patch)
tree868b8fa32075930d219b5662ddd1d6105a6a90f2
parentadded findwidget files (diff)
downloadgpg4usb-ed602e79103fb80af2fa8f83cf63d145895cd629.tar.gz
gpg4usb-ed602e79103fb80af2fa8f83cf63d145895cd629.zip
beautifying findwidget
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@962 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--findwidget.cpp57
-rw-r--r--findwidget.h6
2 files changed, 55 insertions, 8 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);
+*/
diff --git a/findwidget.h b/findwidget.h
index 28f0d74..3f778ec 100644
--- a/findwidget.h
+++ b/findwidget.h
@@ -22,12 +22,12 @@ public:
explicit FindWidget(QWidget *parent, QTextEdit *edit);
private:
+ void keyPressEvent( QKeyEvent* e );
+
QTextEdit *mTextpage; /** Textedit associated to the notification */
QLineEdit *findEdit; /** Label holding the text shown in verifyNotification */
- bool haveHit;
- int start;
- void keyPressEvent( QKeyEvent* e );
QTextCursor cursor;
+ QTextCharFormat cursorFormat;
private slots:
void findNext();