1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

[code cleanup] Moved logic of locationbar's icon into separate classes.

This commit is contained in:
nowrep 2013-02-10 12:28:53 +01:00
parent c9bcf15f9b
commit 49b1e4c43c
17 changed files with 255 additions and 125 deletions

View File

@ -1,3 +1,20 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* 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 "lineedit.h"
#include <QEvent>
@ -47,11 +64,11 @@ void LineEdit::setLeftMargin(int margin)
void LineEdit::init()
{
////we use setTextMargins() instead of padding property, and we should
//// uncomment following line or just update padding property of LineEdit's
//// subclasses in all themes and use same value for padding-left and padding-right,
//// with this new implementation padding-left and padding-right show padding from
//// edges of m_leftWidget and m_rightWidget.
// We use setTextMargins() instead of padding property, and we should
// uncomment following line or just update padding property of LineEdit's
// subclasses in all themes and use same value for padding-left and padding-right,
// with this new implementation padding-left and padding-right show padding from
// edges of m_leftWidget and m_rightWidget.
mainLayout = new QHBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
@ -183,6 +200,30 @@ void LineEdit::updateTextMargins()
// updateSideWidgetLocations();
}
void LineEdit::mouseReleaseEvent(QMouseEvent* event)
{
// Workaround issue in QLineEdit::setDragEnabled(true)
// It will incorrectly set cursor position at the end
// of selection when clicking (and not dragging) into selected text
if (!dragEnabled()) {
QLineEdit::mouseReleaseEvent(event);
return;
}
bool wasSelectedText = !selectedText().isEmpty();
QLineEdit::mouseReleaseEvent(event);
bool isSelectedText = !selectedText().isEmpty();
if (wasSelectedText && !isSelectedText) {
QMouseEvent ev(QEvent::MouseButtonPress, event->pos(), event->button(),
event->buttons(), event->modifiers());
mousePressEvent(&ev);
}
}
//void LineEdit::updateSideWidgetLocations()
//{
// QStyleOptionFrameV2 opt;

View File

@ -28,6 +28,23 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* 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 <QLineEdit>
#include "qz_namespace.h"
@ -72,6 +89,7 @@ public slots:
void updateTextMargins();
protected:
void mouseReleaseEvent(QMouseEvent* event);
// void resizeEvent(QResizeEvent* event);
bool event(QEvent* event);

View File

@ -18,13 +18,23 @@
#include "autofillicon.h"
#include "autofillwidget.h"
#include <QContextMenuEvent>
AutoFillIcon::AutoFillIcon(QWidget* parent)
: ClickableLabel(parent)
, m_view(0)
{
setObjectName("locationbar-autofillicon");
setCursor(Qt::PointingHandCursor);
setToolTip(AutoFillWidget::tr("Choose username to login"));
setFocusPolicy(Qt::ClickFocus);
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(iconClicked()));
}
void AutoFillIcon::setWebView(WebView* view)
{
m_view = view;
}
void AutoFillIcon::setFormData(const QList<AutoFillData> &data)
@ -32,7 +42,27 @@ void AutoFillIcon::setFormData(const QList<AutoFillData> &data)
m_data = data;
}
QList<AutoFillData> AutoFillIcon::formData() const
void AutoFillIcon::iconClicked()
{
return m_data;
if (!m_view) {
return;
}
AutoFillWidget* widget = new AutoFillWidget(m_view, this);
widget->setFormData(m_data);
widget->showAt(parentWidget());
}
void AutoFillIcon::contextMenuEvent(QContextMenuEvent* ev)
{
// Prevent propagating to LocationBar
ev->accept();
}
void AutoFillIcon::mousePressEvent(QMouseEvent* ev)
{
ClickableLabel::mousePressEvent(ev);
// Prevent propagating to LocationBar
ev->accept();
}

View File

@ -22,17 +22,27 @@
#include "clickablelabel.h"
#include "autofill.h"
struct AutoFillData;
class WebView;
class QT_QUPZILLA_EXPORT AutoFillIcon : public ClickableLabel
{
Q_OBJECT
public:
explicit AutoFillIcon(QWidget* parent = 0);
void setWebView(WebView* view);
void setFormData(const QList<AutoFillData> &data);
QList<AutoFillData> formData() const;
private slots:
void iconClicked();
private:
void contextMenuEvent(QContextMenuEvent* ev);
void mousePressEvent(QMouseEvent* ev);
WebView* m_view;
QList<AutoFillData> m_data;
};

View File

@ -16,10 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "bookmarkicon.h"
#include "bookmarksmodel.h"
#include "bookmarkswidget.h"
#include "mainapplication.h"
#include "tabbedwebview.h"
#include "locationbar.h"
#include "bookmarksmodel.h"
#include "pluginproxy.h"
#include "speeddial.h"
@ -30,6 +31,7 @@ BookmarkIcon::BookmarkIcon(QWidget* parent)
: ClickableLabel(parent)
, m_bookmarksModel(0)
, m_speedDial(mApp->plugins()->speedDial())
, m_view(0)
{
setObjectName("locationbar-bookmarkicon");
setCursor(Qt::PointingHandCursor);
@ -40,6 +42,12 @@ BookmarkIcon::BookmarkIcon(QWidget* parent)
connect(m_bookmarksModel, SIGNAL(bookmarkAdded(BookmarksModel::Bookmark)), this, SLOT(bookmarkAdded(BookmarksModel::Bookmark)));
connect(m_bookmarksModel, SIGNAL(bookmarkDeleted(BookmarksModel::Bookmark)), this, SLOT(bookmarkDeleted(BookmarksModel::Bookmark)));
connect(m_speedDial, SIGNAL(pagesChanged()), this, SLOT(speedDialChanged()));
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(iconClicked()));
}
void BookmarkIcon::setWebView(WebView* view)
{
m_view = view;
}
void BookmarkIcon::checkBookmark(const QUrl &url, bool forceCheck)
@ -77,6 +85,16 @@ void BookmarkIcon::speedDialChanged()
checkBookmark(m_lastUrl, true);
}
void BookmarkIcon::iconClicked()
{
if (!m_view) {
return;
}
BookmarksWidget* widget = new BookmarksWidget(m_view, parentWidget());
widget->showAt(parentWidget());
}
void BookmarkIcon::setBookmarkSaved()
{
setProperty("bookmarked", QVariant(true));

View File

@ -25,12 +25,15 @@
#include "qz_namespace.h"
class SpeedDial;
class WebView;
class QT_QUPZILLA_EXPORT BookmarkIcon : public ClickableLabel
{
Q_OBJECT
public:
explicit BookmarkIcon(QWidget* parent = 0);
void setWebView(WebView* view);
void checkBookmark(const QUrl &url, bool forceCheck = false);
private slots:
@ -38,6 +41,8 @@ private slots:
void bookmarkDeleted(const BookmarksModel::Bookmark &bookmark);
void speedDialChanged();
void iconClicked();
private:
void contextMenuEvent(QContextMenuEvent* ev);
void mousePressEvent(QMouseEvent* ev);
@ -47,6 +52,7 @@ private:
BookmarksModel* m_bookmarksModel;
SpeedDial* m_speedDial;
WebView* m_view;
QUrl m_lastUrl;

View File

@ -21,12 +21,9 @@
#include "rssmanager.h"
#include "mainapplication.h"
#include "clickablelabel.h"
#include "siteinfowidget.h"
#include "rsswidget.h"
#include "webpage.h"
#include "tabwidget.h"
#include "bookmarkicon.h"
#include "bookmarkswidget.h"
#include "progressbar.h"
#include "statusbarmessage.h"
#include "toolbutton.h"
@ -40,13 +37,13 @@
#include "qzsettings.h"
#include "colors.h"
#include "autofillicon.h"
#include "autofillwidget.h"
#include <QMimeData>
#include <QClipboard>
#include <QTimer>
#include <QContextMenuEvent>
#include <QDebug>
#include <QAction>
#include <QMenu>
LocationBar::LocationBar(QupZilla* mainClass)
: LineEdit(mainClass)
@ -65,8 +62,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
m_bookmarkIcon = new BookmarkIcon(this);
m_goIcon = new GoIcon(this);
m_rssIcon = new RssIcon(this);
m_rssIcon->setToolTip(tr("Add RSS from this page..."));
m_siteIcon = new SiteIcon(this);
m_siteIcon = new SiteIcon(p_QupZilla, this);
m_autofillIcon = new AutoFillIcon(this);
DownIcon* down = new DownIcon(this);
@ -88,11 +84,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
connect(&m_completer, SIGNAL(completionActivated()), this, SLOT(urlEnter()));
connect(this, SIGNAL(textEdited(QString)), this, SLOT(textEdit()));
connect(m_siteIcon, SIGNAL(clicked()), this, SLOT(showSiteInfo()));
connect(m_goIcon, SIGNAL(clicked(QPoint)), this, SLOT(urlEnter()));
connect(m_rssIcon, SIGNAL(clicked(QPoint)), this, SLOT(rssIconClicked()));
connect(m_bookmarkIcon, SIGNAL(clicked(QPoint)), this, SLOT(bookmarkIconClicked()));
connect(m_autofillIcon, SIGNAL(clicked(QPoint)), this, SLOT(autofillIconClicked()));
connect(down, SIGNAL(clicked(QPoint)), this, SLOT(showMostVisited()));
connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText()));
connect(mApp->searchEnginesManager(), SIGNAL(defaultEngineChanged()), this, SLOT(updatePlaceHolderText()));
@ -113,6 +105,11 @@ void LocationBar::setWebView(TabbedWebView* view)
{
m_webView = view;
m_bookmarkIcon->setWebView(m_webView);
m_rssIcon->setWebView(m_webView);
m_siteIcon->setWebView(m_webView);
m_autofillIcon->setWebView(m_webView);
connect(m_webView, SIGNAL(loadStarted()), SLOT(onLoadStarted()));
connect(m_webView, SIGNAL(loadProgress(int)), SLOT(onLoadProgress(int)));
connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(onLoadFinished()));
@ -234,37 +231,6 @@ void LocationBar::showMostVisited()
m_completer.complete(QString());
}
void LocationBar::showSiteInfo()
{
QUrl url = p_QupZilla->weView()->url();
if (url.isEmpty() || url.scheme() == QLatin1String("qupzilla")) {
return;
}
SiteInfoWidget* info = new SiteInfoWidget(p_QupZilla);
info->showAt(this);
}
void LocationBar::rssIconClicked()
{
RSSWidget* rss = new RSSWidget(m_webView, this);
rss->showAt(this);
}
void LocationBar::bookmarkIconClicked()
{
BookmarksWidget* bWidget = new BookmarksWidget(m_webView, this);
bWidget->showAt(this);
}
void LocationBar::autofillIconClicked()
{
AutoFillWidget* widget = new AutoFillWidget(m_webView, this);
widget->setFormData(m_autofillIcon->formData());
widget->showAt(this);
}
void LocationBar::showRSSIcon(bool state)
{
m_rssIcon->setVisible(state);
@ -469,24 +435,6 @@ void LocationBar::mousePressEvent(QMouseEvent* event)
LineEdit::mousePressEvent(event);
}
void LocationBar::mouseReleaseEvent(QMouseEvent* event)
{
// Workaround issue in QLineEdit::setDragEnabled
// It will incorrectly set cursor position at the end
// of selection when clicking into selected text
bool wasSelectedText = !selectedText().isEmpty();
LineEdit::mouseReleaseEvent(event);
bool isSelectedText = !selectedText().isEmpty();
if (wasSelectedText && !isSelectedText) {
QMouseEvent ev(QEvent::MouseButtonPress, event->pos(), event->button(),
event->buttons(), event->modifiers());
mousePressEvent(&ev);
}
}
void LocationBar::keyPressEvent(QKeyEvent* event)
{
switch (event->key()) {

View File

@ -57,21 +57,18 @@ public slots:
void setText(const QString &text);
protected:
virtual void paintEvent(QPaintEvent* event);
void paintEvent(QPaintEvent* event);
private slots:
void showMostVisited();
void textEdit();
void urlEnter();
void pasteAndGo();
void clearIcon();
void siteIconChanged();
void setPrivacy(bool state);
void textEdit();
void showMostVisited();
void showSiteInfo();
void rssIconClicked();
void bookmarkIconClicked();
void autofillIconClicked();
void urlEnter();
void clearIcon();
void showRSSIcon(bool state);
void pasteAndGo();
void updatePlaceHolderText();
void showCompletion(const QString &newText);
@ -95,7 +92,6 @@ private:
void focusOutEvent(QFocusEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
void mousePressEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void keyPressEvent(QKeyEvent* event);
void keyReleaseEvent(QKeyEvent* event);
void dropEvent(QDropEvent* event);

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 Franz Fellner <alpine.art.de@googlemail.com>
* Copyright (C) 2010-2013 Franz Fellner <alpine.art.de@googlemail.com>
* David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
@ -16,10 +16,10 @@
* 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 <QLayout>
#include "locationbarpopup.h"
#include <QLayout>
LocationBarPopup::LocationBarPopup(QWidget* parent)
: QFrame(parent, Qt::Popup)
, m_alignment(Qt::AlignRight)
@ -32,6 +32,11 @@ LocationBarPopup::LocationBarPopup(QWidget* parent)
void LocationBarPopup::showAt(QWidget* parent)
{
if (!parent) {
return;
}
// Calculate sizes before showing
layout()->invalidate();
layout()->activate();
@ -46,3 +51,13 @@ void LocationBarPopup::showAt(QWidget* parent)
QFrame::show();
}
void LocationBarPopup::setPopupAlignment(Qt::Alignment alignment)
{
m_alignment = alignment;
}
Qt::Alignment LocationBarPopup::popupAlignment() const
{
return m_alignment;
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 Franz Fellner <alpine.art.de@googlemail.com>
* Copyright (C) 2010-2013 Franz Fellner <alpine.art.de@googlemail.com>
* David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
@ -21,18 +21,17 @@
#include <QFrame>
class LocationBarPopup : public QFrame
#include "qz_namespace.h"
class QT_QUPZILLA_EXPORT LocationBarPopup : public QFrame
{
public:
LocationBarPopup(QWidget* parent);
void showAt(QWidget* parent);
void setPopupAlignment(Qt::Alignment alignment) {
m_alignment = alignment;
}
explicit LocationBarPopup(QWidget* parent);
Qt::Alignment popupAlignment() const {
return m_alignment;
}
void showAt(QWidget* parent);
void setPopupAlignment(Qt::Alignment alignment);
Qt::Alignment popupAlignment() const;
private:
Qt::Alignment m_alignment;

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* 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
@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "siteicon.h"
#include "siteinfowidget.h"
#include "locationbar.h"
#include "tabbedwebview.h"
#include "qztools.h"
@ -25,15 +26,40 @@
#include <QApplication>
#include <QContextMenuEvent>
SiteIcon::SiteIcon(LocationBar* parent)
SiteIcon::SiteIcon(QupZilla* window, LocationBar* parent)
: ToolButton(parent)
, p_QupZilla(window)
, m_locationBar(parent)
, m_view(0)
{
setObjectName("locationbar-siteicon");
setToolButtonStyle(Qt::ToolButtonIconOnly);
setCursor(Qt::ArrowCursor);
setToolTip(LocationBar::tr("Show information about this page"));
setFocusPolicy(Qt::ClickFocus);
connect(this, SIGNAL(clicked()), this, SLOT(iconClicked()));
}
void SiteIcon::setWebView(WebView* view)
{
m_view = view;
}
void SiteIcon::iconClicked()
{
if (!m_view || !p_QupZilla) {
return;
}
QUrl url = m_view->url();
if (url.isEmpty() || url.scheme() == QLatin1String("qupzilla")) {
return;
}
SiteInfoWidget* info = new SiteInfoWidget(p_QupZilla);
info->showAt(parentWidget());
}
void SiteIcon::contextMenuEvent(QContextMenuEvent* e)

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* 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
@ -22,18 +22,29 @@
#include "toolbutton.h"
class LocationBar;
class WebView;
class QupZilla;
class QT_QUPZILLA_EXPORT SiteIcon : public ToolButton
{
Q_OBJECT
public:
explicit SiteIcon(LocationBar* parent);
explicit SiteIcon(QupZilla* window, LocationBar* parent);
void setWebView(WebView* view);
private slots:
void iconClicked();
private:
void contextMenuEvent(QContextMenuEvent* e);
void mousePressEvent(QMouseEvent* e);
void mouseMoveEvent(QMouseEvent* e);
QupZilla* p_QupZilla;
LocationBar* m_locationBar;
WebView* m_view;
QPoint m_dragStartPosition;
};

View File

@ -387,21 +387,3 @@ void WebSearchBar::keyPressEvent(QKeyEvent* event)
LineEdit::keyPressEvent(event);
}
void WebSearchBar::mouseReleaseEvent(QMouseEvent* event)
{
// Workaround issue in QLineEdit::setDragEnabled
// It will incorrectly set cursor position at the end
// of selection when clicking into selected text
bool wasSelectedText = !selectedText().isEmpty();
LineEdit::mouseReleaseEvent(event);
bool isSelectedText = !selectedText().isEmpty();
if (wasSelectedText && !isSelectedText) {
QMouseEvent ev(QEvent::MouseButtonPress, event->pos(), event->button(),
event->buttons(), event->modifiers());
mousePressEvent(&ev);
}
}

View File

@ -76,7 +76,6 @@ private:
void focusOutEvent(QFocusEvent* e);
void dropEvent(QDropEvent* event);
void keyPressEvent(QKeyEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void completeMenuWithAvailableEngines(QMenu* menu);
void contextMenuEvent(QContextMenuEvent* event);

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* 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
@ -16,16 +16,35 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "rssicon.h"
#include "rsswidget.h"
#include <QMouseEvent>
RssIcon::RssIcon(QWidget* parent)
: ClickableLabel(parent)
, m_view(0)
{
setObjectName("locationbar-rss-icon");
setCursor(Qt::PointingHandCursor);
setFocusPolicy(Qt::ClickFocus);
setVisible(false);
setToolTip(tr("Add RSS from this page..."));
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(iconClicked()));
}
void RssIcon::setWebView(WebView* view)
{
m_view = view;
}
void RssIcon::iconClicked()
{
if (!m_view) {
return;
}
RSSWidget* rss = new RSSWidget(m_view, parentWidget());
rss->showAt(parentWidget());
}
void RssIcon::contextMenuEvent(QContextMenuEvent* ev)

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
*
* 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
@ -21,15 +21,24 @@
#include "qz_namespace.h"
#include "clickablelabel.h"
class WebView;
class QT_QUPZILLA_EXPORT RssIcon : public ClickableLabel
{
Q_OBJECT
public:
explicit RssIcon(QWidget* parent = 0);
void setWebView(WebView* view);
private slots:
void iconClicked();
private:
void contextMenuEvent(QContextMenuEvent* ev);
void mousePressEvent(QMouseEvent* ev);
WebView* m_view;
};
#endif // RSSICON_H

View File

@ -1725,10 +1725,6 @@
</context>
<context>
<name>LocationBar</name>
<message>
<source>Add RSS from this page...</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Enter URL address or search on %1</source>
<translation type="unfinished"></translation>
@ -3743,6 +3739,13 @@ Maybe relaunch with administrator right do a magic for you! ;)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RssIcon</name>
<message>
<source>Add RSS from this page...</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>SSLManager</name>
<message>