File indexing completed on 2025-04-27 04:32:49
0001 /* 0002 SPDX-FileCopyrightText: 2022 Eric Jiang 0003 SPDX-FileCopyrightText: 2022 Jean-Baptiste Mardelle <jb@kdenlive.org> 0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 #include "test_utils.hpp" 0007 // test specific headers 0008 #include "titler/graphicsscenerectmove.h" 0009 0010 TEST_CASE("Title text left alignment", "[Titler]") 0011 { 0012 QScopedPointer<MyTextItem> txt(new MyTextItem("Hello, world!", nullptr)); 0013 txt->setAlignment(Qt::AlignLeft); 0014 QRectF origBB = txt->boundingRect(); 0015 qreal origX = txt->x(); 0016 txt->document()->setPlainText("Hello, longer string!"); 0017 QRectF newBB = txt->boundingRect(); 0018 qreal newX = txt->x(); 0019 0020 // make sure the left and right edges of the title are still aligned properly 0021 CHECK(newBB.width() > 0); 0022 CHECK(origBB.topRight().x() < newBB.topRight().x()); 0023 CHECK(newX == Approx(origX)); 0024 } 0025 0026 TEST_CASE("Title text right alignment", "[Titler]") 0027 { 0028 QScopedPointer<MyTextItem> txt(new MyTextItem("Hello, world!", nullptr)); 0029 txt->setAlignment(Qt::AlignRight); 0030 QRectF origBB = txt->boundingRect(); 0031 // origX is the left edge of the txt object 0032 qreal origX = txt->x(); 0033 // origRightX is the right edge of the txt object 0034 qreal origRightX = origBB.width() + origX; 0035 txt->document()->setPlainText("Hello, longer string!"); 0036 QRectF newBB = txt->boundingRect(); 0037 qreal newX = txt->x(); 0038 qreal newRightX = newBB.width() + newX; 0039 0040 CHECK(newBB.width() > 0); 0041 CHECK(origRightX == Approx(newRightX)); 0042 CHECK(origX > newX); 0043 } 0044 0045 TEST_CASE("Title text center alignment", "[Titler]") 0046 { 0047 QScopedPointer<MyTextItem> txt(new MyTextItem("short", nullptr)); 0048 txt->setAlignment(Qt::AlignHCenter); 0049 QRectF origBB = txt->boundingRect(); 0050 qreal origX = txt->x(); 0051 qreal origRightX = origBB.width() + origX; 0052 qreal origCenter = (origX + origRightX) / 2; 0053 txt->document()->setPlainText("longer string"); 0054 QRectF newBB = txt->boundingRect(); 0055 qreal newX = txt->x(); 0056 qreal newRightX = newBB.width() + newX; 0057 qreal newCenter = (newX + newRightX) / 2; 0058 0059 CHECK(origCenter == Approx(newCenter)); 0060 CHECK(newRightX > origRightX); 0061 CHECK(newX < origX); 0062 }