blob: dd7957bb64c1eb9d26c82b591766a097e8798775 [file] [log] [blame]
Edric Milaret627500d2015-03-27 16:41:40 -04001/***************************************************************************
Edric Milaret5f316da2015-09-28 11:57:42 -04002 * Copyright (C) 2015 by Savoir-faire Linux *
Edric Milaret627500d2015-03-27 16:41:40 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program 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 General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19#include "mainwindow.h"
20#include "ui_mainwindow.h"
21
22#include <QSizeGrip>
Edric Milaret2cf34292015-06-22 16:27:03 -040023#include <QWinThumbnailToolBar>
24#include <QWinThumbnailToolButton>
25
26#include "media/text.h"
27#include "media/textrecording.h"
Edric Milaret627500d2015-03-27 16:41:40 -040028
29MainWindow::MainWindow(QWidget *parent) :
30 QMainWindow(parent),
31 ui(new Ui::MainWindow)
32{
33 ui->setupUi(this);
34
35 this->setWindowFlags(Qt::CustomizeWindowHint);
36 this->setWindowFlags(Qt::FramelessWindowHint);
37
Edric Milaret18e81842015-04-29 13:51:36 -040038 QIcon icon(":images/ring.png");
Edric Milaret627500d2015-03-27 16:41:40 -040039
40 this->setWindowIcon(icon);
41
Edric Milaret2cf34292015-06-22 16:27:03 -040042 GlobalSystemTray& sysIcon = GlobalSystemTray::instance();
43 sysIcon.setIcon(icon);
Edric Milaret627500d2015-03-27 16:41:40 -040044
Edric Milaret2cf34292015-06-22 16:27:03 -040045 QMenu *menu = new QMenu();
46
47 auto configAction = new QAction("Configuration", this);
48 menu->addAction(configAction);
49
50 auto exitAction = new QAction("Exit", this);
51 connect(exitAction, &QAction::triggered, []() {
52 QCoreApplication::exit();
53 });
54
55 menu->addAction(exitAction);
56
57 sysIcon.setContextMenu(menu);
58 sysIcon.show();
59
60 connect(&sysIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
Edric Milaret627500d2015-03-27 16:41:40 -040061 this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
62
Edric Milaret3a23e492015-04-29 14:23:48 -040063 connect(CallModel::instance(), SIGNAL(incomingCall(Call*)),
64 this, SLOT(onIncomingCall(Call*)));
65
Edric Milaret627500d2015-03-27 16:41:40 -040066 navStack_ = new NavStack(ui->bar, ui->stackedWidgetView, this);
67 ui->verticalLayout_2->addWidget(
68 new QSizeGrip(this), 0, Qt::AlignBottom | Qt::AlignRight);
Edric Milaret2cf34292015-06-22 16:27:03 -040069 connect(configAction, &QAction::triggered, [this]() {
70 navStack_->onNavigationRequested(ScreenEnum::ConfScreen);
71 });
Edric Milaret627500d2015-03-27 16:41:40 -040072}
73
74MainWindow::~MainWindow()
75{
76 delete ui;
Edric Milaret01f23842015-06-22 14:46:01 -040077 delete navStack_;
Edric Milaret627500d2015-03-27 16:41:40 -040078}
79
80void
81MainWindow::mousePressEvent(QMouseEvent *evt)
82{
83 oldPos_ = evt->globalPos();
84}
85
86void
87MainWindow::mouseMoveEvent(QMouseEvent *evt)
88{
89 if(evt->buttons() & Qt::LeftButton) {
90 const auto delta = evt->globalPos() - oldPos_;
91 move(x() + delta.x(), y() + delta.y());
92 oldPos_ = evt->globalPos();
93 }
94}
95
96void
Edric Milaret2cf34292015-06-22 16:27:03 -040097MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason)
98{
Edric Milaret627500d2015-03-27 16:41:40 -040099 if (reason != QSystemTrayIcon::ActivationReason::Context)
100 this->show();
101}
Edric Milaret3a23e492015-04-29 14:23:48 -0400102
Edric Milaret4bba46d2015-04-29 16:33:38 -0400103void
Edric Milaret2cf34292015-06-22 16:27:03 -0400104MainWindow::onIncomingCall(Call *call)
105{
Edric Milaret3a23e492015-04-29 14:23:48 -0400106 Q_UNUSED(call);
107 QWidget::showNormal();
108}
Edric Milaret2cf34292015-06-22 16:27:03 -0400109
110void
111MainWindow::createThumbBar()
112{
113 QWinThumbnailToolBar *thumbbar = new QWinThumbnailToolBar(this);
114 thumbbar->setWindow(this->windowHandle());
115 QWinThumbnailToolButton *settings = new QWinThumbnailToolButton(thumbbar);
116 settings->setToolTip("Settings");
117 QIcon icon(":/images/settings.png");
118 settings->setIcon(icon);
119 settings->setDismissOnClick(true);
120 connect(settings, &QWinThumbnailToolButton::clicked, [this]() {
121 navStack_->onNavigationRequested(ScreenEnum::ConfScreen);
122 });
123
124 thumbbar->addButton(settings);
125}