Adding upstream version 0.9.0+20151028.
This commit is contained in:
parent
ed9ce054e2
commit
2e7cc6bbed
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>340</width>
|
<width>350</width>
|
||||||
<height>284</height>
|
<height>301</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
@ -70,6 +70,12 @@
|
|||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Some notifications set their own on-screen duration.</string>
|
<string>Some notifications set their own on-screen duration.</string>
|
||||||
</property>
|
</property>
|
||||||
|
@ -33,12 +33,15 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <XdgIcon>
|
#include <XdgIcon>
|
||||||
#include <KWindowSystem/KWindowSystem>
|
#include <KWindowSystem/KWindowSystem>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
#include "notification.h"
|
#include "notification.h"
|
||||||
#include "notificationwidgets.h"
|
#include "notificationwidgets.h"
|
||||||
|
|
||||||
#define ICONSIZE QSize(32, 32)
|
#define ICONSIZE QSize(32, 32)
|
||||||
|
|
||||||
|
|
||||||
Notification::Notification(const QString &application,
|
Notification::Notification(const QString &application,
|
||||||
const QString &summary, const QString &body,
|
const QString &summary, const QString &body,
|
||||||
const QString &icon, int timeout,
|
const QString &icon, int timeout,
|
||||||
@ -46,6 +49,7 @@ Notification::Notification(const QString &application,
|
|||||||
QWidget *parent)
|
QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
m_timer(0),
|
m_timer(0),
|
||||||
|
m_linkHovered(false),
|
||||||
m_actionWidget(0)
|
m_actionWidget(0)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
@ -57,7 +61,14 @@ Notification::Notification(const QString &application,
|
|||||||
|
|
||||||
setValues(application, summary, body, icon, timeout, actions, hints);
|
setValues(application, summary, body, icon, timeout, actions, hints);
|
||||||
|
|
||||||
connect(closeButton, SIGNAL(clicked()), this, SLOT(closeButton_clicked()));
|
connect(closeButton, &QPushButton::clicked, this, &Notification::closeButton_clicked);
|
||||||
|
|
||||||
|
for (QLabel *label : {bodyLabel, summaryLabel})
|
||||||
|
{
|
||||||
|
connect(label, &QLabel::linkHovered, this, &Notification::linkHovered);
|
||||||
|
|
||||||
|
label->installEventFilter(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Notification::setValues(const QString &application,
|
void Notification::setValues(const QString &application,
|
||||||
@ -145,7 +156,7 @@ void Notification::setValues(const QString &application,
|
|||||||
if (timeout > 0)
|
if (timeout > 0)
|
||||||
{
|
{
|
||||||
m_timer = new NotificationTimer(this);
|
m_timer = new NotificationTimer(this);
|
||||||
connect(m_timer, SIGNAL(timeout()), this, SIGNAL(timeout()));
|
connect(m_timer, &NotificationTimer::timeout, this, &Notification::timeout);
|
||||||
m_timer->start(timeout);
|
m_timer->start(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,8 +185,10 @@ void Notification::setValues(const QString &application,
|
|||||||
m_actionWidget = new NotificationActionsButtonsWidget(actions, this);
|
m_actionWidget = new NotificationActionsButtonsWidget(actions, this);
|
||||||
else
|
else
|
||||||
m_actionWidget = new NotificationActionsComboWidget(actions, this);
|
m_actionWidget = new NotificationActionsComboWidget(actions, this);
|
||||||
connect(m_actionWidget, SIGNAL(actionTriggered(const QString &)),
|
|
||||||
this, SIGNAL(actionTriggered(const QString &)));
|
connect(m_actionWidget, &NotificationActionsWidget::actionTriggered,
|
||||||
|
this, &Notification::actionTriggered);
|
||||||
|
|
||||||
actionsLayout->addWidget(m_actionWidget);
|
actionsLayout->addWidget(m_actionWidget);
|
||||||
m_actionWidget->show();
|
m_actionWidget->show();
|
||||||
}
|
}
|
||||||
@ -272,6 +285,25 @@ void Notification::leaveEvent(QEvent * event)
|
|||||||
m_timer->resume();
|
m_timer->resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Notification::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
// Catch mouseReleaseEvent on child labels if a link is not currently being hovered.
|
||||||
|
//
|
||||||
|
// This workarounds QTBUG-49025 where clicking on text does not propagate the mouseReleaseEvent
|
||||||
|
// to the parent even though the text is not selectable and no link is being clicked.
|
||||||
|
if (event->type() == QEvent::MouseButtonRelease && !m_linkHovered)
|
||||||
|
{
|
||||||
|
mouseReleaseEvent(static_cast<QMouseEvent*>(event));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Notification::linkHovered(QString link)
|
||||||
|
{
|
||||||
|
m_linkHovered = !link.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
void Notification::mouseReleaseEvent(QMouseEvent * event)
|
void Notification::mouseReleaseEvent(QMouseEvent * event)
|
||||||
{
|
{
|
||||||
// qDebug() << "CLICKED" << event;
|
// qDebug() << "CLICKED" << event;
|
||||||
|
@ -99,6 +99,7 @@ private:
|
|||||||
NotificationTimer *m_timer;
|
NotificationTimer *m_timer;
|
||||||
|
|
||||||
QPixmap m_pixmap;
|
QPixmap m_pixmap;
|
||||||
|
bool m_linkHovered;
|
||||||
|
|
||||||
NotificationActionsWidget *m_actionWidget;
|
NotificationActionsWidget *m_actionWidget;
|
||||||
|
|
||||||
@ -106,9 +107,11 @@ private:
|
|||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
QPixmap getPixmapFromHint(const QVariant &argument) const;
|
QPixmap getPixmapFromHint(const QVariant &argument) const;
|
||||||
QPixmap getPixmapFromString(const QString &str) const;
|
QPixmap getPixmapFromString(const QString &str) const;
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void closeButton_clicked();
|
void closeButton_clicked();
|
||||||
|
void linkHovered(QString);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@
|
|||||||
<string notr="true">TextLabel</string>
|
<string notr="true">TextLabel</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="textFormat">
|
<property name="textFormat">
|
||||||
<enum>Qt::RichText</enum>
|
<enum>Qt::PlainText</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
@ -55,10 +55,10 @@ NotificationArea::NotificationArea(QWidget *parent)
|
|||||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
connect(m_layout, SIGNAL(allNotificationsClosed()), this, SLOT(close()));
|
connect(m_layout, &NotificationLayout::allNotificationsClosed, this, &NotificationArea::close);
|
||||||
connect(m_layout, SIGNAL(notificationAvailable()), this, SLOT(show()));
|
connect(m_layout, &NotificationLayout::notificationAvailable, this, &NotificationArea::show);
|
||||||
connect(m_layout, SIGNAL(heightChanged(int)), this, SLOT(setHeight(int)));
|
connect(m_layout, &NotificationLayout::heightChanged, this, &NotificationArea::setHeight);
|
||||||
connect(qApp->desktop(), SIGNAL(workAreaResized(int)), SLOT(setHeight()));
|
connect(qApp->desktop(), &QDesktopWidget::workAreaResized, this, &NotificationArea::setHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationArea::setHeight(int contentHeight)
|
void NotificationArea::setHeight(int contentHeight)
|
||||||
|
@ -96,10 +96,10 @@ void NotificationLayout::addNotification(uint id, const QString &application,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(n, SIGNAL(timeout()), this, SLOT(removeNotificationTimeout()));
|
connect(n, &Notification::timeout, this, &NotificationLayout::removeNotificationTimeout);
|
||||||
connect(n, SIGNAL(userCanceled()), this, SLOT(removeNotificationUser()));
|
connect(n, &Notification::userCanceled, this, &NotificationLayout::removeNotificationUser);
|
||||||
connect(n, SIGNAL(actionTriggered(QString)),
|
connect(n, &Notification::actionTriggered,
|
||||||
this, SLOT(notificationActionCalled(QString)));
|
this, &NotificationLayout::notificationActionCalled);
|
||||||
m_notifications[id] = n;
|
m_notifications[id] = n;
|
||||||
m_layout->addWidget(n);
|
m_layout->addWidget(n);
|
||||||
n->show();
|
n->show();
|
||||||
|
@ -39,77 +39,77 @@
|
|||||||
NotificationActionsWidget::NotificationActionsWidget(const QStringList& actions, QWidget *parent)
|
NotificationActionsWidget::NotificationActionsWidget(const QStringList& actions, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < actions.count(); ++i)
|
for (int i = 0; i < actions.count(); i += 2)
|
||||||
{
|
{
|
||||||
|
QString key = actions[i];
|
||||||
|
QString value;
|
||||||
|
|
||||||
if (i == actions.count() - 1)
|
if (i == actions.count() - 1)
|
||||||
{
|
{
|
||||||
qDebug() << "NotificationActionsWidget actions has contains pairs (id, value, id, value...) got odd count:" << actions.count() << "Actions:" << actions;
|
value = key;
|
||||||
m_actionMap[actions.at(i)] = actions.at(i);
|
qWarning() << "Odd number of elements in action list. Last action will use key as text (" << key << ")";
|
||||||
}
|
} else {
|
||||||
else
|
value = actions[i + 1];
|
||||||
{
|
|
||||||
m_actionMap[actions.at(i)] = actions.at(i+1);
|
|
||||||
}
|
|
||||||
++i; // move to the next ID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there is only one action let's take it as a default one
|
if (key == "default")
|
||||||
if (m_actionMap.count() == 1)
|
m_defaultAction = key;
|
||||||
m_defaultAction = m_actionMap[m_actionMap.keys().at(0)];
|
|
||||||
|
|
||||||
qDebug() << "NotificationActionsWidget processed actions:" << m_actionMap;
|
m_actions.append({key, value});
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there is only one action let's use it as the default one
|
||||||
|
if (m_actions.count() == 1)
|
||||||
|
m_defaultAction = m_actions[0].first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NotificationActionsButtonsWidget::NotificationActionsButtonsWidget(const QStringList& actions, QWidget *parent)
|
NotificationActionsButtonsWidget::NotificationActionsButtonsWidget(const QStringList& actions, QWidget *parent)
|
||||||
: NotificationActionsWidget(actions, parent)
|
: NotificationActionsWidget(actions, parent)
|
||||||
{
|
{
|
||||||
QHashIterator<QString,QString> it(m_actionMap);
|
|
||||||
QHBoxLayout *l = new QHBoxLayout();
|
QHBoxLayout *l = new QHBoxLayout();
|
||||||
setLayout(l);
|
setLayout(l);
|
||||||
|
|
||||||
QButtonGroup *group = new QButtonGroup(this);
|
QButtonGroup *group = new QButtonGroup(this);
|
||||||
|
|
||||||
while (it.hasNext())
|
for (auto const & action : m_actions)
|
||||||
{
|
{
|
||||||
it.next();
|
QPushButton *b = new QPushButton(action.second, this);
|
||||||
QPushButton *b = new QPushButton(it.value(), this);
|
b->setObjectName(action.first);
|
||||||
l->addWidget(b);
|
l->addWidget(b);
|
||||||
group->addButton(b);
|
group->addButton(b);
|
||||||
if (it.key() == "default")
|
|
||||||
{
|
if (action.first == m_defaultAction)
|
||||||
b->setFocus(Qt::OtherFocusReason);
|
b->setFocus(Qt::OtherFocusReason);
|
||||||
m_defaultAction = it.key();
|
|
||||||
}
|
}
|
||||||
}
|
connect(group, static_cast<void (QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked),
|
||||||
connect(group, SIGNAL(buttonClicked(QAbstractButton*)),
|
this, &NotificationActionsButtonsWidget::actionButtonActivated);
|
||||||
this, SLOT(actionButtonActivated(QAbstractButton*)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationActionsButtonsWidget::actionButtonActivated(QAbstractButton* button)
|
void NotificationActionsButtonsWidget::actionButtonActivated(QAbstractButton* button)
|
||||||
{
|
{
|
||||||
emit actionTriggered(m_actionMap.key(button->text()));
|
emit actionTriggered(button->objectName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NotificationActionsComboWidget::NotificationActionsComboWidget(const QStringList& actions, QWidget *parent)
|
NotificationActionsComboWidget::NotificationActionsComboWidget(const QStringList& actions, QWidget *parent)
|
||||||
: NotificationActionsWidget(actions, parent)
|
: NotificationActionsWidget(actions, parent)
|
||||||
{
|
{
|
||||||
QHashIterator<QString,QString> it(m_actionMap);
|
|
||||||
QHBoxLayout *l = new QHBoxLayout();
|
QHBoxLayout *l = new QHBoxLayout();
|
||||||
setLayout(l);
|
setLayout(l);
|
||||||
|
|
||||||
l->addWidget(new QLabel(tr("Actions:"), this));
|
l->addWidget(new QLabel(tr("Actions:"), this));
|
||||||
m_comboBox = new QComboBox(this);
|
m_comboBox = new QComboBox(this);
|
||||||
int currentIndex = -1;
|
int currentIndex = -1;
|
||||||
while (it.hasNext())
|
|
||||||
|
for (int i = 0; i < m_actions.count(); ++i)
|
||||||
{
|
{
|
||||||
it.next();
|
auto const & action = m_actions[i];
|
||||||
m_comboBox->addItem(it.value(), it.key());
|
|
||||||
if (it.key() == "default")
|
m_comboBox->addItem(action.second, action.first);
|
||||||
|
if (action.first == m_defaultAction)
|
||||||
{
|
{
|
||||||
currentIndex = m_comboBox->count()-1;
|
currentIndex = i;
|
||||||
m_defaultAction = it.key();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
l->addWidget(m_comboBox);
|
l->addWidget(m_comboBox);
|
||||||
@ -119,8 +119,8 @@ NotificationActionsComboWidget::NotificationActionsComboWidget(const QStringList
|
|||||||
|
|
||||||
QPushButton *b = new QPushButton(tr("OK"), this);
|
QPushButton *b = new QPushButton(tr("OK"), this);
|
||||||
l->addWidget(b);
|
l->addWidget(b);
|
||||||
connect(b, SIGNAL(clicked()),
|
connect(b, &QPushButton::clicked,
|
||||||
this, SLOT(actionComboBoxActivated()));
|
this, &NotificationActionsComboWidget::actionComboBoxActivated);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationActionsComboWidget::actionComboBoxActivated()
|
void NotificationActionsComboWidget::actionComboBoxActivated()
|
||||||
@ -130,5 +130,5 @@ void NotificationActionsComboWidget::actionComboBoxActivated()
|
|||||||
int ix = m_comboBox->currentIndex();
|
int ix = m_comboBox->currentIndex();
|
||||||
if (ix == -1)
|
if (ix == -1)
|
||||||
return;
|
return;
|
||||||
emit actionTriggered(m_actionMap.key(m_comboBox->itemText(ix)));
|
emit actionTriggered(m_actions[ix].first);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ signals:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_defaultAction;
|
QString m_defaultAction;
|
||||||
QHash<QString,QString> m_actionMap;
|
QList<QPair<QString/*action key*/, QString/*action value*/>> m_actions;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotificationActionsButtonsWidget : public NotificationActionsWidget
|
class NotificationActionsButtonsWidget : public NotificationActionsWidget
|
||||||
|
@ -43,18 +43,18 @@ Notifyd::Notifyd(QObject* parent)
|
|||||||
m_settings = new LXQt::Settings("notifications");
|
m_settings = new LXQt::Settings("notifications");
|
||||||
reloadSettings();
|
reloadSettings();
|
||||||
|
|
||||||
connect(this, SIGNAL(notificationAdded(uint,QString,QString,QString,QString,int,QStringList,QVariantMap)),
|
connect(this, &Notifyd::notificationAdded,
|
||||||
m_area->layout(), SLOT(addNotification(uint,QString,QString,QString,QString,int,QStringList,QVariantMap)));
|
m_area->layout(), &NotificationLayout::addNotification);
|
||||||
connect(this, SIGNAL(notificationClosed(uint, uint)),
|
connect(this, &Notifyd::notificationClosed,
|
||||||
m_area->layout(), SLOT(removeNotification(uint, uint)));
|
m_area->layout(), &NotificationLayout::removeNotification);
|
||||||
// feedback for original caller
|
// feedback for original caller
|
||||||
connect(m_area->layout(), SIGNAL(notificationClosed(uint,uint)),
|
connect(m_area->layout(), &NotificationLayout::notificationClosed,
|
||||||
this, SIGNAL(NotificationClosed(uint,uint)));
|
this, &Notifyd::NotificationClosed);
|
||||||
connect(m_area->layout(), SIGNAL(actionInvoked(uint, QString)),
|
connect(m_area->layout(), &NotificationLayout::actionInvoked,
|
||||||
this, SIGNAL(ActionInvoked(uint,QString)));
|
this, &Notifyd::ActionInvoked);
|
||||||
|
|
||||||
connect(m_settings, SIGNAL(settingsChanged()),
|
connect(m_settings, &LXQt::Settings::settingsChanged,
|
||||||
this, SLOT(reloadSettings()));
|
this, &Notifyd::reloadSettings);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user