[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdebase/workspace/libs/plasma
From:       Aaron J. Seigo <aseigo () kde ! org>
Date:       2008-06-01 2:13:53
Message-ID: 1212286433.898698.27357.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 815043 by aseigo:

* global keyboard shortcuts for applets
* move the contents of setGeometry to itemChange and resizeEvent for greater \
reliability


 M  +50 -19    applet.cpp  
 M  +13 -9     applet.h  
 M  +2 -0      applet_p.h  
 M  +15 -0     containment.cpp  
 M  +0 -1      corona.cpp  


--- trunk/KDE/kdebase/workspace/libs/plasma/applet.cpp #815042:815043
@@ -42,6 +42,7 @@
 #include <QGraphicsView>
 #include <QAction>
 
+#include <KAction>
 #include <KIcon>
 #include <KColorScheme>
 #include <KConfigDialog>
@@ -51,6 +52,7 @@
 #include <KStandardDirs>
 #include <KService>
 #include <KServiceTypeTrader>
+#include <KShortcut>
 #include <KWindowSystem>
 #include <KActionCollection>
 
@@ -191,12 +193,43 @@
 
     setImmutability((ImmutabilityType)group.readEntry("immutability", \
(int)Mutable));  
-    QRectF geom = group.readEntry("geometry",QRectF());
+    QRectF geom = group.readEntry("geometry", QRectF());
     if (geom.isValid()) {
         setGeometry(geom);
     }
+
+    KConfigGroup shortcutConfig(&group, "Shortcuts");
+    QString shortcutText = shortcutConfig.readEntry("global", QString());
+    if (!shortcutText.isEmpty()) {
+        if (!d->activationAction) {
+            d->activationAction = new KAction(this);
+            //TODO: add better text when we aren't in a string freeze
+            d->activationAction->setText(name());
+            d->activationAction->setObjectName(QString("Activate %1 \
Widget").arg(name())); // NO I18N +            connect(d->activationAction, \
SIGNAL(triggered()), this, SIGNAL(activate())); +            connect(this, \
SIGNAL(activate()), this, SLOT(setFocus())); +        }
+
+        KShortcut shortcut(shortcutText);
+        d->activationAction->setGlobalShortcut(shortcut);
+    }
+
+    // local shortcut, if any
+    //TODO: implement; the shortcut will need to be registered with the containment
+    /*
+    shortcutText = shortcutConfig.readEntry("local", QString());
+    if (!shortcutText.isEmpty()) {
+        //TODO: implement; the shortcut 
+    }
+    */
 }
 
+void Applet::Private::setFocus()
+{
+    kDebug() << "setting focus";
+    q->setFocus(Qt::ShortcutFocusReason);
+}
+
 void Applet::setFailedToLaunch(bool failed, const QString& reason)
 {
     if (d->failed == failed) {
@@ -1059,9 +1092,21 @@
         //which should be harmless
         //focusing an applet may trigger this event again, but we won't be here more \
than twice  }
+
     QGraphicsWidget::focusInEvent(event);
 }
 
+void Applet::resizeEvent(QGraphicsSceneResizeEvent *event)
+{
+    QGraphicsWidget::resizeEvent(event);
+
+    if (d->background) {
+        d->background->resizePanel(boundingRect().size());
+    }
+
+    updateConstraints(Plasma::SizeConstraint);
+}
+
 void Applet::showConfigurationInterface()
 {
     if (!hasConfigurationInterface()) {
@@ -1291,6 +1336,9 @@
             d->shadow->setVisible(isVisible());
         }
         break;
+    case ItemPositionHasChanged:
+        emit geometryChanged();
+        break;
     default:
         break;
     };
@@ -1322,24 +1370,6 @@
     }
 }
 
-void Applet::setGeometry(const QRectF& geometry)
-{
-    QRectF beforeGeom = QGraphicsWidget::geometry();
-    QGraphicsWidget::setGeometry(geometry);
-    if (geometry.size() != beforeGeom.size()) {
-        updateConstraints(Plasma::SizeConstraint);
-        if (d->background) {
-            d->background->resizePanel(boundingRect().size());
-        }
-        emit geometryChanged();
-    } else  if (geometry.topLeft() != beforeGeom.topLeft()) {
-        /*if (d->background) {
-            kDebug() << QGraphicsWidget::geometry();
-        }*/
-        emit geometryChanged();
-    }
-}
-
 QRect Applet::screenRect() const
 {
     QPointF bottomRight = pos();
@@ -1417,6 +1447,7 @@
           ghostView(0),
           immutability(Mutable),
           actions(applet),
+          activationAction(0),
           constraintsTimerId(0),
           hasConfigurationInterface(false),
           failed(false),
--- trunk/KDE/kdebase/workspace/libs/plasma/applet.h #815042:815043
@@ -426,13 +426,6 @@
         bool isContainment() const;
 
         /**
-         * Sets the geometry of this Plasma::Applet. Should not be used directly by
-         * applet subclasses.
-         * @param geometry the geometry to apply to this Plasma::Applet.
-         */
-        void setGeometry(const QRectF &geometry);
-
-        /**
          * @return a rect of the applet in screen coordinates.
          */
         QRect screenRect() const;
@@ -496,6 +489,12 @@
          */
         void configNeedsSaving();
 
+        /**
+         * Emitted when activation is requested due to, for example, a global
+         * keyboard shortcut. By default the wiget is given focus.
+         */
+        void activate();
+
     public Q_SLOTS:
         /**
          * Sets the immutability type for this applet (not immutable, user immutable \
or system immutable) @@ -681,11 +680,16 @@
         /**
          * Reimplemented from QGraphicsItem
          */
-        void focusInEvent(QFocusEvent * event);
+        void focusInEvent(QFocusEvent *event);
 
         /**
          * Reimplemented from QGraphicsItem
          */
+        void resizeEvent(QGraphicsSceneResizeEvent *event);
+
+        /**
+         * Reimplemented from QGraphicsItem
+         */
         QVariant itemChange(GraphicsItemChange change, const QVariant &value);
 
         /**
@@ -699,7 +703,7 @@
         void timerEvent (QTimerEvent *event);
 
     private:
-        Q_DISABLE_COPY(Applet)
+        Q_PRIVATE_SLOT(d, void setFocus())
         Q_PRIVATE_SLOT(d, void checkImmutability())
         Q_PRIVATE_SLOT(d, void themeChanged())
         Q_PRIVATE_SLOT(d, void appletAnimationComplete(QGraphicsItem *item, \
                Plasma::Animator::Animation anim))
--- trunk/KDE/kdebase/workspace/libs/plasma/applet_p.h #815042:815043
@@ -62,6 +62,7 @@
     void themeChanged();
     void resetConfigurationObject();
     void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation \
anim); +    void setFocus();
 
     static uint s_maxAppletId;
     static uint s_maxZValue;
@@ -89,6 +90,7 @@
     QGraphicsView* ghostView;
     ImmutabilityType immutability;
     KActionCollection actions;
+    KAction *activationAction;
     int constraintsTimerId;
     bool hasConfigurationInterface : 1;
     bool failed : 1;
--- trunk/KDE/kdebase/workspace/libs/plasma/containment.cpp #815042:815043
@@ -32,6 +32,7 @@
 #include <QGraphicsLayout>
 #include <QGraphicsLinearLayout>
 
+#include <KAction>
 #include <KApplication>
 #include <KAuthorized>
 #include <KIcon>
@@ -886,6 +887,12 @@
     if (d->focusedApplet) {
         d->focusedApplet->addAssociatedWidget(widget);
     }
+
+    foreach (const Applet* applet, d->applets) {
+        if (applet->d->activationAction) {
+            widget->addAction(applet->d->activationAction);
+        }
+    }
 }
 
 void Containment::removeAssociatedWidget(QWidget *widget)
@@ -894,6 +901,12 @@
     if (d->focusedApplet) {
         d->focusedApplet->removeAssociatedWidget(widget);
     }
+
+    foreach (const Applet* applet, d->applets) {
+        if (applet->d->activationAction) {
+            widget->removeAction(applet->d->activationAction);
+        }
+    }
 }
 
 KActionCollection& Containment::Private::actions()
@@ -1171,6 +1184,8 @@
     if (!applet) {
         kDebug() << "Applet" << name << "could not be loaded.";
         applet = new Applet;
+        //TODO: uncomment this when not in string freeze.
+        //applet->setFailedToLaunch(true, QString("Could not find requested \
component: %1").arg(name));  }
 
     //kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" \
                << applet->geometry();
--- trunk/KDE/kdebase/workspace/libs/plasma/corona.cpp #815042:815043
@@ -22,7 +22,6 @@
 #include "corona.h"
 
 #include <QApplication>
-#include <QDesktopWidget>
 #include <QGraphicsSceneDragDropEvent>
 #include <QMimeData>
 #include <QPainter>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic