1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
/*
SPDX-FileCopyrightText: 2022 Eric Jiang
SPDX-FileCopyrightText: 2022 Jean-Baptiste Mardelle <jb@kdenlive.org>
SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "test_utils.hpp"
// test specific headers
#include "titler/graphicsscenerectmove.h"
TEST_CASE("Title text left alignment", "[Titler]")
{
QScopedPointer<MyTextItem> txt(new MyTextItem("Hello, world!", nullptr));
txt->setAlignment(Qt::AlignLeft);
QRectF origBB = txt->boundingRect();
qreal origX = txt->x();
txt->document()->setPlainText("Hello, longer string!");
QRectF newBB = txt->boundingRect();
qreal newX = txt->x();
// make sure the left and right edges of the title are still aligned properly
CHECK(newBB.width() > 0);
CHECK(origBB.topRight().x() < newBB.topRight().x());
CHECK(newX == Approx(origX));
}
TEST_CASE("Title text right alignment", "[Titler]")
{
QScopedPointer<MyTextItem> txt(new MyTextItem("Hello, world!", nullptr));
txt->setAlignment(Qt::AlignRight);
QRectF origBB = txt->boundingRect();
// origX is the left edge of the txt object
qreal origX = txt->x();
// origRightX is the right edge of the txt object
qreal origRightX = origBB.width() + origX;
txt->document()->setPlainText("Hello, longer string!");
QRectF newBB = txt->boundingRect();
qreal newX = txt->x();
qreal newRightX = newBB.width() + newX;
CHECK(newBB.width() > 0);
CHECK(origRightX == Approx(newRightX));
CHECK(origX > newX);
}
TEST_CASE("Title text center alignment", "[Titler]")
{
QScopedPointer<MyTextItem> txt(new MyTextItem("short", nullptr));
txt->setAlignment(Qt::AlignHCenter);
QRectF origBB = txt->boundingRect();
qreal origX = txt->x();
qreal origRightX = origBB.width() + origX;
qreal origCenter = (origX + origRightX) / 2;
txt->document()->setPlainText("longer string");
QRectF newBB = txt->boundingRect();
qreal newX = txt->x();
qreal newRightX = newBB.width() + newX;
qreal newCenter = (newX + newRightX) / 2;
CHECK(origCenter == Approx(newCenter));
CHECK(newRightX > origRightX);
CHECK(newX < origX);
}
|