-
Notifications
You must be signed in to change notification settings - Fork 2
/
searchbar.cpp
77 lines (63 loc) · 2.13 KB
/
searchbar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//-------------------------------------------------
//
// Copyright (c) 2013, Malcer <malcer@gmx.com>
// Copyright (c) 2012, Aaron Lewis <the.warl0ck.1989@gmail.com>
//
// This software is distributed as free and open source software, licensed under the LGPL license.
//
//-------------------------------------------------
//
//Inspired in Lightweight2 code by Thomas Kamps :)
//
#include "searchbar.h"
#include "ui_searchbar.h"
SearchBar::SearchBar(QWidget *parent) : QWidget(parent), ui(new Ui::SearchBar) {
ui->setupUi(this);
setMaximumHeight(32);
ui->textBar->setFixedHeight(28);
connect(ui->previousButton, SIGNAL(clicked()), this, SLOT(searchPrevious()));
connect(ui->nextButton, SIGNAL(clicked()), this, SLOT(searchNext()));
connect(ui->textBar, SIGNAL(returnPressed()), this, SLOT(searchNext()));
connect(ui->doneButton, SIGNAL(clicked()), this, SLOT(done()));
}
SearchBar::~SearchBar() {
delete ui;
}
void SearchBar::setFocus() {
ui->textBar->setFocus(Qt::OtherFocusReason);
}
void SearchBar::showEvent(QShowEvent *)
{
ui->textBar->setFocus();
}
void SearchBar::searchPrevious() {
QWebPage::FindFlags flags = QWebPage::FindBackward;
if (ui->checkBox->isChecked()) flags |= QWebPage::FindCaseSensitively;
bool found = true;
emit(searchText(ui->textBar->text(), flags, &found));
if (found) {
ui->textBar->setStyleSheet("background:rgb(192,255,192); font:black;");
} else {
ui->textBar->setStyleSheet("background:rgb(255,192,192); font:black;");
}
}
void SearchBar::searchNext() {
QWebPage::FindFlags flags = 0;
if (ui->checkBox->isChecked()) flags |= QWebPage::FindCaseSensitively;
bool found = true;
emit(searchText(ui->textBar->text(), flags, &found));
if (found) {
ui->textBar->setStyleSheet("background:rgb(192,255,192); font:black;");
} else {
ui->textBar->setStyleSheet("background:rgb(255,192,192); font:black;");
}
}
void SearchBar::done() {
ui->textBar->setText("");
ui->textBar->setStyleSheet("");
ui->checkBox->setChecked(false);
hide();
}
void SearchBar::on_textBar_textChanged(const QString &arg1)
{
}