2011-04-22 16:03:38 +02:00
|
|
|
#include "desktopnotification.h"
|
|
|
|
#include "ui_desktopnotification.h"
|
|
|
|
|
2011-04-23 22:33:25 +02:00
|
|
|
DesktopNotification::DesktopNotification(bool settingPosition)
|
2011-04-22 16:03:38 +02:00
|
|
|
: QWidget(0)
|
|
|
|
, ui(new Ui::DesktopNotification)
|
2011-04-23 22:33:25 +02:00
|
|
|
, m_settingPosition(settingPosition)
|
|
|
|
, m_timeout(6000)
|
|
|
|
, m_timer(new QTimer(this))
|
2011-04-22 16:03:38 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setStyleSheet("background:transparent;");
|
|
|
|
setAttribute(Qt::WA_TranslucentBackground);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
Qt::WindowFlags flags = Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint |
|
|
|
|
Qt::X11BypassWindowManagerHint;
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
flags |= Qt::ToolTip;
|
|
|
|
#endif
|
|
|
|
setWindowFlags(flags);
|
|
|
|
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-26 19:47:12 +02:00
|
|
|
if (m_settingPosition)
|
|
|
|
setCursor(Qt::OpenHandCursor);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopNotification::enterEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e)
|
|
|
|
setWindowOpacity(0.5);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopNotification::leaveEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
Q_UNUSED(e)
|
|
|
|
setWindowOpacity(0.9);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopNotification::mousePressEvent(QMouseEvent *e)
|
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopNotification::mouseMoveEvent(QMouseEvent *e)
|
|
|
|
{
|
|
|
|
if (e->buttons() & Qt::LeftButton) {
|
|
|
|
move(e->globalPos() - m_dragPosition);
|
|
|
|
e->accept();
|
|
|
|
}
|
2011-04-22 16:03:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopNotification::~DesktopNotification()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|