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

Properly display all the spectrum below the axis

parent b9594dd9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!29Improve timingView with display of the ASS lines
Pipeline #2660 réussi
......@@ -16,19 +16,21 @@
using namespace Vivy;
TimingAxis::TimingAxis(AudioContext::StreamPtr stream) noexcept
TimingAxis::TimingAxis(AudioContext::StreamPtr stream, int height_, int width_) noexcept
: QGraphicsObject()
, audioStream(stream)
, height(height_)
, width(width_)
{
setPos(0, height);
pen = QPen(axisColour);
pen.setWidth(penWidth);
refreshTicks();
}
QRectF
TimingAxis::boundingRect() const
{
return QRectF(0, penWidth, scene()->width(), -height - penWidth);
return QRectF(0, penWidth, width + 2*penWidth, -height - penWidth);
}
/*
......@@ -38,13 +40,10 @@ TimingAxis::boundingRect() const
void
TimingAxis::refreshTicks()
{
qDebug() << "Refreshing ticks...";
int nbAvailableTicks = availableTicks.size();
QGraphicsScene *parentScene = scene();
int minorTicksIndex = 0;
int length{ int(audioStream->getLength()) };
int width{ int(parentScene->width()) };
if (parentScene != nullptr) {
if (width != 0 && length != 0){
for (minorTicksIndex = 0; minorTicksIndex < nbAvailableTicks; minorTicksIndex++) {
if (width * availableTicks[minorTicksIndex] / length >= minBetweenMinor) {
break;
......@@ -52,6 +51,7 @@ TimingAxis::refreshTicks()
}
}
prepareGeometryChange();
if (minorTicksIndex < nbAvailableTicks - 1) {
minorTicks = availableTicks[minorTicksIndex];
majorTicks = availableTicks[minorTicksIndex + 1];
......@@ -59,7 +59,6 @@ TimingAxis::refreshTicks()
minorTicks = 0;
majorTicks = availableTicks[minorTicksIndex];
}
update();
}
void
......@@ -70,7 +69,6 @@ TimingAxis::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
return;
int yText = -majorTicksHeight - timeDigitsMargin;
int width{ int(scene()->width()) };
painter->setPen(pen);
painter->drawLine(0, 0, audioLength, 0);
......
......@@ -20,7 +20,7 @@ class TimingAxis final : public QGraphicsObject {
Q_OBJECT
public:
explicit TimingAxis(AudioContext::StreamPtr stream) noexcept;
explicit TimingAxis(AudioContext::StreamPtr stream, int height, int width) noexcept;
~TimingAxis() noexcept override = default;
QRectF boundingRect() const override;
......@@ -32,6 +32,8 @@ private:
int penWidth{ 1 };
AudioContext::StreamPtr audioStream;
int height{ 30 };
int width{ 0 };
/*
* We use ints here because
......@@ -47,7 +49,6 @@ private:
int majorTicksHeight{ 7 };
int timeDigitsHeight{ 20 };
int timeDigitsMargin{ 3 };
int height{ 30 };
QString msToString(int i) const noexcept;
......
......@@ -30,14 +30,19 @@ TimingScene::TimingScene(QImage img_, AudioContext::StreamPtr stream, QWidget *p
, img(img_)
, audioStream(stream)
{
ax = new TimingAxis(stream);
int timingAxisHeight = 30;
// We put a common origin for the items at the bottom of the axis
QPixmap pixmap(QPixmap::fromImage(img));
backgroundImg = addPixmap(pixmap);
setSceneRect(QRect(pixmap.rect()));
backgroundImg->setPos(0, timingAxisHeight);
ax = new TimingAxis(stream, timingAxisHeight, pixmap.width());
addItem(ax);
ax->setPos(0, timingAxisHeight);
ax->refreshTicks();
// Freeze the scene boundaries
setSceneRect(sceneRect());
if (auto assDocument = currentVivyDocument->getAssSubDocument()) {
QVector<Ass::LinePtr> lines = assDocument->getLines();
......
......@@ -7,17 +7,18 @@ TimingView::TimingView(QGraphicsScene *scene, QImage img, AudioContext::StreamPt
: QGraphicsView(scene, parent)
, audioStream(stream)
{
//setFixedHeight(img.height());
//setMaximumHeight(img.height());
int interestingViewHeight = int(scene->height() + horizontalScrollBar()->height());
setFixedHeight(interestingViewHeight);
setMaximumHeight(interestingViewHeight);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Minimum);
QObject::connect(verticalScrollBar(), &QScrollBar::rangeChanged, this,
&TimingView::moveScrollBarToBottom);
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
//horizontalScrollBar()->setValue(horizontalScrollBar()->minimum());
centerOn(0, height());
// We want to see the bottom part of the spectrum, the top is less important if a few pixels get trimmed
centerOn(0, interestingViewHeight);
}
void
......
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