From 9c9e6e4371c75e8a5be522ac0b070c48cda9afd3 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Sun, 18 Nov 2007 21:33:04 +0000 Subject: [PATCH] provide a rounded rectangle path generator so we can share this implementatoin around plasma svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=738424 --- plasma.cpp | 15 +++++++++++++++ plasma.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/plasma.cpp b/plasma.cpp index 390bd0e23..4b4071ad6 100644 --- a/plasma.cpp +++ b/plasma.cpp @@ -62,4 +62,19 @@ Direction locationToDirection(Location location) return Down; } +QPainterPath roundedRectangle(const QRectF& rect, qreal radius) +{ + QPainterPath path(QPointF(rect.left(), rect.top() + radius)); + path.quadTo(rect.left(), rect.top(), rect.left() + radius, rect.top()); // Top left corner + path.lineTo(rect.right() - radius, rect.top()); // Top side + path.quadTo(rect.right(), rect.top(), rect.right(), rect.top() + radius); // Top right corner + path.lineTo(rect.right(), rect.bottom() - radius); // Right side + path.quadTo(rect.right(), rect.bottom(), rect.right() - radius, rect.bottom()); // Bottom right corner + path.lineTo(rect.left() + radius, rect.bottom()); // Bottom side + path.quadTo(rect.left(), rect.bottom(), rect.left(), rect.bottom() - radius); // Bottom left corner + path.closeSubpath(); + + return path; +} + } // Plasma namespace diff --git a/plasma.h b/plasma.h index e76e3683c..617d85452 100644 --- a/plasma.h +++ b/plasma.h @@ -21,6 +21,7 @@ #define PLASMA_DEFS_H #include +#include #include @@ -136,6 +137,11 @@ PLASMA_EXPORT qreal scalingFactor(ZoomLevel level); **/ PLASMA_EXPORT Direction locationToDirection(Location location); +/** + * Returns a nicely rounded rectanglular path for painting. + */ +PLASMA_EXPORT QPainterPath roundedRectangle(const QRectF& rect, qreal radius); + } // Plasma namespace Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Constraints)