Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -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> |
| 23 | |
| 24 | MainWindow::MainWindow(QWidget *parent) : |
| 25 | QMainWindow(parent), |
| 26 | ui(new Ui::MainWindow) |
| 27 | { |
| 28 | ui->setupUi(this); |
| 29 | |
| 30 | this->setWindowFlags(Qt::CustomizeWindowHint); |
| 31 | this->setWindowFlags(Qt::FramelessWindowHint); |
| 32 | |
Edric Milaret | 18e8184 | 2015-04-29 13:51:36 -0400 | [diff] [blame] | 33 | QIcon icon(":images/ring.png"); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 34 | |
| 35 | this->setWindowIcon(icon); |
| 36 | |
| 37 | sysIcon_.setIcon(icon); |
| 38 | sysIcon_.show(); |
| 39 | |
| 40 | connect(&sysIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), |
| 41 | this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason))); |
| 42 | |
Edric Milaret | 3a23e49 | 2015-04-29 14:23:48 -0400 | [diff] [blame] | 43 | connect(CallModel::instance(), SIGNAL(incomingCall(Call*)), |
| 44 | this, SLOT(onIncomingCall(Call*))); |
| 45 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 46 | navStack_ = new NavStack(ui->bar, ui->stackedWidgetView, this); |
| 47 | ui->verticalLayout_2->addWidget( |
| 48 | new QSizeGrip(this), 0, Qt::AlignBottom | Qt::AlignRight); |
| 49 | } |
| 50 | |
| 51 | MainWindow::~MainWindow() |
| 52 | { |
| 53 | delete ui; |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | MainWindow::mousePressEvent(QMouseEvent *evt) |
| 58 | { |
| 59 | oldPos_ = evt->globalPos(); |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | MainWindow::mouseMoveEvent(QMouseEvent *evt) |
| 64 | { |
| 65 | if(evt->buttons() & Qt::LeftButton) { |
| 66 | const auto delta = evt->globalPos() - oldPos_; |
| 67 | move(x() + delta.x(), y() + delta.y()); |
| 68 | oldPos_ = evt->globalPos(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason) { |
| 74 | if (reason != QSystemTrayIcon::ActivationReason::Context) |
| 75 | this->show(); |
| 76 | } |
Edric Milaret | 3a23e49 | 2015-04-29 14:23:48 -0400 | [diff] [blame] | 77 | |
Edric Milaret | 4bba46d | 2015-04-29 16:33:38 -0400 | [diff] [blame] | 78 | void |
| 79 | MainWindow::onIncomingCall(Call *call) { |
Edric Milaret | 3a23e49 | 2015-04-29 14:23:48 -0400 | [diff] [blame] | 80 | Q_UNUSED(call); |
| 81 | QWidget::showNormal(); |
| 82 | } |