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
|
#pragma once
|
||||||
|
|
||||||
#include "Dpi/DpiForms.h"
|
#include "Dpi/DpiForms.h"
|
||||||
|
#include "Dpi/DpiGraphics.h"
|
||||||
|
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
@@ -83,8 +84,9 @@ protected:
|
|||||||
|
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
// Pass preview=true to just measure how many lines the text needs
|
// Pass preview=true to just measure how many lines the text needs
|
||||||
// (fills `lines`) without drawing anything.
|
// (fills `lines`) without drawing anything. Otherwise the text is drawn
|
||||||
void splitText(bool preview);
|
// on `target`.
|
||||||
|
void splitText(bool preview, Dpi::Canvas *target = nullptr);
|
||||||
void correctHeight();
|
void correctHeight();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRegion>
|
#include <QRegion>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
namespace Cevo {
|
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.
|
// The original's dialogs are borderless (BorderStyle = bsNone): they draw their own frame and title.
|
||||||
setWindowFlag(Qt::FramelessWindowHint, true);
|
setWindowFlag(Qt::FramelessWindowHint, true);
|
||||||
|
setMouseTracking(true); // the dialogs highlight items on mouse over, like the VCL's OnMouseMove
|
||||||
QPalette pal = palette();
|
QPalette pal = palette();
|
||||||
pal.setColor(QPalette::Window, Qt::black);
|
pal.setColor(QPalette::Window, Qt::black);
|
||||||
setPalette(pal);
|
setPalette(pal);
|
||||||
@@ -55,7 +57,12 @@ DrawDlg::DrawDlg(QWidget *parent) : Dpi::Form(parent)
|
|||||||
void DrawDlg::mousePressEvent(QMouseEvent *event)
|
void DrawDlg::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
const QPoint pos = event->pos();
|
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_moveMousePos = mapToGlobal(event->pos());
|
||||||
m_moveFormPos = QPoint(x(), y());
|
m_moveFormPos = QPoint(x(), y());
|
||||||
m_moveActive = true;
|
m_moveActive = true;
|
||||||
@@ -150,7 +157,7 @@ void BaseMessgDlg::paintEvent(QPaintEvent *)
|
|||||||
frame(canvas, 2 + Border, 2 + Border, width() - (3 + Border), height() - (3 + Border),
|
frame(canvas, 2 + Border, 2 + Border, width() - (3 + Border), height() - (3 + Border),
|
||||||
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
|
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
|
||||||
}
|
}
|
||||||
splitText(false);
|
splitText(false, &canvas);
|
||||||
|
|
||||||
if (MainTexture) {
|
if (MainTexture) {
|
||||||
const auto children = findChildren<ButtonBase *>(QString(), Qt::FindDirectChildrenOnly);
|
const auto children = findChildren<ButtonBase *>(QString(), Qt::FindDirectChildrenOnly);
|
||||||
@@ -162,7 +169,7 @@ void BaseMessgDlg::paintEvent(QPaintEvent *)
|
|||||||
canvas.unbind();
|
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
|
// Best-effort port of the 1-indexed Pascal word-wrap logic below; wraps
|
||||||
// messageText at word boundaries (or '\' line breaks) to fit within
|
// messageText at word boundaries (or '\' line breaks) to fit within
|
||||||
@@ -175,6 +182,9 @@ void BaseMessgDlg::splitText(bool preview)
|
|||||||
QPainter painter(&dummy);
|
QPainter painter(&dummy);
|
||||||
Dpi::Canvas canvas;
|
Dpi::Canvas canvas;
|
||||||
canvas.bind(&painter);
|
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()) {
|
while (start < messageText.length()) {
|
||||||
int stop = start;
|
int stop = start;
|
||||||
while (stop < messageText.length() - 1 && messageText.at(stop) != QLatin1Char('\\') &&
|
while (stop < messageText.length() - 1 && messageText.at(stop) != QLatin1Char('\\') &&
|
||||||
@@ -190,7 +200,8 @@ void BaseMessgDlg::splitText(bool preview)
|
|||||||
}
|
}
|
||||||
if (!preview) {
|
if (!preview) {
|
||||||
const QString s = messageText.mid(start, stop - start + 1);
|
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);
|
19 + Border + topSpace + linesCount * MessageLineSpacing, s);
|
||||||
}
|
}
|
||||||
start = stop + 2;
|
start = stop + 2;
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <QWindow>
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
|
|
||||||
namespace Dpi {
|
namespace Dpi {
|
||||||
@@ -50,12 +51,36 @@ ModalResult Form::showModal()
|
|||||||
{
|
{
|
||||||
setWindowModality(Qt::ApplicationModal);
|
setWindowModality(Qt::ApplicationModal);
|
||||||
m_modalResult = ModalResult::None;
|
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();
|
show();
|
||||||
|
raise();
|
||||||
|
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
m_modalLoop = &loop;
|
m_modalLoop = &loop;
|
||||||
loop.exec();
|
loop.exec();
|
||||||
m_modalLoop = nullptr;
|
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;
|
return m_modalResult;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user