some stuff in Plasma::PopupApplet
- add QGraphicsWidget support - add a timer so we can show a popup during a specified time and hide it again - let applet Notifier does a last Swan song by convert it in a PopupApplet before dying and reborn sooner like a phoenix svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=838490
This commit is contained in:
parent
ac1f7e3b5b
commit
88b7a7022e
4
plasma.h
4
plasma.h
@ -157,7 +157,9 @@ enum ImmutabilityType { Mutable = 1 /**< The item can be modified in any way **/
|
|||||||
/**
|
/**
|
||||||
* Defines the aspect ratio used when scaling an applet
|
* Defines the aspect ratio used when scaling an applet
|
||||||
*/
|
*/
|
||||||
enum AspectRatioMode { IgnoreAspectRatio = 0 /**< The applet can be freely resized */,
|
enum AspectRatioMode { InvalidAspectRatioMode = -1 /**< Unsetted mode used for dev convenience when there is a need to store the
|
||||||
|
aspectRatioMode somewhere */,
|
||||||
|
IgnoreAspectRatio = 0 /**< The applet can be freely resized */,
|
||||||
KeepAspectRatio = 1 /**< The applet keeps a fixed aspect ratio */,
|
KeepAspectRatio = 1 /**< The applet keeps a fixed aspect ratio */,
|
||||||
Square = 2 /**< The applet is always a square */,
|
Square = 2 /**< The applet is always a square */,
|
||||||
ConstrainedSquare = 3 /** The applet is no wider (in horizontal formfactors) or no higher (in vertical ones) than a square*/
|
ConstrainedSquare = 3 /** The applet is no wider (in horizontal formfactors) or no higher (in vertical ones) than a square*/
|
||||||
|
110
popupapplet.cpp
110
popupapplet.cpp
@ -22,6 +22,7 @@
|
|||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsProxyWidget>
|
||||||
#include <QGraphicsLinearLayout>
|
#include <QGraphicsLinearLayout>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <KIcon>
|
#include <KIcon>
|
||||||
#include <KIconLoader>
|
#include <KIconLoader>
|
||||||
@ -40,7 +41,9 @@ public:
|
|||||||
icon(0),
|
icon(0),
|
||||||
dialog(0),
|
dialog(0),
|
||||||
layout(0),
|
layout(0),
|
||||||
proxy(0)
|
proxy(0),
|
||||||
|
savedAspectRatio(Plasma::InvalidAspectRatioMode),
|
||||||
|
timer(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,12 +58,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void togglePopup();
|
void togglePopup();
|
||||||
|
void hideTimedPopup();
|
||||||
|
|
||||||
PopupApplet *q;
|
PopupApplet *q;
|
||||||
Plasma::Icon *icon;
|
Plasma::Icon *icon;
|
||||||
Plasma::Dialog *dialog;
|
Plasma::Dialog *dialog;
|
||||||
QGraphicsLinearLayout *layout;
|
QGraphicsLinearLayout *layout;
|
||||||
QGraphicsProxyWidget *proxy;
|
QGraphicsProxyWidget *proxy;
|
||||||
|
Plasma::AspectRatioMode savedAspectRatio;
|
||||||
|
QTimer *timer;
|
||||||
};
|
};
|
||||||
|
|
||||||
PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
|
PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
|
||||||
@ -99,6 +105,16 @@ QIcon PopupApplet::icon() const
|
|||||||
return d->icon->icon();
|
return d->icon->icon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QWidget *PopupApplet::widget()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
QGraphicsWidget *PopupApplet::graphicsWidget()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
||||||
{
|
{
|
||||||
if (constraints & Plasma::StartupCompletedConstraint) {
|
if (constraints & Plasma::StartupCompletedConstraint) {
|
||||||
@ -115,35 +131,55 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
|||||||
d->layout->setMaximumSize(INT_MAX, INT_MAX);
|
d->layout->setMaximumSize(INT_MAX, INT_MAX);
|
||||||
d->layout->setOrientation(Qt::Horizontal);
|
d->layout->setOrientation(Qt::Horizontal);
|
||||||
setLayout(d->layout);
|
setLayout(d->layout);
|
||||||
|
|
||||||
connect(d->icon, SIGNAL(clicked()), this, SLOT(togglePopup()));
|
connect(d->icon, SIGNAL(clicked()), this, SLOT(togglePopup()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constraints & Plasma::FormFactorConstraint) {
|
if (constraints & Plasma::FormFactorConstraint) {
|
||||||
d->layout->removeAt(0);
|
d->layout->removeAt(0);
|
||||||
|
|
||||||
switch (formFactor()) {
|
switch (formFactor()) {
|
||||||
case Plasma::Planar:
|
case Plasma::Planar:
|
||||||
case Plasma::MediaCenter: {
|
case Plasma::MediaCenter: {
|
||||||
delete d->dialog;
|
if (d->savedAspectRatio != Plasma::InvalidAspectRatioMode) {
|
||||||
d->dialog = 0;
|
setAspectRatioMode(d->savedAspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
setAspectRatioMode(Plasma::IgnoreAspectRatio);
|
if (d->dialog) {
|
||||||
|
if (d->dialog->layout() && widget()) {
|
||||||
|
//we dont want to delete Widget inside the dialog layout
|
||||||
|
d->dialog->layout()->removeWidget(widget());
|
||||||
|
}
|
||||||
|
|
||||||
if (!d->proxy) {
|
delete d->dialog;
|
||||||
d->proxy = new QGraphicsProxyWidget(this);
|
d->dialog = 0;
|
||||||
d->proxy->setWidget(widget());
|
|
||||||
d->proxy->show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the margins
|
//get the margins
|
||||||
QSizeF marginSize = size() - contentsRect().size();
|
QSizeF marginSize = size() - contentsRect().size();
|
||||||
|
|
||||||
d->layout->addItem(d->proxy);
|
if (graphicsWidget()) {
|
||||||
setMinimumSize(widget() ? widget()->minimumSize() + marginSize : QSizeF(300, 200));
|
d->layout->addItem(graphicsWidget());
|
||||||
|
setMinimumSize(graphicsWidget()->minimumSize() + marginSize);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!d->proxy) {
|
||||||
|
d->proxy = new QGraphicsProxyWidget(this);
|
||||||
|
d->proxy->setWidget(widget());
|
||||||
|
d->proxy->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
d->layout->addItem(d->proxy);
|
||||||
|
setMinimumSize(widget() ? widget()->minimumSize() + marginSize : QSizeF(300, 200));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Plasma::Horizontal:
|
case Plasma::Horizontal:
|
||||||
case Plasma::Vertical:
|
case Plasma::Vertical:
|
||||||
setAspectRatioMode(Plasma::Square);
|
//save the aspect ratio mode in case we drag'n drop in the Desktop later
|
||||||
|
d->savedAspectRatio = aspectRatioMode();
|
||||||
|
setAspectRatioMode(Plasma::ConstrainedSquare);
|
||||||
|
|
||||||
if (d->proxy) {
|
if (d->proxy) {
|
||||||
d->proxy->setWidget(0); // prevent it from deleting our widget!
|
d->proxy->setWidget(0); // prevent it from deleting our widget!
|
||||||
@ -154,24 +190,48 @@ void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
|
|||||||
if (!d->dialog) {
|
if (!d->dialog) {
|
||||||
d->dialog = new Plasma::Dialog();
|
d->dialog = new Plasma::Dialog();
|
||||||
d->dialog->setWindowFlags(Qt::Popup);
|
d->dialog->setWindowFlags(Qt::Popup);
|
||||||
|
|
||||||
QVBoxLayout *l_layout = new QVBoxLayout(d->dialog);
|
QVBoxLayout *l_layout = new QVBoxLayout(d->dialog);
|
||||||
l_layout->setSpacing(0);
|
l_layout->setSpacing(0);
|
||||||
l_layout->setMargin(0);
|
l_layout->setMargin(0);
|
||||||
l_layout->addWidget(widget());
|
|
||||||
d->dialog->adjustSize();
|
if (graphicsWidget()) {
|
||||||
|
QGraphicsScene *scene = new QGraphicsScene(d->dialog);
|
||||||
|
QGraphicsView *view = new QGraphicsView(scene, d->dialog);
|
||||||
|
|
||||||
|
scene->addItem(graphicsWidget());
|
||||||
|
l_layout->addWidget(view);
|
||||||
|
view->show();
|
||||||
|
} else {
|
||||||
|
l_layout->addWidget(widget());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->dialog->adjustSize();
|
||||||
d->layout->addItem(d->icon);
|
d->layout->addItem(d->icon);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopupApplet::showPopup()
|
void PopupApplet::showPopup(uint popupDuration)
|
||||||
{
|
{
|
||||||
if (d->dialog && (formFactor() == Horizontal || formFactor() == Vertical)) {
|
if (d->dialog && (formFactor() == Horizontal || formFactor() == Vertical)) {
|
||||||
d->dialog->move(popupPosition(d->dialog->sizeHint()));
|
d->dialog->move(popupPosition(d->dialog->sizeHint()));
|
||||||
d->dialog->show();
|
d->dialog->show();
|
||||||
|
|
||||||
|
if (d->timer) {
|
||||||
|
d->timer->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (popupDuration > 0) {
|
||||||
|
if (!d->timer) {
|
||||||
|
d->timer = new QTimer(this);
|
||||||
|
connect(d->timer, SIGNAL(timeout()), this, SLOT(hideTimedPopup()));
|
||||||
|
}
|
||||||
|
|
||||||
|
d->timer->start(popupDuration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,18 +244,22 @@ void PopupApplet::hidePopup()
|
|||||||
|
|
||||||
void PopupAppletPrivate::togglePopup()
|
void PopupAppletPrivate::togglePopup()
|
||||||
{
|
{
|
||||||
if (!dialog) {
|
if (dialog) {
|
||||||
return;
|
if (dialog->isVisible()) {
|
||||||
}
|
dialog->hide();
|
||||||
|
} else {
|
||||||
|
dialog->move(q->popupPosition(dialog->sizeHint()));
|
||||||
|
dialog->show();
|
||||||
|
}
|
||||||
|
|
||||||
if (dialog->isVisible()) {
|
dialog->clearFocus();
|
||||||
dialog->hide();
|
|
||||||
} else {
|
|
||||||
dialog->move(q->popupPosition(dialog->sizeHint()));
|
|
||||||
dialog->show();
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dialog->clearFocus();
|
void PopupAppletPrivate::hideTimedPopup()
|
||||||
|
{
|
||||||
|
timer->stop();
|
||||||
|
q->hidePopup();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
@ -44,15 +44,17 @@ public:
|
|||||||
void setIcon(const QString &iconName);
|
void setIcon(const QString &iconName);
|
||||||
QIcon icon() const;
|
QIcon icon() const;
|
||||||
|
|
||||||
virtual QWidget *widget() = 0;
|
virtual QWidget *widget();
|
||||||
|
virtual QGraphicsWidget *graphicsWidget();
|
||||||
|
|
||||||
|
void showPopup(uint displayTime = 0);
|
||||||
|
void hidePopup();
|
||||||
protected:
|
protected:
|
||||||
void constraintsEvent(Plasma::Constraints constraints);
|
void constraintsEvent(Plasma::Constraints constraints);
|
||||||
void showPopup();
|
|
||||||
void hidePopup();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Q_PRIVATE_SLOT(d, void togglePopup())
|
Q_PRIVATE_SLOT(d, void togglePopup())
|
||||||
|
Q_PRIVATE_SLOT(d, void hideTimedPopup())
|
||||||
PopupAppletPrivate * const d;
|
PopupAppletPrivate * const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user