source: ogBrowser-Git/qtermwidget/lib/SearchBar.cpp @ 9004d96

jenkinsmain
Last change on this file since 9004d96 was 64efc22, checked in by Vadim Troshchinskiy <vtroshchinskiy@…>, 19 months ago

Update qtermwidget to modern version

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2    Copyright 2013 Christian Surlykke
3
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.
8
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.
13
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
17    02110-1301  USA.
18*/
19#include <QMenu>
20#include <QAction>
21#include <QRegExp>
22#include <QDebug>
23
24#include "SearchBar.h"
25
26SearchBar::SearchBar(QWidget *parent) : QWidget(parent)
27{
28    widget.setupUi(this);
29    setAutoFillBackground(true); // make it always opaque, especially inside translucent windows
30    connect(widget.closeButton, &QAbstractButton::clicked, this, &SearchBar::hide);
31    connect(widget.searchTextEdit, SIGNAL(textChanged(QString)), this, SIGNAL(searchCriteriaChanged()));
32    connect(widget.findPreviousButton, SIGNAL(clicked()), this, SIGNAL(findPrevious()));
33    connect(widget.findNextButton, SIGNAL(clicked()), this, SIGNAL(findNext()));
34
35    connect(this, SIGNAL(searchCriteriaChanged()), this, SLOT(clearBackgroundColor()));
36
37    QMenu *optionsMenu = new QMenu(widget.optionsButton);
38    widget.optionsButton->setMenu(optionsMenu);
39
40    m_matchCaseMenuEntry = optionsMenu->addAction(tr("Match case"));
41    m_matchCaseMenuEntry->setCheckable(true);
42    m_matchCaseMenuEntry->setChecked(true);
43    connect(m_matchCaseMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged()));
44
45
46    m_useRegularExpressionMenuEntry = optionsMenu->addAction(tr("Regular expression"));
47    m_useRegularExpressionMenuEntry->setCheckable(true);
48    connect(m_useRegularExpressionMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged()));
49
50    m_highlightMatchesMenuEntry = optionsMenu->addAction(tr("Highlight all matches"));
51    m_highlightMatchesMenuEntry->setCheckable(true);
52    m_highlightMatchesMenuEntry->setChecked(true);
53    connect(m_highlightMatchesMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(highlightMatchesChanged(bool)));
54}
55
56SearchBar::~SearchBar() {
57}
58
59QString SearchBar::searchText()
60{
61    return widget.searchTextEdit->text();
62}
63
64
65bool SearchBar::useRegularExpression()
66{
67    return m_useRegularExpressionMenuEntry->isChecked();
68}
69
70bool SearchBar::matchCase()
71{
72    return m_matchCaseMenuEntry->isChecked();
73}
74
75bool SearchBar::highlightAllMatches()
76{
77    return m_highlightMatchesMenuEntry->isChecked();
78}
79
80void SearchBar::show()
81{
82    QWidget::show();
83    widget.searchTextEdit->setFocus();
84    widget.searchTextEdit->selectAll();
85}
86
87void SearchBar::hide()
88{
89    QWidget::hide();
90    if (QWidget *p = parentWidget())
91    {
92        p->setFocus(Qt::OtherFocusReason); // give the focus to the parent widget on hiding
93    }
94}
95
96void SearchBar::noMatchFound()
97{
98    QPalette palette;
99    palette.setColor(widget.searchTextEdit->backgroundRole(), QColor(255, 128, 128));
100    widget.searchTextEdit->setPalette(palette);
101}
102
103
104void SearchBar::keyReleaseEvent(QKeyEvent* keyEvent)
105{
106    if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter)
107    {
108        if (keyEvent->modifiers() == Qt::ShiftModifier)
109        {
110            Q_EMIT findPrevious();
111        }
112        else
113        {
114            Q_EMIT findNext();
115        }
116    }
117    else if (keyEvent->key() == Qt::Key_Escape)
118    {
119        hide();
120    }
121}
122
123void SearchBar::clearBackgroundColor()
124{
125    widget.searchTextEdit->setPalette(QWidget::window()->palette());
126
127}
Note: See TracBrowser for help on using the repository browser.