Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | 5f316da | 2015-09-28 11:57:42 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015 by Savoir-faire Linux * |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 3 | * 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 Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 23 | #include <QWinThumbnailToolBar> |
| 24 | #include <QWinThumbnailToolButton> |
| 25 | |
| 26 | #include "media/text.h" |
| 27 | #include "media/textrecording.h" |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 28 | |
| 29 | MainWindow::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 Milaret | 18e8184 | 2015-04-29 13:51:36 -0400 | [diff] [blame] | 38 | QIcon icon(":images/ring.png"); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 39 | |
| 40 | this->setWindowIcon(icon); |
| 41 | |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 42 | GlobalSystemTray& sysIcon = GlobalSystemTray::instance(); |
| 43 | sysIcon.setIcon(icon); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 44 | |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 45 | 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 Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 61 | this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); |
| 62 | |
Edric Milaret | 3a23e49 | 2015-04-29 14:23:48 -0400 | [diff] [blame] | 63 | connect(CallModel::instance(), SIGNAL(incomingCall(Call*)), |
| 64 | this, SLOT(onIncomingCall(Call*))); |
| 65 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 66 | navStack_ = new NavStack(ui->bar, ui->stackedWidgetView, this); |
| 67 | ui->verticalLayout_2->addWidget( |
| 68 | new QSizeGrip(this), 0, Qt::AlignBottom | Qt::AlignRight); |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 69 | connect(configAction, &QAction::triggered, [this]() { |
| 70 | navStack_->onNavigationRequested(ScreenEnum::ConfScreen); |
| 71 | }); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | MainWindow::~MainWindow() |
| 75 | { |
| 76 | delete ui; |
Edric Milaret | 01f2384 | 2015-06-22 14:46:01 -0400 | [diff] [blame] | 77 | delete navStack_; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void |
| 81 | MainWindow::mousePressEvent(QMouseEvent *evt) |
| 82 | { |
| 83 | oldPos_ = evt->globalPos(); |
| 84 | } |
| 85 | |
| 86 | void |
| 87 | MainWindow::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 | |
| 96 | void |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 97 | MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason) |
| 98 | { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 99 | if (reason != QSystemTrayIcon::ActivationReason::Context) |
| 100 | this->show(); |
| 101 | } |
Edric Milaret | 3a23e49 | 2015-04-29 14:23:48 -0400 | [diff] [blame] | 102 | |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 103 | void |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 104 | MainWindow::onIncomingCall(Call *call) |
| 105 | { |
Edric Milaret | 3a23e49 | 2015-04-29 14:23:48 -0400 | [diff] [blame] | 106 | Q_UNUSED(call); |
| 107 | QWidget::showNormal(); |
| 108 | } |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 109 | |
| 110 | void |
| 111 | MainWindow::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 | } |