qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
settingswidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2014-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "settingswidget.h"
21 
22 #include "audio/audio.h"
23 #include "src/core/core.h"
24 #include "src/core/coreav.h"
25 #include "src/net/updatecheck.h"
27 #include "src/video/camerasource.h"
35 #include "src/widget/translator.h"
36 #include "src/widget/widget.h"
37 
38 #include <QLabel>
39 #include <QTabWidget>
40 #include <QWindow>
41 
42 #include <memory>
43 
44 SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, Core* core, Widget* parent)
45  : QWidget(parent, Qt::Window)
46 {
47  CoreAV* coreAV = core->getAv();
48  IAudioSettings* audioSettings = &Settings::getInstance();
49  IVideoSettings* videoSettings = &Settings::getInstance();
51 
52  setAttribute(Qt::WA_DeleteOnClose);
53 
54  bodyLayout = std::unique_ptr<QVBoxLayout>(new QVBoxLayout());
55 
56  settingsWidgets = std::unique_ptr<QTabWidget>(new QTabWidget(this));
57  settingsWidgets->setTabPosition(QTabWidget::North);
58  bodyLayout->addWidget(settingsWidgets.get());
59 
60  std::unique_ptr<GeneralForm> gfrm(new GeneralForm(this));
61  connect(gfrm.get(), &GeneralForm::updateIcons, parent, &Widget::updateIcons);
62 
63  std::unique_ptr<UserInterfaceForm> uifrm(new UserInterfaceForm(this));
64  std::unique_ptr<PrivacyForm> pfrm(new PrivacyForm(core));
65  connect(pfrm.get(), &PrivacyForm::clearAllReceipts, parent, &Widget::clearAllReceipts);
66 
67  AVForm* rawAvfrm = new AVForm(audio, coreAV, camera, audioSettings, videoSettings);
68  std::unique_ptr<AVForm> avfrm(rawAvfrm);
69  std::unique_ptr<AdvancedForm> expfrm(new AdvancedForm());
70  std::unique_ptr<AboutForm> abtfrm(new AboutForm(updateCheck));
71 
72 #if UPDATE_CHECK_ENABLED
73  if (updateCheck != nullptr) {
75  } else {
76  qWarning() << "SettingsWidget passed null UpdateCheck!";
77  }
78 #endif
79 
80  cfgForms = {{std::move(gfrm), std::move(uifrm), std::move(pfrm), std::move(avfrm),
81  std::move(expfrm), std::move(abtfrm)}};
82  for (auto& cfgForm : cfgForms)
83  settingsWidgets->addTab(cfgForm.get(), cfgForm->getFormIcon(), cfgForm->getFormName());
84 
85  connect(settingsWidgets.get(), &QTabWidget::currentChanged, this, &SettingsWidget::onTabChanged);
86 
88 }
89 
91 {
93 }
94 
96 {
97  settingsWidgets->setStyle(QStyleFactory::create(style));
98 }
99 
101 {
102  onTabChanged(settingsWidgets->count() - 1);
103 }
104 
106 {
107  if (settingsWidgets->isVisible()) {
108  settingsWidgets->window()->windowHandle()->alert(0);
109  return true;
110  }
111 
112  return false;
113 }
114 
116 {
117  contentLayout->mainContent->layout()->addWidget(settingsWidgets.get());
118  settingsWidgets->show();
119  onTabChanged(settingsWidgets->currentIndex());
120 }
121 
123 {
124  settingsWidgets->setCurrentIndex(index);
125 }
126 
128 {
129  settingsWidgets->tabBar()->setProperty("update-available", true);
130  settingsWidgets->tabBar()->style()->unpolish(settingsWidgets->tabBar());
131  settingsWidgets->tabBar()->style()->polish(settingsWidgets->tabBar());
132 }
133 
135 {
136  for (size_t i = 0; i < cfgForms.size(); ++i)
137  settingsWidgets->setTabText(i, cfgForms[i]->getFormName());
138 }
SettingsWidget::cfgForms
std::array< std::unique_ptr< GenericForm >, 6 > cfgForms
Definition: settingswidget.h:67
SettingsWidget::retranslateUi
void retranslateUi()
Definition: settingswidget.cpp:134
AboutForm
Definition: aboutform.h:35
Widget::updateIcons
void updateIcons()
Definition: widget.cpp:532
SettingsWidget::setBodyHeadStyle
void setBodyHeadStyle(QString style)
Definition: settingswidget.cpp:95
settings.h
Widget::clearAllReceipts
void clearAllReceipts()
Definition: widget.cpp:2446
SettingsWidget::bodyLayout
std::unique_ptr< QVBoxLayout > bodyLayout
Definition: settingswidget.h:65
GeneralForm
Definition: generalform.h:30
CameraSource
This class is a wrapper to share a camera's captured video frames.
Definition: camerasource.h:34
Translator::unregister
static void unregister(void *owner)
Unregisters all handlers of an owner.
Definition: translator.cpp:103
UpdateCheck::updateAvailable
void updateAvailable(QString latestVersion, QUrl link)
UserInterfaceForm
Definition: userinterfaceform.h:31
AVForm
Definition: avform.h:40
SettingsWidget::SettingsWidget
SettingsWidget(UpdateCheck *updateCheck, IAudioControl &audio, Core *core, Widget *parent=nullptr)
Definition: settingswidget.cpp:44
advancedform.h
Core::getAv
const CoreAV * getAv() const
Definition: core.cpp:703
coreav.h
updatecheck.h
userinterfaceform.h
SettingsWidget::isShown
bool isShown() const
Definition: settingswidget.cpp:105
camerasource.h
widget.h
SettingsWidget::showAbout
void showAbout()
Definition: settingswidget.cpp:100
aboutform.h
Translator::registerHandler
static void registerHandler(const std::function< void()> &, void *owner)
Register a function to be called when the UI needs to be retranslated.
Definition: translator.cpp:93
PrivacyForm::clearAllReceipts
void clearAllReceipts()
Settings::getInstance
static Settings & getInstance()
Returns the singleton instance.
Definition: settings.cpp:88
SettingsWidget::show
void show(ContentLayout *contentLayout)
Definition: settingswidget.cpp:115
GeneralForm::updateIcons
void updateIcons()
IVideoSettings
Definition: ivideosettings.h:27
CameraSource::getInstance
static CameraSource & getInstance()
Returns the singleton instance.
Definition: camerasource.cpp:128
SettingsWidget::settingsWidgets
std::unique_ptr< QTabWidget > settingsWidgets
Definition: settingswidget.h:66
contentlayout.h
settingswidget.h
SettingsWidget::~SettingsWidget
~SettingsWidget()
Definition: settingswidget.cpp:90
core.h
ContentLayout::mainContent
QWidget * mainContent
Definition: contentlayout.h:36
ContentLayout
Definition: contentlayout.h:25
privacyform.h
SettingsWidget::onUpdateAvailable
void onUpdateAvailable(void)
Definition: settingswidget.cpp:127
avform.h
generalform.h
translator.h
UpdateCheck
Definition: updatecheck.h:32
PrivacyForm
Definition: privacyform.h:30
CoreAV
Definition: coreav.h:47
SettingsWidget::onTabChanged
void onTabChanged(int)
Definition: settingswidget.cpp:122
Core
Definition: core.h:59
Widget
Definition: widget.h:87
AdvancedForm
Definition: advancedform.h:30