1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

[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.
This commit is contained in:
nowrep 2013-04-21 01:24:24 +02:00
parent beaf05f28e
commit 9861af4d64
9 changed files with 72 additions and 4 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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;
};

View File

@ -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 <QStyleOptionFrame>
#include <QStatusBar>
@ -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);

View File

@ -39,6 +39,7 @@ public:
bool eventFilter(QObject* o, QEvent* e);
private:
void resizeEvent(QResizeEvent* ev);
void paintEvent(QPaintEvent* ev);
QTimer* m_timer;

View File

@ -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<QString, QIcon> iconCache;
@ -730,3 +758,4 @@ QString QzTools::operatingSystem()
return str;
#endif
}

View File

@ -20,6 +20,7 @@
#include <QList>
#include <QString>
#include <QRegion>
#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);

View File

@ -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 <QLabel>
@ -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)

View File

@ -57,6 +57,7 @@ private slots:
#endif
protected:
void resizeEvent(QResizeEvent* ev);
void paintEvent(QPaintEvent* pe);
private: