* global keyboard shortcuts for applets

* move the contents of setGeometry to itemChange and resizeEvent for greater reliability

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=815043
This commit is contained in:
Aaron J. Seigo 2008-06-01 02:13:53 +00:00
parent cc3f0c3a90
commit 40e4b3e88e
5 changed files with 80 additions and 29 deletions

View File

@ -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,10 +193,41 @@ void Applet::restore(KConfigGroup &group)
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)
@ -1059,9 +1092,21 @@ void Applet::focusInEvent(QFocusEvent * event)
//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 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
d->shadow->setVisible(isVisible());
}
break;
case ItemPositionHasChanged:
emit geometryChanged();
break;
default:
break;
};
@ -1322,24 +1370,6 @@ void Applet::timerEvent(QTimerEvent *event)
}
}
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 @@ Applet::Private::Private(KService::Ptr service, int uniqueID, Applet *applet)
ghostView(0),
immutability(Mutable),
actions(applet),
activationAction(0),
constraintsTimerId(0),
hasConfigurationInterface(false),
failed(false),

View File

@ -425,13 +425,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
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.
*/
@ -496,6 +489,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
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,7 +680,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
/**
* Reimplemented from QGraphicsItem
*/
void focusInEvent(QFocusEvent * event);
void focusInEvent(QFocusEvent *event);
/**
* Reimplemented from QGraphicsItem
*/
void resizeEvent(QGraphicsSceneResizeEvent *event);
/**
* Reimplemented from QGraphicsItem
@ -699,7 +703,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
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))

View File

@ -62,6 +62,7 @@ public:
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 @@ public:
QGraphicsView* ghostView;
ImmutabilityType immutability;
KActionCollection actions;
KAction *activationAction;
int constraintsTimerId;
bool hasConfigurationInterface : 1;
bool failed : 1;

View File

@ -32,6 +32,7 @@
#include <QGraphicsLayout>
#include <QGraphicsLinearLayout>
#include <KAction>
#include <KApplication>
#include <KAuthorized>
#include <KIcon>
@ -886,6 +887,12 @@ void Containment::addAssociatedWidget(QWidget *widget)
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 @@ void Containment::removeAssociatedWidget(QWidget *widget)
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 @@ Applet* Containment::Private::addApplet(const QString& name, const QVariantList&
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();

View File

@ -22,7 +22,6 @@
#include "corona.h"
#include <QApplication>
#include <QDesktopWidget>
#include <QGraphicsSceneDragDropEvent>
#include <QMimeData>
#include <QPainter>