GeneralConfigWidget.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file GeneralConfigWidget.cpp
22 
23  \brief A frame for setting general options.
24 */
25 
26 // TerraLib
27 #include "../../../common/SystemApplicationSettings.h"
28 #include "../../../common/UserApplicationSettings.h"
29 #include "../../../core/utils/Platform.h"
30 #include "../../../qt/widgets/srs/SRSManagerDialog.h"
31 #include "../../../qt/widgets/utils/ColorPickerToolButton.h"
32 #include "../../../srs/Config.h"
33 #include "../ApplicationController.h"
34 #include "../Utils.h"
35 #include "GeneralConfigWidget.h"
36 #include "ui_GeneralConfigWidgetForm.h"
37 
38 // Qt
39 #include <QDir>
40 #include <QPushButton>
41 #include <QString>
42 
44  : AbstractSettingWidget(parent),
45  m_ui(new Ui::GeneralConfigWidgetForm),
46  m_defaultSRID(TE_UNKNOWN_SRS),
47  m_needRestart(false)
48 {
49  m_resumeText = tr("Changes the general configurations of the application.");
50 
51  m_ui->setupUi(this);
52 
53  initialize();
54 }
55 
57 {
58  if(m_needRestart)
59  {
60  QMessageBox msgBox(this);
61 
62  msgBox.setText(tr("The system must be restarted for the changes to take effect."));
63  msgBox.setInformativeText(tr("Do you want to do it now?"));
64  msgBox.setWindowTitle(tr("Restart system"));
65 
66  std::unique_ptr<QPushButton> restartButton;
67  restartButton.reset(msgBox.addButton(tr("Restart now"), QMessageBox::ActionRole));
68 
69  std::unique_ptr<QPushButton> laterResButton;
70  laterResButton.reset(msgBox.addButton(tr("Restart later"), QMessageBox::DestructiveRole));
71  msgBox.addButton(QMessageBox::NoButton);
72 
73  msgBox.setDefaultButton(restartButton.get());
74 
75  msgBox.exec();
76 
77  if(msgBox.clickedButton() == restartButton.get())
78  qApp->exit(1000);
79  }
80 }
81 
83 {
84  QSettings settings(QSettings::IniFormat, QSettings::UserScope, qApp->organizationName(), qApp->applicationName());
85 
86  QColor color = m_colorPicker->getColor();
87  // name: #AARRGGBB HexArgb
88  QString hexColor;
89  hexColor.sprintf("#%02x%02x%02x%02x", color.alpha(), color.red(), color.green(), color.blue());
90 
91  settings.setValue("srs/default_srid", m_defaultSRID);
92  settings.setValue("color/selection_color", hexColor);
93  settings.setValue("toolbars/icon_size", m_ui->m_toolBarIconSizeSpinBox->value());
94  settings.setValue("icon_theme/selected_theme", m_ui->m_iconThemeComboBox->currentText());
95 
97 
99 }
100 
102 {
103 }
104 
105 void te::qt::af::GeneralConfigWidget::getHelpInformations(QString& ns, QString& helpFile)
106 {
107  ns = "dpi.inpe.br.apf";
108  helpFile = "apf/settings/generalconfig/GeneralConfig.html";
109 }
110 
112 {
113  // Setup UI icons
114  m_ui->m_defaultSRSToolButton->setIcon(QIcon::fromTheme("srs"));
115 
116  // Create Color Picker to selection color
118  m_colorPicker->setFixedSize(70, 24);
119 
120  // Adjusting color picker...
121  QGridLayout* layout = new QGridLayout(m_ui->m_selectionColorFrame);
122  layout->setContentsMargins(0, 0, 0, 0);
123  layout->setSizeConstraint(QLayout::SetFixedSize);
124  layout->addWidget(m_colorPicker);
125 
126  // Get user settings
127  QSettings settings(QSettings::IniFormat, QSettings::UserScope, QApplication::instance()->organizationName(), QApplication::instance()->applicationName());
128 
129  // SRID
130  m_defaultSRID = settings.value("srs/default_srid", te::common::SystemApplicationSettings::getInstance().getValue("Application.DefaultSRID").c_str()).toInt();
131  setupSRSUi();
132 
133  // Selection Color
134  QString selectionColorName = settings.value("color/selection_color", te::common::SystemApplicationSettings::getInstance().getValue("Application.DefaultSelectionColor").c_str()).toString();
135  QColor selectionColor = QColor(selectionColorName);
136  m_colorPicker->setColor(selectionColor);
137 
138  // ToolBar Icon Size
139  int iconSize = settings.value("toolbars/icon_size", te::common::SystemApplicationSettings::getInstance().getValue("Application.ToolBarDefaultIconSize").c_str()).toInt();
140  m_ui->m_toolBarIconSizeSpinBox->setValue(iconSize);
141 
142  // Icon Theme
143  std::string iconThemesDirPath = te::core::FindInTerraLibPath(te::common::SystemApplicationSettings::getInstance().getValue("Application.IconThemeInfo.BaseDirectory.<xmlattr>.xlink:href"));
144  QDir iconThemesDir(iconThemesDirPath.c_str());
145 
146  // Find themes
147  QStringList themes = iconThemesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
148  m_ui->m_iconThemeComboBox->clear();
149  m_ui->m_iconThemeComboBox->addItems(themes);
150 
151  // Signals & slots
152  connect(m_ui->m_defaultSRSToolButton, SIGNAL(pressed()), SLOT(onDefaultSRSToolButtonPressed()));
153  connect(m_colorPicker, SIGNAL(colorChanged(const QColor&)), SLOT(onSelectionColorChanged(const QColor&)));
154  connect(m_ui->m_toolBarIconSizeSpinBox, SIGNAL(valueChanged(int)), SLOT(onToolBarIconSizeValueChanged(int)));
155  connect(m_ui->m_iconThemeComboBox, SIGNAL(currentIndexChanged(const QString&)), SLOT(onIconThemeCurrentIndexChanged(const QString&)));
156 }
157 
159 {
160  m_defaultSRID != TE_UNKNOWN_SRS ? m_ui->m_defaultSRSLineEdit->setText("EPSG:" + QString::number(m_defaultSRID)) : m_ui->m_defaultSRSLineEdit->setText(tr("Unknown SRS"));
161 }
162 
164 {
165  te::qt::widgets::SRSManagerDialog srsDialog(this);
166  srsDialog.setWindowTitle(tr("Choose the Default SRS"));
167 
168  if(srsDialog.exec() == QDialog::Rejected)
169  return;
170 
171  m_defaultSRID = srsDialog.getSelectedSRS().first;
172 
173  setupSRSUi();
174 
176 }
177 
179 {
181 }
182 
184  int /*value*/)
185 {
186  m_needRestart = true;
188 }
189 
191  const QString& /*value*/)
192 {
193  m_needRestart = true;
195 }
void onIconThemeCurrentIndexChanged(const QString &value)
te::qt::af::ApplicationController * m_app
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
A frame for setting general options.
Custom tool button used to pick a color.
static T & getInstance()
It returns a reference to the singleton instance.
Definition: Singleton.h:126
void getHelpInformations(QString &ns, QString &helpFile)
A frame for setting Table options.
std::unique_ptr< Ui::GeneralConfigWidgetForm > m_ui
te::qt::widgets::ColorPickerToolButton * m_colorPicker
void setSelectionColor(const QColor &c)
Sets the application selection color.
TECOREEXPORT std::string FindInTerraLibPath(const std::string &path)
Returns the path relative to a directory or file in the context of TerraLib.
A dialog used to build a SRSManagerDialog element.
virtual void changeApplyButtonState(const bool &state)
Indicates that there&#39;s unsaved information. Use this method after each change in informations of the ...
const std::pair< int, std::string > & getSelectedSRS() const
Returns the selected SRS in the window.
void onSelectionColorChanged(const QColor &color)