summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Fischer <[email protected]>2015-04-03 09:43:55 +0200
committerAndi Fischer <[email protected]>2015-05-01 15:31:05 +0200
commit5e60ccdf7aaaa1d304df7e7741d50764c2edff03 (patch)
tree8088dbd2b8562ca591c8c2f13992ba74c517ce15
parent6457ef70622e5651989567d434d508b9e05cbbd0 (diff)
BirdView improved.
-rw-r--r--umbrello/birdview.cpp74
-rw-r--r--umbrello/birdview.h1
-rw-r--r--umbrello/uml.cpp2
3 files changed, 36 insertions, 41 deletions
diff --git a/umbrello/birdview.cpp b/umbrello/birdview.cpp
index dfb263f..5ed647c 100644
--- a/umbrello/birdview.cpp
+++ b/umbrello/birdview.cpp
@@ -28,7 +28,7 @@
#include <QGraphicsView>
#include <QMouseEvent>
#include <QScrollBar>
-//#include <QTimer>
+#include <QTimer>
DEBUG_REGISTER(BirdView)
@@ -43,9 +43,10 @@ BirdView::BirdView(QDockWidget *parent, UMLView* view)
{
// create view and add it to the container frame
UMLScene* scene = m_view->umlScene();
- m_birdView = new QGraphicsView(scene); //A: , container);
+ m_birdView = new QGraphicsView(scene);
m_birdView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_birdView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ m_birdView->setFrameStyle(QFrame::Box); //:TODO: remove this line - only for debugging
// create a frame on top of the view to hide it from the mouse
m_protectFrame = new QFrame(m_birdView);
@@ -53,7 +54,7 @@ BirdView::BirdView(QDockWidget *parent, UMLView* view)
setBackgroundColor(m_protectFrame, QColor(255, 255, 220, 0));
// draw window frame in the size of shown scene
- setParent(m_protectFrame);
+ setParent(m_birdView); //m_protectFrame);
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
setLineWidth(1);
setMidLineWidth(2);
@@ -61,7 +62,6 @@ BirdView::BirdView(QDockWidget *parent, UMLView* view)
setBackgroundColor(this, QColor(115, 205, 240, 100));
slotDockSizeChanged(parent->rect().size());
- slotViewChanged();
setSlotsEnabled(true);
parent->setWidget(m_birdView); // must be the last command
@@ -81,16 +81,16 @@ BirdView::~BirdView()
*/
void BirdView::slotDockSizeChanged(const QSize& size)
{
- QRectF maxRect = m_birdView->scene()->itemsBoundingRect();
- m_birdView->scene()->setSceneRect(maxRect);
- m_birdView->setSceneRect(maxRect);
- m_birdView->fitInView(maxRect, Qt::KeepAspectRatio);
+ QRectF itemsRect = m_birdView->scene()->itemsBoundingRect();
+ m_birdView->scene()->setSceneRect(itemsRect);
+ m_birdView->setSceneRect(itemsRect);
+ m_birdView->fitInView(itemsRect, Qt::KeepAspectRatio);
- QRect viewRect = QRect(0, 0, size.width(), size.height());
- m_protectFrame->setGeometry(viewRect);
+ QRect frameRect = QRect(0, 0, size.width(), size.height());
+ m_protectFrame->setGeometry(frameRect);
- qreal scaleW = viewRect.width() / m_birdView->scene()->width();
- qreal scaleH = viewRect.height() / m_birdView->scene()->height();
+ qreal scaleW = frameRect.width() / m_birdView->scene()->width();
+ qreal scaleH = frameRect.height() / m_birdView->scene()->height();
qreal scale = scaleH;
if (scaleW < scaleH) {
scale = scaleW;
@@ -98,16 +98,12 @@ void BirdView::slotDockSizeChanged(const QSize& size)
QMatrix wm;
wm.scale(scale, scale);
m_birdView->setMatrix(wm);
-#if 0
- DEBUG(DBG_SRC) << "setting the size to the container: " << maxRect
- << " / to the view: " << viewRect
+#if 1
+ DEBUG(DBG_SRC) << "setting the size to the scene: " << itemsRect
+ << " / to the frame: " << frameRect
<< " / scaleW: " << scaleW << " / scaleH: " << scaleH << " / scale: " << scale;
#endif
-
-//:TODO:crash
-// QMetaObject::invokeMethod(this, "slotViewChanged", Qt::AutoConnection);
-// QTimer::singleShot(0, this, SLOT(slotViewChanged()));
-// emit sigSizeChanged();
+ QTimer::singleShot(0, this, SLOT(slotViewChanged()));
}
/**
@@ -127,8 +123,8 @@ void BirdView::slotViewChanged()
hmin = hScroll->minimum();
hmax = hScroll->maximum();
hpage = hScroll->pageStep();
- hlen = abs(hmax) - hmin + 2 * hpage;
-#if 0
+ hlen = abs(hmax - hmin) + hpage;
+#if 1
DEBUG(DBG_SRC) << "hvalue: " << hvalue << " / hlen: " << hlen
<< " / hmin: " << hmin << " / hmax: " << hmax
<< " / hpage: " << hpage;
@@ -146,31 +142,35 @@ void BirdView::slotViewChanged()
vmin = vScroll->minimum();
vmax = vScroll->maximum();
vpage = vScroll->pageStep();
- vlen = abs(vmax) - vmin + 2 * vpage;
-#if 0
+ vlen = abs(vmax - vmin) + vpage;
+#if 1
DEBUG(DBG_SRC) << "vvalue: " << vvalue << " / vlen: " << vlen
<< " / vmin: " << vmin << " / vmax: " << vmax
<< " / vpage: " << vpage;
#endif
}
- int hdiv = hlen - hpage;
- int vdiv = vlen - vpage;
- if (!(hvalue == 0) && !(vvalue == 0) &&
- !(hdiv == 0) && !(vdiv == 0)) {
- int width = m_protectFrame->width() * hpage / hdiv;
- int height = m_protectFrame->height() * vpage / vdiv;
- int x = m_protectFrame->width() * (hvalue - hmin) / hdiv;
- if (x + width > hmax) {
+ if (!((hmin == 0) && (hmax == 0)) |
+ !((vmin == 0) && (vmax == 0))) {
+ int width = m_protectFrame->width() * hpage / hlen;
+ int height = m_protectFrame->height() * vpage / vlen;
+ int x = m_protectFrame->width() * (hvalue - hmin) / hlen;
+ if (x > (hmax - width)) {
x = hmax - width;
}
- int y = m_protectFrame->height() * (vvalue - vmin) / vdiv;
- if (y + height > vmax) {
+ if (x <= hmin) {
+ x = hmin;
+ }
+ int y = m_protectFrame->height() * (vvalue - vmin) / vlen;
+ if (y > (vmax - height)) {
y = vmax - height;
}
+ if (y <= vmin) {
+ y = vmin;
+ }
QRect rect = QRect(x, y, width, height);
setGeometry(rect);
-#if 0
+#if 1
DEBUG(DBG_SRC) << "rect: " << rect;
#endif
}
@@ -239,16 +239,12 @@ void BirdView::setSlotsEnabled(bool enabled)
this, SLOT(slotViewChanged()));
connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(slotViewChanged()));
- connect(this, SIGNAL(sigSizeChanged()), //:TODO: remove
- this, SLOT(slotViewChanged()));
}
else {
disconnect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(slotViewChanged()));
disconnect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(slotViewChanged()));
- disconnect(this, SIGNAL(sigSizeChanged()), //:TODO: remove
- this, SLOT(slotViewChanged()));
}
}
diff --git a/umbrello/birdview.h b/umbrello/birdview.h
index 35e9ecf..18a6add 100644
--- a/umbrello/birdview.h
+++ b/umbrello/birdview.h
@@ -72,7 +72,6 @@ public:
signals:
void viewPositionChanged(QPoint delta);
- void sigSizeChanged(); //:TODO: remove
public slots:
void slotViewChanged();
diff --git a/umbrello/uml.cpp b/umbrello/uml.cpp
index da8aa95..2b6818f 100644
--- a/umbrello/uml.cpp
+++ b/umbrello/uml.cpp
@@ -202,6 +202,7 @@ UMLApp::UMLApp(QWidget* parent)
*/
UMLApp::~UMLApp()
{
+ delete m_birdView;
delete m_imageExporterAll;
delete m_clipTimer;
delete m_copyTimer;
@@ -209,7 +210,6 @@ UMLApp::~UMLApp()
delete m_pUndoStack;
delete m_printer;
delete m_d;
- delete m_birdView;
}
/**