From 80c329a697432446eb0ccd786082e480791e0846 Mon Sep 17 00:00:00 2001 From: Geoffray Levasseur Date: Wed, 4 Nov 2026 17:11:16 +0100 Subject: [PATCH] fix ports specific bugs --- widget/include/Cevo/CevoDrawDlg.h | 6 ++++-- widget/src/CevoDrawDlg.cpp | 19 +++++++++++++++---- widget/src/DpiForms.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/widget/include/Cevo/CevoDrawDlg.h b/widget/include/Cevo/CevoDrawDlg.h index d365005..ff7217e 100644 --- a/widget/include/Cevo/CevoDrawDlg.h +++ b/widget/include/Cevo/CevoDrawDlg.h @@ -29,6 +29,7 @@ #pragma once #include "Dpi/DpiForms.h" +#include "Dpi/DpiGraphics.h" #include #include @@ -83,8 +84,9 @@ protected: void paintEvent(QPaintEvent *event) override; // Pass preview=true to just measure how many lines the text needs - // (fills `lines`) without drawing anything. - void splitText(bool preview); + // (fills `lines`) without drawing anything. Otherwise the text is drawn + // on `target`. + void splitText(bool preview, Dpi::Canvas *target = nullptr); void correctHeight(); }; diff --git a/widget/src/CevoDrawDlg.cpp b/widget/src/CevoDrawDlg.cpp index 09e4d22..a27fc1d 100644 --- a/widget/src/CevoDrawDlg.cpp +++ b/widget/src/CevoDrawDlg.cpp @@ -39,6 +39,7 @@ #include #include #include +#include namespace Cevo { @@ -46,6 +47,7 @@ DrawDlg::DrawDlg(QWidget *parent) : Dpi::Form(parent) { // The original's dialogs are borderless (BorderStyle = bsNone): they draw their own frame and title. setWindowFlag(Qt::FramelessWindowHint, true); + setMouseTracking(true); // the dialogs highlight items on mouse over, like the VCL's OnMouseMove QPalette pal = palette(); pal.setColor(QPalette::Window, Qt::black); setPalette(pal); @@ -55,7 +57,12 @@ DrawDlg::DrawDlg(QWidget *parent) : Dpi::Form(parent) void DrawDlg::mousePressEvent(QMouseEvent *event) { const QPoint pos = event->pos(); - if (rect().contains(pos) && pos.y() < titleHeight) { + if (event->button() == Qt::LeftButton && rect().contains(pos) && pos.y() < titleHeight) { + // The compositor moves the window: programmatic moves are ignored on Wayland. + if (windowHandle() && windowHandle()->startSystemMove()) { + m_moveActive = false; + return; + } m_moveMousePos = mapToGlobal(event->pos()); m_moveFormPos = QPoint(x(), y()); m_moveActive = true; @@ -150,7 +157,7 @@ void BaseMessgDlg::paintEvent(QPaintEvent *) frame(canvas, 2 + Border, 2 + Border, width() - (3 + Border), height() - (3 + Border), MainTexture->colorBevelLight, MainTexture->colorBevelShade); } - splitText(false); + splitText(false, &canvas); if (MainTexture) { const auto children = findChildren(QString(), Qt::FindDirectChildrenOnly); @@ -162,7 +169,7 @@ void BaseMessgDlg::paintEvent(QPaintEvent *) canvas.unbind(); } -void BaseMessgDlg::splitText(bool preview) +void BaseMessgDlg::splitText(bool preview, Dpi::Canvas *target) { // Best-effort port of the 1-indexed Pascal word-wrap logic below; wraps // messageText at word boundaries (or '\' line breaks) to fit within @@ -175,6 +182,9 @@ void BaseMessgDlg::splitText(bool preview) QPainter painter(&dummy); Dpi::Canvas canvas; canvas.bind(&painter); + canvas.font().assign(UniFont[static_cast(FontType::Normal)]); + if (target) + target->font().assign(UniFont[static_cast(FontType::Normal)]); while (start < messageText.length()) { int stop = start; while (stop < messageText.length() - 1 && messageText.at(stop) != QLatin1Char('\\') && @@ -190,7 +200,8 @@ void BaseMessgDlg::splitText(bool preview) } if (!preview) { const QString s = messageText.mid(start, stop - start + 1); - loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2, + Dpi::Canvas &out = target ? *target : canvas; + loweredTextOut(out, -1, *MainTexture, (width() - biColorTextWidth(out, s)) / 2, 19 + Border + topSpace + linesCount * MessageLineSpacing, s); } start = stop + 2; diff --git a/widget/src/DpiForms.cpp b/widget/src/DpiForms.cpp index 66529dc..7c03803 100644 --- a/widget/src/DpiForms.cpp +++ b/widget/src/DpiForms.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include namespace Dpi { @@ -50,12 +51,36 @@ ModalResult Form::showModal() { setWindowModality(Qt::ApplicationModal); m_modalResult = ModalResult::None; + + // Without a transient parent, the window manager may stack the dialog behind the main window. + QWidget *owner = QApplication::activeWindow(); + if (!owner || owner == this || !owner->isVisible()) { + owner = nullptr; + int bestArea = 0; + for (QWidget *candidate : QApplication::topLevelWidgets()) { + const int area = candidate->width() * candidate->height(); + if (candidate != this && candidate->isVisible() && area > bestArea) { + owner = candidate; + bestArea = area; + } + } + } + if (owner) { + winId(); + owner->winId(); // creates the native windows + if (windowHandle() && owner->windowHandle()) + windowHandle()->setTransientParent(owner->windowHandle()); + } show(); + raise(); QEventLoop loop; m_modalLoop = &loop; loop.exec(); m_modalLoop = nullptr; + setWindowModality(Qt::NonModal); // the same dialog may later be shown as a persistent window + if (windowHandle()) + windowHandle()->setTransientParent(nullptr); return m_modalResult; }