fix ports specific bugs
This commit is contained in:
1 parent
c30531e032
commit
80c329a697
3 files changed
+44
-6
No files matched your search
@@ -29,6 +29,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dpi/DpiForms.h"
|
||||
#include "Dpi/DpiGraphics.h"
|
||||
|
||||
#include <QPoint>
|
||||
#include <QString>
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QRegion>
|
||||
#include <QWindow>
|
||||
|
||||
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<ButtonBase *>(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<std::size_t>(FontType::Normal)]);
|
||||
if (target)
|
||||
target->font().assign(UniFont[static_cast<std::size_t>(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;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QKeyEvent>
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
#include <QtMath>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user