update epan/dissectors/pidl/drsuapi/drsuapi.idl from samba
[wireshark-sm.git] / ui / qt / layout_preferences_frame.cpp
blob693ef228891a070c71994998f2d31188a427051a
1 /* layout_preferences_frame.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
8 */
10 #include <config.h>
12 #include "layout_preferences_frame.h"
13 #include <ui_layout_preferences_frame.h>
15 #include <QAbstractButton>
16 #include <QToolButton>
17 #include <QRadioButton>
19 #include <QDebug>
20 #include <epan/prefs-int.h>
21 #include <ui/qt/models/pref_models.h>
23 LayoutPreferencesFrame::LayoutPreferencesFrame(QWidget *parent) :
24 QFrame(parent),
25 ui(new Ui::LayoutPreferencesFrame)
27 ui->setupUi(this);
29 pref_layout_type_ = prefFromPrefPtr(&prefs.gui_layout_type);
30 pref_layout_content_1_ = prefFromPrefPtr(&prefs.gui_layout_content_1);
31 pref_layout_content_2_ = prefFromPrefPtr(&prefs.gui_layout_content_2);
32 pref_layout_content_3_ = prefFromPrefPtr(&prefs.gui_layout_content_3);
34 QString image_pad_ss = "QToolButton { padding: 0.3em; }";
35 ui->layout1ToolButton->setStyleSheet(image_pad_ss);
36 ui->layout2ToolButton->setStyleSheet(image_pad_ss);
37 ui->layout3ToolButton->setStyleSheet(image_pad_ss);
38 ui->layout4ToolButton->setStyleSheet(image_pad_ss);
39 ui->layout5ToolButton->setStyleSheet(image_pad_ss);
40 ui->layout6ToolButton->setStyleSheet(image_pad_ss);
42 QStyleOption style_opt;
43 QString indent_ss = QString(
44 "QCheckBox, QLabel {"
45 " margin-left: %1px;"
46 "}"
47 ).arg(ui->packetListSeparatorCheckBox->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left());
48 ui->packetListSeparatorCheckBox->setStyleSheet(indent_ss);
49 ui->packetListHeaderShowColumnDefinition->setStyleSheet(indent_ss);
50 ui->packetListHoverStyleCheckbox->setStyleSheet(indent_ss);
51 ui->packetListAllowSorting->setStyleSheet(indent_ss);
52 ui->packetListCachedRowsLabel->setStyleSheet(indent_ss);
53 ui->statusBarShowSelectedPacketCheckBox->setStyleSheet(indent_ss);
54 ui->statusBarShowFileLoadTimeCheckBox->setStyleSheet(indent_ss);
56 pref_packet_list_separator_ = prefFromPrefPtr(&prefs.gui_packet_list_separator);
57 ui->packetListSeparatorCheckBox->setChecked(prefs_get_bool_value(pref_packet_list_separator_, pref_stashed));
59 pref_packet_header_column_definition_ = prefFromPrefPtr(&prefs.gui_packet_header_column_definition);
60 ui->packetListHeaderShowColumnDefinition->setChecked(prefs_get_bool_value(pref_packet_header_column_definition_, pref_stashed));
62 pref_packet_list_hover_style_ = prefFromPrefPtr(&prefs.gui_packet_list_hover_style);
63 ui->packetListHoverStyleCheckbox->setChecked(prefs_get_bool_value(pref_packet_list_hover_style_, pref_stashed));
65 pref_packet_list_sorting_ = prefFromPrefPtr(&prefs.gui_packet_list_sortable);
66 ui->packetListAllowSorting->setChecked(prefs_get_bool_value(pref_packet_list_sorting_, pref_stashed));
68 pref_packet_list_cached_rows_max_ = prefFromPrefPtr(&prefs.gui_packet_list_cached_rows_max);
70 pref_show_selected_packet_ = prefFromPrefPtr(&prefs.gui_show_selected_packet);
71 ui->statusBarShowSelectedPacketCheckBox->setChecked(prefs_get_bool_value(pref_show_selected_packet_, pref_stashed));
73 pref_show_file_load_time_ = prefFromPrefPtr(&prefs.gui_show_file_load_time);
74 ui->statusBarShowFileLoadTimeCheckBox->setChecked(prefs_get_bool_value(pref_show_file_load_time_, pref_stashed));
77 LayoutPreferencesFrame::~LayoutPreferencesFrame()
79 delete ui;
82 void LayoutPreferencesFrame::showEvent(QShowEvent *)
84 updateWidgets();
87 void LayoutPreferencesFrame::updateWidgets()
89 switch (prefs_get_uint_value_real(pref_layout_type_, pref_stashed)) {
90 case layout_type_5:
91 ui->layout5ToolButton->setChecked(true);
92 break;
93 case layout_type_2:
94 ui->layout2ToolButton->setChecked(true);
95 break;
96 case layout_type_1:
97 ui->layout1ToolButton->setChecked(true);
98 break;
99 case layout_type_4:
100 ui->layout4ToolButton->setChecked(true);
101 break;
102 case layout_type_3:
103 ui->layout3ToolButton->setChecked(true);
104 break;
105 case layout_type_6:
106 ui->layout6ToolButton->setChecked(true);
107 break;
110 switch (prefs_get_enum_value(pref_layout_content_1_, pref_stashed)) {
111 case layout_pane_content_plist:
112 ui->pane1PacketListRadioButton->setChecked(true);
113 break;
114 case layout_pane_content_pdetails:
115 ui->pane1PacketDetailsRadioButton->setChecked(true);
116 break;
117 case layout_pane_content_pbytes:
118 ui->pane1PacketBytesRadioButton->setChecked(true);
119 break;
120 case layout_pane_content_pdiagram:
121 ui->pane1PacketDiagramRadioButton->setChecked(true);
122 break;
123 case layout_pane_content_none:
124 ui->pane1NoneRadioButton->setChecked(true);
125 break;
128 switch (prefs_get_enum_value(pref_layout_content_2_, pref_stashed)) {
129 case layout_pane_content_plist:
130 ui->pane2PacketListRadioButton->setChecked(true);
131 break;
132 case layout_pane_content_pdetails:
133 ui->pane2PacketDetailsRadioButton->setChecked(true);
134 break;
135 case layout_pane_content_pbytes:
136 ui->pane2PacketBytesRadioButton->setChecked(true);
137 break;
138 case layout_pane_content_pdiagram:
139 ui->pane2PacketDiagramRadioButton->setChecked(true);
140 break;
141 case layout_pane_content_none:
142 ui->pane2NoneRadioButton->setChecked(true);
143 break;
146 switch (prefs_get_enum_value(pref_layout_content_3_, pref_stashed)) {
147 case layout_pane_content_plist:
148 ui->pane3PacketListRadioButton->setChecked(true);
149 break;
150 case layout_pane_content_pdetails:
151 ui->pane3PacketDetailsRadioButton->setChecked(true);
152 break;
153 case layout_pane_content_pbytes:
154 ui->pane3PacketBytesRadioButton->setChecked(true);
155 break;
156 case layout_pane_content_pdiagram:
157 ui->pane3PacketDiagramRadioButton->setChecked(true);
158 break;
159 case layout_pane_content_none:
160 ui->pane3NoneRadioButton->setChecked(true);
161 break;
164 ui->packetListCachedRowsLineEdit->setText(QString::number(prefs_get_uint_value_real(pref_packet_list_cached_rows_max_, pref_stashed)));
167 void LayoutPreferencesFrame::on_layout5ToolButton_toggled(bool checked)
169 if (!checked) return;
170 prefs_set_uint_value(pref_layout_type_, layout_type_5, pref_stashed);
173 void LayoutPreferencesFrame::on_layout2ToolButton_toggled(bool checked)
175 if (!checked) return;
176 prefs_set_uint_value(pref_layout_type_, layout_type_2, pref_stashed);
179 void LayoutPreferencesFrame::on_layout1ToolButton_toggled(bool checked)
181 if (!checked) return;
182 prefs_set_uint_value(pref_layout_type_, layout_type_1, pref_stashed);
185 void LayoutPreferencesFrame::on_layout4ToolButton_toggled(bool checked)
187 if (!checked) return;
188 prefs_set_uint_value(pref_layout_type_, layout_type_4, pref_stashed);
191 void LayoutPreferencesFrame::on_layout3ToolButton_toggled(bool checked)
193 if (!checked) return;
194 prefs_set_uint_value(pref_layout_type_, layout_type_3, pref_stashed);
197 void LayoutPreferencesFrame::on_layout6ToolButton_toggled(bool checked)
199 if (!checked) return;
200 prefs_set_uint_value(pref_layout_type_, layout_type_6, pref_stashed);
203 void LayoutPreferencesFrame::on_pane1PacketListRadioButton_toggled(bool checked)
205 if (!checked) return;
206 prefs_set_enum_value(pref_layout_content_1_, layout_pane_content_plist, pref_stashed);
207 if (ui->pane2PacketListRadioButton->isChecked())
208 ui->pane2NoneRadioButton->click();
209 if (ui->pane3PacketListRadioButton->isChecked())
210 ui->pane3NoneRadioButton->click();
213 void LayoutPreferencesFrame::on_pane1PacketDetailsRadioButton_toggled(bool checked)
215 if (!checked) return;
216 prefs_set_enum_value(pref_layout_content_1_, layout_pane_content_pdetails, pref_stashed);
217 if (ui->pane2PacketDetailsRadioButton->isChecked())
218 ui->pane2NoneRadioButton->click();
219 if (ui->pane3PacketDetailsRadioButton->isChecked())
220 ui->pane3NoneRadioButton->click();
223 void LayoutPreferencesFrame::on_pane1PacketBytesRadioButton_toggled(bool checked)
225 if (!checked) return;
226 prefs_set_enum_value(pref_layout_content_1_, layout_pane_content_pbytes, pref_stashed);
227 if (ui->pane2PacketBytesRadioButton->isChecked())
228 ui->pane2NoneRadioButton->click();
229 if (ui->pane3PacketBytesRadioButton->isChecked())
230 ui->pane3NoneRadioButton->click();
233 void LayoutPreferencesFrame::on_pane1PacketDiagramRadioButton_toggled(bool checked)
235 if (!checked) return;
236 prefs_set_enum_value(pref_layout_content_1_, layout_pane_content_pdiagram, pref_stashed);
237 if (ui->pane2PacketDiagramRadioButton->isChecked())
238 ui->pane2NoneRadioButton->click();
239 if (ui->pane3PacketDiagramRadioButton->isChecked())
240 ui->pane3NoneRadioButton->click();
243 void LayoutPreferencesFrame::on_pane1NoneRadioButton_toggled(bool checked)
245 if (!checked) return;
246 prefs_set_enum_value(pref_layout_content_1_, layout_pane_content_none, pref_stashed);
249 void LayoutPreferencesFrame::on_pane2PacketListRadioButton_toggled(bool checked)
251 if (!checked) return;
252 prefs_set_enum_value(pref_layout_content_2_, layout_pane_content_plist, pref_stashed);
253 if (ui->pane1PacketListRadioButton->isChecked())
254 ui->pane1NoneRadioButton->click();
255 if (ui->pane3PacketListRadioButton->isChecked())
256 ui->pane3NoneRadioButton->click();
259 void LayoutPreferencesFrame::on_pane2PacketDetailsRadioButton_toggled(bool checked)
261 if (!checked) return;
262 prefs_set_enum_value(pref_layout_content_2_, layout_pane_content_pdetails, pref_stashed);
263 if (ui->pane1PacketDetailsRadioButton->isChecked())
264 ui->pane1NoneRadioButton->click();
265 if (ui->pane3PacketDetailsRadioButton->isChecked())
266 ui->pane3NoneRadioButton->click();
269 void LayoutPreferencesFrame::on_pane2PacketBytesRadioButton_toggled(bool checked)
271 if (!checked) return;
272 prefs_set_enum_value(pref_layout_content_2_, layout_pane_content_pbytes, pref_stashed);
273 if (ui->pane1PacketBytesRadioButton->isChecked())
274 ui->pane1NoneRadioButton->click();
275 if (ui->pane3PacketBytesRadioButton->isChecked())
276 ui->pane3NoneRadioButton->click();
279 void LayoutPreferencesFrame::on_pane2PacketDiagramRadioButton_toggled(bool checked)
281 if (!checked) return;
282 prefs_set_enum_value(pref_layout_content_2_, layout_pane_content_pdiagram, pref_stashed);
283 if (ui->pane1PacketDiagramRadioButton->isChecked())
284 ui->pane1NoneRadioButton->click();
285 if (ui->pane3PacketDiagramRadioButton->isChecked())
286 ui->pane3NoneRadioButton->click();
289 void LayoutPreferencesFrame::on_pane2NoneRadioButton_toggled(bool checked)
291 if (!checked) return;
292 prefs_set_enum_value(pref_layout_content_2_, layout_pane_content_none, pref_stashed);
295 void LayoutPreferencesFrame::on_pane3PacketListRadioButton_toggled(bool checked)
297 if (!checked) return;
298 prefs_set_enum_value(pref_layout_content_3_, layout_pane_content_plist, pref_stashed);
299 if (ui->pane1PacketListRadioButton->isChecked())
300 ui->pane1NoneRadioButton->click();
301 if (ui->pane2PacketListRadioButton->isChecked())
302 ui->pane2NoneRadioButton->click();
305 void LayoutPreferencesFrame::on_pane3PacketDetailsRadioButton_toggled(bool checked)
307 if (!checked) return;
308 prefs_set_enum_value(pref_layout_content_3_, layout_pane_content_pdetails, pref_stashed);
309 if (ui->pane1PacketDetailsRadioButton->isChecked())
310 ui->pane1NoneRadioButton->click();
311 if (ui->pane2PacketDetailsRadioButton->isChecked())
312 ui->pane2NoneRadioButton->click();
315 void LayoutPreferencesFrame::on_pane3PacketBytesRadioButton_toggled(bool checked)
317 if (!checked) return;
318 prefs_set_enum_value(pref_layout_content_3_, layout_pane_content_pbytes, pref_stashed);
319 if (ui->pane1PacketBytesRadioButton->isChecked())
320 ui->pane1NoneRadioButton->click();
321 if (ui->pane2PacketBytesRadioButton->isChecked())
322 ui->pane2NoneRadioButton->click();
325 void LayoutPreferencesFrame::on_pane3PacketDiagramRadioButton_toggled(bool checked)
327 if (!checked) return;
328 prefs_set_enum_value(pref_layout_content_3_, layout_pane_content_pdiagram, pref_stashed);
329 if (ui->pane1PacketDiagramRadioButton->isChecked())
330 ui->pane1NoneRadioButton->click();
331 if (ui->pane2PacketDiagramRadioButton->isChecked())
332 ui->pane2NoneRadioButton->click();
335 void LayoutPreferencesFrame::on_pane3NoneRadioButton_toggled(bool checked)
337 if (!checked) return;
338 prefs_set_enum_value(pref_layout_content_3_, layout_pane_content_none, pref_stashed);
341 void LayoutPreferencesFrame::on_restoreButtonBox_clicked(QAbstractButton *)
343 reset_stashed_pref(pref_layout_type_);
344 reset_stashed_pref(pref_layout_content_1_);
345 updateWidgets();
346 reset_stashed_pref(pref_layout_content_2_);
347 updateWidgets();
348 reset_stashed_pref(pref_layout_content_3_);
349 updateWidgets();
351 ui->packetListSeparatorCheckBox->setChecked(prefs_get_bool_value(pref_packet_list_separator_, pref_default));
352 ui->packetListHeaderShowColumnDefinition->setChecked(prefs_get_bool_value(pref_packet_header_column_definition_, pref_default));
353 ui->packetListHoverStyleCheckbox->setChecked(prefs_get_bool_value(pref_packet_list_hover_style_, pref_default));
354 ui->packetListAllowSorting->setChecked(prefs_get_bool_value(pref_packet_list_sorting_, pref_default));
355 ui->statusBarShowSelectedPacketCheckBox->setChecked(prefs_get_bool_value(pref_show_selected_packet_, pref_default));
356 ui->statusBarShowFileLoadTimeCheckBox->setChecked(prefs_get_bool_value(pref_show_file_load_time_, pref_default));
359 void LayoutPreferencesFrame::on_packetListSeparatorCheckBox_toggled(bool checked)
361 prefs_set_bool_value(pref_packet_list_separator_, (bool) checked, pref_stashed);
364 void LayoutPreferencesFrame::on_packetListHeaderShowColumnDefinition_toggled(bool checked)
366 prefs_set_bool_value(pref_packet_header_column_definition_, (bool) checked, pref_stashed);
369 void LayoutPreferencesFrame::on_packetListHoverStyleCheckbox_toggled(bool checked)
371 prefs_set_bool_value(pref_packet_list_hover_style_, (bool) checked, pref_stashed);
374 void LayoutPreferencesFrame::on_packetListAllowSorting_toggled(bool checked)
376 prefs_set_bool_value(pref_packet_list_sorting_, (bool) checked, pref_stashed);
379 void LayoutPreferencesFrame::on_packetListCachedRowsLineEdit_textEdited(const QString &new_str)
381 bool ok;
382 uint new_uint = new_str.toUInt(&ok, 0);
383 if (ok) {
384 prefs_set_uint_value(pref_packet_list_cached_rows_max_, new_uint, pref_stashed);
388 void LayoutPreferencesFrame::on_statusBarShowSelectedPacketCheckBox_toggled(bool checked)
390 prefs_set_bool_value(pref_show_selected_packet_, (bool) checked, pref_stashed);
393 void LayoutPreferencesFrame::on_statusBarShowFileLoadTimeCheckBox_toggled(bool checked)
395 prefs_set_bool_value(pref_show_file_load_time_, (bool) checked, pref_stashed);