From 9861af4d64aaef753e2d2ee7273a27556fcc7586 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 21 Apr 2013 01:24:24 +0200 Subject: [PATCH] [Oxygen] Set rounded corners for custom tooltips. Show custom tooltips with rounded corners when using Oxygen theme. Tab previews and popup statusbar message are now painted with rounded corners. --- CHANGELOG | 1 + src/lib/app/proxystyle.cpp | 7 ++++++- src/lib/app/proxystyle.h | 3 ++- src/lib/other/statusbarmessage.cpp | 14 +++++++++++++- src/lib/other/statusbarmessage.h | 1 + src/lib/tools/qztools.cpp | 29 +++++++++++++++++++++++++++++ src/lib/tools/qztools.h | 2 ++ src/lib/webview/tabpreview.cpp | 18 +++++++++++++++++- src/lib/webview/tabpreview.h | 1 + 9 files changed, 72 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3e9ef709c..5de1543b7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ Version 1.5.0 * proxy exceptions now supports wildcards (*, ?) * cancel upload when trying to upload non-readable files * GreaseMonkey: added support for GM_Settings + * oxygen: set rounded corners for tooltips * fixed: size of preferences dialog on low-res screens * fixed: loading plugins with relative paths in portable build diff --git a/src/lib/app/proxystyle.cpp b/src/lib/app/proxystyle.cpp index 360af66f0..ff2b4b575 100644 --- a/src/lib/app/proxystyle.cpp +++ b/src/lib/app/proxystyle.cpp @@ -44,7 +44,7 @@ int ProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, cons if (m_TabBarTabHSpace == -1) { m_TabBarTabHSpace = qMin(QProxyStyle::pixelMetric(PM_TabBarTabHSpace, option, widget), 14); - if (baseStyle()->objectName() == QLatin1String("oxygen")) { + if (name() == QLatin1String("oxygen")) { m_TabBarTabHSpace = 14; } } @@ -55,3 +55,8 @@ int ProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, cons return QProxyStyle::pixelMetric(metric, option, widget); } } + +QString ProxyStyle::name() const +{ + return baseStyle()->objectName(); +} diff --git a/src/lib/app/proxystyle.h b/src/lib/app/proxystyle.h index a8b13ca86..80f3c2c29 100644 --- a/src/lib/app/proxystyle.h +++ b/src/lib/app/proxystyle.h @@ -28,9 +28,10 @@ public: explicit ProxyStyle(); int styleHint(StyleHint hint, const QStyleOption* option = 0, const QWidget* widget = 0, QStyleHintReturn* returnData = 0) const; - int pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget) const; + QString name() const; + private: mutable int m_TabBarTabHSpace; }; diff --git a/src/lib/other/statusbarmessage.cpp b/src/lib/other/statusbarmessage.cpp index 7de4f3638..8c87575b3 100644 --- a/src/lib/other/statusbarmessage.cpp +++ b/src/lib/other/statusbarmessage.cpp @@ -19,9 +19,11 @@ #include "qupzilla.h" #include "tabwidget.h" #include "tabbedwebview.h" -#include "webpage.h" #include "squeezelabelv1.h" #include "mainapplication.h" +#include "webpage.h" +#include "proxystyle.h" +#include "qztools.h" #include #include @@ -60,6 +62,16 @@ void TipLabel::hideDelayed() m_timer->start(); } +void TipLabel::resizeEvent(QResizeEvent* ev) +{ + SqueezeLabelV1::resizeEvent(ev); + + // Oxygen is setting rounded corners only for top-level tooltips + if (mApp->proxyStyle()->name() == QLatin1String("oxygen")) { + setMask(QzTools::roundedRect(rect(), 4)); + } +} + void TipLabel::paintEvent(QPaintEvent* ev) { QStylePainter p(this); diff --git a/src/lib/other/statusbarmessage.h b/src/lib/other/statusbarmessage.h index 6ba5613d3..a8faef20a 100644 --- a/src/lib/other/statusbarmessage.h +++ b/src/lib/other/statusbarmessage.h @@ -39,6 +39,7 @@ public: bool eventFilter(QObject* o, QEvent* e); private: + void resizeEvent(QResizeEvent* ev); void paintEvent(QPaintEvent* ev); QTimer* m_timer; diff --git a/src/lib/tools/qztools.cpp b/src/lib/tools/qztools.cpp index 6f05a2651..f2b920c61 100644 --- a/src/lib/tools/qztools.cpp +++ b/src/lib/tools/qztools.cpp @@ -352,6 +352,34 @@ QString QzTools::applyDirectionToPage(QString &pageContents) return pageContents; } +// Thanks to http://www.qtcentre.org/threads/3205-Toplevel-widget-with-rounded-corners?p=17492#post17492 +QRegion QzTools::roundedRect(const QRect &rect, int radius) +{ + QRegion region; + + // middle and borders + region += rect.adjusted(radius, 0, -radius, 0); + region += rect.adjusted(0, radius, 0, -radius); + + // top left + QRect corner(rect.topLeft(), QSize(radius * 2, radius * 2)); + region += QRegion(corner, QRegion::Ellipse); + + // top right + corner.moveTopRight(rect.topRight()); + region += QRegion(corner, QRegion::Ellipse); + + // bottom left + corner.moveBottomLeft(rect.bottomLeft()); + region += QRegion(corner, QRegion::Ellipse); + + // bottom right + corner.moveBottomRight(rect.bottomRight()); + region += QRegion(corner, QRegion::Ellipse); + + return region; +} + QIcon QzTools::iconFromFileName(const QString &fileName) { static QHash iconCache; @@ -730,3 +758,4 @@ QString QzTools::operatingSystem() return str; #endif } + diff --git a/src/lib/tools/qztools.h b/src/lib/tools/qztools.h index eb414c38b..f5cbda307 100644 --- a/src/lib/tools/qztools.h +++ b/src/lib/tools/qztools.h @@ -20,6 +20,7 @@ #include #include +#include #include "qz_namespace.h" @@ -60,6 +61,7 @@ QString QT_QUPZILLA_EXPORT resolveFromPath(const QString &name); QStringList QT_QUPZILLA_EXPORT splitCommandArguments(const QString &command); bool QT_QUPZILLA_EXPORT startExternalProcess(const QString &executable, const QString &args); +QRegion QT_QUPZILLA_EXPORT roundedRect(const QRect &rect, int radius); QIcon QT_QUPZILLA_EXPORT iconFromFileName(const QString &fileName); bool QT_QUPZILLA_EXPORT isUtf8(const char* string); diff --git a/src/lib/webview/tabpreview.cpp b/src/lib/webview/tabpreview.cpp index eba4033c6..114bcbec1 100644 --- a/src/lib/webview/tabpreview.cpp +++ b/src/lib/webview/tabpreview.cpp @@ -18,7 +18,10 @@ * ============================================================ */ #include "qupzilla.h" #include "tabpreview.h" +#include "qztools.h" #include "webtab.h" +#include "mainapplication.h" +#include "proxystyle.h" #include "tabbedwebview.h" #include @@ -227,14 +230,27 @@ void TabPreview::showAnimated() #endif } +void TabPreview::resizeEvent(QResizeEvent* ev) +{ + QFrame::resizeEvent(ev); + + // Oxygen is setting rounded corners only for top-level tooltips + if (mApp->proxyStyle()->name() == QLatin1String("oxygen")) { + setMask(QzTools::roundedRect(rect(), 4)); + } +} + void TabPreview::paintEvent(QPaintEvent* pe) { + QStylePainter painter(this); QStyleOptionFrame opt; opt.init(this); - QStylePainter painter(this); painter.setClipRegion(pe->region()); painter.drawPrimitive(QStyle::PE_PanelTipLabel, opt); + painter.end(); + + QFrame::paintEvent(pe); } void TabPreview::calculateSteps(const QRect &oldGeometry, const QRect &newGeometry) diff --git a/src/lib/webview/tabpreview.h b/src/lib/webview/tabpreview.h index efada9d7b..20b2905a9 100644 --- a/src/lib/webview/tabpreview.h +++ b/src/lib/webview/tabpreview.h @@ -57,6 +57,7 @@ private slots: #endif protected: + void resizeEvent(QResizeEvent* ev); void paintEvent(QPaintEvent* pe); private: