// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: BSD-2-Clause #include #include #include #include #include #include #include // What the emoji panel's column of its own costs the conversation. // // Telegram opens the panel as a third section of the window when there is room // for one: its width comes off the conversation and its height is the window's // (ComposeControls::createTabbedPanel, resizeForThirdSection). Getting that to // mean anything on a Kirigami.Page is three separate things, and each of them // has a way of quietly not happening: // // - The column has to be reparented onto the page. The page's own children are // its content item's, which stops above the composer, so a column left in // there comes up short of the bottom of the window and is the drop-down with // extra steps. // - The composer has to give up the same width the conversation does, and it // cannot do it by setting its own width: the page sizes the footer band // itself and overwrites it. The composer is in a wrapper, and it is the // wrapper's own geometry that has to come out right - the band as tall as // the composer was, the composer as tall as the band. // - A window in one column has nowhere to put a third of itself, and there the // panel is the drop-down over the conversation again. // // This is a reduction of ChatPage.qml's arrangement, the same way // EmojiPopupPositionTest is a reduction of EmojiPopup.qml's geometry: the // timeline, the composer and the panel are stand-ins, and what is copied is the // anchors and the arithmetic. The assertions are all about where the three of // them ended up. static const char *sceneQml = R"QML( import QtQuick import QtQuick.Controls as QQC2 import org.kde.kirigami as Kirigami // only a host for the page: a Page is not a window, and without one it is never // in a scene and answers nothing QQC2.ApplicationWindow { id: window width: 800 height: 600 visible: true QQC2.Page { id: page objectName: "page" width: 800 height: 600 padding: 0 property bool compact: false readonly property real gridUnit: Kirigami.Units.gridUnit // stands in for the conversation Rectangle { id: content objectName: "content" anchors.fill: parent anchors.rightMargin: page.panelWidth color: "transparent" } // stands in for EmojiSidePanel: reparented onto the page, so that it is the // height of the page and not the height of the content item Rectangle { id: column objectName: "column" parent: page visible: false width: Math.round(Kirigami.Units.gridUnit * 19.2) readonly property real columnWidth: column.visible ? column.width : 0 readonly property bool docked: !page.compact && page.width >= column.width + page.gridUnit * 12 function close() { column.visible = false } anchors.top: parent.top anchors.bottom: parent.bottom anchors.right: parent.right } readonly property bool panelDocked: column.docked readonly property real panelWidth: page.panelDocked ? column.columnWidth : 0 // the narrower of a Telegram panel's own two shapes, the one with no room for // a column of its own readonly property bool panelDropsDown: !page.panelDocked function toggleColumn() { if (page.panelDocked) { column.visible = !column.visible return } dropDown.visible = true } // the column put up without asking whether it fits, which is what a window // dragged out from under one leaves standing function forceColumn() { column.visible = true } // a window too narrow for a column takes it down again: a column a // conversation no longer fits beside is the drop-down without the drop-down's // sizing onPanelDockedChanged: if (!page.panelDocked) { column.close() } readonly property alias columnOpen: column.visible readonly property alias dropDownOpen: dropDown.visible QQC2.Popup { id: dropDown objectName: "dropDown" width: column.width height: 300 } // the page gives the footer the full width whatever is in it, so the // composer goes in a wrapper which takes the column's width off it footer: Item { id: band objectName: "band" implicitHeight: composer.implicitHeight Rectangle { id: composer objectName: "composer" implicitHeight: 60 anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom anchors.rightMargin: page.panelWidth color: "transparent" } } } } )QML"; class EmojiSidePanelTest : public QObject { Q_OBJECT static void settle(int rounds = 4) { for (int i = 0; i < rounds; ++i) { QCoreApplication::processEvents(QEventLoop::AllEvents, 20); } } QTemporaryDir *m_dir = nullptr; QQmlApplicationEngine *m_view = nullptr; QObject *m_scene = nullptr; QQuickItem *item(const char *name) const { return m_scene->findChild(QString::fromLatin1(name)); } int pageWidth() const { return page()->property("width").toInt(); } int pageHeight() const { return page()->property("height").toInt(); } int columnWidth() const { return item("column")->property("width").toInt(); } int contentWidth() const { return item("content")->property("width").toInt(); } int composerWidth() const { return item("composer")->property("width").toInt(); } int composerHeight() const { return item("composer")->property("height").toInt(); } int bandHeight() const { return item("band")->property("height").toInt(); } bool panelDocked() const { return page()->property("panelDocked").toBool(); } bool panelDropsDown() const { return page()->property("panelDropsDown").toBool(); } QQuickItem *page() const { return item("page"); } qreal gridUnit() const { return page()->property("gridUnit").toReal(); } // Put the page at a size and press the composer's button void togglePanelAt(int width, int height, bool compact = false) { auto *subject = page(); QVERIFY(subject->setProperty("width", width)); QVERIFY(subject->setProperty("height", height)); QVERIFY(subject->setProperty("compact", compact)); settle(); QVERIFY(QMetaObject::invokeMethod(subject, "toggleColumn")); settle(); } private Q_SLOTS: void initTestCase() { m_dir = new QTemporaryDir; QVERIFY(m_dir->isValid()); QFile scene(m_dir->filePath(QStringLiteral("scene.qml"))); QVERIFY(scene.open(QIODevice::WriteOnly)); QCOMPARE(scene.write(sceneQml), qint64(qstrlen(sceneQml))); } void cleanupTestCase() { delete m_dir; } void init() { delete m_view; m_view = new QQmlApplicationEngine; QQmlComponent c(m_view, QUrl::fromLocalFile(m_dir->filePath(QStringLiteral("scene.qml")))); if (c.isError()) { for (const auto &e : c.errors()) { qWarning("%s", qPrintable(e.toString())); } QFAIL("the scene does not load"); } m_scene = c.create(); QVERIFY(m_scene); m_scene->setParent(m_view); auto *window = qobject_cast(m_scene); QVERIFY(window); window->show(); settle(); QVERIFY(window->isVisible()); } void cleanup() { delete m_view; m_view = nullptr; m_scene = nullptr; } void aClosedColumnCostsTheConversationNothing() { QCOMPARE(contentWidth(), pageWidth()); QCOMPARE(composerWidth(), pageWidth()); } void theColumnIsTheHeightOfTheWholePage() { // not the height of the content item, which stops above the composer: a // column that came up short of the bottom of the window is the drop-down // with extra steps togglePanelAt(800, 600); QVERIFY(panelDocked()); auto *column = item("column"); QCOMPARE(column->property("height").toInt(), pageHeight()); QCOMPARE(column->property("y").toInt(), 0); } void theConversationStopsWhereTheColumnStarts() { togglePanelAt(800, 600); QCOMPARE(contentWidth(), pageWidth() - columnWidth()); } void theComposerStopsWhereTheColumnStarts() { // the composer cannot do this by setting its own width, the page sizes // the band and overwrites it, so it is in a wrapper togglePanelAt(800, 600); QCOMPARE(composerWidth(), pageWidth() - columnWidth()); } void theBandIsAsTallAsTheComposerAndNoTaller() { // the wrapper does not cost the composer its height: the band is the // composer's implicit height, and the composer fills the band togglePanelAt(800, 600); QCOMPARE(bandHeight(), 60); QCOMPARE(composerHeight(), 60); } void closingTheColumnGivesTheRoomBack() { togglePanelAt(800, 600); QCOMPARE(contentWidth(), pageWidth() - columnWidth()); togglePanelAt(800, 600); QCOMPARE(contentWidth(), pageWidth()); QCOMPARE(composerWidth(), pageWidth()); } void aOneColumnWindowDropsThePanelDownInstead() { // in compact mode there is nowhere for a third of the window to go, and // the panel is the drop-down over the conversation again togglePanelAt(800, 600, true); QVERIFY(!panelDocked()); QVERIFY(panelDropsDown()); // and it costs the conversation nothing while it is down there QCOMPARE(contentWidth(), pageWidth()); QCOMPARE(composerWidth(), pageWidth()); } void aWindowDraggedOutFromUnderAColumnTakesItDown() { togglePanelAt(800, 600); QVERIFY(item("column")->property("visible").toBool()); // narrowed, without the button being pressed again auto *subject = page(); QVERIFY(subject->setProperty("width", qRound(columnWidth() + gridUnit() * 4))); settle(); QVERIFY(!panelDocked()); QVERIFY(!item("column")->property("visible").toBool()); QCOMPARE(contentWidth(), pageWidth()); } void aWindowTooNarrowForAConversationAndAColumnDropsDownToo() { // one grid unit short of the twelve the conversation keeps, so the // column would leave it with too little togglePanelAt(qRound(columnWidth() + gridUnit() * 11), 600); QVERIFY(!panelDocked()); QCOMPARE(contentWidth(), pageWidth()); } }; QTEST_MAIN(EmojiSidePanelTest) #include "EmojiSidePanelTest.moc"