1 /* geometry_state_dialog.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #include "geometry_state_dialog.h"
11 #include <ui/qt/utils/qt_ui_utils.h>
12 #include "ui/recent.h"
13 #include "ui/ws_ui_util.h"
15 GeometryStateDialog::~GeometryStateDialog()
21 void GeometryStateDialog::loadGeometry(int width
, int height
, const QString
&dialog_name
)
23 window_geometry_t geom
;
25 dialog_name_
= dialog_name
.isEmpty() ? objectName() : dialog_name
;
26 if (!dialog_name_
.isEmpty() && window_geom_load(dialog_name_
.toUtf8().constData(), &geom
)) {
27 if (geom
.qt_geom
== nullptr || !restoreGeometry(QByteArray::fromHex(geom
.qt_geom
))) {
28 // restoreGeometry didn't work, fallback to older (but other
29 // toolkit compatible?) less-accurate method. (restoreGeometry
30 // is supposed to take care of things like making sure the window
31 // is on screen, setting the non-maximized size if maximized, etc.)
32 QRect
recent_geom(geom
.x
, geom
.y
, geom
.width
, geom
.height
);
34 // Check if the dialog is visible on any screen
35 if (rect_on_screen(recent_geom
)) {
36 move(recent_geom
.topLeft());
37 resize(recent_geom
.size());
39 // Not visible, move within a reasonable area and try size only
40 recent_geom
.moveTopLeft(QPoint(50, 50));
41 if (rect_on_screen(recent_geom
)) {
42 resize(recent_geom
.size());
43 } else if (width
> 0 && height
> 0) {
44 // We're not visible on any screens, use defaults
45 resize(width
, height
);
52 } else if (width
> 0 && height
> 0) {
53 // No saved geometry found, use defaults
54 resize(width
, height
);
59 void GeometryStateDialog::setWindowModality(Qt::WindowModality modality
)
61 if (modality
!= windowModality()) {
62 if (modality
== Qt::NonModal
) {
63 setParent(nullptr, windowFlags());
65 setParent(parent_
, windowFlags());
68 QDialog::setWindowModality(modality
);
72 void GeometryStateDialog::loadSplitterState(QSplitter
*splitter
)
74 if (splitter
== nullptr) {
75 splitter
= findChild
<QSplitter
*>();
77 if (splitter
!= nullptr) {
78 const char* splitter_state
= window_splitter_load(dialog_name_
.toUtf8().constData());
79 if (splitter_state
!= nullptr) {
80 splitter
->restoreState(QByteArray::fromHex(splitter_state
));
85 void GeometryStateDialog::saveWindowGeometry()
87 if (dialog_name_
.isEmpty())
90 window_geometry_t geom
;
97 geom
.width
= size().width();
98 geom
.height
= size().height();
99 geom
.set_maximized
= true;
100 // XXX: maximized and fullScreen are different window states; we've been
101 // using the maximized key for fullScreen ever since this was added.
102 geom
.maximized
= isFullScreen();
103 geom
.qt_geom
= g_strdup(saveGeometry().toHex().constData());
105 window_geom_save(dialog_name_
.toUtf8().constData(), &geom
);
108 void GeometryStateDialog::saveSplitterState(const QSplitter
*splitter
)
110 if (splitter
== nullptr) {
111 splitter
= findChild
<QSplitter
*>();
113 if (splitter
!= nullptr) {
114 window_splitter_save(dialog_name_
.toUtf8().constData(), splitter
->saveState().toHex().constData());