[Uml-devel] branches/work/soc-umbrello/umbrello
Andi Fischer
andi.fischer at hispeed.ch
Sat Feb 19 13:50:52 UTC 2011
SVN commit 1221607 by fischer:
Wheel event handled for zoom in and out. Getter for selected widgets changed.
M +2 -4 clipboard/umlclipboard.cpp
M +23 -29 umlscene.cpp
M +2 -3 umlscene.h
M +177 -5 umlview.cpp
M +12 -22 umlview.h
--- branches/work/soc-umbrello/umbrello/clipboard/umlclipboard.cpp #1221606:1221607
@@ -80,14 +80,12 @@
m_type = clip4;
UMLScene *scene = UMLApp::app()->currentView()->umlScene();
scene->checkSelections();
- if (!scene->getSelectedWidgets(m_WidgetList)) {
- return 0;
- }
+ m_WidgetList = scene->selectedWidgetsExt();
//if there is no selected widget then there is no copy action
if (!m_WidgetList.count()) {
return 0;
}
- m_AssociationList = scene->getSelectedAssocs();
+ m_AssociationList = scene->selectedAssocs();
scene->copyAsImage(png);
} else { //if the copy action is being performed from the ListView
--- branches/work/soc-umbrello/umbrello/umlscene.cpp #1221606:1221607
@@ -1200,8 +1200,8 @@
// ourselves as this is done by QGraphicsScene
w->setSelected(true);
- /* selection changed, we have to make sure the copy and paste items
- * are correctly enabled/disabled */
+ // selection changed, we have to make sure the copy and paste items
+ // are correctly enabled/disabled
UMLApp::app()->slotCopyChanged();
}
@@ -1291,7 +1291,7 @@
temp->setLineColor(color);
// [PORT] temp->setUsesDiagramLineColour(false);
}
- AssociationWidgetList assoclist = getSelectedAssocs();
+ AssociationWidgetList assoclist = selectedAssocs();
foreach(AssociationWidget *aw , assoclist) {
aw->setLineColor(color);
// [PORT] aw->setUsesDiagramLineColour(false);
@@ -1308,7 +1308,7 @@
temp->setLineWidth(width);
// [PORT] temp->setUsesDiagramLineWidth(false);
}
- AssociationWidgetList assoclist = getSelectedAssocs();
+ AssociationWidgetList assoclist = selectedAssocs();
foreach(AssociationWidget *aw , assoclist) {
aw->setLineWidth(width);
// [PORT] aw->setUsesDiagramLineWidth(false);
@@ -1582,7 +1582,7 @@
foreach(UMLWidget* widget , selected) {
widget->setSelected(false);
}
- AssociationWidgetList selectedAssociationsList = getSelectedAssocs();
+ AssociationWidgetList selectedAssociationsList = selectedAssocs();
foreach(AssociationWidget* association , selectedAssociationsList) {
association->setSelected(false);
@@ -1722,24 +1722,26 @@
return counter;
}
-bool UMLScene::getSelectedWidgets(UMLWidgetList &WidgetList, bool filterText /*= true*/)
+UMLWidgetList UMLScene::selectedWidgetsExt(bool filterText /*= true*/)
{
- foreach(UMLWidget* temp, selectedWidgets()) {
- if (filterText && temp->baseType() == WidgetBase::wt_Text) {
- const FloatingTextWidget *ft = static_cast<const FloatingTextWidget*>(temp);
+ UMLWidgetList widgetList;
+
+ foreach(UMLWidget* widgt, selectedWidgets()) {
+ if (filterText && widgt->baseType() == WidgetBase::wt_Text) {
+ const FloatingTextWidget *ft = static_cast<const FloatingTextWidget*>(widgt);
if (ft->textRole() == tr_Floating)
- WidgetList.append(temp);
+ widgetList.append(widgt);
} else {
- WidgetList.append(temp);
+ widgetList.append(widgt);
}
}
- return true;
+ return widgetList;
}
/**
* Returns a list with all the selected associations from the diagram
*/
-AssociationWidgetList UMLScene::getSelectedAssocs()
+AssociationWidgetList UMLScene::selectedAssocs()
{
AssociationWidgetList assocWidgetList;
@@ -4216,8 +4218,7 @@
*/
void UMLScene::alignLeft()
{
- UMLWidgetList widgetList;
- getSelectedWidgets(widgetList);
+ UMLWidgetList widgetList = selectedWidgetsExt();
if (widgetList.isEmpty())
return;
@@ -4236,8 +4237,7 @@
*/
void UMLScene::alignRight()
{
- UMLWidgetList widgetList;
- getSelectedWidgets(widgetList);
+ UMLWidgetList widgetList = selectedWidgetsExt();
if (widgetList.isEmpty())
return;
qreal biggestX = WidgetList_Utils::getBiggestX(widgetList);
@@ -4255,8 +4255,7 @@
*/
void UMLScene::alignTop()
{
- UMLWidgetList widgetList;
- getSelectedWidgets(widgetList);
+ UMLWidgetList widgetList = selectedWidgetsExt();
if (widgetList.isEmpty())
return;
@@ -4275,8 +4274,7 @@
*/
void UMLScene::alignBottom()
{
- UMLWidgetList widgetList;
- getSelectedWidgets(widgetList);
+ UMLWidgetList widgetList = selectedWidgetsExt();
if (widgetList.isEmpty())
return;
qreal biggestY = WidgetList_Utils::getBiggestY(widgetList);
@@ -4294,8 +4292,7 @@
*/
void UMLScene::alignVerticalMiddle()
{
- UMLWidgetList widgetList;
- getSelectedWidgets(widgetList);
+ UMLWidgetList widgetList = selectedWidgetsExt();
if (widgetList.isEmpty())
return;
@@ -4316,8 +4313,7 @@
*/
void UMLScene::alignHorizontalMiddle()
{
- UMLWidgetList widgetList;
- getSelectedWidgets(widgetList);
+ UMLWidgetList widgetList = selectedWidgetsExt();
if (widgetList.isEmpty())
return;
@@ -4338,8 +4334,7 @@
*/
void UMLScene::alignVerticalDistribute()
{
- UMLWidgetList widgetList;
- getSelectedWidgets(widgetList);
+ UMLWidgetList widgetList = selectedWidgetsExt();
if (widgetList.isEmpty())
return;
@@ -4371,8 +4366,7 @@
*/
void UMLScene::alignHorizontalDistribute()
{
- UMLWidgetList widgetList;
- getSelectedWidgets(widgetList);
+ UMLWidgetList widgetList = selectedWidgetsExt();
if (widgetList.isEmpty())
return;
--- branches/work/soc-umbrello/umbrello/umlscene.h #1221606:1221607
@@ -196,10 +196,9 @@
void activate();
- AssociationWidgetList getSelectedAssocs();
+ AssociationWidgetList selectedAssocs();
+ UMLWidgetList selectedWidgetsExt(bool filterText = true);
- bool getSelectedWidgets(UMLWidgetList& WidgetList, bool filterText = true);
-
void activateAfterLoad(bool bUseLog = false);
void endPartialWidgetPaste();
--- branches/work/soc-umbrello/umbrello/umlview.cpp #1221606:1221607
@@ -4,34 +4,44 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * copyright (C) 2002-2010 *
+ * copyright (C) 2002-2011 *
* Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
***************************************************************************/
// own header
+#include "umlview.h"
+
+#include "debug_utils.h"
#include "docwindow.h"
-#include "umlview.h"
#include "umlscene.h"
#include "uml.h"
#include "umldoc.h"
#include "worktoolbar.h"
-// constructor
+#include <QtGui/QMouseEvent>
+
+/**
+ * Constructor
+ */
UMLView::UMLView(UMLFolder *f)
: QGraphicsView(UMLApp::app()->mainViewWidget())
{
m_nZoom = 100;
setAcceptDrops(true);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
-
setDragMode(RubberBandDrag);
// [PORT] For now the following is used. Shd check for creation of
// new scene later.
UMLScene *scene = new UMLScene(f);
setScene(scene);
setSceneRect(scene->sceneRect());
+
+ DEBUG_REGISTER(DBG_SRC);
}
+/**
+ * Destructor
+ */
UMLView::~UMLView()
{
//TODO: Check if the scene shd be deleted
@@ -57,7 +67,7 @@
}
/**
- * return the current zoom factor
+ * Return the current zoom factor.
*/
int UMLView::currentZoom()
{
@@ -78,6 +88,162 @@
setZoom((int)(wm.m11()*100.0));
}
+/**
+ * Sets the current centerpoint. Also updates the scene's center point.
+ * Unlike centerOn, which has no way of getting the floating point center
+ * back, setCenter() stores the center point. It also handles the special
+ * sidebar case. This function will claim the centerPoint to sceneRec ie.
+ * the centerPoint must be within the sceneRec.
+ */
+void UMLView::setCenter(const QPointF& centerPoint)
+{
+ // get the rectangle of the visible area in scene coords
+ QRectF visibleArea = mapToScene(rect()).boundingRect();
+
+ // get the scene area
+ QRectF sceneBounds = sceneRect();
+
+ double boundX = visibleArea.width() / 2.0;
+ double boundY = visibleArea.height() / 2.0;
+ double boundWidth = sceneBounds.width() - 2.0 * boundX;
+ double boundHeight = sceneBounds.height() - 2.0 * boundY;
+
+ // the max boundary that the centerPoint can be to
+ QRectF bounds(boundX, boundY, boundWidth, boundHeight);
+
+ if (bounds.contains(centerPoint)) {
+ // we are within the bounds
+ m_currentCenterPoint = centerPoint;
+ } else {
+ // we need to clamp or use the center of the screen
+ if(visibleArea.contains(sceneBounds)) {
+ // use the center of scene ie. we can see the whole scene
+ m_currentCenterPoint = sceneBounds.center();
+ } else {
+
+ m_currentCenterPoint = centerPoint;
+
+ // we need to clamp the center. The centerPoint is too large
+ if (centerPoint.x() > bounds.x() + bounds.width()) {
+ m_currentCenterPoint.setX(bounds.x() + bounds.width());
+ } else if (centerPoint.x() < bounds.x()) {
+ m_currentCenterPoint.setX(bounds.x());
+ }
+
+ if (centerPoint.y() > bounds.y() + bounds.height()) {
+ m_currentCenterPoint.setY(bounds.y() + bounds.height());
+ } else if (centerPoint.y() < bounds.y()) {
+ m_currentCenterPoint.setY(bounds.y());
+ }
+
+ }
+ }
+ // update the scrollbars
+ centerOn(m_currentCenterPoint);
+}
+
+/**
+ * Get the center.
+ */
+QPointF UMLView::center()
+{
+ return m_currentCenterPoint;
+}
+
+/**
+ * Handles when the mouse button is pressed.
+ */
+/*:TODO:
+void UMLView::mousePressEvent(QMouseEvent* event)
+{
+ // for panning the view
+ m_lastPanPoint = event->pos();
+}
+*/
+
+/**
+ * Handles when the mouse button is released.
+ */
+/*:TODO:
+void UMLView::mouseReleaseEvent(QMouseEvent* event)
+{
+ Q_UNUSED(event);
+ m_lastPanPoint = QPoint();
+}
+*/
+
+/**
+ * Handles the mouse move event.
+ */
+/*:TODO:
+void UMLView::mouseMoveEvent(QMouseEvent* event)
+{
+ if (!m_lastPanPoint.isNull()) {
+ // get how much we panned
+ QPointF delta = mapToScene(m_lastPanPoint) - mapToScene(event->pos());
+ m_lastPanPoint = event->pos();
+
+ // update the center ie. do the pan
+ setCenter(center() + delta);
+ }
+}
+*/
+
+/**
+ * Zoom the view in and out.
+ */
+void UMLView::wheelEvent(QWheelEvent* event)
+{
+ // get the position of the mouse before scaling, in scene coords
+ QPointF pointBeforeScale(mapToScene(event->pos()));
+
+ // get the original screen centerpoint
+ QPointF screenCenter = center();
+
+ // scale the view ie. do the zoom
+ double scaleFactor = 1.15;
+ if (event->delta() > 0) {
+ // zoom in
+ if (currentZoom() < 500) {
+ scale(scaleFactor, scaleFactor);
+ }
+ } else {
+ // zooming out
+ if (currentZoom() > 10) {
+ scale(1.0 / scaleFactor, 1.0 / scaleFactor);
+ }
+ }
+
+ // get the position after scaling, in scene coords
+ QPointF pointAfterScale(mapToScene(event->pos()));
+
+ // get the offset of how the screen moved
+ QPointF offset = pointBeforeScale - pointAfterScale;
+
+ // adjust to the new center for correct zooming
+ QPointF newCenter = screenCenter + offset;
+ setCenter(newCenter);
+
+ DEBUG(DBG_SRC) << "currentZoom=" << currentZoom();
+}
+
+/**
+ * Need to update the center so there is no jolt in the
+ * interaction after resizing the widget.
+ */
+void UMLView::resizeEvent(QResizeEvent* event)
+{
+ // get the rectangle of the visible area in scene coords
+ QRectF visibleArea = mapToScene(rect()).boundingRect();
+ setCenter(visibleArea.center());
+
+ // call the subclass resize so the scrollbars are updated correctly
+ QGraphicsView::resizeEvent(event);
+}
+
+/**
+ * Event handler for the show event.
+ */
void UMLView::showEvent(QShowEvent* /*se*/)
{
UMLApp* theApp = UMLApp::app();
@@ -96,6 +262,9 @@
}
+/**
+ * Event handler for the hide event.
+ */
void UMLView::hideEvent(QHideEvent* /*he*/)
{
UMLApp* theApp = UMLApp::app();
@@ -119,6 +288,9 @@
QWidget::closeEvent(e);
}
+/**
+ * Getter for the scene.
+ */
UMLScene* UMLView::umlScene() const
{
return qobject_cast<UMLScene*>(scene());
--- branches/work/soc-umbrello/umbrello/umlview.h #1221606:1221607
@@ -4,14 +4,14 @@
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
- * copyright (C) 2002-2009 *
+ * copyright (C) 2002-2011 *
* Umbrello UML Modeller Authors <uml-devel at uml.sf.net> *
***************************************************************************/
#ifndef UMLVIEW_H
#define UMLVIEW_H
-#include <QGraphicsView>
+#include <QtGui/QGraphicsView>
class QHideEvent;
class QCloseEvent;
@@ -33,42 +33,32 @@
{
Q_OBJECT
public:
-
- /**
- * Constructor
- */
UMLView(UMLFolder *f );
-
- /**
- * Destructor
- */
virtual ~UMLView();
- int getZoom() const {
- return m_nZoom;
- }
-
+ int zoom() const { return m_nZoom; }
void setZoom(int zoom);
-
int currentZoom();
void hideEvent(QHideEvent *he);
-
void showEvent(QShowEvent *se);
UMLScene* umlScene() const;
protected:
+ void closeEvent(QCloseEvent * e);
- /**
- * The zoom level in percent, default 100
- */
- int m_nZoom;
+ void setCenter(const QPointF& centerPoint);
+ QPointF center();
- void closeEvent ( QCloseEvent * e );
+ virtual void wheelEvent(QWheelEvent* event);
+ virtual void resizeEvent(QResizeEvent* event);
-public slots:
+ QPointF m_currentCenterPoint; ///< holds the current centerpoint for the view, used for panning and zooming
+ QPoint m_lastPanPoint; ///< from panning the view
+ int m_nZoom; ///< zoom level in percent, default 100
+public slots:
void zoomIn();
void zoomOut();
void show();
More information about the umbrello-devel
mailing list