Skip to content

Commit

Permalink
Overview Window Animated Layout
Browse files Browse the repository at this point in the history
.. as the layout changes we animate.

.. in the prototype you click on a rectangle to remove it,
   which triggers the rest of the items to fall up into
   the space vacated.

.. now the animation is in place we can start working on
   the click to drag and relocate as we move the cursor
  • Loading branch information
liversedge committed Jan 24, 2017
1 parent a5c30d5 commit 76cf1e8
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 14 deletions.
74 changes: 67 additions & 7 deletions src/Charts/OverviewWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <QGraphicsSceneMouseEvent>

OverviewWindow::OverviewWindow(Context *context) :
GcChartWindow(context), context(context)
GcChartWindow(context), context(context), group(NULL)
{
setContentsMargins(0,0,0,0);
setProperty("color", GColor(COVERVIEWBACKGROUND));
Expand Down Expand Up @@ -63,6 +63,22 @@ OverviewWindow::OverviewWindow(Context *context) :
newCard(3, 2, 10);
newCard(3, 3, 5);
newCard(3, 4, 10);
newCard(4, 1, 5);
newCard(4, 2, 10);
newCard(4, 3, 10);
newCard(4, 4, 5);
newCard(5, 1, 10);
newCard(5, 2, 5);
newCard(5, 3, 10);
newCard(5, 4, 5);
newCard(6, 1, 10);
newCard(6, 2, 5);
newCard(6, 3, 10);
newCard(6, 4, 5);
newCard(7, 1, 5);
newCard(7, 2, 10);
newCard(7, 3, 5);
newCard(7, 4, 10);

// set the widgets etc
configChanged(CONFIG_APPEARANCE);
Expand Down Expand Up @@ -94,6 +110,7 @@ static bool cardSort(const Card* left, const Card* right)
void
OverviewWindow::updateGeometry()
{
bool animated=false;

// order the items to their positions
qSort(cards.begin(), cards.end(), cardSort);
Expand All @@ -104,6 +121,9 @@ OverviewWindow::updateGeometry()
// just set their geometry for now, no interaction
for(int i=0; i<cards.count(); i++) {

// don't show hidden
if (!cards[i]->isVisible()) continue;

// move on to next column
if (cards[i]->column > column) { y=25; column = cards[i]->column; }

Expand All @@ -113,19 +133,44 @@ OverviewWindow::updateGeometry()
int twidth = 400;
int theight = cards[i]->deep * 25;

cards[i]->setGeometry(tx, ty, twidth, theight);

// add to scene if new
if (!cards[i]->onscene) {
cards[i]->setGeometry(tx, ty, twidth, theight);
scene->addItem(cards[i]);
qDebug()<<"add col,order:"<<cards[i]->column<<cards[i]->order<<"y,x,width,height"<<ty<<tx<<twidth<<theight;
cards[i]->onscene = true;

} else if (cards[i]->geometry().x() != tx ||
cards[i]->geometry().y() != ty ||
cards[i]->geometry().width() != twidth ||
cards[i]->geometry().height() != theight) {

// its moved, so animate that.
if (animated == false) {

// we've got an animation to perform
animated = true;

// we're starting to animate so clear and restart any animations
if (group) group->clear();
else group = new QParallelAnimationGroup(this);
}

// add an animation for this movement
QPropertyAnimation *animation = new QPropertyAnimation(cards[i], "geometry");
animation->setDuration(200);
animation->setStartValue(cards[i]->geometry());
animation->setEndValue(QRect(tx,ty,twidth,theight));
animation->setEasingCurve(QEasingCurve(QEasingCurve::InSine));

group->addAnimation(animation);
}

// set spot for next tile
y += theight + 25;
}
qDebug()<<"scene="<<scene->itemsBoundingRect();

if (animated) group->start();
}

void
Expand Down Expand Up @@ -192,16 +237,31 @@ OverviewWindow::eventFilter(QObject *, QEvent *event)

}

} else if (event->type() == QEvent::GraphicsSceneMouseMove) {
} else if (event->type() == QEvent::GraphicsSceneMousePress) {

// where am i ?
QPointF pos = static_cast<QGraphicsSceneMouseEvent*>(event)->scenePos();
QGraphicsItem *item = scene->itemAt(pos, view->transform());

qDebug()<<"mouse:"<<pos;
if (item) {
qDebug()<<"POP..";
static_cast<Card*>(item)->clicked();
updateGeometry();
scene->update();
view->update();
}
}
return returning;
}


void
Card::clicked()
{
if (isVisible()) hide();
else show();

//if (brush.color() == GColor(CCARDBACKGROUND)) brush.setColor(Qt::red);
//else brush.setColor(GColor(CCARDBACKGROUND));

update(geometry());
}
21 changes: 18 additions & 3 deletions src/Charts/OverviewWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include <QGraphicsView>
#include <QGraphicsWidget>

// qt
#include <QtGui>

class OverviewWindow;

// keep it simple for now
Expand All @@ -40,15 +43,24 @@ class Card : public QGraphicsWidget

Card(int deep) : QGraphicsWidget(NULL), column(0), order(0), deep(deep), onscene(false) {
setAutoFillBackground(true);
brush = QBrush(GColor(CCARDBACKGROUND));
}

// what to do if clicked XXX just a hack for now
void clicked();

// which column, sequence and size in rows
int column, order, deep;
bool onscene;
};

// qt
#include <QtGui>
void paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *p=0) {
painter->setBrush(brush);
painter->fillRect(QRectF(0,0,geometry().width(),geometry().height()), brush);

}

QBrush brush;
};

class OverviewWindow : public GcChartWindow
{
Expand Down Expand Up @@ -89,6 +101,9 @@ class OverviewWindow : public GcChartWindow

QList<Card*> cards;

// for animating
QParallelAnimationGroup *group;

};

#endif // _GC_OverviewWindow_h
11 changes: 7 additions & 4 deletions src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,16 @@ greaterThan(QT_MAJOR_VERSION, 4) {
greaterThan(QT_MINOR_VERSION, 6) {
QT += charts

# overview in the new summary chart with moveable tiles
DEFINES += GC_HAVE_OVERVIEW
HEADERS += Charts/OverviewWindow.h
SOURCES += Charts/OverviewWindow.cpp
}
}

# whilst its just a QGraphics prototype lets always enable it
# as soon as we need qt charts for the cards we can remove it
# overview in the new summary chart with moveable tiles
DEFINES += GC_HAVE_OVERVIEW
HEADERS += Charts/OverviewWindow.h
SOURCES += Charts/OverviewWindow.cpp


###=====================
### LEX AND YACC SOURCES
Expand Down

0 comments on commit 76cf1e8

Please sign in to comment.