Skip to content

Commit

Permalink
* Laying background to enable swipe on GraphicSlidingDownBts
Browse files Browse the repository at this point in the history
 * Moving touch out of the bt "cancels" the click :D
  • Loading branch information
cpscotti committed Mar 3, 2011
1 parent c17c1b6 commit e16ad14
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
30 changes: 28 additions & 2 deletions PushBurton2/graphicslidingdownbts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ GraphicSlidingDownBts::GraphicSlidingDownBts(QGraphicsItem* parent) : QGraphicsO

rootState = new QState();
chooserState = new QState(rootState);
connect(chooserState, SIGNAL(entered()), this, SLOT(entered_chooser()));
connect(chooserState, SIGNAL(exited()), this, SLOT(exited_chooser()));

// machine.setGlobalRestorePolicy(QStateMachine::RestoreProperties);
machine.addState(rootState);
machine.setInitialState(rootState);
rootState->setInitialState(chooserState);

initial_selection = -1;
isOnChooser = false;
}

void GraphicSlidingDownBts::setBtsRect(const QRectF& a_btsrect)
Expand All @@ -62,6 +65,8 @@ void GraphicSlidingDownBts::addBt(QString text, QString value)
newBt->setBtRect(btsRect);
newBt->setPos(0,0);
newBt->setZValue(1.0);
connect(newBt, SIGNAL(v_swipe_hint(qreal)), this, SLOT(get_swipe_hints(qreal)));
connect(this, SIGNAL(do_swipe(qreal)), newBt, SLOT(v_swipe_action(qreal)));
push_back(newBt, value);
}

Expand All @@ -71,7 +76,7 @@ void GraphicSlidingDownBts::push_back(GraphicTextBt* newBt, QString val)
selectedStates.push_back(newState);
graphicBts.push_back(newBt);

newState->addTransition(newBt, SIGNAL(activated()), chooserState);
newState->addTransition(newBt, SIGNAL(released()), chooserState);
// newState->assignProperty(newBt, "y", 0);

connect(newState, SIGNAL(entered()), selectedMapper, SLOT(map()));
Expand Down Expand Up @@ -100,7 +105,7 @@ void GraphicSlidingDownBts::construction_finished()
for(int i=0;i < cnt;i++)
{
chooserState->assignProperty(graphicBts[i], "y", 60*i);//chooser position for all bts (unfolded down)
chooserState->addTransition(graphicBts[i], SIGNAL(activated()), selectedStates[i]);
chooserState->addTransition(graphicBts[i], SIGNAL(released()), selectedStates[i]);
}

if(cnt > 0)
Expand Down Expand Up @@ -136,4 +141,25 @@ void GraphicSlidingDownBts::paint(QPainter *painter, const QStyleOptionGraphicsI
void GraphicSlidingDownBts::inn_selected(const QString& val)
{
qDebug() << "Inner selection is " << val;
lastInnSelection = val;
}


void GraphicSlidingDownBts::get_swipe_hints(qreal ydif)
{
// if(isOnChooser) {
// emit do_swipe(ydif);
// }
}

void GraphicSlidingDownBts::entered_chooser()
{
isOnChooser = true;
//start timer
}

void GraphicSlidingDownBts::exited_chooser()
{
isOnChooser = false;
//stop timer
}
14 changes: 14 additions & 0 deletions PushBurton2/graphicslidingdownbts.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <QVector>
#include <QSignalMapper>
#include <QStateMachine>

#include <QPropertyAnimation>

#include "graphictextbt.h"
Expand Down Expand Up @@ -68,6 +69,8 @@ private slots:

int initial_selection;

bool isOnChooser;

QRectF btsRect;

QVector<GraphicTextBt*> graphicBts;
Expand All @@ -76,6 +79,17 @@ private slots:
QState * chooserState;
QStateMachine machine;
QSignalMapper * selectedMapper;

QString lastInnSelection;

signals:
void do_swipe(qreal ydif);

public slots:
void get_swipe_hints(qreal ydif);
void entered_chooser();
void exited_chooser();

};

#endif // GRAPHICSLIDINGDOWNBTS_H
32 changes: 29 additions & 3 deletions PushBurton2/graphictextbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,46 @@ void GraphicTextBt::paint(QPainter *painter, const QStyleOptionGraphicsItem *,QW
painter->drawText(btRect, Qt::AlignCenter, text);
}

void GraphicTextBt::mousePressEvent(QGraphicsSceneMouseEvent *)
void GraphicTextBt::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
firstTch = event->screenPos();
prevTch = event->screenPos();

if(!toggled) {
emit activated();
toggled = true;
this->update();
}
}

void GraphicTextBt::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
void GraphicTextBt::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
QPoint now = event->screenPos();
qreal entireFlight = sqrt(pow(now.x() - firstTch.x(),2.0) + pow(now.y() - firstTch.y(),2.0));

if(toggled) {
emit released();
// qDebug() << "entireFlight = " << entireFlight;
if(fabs(entireFlight) < 30.0) {
emit released();
}
toggled = false;
this->update();
}
}

void GraphicTextBt::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
{
QPoint now = event->screenPos();
qreal vertFlight = now.y() - prevTch.y();
// qDebug() << "entireFlight = " << entireFlight;
// qreal entireFlight = now.x() - prevTch.x();
emit v_swipe_hint(vertFlight);
prevTch = now;

}

void GraphicTextBt::v_swipe_action(qreal dif)
{
QVariant oldY = this->property("y");
this->setProperty("y", oldY.toFloat()+dif);
}
12 changes: 12 additions & 0 deletions PushBurton2/graphictextbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
#define GRAPHICTEXTBT_H

#include <QGraphicsObject>
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
#include <QString>
#include <QFont>
#include <QColor>

#include <QDebug>
#include <qmath.h>

class GraphicTextBt : public QGraphicsObject
{
Expand All @@ -53,15 +55,25 @@ class GraphicTextBt : public QGraphicsObject
void activated();
void released();

public slots:
void v_swipe_action(qreal dif);
signals:
void v_swipe_hint(qreal ydrag);

protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);

private:
bool toggled;
QString text;
QColor textColor;
QRectF btRect;

QPoint firstTch;
QPoint prevTch;

};

#endif // GRAPHICTEXTBT_H

0 comments on commit e16ad14

Please sign in to comment.