2
Copyright 2013 Christian Surlykke
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
#include "SearchBar.h"
26
SearchBar::SearchBar(QWidget *parent) : QWidget(parent)
29
connect(widget.closeButton, SIGNAL(clicked()), this, SLOT(hide()));
30
connect(widget.searchTextEdit, SIGNAL(textChanged(QString)), this, SIGNAL(searchCriteriaChanged()));
31
connect(widget.findPreviousButton, SIGNAL(clicked()), this, SIGNAL(findPrevious()));
32
connect(widget.findNextButton, SIGNAL(clicked()), this, SIGNAL(findNext()));
34
connect(this, SIGNAL(searchCriteriaChanged()), this, SLOT(clearBackgroundColor()));
36
QMenu *optionsMenu = new QMenu(widget.optionsButton);
37
widget.optionsButton->setMenu(optionsMenu);
39
m_matchCaseMenuEntry = optionsMenu->addAction(tr("Match case"));
40
m_matchCaseMenuEntry->setCheckable(true);
41
m_matchCaseMenuEntry->setChecked(true);
42
connect(m_matchCaseMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged()));
45
m_useRegularExpressionMenuEntry = optionsMenu->addAction(tr("Regular expression"));
46
m_useRegularExpressionMenuEntry->setCheckable(true);
47
connect(m_useRegularExpressionMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged()));
49
m_highlightMatchesMenuEntry = optionsMenu->addAction(tr("Higlight all matches"));
50
m_highlightMatchesMenuEntry->setCheckable(true);
51
m_highlightMatchesMenuEntry->setChecked(true);
52
connect(m_highlightMatchesMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(highlightMatchesChanged(bool)));
55
SearchBar::~SearchBar() {
58
QString SearchBar::searchText()
60
return widget.searchTextEdit->text();
64
bool SearchBar::useRegularExpression()
66
return m_useRegularExpressionMenuEntry->isChecked();
69
bool SearchBar::matchCase()
71
return m_matchCaseMenuEntry->isChecked();
74
bool SearchBar::highlightAllMatches()
76
return m_highlightMatchesMenuEntry->isChecked();
79
void SearchBar::show()
82
widget.searchTextEdit->setFocus();
85
void SearchBar::noMatchFound()
88
palette.setColor(widget.searchTextEdit->backgroundRole(), QColor(255, 128, 128));
89
widget.searchTextEdit->setPalette(palette);
93
void SearchBar::keyReleaseEvent(QKeyEvent* keyEvent)
95
if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
97
if (keyEvent->modifiers() == Qt::ShiftModifier)
106
else if (keyEvent->key() == Qt::Key_Escape)
112
void SearchBar::clearBackgroundColor()
115
p.setColor(QPalette::Base, Qt::white);
116
widget.searchTextEdit->setPalette(p);
b'\\ No newline at end of file'