blob: b65b267f61f4e7bb8a5b3c8c678b12c34de12ea0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
/* main_window_layout.cpp
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <config.h>
#include <ui/qt/main_window.h>
#include <ui/qt/widgets/additional_toolbar.h>
#include "ui/recent.h"
#include "epan/prefs.h"
#include <QSplitter>
#include <QVector>
#include <QList>
#include <QWidget>
#include <QRect>
#include <QAction>
#include <QStackedWidget>
#include <QToolBar>
#include <ui/qt/byte_view_tab.h>
#include <ui/qt/packet_list.h>
#include <ui/qt/packet_diagram.h>
#include <ui/qt/proto_tree.h>
#include <ui/qt/welcome_page.h>
#include <wsutil/ws_assert.h>
void MainWindow::showWelcome()
{
main_stack_->setCurrentWidget(welcome_page_);
}
void MainWindow::showCapture()
{
main_stack_->setCurrentWidget(&master_split_);
}
QWidget* MainWindow::getLayoutWidget(layout_pane_content_e type) {
switch (type) {
case layout_pane_content_none:
return &empty_pane_;
case layout_pane_content_plist:
return packet_list_;
case layout_pane_content_pdetails:
return proto_tree_;
case layout_pane_content_pbytes:
return byte_view_tab_;
case layout_pane_content_pdiagram:
return packet_diagram_;
default:
ws_assert_not_reached();
return NULL;
}
}
// A new layout should be applied when it differs from the old layout AND
// at the following times:
// - At startup
// - When the preferences change
// - When the profile changes
void MainWindow::layoutPanes()
{
QVector<unsigned> new_layout = QVector<unsigned>() << prefs.gui_layout_type
<< prefs.gui_layout_content_1
<< prefs.gui_layout_content_2
<< prefs.gui_layout_content_3
<< recent.packet_list_show
<< recent.tree_view_show
<< recent.byte_view_show
<< recent.packet_diagram_show;
if (cur_layout_ == new_layout) return;
QSplitter *parents[3];
// Reparent all widgets and add them back in the proper order below.
// This hides each widget as well.
bool frozen = packet_list_->freeze(); // Clears tree, byte view tabs, and diagram.
packet_list_->setParent(main_stack_);
proto_tree_->setParent(main_stack_);
byte_view_tab_->setParent(main_stack_);
packet_diagram_->setParent(main_stack_);
empty_pane_.setParent(main_stack_);
extra_split_.setParent(main_stack_);
// XXX We should try to preserve geometries if we can, e.g. by
// checking to see if the layout type is the same.
switch(prefs.gui_layout_type) {
case(layout_type_2):
case(layout_type_1):
extra_split_.setOrientation(Qt::Horizontal);
/* Fall Through */
case(layout_type_5):
master_split_.setOrientation(Qt::Vertical);
break;
case(layout_type_4):
case(layout_type_3):
extra_split_.setOrientation(Qt::Vertical);
/* Fall Through */
case(layout_type_6):
master_split_.setOrientation(Qt::Horizontal);
break;
default:
ws_assert_not_reached();
}
switch(prefs.gui_layout_type) {
case(layout_type_5):
case(layout_type_6):
parents[0] = &master_split_;
parents[1] = &master_split_;
parents[2] = &master_split_;
break;
case(layout_type_2):
case(layout_type_4):
parents[0] = &master_split_;
parents[1] = &extra_split_;
parents[2] = &extra_split_;
break;
case(layout_type_1):
case(layout_type_3):
parents[0] = &extra_split_;
parents[1] = &extra_split_;
parents[2] = &master_split_;
break;
default:
ws_assert_not_reached();
}
if (parents[0] == &extra_split_) {
master_split_.addWidget(&extra_split_);
}
parents[0]->addWidget(getLayoutWidget(prefs.gui_layout_content_1));
if (parents[2] == &extra_split_) {
master_split_.addWidget(&extra_split_);
}
parents[1]->addWidget(getLayoutWidget(prefs.gui_layout_content_2));
parents[2]->addWidget(getLayoutWidget(prefs.gui_layout_content_3));
if (frozen) {
// Show the packet list here to prevent pending resize events changing columns
// when the packet list is set as current widget for the first time.
packet_list_->show();
}
const QList<QWidget *> ms_children = master_split_.findChildren<QWidget *>();
extra_split_.setVisible(ms_children.contains(&extra_split_));
packet_list_->setVisible(ms_children.contains(packet_list_) && recent.packet_list_show);
proto_tree_->setVisible(ms_children.contains(proto_tree_) && recent.tree_view_show);
byte_view_tab_->setVisible(ms_children.contains(byte_view_tab_) && recent.byte_view_show);
packet_diagram_->setVisible(ms_children.contains(packet_diagram_) && recent.packet_diagram_show);
if (frozen) {
packet_list_->thaw(true);
}
cur_layout_ = new_layout;
}
// The recent layout geometry should be applied after the layout has been
// applied AND at the following times:
// - At startup
// - When the profile changes
void MainWindow::applyRecentPaneGeometry()
{
// XXX This shrinks slightly each time the application is run. For some
// reason the master_split_ geometry is two pixels shorter when
// saveWindowGeometry is invoked.
// This is also an awful lot of trouble to go through to reuse the GTK+
// pane settings. We might want to add gui.geometry_main_master_sizes
// and gui.geometry_main_extra_sizes and save QSplitter::saveState in
// each.
// Force a geometry recalculation
QWidget *cur_w = main_stack_->currentWidget();
showCapture();
QRect geom = main_stack_->geometry();
QList<int> master_sizes = master_split_.sizes();
QList<int> extra_sizes = extra_split_.sizes();
main_stack_->setCurrentWidget(cur_w);
int master_last_size = master_split_.orientation() == Qt::Vertical ? geom.height() : geom.width();
master_last_size -= master_split_.handleWidth() * (master_sizes.length() - 1);
int extra_last_size = extra_split_.orientation() == Qt::Vertical ? geom.height() : geom.width();
extra_last_size -= extra_split_.handleWidth();
if (recent.gui_geometry_main_upper_pane > 0) {
master_sizes[0] = recent.gui_geometry_main_upper_pane;
master_last_size -= recent.gui_geometry_main_upper_pane;
} else {
master_sizes[0] = master_last_size / master_sizes.length();
master_last_size -= master_last_size / master_sizes.length();
}
if (recent.gui_geometry_main_lower_pane > 0) {
if (master_sizes.length() > 2) {
master_sizes[1] = recent.gui_geometry_main_lower_pane;
master_last_size -= recent.gui_geometry_main_lower_pane;
} else if (extra_sizes.length() > 0) {
extra_sizes[0] = recent.gui_geometry_main_lower_pane;
extra_last_size -= recent.gui_geometry_main_lower_pane;
extra_sizes.last() = extra_last_size;
}
} else {
if (master_sizes.length() > 2) {
master_sizes[1] = master_last_size / 2;
master_last_size -= master_last_size / 2;
} else if (extra_sizes.length() > 0) {
extra_sizes[0] = extra_last_size / 2;
extra_last_size -= extra_last_size / 2;
extra_sizes.last() = extra_last_size;
}
}
master_sizes.last() = master_last_size;
master_split_.setSizes(master_sizes);
extra_split_.setSizes(extra_sizes);
}
|