From c9210d392ca720028a4a2be427ba13100418c5b7 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 9 Mar 2016 20:55:00 +0100 Subject: Add argument names to the function signatures in headers Sometimes, in the .cpp, the declaration has the argument name in comments because it is not used (instead of using Q_UNUSED). The old qdoc could parse that, but once clang is used, these comments are not seen anymore. So add the argument names to the headers. This is also good for things like auto completion, which uses only the header to know what the argument name is. I grepped for " */)" and made sure all the functions that are documented have the right arguments. I also added the name to all the function around for consistency. Change-Id: I1aaa37e25a1985f7f51653f047a1ac2633242b56 Reviewed-by: Marc Mutz Reviewed-by: Martin Smith --- src/widgets/styles/qstyle.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index 1e9d15c993..26d1c63195 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -66,13 +66,13 @@ public: QStyle(); virtual ~QStyle(); - virtual void polish(QWidget *); - virtual void unpolish(QWidget *); + virtual void polish(QWidget *widget); + virtual void unpolish(QWidget *widget); - virtual void polish(QApplication *); - virtual void unpolish(QApplication *); + virtual void polish(QApplication *application); + virtual void unpolish(QApplication *application); - virtual void polish(QPalette &); + virtual void polish(QPalette &palette); virtual QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, -- cgit v1.2.3 From 7c7ece94429d6e12e0543c275d26fd90501193ff Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 24 Feb 2016 17:19:37 -0800 Subject: QMacStyle: Ensure proper focus ring clipping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By rendering the focus ring directly on the backing NSView, we would ignore the painter's clipping information. It would also require creating a custom CGContext and attached NSGraphicsContext every time. The first step is to render the focus ring on a pixmap and then use the painter to render that pixamp. This ensures the clipping is done properly. The second step is to cache said pixmap and render it as a nine-patch image. Change-Id: I1df1baf7dc490023319f025a16306d4f04e5264c Task-number: QTBUG-50645 Reviewed-by: Morten Johan Sørvig --- src/widgets/styles/qmacstyle_mac.mm | 90 +++++++++++++++++++++++++--------- src/widgets/styles/qmacstyle_mac_p_p.h | 2 + 2 files changed, 70 insertions(+), 22 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 4f688f6f28..092cf4d543 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -1097,17 +1097,67 @@ static QAquaWidgetSize qt_aqua_guess_size(const QWidget *widg, QSize large, QSiz } #endif -static void qt_drawFocusRingOnPath(CGContextRef cg, NSBezierPath *focusRingPath) +void QMacStylePrivate::drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius) const { - CGContextSaveGState(cg); - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext - graphicsContextWithGraphicsPort:(CGContextRef)cg flipped:NO]]; - NSSetFocusRingStyle(NSFocusRingOnly); - [focusRingPath setClip]; // Clear clip path to avoid artifacts when rendering the cursor at zero pos - [focusRingPath fill]; - [NSGraphicsContext restoreGraphicsState]; - CGContextRestoreGState(cg); + qreal pixelRatio = p->device()->devicePixelRatioF(); + static const QString keyFormat = QLatin1String("$qt_focusring%1-%2-%3-%4"); + const QString &key = keyFormat.arg(hMargin).arg(vMargin).arg(radius).arg(pixelRatio); + QPixmap focusRingPixmap; + const qreal size = radius * 2 + 5; + + if (!QPixmapCache::find(key, focusRingPixmap)) { + focusRingPixmap = QPixmap((QSize(size, size) + 2 * QSize(hMargin, vMargin)) * pixelRatio); + focusRingPixmap.fill(Qt::transparent); + focusRingPixmap.setDevicePixelRatio(pixelRatio); + { + QMacAutoReleasePool pool; + NSBezierPath *focusRingPath; + if (radius > 0) + focusRingPath = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(hMargin, vMargin, size, size) + xRadius:radius + yRadius:radius]; + else + focusRingPath = [NSBezierPath bezierPathWithRect:NSMakeRect(hMargin, vMargin, size, size)]; + [NSGraphicsContext saveGraphicsState]; + QMacCGContext gc(&focusRingPixmap); + [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:(CGContextRef)gc + flipped:NO]]; + NSSetFocusRingStyle(NSFocusRingOnly); + [focusRingPath fill]; + [NSGraphicsContext restoreGraphicsState]; + } + QPixmapCache::insert(key, focusRingPixmap); + } + + // Add 2 for the actual ring tickness going inwards + const qreal hCornerSize = 2 + hMargin + radius; + const qreal vCornerSize = 2 + vMargin + radius; + const qreal shCornerSize = hCornerSize * pixelRatio; + const qreal svCornerSize = vCornerSize * pixelRatio; + // top-left corner + p->drawPixmap(QPointF(targetRect.left(), targetRect.top()), focusRingPixmap, + QRectF(0, 0, shCornerSize, svCornerSize)); + // top-right corner + p->drawPixmap(QPointF(targetRect.right() - hCornerSize + 1, targetRect.top()), focusRingPixmap, + QRectF(focusRingPixmap.width() - shCornerSize, 0, shCornerSize, svCornerSize)); + // bottom-left corner + p->drawPixmap(QPointF(targetRect.left(), targetRect.bottom() - vCornerSize + 1), focusRingPixmap, + QRectF(0, focusRingPixmap.height() - svCornerSize, shCornerSize, svCornerSize)); + // bottom-right corner + p->drawPixmap(QPointF(targetRect.right() - hCornerSize + 1, targetRect.bottom() - vCornerSize + 1), focusRingPixmap, + QRect(focusRingPixmap.width() - shCornerSize, focusRingPixmap.height() - svCornerSize, shCornerSize, svCornerSize)); + // top edge + p->drawPixmap(QRectF(targetRect.left() + hCornerSize, targetRect.top(), targetRect.width() - 2 * hCornerSize, vCornerSize), focusRingPixmap, + QRect(shCornerSize, 0, focusRingPixmap.width() - 2 * shCornerSize, svCornerSize)); + // bottom edge + p->drawPixmap(QRectF(targetRect.left() + hCornerSize, targetRect.bottom() - vCornerSize + 1, targetRect.width() - 2 * hCornerSize, vCornerSize), focusRingPixmap, + QRect(shCornerSize, focusRingPixmap.height() - svCornerSize, focusRingPixmap.width() - 2 * shCornerSize, svCornerSize)); + // left edge + p->drawPixmap(QRectF(targetRect.left(), targetRect.top() + vCornerSize, hCornerSize, targetRect.height() - 2 * vCornerSize), focusRingPixmap, + QRect(0, svCornerSize, shCornerSize, focusRingPixmap.width() - 2 * svCornerSize)); + // right edge + p->drawPixmap(QRectF(targetRect.right() - hCornerSize + 1, targetRect.top() + vCornerSize, hCornerSize, targetRect.height() - 2 * vCornerSize), focusRingPixmap, + QRect(focusRingPixmap.width() - shCornerSize, svCornerSize, shCornerSize, focusRingPixmap.width() - 2 * svCornerSize)); } QAquaWidgetSize QMacStylePrivate::aquaSizeConstrain(const QStyleOption *option, const QWidget *widg, @@ -3947,12 +3997,11 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } } - NSBezierPath *pushButtonFocusRingPath; - if (bdi.kind == kThemeBevelButton) - pushButtonFocusRingPath = [NSBezierPath bezierPathWithRect:NSRectFromCGRect(focusRect)]; - else - pushButtonFocusRingPath = [NSBezierPath bezierPathWithRoundedRect:NSRectFromCGRect(focusRect) xRadius:4 yRadius:4]; - qt_drawFocusRingOnPath(cg, pushButtonFocusRingPath); + const qreal radius = bdi.kind == kThemeBevelButton ? 0 : 4; + const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, btn, w); + const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, btn, w); + const QRect focusTargetRect(focusRect.origin.x, focusRect.origin.y, focusRect.size.width, focusRect.size.height); + d->drawFocusRing(p, focusTargetRect.adjusted(-hMargin, -vMargin, hMargin, vMargin), hMargin, vMargin, radius); } if (hasMenu && (!usingYosemiteOrLater || bdi.kind == kThemeBevelButton)) { @@ -4391,12 +4440,9 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter } break; case CE_FocusFrame: { - int xOff = proxy()->pixelMetric(PM_FocusFrameHMargin, opt, w); - int yOff = proxy()->pixelMetric(PM_FocusFrameVMargin, opt, w); - NSRect rect = NSMakeRect(xOff+opt->rect.x(), yOff+opt->rect.y(), opt->rect.width() - 2 * xOff, - opt->rect.height() - 2 * yOff); - NSBezierPath *focusFramePath = [NSBezierPath bezierPathWithRect:rect]; - qt_drawFocusRingOnPath(cg, focusFramePath); + const int hMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameHMargin, opt, w); + const int vMargin = proxy()->pixelMetric(QStyle::PM_FocusFrameVMargin, opt, w); + d->drawFocusRing(p, opt->rect, hMargin, vMargin); break; } case CE_MenuItem: case CE_MenuEmptyArea: diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index 33818568ec..b2c76c2d76 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -209,6 +209,8 @@ public: void drawNSViewInRect(QCocoaWidget widget, NSView *view, const QRect &rect, QPainter *p, bool isQWidget = true, QCocoaDrawRectBlock drawRectBlock = nil) const; void resolveCurrentNSView(QWindow *window); + void drawFocusRing(QPainter *p, const QRect &targetRect, int hMargin, int vMargin, qreal radius = 0) const; + public: mutable QPointer pressedButton; mutable QPointer defaultButton; -- cgit v1.2.3 From 5655f3413151beb0abaeb847942f7bf29a114d7d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 18 Mar 2016 10:25:08 +0100 Subject: QWindows(XP)Style: fix build with Clang after includemocs run Clang doesn't like the unused member variable: qwindowsstyle_p.h:100:11: error: private field 'reserved' is not used [-Werror,-Wunused-private-field] Remove. It's private API. Triggered by Clang seeing all methods of the classes in one TU by the following includemocs commit. Change-Id: I84e92d63af573c090ef89c1d8ee19af30f90b171 Reviewed-by: Friedemann Kleint Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/styles/qwindowsstyle_p.h | 1 - src/widgets/styles/qwindowsxpstyle_p.h | 1 - 2 files changed, 2 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qwindowsstyle_p.h b/src/widgets/styles/qwindowsstyle_p.h index da36d2af1b..2724222652 100644 --- a/src/widgets/styles/qwindowsstyle_p.h +++ b/src/widgets/styles/qwindowsstyle_p.h @@ -97,7 +97,6 @@ protected: private: Q_DISABLE_COPY(QWindowsStyle) Q_DECLARE_PRIVATE(QWindowsStyle) - void *reserved; }; #endif // QT_NO_STYLE_WINDOWS diff --git a/src/widgets/styles/qwindowsxpstyle_p.h b/src/widgets/styles/qwindowsxpstyle_p.h index 1706a1abe6..4dcb75716e 100644 --- a/src/widgets/styles/qwindowsxpstyle_p.h +++ b/src/widgets/styles/qwindowsxpstyle_p.h @@ -93,7 +93,6 @@ private: Q_DISABLE_COPY(QWindowsXPStyle) Q_DECLARE_PRIVATE(QWindowsXPStyle) friend class QStyleFactory; - void *reserved; }; #endif // QT_NO_STYLE_WINDOWSXP -- cgit v1.2.3 From 0e6ad275498dc8cc60a7d163bac9ed0add8e48d5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 16 Mar 2016 00:47:08 +0100 Subject: QtWidgets: includemocs A very simple way to save ~3KiB in test size and 440b in data size on GCC 5.3 Linux AMD64 release builds. Change-Id: I6619148cc497116b9772a00e1bc30d573a2b2534 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/styles/qfusionstyle.cpp | 2 ++ src/widgets/styles/qgtkstyle_p.cpp | 3 +++ src/widgets/styles/qproxystyle.cpp | 2 ++ src/widgets/styles/qstyle.cpp | 2 ++ src/widgets/styles/qstyleanimation.cpp | 2 ++ src/widgets/styles/qstyleplugin.cpp | 2 ++ src/widgets/styles/qwindowsstyle.cpp | 2 ++ 7 files changed, 15 insertions(+) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 2fc52e9a32..e4302247f5 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -3739,4 +3739,6 @@ QPixmap QFusionStyle::standardPixmap(StandardPixmap standardPixmap, const QStyle QT_END_NAMESPACE +#include "moc_qfusionstyle_p.cpp" + #endif // QT_NO_STYLE_FUSION || QT_PLUGIN diff --git a/src/widgets/styles/qgtkstyle_p.cpp b/src/widgets/styles/qgtkstyle_p.cpp index 00682c1c0f..a0fd8bf7db 100644 --- a/src/widgets/styles/qgtkstyle_p.cpp +++ b/src/widgets/styles/qgtkstyle_p.cpp @@ -888,4 +888,7 @@ uint qHash(const QHashableLatin1Literal &key) QT_END_NAMESPACE +#include "moc_qgtkstyle_p.cpp" +#include "moc_qgtkstyle_p_p.cpp" + #endif // !defined(QT_NO_STYLE_GTK) diff --git a/src/widgets/styles/qproxystyle.cpp b/src/widgets/styles/qproxystyle.cpp index 61f836b23c..2829d2db79 100644 --- a/src/widgets/styles/qproxystyle.cpp +++ b/src/widgets/styles/qproxystyle.cpp @@ -423,4 +423,6 @@ int QProxyStyle::layoutSpacing(QSizePolicy::ControlType control1, QT_END_NAMESPACE +#include "moc_qproxystyle.cpp" + #endif // QT_NO_STYLE_PROXY diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 02c420e55c..4a601ba871 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -2407,3 +2407,5 @@ void QStyle::setProxy(QStyle *style) } QT_END_NAMESPACE + +#include "moc_qstyle.cpp" diff --git a/src/widgets/styles/qstyleanimation.cpp b/src/widgets/styles/qstyleanimation.cpp index 78d0297be2..922a1e5ffb 100644 --- a/src/widgets/styles/qstyleanimation.cpp +++ b/src/widgets/styles/qstyleanimation.cpp @@ -359,4 +359,6 @@ void QScrollbarStyleAnimation::updateCurrentTime(int time) QT_END_NAMESPACE +#include "moc_qstyleanimation_p.cpp" + #endif //QT_NO_ANIMATION diff --git a/src/widgets/styles/qstyleplugin.cpp b/src/widgets/styles/qstyleplugin.cpp index 2be37bd65a..e1b28c1491 100644 --- a/src/widgets/styles/qstyleplugin.cpp +++ b/src/widgets/styles/qstyleplugin.cpp @@ -99,3 +99,5 @@ QStylePlugin::~QStylePlugin() } QT_END_NAMESPACE + +#include "moc_qstyleplugin.cpp" diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 01b82424c8..5d02bc17ae 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -2397,4 +2397,6 @@ QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon, const QStyleOptio QT_END_NAMESPACE +#include "moc_qwindowsstyle_p.cpp" + #endif // QT_NO_STYLE_WINDOWS -- cgit v1.2.3