mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Added search for Source Viewer
This commit is contained in:
parent
d070c785a0
commit
2449573c13
|
@ -95,7 +95,8 @@ SOURCES += main.cpp\
|
||||||
navigation/locationpopup.cpp \
|
navigation/locationpopup.cpp \
|
||||||
preferences/sslmanager.cpp \
|
preferences/sslmanager.cpp \
|
||||||
tools/notification.cpp \
|
tools/notification.cpp \
|
||||||
tools/htmlhighlighter.cpp
|
tools/htmlhighlighter.cpp \
|
||||||
|
other/sourceviewersearch.cpp
|
||||||
|
|
||||||
HEADERS += 3rdparty/squeezelabel.h \
|
HEADERS += 3rdparty/squeezelabel.h \
|
||||||
3rdparty/qtwin.h \
|
3rdparty/qtwin.h \
|
||||||
|
@ -153,7 +154,8 @@ HEADERS += 3rdparty/squeezelabel.h \
|
||||||
navigation/locationpopup.h \
|
navigation/locationpopup.h \
|
||||||
preferences/sslmanager.h \
|
preferences/sslmanager.h \
|
||||||
tools/notification.h \
|
tools/notification.h \
|
||||||
tools/htmlhighlighter.h
|
tools/htmlhighlighter.h \
|
||||||
|
other/sourceviewersearch.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
preferences/autofillmanager.ui \
|
preferences/autofillmanager.ui \
|
||||||
|
@ -174,7 +176,8 @@ FORMS += \
|
||||||
autofill/autofillnotification.ui \
|
autofill/autofillnotification.ui \
|
||||||
rss/rssnotification.ui \
|
rss/rssnotification.ui \
|
||||||
preferences/sslmanager.ui \
|
preferences/sslmanager.ui \
|
||||||
other/clearprivatedata.ui
|
other/clearprivatedata.ui \
|
||||||
|
other/sourceviewersearch.ui
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
data/icons.qrc \
|
data/icons.qrc \
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "sourceviewer.h"
|
#include "sourceviewer.h"
|
||||||
#include "webview.h"
|
#include "webview.h"
|
||||||
#include "htmlhighlighter.h"
|
#include "htmlhighlighter.h"
|
||||||
|
#include "sourceviewersearch.h"
|
||||||
|
|
||||||
SourceViewer::SourceViewer(QWebPage* page, QWidget* parent) :
|
SourceViewer::SourceViewer(QWebPage* page, QWidget* parent) :
|
||||||
QWidget(parent)
|
QWidget(parent)
|
||||||
|
@ -115,7 +116,14 @@ void SourceViewer::save()
|
||||||
|
|
||||||
void SourceViewer::findText()
|
void SourceViewer::findText()
|
||||||
{
|
{
|
||||||
|
if (m_layout->count() > 2) {
|
||||||
|
SourceViewerSearch* search= qobject_cast<SourceViewerSearch*>( m_layout->itemAt(1)->widget() );
|
||||||
|
search->activateLineEdit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SourceViewerSearch* search = new SourceViewerSearch(this);
|
||||||
|
m_layout->insertWidget(1, search);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SourceViewer::reload()
|
void SourceViewer::reload()
|
||||||
|
@ -142,7 +150,7 @@ void SourceViewer::setTextWordWrap()
|
||||||
|
|
||||||
void SourceViewer::goToLine()
|
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)
|
if (line == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ class SourceViewer : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SourceViewer(QWebPage* page, QWidget* parent = 0);
|
explicit SourceViewer(QWebPage* page, QWidget* parent = 0);
|
||||||
|
QTextEdit* sourceEdit() { return m_sourceEdit; }
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
110
src/other/sourceviewersearch.cpp
Normal file
110
src/other/sourceviewersearch.cpp
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
55
src/other/sourceviewersearch.h
Normal file
55
src/other/sourceviewersearch.h
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#ifndef SOURCEVIEWERSEARCH_H
|
||||||
|
#define SOURCEVIEWERSEARCH_H
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QTextDocument>
|
||||||
|
#include <QTextCursor>
|
||||||
|
|
||||||
|
#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
|
105
src/other/sourceviewersearch.ui
Normal file
105
src/other/sourceviewersearch.ui
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>SourceViewerSearch</class>
|
||||||
|
<widget class="QWidget" name="SourceViewerSearch">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>679</width>
|
||||||
|
<height>40</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>2</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="closeButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Esc</string>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Search: </string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>Search...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="previous">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="next">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="autoRaise">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user