qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
gui.h
Go to the documentation of this file.
1 /*
2  Copyright © 2015-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 
21 #pragma once
22 
23 #include <QObject>
24 
25 class QWidget;
26 
27 class GUI : public QObject
28 {
29  Q_OBJECT
30 public:
31  static GUI& getInstance();
32  static QWidget* getMainWidget();
33  static void setEnabled(bool state);
34  static void setWindowTitle(const QString& title);
35  static void reloadTheme();
36  static void showInfo(const QString& title, const QString& msg);
37  static void showWarning(const QString& title, const QString& msg);
38  static void showError(const QString& title, const QString& msg);
39  static bool askQuestion(const QString& title, const QString& msg, bool defaultAns = false,
40  bool warning = true, bool yesno = true);
41 
42  static bool askQuestion(const QString& title, const QString& msg, const QString& button1,
43  const QString& button2, bool defaultAns = false, bool warning = true);
44 
45 
46 private:
47  explicit GUI(QObject* parent = nullptr);
48 
49 private slots:
50  // Private implementation, those must be called from the GUI thread
51  void _setEnabled(bool state);
52  void _setWindowTitle(const QString& title);
53  void _showInfo(const QString& title, const QString& msg);
54  void _showWarning(const QString& title, const QString& msg);
55  void _showError(const QString& title, const QString& msg);
56  bool _askQuestion(const QString& title, const QString& msg, bool defaultAns = false,
57  bool warning = true, bool yesno = true);
58  bool _askQuestion(const QString& title, const QString& msg, const QString& button1,
59  const QString& button2, bool defaultAns = false, bool warning = true);
60 
61 signals:
62  void themeReload();
63 };
GUI::setEnabled
static void setEnabled(bool state)
Will enable or disable the GUI.
Definition: gui.cpp:69
GUI::_showWarning
void _showWarning(const QString &title, const QString &msg)
Definition: gui.cpp:237
GUI::askQuestion
static bool askQuestion(const QString &title, const QString &msg, bool defaultAns=false, bool warning=true, bool yesno=true)
Asks the user a question with Ok/Cancel or Yes/No buttons.
Definition: gui.cpp:169
GUI::_askQuestion
bool _askQuestion(const QString &title, const QString &msg, bool defaultAns=false, bool warning=true, bool yesno=true)
Definition: gui.cpp:251
GUI
Abstracts the GUI from the target backend (DesktopGUI, ...)
Definition: gui.h:27
GUI::setWindowTitle
static void setWindowTitle(const QString &title)
Change the title of the main window.
Definition: gui.cpp:85
GUI::getInstance
static GUI & getInstance()
Returns the singleton instance.
Definition: gui.cpp:56
GUI::_showError
void _showError(const QString &title, const QString &msg)
Definition: gui.cpp:244
GUI::showInfo
static void showInfo(const QString &title, const QString &msg)
Show some text to the user.
Definition: gui.cpp:115
GUI::themeReload
void themeReload()
GUI::getMainWidget
static QWidget * getMainWidget()
Get the main widget.
Definition: gui.cpp:280
GUI::_showInfo
void _showInfo(const QString &title, const QString &msg)
Definition: gui.cpp:230
GUI::reloadTheme
static void reloadTheme()
Reloads the application theme and redraw the window.
Definition: gui.cpp:101
GUI::showError
static void showError(const QString &title, const QString &msg)
Show an error to the user.
Definition: gui.cpp:145
GUI::showWarning
static void showWarning(const QString &title, const QString &msg)
Show a warning to the user.
Definition: gui.cpp:130
GUI::_setEnabled
void _setEnabled(bool state)
Definition: gui.cpp:212
GUI::_setWindowTitle
void _setWindowTitle(const QString &title)
Definition: gui.cpp:219
GUI::GUI
GUI(QObject *parent=nullptr)
Definition: gui.cpp:46