diff options
author | Nils Achtergarde <[email protected]> | 2018-01-04 21:39:25 +0000 |
---|---|---|
committer | Nils Achtergarde <[email protected]> | 2018-01-04 21:39:25 +0000 |
commit | b36dc4d79f446ae69aeb85137663a4e0ca23eba2 (patch) | |
tree | 23d0ae5e94e874064143735c249a2ad2cb95ad16 /findwidget.cpp | |
parent | added .gitignore with mocfiles-dir and objectfiles-dir (diff) | |
download | gpg4usb-b36dc4d79f446ae69aeb85137663a4e0ca23eba2.tar.gz gpg4usb-b36dc4d79f446ae69aeb85137663a4e0ca23eba2.zip |
put *.h and *.cpp to src-subdirectory
Diffstat (limited to 'findwidget.cpp')
-rw-r--r-- | findwidget.cpp | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/findwidget.cpp b/findwidget.cpp deleted file mode 100644 index ff8de5a..0000000 --- a/findwidget.cpp +++ /dev/null @@ -1,135 +0,0 @@ - -#include "findwidget.h" - -FindWidget::FindWidget(QWidget *parent, QTextEdit *edit) : - QWidget(parent) -{ - mTextpage = edit; - findEdit = new QLineEdit(this); - QPushButton *closeButton= new QPushButton(this->style()->standardIcon(QStyle::SP_TitleBarCloseButton),"",this); - QPushButton *nextButton= new QPushButton(QIcon(":button_next.png"), ""); - QPushButton *previousButton= new QPushButton(QIcon(":button_previous.png"), ""); - - QHBoxLayout *notificationWidgetLayout = new QHBoxLayout(this); - notificationWidgetLayout->setContentsMargins(10,0,0,0); - notificationWidgetLayout->addWidget(new QLabel(tr("Find:"))); - notificationWidgetLayout->addWidget(findEdit,2); - notificationWidgetLayout->addWidget(nextButton); - notificationWidgetLayout->addWidget(previousButton); - notificationWidgetLayout->addWidget(closeButton); - - this->setLayout(notificationWidgetLayout); - connect(findEdit,SIGNAL(textEdited(QString)),this,SLOT(slotFind())); - connect(findEdit,SIGNAL(returnPressed()),this,SLOT(slotFindNext())); - connect(nextButton,SIGNAL(clicked()),this,SLOT(slotFindNext())); - connect(previousButton,SIGNAL(clicked()),this,SLOT(slotFindPrevious())); - connect(closeButton,SIGNAL(clicked()),this,SLOT(slotClose())); - - // The timer is necessary for setting the focus - QTimer::singleShot(0, findEdit, SLOT(setFocus())); -} - -void FindWidget::setBackground() -{ - QTextCursor cursor = mTextpage->textCursor(); - // if match is found set background of QLineEdit to white, otherwise to red - QPalette bgPalette( findEdit->palette() ); - - if (!findEdit->text().isEmpty() && mTextpage->document()->find(findEdit->text()).position() < 0 ) { - bgPalette.setColor( QPalette::Base, "#ececba"); - } else { - bgPalette.setColor( QPalette::Base, Qt::white); - } - findEdit->setPalette(bgPalette); -} - -void FindWidget::slotFindNext() -{ - QTextCursor cursor = mTextpage->textCursor(); - cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively); - - // if end of document is reached, restart search from beginning - if (cursor.position() == -1) { - cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively); - } - - // cursor should not stay at -1, otherwise text is not editable - // todo: check how gedit handles this - if(cursor.position() != -1) { - mTextpage->setTextCursor(cursor); - } - this->setBackground(); -} - -void FindWidget::slotFind() -{ - QTextCursor cursor = mTextpage->textCursor(); - - if (cursor.anchor() == -1) { - cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively); - } else { - cursor = mTextpage->document()->find(findEdit->text(), cursor.anchor(), QTextDocument::FindCaseSensitively); - } - - // if end of document is reached, restart search from beginning - if (cursor.position() == -1) { - cursor = mTextpage->document()->find(findEdit->text(), cursor, QTextDocument::FindCaseSensitively); - } - - // cursor should not stay at -1, otherwise text is not editable - // todo: check how gedit handles this - if(cursor.position() != -1) { - mTextpage->setTextCursor(cursor); - } - this->setBackground(); -} - -void FindWidget::slotFindPrevious() -{ - QTextDocument::FindFlags flags; - flags |= QTextDocument::FindBackward; - flags |= QTextDocument::FindCaseSensitively; - - QTextCursor cursor = mTextpage->textCursor(); - cursor = mTextpage->document()->find(findEdit->text(), cursor, flags); - - // if begin of document is reached, restart search from end - if (cursor.position() == -1) { - cursor = mTextpage->document()->find(findEdit->text(), QTextCursor::End, flags); - } - - // cursor should not stay at -1, otherwise text is not editable - // todo: check how gedit handles this - if(cursor.position() != -1) { - mTextpage->setTextCursor(cursor); - } - this->setBackground(); -} - -void FindWidget::keyPressEvent( QKeyEvent* e ) -{ - switch ( e->key() ) - { - case Qt::Key_Escape: - this->slotClose(); - break; - case Qt::Key_F3: - if (e->modifiers() & Qt::ShiftModifier) { - this->slotFindPrevious(); - } else { - this->slotFindNext(); - } - break; - } -} - -void FindWidget::slotClose() { - QTextCursor cursor = mTextpage->textCursor(); - - if ( cursor.position() == -1) { - cursor.setPosition(0); - mTextpage->setTextCursor(cursor); - } - mTextpage->setFocus(); - close(); -} |