ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #01525
[Branch ~agateau/plasma-widget-message-indicator/trunk] Rev 137: Middle clicking or shift+left clicking on the applet now activates the latest indicator.
------------------------------------------------------------
revno: 137
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: plasma-widget-message-indicator
timestamp: Wed 2010-06-02 18:09:17 +0200
message:
Middle clicking or shift+left clicking on the applet now activates the latest indicator.
modified:
src/message-indicator.cpp
src/message-indicator.h
--
lp:plasma-widget-message-indicator
https://code.launchpad.net/~agateau/plasma-widget-message-indicator/trunk
Your team ayatana-commits is subscribed to branch lp:plasma-widget-message-indicator.
To unsubscribe from this branch go to https://code.launchpad.net/~agateau/plasma-widget-message-indicator/trunk/+edit-subscription
=== modified file 'src/message-indicator.cpp'
--- src/message-indicator.cpp 2010-03-08 10:20:45 +0000
+++ src/message-indicator.cpp 2010-06-02 16:09:17 +0000
@@ -13,6 +13,7 @@
// Qt
#include <QGraphicsLinearLayout>
+#include <QGraphicsSceneMouseEvent>
#include <QLabel>
#include <QLayout>
#include <QRegExp>
@@ -95,10 +96,36 @@
layout->setSpacing(0);
layout->addItem(mIconWidget);
- connect(mIconWidget, SIGNAL(clicked()), SLOT(togglePopup()));
+ // activate() is emitted on all clicks. We disable it because we
+ // want the popup to show on left-click only, middle-click is used
+ // to activate the latest indicator.
+ disconnect(this, SIGNAL(activate()), 0, 0);
+ installSceneEventFilter(this);
+ mIconWidget->installSceneEventFilter(this);
+
updateStatus();
}
+bool MessageIndicator::sceneEventFilter(QGraphicsItem*, QEvent* event)
+{
+ if (event->type() == QEvent::GraphicsSceneMousePress) {
+ return true;
+ }
+ if (event->type() == QEvent::GraphicsSceneMouseRelease) {
+ QGraphicsSceneMouseEvent* mouseEvent = static_cast<QGraphicsSceneMouseEvent*>(event);
+ if (mouseEvent->button() == Qt::MidButton
+ || (mouseEvent->button() == Qt::LeftButton
+ && (mouseEvent->modifiers() & Qt::ShiftModifier)))
+ {
+ activateLatestIndicator();
+ } else {
+ togglePopup();
+ }
+ return true;
+ }
+ return false;
+}
+
void MessageIndicator::initSourceModel()
{
// Reg exp is a hack to avoid regressions while changing app server types
@@ -282,6 +309,30 @@
}
}
+void MessageIndicator::activateLatestIndicator()
+{
+ QDateTime latestDateTime;
+ QModelIndex latestIndicatorIndex;
+ for (int row = mSourceModel->rowCount() - 1; row >= 0; --row) {
+ QModelIndex serverIndex = mSourceModel->index(row, 0);
+ for (int row2 = mSourceModel->rowCount(serverIndex) - 1; row2 >= 0; --row2) {
+ QModelIndex indicatorIndex = mSourceModel->index(row2, 0, serverIndex);
+ QDateTime dateTime = indicatorIndex.data(ListenerModel::IndicatorDateTimeRole).toDateTime();
+ if (dateTime.isNull()) {
+ continue;
+ }
+ if (latestDateTime.isNull() || latestDateTime < dateTime) {
+ latestDateTime = dateTime;
+ latestIndicatorIndex = indicatorIndex;
+ }
+ }
+ }
+
+ if (latestIndicatorIndex.isValid()) {
+ mSourceModel->activate(latestIndicatorIndex);
+ }
+}
+
#ifdef DUMP_MODELS
#include "modeldump.h"
=== modified file 'src/message-indicator.h'
--- src/message-indicator.h 2010-02-15 10:09:31 +0000
+++ src/message-indicator.h 2010-06-02 16:09:17 +0000
@@ -39,6 +39,7 @@
protected:
virtual void popupEvent(bool show);
+ virtual bool sceneEventFilter(QGraphicsItem*, QEvent* event);
private Q_SLOTS:
void slotRowsChanged(const QModelIndex& parent);
@@ -48,6 +49,7 @@
void dumpModels();
void initPalette();
void adjustViewSize();
+ void activateLatestIndicator();
private:
QIndicate::Listener* mListener;