2011-04-27 09:05:54 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-04-27 09:05:54 +02:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
* ============================================================ */
|
2011-04-22 16:03:38 +02:00
|
|
|
#include "desktopnotification.h"
|
|
|
|
#include "ui_desktopnotification.h"
|
|
|
|
|
2011-04-27 09:49:41 +02:00
|
|
|
DesktopNotification::DesktopNotification(bool setPosition)
|
2011-11-06 17:01:23 +01:00
|
|
|
: QWidget(0)
|
|
|
|
, ui(new Ui::DesktopNotification)
|
|
|
|
, m_settingPosition(setPosition)
|
|
|
|
, m_timeout(6000)
|
|
|
|
, m_timer(new QTimer(this))
|
2011-04-22 16:03:38 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2011-04-27 09:49:41 +02:00
|
|
|
Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint;
|
2011-11-06 17:01:23 +01:00
|
|
|
#ifdef Q_WS_WIN
|
2011-04-22 16:03:38 +02:00
|
|
|
flags |= Qt::ToolTip;
|
2011-11-06 17:01:23 +01:00
|
|
|
#endif
|
2011-04-22 16:03:38 +02:00
|
|
|
setWindowFlags(flags);
|
2012-02-04 23:52:36 +01:00
|
|
|
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
2011-04-22 16:03:38 +02:00
|
|
|
setWindowOpacity(0.9);
|
|
|
|
|
2011-04-23 22:33:25 +02:00
|
|
|
m_timer->setSingleShot(true);
|
|
|
|
connect(m_timer, SIGNAL(timeout()), this, SLOT(close()));
|
2011-04-27 09:49:41 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_settingPosition) {
|
2011-04-26 19:47:12 +02:00
|
|
|
setCursor(Qt::OpenHandCursor);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-23 22:33:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopNotification::show()
|
|
|
|
{
|
|
|
|
ui->icon->setPixmap(m_icon);
|
2011-04-24 22:40:35 +02:00
|
|
|
ui->heading->setText(m_heading);
|
2011-04-23 22:33:25 +02:00
|
|
|
ui->text->setText(m_text);
|
2011-04-22 16:03:38 +02:00
|
|
|
|
2011-04-23 22:33:25 +02:00
|
|
|
if (!m_settingPosition) {
|
|
|
|
m_timer->stop();
|
|
|
|
m_timer->setInterval(m_timeout);
|
|
|
|
m_timer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::show();
|
2011-04-22 16:03:38 +02:00
|
|
|
}
|
|
|
|
|
2011-04-27 09:49:41 +02:00
|
|
|
void DesktopNotification::enterEvent(QEvent*)
|
2011-04-22 16:03:38 +02:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_settingPosition) {
|
2011-04-27 09:49:41 +02:00
|
|
|
setWindowOpacity(0.5);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-22 16:03:38 +02:00
|
|
|
}
|
|
|
|
|
2011-04-27 09:49:41 +02:00
|
|
|
void DesktopNotification::leaveEvent(QEvent*)
|
2011-04-22 16:03:38 +02:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_settingPosition) {
|
2011-04-27 09:49:41 +02:00
|
|
|
setWindowOpacity(0.9);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-22 16:03:38 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void DesktopNotification::mousePressEvent(QMouseEvent* e)
|
2011-04-22 16:03:38 +02:00
|
|
|
{
|
2011-04-23 22:33:25 +02:00
|
|
|
if (!m_settingPosition) {
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e->button() == Qt::LeftButton) {
|
|
|
|
m_dragPosition = e->globalPos() - frameGeometry().topLeft();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void DesktopNotification::mouseMoveEvent(QMouseEvent* e)
|
2011-04-23 22:33:25 +02:00
|
|
|
{
|
|
|
|
if (e->buttons() & Qt::LeftButton) {
|
|
|
|
move(e->globalPos() - m_dragPosition);
|
|
|
|
e->accept();
|
|
|
|
}
|
2011-04-22 16:03:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopNotification::~DesktopNotification()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|