Falkon Develop
Cross-platform Qt-based web browser
desktopnotification.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2018 David Rosca <nowrep@gmail.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#include "desktopnotification.h"
19#include "ui_desktopnotification.h"
20
21#include <QTimer>
22#include <QMouseEvent>
23
25 : QWidget(nullptr)
26 , ui(new Ui::DesktopNotification)
27 , m_settingPosition(setPosition)
28 , m_timeout(6000)
29 , m_timer(new QTimer(this))
30{
31 ui->setupUi(this);
32 setAttribute(Qt::WA_DeleteOnClose);
33 setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
34
35 m_timer->setSingleShot(true);
36 connect(m_timer, &QTimer::timeout, this, &QWidget::close);
37
38 if (m_settingPosition) {
39 setCursor(Qt::OpenHandCursor);
40 }
41}
42
44{
45 ui->icon->setPixmap(m_icon);
46 ui->icon->setVisible(!m_icon.isNull());
47 ui->heading->setText(m_heading);
48 ui->text->setText(m_text);
49
50 if (!m_settingPosition) {
51 m_timer->setInterval(m_timeout);
52 m_timer->start();
53 }
54
55 QWidget::show();
56}
57
58void DesktopNotification::mousePressEvent(QMouseEvent* e)
59{
60 if (!m_settingPosition) {
61 close();
62 return;
63 }
64
65 if (e->buttons() == Qt::LeftButton) {
66 m_dragPosition = e->globalPosition().toPoint() - frameGeometry().topLeft();
67 e->accept();
68 }
69}
70
71void DesktopNotification::mouseMoveEvent(QMouseEvent* e)
72{
73 if (e->buttons() & Qt::LeftButton) {
74 move(e->globalPosition().toPoint() - m_dragPosition);
75 e->accept();
76 }
77}
78
80{
81 delete ui;
82}
DesktopNotification(bool setPosition=false)