1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-22 10:12:10 +02:00
falkonOfficial/src/lib/desktopnotifications/desktopnotification.cpp
nowrep c7cdaf824f Qt5: Changing Q_WS_* macros to Q_OS_*
- Q_WS_* macros have been removed in Qt 5
2012-09-03 23:03:20 +02:00

104 lines
2.7 KiB
C++

/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.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/>.
* ============================================================ */
#include "desktopnotification.h"
#include "ui_desktopnotification.h"
#include <QTimer>
#include <QMouseEvent>
DesktopNotification::DesktopNotification(bool setPosition)
: QWidget(0)
, ui(new Ui::DesktopNotification)
, m_settingPosition(setPosition)
, m_timeout(6000)
, m_timer(new QTimer(this))
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint;
#ifdef Q_OS_WIN
flags |= Qt::ToolTip;
#endif
setWindowFlags(flags);
setAttribute(Qt::WA_TranslucentBackground);
setWindowOpacity(0.9);
m_timer->setSingleShot(true);
connect(m_timer, SIGNAL(timeout()), this, SLOT(close()));
if (m_settingPosition) {
setCursor(Qt::OpenHandCursor);
}
}
void DesktopNotification::show()
{
ui->icon->setPixmap(m_icon);
ui->heading->setText(m_heading);
ui->text->setText(m_text);
if (!m_settingPosition) {
m_timer->stop();
m_timer->setInterval(m_timeout);
m_timer->start();
}
QWidget::show();
}
void DesktopNotification::enterEvent(QEvent*)
{
if (!m_settingPosition) {
setWindowOpacity(0.5);
}
}
void DesktopNotification::leaveEvent(QEvent*)
{
if (!m_settingPosition) {
setWindowOpacity(0.9);
}
}
void DesktopNotification::mousePressEvent(QMouseEvent* e)
{
if (!m_settingPosition) {
close();
return;
}
if (e->button() == Qt::LeftButton) {
m_dragPosition = e->globalPos() - frameGeometry().topLeft();
e->accept();
}
}
void DesktopNotification::mouseMoveEvent(QMouseEvent* e)
{
if (e->buttons() & Qt::LeftButton) {
move(e->globalPos() - m_dragPosition);
e->accept();
}
}
DesktopNotification::~DesktopNotification()
{
delete ui;
}