diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:53 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:14:53 +0000 |
commit | a86c5f7cae7ec9a3398300555a0b644689d946a1 (patch) | |
tree | 39fe4b107c71174fd1e8a8ceb9a4d2aa14116248 /ui/qt/geometry_state_dialog.cpp | |
parent | Releasing progress-linux version 4.2.6-1~progress7.99u1. (diff) | |
download | wireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.tar.xz wireshark-a86c5f7cae7ec9a3398300555a0b644689d946a1.zip |
Merging upstream version 4.4.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ui/qt/geometry_state_dialog.cpp')
-rw-r--r-- | ui/qt/geometry_state_dialog.cpp | 85 |
1 files changed, 66 insertions, 19 deletions
diff --git a/ui/qt/geometry_state_dialog.cpp b/ui/qt/geometry_state_dialog.cpp index ca6d3980..28a746ee 100644 --- a/ui/qt/geometry_state_dialog.cpp +++ b/ui/qt/geometry_state_dialog.cpp @@ -14,7 +14,8 @@ GeometryStateDialog::~GeometryStateDialog() { - saveGeometry(); + saveWindowGeometry(); + saveSplitterState(); } void GeometryStateDialog::loadGeometry(int width, int height, const QString &dialog_name) @@ -23,24 +24,30 @@ void GeometryStateDialog::loadGeometry(int width, int height, const QString &dia dialog_name_ = dialog_name.isEmpty() ? objectName() : dialog_name; if (!dialog_name_.isEmpty() && window_geom_load(dialog_name_.toUtf8().constData(), &geom)) { - QRect recent_geom(geom.x, geom.y, geom.width, geom.height); + if (geom.qt_geom == nullptr || !restoreGeometry(QByteArray::fromHex(geom.qt_geom))) { + // restoreGeometry didn't work, fallback to older (but other + // toolkit compatible?) less-accurate method. (restoreGeometry + // is supposed to take care of things like making sure the window + // is on screen, setting the non-maximized size if maximized, etc.) + QRect recent_geom(geom.x, geom.y, geom.width, geom.height); - // Check if the dialog is visible on any screen - if (rect_on_screen(recent_geom)) { - move(recent_geom.topLeft()); - resize(recent_geom.size()); - } else { - // Not visible, move within a reasonable area and try size only - recent_geom.moveTopLeft(QPoint(50, 50)); + // Check if the dialog is visible on any screen if (rect_on_screen(recent_geom)) { + move(recent_geom.topLeft()); resize(recent_geom.size()); - } else if (width > 0 && height > 0) { - // We're not visible on any screens, use defaults - resize(width, height); + } else { + // Not visible, move within a reasonable area and try size only + recent_geom.moveTopLeft(QPoint(50, 50)); + if (rect_on_screen(recent_geom)) { + resize(recent_geom.size()); + } else if (width > 0 && height > 0) { + // We're not visible on any screens, use defaults + resize(width, height); + } + } + if (geom.maximized) { + showFullScreen(); } - } - if (geom.maximized) { - showFullScreen(); } } else if (width > 0 && height > 0) { // No saved geometry found, use defaults @@ -48,7 +55,34 @@ void GeometryStateDialog::loadGeometry(int width, int height, const QString &dia } } -void GeometryStateDialog::saveGeometry() +#ifndef Q_OS_MAC +void GeometryStateDialog::setWindowModality(Qt::WindowModality modality) +{ + if (modality != windowModality()) { + if (modality == Qt::NonModal) { + setParent(nullptr, windowFlags()); + } else { + setParent(parent_, windowFlags()); + } + } + QDialog::setWindowModality(modality); +} +#endif + +void GeometryStateDialog::loadSplitterState(QSplitter *splitter) +{ + if (splitter == nullptr) { + splitter = findChild<QSplitter *>(); + } + if (splitter != nullptr) { + const char* splitter_state = window_splitter_load(dialog_name_.toUtf8().constData()); + if (splitter_state != nullptr) { + splitter->restoreState(QByteArray::fromHex(splitter_state)); + } + } +} + +void GeometryStateDialog::saveWindowGeometry() { if (dialog_name_.isEmpty()) return; @@ -56,14 +90,27 @@ void GeometryStateDialog::saveGeometry() window_geometry_t geom; geom.key = NULL; - geom.set_pos = TRUE; + geom.set_pos = true; geom.x = pos().x(); geom.y = pos().y(); - geom.set_size = TRUE; + geom.set_size = true; geom.width = size().width(); geom.height = size().height(); - geom.set_maximized = TRUE; + geom.set_maximized = true; + // XXX: maximized and fullScreen are different window states; we've been + // using the maximized key for fullScreen ever since this was added. geom.maximized = isFullScreen(); + geom.qt_geom = g_strdup(saveGeometry().toHex().constData()); window_geom_save(dialog_name_.toUtf8().constData(), &geom); } + +void GeometryStateDialog::saveSplitterState(const QSplitter *splitter) +{ + if (splitter == nullptr) { + splitter = findChild<QSplitter *>(); + } + if (splitter != nullptr) { + window_splitter_save(dialog_name_.toUtf8().constData(), splitter->saveState().toHex().constData()); + } +} |