summaryrefslogtreecommitdiffstats
path: root/ui/qt/geometry_state_dialog.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
commite4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch)
tree68cb5ef9081156392f1dd62a00c6ccc1451b93df /ui/qt/geometry_state_dialog.cpp
parentInitial commit. (diff)
downloadwireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz
wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip
Adding upstream version 4.2.2.upstream/4.2.2
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.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/ui/qt/geometry_state_dialog.cpp b/ui/qt/geometry_state_dialog.cpp
new file mode 100644
index 0000000..ca6d398
--- /dev/null
+++ b/ui/qt/geometry_state_dialog.cpp
@@ -0,0 +1,69 @@
+/* geometry_state_dialog.cpp
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "geometry_state_dialog.h"
+#include <ui/qt/utils/qt_ui_utils.h>
+#include "ui/recent.h"
+#include "ui/ws_ui_util.h"
+
+GeometryStateDialog::~GeometryStateDialog()
+{
+ saveGeometry();
+}
+
+void GeometryStateDialog::loadGeometry(int width, int height, const QString &dialog_name)
+{
+ window_geometry_t geom;
+
+ 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);
+
+ // 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));
+ 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();
+ }
+ } else if (width > 0 && height > 0) {
+ // No saved geometry found, use defaults
+ resize(width, height);
+ }
+}
+
+void GeometryStateDialog::saveGeometry()
+{
+ if (dialog_name_.isEmpty())
+ return;
+
+ window_geometry_t geom;
+
+ geom.key = NULL;
+ geom.set_pos = TRUE;
+ geom.x = pos().x();
+ geom.y = pos().y();
+ geom.set_size = TRUE;
+ geom.width = size().width();
+ geom.height = size().height();
+ geom.set_maximized = TRUE;
+ geom.maximized = isFullScreen();
+
+ window_geom_save(dialog_name_.toUtf8().constData(), &geom);
+}