[Uml-devel] branches/work/soc-umbrello/umbrello
Gopala Krishna A
krishna.ggk at gmail.com
Sat Jul 4 18:36:13 UTC 2009
SVN commit 991371 by gopala:
* Added Corner enumeration.
* Added a method to draw rounded rect such that only specific corners can be
rounded.
* Draw the header background of ClassifierWidget with a rounded rect, rounded
in top left and top right corners only.
M +8 -0 umlnamespace.h
M +4 -1 widgets/classifierwidget.cpp
M +50 -0 widgets/widget_utils.cpp
M +4 -1 widgets/widget_utils.h
--- branches/work/soc-umbrello/umbrello/umlnamespace.h #991370:991371
@@ -316,6 +316,14 @@
reg_SouthWest
};
+ enum Corner {
+ corner_TopLeft = 0x1,
+ corner_TopRight = 0x2,
+ corner_BottomRight = 0x4,
+ corner_BottomLeft = 0x8
+ };
+ Q_DECLARE_FLAGS(Corners, Corner);
+
/**
* The data type used for unique IDs.
*/
--- branches/work/soc-umbrello/umbrello/widgets/classifierwidget.cpp #991370:991371
@@ -27,6 +27,7 @@
#include "umldoc.h"
#include "umlscene.h"
#include "umlview.h"
+#include "widget_utils.h"
static QBrush awesomeHeaderBrush()
{
@@ -436,7 +437,9 @@
painter->setPen(QPen(Qt::NoPen));
painter->setBrush(awesomeHeaderBrush());
- painter->drawRoundedRect(textItemGroupAt(HeaderGroupIndex)->groupGeometry(), 5, 5);
+ Uml::Corners corners(Uml::corner_TopLeft | Uml::corner_TopRight);
+ Widget_Utils::drawRoundedRect(painter, textItemGroupAt(HeaderGroupIndex)->groupGeometry(),
+ 5, 5, corners);
pen.setStyle(Qt::DotLine);
painter->setPen(pen);
--- branches/work/soc-umbrello/umbrello/widgets/widget_utils.cpp #991370:991371
@@ -180,6 +180,56 @@
}
}
+ void drawRoundedRect(QPainter *painter, const QRectF& rect, qreal xRadius,
+ qreal yRadius, Uml::Corners corners)
+ {
+ if (xRadius < 0 || yRadius < 0) {
+ painter->drawRect(rect);
+ return;
+ }
+ QRectF arcRect(0, 0, 2 * xRadius, 2 * yRadius);
+
+ QPainterPath path;
+ path.moveTo(rect.left(), rect.top() + yRadius);
+ if (corners.testFlag(Uml::corner_TopLeft)) {
+ arcRect.moveTopLeft(rect.topLeft());
+ path.arcTo(arcRect, 180, -90);
+ } else {
+ path.lineTo(rect.topLeft());
+ }
+
+ path.lineTo(rect.right() - xRadius, rect.top());
+
+ if (corners.testFlag(Uml::corner_TopRight)) {
+ arcRect.moveTopRight(rect.topRight());
+ path.arcTo(arcRect, 90, -90);
+ } else {
+ path.lineTo(rect.topRight());
+ }
+
+ path.lineTo(rect.right(), rect.bottom() - yRadius);
+
+ if (corners.testFlag(Uml::corner_BottomRight)) {
+ arcRect.moveBottomRight(rect.bottomRight());
+ path.arcTo(arcRect, 0, -90);
+ } else {
+ path.lineTo(rect.bottomRight());
+ }
+
+ path.lineTo(rect.left() + xRadius, rect.bottom());
+
+ if (corners.testFlag(Uml::corner_BottomLeft)) {
+ arcRect.moveBottomLeft(rect.bottomLeft());
+ path.arcTo(arcRect, 270, 90);
+ } else {
+ path.lineTo(rect.bottomLeft());
+ }
+
+ path.closeSubpath();
+ painter->drawPath(path);
+ }
+
+
/**
* Converts a point to a comma separated string i.e "x,y"
*/
--- branches/work/soc-umbrello/umbrello/widgets/widget_utils.h #991370:991371
@@ -34,7 +34,7 @@
UMLWidget* findWidget(Uml::IDType id,
const UMLWidgetList& widgets,
- const MessageWidgetList* pMessages = NULL);
+ const MessageWidgetList* pMessages = 0);
QGraphicsRectItem *decoratePoint(const QPointF& p);
@@ -46,6 +46,9 @@
const QSizeF& arrowSize, Qt::ArrowType arrowType,
bool solid = false);
+ void drawRoundedRect(QPainter *painter, const QRectF& rect, qreal xRadius,
+ qreal yRadius, Uml::Corners corners);
+
QString pointToString(const QPointF& point);
QPointF stringToPoint(const QString& str);
More information about the umbrello-devel
mailing list