mainwindow.h 3.59 KB
Newer Older
Edric Milaret's avatar
Edric Milaret committed
1
/***************************************************************************
2
 * Copyright (C) 2015-2019 by Savoir-faire Linux                           *
Edric Milaret's avatar
Edric Milaret committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
 *                                                                         *
 * 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 3 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, see <http://www.gnu.org/licenses/>.   *
 **************************************************************************/

Edric Milaret's avatar
Edric Milaret committed
19
#pragma once
Edric Milaret's avatar
Edric Milaret committed
20

21
22
23
24
#include "navwidget.h"
#include "settingswidget.h"
#include "utils.h"
#include "connectivitymonitor.h"
25
#include "globalsystemtray.h"
26
#include "widgethelpers.h"
27

Edric Milaret's avatar
Edric Milaret committed
28
29
#include <QMainWindow>
#include <QMouseEvent>
30

31
static constexpr char IDM_ABOUTBOX = 0x0010;
32
static constexpr char IDM_SHORTCUTSBOX = 0x0011;
33

34
35
static constexpr uint32_t QtMaxDimension = 16777215;
static constexpr uint32_t mainWindowMinWidth = 1088;
Andreas Traczyk's avatar
Andreas Traczyk committed
36
static constexpr uint32_t mainWindowMinHeight = 638;
37
static constexpr uint32_t wizardDialogWidth = 512;
Andreas Traczyk's avatar
Andreas Traczyk committed
38
static constexpr uint32_t wizardDialogHeight = 638;
39

Edric Milaret's avatar
Edric Milaret committed
40
41
42
43
44
45
46
47
48
namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
49
50
51
52
    inline static MainWindow& instance()  {
        static auto instance = new MainWindow();
        return *instance;
    }
Olivier SOLDANO's avatar
Olivier SOLDANO committed
53
    bool init();
54
    void show();
55
    float getCurrentScalingRatio();
Andreas Traczyk's avatar
Andreas Traczyk committed
56
    void showWindow();
57
58
    void darken();
    void lighten();
59

60
protected:
61
62
63
64
65
    bool nativeEvent(const QByteArray& eventType, void* message, long* result) override;
    void closeEvent(QCloseEvent* event) override;
    void resizeEvent(QResizeEvent *event) override;
    void keyReleaseEvent(QKeyEvent* ke) override;
    void changeEvent(QEvent* e) override;
66
67
68

signals:
    void keyReleased(QKeyEvent*ke);
69

70
71
72
protected:
    const QUrl qmlKeyBoardShortcutTable_ { QStringLiteral("qrc:/src/KeyBoardShortcutTable.qml") };

Edric Milaret's avatar
Edric Milaret committed
73
private slots:
74
    void slotCurrentChanged(int index);
Edric Milaret's avatar
Edric Milaret committed
75
    void trayActivated(QSystemTrayIcon::ActivationReason reason);
Edric Milaret's avatar
Edric Milaret committed
76
    void notificationClicked();
77
    void slotScreenChanged(QScreen* screen);
78
    void slotAccountListChanged();
79
    void generateQmlDialog(const QUrl& qmlSource);
Edric Milaret's avatar
Edric Milaret committed
80
81

private:
Edric Milaret's avatar
Edric Milaret committed
82
    explicit MainWindow(QWidget* parent = 0);
83
84
    ~MainWindow();

85
86
    Ui::MainWindow* ui;

87
88
    void setWindowSize(ScreenEnum scr, bool firstUse = false);
    ScreenEnum lastScr_;
89
    int lastAccountCount_;
90
    Qt::WindowFlags flags_;
91
    float currentScalingRatio_;
92
    Qt::WindowState currentWindowState_{ Qt::WindowState::WindowNoState };
93

94
    void readSettingsFromRegistry();
95

96
97
    QAction* settingsAction_;
    QAction* exitAction_;
98
    QAction* keyboardShortcutsAction_;
99
#ifdef Q_OS_WIN
100
    std::unique_ptr<ConnectivityMonitor> connectivityMonitor_;
101
#endif // Q_OS_WIN
102
    QMetaObject::Connection screenChangedConnection_;
103

104
105
106
    QTimer* updateTimer_;

    Darkenable* overlay_;
Edric Milaret's avatar
Edric Milaret committed
107
};