← Back to team overview

ayatana-commits team mailing list archive

[Branch ~agateau/plasma-widget-message-indicator/trunk] Rev 133: Better rendering, nicer 'new' icon

 

------------------------------------------------------------
revno: 133
committer: Aurelien Gateau <aurelien.gateau@xxxxxxxxxxxxx>
branch nick: plasma-widget-message-indicator
timestamp: Sat 2010-08-28 15:38:13 +0200
message:
  Better rendering, nicer 'new' icon
modified:
  icons/message-indicator.svgz
  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 'icons/message-indicator.svgz'
Binary files icons/message-indicator.svgz	2010-08-27 10:48:22 +0000 and icons/message-indicator.svgz	2010-08-28 13:38:13 +0000 differ
=== modified file 'src/message-indicator.cpp'
--- src/message-indicator.cpp	2010-08-27 10:51:24 +0000
+++ src/message-indicator.cpp	2010-08-28 13:38:13 +0000
@@ -43,11 +43,12 @@
 , mSourceModel(0)
 , mStack(new QWidget)
 , mView(new ExpandedTreeView(mStack))
+, mSvg(new Plasma::Svg(this))
 , mNoIndicatorLabel(new QLabel(mStack))
-, mIconWidget(new Plasma::IconWidget(this))
 {
     setBackgroundHints(StandardBackground);
-    setAspectRatioMode(Plasma::Square);
+    setAspectRatioMode(Plasma::ConstrainedSquare);
+    resize(48, 48);
 
     mNoIndicatorLabel->setText(i18n(
         "<p>The Message Indicator widget helps you keep track of incoming messages in a non-intrusive way.</p>"
@@ -64,6 +65,9 @@
     mNoIndicatorLabel->setOpenExternalLinks(true);
     mCurrentWidget = mNoIndicatorLabel;
 
+    mSvg->setImagePath("icons/message-indicator");
+    mSvg->setContainsMultipleImages(true);
+
     setWidget(mStack);
     updateStatus();
 }
@@ -88,21 +92,12 @@
 
 void MessageIndicator::initIcon()
 {
-    // Note: we use an icon widget, not the builtin setPopupIcon() because
-    // otherwise our view might get embedded if there is enough space, and we do
-    // not want that. Therefore we need to implement the icon look and behavior
-    // ourself
-    QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(this);
-    layout->setSpacing(0);
-    layout->addItem(mIconWidget);
-
+    mSvg->resize(contentsRect().size());
     // 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();
 }
 
@@ -190,7 +185,15 @@
 void MessageIndicator::toolTipAboutToShow()
 {
     Plasma::ToolTipContent toolTip;
-    toolTip.setImage(mIconWidget->icon());
+
+    QSizeF oldSize = mSvg->size();
+    // FIXME: Hardcoded size
+    mSvg->resize(32, 32);
+    QString element = status() == Plasma::NeedsAttentionStatus ? NEW_STUFF_ICON : NO_NEW_STUFF_ICON;
+    QPixmap pix = mSvg->pixmap(element);
+    mSvg->resize(oldSize);
+    toolTip.setImage(pix);
+
     toolTip.setMainText(i18n("Message Indicator"));
     int appCount = mSourceModel->rowCount();
     if (appCount == 0) {
@@ -222,6 +225,20 @@
     QMetaObject::invokeMethod(dialog, "dialogResized");
 }
 
+void MessageIndicator::constraintsEvent(Plasma::Constraints)
+{
+    mSvg->resize(contentsRect().size());
+}
+
+void MessageIndicator::paintInterface(QPainter* painter, const QStyleOptionGraphicsItem*, const QRect& contentsRect)
+{
+    int minSize = qMin(contentsRect.height(), contentsRect.width());
+    QRect contentsSquare = QRect(contentsRect.x() + (contentsRect.width() - minSize) / 2, contentsRect.y() + (contentsRect.height() - minSize) / 2, minSize, minSize);
+
+    QString element = status() == Plasma::NeedsAttentionStatus ? NEW_STUFF_ICON : NO_NEW_STUFF_ICON;
+    mSvg->paint(painter, contentsSquare, element);
+}
+
 void MessageIndicator::popupEvent(bool show)
 {
     if (show) {
@@ -271,8 +288,7 @@
     setStatus(status);
 
     // Update icon
-    mIconWidget->setSvg("icons/message-indicator",
-        status == Plasma::NeedsAttentionStatus ? NEW_STUFF_ICON : NO_NEW_STUFF_ICON);
+    update();
 
     // Update views
     if (status == Plasma::PassiveStatus) {

=== modified file 'src/message-indicator.h'
--- src/message-indicator.h	2010-06-02 16:09:17 +0000
+++ src/message-indicator.h	2010-08-28 13:38:13 +0000
@@ -40,6 +40,8 @@
 protected:
     virtual void popupEvent(bool show);
     virtual bool sceneEventFilter(QGraphicsItem*, QEvent* event);
+    virtual void constraintsEvent(Plasma::Constraints);
+    virtual void paintInterface(QPainter*, const QStyleOptionGraphicsItem*, const QRect&);
 
 private Q_SLOTS:
     void slotRowsChanged(const QModelIndex& parent);
@@ -56,9 +58,9 @@
     ListenerModel* mSourceModel;
     QWidget* mStack;
     QTreeView* mView;
+    Plasma::Svg* mSvg;
     QLabel* mNoIndicatorLabel;
     QWidget* mCurrentWidget;
-    Plasma::IconWidget* mIconWidget;
 
     void initIcon();
     void initSourceModel();