~verzegnassi-stefano/+junk/ubuntu-terminal-app-uitk13

« back to all changes in this revision

Viewing changes to src/plugin/qmltermwidget/qtermwidget/lib/SearchBar.cpp

  • Committer: Filippo Scognamiglio
  • Date: 2014-10-25 04:42:31 UTC
  • Revision ID: flscogna@gmail.com-20141025044231-javjhusbqa171127
Initial reboot commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
26
SearchBar::SearchBar(QWidget *parent) : QWidget(parent)
 
27
{
 
28
    widget.setupUi(this);
 
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()));
 
33
    
 
34
    connect(this, SIGNAL(searchCriteriaChanged()), this, SLOT(clearBackgroundColor()));
 
35
 
 
36
    QMenu *optionsMenu = new QMenu(widget.optionsButton);
 
37
    widget.optionsButton->setMenu(optionsMenu);
 
38
    
 
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()));
 
43
 
 
44
    
 
45
    m_useRegularExpressionMenuEntry = optionsMenu->addAction(tr("Regular expression"));
 
46
    m_useRegularExpressionMenuEntry->setCheckable(true);
 
47
    connect(m_useRegularExpressionMenuEntry, SIGNAL(toggled(bool)), this, SIGNAL(searchCriteriaChanged()));
 
48
 
 
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)));
 
53
}
 
54
 
 
55
SearchBar::~SearchBar() {
 
56
}
 
57
 
 
58
QString SearchBar::searchText()
 
59
{
 
60
    return widget.searchTextEdit->text();
 
61
}
 
62
 
 
63
 
 
64
bool SearchBar::useRegularExpression()
 
65
{
 
66
    return m_useRegularExpressionMenuEntry->isChecked();
 
67
}
 
68
 
 
69
bool SearchBar::matchCase()
 
70
{
 
71
    return m_matchCaseMenuEntry->isChecked();
 
72
}
 
73
 
 
74
bool SearchBar::highlightAllMatches()
 
75
{
 
76
    return m_highlightMatchesMenuEntry->isChecked();
 
77
}
 
78
 
 
79
void SearchBar::show()
 
80
{
 
81
    QWidget::show();
 
82
    widget.searchTextEdit->setFocus();
 
83
}
 
84
 
 
85
void SearchBar::noMatchFound()
 
86
{
 
87
    QPalette palette;
 
88
    palette.setColor(widget.searchTextEdit->backgroundRole(), QColor(255, 128, 128));
 
89
    widget.searchTextEdit->setPalette(palette);
 
90
}
 
91
 
 
92
 
 
93
void SearchBar::keyReleaseEvent(QKeyEvent* keyEvent)
 
94
{
 
95
    if (keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) 
 
96
    {
 
97
        if (keyEvent->modifiers() == Qt::ShiftModifier)
 
98
        {
 
99
            findPrevious();
 
100
        }
 
101
        else 
 
102
        {
 
103
            findNext();
 
104
        }
 
105
    }
 
106
    else if (keyEvent->key() == Qt::Key_Escape)
 
107
    {
 
108
        hide(); 
 
109
    }
 
110
}
 
111
 
 
112
void SearchBar::clearBackgroundColor()
 
113
{
 
114
    QPalette p;
 
115
    p.setColor(QPalette::Base, Qt::white);
 
116
    widget.searchTextEdit->setPalette(p);
 
117
 
 
118
}
 
 
b'\\ No newline at end of file'