[Simulator] Navigation buttons in radio UIs are now animated in response to keyboard shortcuts.
This commit is contained in:
@@ -27,9 +27,44 @@
|
|||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
|
|
||||||
|
class Area : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Area(const QPolygon & polygon, const QString &image, RadioUiAction * action = NULL, QObject * parent = NULL):
|
||||||
|
QObject(parent),
|
||||||
|
polygon(polygon),
|
||||||
|
imgFile(image),
|
||||||
|
action(action)
|
||||||
|
{
|
||||||
|
if (action)
|
||||||
|
connect(action, &RadioUiAction::triggered, this, &Area::onActionTriggered);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool contains(int x, int y)
|
||||||
|
{
|
||||||
|
return polygon.containsPoint(QPoint(x, y), Qt::OddEvenFill);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onActionTriggered(int, bool active)
|
||||||
|
{
|
||||||
|
if (active)
|
||||||
|
emit imageChanged(imgFile);
|
||||||
|
else
|
||||||
|
emit imageChanged("");
|
||||||
|
}
|
||||||
|
|
||||||
|
QPolygon polygon;
|
||||||
|
QString imgFile;
|
||||||
|
RadioUiAction * action;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void imageChanged(const QString image);
|
||||||
|
};
|
||||||
|
|
||||||
class ButtonsWidget : public QWidget
|
class ButtonsWidget : public QWidget
|
||||||
{
|
{
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -54,59 +89,39 @@ class ButtonsWidget : public QWidget
|
|||||||
|
|
||||||
void addArea(const QPolygon & polygon, const char * image, RadioUiAction * action = NULL)
|
void addArea(const QPolygon & polygon, const char * image, RadioUiAction * action = NULL)
|
||||||
{
|
{
|
||||||
areas.push_back(Area(polygon, image, action));
|
Area * area = new Area(polygon, image, action, this);
|
||||||
|
areas.push_back(area);
|
||||||
|
connect(area, &Area::imageChanged, this, &ButtonsWidget::setBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
class Area
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Area(const QPolygon & polygon, const QString &image, RadioUiAction * action = NULL):
|
|
||||||
polygon(polygon),
|
|
||||||
imgFile(image),
|
|
||||||
action(action)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool contains(int x, int y)
|
|
||||||
{
|
|
||||||
return polygon.containsPoint(QPoint(x, y), Qt::OddEvenFill);
|
|
||||||
}
|
|
||||||
|
|
||||||
QPolygon polygon;
|
|
||||||
QString imgFile;
|
|
||||||
RadioUiAction * action;
|
|
||||||
};
|
|
||||||
|
|
||||||
void setBitmap(QString bitmap)
|
void setBitmap(QString bitmap)
|
||||||
{
|
{
|
||||||
if (!bitmap.isEmpty()) {
|
QString css = defaultStyleSheet;
|
||||||
QWidget::setStyleSheet(QString("background:url(:/images/simulator/%1);").arg(bitmap));
|
if (!bitmap.isEmpty())
|
||||||
}
|
css = QString("background:url(:/images/simulator/%1);").arg(bitmap);
|
||||||
else {
|
|
||||||
QWidget::setStyleSheet(defaultStyleSheet);
|
QWidget::setStyleSheet(css);
|
||||||
}
|
setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onMouseButtonEvent(bool press, QMouseEvent * event)
|
void onMouseButtonEvent(bool press, QMouseEvent * event)
|
||||||
{
|
{
|
||||||
bool trig;
|
bool anyTriggered = false;
|
||||||
QString img = "";
|
|
||||||
int x = event->x();
|
int x = event->x();
|
||||||
int y = event->y();
|
int y = event->y();
|
||||||
|
|
||||||
foreach(Area area, areas) {
|
foreach(Area * area, areas) {
|
||||||
trig = false;
|
if (event->button() == Qt::LeftButton && area->contains(x, y)) {
|
||||||
if (press && event->button() == Qt::LeftButton && area.contains(x, y)) {
|
if (area->action)
|
||||||
img = area.imgFile;
|
area->action->trigger(press);
|
||||||
setFocus();
|
anyTriggered = true;
|
||||||
trig = true;
|
break;
|
||||||
}
|
}
|
||||||
if (area.action)
|
|
||||||
area.action->trigger(trig);
|
|
||||||
}
|
}
|
||||||
setBitmap(img);
|
if (!anyTriggered)
|
||||||
|
setBitmap("");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void mousePressEvent(QMouseEvent * event)
|
virtual void mousePressEvent(QMouseEvent * event)
|
||||||
@@ -130,9 +145,7 @@ class ButtonsWidget : public QWidget
|
|||||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
QList<Area *> areas;
|
||||||
|
|
||||||
QList<Area> areas;
|
|
||||||
QString defaultStyleSheet;
|
QString defaultStyleSheet;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user