diff options
author | Gerald Combs <gerald@wireshark.org> | 2013-01-19 00:57:57 +0000 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2013-01-19 00:57:57 +0000 |
commit | 2c5ce01f33e752222fa6fcaea8abe90e219c0753 (patch) | |
tree | bfc93a2b32cdf8b9e6b3a41052147bef7c556c4a /ui | |
parent | 69489bc85a6d420c8e9766574f63d07e4a679a4e (diff) |
Add an "Appearance" (aka "User Interface") preference pane. Having an
"Advanced" pane gives us the luxury of omitting some items in favor of
simplicity so do that.
svn path=/trunk/; revision=47158
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gtk/prefs_gui.c | 6 | ||||
-rw-r--r-- | ui/qt/CMakeLists.txt | 3 | ||||
-rw-r--r-- | ui/qt/Makefile.am | 3 | ||||
-rw-r--r-- | ui/qt/Makefile.common | 3 | ||||
-rw-r--r-- | ui/qt/QtShark.pro | 9 | ||||
-rw-r--r-- | ui/qt/main_window_preferences_frame.cpp | 183 | ||||
-rw-r--r-- | ui/qt/main_window_preferences_frame.h | 75 | ||||
-rw-r--r-- | ui/qt/main_window_preferences_frame.ui | 196 | ||||
-rw-r--r-- | ui/qt/preferences_dialog.cpp | 41 | ||||
-rw-r--r-- | ui/qt/preferences_dialog.h | 2 | ||||
-rw-r--r-- | ui/qt/preferences_dialog.ui | 24 |
11 files changed, 530 insertions, 15 deletions
diff --git a/ui/gtk/prefs_gui.c b/ui/gtk/prefs_gui.c index bb74311085..30d91854b6 100644 --- a/ui/gtk/prefs_gui.c +++ b/ui/gtk/prefs_gui.c @@ -277,7 +277,7 @@ gui_prefs_show(void) /* Number of recent entries in the display filter list ... */ recent_df_entries_max_te = create_preference_entry(main_tb, pos++, - "Filter display max. list entries:", + "Maximum recent filters:", "Maximum number of recent entries in filter display list.", recent_df_entries_max_str); g_snprintf(current_val_str, sizeof(current_val_str), "%d", prefs.gui_recent_df_entries_max); @@ -287,7 +287,7 @@ gui_prefs_show(void) /* Number of entries in the recent_files list ... */ recent_files_count_max_te = create_preference_entry(main_tb, pos++, - "\"Open Recent\" max. list entries:", + "Maximum recent files:", "Maximum number of entries in the \"File/Open Recent\" list.", recent_files_count_max_str); g_snprintf(current_val_str, sizeof(current_val_str), "%d", prefs.gui_recent_files_count_max); @@ -299,7 +299,7 @@ gui_prefs_show(void) /* ask for unsaved capture files? */ ask_unsaved_cb = create_preference_check_button(main_tb, pos++, - "Ask for unsaved capture files:", + "Confirm unsaved capture files:", "Whether a dialog should pop up in case of an unsaved capture file.", prefs.gui_ask_unsaved); g_object_set_data(G_OBJECT(main_vb), GUI_ASK_UNSAVED_KEY, ask_unsaved_cb); diff --git a/ui/qt/CMakeLists.txt b/ui/qt/CMakeLists.txt index 743602cfb2..15ffd0a739 100644 --- a/ui/qt/CMakeLists.txt +++ b/ui/qt/CMakeLists.txt @@ -43,6 +43,7 @@ set(QTSHARK_H_SRC main_status_bar.h main_welcome.h main_window.h + main_window_preferences_frame.h monospace_font.h packet_comment_dialog.h packet_format_group_box.h @@ -89,6 +90,7 @@ set(QTSHARK_CPP_SRC main_status_bar.cpp main_welcome.cpp main_window.cpp + main_window_preferences_frame.cpp main_window_slots.cpp monospace_font.cpp packet_comment_dialog.cpp @@ -123,6 +125,7 @@ set(QTSHARK_UI import_text_dialog.ui main_welcome.ui main_window.ui + main_window_preferences_frame.ui packet_comment_dialog.ui packet_format_group_box.ui packet_range_group_box.ui diff --git a/ui/qt/Makefile.am b/ui/qt/Makefile.am index 4a30d6ed39..3ca2b4900a 100644 --- a/ui/qt/Makefile.am +++ b/ui/qt/Makefile.am @@ -93,6 +93,8 @@ main_welcome.cpp main_welcome.h: ui_main_welcome.h main_window.cpp main_window.h: ui_main_window.h +main_window_preferences_frame.cpp main_window_preferences_frame.h: ui_main_window_preferences_frame.h + packet_comment_dialog.cpp packet_comment_dialog.h: ui_packet_comment_dialog.h packet_format_group_box.cpp packet_format_group_box.h: ui_packet_format_group_box.h @@ -169,6 +171,7 @@ EXTRA_DIST = \ Makefile_custom.common \ main_welcome.ui \ main_window.ui \ + main_window_preferences_frame.ui \ packet_format_group_box.ui \ packet_range_group_box.ui \ packet_comment_dialog.ui \ diff --git a/ui/qt/Makefile.common b/ui/qt/Makefile.common index 140974775b..21874903fb 100644 --- a/ui/qt/Makefile.common +++ b/ui/qt/Makefile.common @@ -36,6 +36,7 @@ GENERATED_NODIST_HEADER_FILES = \ ui_import_text_dialog.h \ ui_main_welcome.h \ ui_main_window.h \ + ui_main_window_preferences_frame.h \ ui_packet_comment_dialog.h \ ui_packet_format_group_box.h \ ui_packet_range_group_box.h \ @@ -98,6 +99,7 @@ MOC_HDRS = \ main_status_bar.h \ main_welcome.h \ main_window.h \ + main_window_preferences_frame.h \ monospace_font.h \ packet_comment_dialog.h \ packet_format_group_box.h \ @@ -181,6 +183,7 @@ WIRESHARK_QT_SRC = \ main_status_bar.cpp \ main_welcome.cpp \ main_window.cpp \ + main_window_preferences_frame.cpp \ main_window_slots.cpp \ monospace_font.cpp \ packet_comment_dialog.cpp \ diff --git a/ui/qt/QtShark.pro b/ui/qt/QtShark.pro index d29c0315b9..4407aff530 100644 --- a/ui/qt/QtShark.pro +++ b/ui/qt/QtShark.pro @@ -193,7 +193,8 @@ FORMS += main_window.ui \ splash_overlay.ui \ time_shift_dialog.ui \ profile_dialog.ui \ - preferences_dialog.ui + preferences_dialog.ui \ + main_window_preferences_frame.ui win32 { ## These should be in config.pri ?? !isEmpty(PORTAUDIO_DIR) { @@ -227,7 +228,8 @@ HEADERS += $$HEADERS_WS_C \ splash_overlay.h \ tango_colors.h \ profile_dialog.h \ - preferences_dialog.h + preferences_dialog.h \ + main_window_preferences_frame.h win32 { OBJECTS_WS_C = $$SOURCES_WS_C @@ -446,4 +448,5 @@ SOURCES += \ time_shift_dialog.cpp \ wireshark_application.cpp \ profile_dialog.cpp \ - preferences_dialog.cpp + preferences_dialog.cpp \ + main_window_preferences_frame.cpp diff --git a/ui/qt/main_window_preferences_frame.cpp b/ui/qt/main_window_preferences_frame.cpp new file mode 100644 index 0000000000..d435b03e9c --- /dev/null +++ b/ui/qt/main_window_preferences_frame.cpp @@ -0,0 +1,183 @@ +/* main_window_preferences_frame.cpp + * + * $Id: preferences_dialog.cpp 47142 2013-01-18 01:36:37Z gerald $ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "main_window_preferences_frame.h" +#include "ui_main_window_preferences_frame.h" + +#include <epan/prefs-int.h> + +#include <QFileDialog> +#include <QDebug> + +MainWindowPreferencesFrame::MainWindowPreferencesFrame(QWidget *parent) : + QFrame(parent), + ui(new Ui::MainWindowPreferencesFrame) +{ + ui->setupUi(this); + + pref_geometry_save_position_ = prefFromPrefPtr(&prefs.gui_geometry_save_position); + pref_geometry_save_size_ = prefFromPrefPtr(&prefs.gui_geometry_save_size); + pref_geometry_save_maximized_ = prefFromPrefPtr(&prefs.gui_geometry_save_maximized); + pref_fileopen_style_ = prefFromPrefPtr(&prefs.gui_fileopen_style); + pref_fileopen_dir_ = prefFromPrefPtr(&prefs.gui_fileopen_dir); + pref_recent_df_entries_max_ = prefFromPrefPtr(&prefs.gui_recent_df_entries_max); + pref_recent_files_count_max_ = prefFromPrefPtr(&prefs.gui_recent_files_count_max); + pref_ask_unsaved_ = prefFromPrefPtr(&prefs.gui_ask_unsaved); + pref_auto_scroll_on_expand_ = prefFromPrefPtr(&prefs.gui_auto_scroll_on_expand); + pref_auto_scroll_percentage_ = prefFromPrefPtr(&prefs.gui_auto_scroll_percentage); + + QStyleOption style_opt; + QString indent_ss = QString( + "QRadioButton, QLineEdit, QLabel {" + " margin-left: %1px;" + "}" + ).arg(ui->geometryCheckBox->style()->subElementRect(QStyle::SE_CheckBoxContents, &style_opt).left()); + ui->foStyleLastOpenedRadioButton->setStyleSheet(indent_ss); + ui->foStyleSpecifiedRadioButton->setStyleSheet(indent_ss); + ui->maxFilterLineEdit->setStyleSheet(indent_ss); + ui->maxRecentLineEdit->setStyleSheet(indent_ss); + + ui->autoScrollPercentageLabel->setStyleSheet(indent_ss); + + int num_entry_width = ui->maxFilterLineEdit->fontMetrics().height() * 3; + ui->maxFilterLineEdit->setMaximumWidth(num_entry_width); + ui->maxRecentLineEdit->setMaximumWidth(num_entry_width); + ui->autoScrollPercentageLineEdit->setMaximumWidth(num_entry_width); +} + +MainWindowPreferencesFrame::~MainWindowPreferencesFrame() +{ + delete ui; +} + +void MainWindowPreferencesFrame::showEvent(QShowEvent *evt) +{ + Q_UNUSED(evt); + updateWidgets(); +} + +void MainWindowPreferencesFrame::updateWidgets() +{ + // Yes, this means we're potentially clobbering two prefs in favor of one. + if (pref_geometry_save_position_->stashed_val.boolval || pref_geometry_save_size_->stashed_val.boolval || pref_geometry_save_maximized_->stashed_val.boolval) { + ui->geometryCheckBox->setChecked(true); + } else { + ui->geometryCheckBox->setChecked(false); + } + + if (pref_fileopen_style_->stashed_val.enumval == FO_STYLE_LAST_OPENED) { + ui->foStyleLastOpenedRadioButton->setChecked(true); + } else { + ui->foStyleSpecifiedRadioButton->setChecked(true); + } + + ui->foStyleSpecifiedLineEdit->setText(pref_fileopen_dir_->stashed_val.string); + + ui->maxFilterLineEdit->setText(QString::number(pref_recent_df_entries_max_->stashed_val.uint)); + ui->maxRecentLineEdit->setText(QString::number(pref_recent_files_count_max_->stashed_val.uint)); + + ui->autoScrollCheckBox->setChecked(pref_auto_scroll_on_expand_->stashed_val.boolval); + ui->autoScrollPercentageLineEdit->setText(QString::number(pref_auto_scroll_on_expand_->stashed_val.uint)); +} + +void MainWindowPreferencesFrame::on_geometryCheckBox_toggled(bool checked) +{ + pref_geometry_save_position_->stashed_val.boolval = checked; + pref_geometry_save_size_->stashed_val.boolval = checked; + pref_geometry_save_maximized_->stashed_val.boolval = checked; +} + +void MainWindowPreferencesFrame::on_foStyleLastOpenedRadioButton_toggled(bool checked) +{ + if (checked) { + pref_fileopen_style_->stashed_val.enumval = FO_STYLE_LAST_OPENED; + } +} + +void MainWindowPreferencesFrame::on_foStyleSpecifiedRadioButton_toggled(bool checked) +{ + if (checked) { + pref_fileopen_style_->stashed_val.enumval = FO_STYLE_SPECIFIED; + } +} + +void MainWindowPreferencesFrame::on_foStyleSpecifiedLineEdit_textEdited(const QString &new_dir) +{ + g_free(pref_fileopen_dir_->stashed_val.string); + pref_fileopen_dir_->stashed_val.string = g_strdup(new_dir.toUtf8().constData()); + pref_fileopen_style_->stashed_val.enumval = FO_STYLE_SPECIFIED; + updateWidgets(); +} + +void MainWindowPreferencesFrame::on_foStyleSpecifiedPushButton_clicked() +{ + QString specified_dir = QFileDialog::getExistingDirectory(this, tr("Open Files In")); + + if (specified_dir.isEmpty()) return; + + ui->foStyleSpecifiedLineEdit->setText(specified_dir); + g_free(pref_fileopen_dir_->stashed_val.string); + pref_fileopen_dir_->stashed_val.string = g_strdup(specified_dir.toUtf8().constData()); + pref_fileopen_style_->stashed_val.enumval = FO_STYLE_SPECIFIED; + updateWidgets(); +} + +void MainWindowPreferencesFrame::on_maxFilterLineEdit_textEdited(const QString &new_max) +{ + pref_recent_df_entries_max_->stashed_val.uint = new_max.toUInt(); +} + +void MainWindowPreferencesFrame::on_maxRecentLineEdit_textEdited(const QString &new_max) +{ + pref_recent_df_entries_max_->stashed_val.uint = new_max.toUInt(); +} + +void MainWindowPreferencesFrame::on_confirmUnsavedCheckBox_toggled(bool checked) +{ + pref_ask_unsaved_->stashed_val.boolval = checked; +} + +void MainWindowPreferencesFrame::on_autoScrollCheckBox_toggled(bool checked) +{ + pref_auto_scroll_on_expand_->stashed_val.boolval = checked; +} + +void MainWindowPreferencesFrame::on_autoScrollPercentageLineEdit_textEdited(const QString &new_pct) +{ + pref_auto_scroll_percentage_->stashed_val.uint = new_pct.toUInt(); + pref_auto_scroll_on_expand_->stashed_val.boolval = TRUE; + ui->autoScrollCheckBox->setChecked(true); +} + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 4 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=4 tabstop=8 expandtab: + * :indentSize=4:tabSize=8:noTabs=true: + */ diff --git a/ui/qt/main_window_preferences_frame.h b/ui/qt/main_window_preferences_frame.h new file mode 100644 index 0000000000..bb9a753ce2 --- /dev/null +++ b/ui/qt/main_window_preferences_frame.h @@ -0,0 +1,75 @@ +/* main_window_preferences_frame.h + * + * $Id: preferences_dialog.cpp 47142 2013-01-18 01:36:37Z gerald $ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MAIN_WINDOW_PREFERENCES_FRAME_H +#define MAIN_WINDOW_PREFERENCES_FRAME_H + +#include "preferences_dialog.h" + +#include <QFrame> + +namespace Ui { +class MainWindowPreferencesFrame; +} + +class MainWindowPreferencesFrame : public QFrame +{ + Q_OBJECT + +public: + explicit MainWindowPreferencesFrame(QWidget *parent = 0); + ~MainWindowPreferencesFrame(); + +protected: + void showEvent(QShowEvent *evt); + +private: + Ui::MainWindowPreferencesFrame *ui; + + pref_t *pref_geometry_save_position_; + pref_t *pref_geometry_save_size_; + pref_t *pref_geometry_save_maximized_; + pref_t *pref_fileopen_style_; + pref_t *pref_fileopen_dir_; + pref_t *pref_recent_df_entries_max_; + pref_t *pref_recent_files_count_max_; + pref_t *pref_ask_unsaved_; + pref_t *pref_auto_scroll_on_expand_; + pref_t *pref_auto_scroll_percentage_; + + void updateWidgets(); + +private slots: + void on_geometryCheckBox_toggled(bool checked); + void on_foStyleLastOpenedRadioButton_toggled(bool checked); + void on_foStyleSpecifiedRadioButton_toggled(bool checked); + void on_foStyleSpecifiedLineEdit_textEdited(const QString &new_dir); + void on_foStyleSpecifiedPushButton_clicked(); + void on_maxFilterLineEdit_textEdited(const QString &new_max); + void on_maxRecentLineEdit_textEdited(const QString &new_max); + void on_confirmUnsavedCheckBox_toggled(bool checked); + void on_autoScrollCheckBox_toggled(bool checked); + void on_autoScrollPercentageLineEdit_textEdited(const QString &new_pct); +}; + +#endif // MAIN_WINDOW_PREFERENCES_FRAME_H diff --git a/ui/qt/main_window_preferences_frame.ui b/ui/qt/main_window_preferences_frame.ui new file mode 100644 index 0000000000..fc7768fa04 --- /dev/null +++ b/ui/qt/main_window_preferences_frame.ui @@ -0,0 +1,196 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindowPreferencesFrame</class> + <widget class="QFrame" name="MainWindowPreferencesFrame"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>425</width> + <height>301</height> + </rect> + </property> + <property name="windowTitle"> + <string>Frame</string> + </property> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Plain</enum> + </property> + <property name="lineWidth"> + <number>0</number> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QCheckBox" name="geometryCheckBox"> + <property name="toolTip"> + <string>Checking this will save the size, position, and maximized state of the main window.</string> + </property> + <property name="text"> + <string>Remember main window size and placement</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Open files in</string> + </property> + </widget> + </item> + <item> + <layout class="QGridLayout" name="gridLayout"> + <item row="1" column="0"> + <widget class="QRadioButton" name="foStyleSpecifiedRadioButton"> + <property name="text"> + <string>This folder:</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">openInButtonGroup</string> + </attribute> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="foStyleSpecifiedLineEdit"/> + </item> + <item row="1" column="2"> + <widget class="QPushButton" name="foStyleSpecifiedPushButton"> + <property name="text"> + <string>Choose...</string> + </property> + </widget> + </item> + <item row="0" column="0" colspan="3"> + <widget class="QRadioButton" name="foStyleLastOpenedRadioButton"> + <property name="text"> + <string>The most recently used folder</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">openInButtonGroup</string> + </attribute> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Show up to</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,1"> + <item> + <widget class="QLineEdit" name="maxFilterLineEdit"/> + </item> + <item> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>filter entries</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_3" stretch="0,0,1"> + <item> + <widget class="QLineEdit" name="maxRecentLineEdit"/> + </item> + <item> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>recent files</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item> + <widget class="QCheckBox" name="confirmUnsavedCheckBox"> + <property name="text"> + <string>Confirm unsaved capture files</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="autoScrollCheckBox"> + <property name="toolTip"> + <string>If checked the packet detail items will be automatically scrolled when they are expanded.</string> + </property> + <property name="text"> + <string>Automatically scroll packet details</string> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_4" stretch="0,0,1"> + <item> + <widget class="QLabel" name="autoScrollPercentageLabel"> + <property name="toolTip"> + <string>Percentage distance from the top to scroll packet details.</string> + </property> + <property name="text"> + <string>Packet detail scroll percentage:</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="autoScrollPercentageLineEdit"> + <property name="toolTip"> + <string>Percentage distance from the top to scroll packet details.</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + </layout> + </widget> + <resources/> + <connections/> + <buttongroups> + <buttongroup name="openInButtonGroup"/> + </buttongroups> +</ui> diff --git a/ui/qt/preferences_dialog.cpp b/ui/qt/preferences_dialog.cpp index b40e8aa558..66addf704a 100644 --- a/ui/qt/preferences_dialog.cpp +++ b/ui/qt/preferences_dialog.cpp @@ -46,6 +46,13 @@ Q_DECLARE_METATYPE(pref_t *) +// XXX Should we move this to ui/preference_utils? +static QHash<void *, pref_t *> pref_ptr_to_pref_; +pref_t *prefFromPrefPtr(void *pref_ptr) +{ + return pref_ptr_to_pref_[pref_ptr]; +} + extern "C" { // Callbacks prefs routines @@ -90,6 +97,11 @@ fill_advanced_prefs(module_t *module, gpointer root_ptr) item->setToolTip(3, QString("<span>%1</span>").arg( default_value.isEmpty() ? default_value : "Default value is empty")); tl_children << item; + + // .uat is a void * so it wins the "useful key value" prize. + if (pref->varp.uat) { + pref_ptr_to_pref_[pref->varp.uat] = pref; + } } tl_item->addChildren(tl_children); @@ -161,11 +173,10 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : cur_line_edit_(NULL), cur_combo_box_(NULL) { - pd_ui_->setupUi(this); QTreeWidgetItem tmp_item; // Adding pre-populated top-level items is much faster - prefs_modules_foreach_submodules(NULL, fill_advanced_prefs, (gpointer) &tmp_item); + pd_ui_->setupUi(this); pd_ui_->advancedTree->invisibleRootItem()->addChildren(tmp_item.takeChildren()); QTreeWidgetItemIterator pref_it(pd_ui_->advancedTree, QTreeWidgetItemIterator::NoChildren); while (*pref_it) { @@ -179,7 +190,15 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) : pd_ui_->splitter->setStretchFactor(1, 5); pd_ui_->prefsTree->invisibleRootItem()->child(appearance_item_)->setExpanded(true); - pd_ui_->prefsTree->setCurrentItem(pd_ui_->prefsTree->invisibleRootItem()->child(advanced_item_)); + pd_ui_->prefsTree->setCurrentItem(pd_ui_->prefsTree->invisibleRootItem()->child(appearance_item_)); + + // This assumes that the prefs tree and stacked widget contents exactly + // correspond to each other. + QTreeWidgetItem *item = pd_ui_->prefsTree->itemAt(0,0); + for (int i = 0; i < pd_ui_->stackedWidget->count() && item; i++) { + item->setData(0, Qt::UserRole, qVariantFromValue(pd_ui_->stackedWidget->widget(i))); + item = pd_ui_->prefsTree->itemBelow(item); + } } PreferencesDialog::~PreferencesDialog() @@ -341,10 +360,18 @@ void PreferencesDialog::updateItem(QTreeWidgetItem &item) void PreferencesDialog::on_prefsTree_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { Q_UNUSED(previous) - QString frame_name = current->text(0).remove(" ").toLower().append("Frame"); - QFrame *frame = pd_ui_->stackedWidget->findChild<QFrame *>(frame_name); - if (frame) { - pd_ui_->stackedWidget->setCurrentWidget(frame); + + if (!current) return; + QWidget *new_item = current->data(0, Qt::UserRole).value<QWidget *>(); + if (new_item) { + pd_ui_->stackedWidget->setCurrentWidget(new_item); + if (new_item == pd_ui_->advancedFrame) { + QTreeWidgetItemIterator it(pd_ui_->advancedTree, QTreeWidgetItemIterator::NoChildren); + while (*it) { + updateItem(*(*it)); + ++it; + } + } } } diff --git a/ui/qt/preferences_dialog.h b/ui/qt/preferences_dialog.h index 4654146db0..6c9702bea8 100644 --- a/ui/qt/preferences_dialog.h +++ b/ui/qt/preferences_dialog.h @@ -37,6 +37,8 @@ #include <QTreeWidgetItem> #include <QComboBox> +extern pref_t *prefFromPrefPtr(void *pref_ptr); + namespace Ui { class PreferencesDialog; } diff --git a/ui/qt/preferences_dialog.ui b/ui/qt/preferences_dialog.ui index 8fd7b1e982..ed5ed9caf8 100644 --- a/ui/qt/preferences_dialog.ui +++ b/ui/qt/preferences_dialog.ui @@ -20,6 +20,12 @@ <enum>Qt::Horizontal</enum> </property> <widget class="QTreeWidget" name="prefsTree"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="uniformRowHeights"> <bool>true</bool> </property> @@ -107,10 +113,16 @@ </item> </widget> <widget class="QStackedWidget" name="stackedWidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> <property name="currentIndex"> - <number>9</number> + <number>0</number> </property> - <widget class="QFrame" name="appearanceFrame"/> + <widget class="MainWindowPreferencesFrame" name="appearanceFrame"/> <widget class="QFrame" name="layoutFrame"/> <widget class="QFrame" name="columnFrame"/> <widget class="QFrame" name="fontandcolorFrame"/> @@ -192,6 +204,14 @@ </item> </layout> </widget> + <customwidgets> + <customwidget> + <class>MainWindowPreferencesFrame</class> + <extends>QFrame</extends> + <header>main_window_preferences_frame.h</header> + <container>1</container> + </customwidget> + </customwidgets> <resources/> <connections> <connection> |