[Uml-devel] branches/work/soc-umbrello/umbrello
Gopala Krishna A
krishna.ggk at gmail.com
Thu Jul 24 21:09:50 UTC 2008
SVN commit 837503 by gopala:
Ported RegionWidget.
M +35 -75 regionwidget.cpp
M +10 -51 regionwidget.h
M +1 -1 toolbarstateother.cpp
M +1 -1 widget_factory.cpp
--- branches/work/soc-umbrello/umbrello/regionwidget.cpp #837502:837503
@@ -12,96 +12,56 @@
// own header
#include "regionwidget.h"
-// qt includes
-#include <qevent.h>
-#include <QPolygon>
+/// Minimum size of region widget.
+const QSizeF RegionWidget::MinimumSize(90, 45);
-// kde includes
-#include <klocale.h>
-#include <kdebug.h>
-#include <kinputdialog.h>
+/**
+ * Creates a Region widget.
+ *
+ * @param id The ID to assign (-1 will prompt a new ID.)
+ */
+RegionWidget::RegionWidget(Uml::IDType id)
+ : NewUMLRectWidget(0, id)
+{
+ m_baseType = Uml::wt_Region;
+ setMinimumSize(RegionWidget::MinimumSize);
+}
-// app includes
-#include "uml.h"
-#include "umldoc.h"
-#include "docwindow.h"
-#include "umlwidget.h"
-#include "umlview.h"
-#include "floatingtextwidget.h"
-
-RegionWidget::RegionWidget(UMLScene * view, Uml::IDType id)
- : NewUMLRectWidget(view, id) {
- NewUMLRectWidget::setBaseType( Uml::wt_Region );
- updateComponentSize();
+/// Destructor
+RegionWidget::~RegionWidget()
+{
}
-RegionWidget::~RegionWidget() {}
-
+/// Draws a rounded rect with dash line property.
void RegionWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *)
{
- QPainter &p = *painter;
- qreal offsetX = 0, offsetY = 0;
+ QPen pen(lineColor(), lineWidth());
+ pen.setStyle(Qt::DashLine);
- setPenFromSettings(p);
- const int w = getWidth();
- const int h = getHeight();
- QPen pen = p.pen();
- {
- setPenFromSettings(p);
- pen.setColor ( Qt::red );
- pen.setStyle ( Qt::DashLine );
- p.setPen( pen );
- p.drawRoundRect(offsetX, offsetY, w, h, (h * 60) / w, 60);
+ painter->setPen(pen);
+ painter->setBrush(Qt::NoBrush);
- }
- if(isSelected())
- drawSelected(&p, offsetX, offsetY);
+ const QRectF r = rect();
+ painter->drawRoundRect(r, (r.height() * 60) / r.width(), 60);
}
-QSizeF RegionWidget::calculateSize() {
-
- int width = 10, height = 10;
- const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
- const int fontHeight = fm.lineSpacing();
- int textWidth = fm.width(getName());
-
- height = fontHeight;
- width = textWidth > REGION_WIDTH?textWidth:REGION_WIDTH;
- height = height > REGION_HEIGHT ? height : REGION_HEIGHT;
- width += REGION_MARGIN * 2;
- height += REGION_MARGIN * 2;
-
- return QSizeF(width, height);
+/// Loads region widget from XMI element
+bool RegionWidget::loadFromXMI( QDomElement & qElement )
+{
+ if( !NewUMLRectWidget::loadFromXMI( qElement ) )
+ return false;
+ setName(qElement.attribute( "regionname", "" ));
+ setDocumentation(qElement.attribute( "documentation", "" ));
+ return true;
}
-void RegionWidget::setName(const QString &strName) {
- m_Text = strName;
- updateComponentSize();
- adjustAssocs( getX(), getY() );
-}
-
-QString RegionWidget::getName() const {
- return m_Text;
-}
-
-
-void RegionWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement ) {
+/// Saves region widget to XMI element.
+void RegionWidget::saveToXMI( QDomDocument & qDoc, QDomElement & qElement )
+{
QDomElement regionElement = qDoc.createElement( "regionwidget" );
NewUMLRectWidget::saveToXMI( qDoc, regionElement );
- regionElement.setAttribute( "regionname", m_Text );
+ regionElement.setAttribute( "regionname", name() );
regionElement.setAttribute( "documentation", documentation() );
qElement.appendChild( regionElement );
}
-
-bool RegionWidget::loadFromXMI( QDomElement & qElement ) {
- if( !NewUMLRectWidget::loadFromXMI( qElement ) )
- return false;
- m_Text = qElement.attribute( "regionname", "" );
- setDocumentation(qElement.attribute( "documentation", "" ));
- return true;
-}
-
-
-#include "regionwidget.moc"
-
--- branches/work/soc-umbrello/umbrello/regionwidget.h #837502:837503
@@ -11,65 +11,24 @@
#ifndef REGIONWIDGET_H
#define REGIONWIDGET_H
-#include <qpainter.h>
-#include <qstringlist.h>
-#include "umlwidget.h"
-#include "worktoolbar.h"
-#include "floatingtextwidget.h"
-#define REGION_MARGIN 5
-#define REGION_WIDTH 90
-#define REGION_HEIGHT 45
+#include "newumlrectwidget.h"
-class RegionWidget: public NewUMLRectWidget {
- Q_OBJECT
+/**
+ * Represents a rectangular region on Activity diagram.
+ */
+class RegionWidget: public NewUMLRectWidget
+{
public:
-
- /**
- * Creates a Region widget.
- *
- * @param view The parent of the widget.
- * @param id The ID to assign (-1 will prompt a new ID.)
- */
- explicit RegionWidget( UMLScene * view, Uml::IDType id = Uml::id_None );
-
- /**
- * destructor
- */
+ explicit RegionWidget(Uml::IDType id = Uml::id_None );
virtual ~RegionWidget();
- /**
- * Overrides the standard paint event.
- */
void paint(QPainter *p, const QStyleOptionGraphicsItem *item, QWidget *w);
- /**
- * Sets the name of the REGION.
- */
- virtual void setName(const QString &strName);
-
- /**
- * Returns the name of the Region.
- */
- virtual QString getName() const;
-
-
- /**
- * Creates the "REGIONwidget" XMI element.
- */
+ bool loadFromXMI( QDomElement & qElement );
void saveToXMI( QDomDocument & qDoc, QDomElement & qElement );
- /**
- * Loads a "REGIONwidget" XMI element.
- */
- bool loadFromXMI( QDomElement & qElement );
-
-protected:
- /**
- * Overrides method from NewUMLRectWidget
- */
- QSizeF calculateSize();
-
+private:
+ static const QSizeF MinimumSize;
};
-
#endif
--- branches/work/soc-umbrello/umbrello/toolbarstateother.cpp #837502:837503
@@ -159,7 +159,7 @@
break;
case WorkToolBar::tbb_Region:
- umlWidget = new RegionWidget(m_pUMLScene);
+ umlWidget = new RegionWidget();
break;
case WorkToolBar::tbb_Seq_Combined_Fragment:
--- branches/work/soc-umbrello/umbrello/widget_factory.cpp #837502:837503
@@ -212,7 +212,7 @@
} else if (tag == "objectnodewidget") {
widget = new ObjectNodeWidget(scene, ObjectNodeWidget::Normal, Uml::id_Reserved);
} else if (tag == "regionwidget") {
- widget = new RegionWidget(scene, Uml::id_Reserved);
+ widget = new RegionWidget(Uml::id_Reserved);
} else if (tag == "pinwidget") {
widget = new PinWidget(scene, NULL, Uml::id_Reserved);
}
More information about the umbrello-devel
mailing list