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

Add currentLine to TimingScene and basic placement action

parent 2a0a3be8
Branches
Aucune étiquette associée trouvée
1 requête de fusion!3Add documents
......@@ -20,6 +20,17 @@ public:
Line& operator=(const Line&) = delete;
~Line() noexcept = default;
inline void setStart(quint64 s){
start = s;
if (s > end)
end = s;
};
inline void setEnd(quint64 s){
end = s;
if (start > s)
start = s;
};
};
#endif // VIVY_ASS_LINE_H
......@@ -16,7 +16,7 @@ AudioVisualizer::AudioVisualizer(QWidget *parent) noexcept
void
AudioVisualizer::printSpectrum(QImage pixmap) noexcept
{
TimingView *timer = new TimingView(pixmap);
TimingView *timer = new TimingView(pixmap, 0);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(timer);
......
......@@ -8,6 +8,7 @@
#include "../Utils.h"
#include "../Ass/Ass.h"
#include <QString>
#include <memory>
/* Types for the different documents */
......@@ -100,7 +101,7 @@ class AssDocument final : public CRTPDocument<AssDocumentType, AssDocument> {
friend CRTPDocument<AssDocumentType, AssDocument>;
private:
QVector<Line> lines;
QVector<std::shared_ptr<Line>> lines;
};
#endif // VIVY_CRTP_DOCUMENT_H
......@@ -17,9 +17,10 @@ TimingScene::TimingScene(QWidget *parent) noexcept
{
}
TimingScene::TimingScene(QImage img, QWidget *parent) noexcept
: QGraphicsScene(parent)
, img(img)
TimingScene::TimingScene(QImage img, quint64 soundLength, QWidget *parent) noexcept
: QGraphicsScene(parent),
img(img),
soundLength(soundLength)
{
QPixmap pixmap(QPixmap::fromImage(img));
backgroundImg = addPixmap(pixmap);
......@@ -34,8 +35,21 @@ TimingScene::mousePressEvent(QGraphicsSceneMouseEvent *event) noexcept
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));
if (auto p = currentLine.lock()){
quint64 time = timeFromPos(pos.x());
switch (event->button()){
case Qt::LeftButton:
p->setStart(time);
break;
case Qt::RightButton:
p->setEnd(time);
break;
default:
break;
}
}
}
QGraphicsScene::mousePressEvent(event);
......
......@@ -2,12 +2,14 @@
#define VIVY_TIMING_SCENE_H
#include "TimingBar.h"
#include "Ass/Line.h"
#include <QWidget>
#include <QColor>
#include <QVector>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <memory>
class QGraphicsPixmapItem;
......@@ -19,19 +21,23 @@ public:
static inline constexpr QColor endColour = QColor(0, 127, 0);
explicit TimingScene(QWidget *parent = nullptr) noexcept;
TimingScene(QImage img, QWidget *parent = nullptr) noexcept;
TimingScene(QImage, quint64, QWidget* = nullptr) noexcept;
~TimingScene() noexcept = default;
private:
QGraphicsPixmapItem *backgroundImg = nullptr;
QImage img;
QVector<QLine> lines;
quint64 soundLength;
std::weak_ptr<Line> currentLine;
public:
inline QGraphicsPixmapItem* bg() { return backgroundImg; };
void mousePressEvent(QGraphicsSceneMouseEvent *event) noexcept override;
private:
inline quint64 timeFromPos(qreal x) { return x * soundLength / width(); };
public slots:
};
......
......@@ -14,10 +14,10 @@
#define TO_ADD_TO_IMAGE_HEIGHT 2 /* Used for alignement */
TimingView::TimingView(QImage img, QWidget *parent) noexcept
TimingView::TimingView(QImage img, quint64 soundLength, QWidget *parent) noexcept
: QGraphicsView(parent)
{
scene = new TimingScene(img);
scene = new TimingScene(img, soundLength);
setFixedHeight(img.height());
setMaximumHeight(img.height() + horizontalScrollBar()->height() - TO_ADD_TO_IMAGE_HEIGHT);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
......
......@@ -22,7 +22,7 @@ public:
static inline constexpr QColor startColour = QColor(127, 0, 127);
static inline constexpr QColor endColour = QColor(0, 127, 0);
explicit TimingView(QImage img, QWidget *parent = nullptr) noexcept;
explicit TimingView(QImage, quint64, QWidget* = nullptr) noexcept;
~TimingView() noexcept = default;
private:
......
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