diff --git a/src/QupZilla.pro b/src/QupZilla.pro index 3ec53e36c..c66570206 100644 --- a/src/QupZilla.pro +++ b/src/QupZilla.pro @@ -95,7 +95,8 @@ SOURCES += main.cpp\ navigation/locationpopup.cpp \ preferences/sslmanager.cpp \ tools/notification.cpp \ - tools/htmlhighlighter.cpp + tools/htmlhighlighter.cpp \ + other/sourceviewersearch.cpp HEADERS += 3rdparty/squeezelabel.h \ 3rdparty/qtwin.h \ @@ -153,7 +154,8 @@ HEADERS += 3rdparty/squeezelabel.h \ navigation/locationpopup.h \ preferences/sslmanager.h \ tools/notification.h \ - tools/htmlhighlighter.h + tools/htmlhighlighter.h \ + other/sourceviewersearch.h FORMS += \ preferences/autofillmanager.ui \ @@ -174,7 +176,8 @@ FORMS += \ autofill/autofillnotification.ui \ rss/rssnotification.ui \ preferences/sslmanager.ui \ - other/clearprivatedata.ui + other/clearprivatedata.ui \ + other/sourceviewersearch.ui RESOURCES += \ data/icons.qrc \ diff --git a/src/other/sourceviewer.cpp b/src/other/sourceviewer.cpp index ef39e0869..81a96d050 100644 --- a/src/other/sourceviewer.cpp +++ b/src/other/sourceviewer.cpp @@ -18,6 +18,7 @@ #include "sourceviewer.h" #include "webview.h" #include "htmlhighlighter.h" +#include "sourceviewersearch.h" SourceViewer::SourceViewer(QWebPage* page, QWidget* parent) : QWidget(parent) @@ -115,7 +116,14 @@ void SourceViewer::save() void SourceViewer::findText() { + if (m_layout->count() > 2) { + SourceViewerSearch* search= qobject_cast( m_layout->itemAt(1)->widget() ); + search->activateLineEdit(); + return; + } + SourceViewerSearch* search = new SourceViewerSearch(this); + m_layout->insertWidget(1, search); } void SourceViewer::reload() @@ -142,7 +150,7 @@ void SourceViewer::setTextWordWrap() void SourceViewer::goToLine() { - int line = QInputDialog::getInt(this, tr("Go to Line..."), tr("Enter line number")); + int line = QInputDialog::getInt(this, tr("Go to Line..."), tr("Enter line number"), 0, 1, 5000); if (line == 0) return; diff --git a/src/other/sourceviewer.h b/src/other/sourceviewer.h index 93c58ffb1..613760413 100644 --- a/src/other/sourceviewer.h +++ b/src/other/sourceviewer.h @@ -39,7 +39,7 @@ class SourceViewer : public QWidget Q_OBJECT public: explicit SourceViewer(QWebPage* page, QWidget* parent = 0); - + QTextEdit* sourceEdit() { return m_sourceEdit; } signals: public slots: diff --git a/src/other/sourceviewersearch.cpp b/src/other/sourceviewersearch.cpp new file mode 100644 index 000000000..f31a6696d --- /dev/null +++ b/src/other/sourceviewersearch.cpp @@ -0,0 +1,110 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2011 nowrep +* +* 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 . +* ============================================================ */ +#include "sourceviewersearch.h" +#include "ui_sourceviewersearch.h" +#include "sourceviewer.h" + +SourceViewerSearch::SourceViewerSearch(SourceViewer* parent) : + Notification((QWidget*)parent) + ,m_sourceViewer(parent) + ,ui(new Ui::SourceViewerSearch) +{ + setAttribute(Qt::WA_DeleteOnClose); + ui->setupUi(this); + ui->closeButton->setIcon( +#ifdef Q_WS_X11 + style()->standardIcon(QStyle::SP_DialogCloseButton) +#else + QIcon(":/icons/faenza/close.png") +#endif + ); + + ui->next->setIcon( +#ifdef Q_WS_X11 + style()->standardIcon(QStyle::SP_ArrowForward) +#else + QIcon(":/icons/faenza/forward.png") +#endif + ); + + ui->previous->setIcon( +#ifdef Q_WS_X11 + style()->standardIcon(QStyle::SP_ArrowBack) +#else + QIcon(":/icons/faenza/back.png") +#endif + ); + ui->lineEdit->setFocus(); + startAnimation(); + connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(hide())); + connect(ui->lineEdit, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(next())); + connect(ui->next, SIGNAL(clicked()), this, SLOT(next())); + connect(ui->previous, SIGNAL(clicked()), this, SLOT(previous())); +} + +void SourceViewerSearch::activateLineEdit() +{ + ui->lineEdit->setFocus(); +} + +void SourceViewerSearch::next() +{ + if (!find(0)) { + ui->lineEdit->setStyleSheet("QLineEdit {background:#ff6666;; }"); + m_sourceViewer->sourceEdit()->moveCursor(QTextCursor::Start); + } else { + ui->lineEdit->setStyleSheet(""); + } +} + +void SourceViewerSearch::previous() +{ + if (!find(QTextDocument::FindBackward)) { + ui->lineEdit->setStyleSheet("QLineEdit {background:#ff6666;; }"); + m_sourceViewer->sourceEdit()->moveCursor(QTextCursor::Start); + } else { + ui->lineEdit->setStyleSheet(""); + } +} + +bool SourceViewerSearch::find(QTextDocument::FindFlags flags) +{ + QString string = ui->lineEdit->text(); + if (string.isEmpty()) + return true; + if (string != m_lastSearchedString) { + QTextCursor cursor = m_sourceViewer->sourceEdit()->textCursor(); + cursor.setPosition(cursor.selectionStart()); + cursor.clearSelection(); + m_sourceViewer->sourceEdit()->setTextCursor(cursor); + m_lastSearchedString = string; + } + + if (!m_sourceViewer->sourceEdit()->find(string, flags)) { + QTextCursor cursor = m_sourceViewer->sourceEdit()->textCursor(); + m_sourceViewer->sourceEdit()->moveCursor(QTextCursor::Start); + if (!m_sourceViewer->sourceEdit()->find(string,flags)) { + cursor.clearSelection(); + m_sourceViewer->sourceEdit()->setTextCursor(cursor); + return false; + } + } + return true; +} + + diff --git a/src/other/sourceviewersearch.h b/src/other/sourceviewersearch.h new file mode 100644 index 000000000..08e90662e --- /dev/null +++ b/src/other/sourceviewersearch.h @@ -0,0 +1,55 @@ +/* ============================================================ +* QupZilla - WebKit based browser +* Copyright (C) 2010-2011 nowrep +* +* 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 . +* ============================================================ */ +#ifndef SOURCEVIEWERSEARCH_H +#define SOURCEVIEWERSEARCH_H +#include +#include +#include + +#include "notification.h" + +namespace Ui { + class SourceViewerSearch; +} + +class SourceViewer; +class SourceViewerSearch : public Notification +{ + Q_OBJECT +public: + explicit SourceViewerSearch(SourceViewer* parent = 0); + + void activateLineEdit(); + +signals: + +public slots: + +private slots: + void next(); + void previous(); + bool find(QTextDocument::FindFlags flags); + +private: + SourceViewer* m_sourceViewer; + Ui::SourceViewerSearch* ui; + + QString m_lastSearchedString; +}; + +#endif // SOURCEVIEWERSEARCH_H diff --git a/src/other/sourceviewersearch.ui b/src/other/sourceviewersearch.ui new file mode 100644 index 000000000..f5113b730 --- /dev/null +++ b/src/other/sourceviewersearch.ui @@ -0,0 +1,105 @@ + + + SourceViewerSearch + + + + 0 + 0 + 679 + 40 + + + + + 2 + + + 4 + + + 4 + + + + + + 0 + 0 + + + + + + + Esc + + + true + + + + + + + Search: + + + + + + + Search... + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + +