* 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:
parent
cc3f0c3a90
commit
40e4b3e88e
69
applet.cpp
69
applet.cpp
@ -42,6 +42,7 @@
|
|||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
|
#include <KAction>
|
||||||
#include <KIcon>
|
#include <KIcon>
|
||||||
#include <KColorScheme>
|
#include <KColorScheme>
|
||||||
#include <KConfigDialog>
|
#include <KConfigDialog>
|
||||||
@ -51,6 +52,7 @@
|
|||||||
#include <KStandardDirs>
|
#include <KStandardDirs>
|
||||||
#include <KService>
|
#include <KService>
|
||||||
#include <KServiceTypeTrader>
|
#include <KServiceTypeTrader>
|
||||||
|
#include <KShortcut>
|
||||||
#include <KWindowSystem>
|
#include <KWindowSystem>
|
||||||
#include <KActionCollection>
|
#include <KActionCollection>
|
||||||
|
|
||||||
@ -191,10 +193,41 @@ void Applet::restore(KConfigGroup &group)
|
|||||||
|
|
||||||
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
|
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
|
||||||
|
|
||||||
QRectF geom = group.readEntry("geometry",QRectF());
|
QRectF geom = group.readEntry("geometry", QRectF());
|
||||||
if (geom.isValid()) {
|
if (geom.isValid()) {
|
||||||
setGeometry(geom);
|
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)
|
void Applet::setFailedToLaunch(bool failed, const QString& reason)
|
||||||
@ -1059,9 +1092,21 @@ void Applet::focusInEvent(QFocusEvent * event)
|
|||||||
//which should be harmless
|
//which should be harmless
|
||||||
//focusing an applet may trigger this event again, but we won't be here more than twice
|
//focusing an applet may trigger this event again, but we won't be here more than twice
|
||||||
}
|
}
|
||||||
|
|
||||||
QGraphicsWidget::focusInEvent(event);
|
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()
|
void Applet::showConfigurationInterface()
|
||||||
{
|
{
|
||||||
if (!hasConfigurationInterface()) {
|
if (!hasConfigurationInterface()) {
|
||||||
@ -1291,6 +1336,9 @@ QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
|
|||||||
d->shadow->setVisible(isVisible());
|
d->shadow->setVisible(isVisible());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case ItemPositionHasChanged:
|
||||||
|
emit geometryChanged();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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
|
QRect Applet::screenRect() const
|
||||||
{
|
{
|
||||||
QPointF bottomRight = pos();
|
QPointF bottomRight = pos();
|
||||||
@ -1417,6 +1447,7 @@ Applet::Private::Private(KService::Ptr service, int uniqueID, Applet *applet)
|
|||||||
ghostView(0),
|
ghostView(0),
|
||||||
immutability(Mutable),
|
immutability(Mutable),
|
||||||
actions(applet),
|
actions(applet),
|
||||||
|
activationAction(0),
|
||||||
constraintsTimerId(0),
|
constraintsTimerId(0),
|
||||||
hasConfigurationInterface(false),
|
hasConfigurationInterface(false),
|
||||||
failed(false),
|
failed(false),
|
||||||
|
22
applet.h
22
applet.h
@ -425,13 +425,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
*/
|
*/
|
||||||
bool isContainment() const;
|
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.
|
* @return a rect of the applet in screen coordinates.
|
||||||
*/
|
*/
|
||||||
@ -496,6 +489,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
*/
|
*/
|
||||||
void configNeedsSaving();
|
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:
|
public Q_SLOTS:
|
||||||
/**
|
/**
|
||||||
* Sets the immutability type for this applet (not immutable, user immutable or system immutable)
|
* 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
|
* Reimplemented from QGraphicsItem
|
||||||
*/
|
*/
|
||||||
void focusInEvent(QFocusEvent * event);
|
void focusInEvent(QFocusEvent *event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reimplemented from QGraphicsItem
|
||||||
|
*/
|
||||||
|
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reimplemented from QGraphicsItem
|
* Reimplemented from QGraphicsItem
|
||||||
@ -699,7 +703,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
void timerEvent (QTimerEvent *event);
|
void timerEvent (QTimerEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(Applet)
|
Q_PRIVATE_SLOT(d, void setFocus())
|
||||||
Q_PRIVATE_SLOT(d, void checkImmutability())
|
Q_PRIVATE_SLOT(d, void checkImmutability())
|
||||||
Q_PRIVATE_SLOT(d, void themeChanged())
|
Q_PRIVATE_SLOT(d, void themeChanged())
|
||||||
Q_PRIVATE_SLOT(d, void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim))
|
Q_PRIVATE_SLOT(d, void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim))
|
||||||
|
@ -62,6 +62,7 @@ public:
|
|||||||
void themeChanged();
|
void themeChanged();
|
||||||
void resetConfigurationObject();
|
void resetConfigurationObject();
|
||||||
void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim);
|
void appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim);
|
||||||
|
void setFocus();
|
||||||
|
|
||||||
static uint s_maxAppletId;
|
static uint s_maxAppletId;
|
||||||
static uint s_maxZValue;
|
static uint s_maxZValue;
|
||||||
@ -89,6 +90,7 @@ public:
|
|||||||
QGraphicsView* ghostView;
|
QGraphicsView* ghostView;
|
||||||
ImmutabilityType immutability;
|
ImmutabilityType immutability;
|
||||||
KActionCollection actions;
|
KActionCollection actions;
|
||||||
|
KAction *activationAction;
|
||||||
int constraintsTimerId;
|
int constraintsTimerId;
|
||||||
bool hasConfigurationInterface : 1;
|
bool hasConfigurationInterface : 1;
|
||||||
bool failed : 1;
|
bool failed : 1;
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <QGraphicsLayout>
|
#include <QGraphicsLayout>
|
||||||
#include <QGraphicsLinearLayout>
|
#include <QGraphicsLinearLayout>
|
||||||
|
|
||||||
|
#include <KAction>
|
||||||
#include <KApplication>
|
#include <KApplication>
|
||||||
#include <KAuthorized>
|
#include <KAuthorized>
|
||||||
#include <KIcon>
|
#include <KIcon>
|
||||||
@ -886,6 +887,12 @@ void Containment::addAssociatedWidget(QWidget *widget)
|
|||||||
if (d->focusedApplet) {
|
if (d->focusedApplet) {
|
||||||
d->focusedApplet->addAssociatedWidget(widget);
|
d->focusedApplet->addAssociatedWidget(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (const Applet* applet, d->applets) {
|
||||||
|
if (applet->d->activationAction) {
|
||||||
|
widget->addAction(applet->d->activationAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Containment::removeAssociatedWidget(QWidget *widget)
|
void Containment::removeAssociatedWidget(QWidget *widget)
|
||||||
@ -894,6 +901,12 @@ void Containment::removeAssociatedWidget(QWidget *widget)
|
|||||||
if (d->focusedApplet) {
|
if (d->focusedApplet) {
|
||||||
d->focusedApplet->removeAssociatedWidget(widget);
|
d->focusedApplet->removeAssociatedWidget(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (const Applet* applet, d->applets) {
|
||||||
|
if (applet->d->activationAction) {
|
||||||
|
widget->removeAction(applet->d->activationAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KActionCollection& Containment::Private::actions()
|
KActionCollection& Containment::Private::actions()
|
||||||
@ -1171,6 +1184,8 @@ Applet* Containment::Private::addApplet(const QString& name, const QVariantList&
|
|||||||
if (!applet) {
|
if (!applet) {
|
||||||
kDebug() << "Applet" << name << "could not be loaded.";
|
kDebug() << "Applet" << name << "could not be loaded.";
|
||||||
applet = new Applet;
|
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();
|
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "corona.h"
|
#include "corona.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QGraphicsSceneDragDropEvent>
|
#include <QGraphicsSceneDragDropEvent>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user