From dd84a84bc02c10926af265e501aa67a238bd57e3 Mon Sep 17 00:00:00 2001 From: nowrep Date: Fri, 24 Aug 2012 20:53:53 +0200 Subject: [PATCH] New option to show loading progress in address bar. - enable it in Preferences -> Tabs -> Address Bar - patch by Franz Fellner closes #236 --- src/lib/navigation/locationbar.cpp | 83 ++++++ src/lib/navigation/locationbar.h | 11 +- src/lib/other/qzsettings.cpp | 1 + src/lib/other/qzsettings.h | 1 + src/lib/preferences/preferences.cpp | 2 + src/lib/preferences/preferences.ui | 440 ++++++++++++++-------------- src/lib/webview/tabbedwebview.cpp | 4 +- src/lib/webview/tabbedwebview.h | 2 +- 8 files changed, 319 insertions(+), 225 deletions(-) diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 6d77af677..cf5f117dd 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -39,6 +39,7 @@ #include "qzsettings.h" #include +#include LocationBar::LocationBar(QupZilla* mainClass) : LineEdit(mainClass) @@ -48,6 +49,8 @@ LocationBar::LocationBar(QupZilla* mainClass) , m_pasteAndGoAction(0) , m_clearAction(0) , m_holdingAlt(false) + , m_loadProgress(0) + , m_loadFinished(true) { setObjectName("locationbar"); setDragEnabled(true); @@ -86,6 +89,14 @@ LocationBar::LocationBar(QupZilla* mainClass) updatePlaceHolderText(); } +void LocationBar::setWebView(TabbedWebView* view) +{ + m_webView = view; + + connect(m_webView, SIGNAL(loadProgress(int)), SLOT(onLoadProgress(int))); + connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(onLoadFinished())); +} + void LocationBar::setText(const QString &text) { LineEdit::setText(text); @@ -484,3 +495,75 @@ LocationBar::~LocationBar() { delete m_bookmarkIcon; } + +void LocationBar::onLoadProgress(int progress) +{ + if (qzSettings->showLoadingProgress) { + m_loadFinished = false; + m_loadProgress = progress; + repaint(); + } +} + +void LocationBar::onLoadFinished() +{ + if (qzSettings->showLoadingProgress) { + m_loadFinished = false; + QTimer::singleShot(700, this, SLOT(hideProgress())); + } +} + +void LocationBar::hideProgress() +{ + if (qzSettings->showLoadingProgress) { + m_loadFinished = true; + repaint(); + } +} + +void LocationBar::paintEvent(QPaintEvent* event) +{ + if (hasFocus() || !qzSettings->showLoadingProgress || m_loadFinished) { + LineEdit::paintEvent(event); + return; + } + + QStyleOptionFrameV3 option; + initStyleOption(&option); + + QPainter p(this); + p.setRenderHint(QPainter::Antialiasing, true); + p.setRenderHint(QPainter::TextAntialiasing, true); + + style()->drawPrimitive(QStyle::PE_PanelLineEdit, &option, &p, this); + + QRect contentsRect = style()->subElementRect(QStyle::SE_LineEditContents, &option, this); + int lm, tm, rm, bm; + getTextMargins(&lm, &tm, &rm, &bm); + contentsRect.adjust(lm, tm, -rm, -bm); + QFontMetrics fm = fontMetrics(); + const int x = contentsRect.x() + 3; + const int y = contentsRect.y() + (contentsRect.height() - fm.height() + 1) / 2; + const int width = contentsRect.width() - 6; + const int height = fm.height(); + QRect textRect(x, y, width, height); + + QColor bg = palette().color(QPalette::Base); + if (!bg.isValid() || bg.alpha() == 0) { + bg = p_QupZilla->palette().color(QPalette::Base); + } + bg = bg.darker(110); + p.setBrush(QBrush(bg)); + + QPen oldPen = p.pen(); + QPen outlinePen(bg.darker(110), 0.8); + p.setPen(outlinePen); + + QRect bar = textRect.adjusted(-3, 0, 6 - (textRect.width() * (100.0 - m_loadProgress) / 100), 0); + const int roundness = bar.height() / 4.0; + p.drawRoundedRect(bar, roundness, roundness); + + p.setPen(oldPen); +// Qt::Alignment va = QStyle::visualAlignment(QApplication::layoutDirection(), QFlag(alignment())); + p.drawText(textRect, text()); +} diff --git a/src/lib/navigation/locationbar.h b/src/lib/navigation/locationbar.h index 806a3cf17..cbcc8400f 100644 --- a/src/lib/navigation/locationbar.h +++ b/src/lib/navigation/locationbar.h @@ -45,7 +45,7 @@ public: explicit LocationBar(QupZilla* mainClass); ~LocationBar(); - void setWebView(TabbedWebView* view) { m_webView = view; } + void setWebView(TabbedWebView* view); TabbedWebView* webView() { return m_webView; } signals: @@ -55,6 +55,9 @@ public slots: void showUrl(const QUrl &url); void setText(const QString &text); +protected: + virtual void paintEvent(QPaintEvent* event); + private slots: void siteIconChanged(); void setPrivacy(bool state); @@ -70,6 +73,10 @@ private slots: void updatePlaceHolderText(); void showCompletion(const QString &newText); + void onLoadProgress(int progress); + void onLoadFinished(); + void hideProgress(); + private: void contextMenuEvent(QContextMenuEvent* event); void focusOutEvent(QFocusEvent* e); @@ -100,6 +107,8 @@ private: bool m_rssIconVisible; bool m_holdingAlt; + int m_loadProgress; + bool m_loadFinished; }; #endif // LOCATIONBAR_H diff --git a/src/lib/other/qzsettings.cpp b/src/lib/other/qzsettings.cpp index 8d193fd77..c3c8025c7 100644 --- a/src/lib/other/qzsettings.cpp +++ b/src/lib/other/qzsettings.cpp @@ -30,6 +30,7 @@ void QzSettings::loadSettings() selectAllOnDoubleClick = settings.value("SelectAllTextOnDoubleClick", true).toBool(); selectAllOnClick = settings.value("SelectAllTextOnClick", false).toBool(); addCountryWithAlt = settings.value("AddCountryDomainWithAltKey", true).toBool(); + showLoadingProgress = settings.value("ShowLoadingProgress", false).toBool(); showLocationSuggestions = settings.value("showSuggestions", 0).toInt(); settings.endGroup(); diff --git a/src/lib/other/qzsettings.h b/src/lib/other/qzsettings.h index 5b8ca49f6..4026141a9 100644 --- a/src/lib/other/qzsettings.h +++ b/src/lib/other/qzsettings.h @@ -35,6 +35,7 @@ public: bool selectAllOnDoubleClick; bool selectAllOnClick; bool addCountryWithAlt; + bool showLoadingProgress; int showLocationSuggestions; // SearchEngines diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index eb4855efb..02c48daa2 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -182,6 +182,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) ui->selectAllOnFocus->setChecked(settings.value("SelectAllTextOnDoubleClick", true).toBool()); ui->selectAllOnClick->setChecked(settings.value("SelectAllTextOnClick", false).toBool()); ui->addCountryWithAlt->setChecked(settings.value("AddCountryDomainWithAltKey", true).toBool()); + ui->showLoadingInAddressBar->setChecked(settings.value("ShowLoadingProgress", false).toBool()); settings.endGroup(); //BROWSING @@ -867,6 +868,7 @@ void Preferences::saveSettings() settings.setValue("SelectAllTextOnDoubleClick", ui->selectAllOnFocus->isChecked()); settings.setValue("SelectAllTextOnClick", ui->selectAllOnClick->isChecked()); settings.setValue("AddCountryDomainWithAltKey", ui->addCountryWithAlt->isChecked()); + settings.setValue("ShowLoadingProgress", ui->showLoadingInAddressBar->isChecked()); settings.endGroup(); //Languages diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index 48b33f8a7..178ac7484 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -602,236 +602,234 @@ - - - - - <b>Tabs behavior</b> + + + + + 0 - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Hide tabs when there is only one tab - - - - - - - Activate last tab when closing active tab - - - - - - - Open new tabs after active tab - - - - - - - Don't quit upon closing last tab - - - - - - - Ask when closing multiple tabs - - - - - - - Closed tabs list instead of opened in tab bar - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - <b>Address Bar behaviour</b> - - - - - - - Select all text by double clicking in address bar - - - - - - - Select all text by clicking in address bar - - - - - - - Add .co.uk domain by pressing ALT key - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Automatically switch to newly opened tab - - - - - - - - - Show tab previews - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - Make tab previews animated - - - - - - - - - - - Suggest when typing into address bar: - - - - - - - - 170 - 0 - - + + + Tabs behavior + + - - History and Bookmarks - + + + + + Show tab previews + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + Make tab previews animated + + + + + + + Qt::Horizontal + + + + 63 + 13 + + + + + - - History - + + + Hide tabs when there is only one tab + + - - Bookmarks - + + + Activate last tab when closing active tab + + - - Nothing - + + + Open new tabs after active tab + + - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 40 - 20 - - - - - + + + + Automatically switch to newly opened tab + + + + + + + Don't quit upon closing last tab + + + + + + + Ask when closing multiple tabs + + + + + + + Closed tabs list instead of opened in tab bar + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Address Bar behavior + + + + + + + + Suggest when typing into address bar: + + + + + + + + 170 + 0 + + + + + History and Bookmarks + + + + + History + + + + + Bookmarks + + + + + Nothing + + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + + Show loading progress in address bar + + + + + + + Select all text by double clicking in address bar + + + + + + + Select all text by clicking in address bar + + + + + + + Add .co.uk domain by pressing ALT key + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + diff --git a/src/lib/webview/tabbedwebview.cpp b/src/lib/webview/tabbedwebview.cpp index 5a726a84c..1e0cb4b78 100644 --- a/src/lib/webview/tabbedwebview.cpp +++ b/src/lib/webview/tabbedwebview.cpp @@ -49,7 +49,7 @@ TabbedWebView::TabbedWebView(QupZilla* mainClass, WebTab* webTab) , m_rssChecked(false) { connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); - connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int))); + connect(this, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished())); connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl))); @@ -128,7 +128,7 @@ void TabbedWebView::urlChanged(const QUrl &url) } } -void TabbedWebView::slotLoadProgress(int prog) +void TabbedWebView::loadProgress(int prog) { if (prog > 60) { checkRss(); diff --git a/src/lib/webview/tabbedwebview.h b/src/lib/webview/tabbedwebview.h index d0fda02ec..53a15be8f 100644 --- a/src/lib/webview/tabbedwebview.h +++ b/src/lib/webview/tabbedwebview.h @@ -63,7 +63,7 @@ public slots: void showIcon(); void slotLoadStarted(); - void slotLoadProgress(int prog); + void loadProgress(int prog); void userLoadAction(const QUrl &url);