]> git.cworth.org Git - apitrace/blob - gui/searchwidget.cpp
qapitrace: Determine binary dir in run-time.
[apitrace] / gui / searchwidget.cpp
1 #include "searchwidget.h"
2
3 #include <QDebug>
4 #include <QKeyEvent>
5 #include <QKeySequence>
6
7 SearchWidget::SearchWidget(QWidget *parent)
8     : QWidget(parent)
9 {
10     m_ui.setupUi(this);
11
12     m_ui.notFoundLabel->hide();
13     m_origPalette = m_ui.lineEdit->palette();
14
15     connect(m_ui.nextButton, SIGNAL(clicked()),
16             SLOT(slotSearchNext()));
17     connect(m_ui.prevButton, SIGNAL(clicked()),
18             SLOT(slotSearchPrev()));
19     connect(m_ui.closeButton, SIGNAL(clicked()),
20             SLOT(slotCancel()));
21     connect(m_ui.lineEdit, SIGNAL(returnPressed()),
22             SLOT(slotSearchNext()));
23
24     m_ui.nextButton->setShortcut(
25         QKeySequence::FindNext);
26     m_ui.prevButton->setShortcut(
27         QKeySequence::FindPrevious);
28
29     installEventFilter(this);
30 }
31
32 void SearchWidget::slotSearchNext()
33 {
34     QString txt = m_ui.lineEdit->text();
35     if (!txt.isEmpty())
36         emit searchNext(txt, caseSensitivity());
37 }
38
39 void SearchWidget::slotSearchPrev()
40 {
41     QString txt = m_ui.lineEdit->text();
42     if (!txt.isEmpty())
43         emit searchPrev(txt, caseSensitivity());
44 }
45
46 void SearchWidget::slotCancel()
47 {
48     hide();
49 }
50
51 void SearchWidget::showEvent(QShowEvent *event)
52 {
53     return QWidget::showEvent(event);
54 }
55
56 Qt::CaseSensitivity SearchWidget::caseSensitivity() const
57 {
58     if (m_ui.caseSensitiveBox->isChecked())
59         return Qt::CaseSensitive;
60     else
61         return Qt::CaseInsensitive;
62 }
63
64 bool SearchWidget::eventFilter(QObject *object, QEvent* event)
65 {
66     if (event->type() == QEvent::KeyPress) {
67         if ((static_cast<QKeyEvent*>(event))->key() == Qt::Key_Escape) {
68             hide();
69         }
70     }
71     return QWidget::eventFilter(object, event);
72 }
73
74 void SearchWidget::setFound(bool found)
75 {
76     QPalette pal = m_origPalette;
77     pal.setColor(QPalette::Active, QPalette::Base,
78                  found ? Qt::white : QColor(255, 102, 102));
79     m_ui.lineEdit->setPalette(pal);
80     m_ui.notFoundLabel->setVisible(!found);
81 }
82
83 void SearchWidget::show()
84 {
85     QWidget::show();
86     m_ui.lineEdit->selectAll();
87     m_ui.lineEdit->setFocus(Qt::ShortcutFocusReason);
88     m_ui.lineEdit->setPalette(m_origPalette);
89 }
90
91 #include "searchwidget.moc"