PopupApplet now respects the configured size

svn path=/trunk/KDE/kdelibs/; revision=1130581
This commit is contained in:
Aaron J. Seigo 2010-05-25 18:21:04 +00:00
parent 6db772c0db
commit 376b6cbb88
3 changed files with 64 additions and 10 deletions

View File

@ -58,22 +58,12 @@ PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args),
d(new PopupAppletPrivate(this))
{
int iconSize = IconSize(KIconLoader::Desktop);
resize(iconSize, iconSize);
disconnect(this, SIGNAL(activate()), (Applet*)this, SLOT(setFocus()));
connect(this, SIGNAL(activate()), this, SLOT(appletActivated()));
setAcceptDrops(true);
}
PopupApplet::PopupApplet(const QString &packagePath, uint appletId, const QVariantList &args)
: Plasma::Applet(packagePath, appletId, args),
d(new PopupAppletPrivate(this))
{
int iconSize = IconSize(KIconLoader::Desktop);
resize(iconSize, iconSize);
disconnect(this, SIGNAL(activate()), (Applet*)this, SLOT(setFocus()));
connect(this, SIGNAL(activate()), this, SLOT(togglePopup()));
setAcceptDrops(true);
}
PopupApplet::~PopupApplet()
@ -435,6 +425,27 @@ void PopupAppletPrivate::appletActivated()
q->showPopup();
}
QSizeF PopupApplet::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
{
if (!d->icon) {
return Applet::sizeHint(which, constraint);
}
switch (formFactor()) {
case Vertical:
case Horizontal: {
const int size = IconSize(KIconLoader::Panel);
return QSizeF(size, size);
break;
}
default:
break;
}
const int size = IconSize(KIconLoader::Desktop);
return QSizeF(size, size);
}
void PopupApplet::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (!d->icon && !d->popupLostFocus && event->buttons() == Qt::LeftButton) {
@ -610,6 +621,12 @@ PopupAppletPrivate::PopupAppletPrivate(PopupApplet *applet)
popupLostFocus(false),
passive(false)
{
int iconSize = IconSize(KIconLoader::Desktop);
q->resize(iconSize, iconSize);
q->setAcceptDrops(true);
QObject::disconnect(q, SIGNAL(activate()), static_cast<Applet*>(q), SLOT(setFocus()));
QObject::connect(q, SIGNAL(activate()), q, SLOT(appletActivated()));
QObject::connect(KGlobalSettings::self(), SIGNAL(iconChanged(int)), q, SLOT(iconSizeChanged(int)));
}
PopupAppletPrivate::~PopupAppletPrivate()
@ -622,6 +639,13 @@ PopupAppletPrivate::~PopupAppletPrivate()
delete icon;
}
void PopupAppletPrivate::iconSizeChanged(int group)
{
if (icon && (group == KIconLoader::Desktop || group == KIconLoader::Panel)) {
q->updateGeometry();
}
}
void PopupAppletPrivate::internalTogglePopup()
{
if (timer) {

View File

@ -144,11 +144,39 @@ protected:
*/
virtual void popupEvent(bool show);
/**
* Reimplemented from QGraphicsLayoutItem
*/
QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const;
/**
* Reimplemented from QGraphicsLayoutItem
*/
void mousePressEvent(QGraphicsSceneMouseEvent *event);
/**
* Reimplemented from QGraphicsLayoutItem
*/
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
/**
* Reimplemented from QGraphicsLayoutItem
*/
bool eventFilter(QObject *watched, QEvent *event);
/**
* Reimplemented from QGraphicsLayoutItem
*/
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
/**
* Reimplemented from QGraphicsLayoutItem
*/
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
/**
* Reimplemented from QGraphicsLayoutItem
*/
void dropEvent(QGraphicsSceneDragDropEvent *event);
private:
@ -169,6 +197,7 @@ private:
Q_PRIVATE_SLOT(d, void dialogStatusChanged(bool))
Q_PRIVATE_SLOT(d, void updateDialogPosition())
Q_PRIVATE_SLOT(d, void appletActivated())
Q_PRIVATE_SLOT(d, void iconSizeChanged(int))
friend class Applet;
friend class AppletPrivate;

View File

@ -33,6 +33,7 @@ public:
PopupAppletPrivate(PopupApplet *applet);
~PopupAppletPrivate();
void iconSizeChanged(int group);
void internalTogglePopup();
void hideTimedPopup();
void clearPopupLostFocus();