1 #include "searchwidget.h"
5 #include <QKeySequence>
7 SearchWidget::SearchWidget(QWidget *parent)
12 m_ui.notFoundLabel->hide();
13 m_origPalette = m_ui.lineEdit->palette();
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()),
21 connect(m_ui.lineEdit, SIGNAL(returnPressed()),
22 SLOT(slotSearchNext()));
24 m_ui.nextButton->setShortcut(
25 QKeySequence::FindNext);
26 m_ui.prevButton->setShortcut(
27 QKeySequence::FindPrevious);
29 installEventFilter(this);
32 void SearchWidget::slotSearchNext()
34 QString txt = m_ui.lineEdit->text();
36 emit searchNext(txt, caseSensitivity());
39 void SearchWidget::slotSearchPrev()
41 QString txt = m_ui.lineEdit->text();
43 emit searchPrev(txt, caseSensitivity());
46 void SearchWidget::slotCancel()
51 void SearchWidget::showEvent(QShowEvent *event)
53 return QWidget::showEvent(event);
56 Qt::CaseSensitivity SearchWidget::caseSensitivity() const
58 if (m_ui.caseSensitiveBox->isChecked())
59 return Qt::CaseSensitive;
61 return Qt::CaseInsensitive;
64 bool SearchWidget::eventFilter(QObject *object, QEvent* event)
66 if (event->type() == QEvent::KeyPress) {
67 if ((static_cast<QKeyEvent*>(event))->key() == Qt::Key_Escape) {
71 return QWidget::eventFilter(object, event);
74 void SearchWidget::setFound(bool found)
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);
83 void SearchWidget::show()
86 m_ui.lineEdit->selectAll();
87 m_ui.lineEdit->setFocus(Qt::ShortcutFocusReason);
88 m_ui.lineEdit->setPalette(m_origPalette);
91 #include "searchwidget.moc"