2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-10-17 09:57:07 +02:00
|
|
|
* Copyright (C) 2010-2011 David Rosca
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "searchtoolbar.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "webview.h"
|
|
|
|
#include "lineedit.h"
|
2011-08-02 16:19:20 +02:00
|
|
|
#include "ui_searchtoolbar.h"
|
2011-09-30 21:44:18 +02:00
|
|
|
#include "iconprovider.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-08-02 16:19:20 +02:00
|
|
|
SearchToolBar::SearchToolBar(QupZilla* mainClass, QWidget* parent)
|
2011-09-11 19:15:06 +02:00
|
|
|
: AnimatedWidget(AnimatedWidget::Up, 300, parent)
|
2011-08-02 16:19:20 +02:00
|
|
|
, ui(new Ui::SearchToolbar)
|
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_findFlags(0)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-08-02 16:19:20 +02:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
ui->setupUi(widget());
|
2011-09-30 21:44:18 +02:00
|
|
|
ui->closeButton->setIcon(IconProvider::standardIcon(QStyle::SP_DialogCloseButton));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-09-30 21:44:18 +02:00
|
|
|
ui->next->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowForward));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-09-30 21:44:18 +02:00
|
|
|
ui->previous->setIcon(IconProvider::standardIcon(QStyle::SP_ArrowBack));
|
2011-08-02 16:19:20 +02:00
|
|
|
|
|
|
|
connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(hide()));
|
|
|
|
connect(ui->lineEdit, SIGNAL(textChanged(QString)), this, SLOT(searchText(QString)));
|
|
|
|
connect(ui->next, SIGNAL(clicked()), this, SLOT(findNext()));
|
|
|
|
connect(ui->previous, SIGNAL(clicked()), this, SLOT(findPrevious()));
|
|
|
|
connect(ui->highligh, SIGNAL(clicked()), this, SLOT(refreshFindFlags()));
|
|
|
|
connect(ui->caseSensitive, SIGNAL(clicked()), this, SLOT(refreshFindFlags()));
|
|
|
|
startAnimation();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-08-02 16:19:20 +02:00
|
|
|
QLineEdit* SearchToolBar::searchLine()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-08-02 16:19:20 +02:00
|
|
|
return ui->lineEdit;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchToolBar::findNext()
|
|
|
|
{
|
2011-08-02 16:19:20 +02:00
|
|
|
refreshFindFlags();
|
2011-03-02 16:57:41 +01:00
|
|
|
m_findFlags+=4;
|
2011-08-02 16:19:20 +02:00
|
|
|
searchText(ui->lineEdit->text());
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchToolBar::findPrevious()
|
|
|
|
{
|
2011-08-02 16:19:20 +02:00
|
|
|
refreshFindFlags();
|
2011-03-02 16:57:41 +01:00
|
|
|
m_findFlags+=5;
|
2011-08-02 16:19:20 +02:00
|
|
|
searchText(ui->lineEdit->text());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-08-02 16:19:20 +02:00
|
|
|
void SearchToolBar::refreshFindFlags()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
m_findFlags = 0;
|
2011-08-02 16:19:20 +02:00
|
|
|
if (ui->highligh->isChecked()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
m_findFlags+=8;
|
2011-08-02 16:19:20 +02:00
|
|
|
searchText(ui->lineEdit->text());
|
2011-03-02 16:57:41 +01:00
|
|
|
}else{
|
|
|
|
m_findFlags+=8;
|
|
|
|
searchText("");
|
|
|
|
m_findFlags-=8;
|
|
|
|
}
|
2011-08-02 16:19:20 +02:00
|
|
|
if (ui->caseSensitive->isChecked()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
m_findFlags+=2;
|
2011-08-02 16:19:20 +02:00
|
|
|
searchText(ui->lineEdit->text());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchToolBar::searchText(const QString &text)
|
|
|
|
{
|
|
|
|
bool found = p_QupZilla->weView()->findText(text, QFlags<QWebPage::FindFlag>(m_findFlags));
|
2011-09-11 19:15:06 +02:00
|
|
|
if (text.isEmpty())
|
|
|
|
found = true;
|
|
|
|
|
|
|
|
if (!found)
|
2011-08-02 16:19:20 +02:00
|
|
|
ui->results->setText(tr("No results found."));
|
2011-09-11 19:15:06 +02:00
|
|
|
else
|
2011-08-02 16:19:20 +02:00
|
|
|
ui->results->clear();
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
ui->lineEdit->setProperty("notfound", !found);
|
|
|
|
|
|
|
|
ui->lineEdit->style()->unpolish(ui->lineEdit);
|
|
|
|
ui->lineEdit->style()->polish(ui->lineEdit);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-08-02 16:19:20 +02:00
|
|
|
|
|
|
|
SearchToolBar::~SearchToolBar()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|