Skip to content

Commit

Permalink
Overview Animate View Transition
Browse files Browse the repository at this point in the history
.. no more jarring fit to view transitions and it
   *finally* starts to feel like a polished UX

.. need to look at handling scrolling next.
  • Loading branch information
liversedge committed Jan 29, 2017
1 parent 23031f7 commit a75b26c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
53 changes: 45 additions & 8 deletions src/Charts/OverviewWindow.cpp
Expand Up @@ -71,6 +71,10 @@ OverviewWindow::OverviewWindow(Context *context) :
// set the widgets etc
configChanged(CONFIG_APPEARANCE);

// for changing the view
viewchange = new QPropertyAnimation(this, "viewRect");
viewchange->setEasingCurve(QEasingCurve(QEasingCurve::OutQuint));

// sort out the view
updateGeometry();

Expand Down Expand Up @@ -220,17 +224,50 @@ OverviewWindow::updateView()

// don'r scale whilst resizing on x?
if (state != XRESIZE && state != DRAG) {
// fit to scene width XXX need to fix scrollbars.
double scale = view->frameGeometry().width() / scene->sceneRect().width();
QRectF viewRect(0,0, scene->sceneRect().width(), view->frameGeometry().height() / scale);
view->scale(scale,scale);
view->setSceneRect(viewRect);

view->fitInView(viewRect, Qt::KeepAspectRatio);
view->update();

// much of a resize / change ?
double dx = fabs(viewRect.x() - sceneRect.x());
double dy = fabs(viewRect.y() - sceneRect.y());
double dwidth = fabs(viewRect.width() - sceneRect.width());
double dheight = fabs(viewRect.height() - sceneRect.height());

// scale immediately if not a bit change
// otherwise it feels unresponsive
if (viewRect.width() == 0 || (dx < 20 && dy < 20 && dwidth < 20 && dheight < 20)) {
setViewRect(sceneRect);
} else {

// tempting to make this longer but feels ponderous at longer durations
viewchange->setDuration(400);
viewchange->setStartValue(viewRect);
viewchange->setEndValue(sceneRect);
viewchange->start();
}
}
}

void
OverviewWindow::setViewRect(QRectF rect)
{
//static bool __block = false;
//if (__block) return;

//__block = true;
viewRect = rect;

// fit to scene width XXX need to fix scrollbars.
double scale = view->frameGeometry().width() / viewRect.width();
QRectF scaledRect(0,0, viewRect.width(), view->frameGeometry().height() / scale);

// scale to selection
view->scale(scale,scale);
view->setSceneRect(scaledRect);
view->fitInView(scaledRect, Qt::KeepAspectRatio);
view->update();

//__block = false;
}

bool
OverviewWindow::eventFilter(QObject *, QEvent *event)
{
Expand Down
11 changes: 11 additions & 0 deletions src/Charts/OverviewWindow.h
Expand Up @@ -69,6 +69,8 @@ class OverviewWindow : public GcChartWindow
{
Q_OBJECT

Q_PROPERTY(QRectF viewRect READ getViewRect WRITE setViewRect)

public:

OverviewWindow(Context *context);
Expand All @@ -79,6 +81,9 @@ class OverviewWindow : public GcChartWindow
// current state for event processing
enum { NONE, DRAG, XRESIZE, YRESIZE } state;

void setViewRect(QRectF);
QRectF getViewRect() const { return viewRect; }

public slots:

// trap signals
Expand Down Expand Up @@ -113,8 +118,14 @@ class OverviewWindow : public GcChartWindow
Context *context;
QGraphicsScene *scene;
QGraphicsView *view;

// for animating transitions
QParallelAnimationGroup *group;
QPropertyAnimation *viewchange;

// scene and view
QRectF sceneRect;
QRectF viewRect;

// content
QVector<int> columns; // column widths
Expand Down

0 comments on commit a75b26c

Please sign in to comment.