preferences_dialog.cpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5  */
6 
7 #include "preferences_dialog.h"
8 #include "ui_preferences_dialog.h"
9 #include <QSettings>
10 #include <QDir>
11 #include <QFileDialog>
12 #include "PlotJuggler/svg_util.h"
13 
15  : QDialog(parent), ui(new Ui::PreferencesDialog)
16 {
17  ui->setupUi(this);
18  QSettings settings;
19  QString theme = settings.value("Preferences::theme", "light").toString();
20  if (theme == "dark")
21  {
22  ui->comboBoxTheme->setCurrentIndex(1);
23  }
24  else
25  {
26  ui->comboBoxTheme->setCurrentIndex(0);
27  }
28 
29  bool use_plot_color_index =
30  settings.value("Preferences::use_plot_color_index", false).toBool();
31  bool remember_color = settings.value("Preferences::remember_color", true).toBool();
32 
33  ui->checkBoxRememberColor->setChecked(remember_color);
34  ui->radioLocalColorIndex->setChecked(use_plot_color_index);
35  ui->radioGlobalColorIndex->setChecked(!use_plot_color_index);
36 
37  ui->pushButtonAdd->setIcon(LoadSvg(":/resources/svg/add_tab.svg", theme));
38  ui->pushButtonRemove->setIcon(LoadSvg(":/resources/svg/trash.svg", theme));
39 
40  bool use_separator = settings.value("Preferences::use_separator", true).toBool();
41  ui->checkBoxSeparator->setChecked(use_separator);
42 
43  bool use_opengl = settings.value("Preferences::use_opengl", true).toBool();
44  ui->checkBoxOpenGL->setChecked(use_opengl);
45 
46  bool autozoom_visibility =
47  settings.value("Preferences::autozoom_visibility", true).toBool();
48  ui->checkBoxAutoZoomVisibility->setChecked(autozoom_visibility);
49 
50  bool autozoom_curve_added =
51  settings.value("Preferences::autozoom_curve_added", true).toBool();
52  ui->checkBoxAutoZoomAdded->setChecked(autozoom_curve_added);
53 
54  bool autozoom_filter_applied =
55  settings.value("Preferences::autozoom_filter_applied", true).toBool();
56  ui->checkBoxAutoZoomFilter->setChecked(autozoom_filter_applied);
57 
58  bool truncation_check = settings.value("Preferences::truncation_check", true).toBool();
59  ui->checkBoxTruncation->setChecked(truncation_check);
60 
61  //---------------
62  auto custom_plugin_folders =
63  settings.value("Preferences::plugin_folders", true).toStringList();
64  for (const auto& folder : custom_plugin_folders)
65  {
66  QDir dir(folder);
67  auto item = new QListWidgetItem(folder);
68  if (!dir.exists())
69  {
70  item->setForeground(Qt::red);
71  }
72  ui->listWidgetCustom->addItem(item);
73  };
74  ui->pushButtonRemove->setEnabled(!ui->listWidgetCustom->selectedItems().isEmpty());
75  //---------------
76  auto builtin_plugin_folders =
77  settings.value("Preferences::builtin_plugin_folders", true).toStringList();
78  for (const auto& folder : builtin_plugin_folders)
79  {
80  ui->listWidgetBuiltin->addItem(new QListWidgetItem(folder));
81  };
82 }
83 
85 {
86  delete ui;
87 }
88 
90 {
91  QSettings settings;
92  settings.setValue("Preferences::theme",
93  ui->comboBoxTheme->currentIndex() == 1 ? "dark" : "light");
94  settings.setValue("Preferences::remember_color",
95  ui->checkBoxRememberColor->isChecked());
96  settings.setValue("Preferences::use_plot_color_index",
97  ui->radioLocalColorIndex->isChecked());
98  settings.setValue("Preferences::use_separator", ui->checkBoxSeparator->isChecked());
99  settings.setValue("Preferences::use_opengl", ui->checkBoxOpenGL->isChecked());
100  settings.setValue("Preferences::autozoom_visibility",
101  ui->checkBoxAutoZoomVisibility->isChecked());
102  settings.setValue("Preferences::autozoom_curve_added",
103  ui->checkBoxAutoZoomAdded->isChecked());
104  settings.setValue("Preferences::autozoom_filter_applied",
105  ui->checkBoxAutoZoomFilter->isChecked());
106  settings.setValue("Preferences::truncation_check", ui->checkBoxTruncation->isChecked());
107 
108  QStringList plugin_folders;
109  for (int row = 0; row < ui->listWidgetCustom->count(); row++)
110  {
111  plugin_folders.push_back(ui->listWidgetCustom->item(row)->text());
112  }
113  settings.setValue("Preferences::plugin_folders", plugin_folders);
114 
115  settings.sync();
116 }
117 
119 {
120  QString dir = QFileDialog::getExistingDirectory(
121  this, tr("Select a Directory"), QDir::homePath(),
122  QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
123  auto item = new QListWidgetItem(dir);
124  ui->listWidgetCustom->addItem(item);
125 }
126 
128 {
129  auto selected = ui->listWidgetCustom->selectedItems();
130 
131  for (QListWidgetItem* item : selected)
132  {
133  ui->listWidgetCustom->removeItemWidget(item);
134  delete item;
135  }
136 }
137 
139 {
140  ui->pushButtonRemove->setEnabled(!ui->listWidgetCustom->selectedItems().isEmpty());
141 }
PreferencesDialog::~PreferencesDialog
~PreferencesDialog()
Definition: preferences_dialog.cpp:84
PreferencesDialog::ui
Ui::PreferencesDialog * ui
Definition: preferences_dialog.h:35
LoadSvg
const QPixmap & LoadSvg(QString filename, QString style_name="light")
Definition: svg_util.h:26
PreferencesDialog::on_pushButtonAdd_clicked
void on_pushButtonAdd_clicked()
Definition: preferences_dialog.cpp:118
PreferencesDialog
Definition: preferences_dialog.h:17
PreferencesDialog::on_buttonBox_accepted
void on_buttonBox_accepted()
Definition: preferences_dialog.cpp:89
PreferencesDialog::on_listWidgetCustom_itemSelectionChanged
void on_listWidgetCustom_itemSelectionChanged()
Definition: preferences_dialog.cpp:138
Ui
Definition: cheatsheet_dialog.h:6
PreferencesDialog::on_pushButtonRemove_clicked
void on_pushButtonRemove_clicked()
Definition: preferences_dialog.cpp:127
preferences_dialog.h
svg_util.h
PreferencesDialog::PreferencesDialog
PreferencesDialog(QWidget *parent=nullptr)
Definition: preferences_dialog.cpp:14


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45