diff options
Diffstat (limited to 'src/ui/FindWidget.cpp')
-rw-r--r-- | src/ui/FindWidget.cpp | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/src/ui/FindWidget.cpp b/src/ui/FindWidget.cpp index e6b82734..17a65ee4 100644 --- a/src/ui/FindWidget.cpp +++ b/src/ui/FindWidget.cpp @@ -31,8 +31,8 @@ namespace GpgFrontend::UI { FindWidget::FindWidget(QWidget* parent, PlainTextEditorPage* edit) - : QWidget(parent), mTextpage(edit) { - findEdit = new QLineEdit(this); + : QWidget(parent), m_text_page_(edit) { + find_edit_ = new QLineEdit(this); auto* closeButton = new QPushButton( this->style()->standardIcon(QStyle::SP_TitleBarCloseButton), QString(), this); @@ -42,127 +42,129 @@ FindWidget::FindWidget(QWidget* parent, PlainTextEditorPage* edit) auto* notificationWidgetLayout = new QHBoxLayout(this); notificationWidgetLayout->setContentsMargins(10, 0, 0, 0); notificationWidgetLayout->addWidget(new QLabel(QString(_("Find")) + ": ")); - notificationWidgetLayout->addWidget(findEdit, 2); + notificationWidgetLayout->addWidget(find_edit_, 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())); + connect(find_edit_, SIGNAL(textEdited(QString)), this, SLOT(slot_find())); + connect(find_edit_, SIGNAL(returnPressed()), this, SLOT(slot_find_next())); + connect(nextButton, SIGNAL(clicked()), this, SLOT(slot_find_next())); + connect(previousButton, SIGNAL(clicked()), this, SLOT(slot_find_previous())); + connect(closeButton, SIGNAL(clicked()), this, SLOT(slot_close())); // The timer is necessary for setting the focus - QTimer::singleShot(0, findEdit, SLOT(setFocus())); + QTimer::singleShot(0, find_edit_, SLOT(setFocus())); } -void FindWidget::setBackground() { - auto cursor = mTextpage->GetTextPage()->textCursor(); +void FindWidget::set_background() { + auto cursor = m_text_page_->GetTextPage()->textCursor(); // if match is found set background of QLineEdit to white, otherwise to red - QPalette bgPalette(findEdit->palette()); + QPalette bgPalette(find_edit_->palette()); - if (!findEdit->text().isEmpty() && - mTextpage->GetTextPage()->document()->find(findEdit->text()).position() < - 0) { + if (!find_edit_->text().isEmpty() && m_text_page_->GetTextPage() + ->document() + ->find(find_edit_->text()) + .position() < 0) { bgPalette.setColor(QPalette::Base, "#ececba"); } else { bgPalette.setColor(QPalette::Base, Qt::white); } - findEdit->setPalette(bgPalette); + find_edit_->setPalette(bgPalette); } -void FindWidget::slotFindNext() { - QTextCursor cursor = mTextpage->GetTextPage()->textCursor(); - cursor = mTextpage->GetTextPage()->document()->find( - findEdit->text(), cursor, QTextDocument::FindCaseSensitively); +void FindWidget::slot_find_next() { + QTextCursor cursor = m_text_page_->GetTextPage()->textCursor(); + cursor = m_text_page_->GetTextPage()->document()->find( + find_edit_->text(), cursor, QTextDocument::FindCaseSensitively); // if end of document is reached, restart search from beginning if (cursor.position() == -1) { - cursor = mTextpage->GetTextPage()->document()->find( - findEdit->text(), cursor, QTextDocument::FindCaseSensitively); + cursor = m_text_page_->GetTextPage()->document()->find( + find_edit_->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->GetTextPage()->setTextCursor(cursor); + m_text_page_->GetTextPage()->setTextCursor(cursor); } - this->setBackground(); + this->set_background(); } -void FindWidget::slotFind() { - QTextCursor cursor = mTextpage->GetTextPage()->textCursor(); +void FindWidget::slot_find() { + QTextCursor cursor = m_text_page_->GetTextPage()->textCursor(); if (cursor.anchor() == -1) { - cursor = mTextpage->GetTextPage()->document()->find( - findEdit->text(), cursor, QTextDocument::FindCaseSensitively); + cursor = m_text_page_->GetTextPage()->document()->find( + find_edit_->text(), cursor, QTextDocument::FindCaseSensitively); } else { - cursor = mTextpage->GetTextPage()->document()->find( - findEdit->text(), cursor.anchor(), QTextDocument::FindCaseSensitively); + cursor = m_text_page_->GetTextPage()->document()->find( + find_edit_->text(), cursor.anchor(), + QTextDocument::FindCaseSensitively); } // if end of document is reached, restart search from beginning if (cursor.position() == -1) { - cursor = mTextpage->GetTextPage()->document()->find( - findEdit->text(), cursor, QTextDocument::FindCaseSensitively); + cursor = m_text_page_->GetTextPage()->document()->find( + find_edit_->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->GetTextPage()->setTextCursor(cursor); + m_text_page_->GetTextPage()->setTextCursor(cursor); } - this->setBackground(); + this->set_background(); } -void FindWidget::slotFindPrevious() { +void FindWidget::slot_find_previous() { QTextDocument::FindFlags flags; flags |= QTextDocument::FindBackward; flags |= QTextDocument::FindCaseSensitively; - QTextCursor cursor = mTextpage->GetTextPage()->textCursor(); - cursor = mTextpage->GetTextPage()->document()->find(findEdit->text(), cursor, - flags); + QTextCursor cursor = m_text_page_->GetTextPage()->textCursor(); + cursor = m_text_page_->GetTextPage()->document()->find(find_edit_->text(), + cursor, flags); // if begin of document is reached, restart search from end if (cursor.position() == -1) { - cursor = mTextpage->GetTextPage()->document()->find( - findEdit->text(), QTextCursor::End, flags); + cursor = m_text_page_->GetTextPage()->document()->find( + find_edit_->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->GetTextPage()->setTextCursor(cursor); + m_text_page_->GetTextPage()->setTextCursor(cursor); } - this->setBackground(); + this->set_background(); } void FindWidget::keyPressEvent(QKeyEvent* e) { switch (e->key()) { case Qt::Key_Escape: - this->slotClose(); + this->slot_close(); break; case Qt::Key_F3: if (e->modifiers() & Qt::ShiftModifier) { - this->slotFindPrevious(); + this->slot_find_previous(); } else { - this->slotFindNext(); + this->slot_find_next(); } break; } } -void FindWidget::slotClose() { - QTextCursor cursor = mTextpage->GetTextPage()->textCursor(); +void FindWidget::slot_close() { + QTextCursor cursor = m_text_page_->GetTextPage()->textCursor(); if (cursor.position() == -1) { cursor.setPosition(0); - mTextpage->GetTextPage()->setTextCursor(cursor); + m_text_page_->GetTextPage()->setTextCursor(cursor); } - mTextpage->setFocus(); + m_text_page_->setFocus(); close(); } |