Skip to content
Extraits de code Groupes Projets
Valider 2a0a3be8 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Move mousePressEvent from view to scene

parent 6e39d083
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!3Add documents
......@@ -10,6 +10,7 @@
#include <QMessageBox>
#include <QMouseEvent>
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
TimingScene::TimingScene(QWidget *parent) noexcept
: QGraphicsScene(parent)
......@@ -23,3 +24,19 @@ TimingScene::TimingScene(QImage img, QWidget *parent) noexcept
QPixmap pixmap(QPixmap::fromImage(img));
backgroundImg = addPixmap(pixmap);
}
void
TimingScene::mousePressEvent(QGraphicsSceneMouseEvent *event) noexcept
{
QPointF pos = event->scenePos();
fprintf(stderr, "%f,%f\n", pos.x(), pos.y());
QGraphicsItem *got;
if ((got = itemAt(pos, QTransform())) == nullptr || got == backgroundImg) {
addItem(new TimingBar(QLine(pos.x(), 0, pos.x(), height()),
event->button() == Qt::LeftButton ? startColour : endColour));
}
QGraphicsScene::mousePressEvent(event);
}
......@@ -30,6 +30,8 @@ private:
public:
inline QGraphicsPixmapItem* bg() { return backgroundImg; };
void mousePressEvent(QGraphicsSceneMouseEvent *event) noexcept override;
public slots:
};
......
......@@ -23,19 +23,3 @@ TimingView::TimingView(QImage img, QWidget *parent) noexcept
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setScene(scene);
}
void
TimingView::mousePressEvent(QMouseEvent *event) noexcept
{
QPoint pos = event->pos();
pos.rx() += horizontalScrollBar()->value();
int x = event->pos().x() + horizontalScrollBar()->value();
QGraphicsItem *got;
if ((got = scene->itemAt(pos, QTransform())) == nullptr || got == scene->bg()) {
scene->addItem(new TimingBar(QLine(x, 0, x, scene->height()),
event->button() == Qt::LeftButton ? startColour : endColour));
}
QGraphicsView::mousePressEvent(event);
}
......@@ -28,8 +28,6 @@ public:
private:
TimingScene* scene;
void mousePressEvent(QMouseEvent *event) noexcept;
public slots:
};
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter