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

Separating Timer in TimingScene and TimingView

Setting the horizontal scrollbar as always on
parent 24747981
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!4Add basic lyrics/timing classes
#include "AudioVisualizer.h"
#include "Timer.h"
#include <QLabel>
#include <QScrollArea>
......@@ -16,7 +15,7 @@ AudioVisualizer::AudioVisualizer(QWidget *parent) noexcept
void
AudioVisualizer::printSpectrum(QImage pixmap) noexcept
{
Timer *timer = new Timer(pixmap);
TimingView *timer = new TimingView(pixmap);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(timer);
......
#ifndef VIVY_AUDIOVISUALIZER_H
#define VIVY_AUDIOVISUALIZER_H
#include "Timer.h"
#include "TimingView.hpp"
#include <QWidget>
class AudioVisualizer final : public QWidget {
......
#include "TimingScene.hpp"
#include <QLabel>
#include <QGraphicsLineItem>
#include <QGraphicsView>
#include <QGraphicsPixmapItem>
#include <QScrollArea>
#include <QVBoxLayout>
#include <QScrollBar>
#include <QMessageBox>
#include <QMouseEvent>
#include <QPainter>
TimingScene::TimingScene(QWidget *parent) noexcept
: QGraphicsScene(parent)
{
}
TimingScene::TimingScene(QImage img, QWidget *parent) noexcept
: QGraphicsScene(parent)
, img(img)
{
QPixmap pixmap(QPixmap::fromImage(img));
backgroundImg = addPixmap(pixmap);
}
#ifndef VIVY_TIMING_SCENE_H
#define VIVY_TIMING_SCENE_H
#include "TimingBar.h"
#include <QWidget>
#include <QColor>
#include <QVector>
#include <QGraphicsView>
#include <QGraphicsScene>
class QGraphicsPixmapItem;
class TimingScene final : public QGraphicsScene {
Q_OBJECT
public:
static inline constexpr QColor startColour = QColor(127, 0, 127);
static inline constexpr QColor endColour = QColor(0, 127, 0);
explicit TimingScene(QWidget *parent = nullptr) noexcept;
TimingScene(QImage img, QWidget *parent = nullptr) noexcept;
~TimingScene() noexcept = default;
private:
QGraphicsPixmapItem *backgroundImg = nullptr;
QImage img;
QVector<QLine> lines;
public:
inline QGraphicsPixmapItem* bg() { return backgroundImg; };
public slots:
};
#endif // VIVY_TIMING_SCENE_H
#include "Timer.h"
#include "TimingView.hpp"
#include <QLabel>
#include <QGraphicsLineItem>
......@@ -10,30 +10,30 @@
#include <QMessageBox>
#include <QMouseEvent>
#include <QPainter>
#include <QAbstractScrollArea>
#define TO_ADD_TO_IMAGE_HEIGHT 2 /* Used for alignement */
Timer::Timer(QImage img, QWidget *parent) noexcept
TimingView::TimingView(QImage img, QWidget *parent) noexcept
: QGraphicsView(parent)
, img(img)
{
QPixmap pixmap(QPixmap::fromImage(img));
bg = scene->addPixmap(pixmap);
setFixedHeight(pixmap.height());
scene = new TimingScene(img);
setFixedHeight(img.height());
setMaximumHeight(img.height() + horizontalScrollBar()->height() - TO_ADD_TO_IMAGE_HEIGHT);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setScene(scene);
}
void
Timer::mousePressEvent(QMouseEvent *event) noexcept
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 == bg) {
scene->addItem(new TimingBar(QLine(x, 0, x, img.height() - TO_ADD_TO_IMAGE_HEIGHT),
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));
}
......
#ifndef VIVY_TIMER_H
#define VIVY_TIMER_H
#ifndef VIVY_TIMING_VIEW_H
#define VIVY_TIMING_VIEW_H
#include "TimingBar.h"
#include "TimingScene.hpp"
#include <QWidget>
#include <QColor>
......@@ -10,25 +11,22 @@
class QGraphicsPixmapItem;
class Timer final : public QGraphicsView {
class TimingView final : public QGraphicsView {
Q_OBJECT
public:
static inline constexpr QColor startColour = QColor(127, 0, 127);
static inline constexpr QColor endColour = QColor(0, 127, 0);
Timer(QImage img, QWidget *parent = nullptr) noexcept;
~Timer() noexcept = default;
TimingView(QImage img, QWidget *parent = nullptr) noexcept;
~TimingView() noexcept = default;
private:
QGraphicsPixmapItem *bg = nullptr;
QGraphicsScene *scene = new QGraphicsScene;
QImage img;
QVector<QLine> lines;
TimingScene* scene;
void mousePressEvent(QMouseEvent *event) noexcept;
public slots:
};
#endif // VIVY_TIMER_H
#endif // VIVY_TIMING_VIEW_H
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