From 85daf062d479794c056122f1c67d10e01a54337d Mon Sep 17 00:00:00 2001 From: nowrep Date: Mon, 9 May 2011 17:58:19 +0200 Subject: [PATCH] Added StatusBarMessage class which handles and shows those messages on a tooltip in left bottom corner of webview if statusbar is hidden --- src/QupZilla.pro | 6 ++- src/app/qupzilla.cpp | 2 + src/app/qupzilla.h | 9 +++-- src/navigation/locationbar.cpp | 9 +++-- src/other/statusbarmessage.cpp | 65 +++++++++++++++++++++++++++++++++ src/other/statusbarmessage.h | 27 ++++++++++++++ src/preferences/preferences.cpp | 5 +++ src/webview/webview.cpp | 10 ++--- 8 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 src/other/statusbarmessage.cpp create mode 100644 src/other/statusbarmessage.h diff --git a/src/QupZilla.pro b/src/QupZilla.pro index 0edeee463..d9c706ad3 100644 --- a/src/QupZilla.pro +++ b/src/QupZilla.pro @@ -117,7 +117,8 @@ SOURCES += main.cpp\ tools/progressbar.cpp \ tools/iconprovider.cpp \ network/networkproxyfactory.cpp \ - tools/closedtabsmanager.cpp + tools/closedtabsmanager.cpp \ + other/statusbarmessage.cpp HEADERS += 3rdparty/squeezelabel.h \ 3rdparty/qtwin.h \ @@ -194,7 +195,8 @@ HEADERS += 3rdparty/squeezelabel.h \ tools/progressbar.h \ tools/iconprovider.h \ network/networkproxyfactory.h \ - tools/closedtabsmanager.h + tools/closedtabsmanager.h \ + other/statusbarmessage.h FORMS += \ preferences/autofillmanager.ui \ diff --git a/src/app/qupzilla.cpp b/src/app/qupzilla.cpp index f6678d58d..54fc8ed37 100644 --- a/src/app/qupzilla.cpp +++ b/src/app/qupzilla.cpp @@ -52,6 +52,7 @@ #include "progressbar.h" #include "adblockicon.h" #include "closedtabsmanager.h" +#include "statusbarmessage.h" const QString QupZilla::VERSION = "1.0.0-b2"; //const QString QupZilla::BUILDTIME = QLocale(QLocale::English).toDateTime(__DATE__" "__TIME__, "MMM d yyyy hh:mm:ss").toString("MM/dd/yyyy hh:ss"); @@ -69,6 +70,7 @@ QupZilla::QupZilla(bool tryRestore, QUrl startUrl) : ,m_webInspectorDock(0) ,m_webSearchToolbar(0) ,m_sideBar(0) + ,m_statusBarMessage(new StatusBarMessage(this)) { setAttribute(Qt::WA_DeleteOnClose); this->resize(640,480); diff --git a/src/app/qupzilla.h b/src/app/qupzilla.h index 58f1ffbb4..676c27765 100644 --- a/src/app/qupzilla.h +++ b/src/app/qupzilla.h @@ -72,6 +72,7 @@ class WebTab; class AdBlockIcon; class SideBar; class ProgressBar; +class StatusBarMessage; class QupZilla : public QMainWindow { Q_OBJECT @@ -97,9 +98,10 @@ public: inline WebView* weView() const { WebTab* webTab = qobject_cast(m_tabWidget->widget(m_tabWidget->currentIndex())); if (!webTab) return 0; return webTab->view(); } inline WebView* weView(int index) const { WebTab* webTab = qobject_cast(m_tabWidget->widget(index)); if (!webTab) return 0; return webTab->view(); } - inline LocationBar* locationBar(){ return m_locationBar; } - inline TabWidget* tabWidget(){ return m_tabWidget; } - inline BookmarksToolbar* bookmarksToolbar(){ return m_bookmarksToolbar; } + inline LocationBar* locationBar() { return m_locationBar; } + inline TabWidget* tabWidget() { return m_tabWidget; } + inline BookmarksToolbar* bookmarksToolbar() { return m_bookmarksToolbar; } + inline StatusBarMessage* statusBarMessage() { return m_statusBarMessage; } inline QAction* buttonStop(){ return m_buttonStop; } inline QAction* buttonReload(){ return m_buttonReload; } @@ -237,6 +239,7 @@ private: LocationBar* m_locationBar; TabWidget* m_tabWidget; QPointer m_sideBar; + StatusBarMessage* m_statusBarMessage; QSplitter* m_navigationSplitter; QAction* m_buttonBack; diff --git a/src/navigation/locationbar.cpp b/src/navigation/locationbar.cpp index 6a2173300..fe84b9f4f 100644 --- a/src/navigation/locationbar.cpp +++ b/src/navigation/locationbar.cpp @@ -27,6 +27,7 @@ #include "webpage.h" #include "bookmarkicon.h" #include "progressbar.h" +#include "statusbarmessage.h" LocationBar::LocationBar(QupZilla* mainClass, QWidget* parent) : LineEdit(parent) @@ -154,7 +155,7 @@ void LocationBar::rssIconClicked() void LocationBar::showUrl(const QUrl &url, bool empty) { - if (hasFocus() || (url.isEmpty() && empty)) + if (/*hasFocus() || (*/url.isEmpty() && empty/*)*/) return; if (url.toEncoded()!=text()) { @@ -171,15 +172,15 @@ void LocationBar::showUrl(const QUrl &url, bool empty) p_QupZilla->progressBar()->setValue(view->getLoading()); p_QupZilla->buttonStop()->setVisible(true); p_QupZilla->buttonReload()->setVisible(false); - p_QupZilla->statusBar()->showMessage(tr("Loading...")); - }else{ + } else { p_QupZilla->progressBar()->setVisible(false); p_QupZilla->buttonStop()->setVisible(false); p_QupZilla->buttonReload()->setVisible(true); - p_QupZilla->statusBar()->showMessage(tr("Done")); p_QupZilla->ipLabel()->show(); } + p_QupZilla->statusBarMessage()->clearMessage(); + hideGoButton(); m_bookmarkIcon->checkBookmark(url); diff --git a/src/other/statusbarmessage.cpp b/src/other/statusbarmessage.cpp new file mode 100644 index 000000000..6fb15e39a --- /dev/null +++ b/src/other/statusbarmessage.cpp @@ -0,0 +1,65 @@ +#include "statusbarmessage.h" +#include "qupzilla.h" +#include "squeezelabel.h" + + +class TipLabel : public SqueezeLabel { +public: + TipLabel() + { + setWindowFlags(Qt::ToolTip); + setForegroundRole(QPalette::ToolTipText); + setBackgroundRole(QPalette::ToolTipBase); + setPalette(QToolTip::palette()); + ensurePolished(); + setFrameStyle(QFrame::NoFrame); + setMargin(2); + } + + void paintEvent(QPaintEvent *ev) + { + QStylePainter p(this); + QStyleOptionFrame opt; + opt.init(this); + p.drawPrimitive(QStyle::PE_PanelTipLabel, opt); + p.end(); + + SqueezeLabel::paintEvent(ev); + } +}; + + +StatusBarMessage::StatusBarMessage(QupZilla* mainClass) + : QObject() + , p_QupZilla(mainClass) +{ + m_statusBarText = new TipLabel(); +} + +#define STATUS_Y_OFFSET -35 +#define STATUS_X_OFFSET +3 +#define STATUS_TOOLTIP_WIDTH_OFFSET -20 + +void StatusBarMessage::showMessage(const QString &message) +{ + if (p_QupZilla->statusBar()->isVisible()) { + p_QupZilla->statusBar()->showMessage(message); + } else { + QPoint position = p_QupZilla->weView()->mapToGlobal(p_QupZilla->weView()->pos()); + position.setY( p_QupZilla->weView()->size().height() + position.y() STATUS_Y_OFFSET); + position.setX(position.x() STATUS_X_OFFSET); + m_statusBarText->move(position); + m_statusBarText->setMaximumWidth(p_QupZilla->size().width() STATUS_TOOLTIP_WIDTH_OFFSET); + m_statusBarText->setText(message); + m_statusBarText->resize(m_statusBarText->sizeHint()); + m_statusBarText->show(); + } +} + +void StatusBarMessage::clearMessage() +{ + if (p_QupZilla->statusBar()->isVisible()) + p_QupZilla->statusBar()->showMessage(""); + else + m_statusBarText->hide(); +} diff --git a/src/other/statusbarmessage.h b/src/other/statusbarmessage.h new file mode 100644 index 000000000..9b273464f --- /dev/null +++ b/src/other/statusbarmessage.h @@ -0,0 +1,27 @@ +#ifndef STATUSBARMESSAGE_H +#define STATUSBARMESSAGE_H + +#include +#include + +class QupZilla; +class TipLabel; +class StatusBarMessage : public QObject +{ + Q_OBJECT +public: + explicit StatusBarMessage(QupZilla* mainClass); + + void showMessage(const QString &message); + void clearMessage(); + +signals: + +public slots: + +private: + QupZilla* p_QupZilla; + TipLabel* m_statusBarText; +}; + +#endif // STATUSBARMESSAGE_H diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 5105fc066..fe9dc6db3 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -593,8 +593,13 @@ void Preferences::saveSettings() settings.setValue("defaultDownloadPath",""); else{ QString text = ui->downLoc->text(); +#ifdef Q_WS_WIN + if (!text.endsWith("\\")) + text+="\\"; +#else if (!text.endsWith("/")) text+="/"; +#endif settings.setValue("defaultDownloadPath",text); } settings.endGroup(); diff --git a/src/webview/webview.cpp b/src/webview/webview.cpp index 10a866aae..c846f3b5c 100644 --- a/src/webview/webview.cpp +++ b/src/webview/webview.cpp @@ -31,6 +31,7 @@ #include "pluginproxy.h" #include "iconprovider.h" #include "webtab.h" +#include "statusbarmessage.h" WebView::WebView(QupZilla* mainClass, QWidget* parent) : QWebView(parent) @@ -266,11 +267,10 @@ void WebView::linkHovered(const QString &link, const QString &title, const QStri Q_UNUSED(title); Q_UNUSED(content); if (isCurrent()) { - if (link!="") { - p_QupZilla->statusBar()->showMessage(link); - }else{ - isLoading() ? p_QupZilla->statusBar()->showMessage(tr("Loading...")) : p_QupZilla->statusBar()->showMessage(tr("Done")); - } + if (link!="") + p_QupZilla->statusBarMessage()->showMessage(link); + else + p_QupZilla->statusBarMessage()->clearMessage(); } m_hoveredLink = link; }