massive step towards QGraphicsView being separated from libplasma

* remove extenders (never panned out, used by exactly two components that we can find .. anywhere)
* move animations to libplasmagqv
* schedule js anims to be put into the js scriptengine
* move all QGraphicsProxyWidgets, except for IconWidget which is still used by PopupApplet, into libplasmaqgv
* create a subclass-able private class for Applet

TODO: move out icon widget, address FIXMES in graphicswidgetappletprivate.cpp and decide how to register the "right" private class for instantiation in Applet ctors
This commit is contained in:
Aaron Seigo 2011-11-17 14:40:53 +01:00
parent 5761d0f84b
commit 90b02f3973
51 changed files with 800 additions and 5467 deletions

View File

@ -28,7 +28,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/tier1/threadweaver/
${CMAKE_BINARY_DIR}/tier1/threadweaver/
${CMAKE_BINARY_DIR}/tier1/threadweaver/Weaver
${CMAKE_SOURCE_DIR}/plasma/extenders
${CMAKE_SOURCE_DIR}/plasma/remote
${CMAKE_SOURCE_DIR}/plasma/private/qtjolie-branch/qtjolie
${CMAKE_SOURCE_DIR}/plasma/private/qtjolie-branch
@ -86,26 +85,6 @@ set(plasma_LIB_SRCS
abstractdialogmanager.cpp
abstracttoolbox.cpp
dialog.cpp
animator.cpp
animations/animation.cpp
animations/animationscriptengine.cpp
animations/bindings/animationgroup.cpp
animations/bindings/easingcurve.cpp
animations/easinganimation.cpp
animations/fade.cpp
animations/grow.cpp
animations/javascriptanimation.cpp
animations/pendulumcurve.cpp
animations/pixmaptransition.cpp
animations/pulser.cpp
animations/rotation.cpp
animations/rotationstacked.cpp
animations/slide.cpp
animations/stackedlayout.cpp
animations/geometry.cpp
animations/water.cpp
animations/widgetsnapshot.cpp
animations/zoom.cpp
configloader.cpp
containment.cpp
containmentactions.cpp
@ -115,9 +94,6 @@ set(plasma_LIB_SRCS
dataengine.cpp
dataenginemanager.cpp
delegate.cpp
extenders/extender.cpp
extenders/extendergroup.cpp
extenders/extenderitem.cpp
package.cpp
packagestructure.cpp
paintutils.cpp
@ -134,10 +110,8 @@ set(plasma_LIB_SRCS
private/datacontainer_p.cpp
private/dataengineconsumer.cpp
private/dataengineservice.cpp
private/effects/halopainter.cpp
private/effectwatcher.cpp
private/extenderapplet.cpp
private/extenderitemmimedata.cpp
private/focusindicator.cpp
private/getsource.cpp
private/packages.cpp
private/plasmoidservice.cpp
@ -154,8 +128,6 @@ set(plasma_LIB_SRCS
private/windowpreview.cpp
private/windowshadows.cpp
private/kineticscroll.cpp
private/effects/halopainter.cpp
private/effects/ripple.cpp
querymatch.cpp
remote/accessmanager.cpp
remote/accessappletjob.cpp
@ -204,18 +176,27 @@ set(plasma_LIB_SRCS
private/qtjolie-branch/qtjolie/server.cpp
private/qtjolie-branch/qtjolie/serverthread.cpp
widgets/pushbutton.cpp
widgets/busywidget.cpp
#FIXME: all these must move into the qgv library
widgets/iconwidget.cpp
widgets/label.cpp
widgets/scrollbar.cpp
widgets/scrollwidget.cpp
widgets/svgwidget.cpp
widgets/textbrowser.cpp
widgets/textedit.cpp
)
set (plasmaqgv_LIB_SRCS
graphicsview/graphicsviewappletprivate.cpp
animator.cpp
animations/animation.cpp
animations/easinganimation.cpp
animations/fade.cpp
animations/grow.cpp
animations/pendulumcurve.cpp
animations/pixmaptransition.cpp
animations/pulser.cpp
animations/rotation.cpp
animations/rotationstacked.cpp
animations/slide.cpp
animations/stackedlayout.cpp
animations/geometry.cpp
animations/widgetsnapshot.cpp
animations/zoom.cpp
private/animablegraphicswebview.cpp
private/dataenginebindings.cpp
@ -224,6 +205,13 @@ set (plasmaqgv_LIB_SRCS
private/nativetabbar.cpp
private/style.cpp
widgets/label.cpp
widgets/scrollbar.cpp
widgets/svgwidget.cpp
widgets/scrollwidget.cpp
widgets/textedit.cpp
widgets/textbrowser.cpp
widgets/busywidget.cpp
widgets/checkbox.cpp
widgets/combobox.cpp
widgets/declarativewidget.cpp
@ -233,6 +221,7 @@ set (plasmaqgv_LIB_SRCS
widgets/itembackground.cpp
widgets/lineedit.cpp
widgets/meter.cpp
widgets/pushbutton.cpp
widgets/radiobutton.cpp
widgets/signalplotter.cpp
widgets/slider.cpp
@ -331,9 +320,6 @@ set(plasma_LIB_INCLUDES
dataenginemanager.h
delegate.h
dialog.h
extenders/extender.h
extenders/extendergroup.h
extenders/extenderitem.h
pluginloader.h
paintutils.h
windoweffects.h
@ -435,7 +421,6 @@ install(FILES
DESTINATION ${SERVICETYPES_INSTALL_DIR})
install(FILES
data/services/plasma-applet-extenderapplet.desktop
data/services/plasma.protocol
DESTINATION ${SERVICES_INSTALL_DIR})

View File

@ -1,69 +0,0 @@
/*
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <plasma/private/effects/ripple_p.h>
#include "water_p.h"
namespace Plasma
{
WaterAnimation::WaterAnimation(QObject *parent)
: EasingAnimation(parent),
m_offset(1)
{
}
qint8 WaterAnimation::offset() const
{
return m_offset;
}
void WaterAnimation::setOffset(qint8 offset)
{
m_offset = offset;
}
void WaterAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
{
QGraphicsWidget *widget = targetWidget();
if (!widget) {
return;
}
RippleEffect *effect = qobject_cast<RippleEffect*>(widget->graphicsEffect());
if (!effect) {
effect = new RippleEffect(widget);
widget->setGraphicsEffect(effect);
}
if (oldState == Stopped && newState == Running) {
effect->setOffset(m_offset);
effect->setEnabled(true);
} else if (newState == Stopped) {
effect->setEnabled(false);
}
}
void WaterAnimation::updateEffectiveTime(int currentTime)
{
QGraphicsWidget *widget = targetWidget();
if (widget && widget->graphicsEffect()) {
widget->graphicsEffect()->setProperty("opacity", currentTime / qreal(duration()));
}
}
} // namespace Plasma

View File

@ -1,68 +0,0 @@
/*
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMA_ANIMATIONS_WATER_P_H
#define PLASMA_ANIMATIONS_WATER_P_H
#include <plasma/animations/easinganimation_p.h>
namespace Plasma
{
/*
* @class Water plasma/animations/water_p.h
* @short Water animation using ripple effect
*
* Simulates a water animation using ripple effect
*/
class WaterAnimation : public EasingAnimation
{
Q_OBJECT
Q_PROPERTY(qint8 offset READ offset WRITE setOffset)
public:
/**
* Default constructor
* @param parent Animation object parent
*/
explicit WaterAnimation(QObject *parent = 0);
/**
* Returns the ripple offset. The ripple offset is the distance between neighbour pixels used to
* calculate the wave propagation.
* @return ripple offset
*/
qint8 offset() const;
public slots:
/**
* Sets the ripple offset
* @param offset ripple offset
*/
void setOffset(qint8 offset);
protected:
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
void updateEffectiveTime(int currentTime);
private:
qint8 m_offset; /** Ripple offset (default is 1) */
};
} // namespace Plasma
#endif // PLASMA_ANIMATIONS_WATER_P_H

View File

@ -16,12 +16,10 @@
*/
#include "animator.h"
#include "private/animator_p.h"
#include <kdebug.h>
#include "animations/animation.h"
#include "animations/animationscriptengine_p.h"
#include "animations/fade_p.h"
#include "animations/grow_p.h"
#include "animations/pulser_p.h"
@ -31,119 +29,57 @@
#include "animations/geometry_p.h"
#include "animations/zoom_p.h"
#include "animations/pixmaptransition_p.h"
#include "animations/water_p.h"
#include "animations/pendulumcurve_p.h"
#include "animations/javascriptanimation_p.h"
#include "theme.h"
namespace Plasma
{
QHash<Animator::Animation, Animator::Animation> AnimatorPrivate::s_stockAnimMappings;
QHash<Animator::Animation, QString> AnimatorPrivate::s_loadableAnimMappings;
Animator::Animator(QObject *parent)
: QObject(parent),
d(0)
{
}
void AnimatorPrivate::mapAnimation(Animator::Animation from, Animator::Animation to)
{
if (from == to) {
return;
}
s_loadableAnimMappings.remove(from);
s_stockAnimMappings.insert(from, to);
}
void AnimatorPrivate::mapAnimation(Animator::Animation from, const QString &to)
{
s_stockAnimMappings.remove(from);
s_loadableAnimMappings.insert(from, to);
}
Plasma::Animation* Animator::create(Animator::Animation type, QObject *parent)
{
if (AnimatorPrivate::s_stockAnimMappings.contains(type)) {
return create(AnimatorPrivate::s_stockAnimMappings.value(type));
} else if (AnimatorPrivate::s_loadableAnimMappings.contains(type)) {
const QString anim = AnimatorPrivate::s_loadableAnimMappings.value(type);
return create(anim, parent);
}
Plasma::Animation *result = 0;
switch (type) {
case FadeAnimation:
result = create("FadeAnimation", parent);
if (!result) {
result = new Plasma::FadeAnimation(parent);
}
break;
case GrowAnimation:
result = create("GrowAnimation", parent);
if (!result) {
result = new Plasma::GrowAnimation(parent);
}
break;
case PulseAnimation:
result = create("PulseAnimation", parent);
if (!result) {
result = new Plasma::PulseAnimation(parent);
}
break;
case RotationAnimation:
result = create("RotationAnimation", parent);
if (!result) {
result = new Plasma::RotationAnimation(parent);
}
break;
case RotationStackedAnimation:
result = create("RotationStackedAnimation", parent);
if (!result) {
result = new Plasma::RotationStackedAnimation(parent);
}
break;
case SlideAnimation:
result = create("SlideAnimation", parent);
if (!result) {
result = new Plasma::SlideAnimation(parent);
}
break;
case GeometryAnimation:
result = create("GeometryAnimation", parent);
if (!result) {
result = new Plasma::GeometryAnimation(parent);
}
break;
case ZoomAnimation:
result = create("ZoomAnimation", parent);
if (!result) {
result = new Plasma::ZoomAnimation(parent);
}
break;
case PixmapTransitionAnimation:
result = create("PixmapTransitionAnimation", parent);
if (!result) {
result = new Plasma::PixmapTransition(parent);
}
break;
case WaterAnimation:
result = create("WaterAnimation", parent);
if (!result) {
result = new Plasma::WaterAnimation(parent);
}
break;
default:
@ -189,35 +125,6 @@ QEasingCurve Animator::create(Animator::CurveShape type)
return result;
}
Plasma::Animation *Animator::create(const QString &anim, QObject *parent)
{
if (AnimationScriptEngine::animationFailedToLoad(anim)) {
return 0;
}
if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
const QString path = Theme::defaultTheme()->animationPath(anim);
if (path.isEmpty()) {
AnimationScriptEngine::addToLoadFailures(anim);
//kError() << "************ failed to find script file for animation" << anim;
return 0;
}
if (!AnimationScriptEngine::loadScript(path)) {
AnimationScriptEngine::addToLoadFailures(anim);
return 0;
}
if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
//kError() << "successfully loaded script file" << path << ", but did not get animation object for" << anim;
AnimationScriptEngine::addToLoadFailures(anim);
return 0;
}
}
return new Plasma::JavascriptAnimation(anim, parent);
}
} // namespace Plasma
#include <animator.moc>

View File

@ -64,7 +64,6 @@ public:
GeometryAnimation, /*<< Geometry animation*/
ZoomAnimation, /*<<Zoom animation */
PixmapTransitionAnimation, /*<< Transition between two pixmaps*/
WaterAnimation /*<< Water animation using ripple effect */,
LastAnimation = 1024
};
@ -85,13 +84,6 @@ public:
**/
static Plasma::Animation *create(Animator::Animation type, QObject *parent = 0);
/**
* Factory to build new animation objects from Javascript files. To control their behavior,
* check \ref AbstractAnimation properties.
* @since 4.5
**/
static Plasma::Animation *create(const QString &animationName, QObject *parent = 0);
/**
* Factory to build new custom easing curves.
* @since 4.5

View File

@ -84,8 +84,6 @@
#include "corona.h"
#include "dataenginemanager.h"
#include "dialog.h"
#include "extenders/extender.h"
#include "extenders/extenderitem.h"
#include "package.h"
#include "plasma.h"
#include "scripting/appletscript.h"
@ -93,7 +91,6 @@
#include "framesvg.h"
#include "popupapplet.h"
#include "private/applethandle_p.h"
#include "private/extenderitem_p.h"
#include "private/framesvg_p.h"
#include "remote/authorizationmanager.h"
#include "remote/authorizationmanager_p.h"
@ -101,8 +98,6 @@
#include "view.h"
#include "widgets/iconwidget.h"
#include "widgets/label.h"
#include "widgets/pushbutton.h"
#include "widgets/busywidget.h"
#include "tooltipmanager.h"
#include "wallpaper.h"
#include "paintutils.h"
@ -111,7 +106,6 @@
#include "private/associatedapplicationmanager_p.h"
#include "private/containment_p.h"
#include "private/extenderapplet_p.h"
#include "private/package_p.h"
#include "private/packages_p.h"
#include "private/plasmoidservice_p.h"
@ -142,10 +136,7 @@ Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId)
d->init();
}
Applet::Applet(QGraphicsItem *parent,
const QString &serviceID,
uint appletId,
const QVariantList &args)
Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId, const QVariantList &args)
: QGraphicsWidget(parent),
d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this))
{
@ -209,23 +200,6 @@ Applet::~Applet()
//let people know that i will die
emit appletDestroyed(this);
if (!d->transient && d->extender) {
//This would probably be nicer if it was located in extender. But in it's dtor, this won't
//work since when that get's called, the applet's config() isn't accessible anymore. (same
//problem with calling saveState(). Doing this in saveState() might be a possibility, but
//that would require every extender savestate implementation to call it's parent function,
//which isn't very nice.
d->extender.data()->saveState();
foreach (ExtenderItem *item, d->extender.data()->attachedItems()) {
if (item->autoExpireDelay()) {
//destroy temporary extender items, or items that aren't detached, so their
//configuration won't linger after a plasma restart.
item->destroy();
}
}
}
// clean up our config dialog, if any
delete KConfigDialog::exists(d->configDialogId());
delete d;
@ -358,62 +332,8 @@ void AppletPrivate::setFocus()
void Applet::setFailedToLaunch(bool failed, const QString &reason)
{
if (d->failed == failed) {
if (failed && !reason.isEmpty()) {
foreach (QGraphicsItem *item, QGraphicsItem::children()) {
Label *l = dynamic_cast<Label *>(item);
if (l) {
l->setText(d->visibleFailureText(reason));
}
}
}
return;
}
d->failed = failed;
prepareGeometryChange();
foreach (QGraphicsItem *item, childItems()) {
if (!dynamic_cast<AppletHandle *>(item)) {
delete item;
}
}
d->messageOverlay = 0;
if (d->messageDialog) {
d->messageDialog.data()->deleteLater();
d->messageDialog.clear();
}
setLayout(0);
if (failed) {
setBackgroundHints(StandardBackground);
QGraphicsLinearLayout *failureLayout = new QGraphicsLinearLayout(this);
failureLayout->setContentsMargins(0, 0, 0, 0);
IconWidget *failureIcon = new IconWidget(this);
failureIcon->setIcon(KIcon("dialog-error"));
failureLayout->addItem(failureIcon);
Label *failureWidget = new Plasma::Label(this);
failureWidget->setText(d->visibleFailureText(reason));
QLabel *label = failureWidget->nativeWidget();
label->setWordWrap(true);
failureLayout->addItem(failureWidget);
Plasma::ToolTipManager::self()->registerWidget(failureIcon);
Plasma::ToolTipContent data(i18n("Unable to load the widget"), reason,
KIcon("dialog-error"));
Plasma::ToolTipManager::self()->setContent(failureIcon, data);
setLayout(failureLayout);
resize(300, 250);
d->background->resizeFrame(geometry().size());
}
update();
d->updateFailedToLaunch(reason);
}
void Applet::saveState(KConfigGroup &group) const
@ -476,15 +396,8 @@ void Applet::destroy()
}
d->transient = true;
if (isContainment()) {
//FIXME: an animation on leave if !isContainment() would be good again .. which should be handled by the containment class
d->cleanUpAndDelete();
} else {
Animation *zoomAnim = Plasma::Animator::create(Plasma::Animator::ZoomAnimation);
connect(zoomAnim, SIGNAL(finished()), this, SLOT(cleanUpAndDelete()));
zoomAnim->setTargetWidget(this);
zoomAnim->start();
}
}
bool Applet::destroyed() const
@ -558,113 +471,6 @@ void AppletPrivate::cleanUpAndDelete()
q->deleteLater();
}
void AppletPrivate::createMessageOverlay(bool usePopup)
{
if (messageOverlay) {
qDeleteAll(messageOverlay->children());
messageOverlay->setLayout(0);
}
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
if (!messageOverlay) {
if (usePopup && popup) {
if (popup->widget()) {
messageOverlayProxy = new QGraphicsProxyWidget(q);
messageOverlayProxy->setWidget(popup->widget());
messageOverlay = new AppletOverlayWidget(messageOverlayProxy);
} else if (popup->graphicsWidget() &&
popup->graphicsWidget() != extender.data()) {
messageOverlay = new AppletOverlayWidget(popup->graphicsWidget());
}
}
if (!messageOverlay) {
messageOverlay = new AppletOverlayWidget(q);
}
}
positionMessageOverlay();
}
void AppletPrivate::positionMessageOverlay()
{
if (!messageOverlay) {
return;
}
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
const bool usePopup = popup && (messageOverlay->parentItem() != q);
QGraphicsItem *topItem = q;
if (usePopup && popup->widget()) {
// popupapplet with widget()
topItem = popup->d->proxy.data();
messageOverlay->setGeometry(popup->widget()->contentsRect());
} else if (usePopup && popup->graphicsWidget() && popup->graphicsWidget() != extender.data()) {
// popupapplet with graphicsWidget()
topItem = popup->graphicsWidget();
QGraphicsWidget *w = dynamic_cast<QGraphicsWidget *>(topItem);
messageOverlay->setGeometry(w ? w->contentsRect() : topItem->boundingRect());
} else {
// normal applet
messageOverlay->setGeometry(q->contentsRect());
}
// raise the overlay above all the other children!
int zValue = 100;
foreach (QGraphicsItem *child, topItem->children()) {
if (child->zValue() > zValue) {
zValue = child->zValue() + 1;
}
}
messageOverlay->setZValue(zValue);
}
void AppletPrivate::destroyMessageOverlay()
{
if (messageDialog) {
messageDialog.data()->animatedHide(Plasma::locationToInverseDirection(q->location()));
//messageDialog.data()->deleteLater();
messageDialog.clear();
}
if (!messageOverlay) {
return;
}
messageOverlay->destroy();
messageOverlay = 0;
if (messageOverlayProxy) {
messageOverlayProxy->setWidget(0);
delete messageOverlayProxy;
messageOverlayProxy = 0;
}
MessageButton buttonCode = ButtonNo;
//find out if we're disappearing because of a button press
PushButton *button = qobject_cast<PushButton *>(q->sender());
if (button) {
if (button == messageOkButton.data()) {
buttonCode = ButtonOk;
}
if (button == messageYesButton.data()) {
buttonCode = ButtonYes;
}
if (button == messageNoButton.data()) {
buttonCode = ButtonNo;
}
if (button == messageCancelButton.data()) {
buttonCode = ButtonCancel;
}
emit q->messageButtonPressed(buttonCode);
} else if (q->sender() == messageOverlay) {
emit q->messageButtonPressed(ButtonCancel);
}
}
ConfigLoader *Applet::configScheme() const
{
return d->configLoader;
@ -757,46 +563,14 @@ void Applet::constraintsEvent(Plasma::Constraints constraints)
}
}
void Applet::initExtenderItem(ExtenderItem *item)
{
if (d->script) {
emit extenderItemRestored(item);
} else {
kWarning() << "Missing implementation of initExtenderItem in the applet "
<< item->config().readEntry("SourceAppletPluginName", "")
<< "!\n Any applet that uses extenders should implement initExtenderItem to "
<< "instantiate a widget. Destroying the item...";
item->destroy();
}
}
Extender *Applet::extender() const
{
if (!d->extender) {
new Extender(const_cast<Applet*>(this));
}
return d->extender.data();
}
void Applet::setBusy(bool busy)
{
if (busy) {
if (!d->busyWidget && !d->busyWidgetTimer.isActive()) {
d->busyWidgetTimer.start(500, this);
}
} else {
d->busyWidgetTimer.stop();
if (d->busyWidget) {
d->busyWidget = 0;
d->destroyMessageOverlay();
}
}
d->setBusy(busy);
}
bool Applet::isBusy() const
{
return d->busyWidgetTimer.isActive() || (d->busyWidget && d->busyWidget->isVisible());
return d->isBusy();
}
QString Applet::name() const
@ -994,175 +768,12 @@ void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
}
d->needsConfig = needsConfig;
if (!needsConfig) {
d->destroyMessageOverlay();
return;
}
d->createMessageOverlay(true);
d->messageOverlay->opacity = 0.4;
QGraphicsGridLayout *configLayout = new QGraphicsGridLayout(d->messageOverlay);
configLayout->setContentsMargins(0, 0, 0, 0);
// configLayout->addStretch();
configLayout->setColumnStretchFactor(0, 5);
configLayout->setColumnStretchFactor(2, 5);
configLayout->setRowStretchFactor(0, 5);
configLayout->setRowStretchFactor(3, 5);
int row = 1;
if (!reason.isEmpty()) {
Label *explanation = new Label(d->messageOverlay);
explanation->setText(reason);
configLayout->addItem(explanation, row, 1);
configLayout->setColumnStretchFactor(1, 5);
++row;
configLayout->setAlignment(explanation, Qt::AlignBottom | Qt::AlignCenter);
}
PushButton *configWidget = new PushButton(d->messageOverlay);
if (!qobject_cast<Plasma::PopupApplet *>(this) && (formFactor() == Plasma::Horizontal || formFactor() == Plasma::Vertical)) {
configWidget->setImage("widgets/configuration-icons", "configure");
configWidget->setMaximumSize(24,24);
configWidget->setMinimumSize(24,24);
} else {
configWidget->setText(i18n("Configure..."));
}
connect(configWidget, SIGNAL(clicked()), this, SLOT(showConfigurationInterface()));
configLayout->addItem(configWidget, row, 1);
//configLayout->setAlignment(configWidget, Qt::AlignTop | Qt::AlignCenter);
//configLayout->addStretch();
d->messageOverlay->show();
d->showConfigurationRequiredMessage(needsConfig, reason);
}
void Applet::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
{
if (message.isEmpty()) {
d->destroyMessageOverlay();
return;
}
Corona *corona = qobject_cast<Corona *>(scene());
QGraphicsWidget *mainWidget = new QGraphicsWidget;
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(mainWidget);
mainLayout->setOrientation(Qt::Vertical);
mainLayout->addStretch();
QGraphicsLinearLayout *messageLayout = new QGraphicsLinearLayout();
messageLayout->setOrientation(Qt::Horizontal);
QGraphicsLinearLayout *buttonLayout = new QGraphicsLinearLayout();
buttonLayout->setOrientation(Qt::Horizontal);
mainLayout->addItem(messageLayout);
mainLayout->addItem(buttonLayout);
mainLayout->addStretch();
IconWidget *messageIcon = new IconWidget(mainWidget);
Label *messageText = new Label(mainWidget);
messageText->nativeWidget()->setWordWrap(true);
messageLayout->addStretch();
messageLayout->addItem(messageIcon);
messageLayout->addItem(messageText);
messageLayout->addStretch();
messageIcon->setIcon(icon);
messageText->setText(message);
buttonLayout->addStretch();
if (buttons & ButtonOk) {
d->messageOkButton = new PushButton(mainWidget);
d->messageOkButton.data()->setText(i18n("&OK"));
d->messageOkButton.data()->setIcon(KIcon("dialog-ok"));
buttonLayout->addItem(d->messageOkButton.data());
connect(d->messageOkButton.data(), SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
}
if (buttons & ButtonYes) {
d->messageYesButton = new PushButton(mainWidget);
d->messageYesButton.data()->setText(i18n("&Yes"));
buttonLayout->addItem(d->messageYesButton.data());
connect(d->messageYesButton.data(), SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
}
if (buttons & ButtonNo) {
d->messageNoButton = new PushButton(mainWidget);
d->messageNoButton.data()->setText(i18n("&No"));
buttonLayout->addItem(d->messageNoButton.data());
connect(d->messageNoButton.data(), SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
}
if (buttons & ButtonCancel) {
d->messageCancelButton = new PushButton(mainWidget);
d->messageCancelButton.data()->setText(i18n("&Cancel"));
d->messageCancelButton.data()->setIcon(KIcon("dialog-cancel"));
buttonLayout->addItem(d->messageCancelButton.data());
connect(d->messageCancelButton.data(), SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
}
d->messageCloseAction = new QAction(d->messageOverlay);
d->messageCloseAction.data()->setShortcut(Qt::Key_Escape);
mainWidget->addAction(d->messageCloseAction.data());
connect(d->messageCloseAction.data(), SIGNAL(triggered()), this, SLOT(destroyMessageOverlay()));
buttonLayout->addStretch();
mainWidget->adjustSize();
QSizeF hint = mainWidget->preferredSize();
if (hint.height() > size().height() || hint.width() > size().width()) {
// either a collapsed popup in h/v form factor or just too small,
// so show it in a dialog associated with ourselves
if (corona) {
corona->addOffscreenWidget(mainWidget);
}
if (d->messageDialog) {
delete d->messageDialog.data()->graphicsWidget();
} else {
d->messageDialog = new Plasma::Dialog;
}
ToolTipManager::self()->hide(this);
KWindowSystem::setOnAllDesktops(d->messageDialog.data()->winId(), true);
KWindowSystem::setState(d->messageDialog.data()->winId(), NET::SkipTaskbar | NET::SkipPager);
d->messageDialog.data()->setGraphicsWidget(mainWidget);
connect(d->messageDialog.data(), SIGNAL(destroyed(QObject*)), mainWidget, SLOT(deleteLater()));
// if we are going to show it in a popup, then at least make sure it can be dismissed
if (buttonLayout->count() < 1) {
PushButton *ok = new PushButton(mainWidget);
ok->setText(i18n("OK"));
ok->setIcon(KIcon("dialog-ok"));
buttonLayout->addItem(ok);
connect(ok, SIGNAL(clicked()), this, SLOT(destroyMessageOverlay()));
}
} else {
delete d->messageDialog.data();
d->createMessageOverlay();
d->messageOverlay->opacity = 0.8;
mainWidget->setParentItem(d->messageOverlay);
QGraphicsLinearLayout *l = new QGraphicsLinearLayout(d->messageOverlay);
l->addItem(mainWidget);
}
if (d->messageDialog) {
QPoint pos = geometry().topLeft().toPoint();
if (corona) {
pos = corona->popupPosition(this, d->messageDialog.data()->size());
}
d->messageDialog.data()->move(pos);
d->messageDialog.data()->animatedShow(locationToDirection(location()));
} else {
d->messageOverlay->show();
}
d->showMessage(icon, message, buttons);
}
QVariantList Applet::startupArguments() const
@ -1247,12 +858,6 @@ void Applet::flushPendingConstraintsEvents()
action->setEnabled(canConfig);
}
if (d->extender) {
foreach (ExtenderItem *item, d->extender.data()->attachedItems()) {
item->d->setMovable(unlocked);
}
}
if (!unlocked && d->handle) {
AppletHandle *h = d->handle.data();
disconnect(this);
@ -1557,6 +1162,44 @@ void Applet::setGlobalShortcut(const KShortcut &shortcut)
d->globalShortcutChanged();
}
void AppletPrivate::showConfigurationRequiredMessage(bool show, const QString &reason)
{
// reimplemented in the UI specific library
Q_UNUSED(show)
Q_UNUSED(reason)
}
void AppletPrivate::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
{
// reimplemented in the UI specific library
Q_UNUSED(icon)
Q_UNUSED(message)
Q_UNUSED(buttons)
}
void AppletPrivate::positionMessageOverlay()
{
// reimplemented in the UI specific library
}
void AppletPrivate::setBusy(bool busy)
{
// reimplemented in the UI specific library
Q_UNUSED(busy)
}
bool AppletPrivate::isBusy() const
{
// reimplemented in the UI specific library
return false;
}
void AppletPrivate::updateFailedToLaunch(const QString &reason)
{
// reimplemented in the UI specific library
Q_UNUSED(reason)
}
void AppletPrivate::globalShortcutChanged()
{
if (!activationAction) {
@ -2491,7 +2134,6 @@ void Applet::timerEvent(QTimerEvent *event)
{
if (d->transient) {
d->constraintsTimer.stop();
d->busyWidgetTimer.stop();
if (d->modificationsTimer) {
d->modificationsTimer->stop();
}
@ -2513,22 +2155,6 @@ void Applet::timerEvent(QTimerEvent *event)
save(cg);
emit configNeedsSaving();
} else if (event->timerId() == d->busyWidgetTimer.timerId()) {
if (!d->busyWidget) {
d->createMessageOverlay(false);
d->messageOverlay->opacity = 0;
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(d->messageOverlay);
d->busyWidget = new Plasma::BusyWidget(d->messageOverlay);
d->busyWidget->setAcceptHoverEvents(false);
d->busyWidget->setAcceptedMouseButtons(Qt::NoButton);
d->messageOverlay->setAcceptHoverEvents(false);
d->messageOverlay->setAcceptedMouseButtons(Qt::NoButton);
mainLayout->addStretch();
mainLayout->addItem(d->busyWidget);
mainLayout->addStretch();
}
}
}
@ -2600,9 +2226,6 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int
background(0),
mainConfig(0),
pendingConstraints(NoConstraint),
messageOverlay(0),
messageOverlayProxy(0),
busyWidget(0),
script(0),
package(0),
configLoader(0),
@ -2633,8 +2256,6 @@ AppletPrivate::~AppletPrivate()
activationAction->forgetGlobalShortcut();
}
delete extender.data();
delete script;
script = 0;
delete package;
@ -2650,7 +2271,7 @@ void AppletPrivate::init(const QString &packagePath)
{
// WARNING: do not access config() OR globalConfig() in this method!
// that requires a scene, which is not available at this point
q->setCacheMode(Applet::DeviceCoordinateCache);
q->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
q->setAcceptsHoverEvents(true);
q->setFlag(QGraphicsItem::ItemIsFocusable, true);
q->setFocusPolicy(Qt::ClickFocus);
@ -2963,70 +2584,6 @@ int AppletPrivate::s_maxZValue = 0;
int AppletPrivate::s_minZValue = 0;
QSet<QString> AppletPrivate::s_customCategories;
AppletOverlayWidget::AppletOverlayWidget(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
opacity(0.4)
{
resize(parent->size());
}
void AppletOverlayWidget::destroy()
{
Animation *anim = Plasma::Animator::create(Plasma::Animator::DisappearAnimation);
if (anim) {
connect(anim, SIGNAL(finished()), this, SLOT(overlayAnimationComplete()));
anim->setTargetWidget(this);
anim->start();
} else {
overlayAnimationComplete();
}
}
void AppletOverlayWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
}
void AppletOverlayWidget::overlayAnimationComplete()
{
if (scene()) {
scene()->removeItem(this);
}
deleteLater();
}
void AppletOverlayWidget::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
if (qFuzzyCompare(1, 1+opacity)) {
return;
}
QColor wash = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor);
wash.setAlphaF(opacity);
Applet *applet = qobject_cast<Applet *>(parentWidget());
QPainterPath backgroundShape;
if (!applet || applet->backgroundHints() == StandardBackground) {
//FIXME: a resize here is nasty, but perhaps still better than an eventfilter just for that..
if (parentWidget()->contentsRect().size() != size()) {
resize(parentWidget()->contentsRect().size());
}
backgroundShape = PaintUtils::roundedRectangle(contentsRect(), 5);
} else {
backgroundShape = shape();
}
painter->setRenderHints(QPainter::Antialiasing);
painter->fillPath(backgroundShape, wash);
}
} // Plasma namespace
#include "applet.moc"

View File

@ -49,8 +49,6 @@ namespace Plasma
class AppletPrivate;
class Containment;
class DataEngine;
class Extender;
class ExtenderItem;
class Package;
@ -521,25 +519,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
virtual void removeAssociatedWidget(QWidget *widget);
/**
* Gets called when an extender item has to be initialized after a plasma restart. If you
* create ExtenderItems in your applet, you should implement this function to again create
* the widget that should be shown in this extender item. This function might look something
* like this:
*
* @code
* SuperCoolWidget *widget = new SuperCoolWidget();
* dataEngine("engine")->connectSource(item->config("dataSourceName"), widget);
* item->setWidget(widget);
* @endcode
*
* You can also add one or more custom qactions to this extender item in this function.
*
* Note that by default, not all ExtenderItems are persistent. Only items that are detached,
* will have their configuration stored when plasma exits.
*/
virtual void initExtenderItem(ExtenderItem *item);
/**
* @param parent the QGraphicsItem this applet is parented to
* @param serviceId the name of the .desktop file containing the
@ -547,9 +526,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
* @param appletId a unique id used to differentiate between multiple
* instances of the same Applet type
*/
explicit Applet(QGraphicsItem *parent = 0,
const QString &serviceId = QString(),
uint appletId = 0);
explicit Applet(QGraphicsItem *parent = 0, const QString &serviceId = QString(), uint appletId = 0);
/**
* @param parent the QGraphicsItem this applet is parented to
@ -570,10 +547,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
* and the applet id
* @since 4.3
*/
explicit Applet(QGraphicsItem *parent,
const QString &serviceId,
uint appletId,
const QVariantList &args);
explicit Applet(QGraphicsItem *parent, const QString &serviceId, uint appletId, const QVariantList &args);
/**
@ -714,11 +688,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
void newStatus(Plasma::ItemStatus status);
/**
* Emitted when an ExtenderItem in a scripting applet needs to be initialized
*/
void extenderItemRestored(Plasma::ExtenderItem *item);
/**
* Emitted when the immutability changes
* @since 4.4
@ -965,11 +934,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/
bool isRegisteredAsDragHandle(QGraphicsItem *item);
/**
* @return the extender of this applet.
*/
Extender *extender() const;
/**
* @internal scene event filter; used to manage applet dragging
*/
@ -1037,7 +1001,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
Q_PRIVATE_SLOT(d, void cleanUpAndDelete())
Q_PRIVATE_SLOT(d, void selectItemToDestroy())
Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
Q_PRIVATE_SLOT(d, void destroyMessageOverlay())
Q_PRIVATE_SLOT(d, void clearShortcutEditorPtr())
Q_PRIVATE_SLOT(d, void configDialogFinished())
Q_PRIVATE_SLOT(d, void updateShortcuts())
@ -1066,12 +1029,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
friend class PopupApplet;
friend class PopupAppletPrivate;
friend class AssociatedApplicationManager;
friend class Extender;
friend class ExtenderGroup;
friend class ExtenderGroupPrivate;
friend class ExtenderPrivate;
friend class ExtenderItem;
};
} // Plasma namespace

View File

@ -57,8 +57,6 @@
#include "containmentactions.h"
#include "containmentactionspluginsconfig.h"
#include "corona.h"
#include "extender.h"
#include "extenderitem.h"
#include "pluginloader.h"
#include "svg.h"
#include "wallpaper.h"
@ -68,12 +66,9 @@
#include "private/applet_p.h"
#include "private/containmentactionspluginsconfig_p.h"
#include "private/extenderitemmimedata_p.h"
#include "private/extenderapplet_p.h"
#include "private/wallpaper_p.h"
#include "plasma/plasma.h"
#include "animations/animation.h"
namespace Plasma
{
@ -133,7 +128,7 @@ Containment::Containment(QObject *parent, const QVariantList &args)
}
Containment::Containment(const QString &packagePath, uint appletId, const QVariantList &args)
: Plasma::Applet(packagePath, appletId, args),
: Applet(packagePath, appletId, args),
d(new ContainmentPrivate(this))
{
// WARNING: do not access config() OR globalConfig() in this method!
@ -927,18 +922,9 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
if (!delayInit && !currentContainment) {
applet->restore(*applet->d->mainConfigGroup());
applet->init();
Plasma::Animation *anim = Plasma::Animator::create(Plasma::Animator::AppearAnimation);
if (anim) {
connect(anim, SIGNAL(finished()), this, SLOT(appletAppearAnimationComplete()));
anim->setTargetWidget(applet);
//FIXME: small hack until we have proper js anim support; allows 'zoom' to work in the
//'right' direction for appearance
anim->setDirection(QAbstractAnimation::Backward);
anim->start(QAbstractAnimation::DeleteWhenStopped);
} else {
//FIXME: an on-appear animation would be nice to have again
d->appletAppeared(applet);
}
}
applet->setFlag(QGraphicsItem::ItemIsMovable, true);
applet->updateConstraints(Plasma::AllConstraints);
@ -1165,8 +1151,7 @@ void Containment::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
//kDebug() << immutability() << Mutable << (immutability() == Mutable);
event->setAccepted(immutability() == Mutable &&
(event->mimeData()->hasFormat(static_cast<Corona*>(scene())->appletMimeType()) ||
KUrl::List::canDecode(event->mimeData()) ||
event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())));
KUrl::List::canDecode(event->mimeData())));
if (!event->isAccepted()) {
// check to see if we have an applet that accepts the format.
@ -1292,36 +1277,6 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
if (dropEvent) {
dropEvent->acceptProposedAction();
}
} else if (mimeData->hasFormat(ExtenderItemMimeData::mimeType())) {
#ifndef NDEBUG
kDebug() << "mimeType plasma/extenderitem is dropped, creating internal:extender";
#endif
//Handle dropping extenderitems.
const ExtenderItemMimeData *extenderData = qobject_cast<const ExtenderItemMimeData*>(mimeData);
if (extenderData) {
ExtenderItem *item = extenderData->extenderItem();
QRectF geometry(pos - extenderData->pointerOffset(), item->size());
#ifndef NDEBUG
kDebug() << "desired geometry: " << geometry;
#endif
Applet *applet = qobject_cast<ExtenderApplet *>(item->extender() ? item->extender()->applet() : 0);
if (applet) {
qreal left, top, right, bottom;
applet->getContentsMargins(&left, &top, &right, &bottom);
applet->setPos(geometry.topLeft() - QPointF(int(left), int(top)));
applet->show();
} else {
applet = addApplet("internal:extender", QVariantList(), geometry, 0, true);
applet->hide();
applet->init();
appletAppeared(applet);
applet->flushPendingConstraintsEvents();
applet->d->scheduleModificationNotification();
applet->adjustSize();
applet->show();
}
item->setExtender(applet->extender());
}
} else if (KUrl::List::canDecode(mimeData)) {
//TODO: collect the mimeTypes of available script engines and offer
// to create widgets out of the matching URLs, if any
@ -2269,17 +2224,6 @@ void ContainmentPrivate::appletDestroyed(Plasma::Applet *applet)
emit q->configNeedsSaving();
}
void ContainmentPrivate::appletAppearAnimationComplete()
{
Animation *anim = qobject_cast<Animation *>(q->sender());
if (anim) {
Applet *applet = qobject_cast<Applet*>(anim->targetWidget());
if (applet) {
appletAppeared(applet);
}
}
}
void ContainmentPrivate::appletAppeared(Applet *applet)
{
//kDebug() << type << Containment::DesktopContainment;

View File

@ -610,7 +610,6 @@ Q_SIGNALS:
Containment(const QString &packagePath, uint appletId, const QVariantList &args);
Q_PRIVATE_SLOT(d, void appletDestroyed(Plasma::Applet*))
Q_PRIVATE_SLOT(d, void appletAppearAnimationComplete())
Q_PRIVATE_SLOT(d, void triggerShowAddWidgets())
Q_PRIVATE_SLOT(d, void positionToolBox())
Q_PRIVATE_SLOT(d, void requestConfiguration())

View File

@ -43,11 +43,9 @@
#include "abstractdialogmanager.h"
#include "abstracttoolbox.h"
#include "animator.h"
#include "containment.h"
#include "containmentactionspluginsconfig.h"
#include "pluginloader.h"
#include "private/animator_p.h"
#include "private/applet_p.h"
#include "private/containment_p.h"
#include "tooltipmanager.h"
@ -355,16 +353,6 @@ Containment *Corona::addContainmentDelayed(const QString &name, const QVariantLi
return 0;
}
void Corona::mapAnimation(Animator::Animation from, Animator::Animation to)
{
AnimatorPrivate::mapAnimation(from, to);
}
void Corona::mapAnimation(Animator::Animation from, const QString &to)
{
AnimatorPrivate::mapAnimation(from, to);
}
void Corona::addOffscreenWidget(QGraphicsWidget *widget)
{
foreach (QGraphicsWidget *w, d->offscreenWidgets) {

View File

@ -23,7 +23,6 @@
#include <QtGui/QGraphicsScene>
#include <plasma/applet.h>
#include <plasma/containment.h>
#include <plasma/plasma.h>
#include <plasma/plasma_export.h>
@ -436,24 +435,6 @@ protected:
Containment *addContainmentDelayed(const QString &name,
const QVariantList &args = QVariantList());
/**
* Maps a stock animation to one of the semantic animations. Used to control things such
* as what animation is used to make a Plasma::Appear appear in a containment.
* @param from the animation to map a new value to
* @param to the animation value to map to from
* @since 4.5
*/
void mapAnimation(Animator::Animation from, Animator::Animation to);
/**
* Maps a loadable animation to one of the semantic animations. Used to control things such
* as what animation is used to make a Plasma::Appear appear in a containment.
* @param from the animation to map a new value to
* @param to the animation value to map to from; this must map to a Javascript animation
* @since 4.5
*/
void mapAnimation(Animator::Animation from, const QString &to);
/**
* @return The preferred toolbox plugin name for a given containment type.
* @param type the containment type of which we want to know the preferred toolbox plugin.

View File

@ -1,81 +0,0 @@
[Desktop Entry]
Name=Collection
Name[ar]=المجموعة
Name[ast]=Coleición
Name[be@latin]=Zbor
Name[bg]=Колекция
Name[bn]=
Name[bs]=Kolekcija
Name[ca]=Col·lecció
Name[ca@valencia]=Col·lecció
Name[cs]=Kolekce
Name[csb]=Kòlekcëjô
Name[da]=Samling
Name[de]=Sammlung
Name[el]=Συλλογή
Name[en_GB]=Collection
Name[eo]=Kolekto
Name[es]=Colección
Name[et]=Kollektsioon
Name[eu]=Bilduma
Name[fa]=مجموعه
Name[fi]=Kokoelma
Name[fr]=Collection
Name[fy]=Kolleksje
Name[ga]=Bailiúchán
Name[gl]=Colección
Name[gu]=
Name[he]=אוסף
Name[hi]=
Name[hr]=Kolekcija
Name[hu]=Gyűjtemény
Name[ia]=Collection
Name[id]=Koleksi
Name[is]=Safn
Name[it]=Collezione
Name[ja]=
Name[kk]=Collection
Name[km]=
Name[kn]=
Name[ko]=
Name[ku]=Berhevok
Name[lt]=Rinkinys
Name[lv]=Kolekcija
Name[ml]=
Name[ms]=Koleksi
Name[nb]=Samling
Name[nds]=Sammeln
Name[nl]=Verzameling
Name[nn]=Samling
Name[pa]=
Name[pl]=Kolekcja
Name[pt]=Colecção
Name[pt_BR]=Coleção
Name[ro]=Colecție
Name[ru]=Коллекция
Name[se]=Čoahkádus
Name[si]=
Name[sk]=Kolekcia
Name[sl]=Zbirka
Name[sq]=Koleksioni
Name[sr]=збирка
Name[sr@ijekavian]=збирка
Name[sr@ijekavianlatin]=zbirka
Name[sr@latin]=zbirka
Name[sv]=Samling
Name[ta]=
Name[tg]=Коллексия
Name[th]=
Name[tr]=Koleksiyon
Name[ug]=توپلام
Name[uk]=Збірка
Name[wa]=Ramexhnêye
Name[x-test]=xxCollectionxx
Name[zh_CN]=
Name[zh_TW]=
Type=Service
Icon=utilities-desktop-extra
NoDisplay=true
X-KDE-ServiceTypes=Plasma/Applet
X-KDE-PluginInfo-Name=internal:extender
X-KDE-PluginInfo-EnabledByDefault=false

View File

@ -49,8 +49,6 @@
#include "plasma/animator.h"
#include "plasma/containment.h"
#include "plasma/corona.h"
#include "plasma/extenders/extender.h"
#include "plasma/private/extender_p.h"
#include "plasma/framesvg.h"
#include "plasma/theme.h"
#include "plasma/widgets/scrollwidget.h"
@ -141,7 +139,6 @@ void DialogPrivate::checkBorders(bool updateMaskIfNeeded)
const FrameSvg::EnabledBorders currentBorders = background->enabledBorders();
FrameSvg::EnabledBorders borders = FrameSvg::AllBorders;
Extender *extender = qobject_cast<Extender*>(graphicsWidget);
Plasma::Applet *applet = appletPtr.data();
//used to remove borders at the edge of the desktop
@ -246,30 +243,7 @@ void DialogPrivate::checkBorders(bool updateMaskIfNeeded)
}
background->setEnabledBorders(borders);
if (extender) {
FrameSvg::EnabledBorders disabledBorders = FrameSvg::NoBorder;
if (!(borders & FrameSvg::LeftBorder)) {
disabledBorders |= FrameSvg::LeftBorder;
}
if (!(borders & FrameSvg::RightBorder)) {
disabledBorders |= FrameSvg::RightBorder;
}
extender->d->setDisabledBordersHint(disabledBorders);
//if there is a scrollbar, reserve a margin to not draw it over the shadow
qreal left, top, right, bottom;
background->getMargins(left, top, right, bottom);
if (extender->d->scrollWidget->viewportGeometry().height() < extender->d->scrollWidget->contentsSize().height()) {
if (QApplication::layoutDirection() == Qt::RightToLeft) {
leftWidth = left;
} else {
rightWidth = right;
}
}
} else {
background->getMargins(leftWidth, topHeight, rightWidth, bottomHeight);
}
//kDebug() << leftWidth << topHeight << rightWidth << bottomHeight;
q->setContentsMargins(leftWidth, topHeight, rightWidth, bottomHeight);

View File

@ -1,968 +0,0 @@
/*
* Copyright 2008, 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "extender.h"
#include <QAction>
#include <QDesktopWidget>
#include <QLabel>
#include <QGraphicsSceneDragDropEvent>
#include <QGraphicsGridLayout>
#include <QGraphicsLinearLayout>
#include <QPainter>
#include "applet.h"
#include "containment.h"
#include "corona.h"
#include "dialog.h"
#include "extendergroup.h"
#include "extenderitem.h"
#include "framesvg.h"
#include "paintutils.h"
#include "pluginloader.h"
#include "popupapplet.h"
#include "svg.h"
#include "theme.h"
#include "widgets/label.h"
#include "widgets/scrollwidget.h"
#include "private/applet_p.h"
#include "private/applethandle_p.h"
#include "private/extender_p.h"
#include "private/extenderapplet_p.h"
#include "private/extenderitem_p.h"
#include "private/extenderitemmimedata_p.h"
#include "private/popupapplet_p.h"
namespace Plasma
{
Spacer::Spacer(QGraphicsItem *parent)
: QGraphicsWidget(parent)
{
}
Spacer::~Spacer()
{
}
void Spacer::setMargins(qreal left, qreal top, qreal right, qreal bottom)
{
m_left = left;
m_top = top;
m_right = right;
m_bottom = bottom;
}
void Spacer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
painter->setRenderHint(QPainter::Antialiasing);
QPainterPath p = Plasma::PaintUtils::roundedRectangle(
contentsRect().adjusted(m_left, m_top, -m_right, -m_bottom), 4);
QColor c = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
c.setAlphaF(0.3);
painter->fillPath(p, c);
}
Extender::Extender(Applet *applet)
: QGraphicsWidget(applet),
d(new ExtenderPrivate(applet, this))
{
//At multiple places in the extender code, we make the assumption that an applet doesn't have
//more then one extender. If a second extender is created, destroy the first one to avoid leaks.
if (applet->d->extender) {
kWarning() << "Applet already has an extender, and can have only one extender."
<< "The previous extender will be destroyed.";
delete applet->d->extender.data();
} else if (PopupApplet *popup = qobject_cast<PopupApplet *>(applet)) {
if (!popup->d->graphicsWidget) {
// ensure the popup gets a dialog with us as the graphics widget
popup->d->popupConstraintsEvent(SizeConstraint);
}
}
applet->d->extender = this;
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
d->scrollWidget = new ScrollWidget(this);
d->scrollWidget->setOverflowBordersVisible(false);
d->scrollWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
d->mainWidget = new QGraphicsWidget(d->scrollWidget);
d->scrollWidget->setWidget(d->mainWidget);
d->mainWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
connect(d->scrollWidget, SIGNAL(viewportGeometryChanged(const QRectF &)),
this, SLOT(viewportGeometryChanged(const QRectF &)));
d->layout = new QGraphicsLinearLayout(d->mainWidget);
d->layout->setOrientation(Qt::Vertical);
d->layout->setContentsMargins(0, 0, 0, 0);
d->layout->setSpacing(0);
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(Qt::Vertical, this);
lay->addItem(d->scrollWidget);
setContentsMargins(0, 0, 0, 0);
lay->setContentsMargins(0, 0, 0, 0);
d->loadExtenderItems();
setAcceptDrops(true);
}
Extender::~Extender()
{
d->destroying = true;
// when deleting items that are connected to us, it can happen that
// other items which are in groups may get deleted as well. so we first
// build a new list of guarded pointers, and then use that list. that
// way when items are deleted behind our back, we are still safe.
// FIXME: having groups and items in the same collection is probably a mistake,
// so would be a good candidate for a refactoring exercise
QList<QWeakPointer<ExtenderItem> > guardedItems;
foreach (ExtenderItem *item, d->attachedExtenderItems) {
guardedItems << QWeakPointer<ExtenderItem>(item);
}
d->attachedExtenderItems.clear();
foreach (const QWeakPointer<ExtenderItem> &guardedItem, guardedItems) {
ExtenderItem *item = guardedItem.data();
if (item) {
item->disconnect(this);
delete item;
}
}
delete d;
}
void Extender::setEmptyExtenderMessage(const QString &message)
{
d->emptyExtenderMessage = message;
if (d->emptyExtenderLabel) {
d->emptyExtenderLabel->setText(message);
}
}
QString Extender::emptyExtenderMessage() const
{
return d->emptyExtenderMessage;
}
QList<ExtenderItem*> Extender::items() const
{
QList<ExtenderItem*> result;
//FIXME: a triple nested loop ... ew. there should be a more efficient way to do this
//iterate through all extenders we can find and check each extenders source applet.
if (!d->applet) {
return QList<ExtenderItem*>();
}
Containment *containment = d->applet.data()->containment();
if (!containment) {
return result;
}
foreach (Containment *c, containment->corona()->containments()) {
foreach (Applet *applet, c->applets()) {
if (applet->d->extender) {
foreach (ExtenderItem *item, applet->d->extender.data()->d->attachedExtenderItems) {
if (item->d->sourceApplet == d->applet.data()) {
result.append(item);
}
}
}
}
}
return result;
}
QList<ExtenderItem*> Extender::attachedItems() const
{
return d->attachedExtenderItems;
}
QList<ExtenderItem*> Extender::detachedItems() const
{
QList<ExtenderItem*> result;
//FIXME: a triple nested loop ... ew. there should be a more efficient way to do this
//iterate through all extenders we can find and check each extenders source applet.
if (!d->applet) {
return QList<ExtenderItem*>();
}
Containment *containment = d->applet.data()->containment();
if (!containment) {
return result;
}
foreach (Containment *c, containment->corona()->containments()) {
foreach (Applet *applet, c->applets()) {
if (applet->d->extender) {
foreach (ExtenderItem *item, applet->d->extender.data()->attachedItems()) {
if (item->d->sourceApplet == d->applet.data() && item->isDetached()) {
result.append(item);
}
}
}
}
}
return result;
}
ExtenderItem *Extender::item(const QString &name) const
{
// chances are the item is in our own extender, so check there first
foreach (ExtenderItem *item, d->attachedExtenderItems) {
if (item->d->sourceApplet == d->applet.data() && item->name() == name) {
return item;
}
}
// maybe it's been moved elsewhere, so lets search through the entire tree of elements
//FIXME: a triple nested loop ... ew. there should be a more efficient way to do this
//iterate through all extenders we can find and check each extenders source applet.
if (!d->applet) {
return 0;
}
Containment *containment = d->applet.data()->containment();
if (!containment) {
return 0;
}
QList<Containment *> containments;
if (containment->corona()) {
containments = containment->corona()->containments();
} else {
containments << containment;
}
foreach (Containment *c, containments) {
foreach (Applet *applet, c->applets()) {
if (applet->d->extender) {
if (applet->d->extender.data() == this) {
// skip it, we checked it already
continue;
}
if (!applet->d->extender) {
continue;
}
foreach (ExtenderItem *item, applet->d->extender.data()->attachedItems()) {
if (item->d->sourceApplet == d->applet.data() && item->name() == name) {
return item;
}
}
}
}
}
return 0;
}
ExtenderGroup *Extender::group(const QString &name) const
{
return qobject_cast<ExtenderGroup*>(item(name));
}
bool Extender::hasItem(const QString &name) const
{
if (item(name)) {
return true;
}
if (!d->applet) {
return false;
}
//if item(name) returns false, that doesn't mean that the item doesn't exist, just that it has
//not been instantiated yet. check to see if there's mention of this item existing in the
//plasma config's section DetachedExtenderItems
Corona *corona = qobject_cast<Corona *>(scene());
if (!corona) {
return false;
}
KConfigGroup extenderItemGroup(corona->config(), "DetachedExtenderItems");
foreach (const QString &extenderItemId, extenderItemGroup.groupList()) {
KConfigGroup cg = extenderItemGroup.group(extenderItemId);
if (uint(cg.readEntry("sourceAppletId", 0)) == d->applet.data()->id() &&
cg.readEntry("extenderItemName", "") == name &&
cg.readEntry("sourceAppletPluginName", "") == d->applet.data()->pluginName()) {
return true;
}
}
return false;
}
void Extender::setAppearance(Appearance appearance)
{
if (d->appearance == appearance) {
return;
}
d->appearance = appearance;
d->updateBorders();
}
Extender::Appearance Extender::appearance() const
{
return d->appearance;
}
QList<ExtenderGroup*> Extender::groups() const
{
QList<ExtenderGroup *> result;
foreach (ExtenderItem *item, d->attachedExtenderItems) {
if (item->isGroup() && !result.contains(item->group())) {
ExtenderGroup *group = qobject_cast<ExtenderGroup *>(item);
if (group) {
result.append(group);
}
}
}
return result;
}
Applet *Extender::applet() const
{
return d->applet.data();
}
void Extender::saveState()
{
foreach (ExtenderItem *item, attachedItems()) {
item->config().writeEntry("extenderItemPosition", item->geometry().y());
}
}
QVariant Extender::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemPositionHasChanged) {
emit geometryChanged();
}
return QGraphicsWidget::itemChange(change, value);
}
void Extender::resizeEvent(QGraphicsSceneResizeEvent *event)
{
QGraphicsWidget::resizeEvent(event);
emit geometryChanged();
}
void Extender::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_UNUSED(event)
if (!d->applet) {
return;
}
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(d->applet.data());
if (isEmpty() && popupApplet) {
popupApplet->hidePopup();
}
}
void Extender::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
event->accept();
const ExtenderItemMimeData *mimeData =
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
if (mimeData) {
itemHoverEnterEvent(mimeData->extenderItem());
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(d->applet.data());
if (popupApplet) {
popupApplet->showPopup();
}
}
}
}
void Extender::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
const ExtenderItemMimeData *mimeData =
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
if (mimeData) {
itemHoverMoveEvent(mimeData->extenderItem(), event->pos());
d->setPositionFromDragPosition(event->scenePos());
}
}
}
void Extender::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
const ExtenderItemMimeData *mimeData =
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
if (mimeData) {
itemHoverLeaveEvent(mimeData->extenderItem());
//Some logic to conveniently show/hide popups or applets when logical.
Extender *sourceExtender = mimeData->extenderItem()->d->extender;
//Hide popups when they're not the extender where we started, and we're leaving the
//extender. Use a small timeout here, to avoid accidental hides of extenders we're
//targetting.
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(d->applet.data());
if (popupApplet && sourceExtender != this) {
#ifndef NDEBUG
kDebug() << "leaving another extender then the extender we started, so hide the popup.";
#endif
popupApplet->showPopup(250);
}
//Hide popups when we drag the last item away.
if (popupApplet && sourceExtender == this && (attachedItems().count() < 2)) {
#ifndef NDEBUG
kDebug() << "leaving the extender, and there are no more attached items so hide the popup.";
#endif
popupApplet->hidePopup();
}
//Hide empty internal extender containers when we drag the last item away. Avoids having
//an ugly empty applet on the desktop temporarily.
ExtenderApplet *extenderApplet = qobject_cast<ExtenderApplet*>(d->applet.data());
if (extenderApplet && sourceExtender == this && attachedItems().count() < 2 &&
extenderApplet->formFactor() != Plasma::Horizontal &&
extenderApplet->formFactor() != Plasma::Vertical) {
#ifndef NDEBUG
kDebug() << "leaving the internal extender container, so hide the applet and it's handle.";
#endif
extenderApplet->hide();
AppletHandle *handle = dynamic_cast<AppletHandle*>(extenderApplet->parentItem());
if (handle) {
handle->hide();
}
}
}
}
}
void Extender::dropEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
const ExtenderItemMimeData *mimeData =
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
if (mimeData) {
mimeData->extenderItem()->setExtender(this, event->pos());
QApplication::restoreOverrideCursor();
itemHoverLeaveEvent(0);
}
}
}
void Extender::itemAddedEvent(ExtenderItem *item, const QPointF &pos)
{
ExtenderGroup *group = item->isGroup() ? static_cast<ExtenderGroup*>(item) : 0;
if (group && group->autoHide() && group->items().isEmpty()) {
return;
}
if (!item->group()) {
if (pos == QPointF(-1, -1)) {
//if it was already there, reposition
d->layout->removeItem(item);
//if just plain adding an item, add it at a sane position:
if (appearance() == BottomUpStacked) {
//at the top
d->layout->insertItem(0, item);
} else {
//at the bottom
d->layout->addItem(item);
}
} else {
#ifndef NDEBUG
kDebug() << "inserting at" << pos << d->insertIndexFromPos(pos) << item->size();
#endif
d->layout->insertItem(d->insertIndexFromPos(pos), item);
#ifndef NDEBUG
kDebug() << item->size();
#endif
}
}
d->adjustMinimumSize();
//remove the empty extender message if needed.
d->updateEmptyExtenderLabel();
d->updateBorders();
d->adjustSize();
}
void Extender::itemRemovedEvent(ExtenderItem *item)
{
if (d->destroying) {
return;
}
d->layout->removeItem(item);
if (d->spacerWidget) {
d->layout->removeItem(d->spacerWidget);
delete d->spacerWidget;
d->spacerWidget = 0;
}
d->adjustMinimumSize();
//add the empty extender message if needed.
d->updateEmptyExtenderLabel();
d->updateBorders();
d->layout->updateGeometry();
static_cast<QGraphicsLayoutItem *>(d->scrollWidget)->updateGeometry();
updateGeometry();
d->adjustSize();
}
void Extender::itemHoverEnterEvent(ExtenderItem *item)
{
itemHoverMoveEvent(item, QPointF(0, 0));
}
void Extender::itemHoverMoveEvent(ExtenderItem *item, const QPointF &pos)
{
if (d->spacerWidget && d->spacerWidget->geometry().contains(pos)) {
return;
}
//Make sure we remove any spacer that might already be in the layout.
if (d->spacerWidget) {
d->layout->removeItem(d->spacerWidget);
}
int insertIndex = d->insertIndexFromPos(pos);
//Create a widget that functions as spacer, and add that to the layout.
if (!d->spacerWidget) {
Spacer *widget = new Spacer(this);
qreal left, top, right, bottom;
d->background->getMargins(left, top, right, bottom);
widget->setMargins(left, 4, right, 4);
widget->setMinimumSize(item->minimumSize());
widget->setPreferredSize(item->preferredSize());
widget->setMaximumSize(item->maximumSize());
widget->setSizePolicy(item->sizePolicy());
d->spacerWidget = widget;
}
d->layout->insertItem(insertIndex, d->spacerWidget);
//Make sure we remove any 'no detachables' label that might be there, and update the layout.
d->updateEmptyExtenderLabel();
}
void Extender::itemHoverLeaveEvent(ExtenderItem *item)
{
Q_UNUSED(item);
if (d->spacerWidget) {
//Remove any trace of the spacer widget.
d->layout->removeItem(d->spacerWidget);
delete d->spacerWidget;
d->spacerWidget = 0;
d->currentSpacerIndex = -1;
d->updateEmptyExtenderLabel();
}
}
FrameSvg::EnabledBorders Extender::enabledBordersForItem(ExtenderItem *item) const
{
if (d->layout->count() < 1) {
return 0;
}
ExtenderItem *topItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(0));
ExtenderItem *bottomItem = dynamic_cast<ExtenderItem*>(d->layout->itemAt(d->layout->count() - 1));
FrameSvg::EnabledBorders borders = FrameSvg::NoBorder;
if (item->group()) {
return FrameSvg::NoBorder;
} else if (d->appearance == TopDownStacked && bottomItem != item) {
borders = FrameSvg::LeftBorder | FrameSvg::BottomBorder | FrameSvg::RightBorder;
} else if (d->appearance == BottomUpStacked && topItem != item) {
borders = FrameSvg::LeftBorder | FrameSvg::TopBorder | FrameSvg::RightBorder;
} else if (d->appearance != NoBorders) {
borders = FrameSvg::LeftBorder | FrameSvg::RightBorder;
} else {
return FrameSvg::NoBorder;
}
if (d->scrollWidget->viewportGeometry().height() < d->mainWidget->boundingRect().height()) {
if (QApplication::layoutDirection() == Qt::RightToLeft) {
borders &= ~FrameSvg::LeftBorder;
} else {
borders &= ~FrameSvg::RightBorder;
}
}
//someone (i.e. a Dialog) told the extender to disable some border?
borders &= ~d->disabledBordersHint;
return borders;
}
ExtenderPrivate::ExtenderPrivate(Applet *applet, Extender *extender) :
q(extender),
applet(applet),
background(new FrameSvg(extender)),
disabledBordersHint(FrameSvg::NoBorder),
currentSpacerIndex(-1),
spacerWidget(0),
emptyExtenderMessage(QString()),
emptyExtenderLabel(0),
appearance(Extender::NoBorders),
destroying(false),
scrollbarVisible(false)
{
background->setImagePath("widgets/extender-background");
}
ExtenderPrivate::~ExtenderPrivate()
{
}
void ExtenderPrivate::addExtenderItem(ExtenderItem *item, const QPointF &pos)
{
if (attachedExtenderItems.contains(item)) {
pendingItems.remove(item);
q->itemAddedEvent(item, pos);
return;
}
QObject::connect(item, SIGNAL(destroyed(Plasma::ExtenderItem*)), q, SLOT(extenderItemDestroyed(Plasma::ExtenderItem*)));
attachedExtenderItems.append(item);
q->itemHoverLeaveEvent(item);
pendingItems.insert(item, pos);
QTimer::singleShot(0, q, SLOT(delayItemAddedEvent()));
}
void ExtenderPrivate::removeExtenderItem(ExtenderItem *item)
{
attachedExtenderItems.removeAll(item);
pendingItems.remove(item);
//collapse the popupapplet if the last item is removed.
if (attachedExtenderItems.isEmpty()) {
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(applet.data());
if (popupApplet) {
popupApplet->hidePopup();
}
}
q->itemRemovedEvent(item);
}
int ExtenderPrivate::insertIndexFromPos(const QPointF &pos) const
{
int insertIndex = -1;
//XXX: duplicated from panel
if (pos != QPointF(-1, -1)) {
for (int i = 0; i < layout->count(); ++i) {
QRectF siblingGeometry = layout->itemAt(i)->geometry();
qreal middle = (siblingGeometry.top() + siblingGeometry.bottom()) / 2.0;
if (pos.y() < middle) {
insertIndex = i;
break;
} else if (pos.y() <= siblingGeometry.bottom()) {
insertIndex = i + 1;
break;
}
}
}
return insertIndex;
}
void ExtenderPrivate::loadExtenderItems()
{
if (!applet) {
return;
}
KConfigGroup cg = applet.data()->config("ExtenderItems");
//first create a list of extenderItems, and then sort them on their position, so the items get
//recreated in the correct order.
QList<QPair<int, QString> > groupList;
foreach (const QString &extenderItemId, cg.groupList()) {
KConfigGroup dg = cg.group(extenderItemId);
groupList.append(qMakePair(dg.readEntry("extenderItemPosition", 0), extenderItemId));
}
qSort(groupList);
//iterate over the extender items
for (int i = 0; i < groupList.count(); i++) {
QPair<int, QString> pair = groupList[i];
KConfigGroup dg = cg.group(pair.second);
//load the relevant settings.
QString extenderItemId = dg.name();
QString extenderItemName = dg.readEntry("extenderItemName", "");
QString appletName = dg.readEntry("sourceAppletPluginName", "");
uint sourceAppletId = dg.readEntry("sourceAppletId", 0);
bool temporarySourceApplet = false;
#ifndef NDEBUG
kDebug() << "applet id = " << applet.data()->id();
#endif
#ifndef NDEBUG
kDebug() << "sourceappletid = " << sourceAppletId;
#endif
//find the source applet.
Applet *sourceApplet = 0;
if (applet.data()->id() == sourceAppletId) {
// it's ours!
sourceApplet = applet.data();
} else {
// maybe it's foreign?
Containment *containment = applet.data()->containment();
if (containment) {
Corona *corona = containment->corona();
if (sourceAppletId == q->applet()->id()) {
sourceApplet = q->applet();
} else {
foreach (Containment *containment, corona->containments()) {
foreach (Applet *applet, containment->applets()) {
if (applet->id() == sourceAppletId) {
sourceApplet = applet;
}
}
}
}
}
}
//There is no source applet. We just instantiate one just for the sake of creating
//detachables.
if (!sourceApplet) {
#ifndef NDEBUG
kDebug() << "creating a temporary applet as factory";
#endif
sourceApplet = PluginLoader::self()->loadApplet(appletName);
temporarySourceApplet = true;
//TODO: maybe add an option to applet to indicate that it shouldn't be deleted after
//having used it as factory.
}
if (!sourceApplet) {
#ifndef NDEBUG
kDebug() << "sourceApplet is null? appletName = " << appletName;
#endif
#ifndef NDEBUG
kDebug() << " extenderItemId = " << extenderItemId;
#endif
} else {
ExtenderItem *item;
if (dg.readEntry("isGroup", false)) {
item = new ExtenderGroup(q, extenderItemId.toInt());
} else {
item = new ExtenderItem(q, extenderItemId.toInt());
}
sourceApplet->initExtenderItem(item);
item->d->sourceApplet = sourceApplet;
if (temporarySourceApplet) {
delete sourceApplet;
}
}
}
}
void ExtenderPrivate::updateBorders()
{
foreach (ExtenderItem *item, attachedExtenderItems) {
if (item && (item->d->background->enabledBorders() != q->enabledBordersForItem(item))) {
//call themeChanged to change the backgrounds enabled borders, and move all contained
//widgets according to it's changed margins.
item->d->themeChanged();
}
}
}
void ExtenderPrivate::delayItemAddedEvent()
{
QHash<Plasma::ExtenderItem *, QPointF>::const_iterator i = pendingItems.constBegin();
while (i != pendingItems.constEnd()) {
q->itemAddedEvent(i.key(), i.value());
++i;
}
pendingItems.clear();
}
void ExtenderPrivate::updateEmptyExtenderLabel()
{
if (q->isEmpty() && !emptyExtenderLabel &&
!emptyExtenderMessage.isEmpty() && !spacerWidget ) {
//add the empty extender label.
emptyExtenderLabel = new Label(q);
emptyExtenderLabel->setAlignment(Qt::AlignCenter);
emptyExtenderLabel->setText(emptyExtenderMessage);
qreal left, top, right, bottom;
background->getMargins(left, top, right, bottom);
emptyExtenderLabel->nativeWidget()->setMargin(left + right);
emptyExtenderLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
layout->addItem(emptyExtenderLabel);
} else if (!q->isEmpty() && emptyExtenderLabel) {
//remove the empty extender label.
layout->removeItem(emptyExtenderLabel);
delete emptyExtenderLabel;
emptyExtenderLabel = 0;
}
}
void ExtenderPrivate::adjustMinimumSize()
{
//FIXME: hardcoded number for the scrollbar
scrollWidget->setMinimumWidth(mainWidget->effectiveSizeHint(Qt::MinimumSize).width() + 32);
//FIXME: hardcoded number
scrollWidget->setMinimumHeight(qMin((qreal)300, mainWidget->effectiveSizeHint(Qt::MinimumSize).height()));
}
void ExtenderPrivate::setPositionFromDragPosition(const QPointF &pos)
{
const qreal ratio = (q->mapFromScene(pos).y()/scrollWidget->size().height());
mainWidget->setPos(mainWidget->pos().x(), 30 + (ratio *(scrollWidget->size().height() - mainWidget->size().height() - 30)));
}
ExtenderGroup *ExtenderPrivate::findGroup(const QString &name) const
{
foreach (ExtenderItem *item, attachedExtenderItems) {
if (item->isGroup() && item->name() == name) {
return qobject_cast<ExtenderGroup*>(item);
}
}
return 0;
}
void ExtenderPrivate::extenderItemDestroyed(Plasma::ExtenderItem *item)
{
pendingItems.remove(item);
if (attachedExtenderItems.contains(item)) {
// removeExtenderItem also removes the item from attachedExtenderItems
removeExtenderItem(item);
}
}
void ExtenderPrivate::viewportGeometryChanged(const QRectF &rect)
{
if (appearance != Extender::TopDownStacked && appearance != Extender::BottomUpStacked) {
scrollbarVisible = (rect.height() > mainWidget->boundingRect().height());
return;
}
bool scroll = !(rect.height() >= mainWidget->boundingRect().height());
if (scroll != scrollbarVisible) {
scrollbarVisible = scroll;
updateBorders();
}
}
void ExtenderPrivate::setDisabledBordersHint(const FrameSvg::EnabledBorders borders)
{
if (disabledBordersHint == borders) {
return;
}
disabledBordersHint = borders;
foreach (Plasma::ExtenderItem *item, attachedExtenderItems) {
item->d->themeChanged();
}
}
void ExtenderPrivate::adjustSize()
{
QRect screenRect;
QSizeF size = mainWidget->effectiveSizeHint(Qt::PreferredSize);
if (applet) {
Containment *containment = applet.data()->containment();
if (containment && containment->corona()) {
screenRect = containment->corona()->screenGeometry(containment->screen());
}
}
q->resize(qMin(screenRect.width()/3, (int)size.width()),
qMin(screenRect.height()/3, (int)size.height()));
}
bool Extender::isEmpty() const
{
//It's empty if it doesn't have items or has only group that are empty and autohide
foreach (ExtenderItem *item, d->attachedExtenderItems) {
if (!item->isGroup()) {
return false;
} else {
//a static_cast here should be safe, it's not the case apparently
ExtenderGroup *group = qobject_cast<ExtenderGroup *>(item);
if (group && (!group->autoHide() || group->items().size() > 0)) {
return false;
}
}
}
return true;
}
} // Plasma namespace
#include "extender.moc"

View File

@ -1,324 +0,0 @@
/*
* Copyright 2008, 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef PLASMA_EXTENDER_H
#define PLASMA_EXTENDER_H
#include <QtGui/QGraphicsWidget>
#include "plasma/framesvg.h"
#include "plasma/plasma_export.h"
namespace Plasma
{
class ExtenderGroup;
class ExtenderPrivate;
class ExtenderItem;
class Applet;
/**
* @class Extender plasma/extender.h <Plasma/Extender>
*
* @short Extends applets to allow detachable parts
*
* An Extender is a widget that visually extends the normal contents of an applet with
* additional dynamic widgets called ExtenderItems. These ExtenderItems can be
* detached by the user and dropped either on another Extender or on the canvas directly.
*
* This widget allows using ExtenderItems in your applet. Extender takes care of the presentation
* of a collection of ExtenderItems and keeps track of ExtenderItems that originate in it.
*
* The default Extender implementation displays extender items in a vertical layout with
* spacers that appear when dropping an ExtenderItem over it.
*
* If you wish to have a different presentation of extender items, you can choose to subclass
* Extender and reimplement the extenderItem* events and, optionally, the saveState function.
*
* To use an Extender in you applet, you'll have to instantiate one. A call to extender() in your
* applet will create an extender on your applet if you haven't got one already. Every applet can
* contain only one extender. Think of it as a decorator that adds some functionality to applets
* that require it. Never instantiate an Extender before init() in your applet. This won't work
* correctly since a scene is required when an Extender is instantiated.
*
* As soon as an Extender is instantiated, ExtenderItems contained previously in this Extender are
* restored using the initExtenderItem function from the applet the items originally came from. For
* more information on how this works and how to use ExtenderItems in general, see the ExtenderItem
* API documentation.
*/
class PLASMA_EXPORT Extender : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(QString emptyExtenderMessage READ emptyExtenderMessage WRITE setEmptyExtenderMessage)
Q_PROPERTY(QList<ExtenderItem*> items READ items())
Q_PROPERTY(QList<ExtenderItem*> attachedItems READ attachedItems())
Q_PROPERTY(QList<ExtenderItem*> detachedItems READ detachedItems())
Q_PROPERTY(QList<ExtenderGroup*> groups READ groups())
Q_PROPERTY(bool empty READ isEmpty())
public:
/**
* Description on how to render the extender's items.
*/
enum Appearance {
NoBorders = 0, /**< Draws no borders on the extender's items. When placed in an applet
on the desktop, use this setting and use the standard margins of
the applet containing this extender. */
BottomUpStacked = 1, /**< Draws no borders on the topmost extenderitem, but draws the
left, top and right border on subsequent items. When margins
of the containing dialog are set to 0, except for the top
margin, this leads to the 'stacked' look, recommended for
extenders of applet's contained in a panel at the bottom of
the screen. */
TopDownStacked = 2 /**< Draws no borders on the bottom extenderitem, but draws the
left, bottom and right border on subsequent items. When margins
of the containing dialog are set to 0, except for the bottom
margin, this leads to the 'stacked' look, recommended for
extenders of applet's contained in a panel at the top of
the screen. */
};
/**
* Creates an extender. Note that extender expects applet to have a config(), and needs a
* scene because of that. So you should only instantiate an extender in init() or later, not
* in an applet's constructor.
* The constructor also takes care of restoring ExtenderItems that were contained in this
* extender before, so ExtenderItems are persistent between sessions.
* Note that a call to extender() in an applet will instantiate an Extender for you if one
* isn't already associated with your applet.
* @param applet The applet this extender is part of. Null is not allowed here.
*/
explicit Extender(Applet *applet);
~Extender();
/**
* @param message The text to be shown whenever the applet's extender is empty.
*/
void setEmptyExtenderMessage(const QString &message);
/**
* @return The text to be shown whenever the applet's layout is empty.
*/
QString emptyExtenderMessage() const;
/**
* @returns a list of all extender items (attached AND detached) where the source applet is
* this applet.
*/
QList<ExtenderItem*> items() const;
/**
* @returns a list of all attached extender items.
*/
QList<ExtenderItem*> attachedItems() const;
/**
* @returns a list of all detached extender items.
*/
QList<ExtenderItem*> detachedItems() const;
/**
* This function can be used for obtaining the extender item specified by name. For checking
* whether or not an item already exists, you should use hasItem instead: while plasma is
* starting up, not all detached items might have been instantiated yet. hasItem returns true
* even if the requested item isn't instantiated yet.
* @returns the requested item
*/
Q_INVOKABLE ExtenderItem *item(const QString &name) const;
/**
* Extra convenience function for obtaining groups specified by name. This will avoid needed
* to call item and casting to ExtenderGroup, which is otherwise quite common.
* @returns the requested group
* @since 4.3
*/
Q_INVOKABLE ExtenderGroup *group(const QString &name) const;
/**
* This function can be used for easily determining if a certain item is already displayed
* in an extender item somewhere, so your applet doesn't duplicate this item. This is needed
* because ExtenderItems are persistent, so you can't blindly add new extender items in all
* cases.
* @returns whether or not this item already exists.
* @since 4.3
*/
Q_INVOKABLE bool hasItem(const QString &name) const;
/**
* @return true if the Extender is visually empty (though it may have items such as
* empty groups or detached items associatd with it)
*/
bool isEmpty() const;
/**
* Use this function to instruct the extender on how to render its items. Usually you will
* want to call this function in your applet's constraintsEvent, allthough this is already
* done for you when using PopupApplet as base class for your applet. Defaults to NoBorders.
* @param appearance the way this extender should look.
*/
void setAppearance(Appearance appearance);
/**
* @returns the current way of rendering extender items that is used.
*/
Appearance appearance() const;
/**
* @returns a list of groups that are contained in this extender.
* @since 4.3
*/
QList<ExtenderGroup*> groups() const;
/**
* @returns the Applet this Extender is associated with
* @since 4.4
*/
Applet *applet() const;
protected:
/**
* Get's called after an item has been added to this extender. The bookkeeping has already
* been done when this function get's called. The only thing left to do is put it somewhere
* appropriate. The default implementation adds the extenderItem to the appropriate place in
* a QGraphicsLinearLayout.
* @param item The item that has just been added.
* @param pos The location the item has been dropped in local coordinates.
*/
virtual void itemAddedEvent(ExtenderItem *item, const QPointF &pos = QPointF(-1, -1));
/**
* Get's called after an item has been removed from this extender. All bookkeeping has
* already been done when this function get's called.
* @param item The item that has just been removed.
*/
virtual void itemRemovedEvent(ExtenderItem *item);
/**
* Get's called when an ExtenderItem that get's dragged enters this extender. Default
* implementation does nothing.
*/
virtual void itemHoverEnterEvent(ExtenderItem *item);
/**
* Gets called when an ExtenderItem is hovering over this extender. Implement this function
* to give some visual feedback about what will happen when the mouse button is released at
* that position. The default implementation shows a spacer at the appropriate location in
* the layout.
* @param item The item that's hovering over this extender. Most useful for obtaining the
* size of the spacer.
* @param pos The location the item is hovering.
*/
virtual void itemHoverMoveEvent(ExtenderItem *item, const QPointF &pos);
/**
* Get's called when an ExtenderItem that was previously hovering over this extender moves
* away from this extender. The default implementation removes any spacer from the layout.
*/
virtual void itemHoverLeaveEvent(ExtenderItem *item);
/**
* This function get's called for every extender when plasma exits. Implement this function
* to store the current state of this extender (position in a layout for example), so this
* can be restored when applet starts again. The default implementation stores the y
* coordinate of every extender item in the config field extenderItemPos.
*/
virtual void saveState();
/**
* This function get's called on every item to determine which background border's to
* render.
* @param item the item for which its position or extender has changed.
* @return the borders that have to be enabled on its background.
*/
virtual FrameSvg::EnabledBorders enabledBordersForItem(ExtenderItem *item) const;
/**
* Reimplemented from QGraphicsWidget
*/
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/**
* Reimplemented from QGraphicsWidget
*/
void resizeEvent(QGraphicsSceneResizeEvent *event);
/**
* Reimplemented from QGraphicsWidget
*/
void mousePressEvent(QGraphicsSceneMouseEvent *event);
/**
* Reimplemented from QGraphicsWidget
*/
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
/**
* Reimplemented from QGraphicsWidget
*/
void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
/**
* Reimplemented from QGraphicsWidget
*/
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
/**
* Reimplemented from QGraphicsWidget
*/
void dropEvent(QGraphicsSceneDragDropEvent *event);
Q_SIGNALS:
/**
* Fires when an extender item is added to this extender.
*/
void itemAttached(Plasma::ExtenderItem *);
/**
* Fires when an extender item is removed from this extender.
*/
void itemDetached(Plasma::ExtenderItem *);
/**
* Fires when an extender's preferred size changes.
*/
void geometryChanged();
private:
ExtenderPrivate *const d;
Q_PRIVATE_SLOT(d, void delayItemAddedEvent())
Q_PRIVATE_SLOT(d, void extenderItemDestroyed(Plasma::ExtenderItem *item))
Q_PRIVATE_SLOT(d, void viewportGeometryChanged(const QRectF &))
friend class ExtenderPrivate;
friend class ExtenderGroup;
friend class ExtenderGroupPrivate;
friend class ExtenderItem;
friend class ExtenderItemPrivate;
//dialog needs access to the extender's applet location.
friend class DialogPrivate;
//applet should be able to call saveState();
friend class Applet;
};
} // Plasma namespace
#endif //PLASMA_EXTENDER_H

View File

@ -1,401 +0,0 @@
/*
* Copyright 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "extendergroup.h"
#include <QAction>
#include <QApplication>
#include <QString>
#include <QList>
#include <QTimer>
#include <QtGui/QGraphicsWidget>
#include <QtGui/QGraphicsLinearLayout>
#include <QtGui/QGraphicsSceneDragDropEvent>
#include "applet.h"
#include "extender.h"
#include "extenderitem.h"
#include "theme.h"
#include "widgets/scrollwidget.h"
#include "private/extender_p.h"
#include "private/extendergroup_p.h"
#include "private/extenderitemmimedata_p.h"
namespace Plasma
{
ExtenderGroup::ExtenderGroup(Extender *parent, uint groupId)
: ExtenderItem(parent, groupId),
d(new ExtenderGroupPrivate(this))
{
connect(extender(), SIGNAL(itemAttached(Plasma::ExtenderItem*)),
this, SLOT(addItemToGroup(Plasma::ExtenderItem*)));
connect(extender(), SIGNAL(itemDetached(Plasma::ExtenderItem*)),
this, SLOT(removeItemFromGroup(Plasma::ExtenderItem*)));
//this isn't actually connected to anything, we will just check if it's running or not
d->resizeTimer = new QTimer(this);
d->resizeTimer->setSingleShot(true);
config().writeEntry("isGroup", true);
setAcceptDrops(true);
QGraphicsLinearLayout *lay = static_cast<QGraphicsLinearLayout *>(layout());
d->childsWidget = new QGraphicsWidget(this);
d->childsWidget->installEventFilter(this);
d->layout = new QGraphicsLinearLayout(Qt::Vertical, d->childsWidget);
d->childsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
lay->addItem(d->childsWidget);
QAction *expand = new QAction(this);
expand->setVisible(false);
expand->setToolTip(i18n("Show this group."));
connect(expand, SIGNAL(triggered()), this, SLOT(expandGroup()));
addAction("expand", expand);
QAction *collapse = new QAction(this);
collapse->setVisible(true);
collapse->setToolTip(i18n("Hide this group."));
connect(collapse, SIGNAL(triggered()), this, SLOT(collapseGroup()));
addAction("collapse", collapse);
d->themeChanged();
QString groupName;
foreach (ExtenderItem *item, extender()->attachedItems()) {
groupName = item->config().readEntry("group", "");
if (!groupName.isEmpty() && groupName == name()) {
item->setGroup(this);
}
}
if (items().isEmpty() && d->autoHide && !isDetached()) {
extender()->itemRemovedEvent(this);
hide();
}
if (!config().readEntry("groupCollapsed", true)) {
expandGroup();
}
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
this, SLOT(themeChanged()));
}
ExtenderGroup::~ExtenderGroup()
{
delete d;
}
QList<ExtenderItem*> ExtenderGroup::items() const
{
QList<ExtenderItem*> result;
foreach (ExtenderItem *item, extender()->attachedItems()) {
if (item->group() == this) {
result.append(item);
}
}
return result;
}
bool ExtenderGroup::autoHide() const
{
return d->autoHide;
}
void ExtenderGroup::setAutoHide(bool autoHide)
{
d->autoHide = autoHide;
if (autoHide && items().isEmpty()) {
extender()->itemRemovedEvent(this);
hide();
} else if (!autoHide && !isVisible()) {
extender()->itemAddedEvent(this);
show();
}
}
bool ExtenderGroup::isAutoCollapse() const
{
return d->autoCollapse;
}
void ExtenderGroup::setAutoCollapse(bool collapse)
{
d->autoCollapse = collapse;
}
bool ExtenderGroup::isGroupCollapsed() const
{
return d->collapsed;
}
void ExtenderGroup::setGroupCollapsed(bool collapsed)
{
if (collapsed) {
collapseGroup();
} else {
expandGroup();
}
}
void ExtenderGroup::expandGroup()
{
if (d->autoCollapse) {
setCollapsed(false);
}
if (d->collapsed == false) {
return;
}
d->collapsed = false;
config().writeEntry("groupCollapsed", d->collapsed);
action("collapse")->setVisible(true);
action("expand")->setVisible(false);
d->childsWidget->show();
static_cast<QGraphicsLinearLayout *>(layout())->addItem(d->childsWidget);
updateGeometry();
foreach (ExtenderItem *item, extender()->attachedItems()) {
if (item->group() == this) {
item->show();
extender()->itemAddedEvent(item);
}
}
//extender()->resize(extender()->effectiveSizeHint(Qt::PreferredSize));
}
void ExtenderGroup::collapseGroup()
{
if (d->autoCollapse) {
setCollapsed(true);
}
if (d->collapsed == true) {
return;
}
d->collapsed = true;
config().writeEntry("groupCollapsed", d->collapsed);
action("collapse")->setVisible(false);
action("expand")->setVisible(true);
d->childsWidget->hide();
static_cast<QGraphicsLinearLayout *>(layout())->removeItem(d->childsWidget);
updateGeometry();
foreach (ExtenderItem *item, extender()->attachedItems()) {
if (item != this && item->group() == this) {
item->hide();
extender()->itemRemovedEvent(item);
}
}
}
void ExtenderGroup::resizeEvent(QGraphicsSceneResizeEvent *event)
{
ExtenderItem::resizeEvent(event);
}
bool ExtenderGroup::eventFilter(QObject *watched, QEvent *event)
{
if (watched == d->childsWidget && event->type() == QEvent::GraphicsSceneResize) {
static_cast<QGraphicsLayoutItem *>(extender()->d->scrollWidget)->updateGeometry();
if (!d->resizeTimer->isActive()) {
static_cast<QGraphicsLayoutItem *>(extender())->updateGeometry();
extender()->d->adjustSize();
d->resizeTimer->start(0);
}
}
return ExtenderItem::eventFilter(watched, event);
}
void ExtenderGroup::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
event->accept();
dragMoveEvent(event);
}
}
void ExtenderGroup::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
const ExtenderItemMimeData *mimeData =
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
if (mimeData) {
QPointF pos(event->pos());
if (d->spacerWidget && d->spacerWidget->geometry().contains(pos)) {
return;
}
//Make sure we remove any spacer that might already be in the layout.
if (d->spacerWidget) {
d->layout->removeItem(d->spacerWidget);
}
int insertIndex = d->insertIndexFromPos(pos);
//Create a widget that functions as spacer, and add that to the layout.
if (!d->spacerWidget) {
Spacer *widget = new Spacer(this);
ExtenderItem *item = mimeData->extenderItem();
qreal left, top, right, bottom;
extender()->d->background->getMargins(left, top, right, bottom);
widget->setMargins(left, 4, right, 4);
widget->setMinimumSize(item->minimumSize());
widget->setPreferredSize(item->preferredSize());
widget->setMaximumSize(item->maximumSize());
widget->setSizePolicy(item->sizePolicy());
d->spacerWidget = widget;
}
d->layout->insertItem(insertIndex, d->spacerWidget);
extender()->d->setPositionFromDragPosition(event->scenePos());
}
}
}
void ExtenderGroup::dropEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
const ExtenderItemMimeData *mimeData =
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
if (mimeData) {
mimeData->extenderItem()->setGroup(this, event->pos());
QApplication::restoreOverrideCursor();
d->layout->removeItem(d->spacerWidget);
d->spacerWidget->deleteLater();
d->spacerWidget = 0;
}
}
}
void ExtenderGroup::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
if (d->spacerWidget) {
d->layout->removeItem(d->spacerWidget);
d->spacerWidget->deleteLater();
d->spacerWidget = 0;
}
}
}
ExtenderGroupPrivate::ExtenderGroupPrivate(ExtenderGroup *group)
: q(group),
spacerWidget(0),
svg(new Svg(group)),
collapsed(false),
autoHide(true),
autoCollapse(false)
{
}
ExtenderGroupPrivate::~ExtenderGroupPrivate()
{
}
void ExtenderGroupPrivate::addItemToGroup(Plasma::ExtenderItem *item, const QPointF &pos)
{
if (item->group() == q) {
item->setParentItem(childsWidget);
item->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
layout->insertItem(insertIndexFromPos(pos), item);
layout->activate();
if (!q->isVisible() && !q->items().isEmpty()) {
q->extender()->itemAddedEvent(q);
q->show();
}
childsWidget->setVisible(!q->isGroupCollapsed());
if (!q->isGroupCollapsed()) {
layout->updateGeometry();
static_cast<QGraphicsLayoutItem *>(q)->updateGeometry();
static_cast<QGraphicsLayoutItem *>(childsWidget)->updateGeometry();
static_cast<QGraphicsLayoutItem *>(q->extender()->d->scrollWidget)->updateGeometry();
}
q->extender()->d->adjustSize();
}
}
void ExtenderGroupPrivate::removeItemFromGroup(Plasma::ExtenderItem *item)
{
if (item->group() == q) {
if (q->items().isEmpty() && autoHide && !q->isDetached()) {
q->extender()->itemRemovedEvent(q);
q->hide();
}
layout->removeItem(item);
item->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
layout->updateGeometry();
static_cast<QGraphicsLayoutItem *>(q)->updateGeometry();
static_cast<QGraphicsLayoutItem *>(childsWidget)->updateGeometry();
static_cast<QGraphicsLayoutItem *>(q->extender()->d->scrollWidget)->updateGeometry();
q->extender()->d->adjustSize();
}
}
void ExtenderGroupPrivate::themeChanged()
{
svg->setImagePath("widgets/configuration-icons");
svg->resize();
q->action("expand")->setIcon(QIcon(svg->pixmap("restore")));
q->action("collapse")->setIcon(QIcon(svg->pixmap("collapse")));
}
int ExtenderGroupPrivate::insertIndexFromPos(const QPointF &pos) const
{
int insertIndex = -1;
if (pos != QPointF(-1, -1)) {
for (int i = 0; i < layout->count(); ++i) {
QRectF siblingGeometry = layout->itemAt(i)->geometry();
qreal middle = (siblingGeometry.top() + siblingGeometry.bottom()) / 2.0;
if (pos.y() < middle) {
insertIndex = i;
break;
} else if (pos.y() <= siblingGeometry.bottom()) {
insertIndex = i + 1;
break;
}
}
}
return insertIndex;
}
} // Plasma namespace
#include "extendergroup.moc"

View File

@ -1,137 +0,0 @@
/*
* Copyright 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef PLASMA_EXTENDERGROUP_H
#define PLASMA_EXTENDERGROUP_H
#include <QtGui/QGraphicsWidget>
#include <QtCore/QList>
#include "extenderitem.h"
#include "plasma/plasma_export.h"
namespace Plasma
{
class ExtenderGroupPrivate;
class ExtenderItem;
class Applet;
/**
* @class ExtenderGroup plasma/extendergroup.h <Plasma/ExtenderGroup>
*
* @short Allows for grouping of extender items.
*
* To be able to group multiple items together, you'll need to instantiate an ExtenderGroup, and
* call setGroup() on all extender items you wish to add to this group.
* This ExtenderGroup is just the same as any other ExtenderItem, except for the expand group and
* collapse group buttons it provides, and the fact that it will automatically hide itself if less
* then one item belong to this group and autoHide is set to true.
*
* @since 4.3
*/
class PLASMA_EXPORT ExtenderGroup : public ExtenderItem
{
Q_OBJECT
Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
Q_PROPERTY(bool groupCollapsed READ isGroupCollapsed WRITE setGroupCollapsed)
Q_PROPERTY(bool autoCollapse READ isAutoCollapse WRITE setAutoCollapse)
public:
/**
* Creates a group.
* @param applet The applet this group is part of. Null is not allowed here.
*/
explicit ExtenderGroup(Extender *parent, uint groupId = 0);
~ExtenderGroup();
/**
* @return a list of items that belong to this group.
*/
QList<ExtenderItem*> items() const;
/**
* @return whether or not this item hides itself if there are less then 2 items in.
*/
bool autoHide() const;
/**
* @param autoHide whether or not this item hides itself if less then 2 items belong to this group. The default value is true.
*/
void setAutoHide(bool autoHide);
/**
* @return if the group is collapsed
* @since 4.4
*/
bool isGroupCollapsed() const;
/**
* @return whether or not this item collapses itself when the group gets collapsed
* @since 4.4
*/
bool isAutoCollapse() const;
/**
* @param autoCollapse whether or not this item collapses itself when the group gets collapsed, the default value is false
* @since 4.4
*/
void setAutoCollapse(bool collapse);
public Q_SLOTS:
/**
* expands or collapses this group
* @since 4.4
*/
void setGroupCollapsed(bool collapsed);
/**
* Expands this group to show all ExtenderItems that are contained in this group.
*/
void expandGroup();
/**
* Collapses this group to hide all ExtenderItems that are contained in this group, and
* shows the summary item.
*/
void collapseGroup();
protected:
void resizeEvent(QGraphicsSceneResizeEvent *event);
bool eventFilter(QObject *watched, QEvent *event);
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
private:
ExtenderGroupPrivate * const d;
Q_PRIVATE_SLOT(d, void addItemToGroup(Plasma::ExtenderItem *item))
Q_PRIVATE_SLOT(d, void removeItemFromGroup(Plasma::ExtenderItem *item))
Q_PRIVATE_SLOT(d, void themeChanged())
friend class ExtenderItem;
};
} // Plasma namespace
#endif //PLASMA_EXTENDER_H

File diff suppressed because it is too large Load Diff

View File

@ -1,315 +0,0 @@
/*
* Copyright 2008, 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef PLASMA_EXTENDERITEM_H
#define PLASMA_EXTENDERITEM_H
#include <QtGui/QGraphicsWidget>
#include <kconfiggroup.h>
#include <kicon.h>
#include "plasma/plasma_export.h"
namespace Plasma
{
class Applet;
class Extender;
class ExtenderGroup;
class ExtenderItemPrivate;
/**
* @class ExtenderItem plasma/extenderitem.h <Plasma/ExtenderItem>
*
* @short Provides detachable items for an Extender
*
* This class wraps around a QGraphicsWidget and provides drag&drop handling, a draghandle,
* title and ability to display qactions as a row of icon, ability to expand, collapse, return
* to source and tracks configuration associated with this item for you.
*
* Typical usage of ExtenderItems in your applet could look like this:
*
* @code
* if (!extender()->hasItem("networkmonitoreth0")) {
* ExtenderItem *item = new ExtenderItem(extender());
* //name can be used to later access this item through extender()->item(name):
* item->setName("networkmonitoreth0");
* item->config().writeEntry("device", "eth0");
* initExtenderItem(item);
* }
* @endcode
*
* Note that we first check if the item already exists: ExtenderItems are persistent
* between sessions so we can't blindly add items since they might already exist.
*
* You'll then need to implement the initExtenderItem function. Having this function in your applet
* makes sure that detached extender items get restored after plasma is restarted, just like applets
* are. That is also the reason that we write an entry in item->config().
* In this function you should instantiate a QGraphicsWidget or QGraphicsItem and call the
* setWidget function on the ExtenderItem. This is the only correct way of adding actual content to
* a extenderItem. An example:
*
* @code
* void MyApplet::initExtenderItem(Plasma::ExtenderItem *item)
* {
* QGraphicsWidget *myNetworkMonitorWidget = new NetworkMonitorWidget(item);
* dataEngine("networktraffic")->connectSource(item->config().readEntry("device", ""),
* myNetworkMonitorWidget);
* item->setWidget(myNetworkMonitorWidget);
* }
* @endcode
*
*/
class PLASMA_EXPORT ExtenderItem : public QGraphicsWidget
{
Q_OBJECT
Q_PROPERTY(QGraphicsItem * widget READ widget WRITE setWidget)
Q_PROPERTY(QString title READ title WRITE setTitle)
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
Q_PROPERTY(Extender * extender READ extender WRITE setExtender)
Q_PROPERTY(bool collapsed READ isCollapsed WRITE setCollapsed)
Q_PROPERTY(bool detached READ isDetached)
Q_PROPERTY(uint autoExpireDelay READ autoExpireDelay WRITE setAutoExpireDelay)
public:
/**
* The constructor takes care of adding this item to an extender.
* @param hostExtender The extender the extender item belongs to.
* @param extenderItemId the id of the extender item. Use the default 0 to assign a new,
* unique id to this extender item.
*/
explicit ExtenderItem(Extender *hostExtender, uint extenderItemId = 0);
~ExtenderItem();
/**
* fetch the configuration of this widget.
* @return the configuration of this widget.
*/
KConfigGroup config() const;
/**
* @param widget The widget that should be wrapped into the extender item.
* It has to be a QGraphicsWidget.
*/
void setWidget(QGraphicsItem *widget);
/**
* @return The widget that is wrapped into the extender item.
*/
QGraphicsItem *widget() const;
/**
* @param title the title that will be shown in the extender item's dragger. Default is
* no title. This title will also be stored in the item's configuration, so you don't have
* to manually store/restore this information for your extender items.
*/
void setTitle(const QString &title);
/**
* @return the title shown in the extender item's dragger.
*/
QString title() const;
/**
* You can assign names to extender items to look them up through the item() function.
* Make sure you only use unique names. This name will be stored in the item's
* configuration.
* @param name the name of the item. Defaults to an empty string.
*/
void setName(const QString &name);
/**
* @return the name of the item.
*/
QString name() const;
/**
* @param icon the icon name to display in the extender item's
* drag handle. Defaults to the source applet's icon. This icon name will also be stored
* in the item's configuration, so you don't have to manually store/restore this
* information.
*/
void setIcon(const QString &icon);
/**
* @param icon the icon to display in the extender item's drag handle. Defaults to the
* source applet's icon.
*/
void setIcon(const QIcon &icon);
/**
* @return the icon being displayed in the extender item's drag handle.
*/
QIcon icon() const;
/**
* @param extender the extender this item belongs to.
* @param pos the position in the extender this item should be added. Defaults to 'just
* append'.
*/
void setExtender(Extender *extender, const QPointF &pos = QPointF(-1, -1));
/**
* @return the extender this items belongs to.
*/
Extender *extender() const;
/**
* @param group the group you want this item to belong to. Note that you can't nest
* ExtenderGroups.
* @param pos position inside the extender group
*/
void setGroup(ExtenderGroup *group, const QPointF &pos = QPointF(-1, -1));
/**
* @returns the group this item belongs to.
* @since 4.3
*/
ExtenderGroup *group() const;
/**
* @returns whether or not this is an ExtenderGroup.
* @since 4.3
*/
bool isGroup() const;
/**
* @param time (in ms) before this extender item destroys itself unless it is detached,
* in which case this extender stays around. 0 means forever and is the default.
*/
void setAutoExpireDelay(uint time);
/**
* @return whether or not this extender item has an auto expire delay.
*/
uint autoExpireDelay() const;
/**
* @return whether or not this item is detached from its original source.
*/
bool isDetached() const;
/**
* @return whether or not the extender item is collapsed.
*/
bool isCollapsed() const;
/**
* @param name the name to store the action under in our collection.
* @param action the action to add. Actions will be displayed as an icon in the drag
* handle.
*/
void addAction(const QString &name, QAction *action);
/**
* @return the QAction with the given name from our collection. By default the action
* collection contains a "movebacktosource" action which will be only shown when the
* item is detached.
*/
QAction *action(const QString &name) const;
/**
* Set the ExtenderItem as transient: won't be saved in the Plasma config
* and won't be restored. This is intended for items that have contents
* valid only for this session.
*
* @param transient true if the ExtenderItem will be transient
*
* @since 4.6
*/
void setTransient(const bool transient);
/**
* @return true if the ExtenderItem is transient.
* @since 4.6
*/
bool isTransient() const;
public Q_SLOTS:
/**
* Destroys the extender item. As opposed to calling delete on this class, destroy also
* removes the config group associated with this item.
*/
void destroy();
/**
* Collapse or expand the extender item. Defaults to false.
*/
void setCollapsed(bool collapsed);
/**
* Returns the extender item to its source applet.
*/
void returnToSource();
/**
* Shows a close button in this item's drag handle. By default a close button will not be
* shown.
*/
void showCloseButton();
/**
* Hides the close button in this item's drag handle.
*/
void hideCloseButton();
Q_SIGNALS:
/**
* Emitted when the extender item is destroyed
* @since 4.4.1
*/
void destroyed(Plasma::ExtenderItem *item);
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void moveEvent(QGraphicsSceneMoveEvent *event);
void resizeEvent(QGraphicsSceneResizeEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
private:
Q_PRIVATE_SLOT(d, void toggleCollapse())
Q_PRIVATE_SLOT(d, void updateToolBox())
Q_PRIVATE_SLOT(d, void themeChanged())
Q_PRIVATE_SLOT(d, void sourceAppletRemoved())
Q_PRIVATE_SLOT(d, void actionDestroyed(QObject*))
ExtenderItemPrivate * const d;
friend class Applet;
friend class Extender;
friend class ExtenderPrivate;
friend class ExtenderItemPrivate;
};
} // namespace Plasma
#endif // PLASMA_EXTENDERITEM_H

View File

@ -0,0 +1,505 @@
/*
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "graphicsviewappletprivate_p.h"
#include <QGraphicsLinearLayout>
#include <QGraphicsGridLayout>
#include "kwindowsystem.h"
#include "corona.h"
#include "dialog.h"
#include "paintutils.h"
#include "popupapplet.h"
#include "theme.h"
#include "tooltipmanager.h"
#include "widgets/busywidget.h"
#include "widgets/iconwidget.h"
#include "widgets/label.h"
#include "widgets/pushbutton.h"
namespace Plasma
{
GraphicsViewAppletPrivate::GraphicsViewAppletPrivate(KService::Ptr service, const KPluginInfo *info, int uniqueID, Applet *applet)
: AppletPrivate(service, info, uniqueID, applet),
messageOverlay(0),
messageOverlayProxy(0),
busyWidget(0)
{
}
void GraphicsViewAppletPrivate::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons)
{
if (message.isEmpty()) {
destroyMessageOverlay();
return;
}
Corona *corona = qobject_cast<Corona *>(q->scene());
QGraphicsWidget *mainWidget = new QGraphicsWidget;
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(mainWidget);
mainLayout->setOrientation(Qt::Vertical);
mainLayout->addStretch();
QGraphicsLinearLayout *messageLayout = new QGraphicsLinearLayout();
messageLayout->setOrientation(Qt::Horizontal);
QGraphicsLinearLayout *buttonLayout = new QGraphicsLinearLayout();
buttonLayout->setOrientation(Qt::Horizontal);
mainLayout->addItem(messageLayout);
mainLayout->addItem(buttonLayout);
mainLayout->addStretch();
IconWidget *messageIcon = new IconWidget(mainWidget);
Label *messageText = new Label(mainWidget);
messageText->nativeWidget()->setWordWrap(true);
messageLayout->addStretch();
messageLayout->addItem(messageIcon);
messageLayout->addItem(messageText);
messageLayout->addStretch();
messageIcon->setIcon(icon);
messageText->setText(message);
buttonLayout->addStretch();
if (buttons & ButtonOk) {
messageOkButton = new PushButton(mainWidget);
messageOkButton.data()->setText(i18n("&OK"));
messageOkButton.data()->setIcon(KIcon("dialog-ok"));
buttonLayout->addItem(messageOkButton.data());
QObject::connect(messageOkButton.data(), SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
if (buttons & ButtonYes) {
messageYesButton = new PushButton(mainWidget);
messageYesButton.data()->setText(i18n("&Yes"));
buttonLayout->addItem(messageYesButton.data());
QObject::connect(messageYesButton.data(), SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
if (buttons & ButtonNo) {
messageNoButton = new PushButton(mainWidget);
messageNoButton.data()->setText(i18n("&No"));
buttonLayout->addItem(messageNoButton.data());
QObject::connect(messageNoButton.data(), SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
if (buttons & ButtonCancel) {
messageCancelButton = new PushButton(mainWidget);
messageCancelButton.data()->setText(i18n("&Cancel"));
messageCancelButton.data()->setIcon(KIcon("dialog-cancel"));
buttonLayout->addItem(messageCancelButton.data());
QObject::connect(messageCancelButton.data(), SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
messageCloseAction = new QAction(messageOverlay);
messageCloseAction.data()->setShortcut(Qt::Key_Escape);
mainWidget->addAction(messageCloseAction.data());
QObject::connect(messageCloseAction.data(), SIGNAL(triggered()), q, SLOT(destroyMessageOverlay()));
buttonLayout->addStretch();
mainWidget->adjustSize();
QSizeF hint = mainWidget->preferredSize();
if (hint.height() > q->size().height() || hint.width() > q->size().width()) {
// either a collapsed popup in h/v form factor or just too small,
// so show it in a dialog associated with ourselves
if (corona) {
corona->addOffscreenWidget(mainWidget);
}
if (messageDialog) {
delete messageDialog.data()->graphicsWidget();
} else {
messageDialog = new Plasma::Dialog;
}
ToolTipManager::self()->hide(q);
KWindowSystem::setOnAllDesktops(messageDialog.data()->winId(), true);
KWindowSystem::setState(messageDialog.data()->winId(), NET::SkipTaskbar | NET::SkipPager);
messageDialog.data()->setGraphicsWidget(mainWidget);
QObject::connect(messageDialog.data(), SIGNAL(destroyed(QObject*)), mainWidget, SLOT(deleteLater()));
// if we are going to show it in a popup, then at least make sure it can be dismissed
if (buttonLayout->count() < 1) {
PushButton *ok = new PushButton(mainWidget);
ok->setText(i18n("OK"));
ok->setIcon(KIcon("dialog-ok"));
buttonLayout->addItem(ok);
QObject::connect(ok, SIGNAL(clicked()), q, SLOT(destroyMessageOverlay()));
}
} else {
delete messageDialog.data();
createMessageOverlay();
messageOverlay->opacity = 0.8;
mainWidget->setParentItem(messageOverlay);
QGraphicsLinearLayout *l = new QGraphicsLinearLayout(messageOverlay);
l->addItem(mainWidget);
}
if (messageDialog) {
QPoint pos = q->geometry().topLeft().toPoint();
if (corona) {
pos = corona->popupPosition(q, messageDialog.data()->size());
}
messageDialog.data()->move(pos);
messageDialog.data()->animatedShow(locationToDirection(q->location()));
} else {
messageOverlay->show();
}
}
void GraphicsViewAppletPrivate::updateFailedToLaunch(const QString &reason)
{
if (failed == failed) {
if (failed && !reason.isEmpty()) {
foreach (QGraphicsItem *item, q->QGraphicsItem::children()) {
Label *l = dynamic_cast<Label *>(item);
if (l) {
l->setText(visibleFailureText(reason));
}
}
}
return;
}
//FIXME: q->prepareGeometryChange();
foreach (QGraphicsItem *item, q->childItems()) {
if (!dynamic_cast<AppletHandle *>(item)) {
delete item;
}
}
messageOverlay = 0;
if (messageDialog) {
messageDialog.data()->deleteLater();
messageDialog.clear();
}
q->setLayout(0);
if (failed) {
q->setBackgroundHints(StandardBackground);
QGraphicsLinearLayout *failureLayout = new QGraphicsLinearLayout(q);
failureLayout->setContentsMargins(0, 0, 0, 0);
IconWidget *failureIcon = new IconWidget(q);
failureIcon->setIcon(KIcon("dialog-error"));
failureLayout->addItem(failureIcon);
Label *failureWidget = new Plasma::Label(q);
failureWidget->setText(visibleFailureText(reason));
QLabel *label = failureWidget->nativeWidget();
label->setWordWrap(true);
failureLayout->addItem(failureWidget);
Plasma::ToolTipManager::self()->registerWidget(failureIcon);
Plasma::ToolTipContent data(i18n("Unable to load the widget"), reason,
KIcon("dialog-error"));
Plasma::ToolTipManager::self()->setContent(failureIcon, data);
q->setLayout(failureLayout);
q->resize(300, 250);
background->resizeFrame(q->geometry().size());
}
q->update();
}
void GraphicsViewAppletPrivate::showConfigurationRequiredMessage(bool show, const QString &reason)
{
if (!show) {
destroyMessageOverlay();
return;
}
createMessageOverlay(true);
messageOverlay->opacity = 0.4;
QGraphicsGridLayout *configLayout = new QGraphicsGridLayout(messageOverlay);
configLayout->setContentsMargins(0, 0, 0, 0);
// configLayout->addStretch();
configLayout->setColumnStretchFactor(0, 5);
configLayout->setColumnStretchFactor(2, 5);
configLayout->setRowStretchFactor(0, 5);
configLayout->setRowStretchFactor(3, 5);
int row = 1;
if (!reason.isEmpty()) {
Label *explanation = new Label(messageOverlay);
explanation->setText(reason);
configLayout->addItem(explanation, row, 1);
configLayout->setColumnStretchFactor(1, 5);
++row;
configLayout->setAlignment(explanation, Qt::AlignBottom | Qt::AlignCenter);
}
PushButton *configWidget = new PushButton(messageOverlay);
QObject::connect(configWidget, SIGNAL(clicked()), q, SLOT(showConfigurationInterface()));
const FormFactor formFactor = q->formFactor();
if (!qobject_cast<Plasma::PopupApplet *>(q) && (formFactor == Plasma::Horizontal || formFactor == Plasma::Vertical)) {
configWidget->setImage("widgets/configuration-icons", "configure");
configWidget->setMaximumSize(24,24);
configWidget->setMinimumSize(24,24);
} else {
configWidget->setText(i18n("Configure..."));
}
configLayout->addItem(configWidget, row, 1);
//configLayout->setAlignment(configWidget, Qt::AlignTop | Qt::AlignCenter);
//configLayout->addStretch();
messageOverlay->show();
}
void GraphicsViewAppletPrivate::createMessageOverlay(bool usePopup)
{
if (messageOverlay) {
qDeleteAll(messageOverlay->children());
messageOverlay->setLayout(0);
}
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
if (!messageOverlay) {
if (usePopup && popup) {
if (popup->widget()) {
messageOverlayProxy = new QGraphicsProxyWidget(q);
messageOverlayProxy->setWidget(popup->widget());
messageOverlay = new AppletOverlayWidget(messageOverlayProxy);
} else if (popup->graphicsWidget()) {
messageOverlay = new AppletOverlayWidget(popup->graphicsWidget());
}
}
if (!messageOverlay) {
messageOverlay = new AppletOverlayWidget(q);
}
}
positionMessageOverlay();
}
void GraphicsViewAppletPrivate::positionMessageOverlay()
{
if (!messageOverlay) {
return;
}
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
const bool usePopup = popup && (messageOverlay->parentItem() != q);
QGraphicsItem *topItem = q;
if (usePopup && popup->widget()) {
// popupapplet with widget()
//FIXME:topItem = popup->d->proxy.data();
messageOverlay->setGeometry(popup->widget()->contentsRect());
} else if (usePopup && popup->graphicsWidget()) {
// popupapplet with graphicsWidget()
topItem = popup->graphicsWidget();
QGraphicsWidget *w = dynamic_cast<QGraphicsWidget *>(topItem);
messageOverlay->setGeometry(w ? w->contentsRect() : topItem->boundingRect());
} else {
// normal applet
messageOverlay->setGeometry(q->contentsRect());
}
// raise the overlay above all the other children!
int zValue = 100;
foreach (QGraphicsItem *child, topItem->children()) {
if (child->zValue() > zValue) {
zValue = child->zValue() + 1;
}
}
messageOverlay->setZValue(zValue);
}
void GraphicsViewAppletPrivate::destroyMessageOverlay()
{
if (messageDialog) {
messageDialog.data()->animatedHide(Plasma::locationToInverseDirection(q->location()));
//messageDialog.data()->deleteLater();
messageDialog.clear();
}
if (!messageOverlay) {
return;
}
messageOverlay->destroy();
messageOverlay = 0;
if (messageOverlayProxy) {
messageOverlayProxy->setWidget(0);
delete messageOverlayProxy;
messageOverlayProxy = 0;
}
MessageButton buttonCode = ButtonNo;
//find out if we're disappearing because of a button press
PushButton *button = 0;
//FIXME: PushButton *button = qobject_cast<PushButton *>(q->sender());
if (button) {
if (button == messageOkButton.data()) {
buttonCode = ButtonOk;
}
if (button == messageYesButton.data()) {
buttonCode = ButtonYes;
}
if (button == messageNoButton.data()) {
buttonCode = ButtonNo;
}
if (button == messageCancelButton.data()) {
buttonCode = ButtonCancel;
}
//FIXME: emit q->messageButtonPressed(buttonCode);
} else if (/* FIXME: q->sender() == messageOverlay */ false) {
//FIXME: emit q->messageButtonPressed(ButtonCancel);
}
}
void GraphicsViewAppletPrivate::setBusy(bool busy)
{
if (busy) {
if (!busyWidget && !busyWidgetTimer.isActive()) {
busyWidgetTimer.start(500, this);
}
} else {
busyWidgetTimer.stop();
if (busyWidget) {
busyWidget = 0;
destroyMessageOverlay();
}
}
}
bool GraphicsViewAppletPrivate::isBusy() const
{
return busyWidgetTimer.isActive() || (busyWidget && busyWidget->isVisible());
}
void GraphicsViewAppletPrivate::timerEvent(QTimerEvent *event)
{
if (transient) {
busyWidgetTimer.stop();
return;
}
if (event->timerId() == busyWidgetTimer.timerId()) {
if (!busyWidget) {
createMessageOverlay(false);
messageOverlay->opacity = 0;
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(messageOverlay);
busyWidget = new Plasma::BusyWidget(messageOverlay);
busyWidget->setAcceptHoverEvents(false);
busyWidget->setAcceptedMouseButtons(Qt::NoButton);
messageOverlay->setAcceptHoverEvents(false);
messageOverlay->setAcceptedMouseButtons(Qt::NoButton);
mainLayout->addStretch();
mainLayout->addItem(busyWidget);
mainLayout->addStretch();
}
}
}
AppletOverlayWidget::AppletOverlayWidget(QGraphicsWidget *parent)
: QGraphicsWidget(parent),
opacity(0.4)
{
resize(parent->size());
}
void AppletOverlayWidget::destroy()
{
/*FIXME: a transitional animation would be nice here .. we used to do this:
Animation *anim = Plasma::Animator::create(Plasma::Animator::DisappearAnimation);
if (anim) {
connect(anim, SIGNAL(finished()), this, SLOT(overlayAnimationComplete()));
anim->setTargetWidget(this);
anim->start();
} else {
overlayAnimationComplete();
}
*/
if (scene()) {
scene()->removeItem(this);
}
deleteLater();
}
void AppletOverlayWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->accept();
}
void AppletOverlayWidget::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
if (qFuzzyCompare(1, 1+opacity)) {
return;
}
QColor wash = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor);
wash.setAlphaF(opacity);
Applet *applet = qobject_cast<Applet *>(parentWidget());
QPainterPath backgroundShape;
if (!applet || applet->backgroundHints() == StandardBackground) {
//FIXME: a resize here is nasty, but perhaps still better than an eventfilter just for that..
if (parentWidget()->contentsRect().size() != size()) {
resize(parentWidget()->contentsRect().size());
}
backgroundShape = PaintUtils::roundedRectangle(contentsRect(), 5);
} else {
backgroundShape = shape();
}
painter->setRenderHints(QPainter::Antialiasing);
painter->fillPath(backgroundShape, wash);
}
} // namespace Plasma
#include "graphicsviewappletprivate_p.h"

View File

@ -0,0 +1,81 @@
/*
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PLASMA_GRAPHICSVIEWAPPLETPRIVATE_H
#define PLASMA_GRAPHICSVIEWAPPLETPRIVATE_H
#include "private/applet_p.h"
namespace Plasma
{
class AppletOverlayWidget : public QGraphicsWidget
{
Q_OBJECT
public:
AppletOverlayWidget(QGraphicsWidget *parent);
void destroy();
qreal opacity;
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
};
class GraphicsViewAppletPrivate : public QObject, public AppletPrivate
{
Q_OBJECT
public:
GraphicsViewAppletPrivate(KService::Ptr service, const KPluginInfo *info, int uniqueID, Applet *applet);
void showConfigurationRequiredMessage(bool show, const QString &reason);
void showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons);
void positionMessageOverlay();
void setBusy(bool busy);
bool isBusy() const;
void updateFailedToLaunch(const QString &reason);
protected:
void timerEvent(QTimerEvent *event);
private:
void createMessageOverlay(bool usePopup = true);
private Q_SLOTS:
void destroyMessageOverlay();
private:
// overlays and messages
QWeakPointer<Plasma::Dialog> messageDialog;
AppletOverlayWidget *messageOverlay;
QGraphicsProxyWidget *messageOverlayProxy;
Plasma::BusyWidget *busyWidget;
QWeakPointer<Plasma::PushButton> messageOkButton;
QWeakPointer<Plasma::PushButton> messageYesButton;
QWeakPointer<Plasma::PushButton> messageNoButton;
QWeakPointer<Plasma::PushButton> messageCancelButton;
QWeakPointer<QAction> messageCloseAction;
};
} // namespace Plasma
#endif

View File

@ -0,0 +1,93 @@
#include "animations/animationscriptengine_p.h"
#include "animator.h"
/**
* Loads an animation from the applet package
* @param animation the animation to load
* @return an Animation object on success, a NULL pointer on failure
* @since 4.5
*/
Animation *loadAnimationFromPackage(const QString &name, QObject *parent);
Animation *AppletScript::loadAnimationFromPackage(const QString &name, QObject *parent)
{
if (applet()) {
const QString scopedName = applet()->pluginName() + ":" + name;
if (!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
KConfig conf(applet()->package().path() + "/metadata.desktop", KConfig::SimpleConfig);
KConfigGroup animConf(&conf, "Animations");
QString file;
foreach (const QString &possibleFile, animConf.keyList()) {
const QStringList anims = animConf.readEntry(possibleFile, QStringList());
if (anims.contains(name)) {
file = possibleFile;
break;
}
}
if (file.isEmpty()) {
return 0;
}
const QString path = applet()->package().filePath("animations", file);
if (path.isEmpty()) {
#ifndef NDEBUG
kDebug() << "file path was empty for" << file;
#endif
return 0;
}
if (!AnimationScriptEngine::loadScript(path, applet()->pluginName() + ':') ||
!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
#ifndef NDEBUG
kDebug() << "script engine loading failed for" << path;
#endif
return 0;
}
}
Animation *anim = Animator::create(scopedName, parent ? parent : this);
return anim;
}
return 0;
}
/**
* Factory to build new animation objects from Javascript files. To control their behavior,
* check \ref AbstractAnimation properties.
* @since 4.5
**/
static Plasma::Animation *create(const QString &animationName, QObject *parent = 0);
Plasma::Animation *Animator::create(const QString &anim, QObject *parent)
{
if (AnimationScriptEngine::animationFailedToLoad(anim)) {
return 0;
}
if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
const QString path = Theme::defaultTheme()->animationPath(anim);
if (path.isEmpty()) {
AnimationScriptEngine::addToLoadFailures(anim);
//kError() << "************ failed to find script file for animation" << anim;
return 0;
}
if (!AnimationScriptEngine::loadScript(path)) {
AnimationScriptEngine::addToLoadFailures(anim);
return 0;
}
if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
//kError() << "successfully loaded script file" << path << ", but did not get animation object for" << anim;
AnimationScriptEngine::addToLoadFailures(anim);
return 0;
}
}
return new Plasma::JavascriptAnimation(anim, parent);
}

View File

@ -39,7 +39,6 @@
#include "package.h"
#include "popupapplet.h"
#include "private/applet_p.h"
#include "private/extenderapplet_p.h"
#include "private/packages_p.h"
#include "private/service_p.h" // for NullService
#include "private/storage_p.h"
@ -162,18 +161,13 @@ Applet *PluginLoader::loadApplet(const QString &name, uint appletId, const QVari
KPluginLoader plugin(*offer);
if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion()) &&
(name != "internal:extender")) {
if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
return 0;
}
QString error;
if (name == "internal:extender") {
applet = new ExtenderApplet(0, allArgs);
} else {
applet = offer->createInstance<Plasma::Applet>(0, allArgs, &error);
}
if (!applet) {
#ifndef NDEBUG

View File

@ -39,13 +39,10 @@
#include <netwm.h>
#include "plasma/private/applet_p.h"
#include "plasma/private/extenderitemmimedata_p.h"
#include "plasma/corona.h"
#include "plasma/containment.h"
#include "plasma/private/containment_p.h"
#include "plasma/dialog.h"
#include "plasma/extenders/extender.h"
#include "plasma/extenders/extenderitem.h"
#include "plasma/package.h"
#include "plasma/theme.h"
#include "plasma/scripting/appletscript.h"
@ -56,13 +53,13 @@ namespace Plasma
{
PopupApplet::PopupApplet(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args),
: Applet(parent, args),
d(new PopupAppletPrivate(this))
{
}
PopupApplet::PopupApplet(const QString &packagePath, uint appletId, const QVariantList &args)
: Plasma::Applet(packagePath, appletId, args),
: Applet(packagePath, appletId, args),
d(new PopupAppletPrivate(this))
{
}
@ -160,11 +157,7 @@ void PopupApplet::setWidget(QWidget *widget)
QGraphicsWidget *PopupApplet::graphicsWidget()
{
if (d->graphicsWidget != 0) {
return d->graphicsWidget;
} else {
return static_cast<Applet*>(this)->d->extender.data();
}
}
void PopupApplet::setGraphicsWidget(QGraphicsWidget *graphicsWidget)
@ -182,32 +175,10 @@ void PopupApplet::setGraphicsWidget(QGraphicsWidget *graphicsWidget)
d->graphicsWidget = graphicsWidget;
}
void PopupAppletPrivate::checkExtenderAppearance(Plasma::FormFactor f)
{
Extender *extender = qobject_cast<Extender*>(q->graphicsWidget());
if (extender) {
if (f != Plasma::Horizontal && f != Plasma::Vertical) {
extender->setAppearance(Extender::NoBorders);
} else if (q->location() == TopEdge) {
extender->setAppearance(Extender::TopDownStacked);
} else {
extender->setAppearance(Extender::BottomUpStacked);
}
if (dialogPtr) {
dialogPtr.data()->setGraphicsWidget(extender);
}
}
}
void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
{
Plasma::FormFactor f = q->formFactor();
if (constraints & Plasma::LocationConstraint) {
checkExtenderAppearance(f);
}
if (constraints & Plasma::FormFactorConstraint ||
constraints & Plasma::StartupCompletedConstraint ||
(constraints & Plasma::SizeConstraint &&
@ -229,10 +200,6 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
minimum = gWidget->minimumSize();
// our layout may have been replaced on us in the call to graphicsWidget!
lay = dynamic_cast<QGraphicsLinearLayout *>(q->layout());
if (!(constraints & LocationConstraint)) {
checkExtenderAppearance(f);
}
} else if (qWidget) {
minimum = qWidget->minimumSizeHint();
}
@ -381,7 +348,7 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints)
}
//no longer use Qt::Popup since that seems to cause a lot of problem when you drag
//stuff out of your Dialog (extenders). Monitor WindowDeactivate events so we can
//stuff out of your Dialog. Monitor WindowDeactivate events so we can
//emulate the same kind of behavior as Qt::Popup (close when you click somewhere
//else.
@ -516,50 +483,6 @@ bool PopupApplet::eventFilter(QObject *watched, QEvent *event)
return Applet::eventFilter(watched, event);
}
//FIXME: some duplication between the drag events... maybe add some simple helper function?
void PopupApplet::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
const ExtenderItemMimeData *mimeData =
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
if (mimeData && qobject_cast<Extender*>(graphicsWidget())) {
event->accept();
showPopup();
}
}
}
void PopupApplet::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
const ExtenderItemMimeData *mimeData =
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
if (mimeData && qobject_cast<Extender*>(graphicsWidget())) {
//We want to hide the popup if we're not moving onto the popup AND it is not the popup
//we started.
if (d->dialogPtr && !d->dialogPtr.data()->geometry().contains(event->screenPos()) &&
mimeData->extenderItem()->extender() != qobject_cast<Extender*>(graphicsWidget())) {
//We actually try to hide the popup, with a call to showPopup, with a smal timeout,
//so if the user moves into the popup fast enough, it remains open (the extender
//will call showPopup which will cancel the timeout.
showPopup(250);
}
}
}
}
void PopupApplet::dropEvent(QGraphicsSceneDragDropEvent *event)
{
if (event->mimeData()->hasFormat(ExtenderItemMimeData::mimeType())) {
const ExtenderItemMimeData *mimeData =
qobject_cast<const ExtenderItemMimeData*>(event->mimeData());
if (mimeData && qobject_cast<Extender*>(graphicsWidget())) {
mimeData->extenderItem()->setExtender(extender());
QApplication::restoreOverrideCursor();
}
}
}
void PopupApplet::showPopup(uint popupDuration)
{
// use autohideTimer to store when the next show should be
@ -734,9 +657,7 @@ void PopupAppletPrivate::internalTogglePopup(bool fromActivatedSignal)
dialog->clearFocus();
} else {
if (!q->graphicsWidget() ||
(q->graphicsWidget() == static_cast<Applet*>(q)->d->extender.data() &&
static_cast<Applet*>(q)->d->extender.data()->isEmpty())) {
if (!graphicsWidget) {
// we have nothing to show, so let's not.
if (!fromActivatedSignal) {
QObject::disconnect(q, SIGNAL(activate()), q, SLOT(appletActivated()));

View File

@ -30,23 +30,15 @@ class QGraphicsLinearLayout;
namespace Plasma
{
class Dialog;
class IconWidget;
class PopupAppletPrivate;
/**
* Allows applets to automatically 'collapse' into an icon when put in an panel, and is a convenient
* base class for any applet that wishes to use extenders.
* Allows applets to automatically 'collapse' into an icon when put in an panel.
*
* Applets that subclass this class should implement either widget() or graphicsWidget() to return a
* widget that will be displayed in the applet if the applet is in a Planar or MediaCenter form
* factor. If the applet is put in a panel, an icon will be displayed instead, which shows the
* widget in a popup when clicked.
*
* If you use this class as a base class for your extender using applet, the extender will
* automatically be used for the popup; reimplementing graphicsWidget() is unnecessary in this case.
* If you need a popup that does not steal window focus when openend or used, set window flag
* Qt::X11BypassWindowManagerHint the widget returned by widget() or graphicsWidget().
*/
class PLASMA_EXPORT PopupApplet : public Plasma::Applet
@ -191,21 +183,6 @@ protected:
*/
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);
/**
* Reimplemented from QGraphicsLayoutItem
*/

View File

@ -1,47 +0,0 @@
/*
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
* 2007 Alexis Ménard <darktears31@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ANIMATOR_P_H
#define ANIMATOR_P_H
#include <QHash>
#include <QPixmap>
#include <QSet>
#include <QTime>
#include <QTimeLine>
class QGraphicsItem;
namespace Plasma
{
class AnimatorPrivate
{
public:
static void mapAnimation(Animator::Animation from, Animator::Animation to);
static void mapAnimation(Animator::Animation from, const QString &to);
static QHash<Animator::Animation, Animator::Animation> s_stockAnimMappings;
static QHash<Animator::Animation, QString> s_loadableAnimMappings;
};
}
#endif

View File

@ -73,32 +73,22 @@ private:
bool m_changed;
};
class AppletOverlayWidget : public QGraphicsWidget
{
Q_OBJECT
public:
AppletOverlayWidget(QGraphicsWidget *parent);
void destroy();
qreal opacity;
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
protected Q_SLOTS:
void overlayAnimationComplete();
};
class AppletPrivate : public DataEngineConsumer
class PLASMA_EXPORT AppletPrivate : public DataEngineConsumer
{
public:
AppletPrivate(KService::Ptr service, const KPluginInfo *info, int uniqueID, Applet *applet);
~AppletPrivate();
virtual ~AppletPrivate();
void init(const QString &packagePath = QString());
// the interface
virtual void showConfigurationRequiredMessage(bool show, const QString &reason);
virtual void showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons);
virtual void positionMessageOverlay();
virtual void setBusy(bool busy);
virtual bool isBusy() const;
virtual void updateFailedToLaunch(const QString &reason);
// put all setup routines for script here. at this point we can assume that
// package exists and that we have a script engin
void setupScriptSupport();
@ -121,9 +111,6 @@ public:
void updateRect(const QRectF &rect);
void setFocus();
void cleanUpAndDelete();
void createMessageOverlay(bool usePopup = true);
void positionMessageOverlay();
void destroyMessageOverlay();
void addGlobalShortcutsPage(KConfigDialog *dialog);
void addPublishPage(KConfigDialog *dialog);
void clearShortcutEditorPtr();
@ -147,13 +134,11 @@ public:
static int s_minZValue;
static QSet<QString> s_customCategories;
//TODO: examine the usage of memory here; there's a pretty large
// number of members at this point.
uint appletId;
Applet *q;
// applet attributes
QWeakPointer<Extender> extender;
Service *remotingService;
BackgroundHints preferredBackgroundHints;
BackgroundHints backgroundHints;
@ -170,17 +155,6 @@ public:
KConfigGroup *mainConfig;
Plasma::Constraints pendingConstraints;
// overlays and messages
QWeakPointer<Plasma::Dialog> messageDialog;
AppletOverlayWidget *messageOverlay;
QGraphicsProxyWidget *messageOverlayProxy;
Plasma::BusyWidget *busyWidget;
QWeakPointer<Plasma::PushButton> messageOkButton;
QWeakPointer<Plasma::PushButton> messageYesButton;
QWeakPointer<Plasma::PushButton> messageNoButton;
QWeakPointer<Plasma::PushButton> messageCancelButton;
QWeakPointer<QAction> messageCloseAction;
// sripting and package stuff
AppletScript *script;
Package *package;

View File

@ -27,13 +27,13 @@
#include <QPropertyAnimation>
#include "animator.h"
#include "applet.h"
#include "svg.h"
class QGraphicsView;
namespace Plasma
{
class Applet;
class Containment;
class FrameSvg;
class View;

View File

@ -41,7 +41,6 @@ namespace Plasma
class AccessAppletJob;
class Containment;
class AbstractToolBox;
class Animation;
class ContainmentPrivate
{
@ -96,7 +95,6 @@ public:
QPointF preferredPanelPos(Corona *corona) const;
void setLockToolText();
void appletDestroyed(Applet*);
void appletAppearAnimationComplete();
void appletAppeared(Applet*);
void clearDataForMimeJob(KIO::Job *job);
void remoteAppletReady(Plasma::AccessAppletJob *job);

View File

@ -1,214 +0,0 @@
/*
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtCore/QObject>
#include <QtGui/QPainter>
#include "kdebug.h"
#include "ripple_p.h"
/**
* Allocates an integer matrix with the given size.
* @param size Matrix size
* @return integer matrix
*/
int **allocateWaveMap(const QSize &size)
{
int **waveMap = new int *[size.width()];
if (!waveMap) {
#ifndef NDEBUG
kDebug() << "could not allocate wave map";
#endif
return 0;
}
for (int x = 0; x < size.width(); ++x) {
waveMap[x] = new int[size.height()];
if (!waveMap[x]) {
#ifndef NDEBUG
kDebug() << "could not allocate wave map";
#endif
return 0;
}
}
return waveMap;
}
/**
* Deallocates an integer matrix
* @param waveMap integer matrix
*/
void deallocateWaveMap(int **waveMap)
{
if (waveMap) {
delete [] *waveMap;
delete [] waveMap;
}
}
namespace Plasma
{
RippleEffect::RippleEffect(QObject *parent)
: QGraphicsEffect(parent),
m_offset(1),
m_damping(16),
m_heigth(1),
m_opacity(0.0),
m_mapSize(boundingRect().size().toSize()),
m_previousMap(0),
m_currentMap(0)
{
}
RippleEffect::~RippleEffect()
{
deallocateWaveMap(m_previousMap);
deallocateWaveMap(m_currentMap);
}
qint8 RippleEffect::offset() const
{
return m_offset;
}
qint8 RippleEffect::damping() const
{
return m_damping;
}
qint8 RippleEffect::heigth() const
{
return m_heigth;
}
qreal RippleEffect::opacity() const
{
return m_opacity;
}
void RippleEffect::setOffset(qint8 offset)
{
m_offset = offset;
emit offsetChanged(m_offset);
}
void RippleEffect::setDamping(qint8 damping)
{
m_damping = damping;
emit dampingChanged(m_damping);
}
void RippleEffect::setHeigth(qint8 heigth)
{
m_heigth = heigth;
emit heigthChanged(m_heigth);
}
void RippleEffect::setOpacity(qreal opacity)
{
m_opacity = opacity;
update();
}
void RippleEffect::draw(QPainter *painter)
{
QPoint offset;
const QImage currentImage = sourcePixmap(Qt::LogicalCoordinates, &offset).toImage();
QImage modifiedImage = currentImage;
if (!m_previousMap && !m_currentMap) {
m_previousMap = allocateWaveMap(currentImage.size());
m_currentMap = allocateWaveMap(currentImage.size());
}
int x, y;
if (qFuzzyCompare(m_opacity, qreal(0.0))) {
for (x = 0; x < currentImage.width(); ++x) {
memset(m_currentMap[x], 0, sizeof(int) * currentImage.height());
memset(m_previousMap[x], 0, sizeof(int) * currentImage.height());
}
m_mapSize = currentImage.size();
int waveLength = m_mapSize.width() > m_mapSize.height() ? m_mapSize.width() : m_mapSize.height();
m_currentMap[m_mapSize.width() >> 1][m_mapSize.height() >> 1] = waveLength << m_heigth;
} else if (m_mapSize != currentImage.size()) {
const qreal scaleFactorX = qreal(currentImage.width()) / qreal(m_mapSize.width());
const qreal scaleFactorY = qreal(currentImage.height()) / qreal(m_mapSize.height());
int **newPreviousMap = allocateWaveMap(currentImage.size());
int **newCurrentMap = allocateWaveMap(currentImage.size());
int i, j;
for (y = 0; y < currentImage.height(); ++y) {
for (x = 0; x < currentImage.width(); ++x) {
i = x / scaleFactorX;
j = y / scaleFactorY;
newPreviousMap[x][y] = m_previousMap[i][j];
newCurrentMap[x][y] = m_currentMap[i][j];
}
}
deallocateWaveMap(m_previousMap);
deallocateWaveMap(m_currentMap);
m_mapSize = currentImage.size();
m_previousMap = newPreviousMap;
m_currentMap = newCurrentMap;
}
const int width = m_mapSize.width();
const int height = m_mapSize.height();
int neighbours;
int wave;
int xOffset, yOffset;
for (y = m_offset; y < height - m_offset - 1; ++y) {
for (x = m_offset; x < width - m_offset - 1; ++x) {
neighbours = m_previousMap[x+m_offset][y] +
m_previousMap[x-m_offset][y] +
m_previousMap[x][y+m_offset] +
m_previousMap[x][y-m_offset];
if (!neighbours && !m_currentMap[x][y]) {
continue;
}
wave = (neighbours >> 1) - m_currentMap[x][y];
wave -= wave >> m_damping;
m_currentMap[x][y] = wave;
xOffset = x + m_currentMap[x+m_offset][y] - wave;
yOffset = y + m_currentMap[x][y+m_offset] - wave;
modifiedImage.setPixel(x, y, currentImage.pixel(
qBound(0, xOffset, width - 1),
qBound(0, yOffset, height - 1)));
}
}
// Swap wave maps
int **pointer = m_previousMap;
m_previousMap = m_currentMap;
m_currentMap = pointer;
// Restart wave if image center has no wave
if (m_currentMap[width >> 1][height >> 1] == 0) {
int waveLength = width > height ? width : height;
m_currentMap[width >> 1][height >> 1] = waveLength << m_heigth;
}
painter->drawImage(offset, currentImage);
painter->setOpacity(1 - m_opacity);
painter->drawImage(offset, modifiedImage);
}
} // namespace Plasma

View File

@ -1,132 +0,0 @@
/*
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMA_EFFECTS_RIPPLE_P_H
#define PLASMA_EFFECTS_RIPPLE_P_H
#include <QtGui/QGraphicsEffect>
class QObject;
class QPainter;
namespace Plasma
{
/**
* @class RippleEffect plasma/private/effects/ripple_p.h
* @short Ripple effect.
*
* Simulates a ripple effect on the source. This class can be used to simulate a "water" animation.
*/
class RippleEffect : public QGraphicsEffect
{
Q_OBJECT
Q_PROPERTY(qint8 offset READ offset WRITE setOffset)
Q_PROPERTY(qint8 damping READ damping WRITE setDamping)
Q_PROPERTY(qint8 heigth READ heigth WRITE setHeigth)
Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
public:
/**
* Default constructor
*
* @param parent Effect object parent.
*/
RippleEffect(QObject *parent = 0);
/** Destructor */
~RippleEffect();
/**
* Returns the ripple offset. The offset is used to calculate the distande between
* neighbour pixels.
* @return ripple offset
*/
qint8 offset() const;
/** Returns the ripple damping factor. The damping factor is used to reduce the wave height
* through each pass.
* @return ripple damping factor
*/
qint8 damping() const;
/** Returns the ripple wave heigth factor. The heigth factor is used to enlarge or reduce the
* initial wave heigth.
* @return ripple wave heigth factor
*/
qint8 heigth() const;
/** Returns the ripple opacity. The opacity is used to reduce the effect opacity when
* animating.
* @return ripple opacity level
*/
qreal opacity() const;
public slots:
/**
* Set ripple offset (e.g. 1).
*/
void setOffset(qint8 offset);
/**
* Set ripple damping factor (e.g. 16).
*/
void setDamping(qint8 damping);
/**
* Set ripple wave heigth factor (e.g. 1).
*/
void setHeigth(qint8 heigth);
/**
* Set ripple opacity level (e.g. 1.0).
*/
void setOpacity(qreal opacity);
signals:
/**
* Emitted when the ripple offset has changed.
* @param offset the ripple offset
*/
void offsetChanged(qint8 offset);
/**
* Emitted when the ripple damping factor has changed.
* @param damping the ripple damping factor
*/
void dampingChanged(qint8 damping);
/**
* Emitted when the ripple wave heigth factor has changed.
* @param heigth the ripple wave heigth factor
*/
void heigthChanged(qint8 heigth);
protected:
/**
* Reimplemented from QGraphicsEffect::draw().
* @param painter source painter
*/
void draw(QPainter *painter);
private:
Q_DISABLE_COPY(RippleEffect)
qint8 m_offset; /** Ripple offset (default is 1) */
qint8 m_damping; /** Ripple damping factor (default is 16) */
qint8 m_heigth; /** Ripple wave heigth factor (default is 1) */
qreal m_opacity; /** Ripple opacity level (default is 0.0) */
QSize m_mapSize; /** Ripple matrix wave size */
int **m_previousMap; /** Last ripple matrix wave */
int **m_currentMap; /** Current ripple matrix wave */
};
} // namespace Plasma
#endif // PLASMA_EFFECTS_RIPPLE_P_H

View File

@ -1,112 +0,0 @@
/*
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef LIBS_PLASMA_EXTENDER_P_H
#define LIBS_PLASMA_EXTENDER_P_H
#include <QString>
#include <QList>
#include <QPointF>
#include "plasma/extenders/extender.h"
class QGraphicsGridLayout;
class QGraphicsLinearLayout;
class QGraphicsWidget;
namespace Plasma
{
class Applet;
class Extender;
class ExtenderGroup;
class ExtenderItem;
class Label;
class ScrollWidget;
class Svg;
class Spacer : public QGraphicsWidget
{
public:
Spacer(QGraphicsItem *parent);
~Spacer();
void setMargins(qreal left, qreal top, qreal right, qreal bottom);
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0);
private:
qreal m_left;
qreal m_top;
qreal m_right;
qreal m_bottom;
};
class ExtenderPrivate
{
public:
ExtenderPrivate(Applet *applet, Extender *q);
~ExtenderPrivate();
void addExtenderItem(ExtenderItem *item, const QPointF &pos = QPointF(-1, -1));
void extenderItemDestroyed(Plasma::ExtenderItem *item);
void viewportGeometryChanged(const QRectF &rect);
void removeExtenderItem(ExtenderItem *item);
int insertIndexFromPos(const QPointF &pos) const;
void loadExtenderItems();
void updateBorders();
void delayItemAddedEvent();
void updateEmptyExtenderLabel();
void adjustMinimumSize();
void setPositionFromDragPosition(const QPointF &pos);
ExtenderGroup *findGroup(const QString &name) const;
void setDisabledBordersHint(const FrameSvg::EnabledBorders borders);
void adjustSize();
Extender *q;
QWeakPointer<Applet> applet;
ScrollWidget *scrollWidget;
QGraphicsWidget *mainWidget;
QGraphicsLinearLayout *layout;
FrameSvg *background;
FrameSvg::EnabledBorders disabledBordersHint;
int currentSpacerIndex;
Spacer *spacerWidget;
QString emptyExtenderMessage;
Label *emptyExtenderLabel;
QList<ExtenderItem*> attachedExtenderItems;
Extender::Appearance appearance;
static QGraphicsGridLayout *s_popupLayout;
bool destroying;
bool scrollbarVisible;
QHash<ExtenderItem *, QPointF> pendingItems;
};
} // namespace Plasma
#endif // LIBS_PLASMA_EXTENDER_P_H

View File

@ -1,87 +0,0 @@
/*
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "extenderapplet_p.h"
#include "plasma/extenders/extender.h"
#include "plasma/extenders/extenderitem.h"
#include <QGraphicsLinearLayout>
namespace Plasma
{
ExtenderApplet::ExtenderApplet(QObject *parent, const QVariantList &args)
: PopupApplet(parent, args)
{
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
}
ExtenderApplet::~ExtenderApplet()
{
if (destroyed()) {
disconnect(extender(), SIGNAL(itemDetached(Plasma::ExtenderItem*)),
this, SLOT(itemDetached(Plasma::ExtenderItem*)));
foreach (ExtenderItem *item, extender()->attachedItems()) {
item->returnToSource();
}
}
}
void ExtenderApplet::init()
{
setPopupIcon("utilities-desktop-extra");
setAspectRatioMode(Plasma::IgnoreAspectRatio);
extender()->setAppearance(Extender::NoBorders);
connect(extender(), SIGNAL(itemDetached(Plasma::ExtenderItem*)),
this, SLOT(itemDetached(Plasma::ExtenderItem*)));
connect(extender(), SIGNAL(geometryChanged()),
this, SLOT(extenderGeometryChanged()));
}
void ExtenderApplet::itemDetached(Plasma::ExtenderItem *)
{
if (extender()->attachedItems().isEmpty()) {
destroy();
}
}
void ExtenderApplet::extenderGeometryChanged()
{
if (formFactor() != Plasma::Horizontal &&
formFactor() != Plasma::Vertical) {
qreal left, top, right, bottom;
getContentsMargins(&left, &top, &right, &bottom);
QSizeF margins(left + right, top + bottom);
setMinimumSize(extender()->minimumSize() + margins);
setMaximumSize(extender()->maximumSize() + margins);
setPreferredSize(extender()->preferredSize() + margins);
updateGeometry();
}
}
} // namespace Plasma
#include "extenderapplet_p.moc"

View File

@ -1,49 +0,0 @@
/*
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef EXTENDERAPPLET_H
#define EXTENDERAPPLET_H
#include "popupapplet.h"
namespace Plasma
{
/**
* This class is used as a 'host' for detached extender items. When an extender item is dropped
* somewhere, this applet is added at the location where the item is dropped, and the item is added
* to its extender.
*/
class ExtenderApplet : public Plasma::PopupApplet
{
Q_OBJECT
public:
ExtenderApplet(QObject *parent, const QVariantList &args);
~ExtenderApplet();
void init();
public Q_SLOTS:
void itemDetached(Plasma::ExtenderItem *);
void extenderGeometryChanged();
};
} // namespace Plasma
#endif

View File

@ -1,57 +0,0 @@
/*
* Copyright 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef PLASMA_EXTENDERGROUPPRIVATE_H
#define PLASMA_EXTENDERGROUPPRIVATE_H
class QTimer;
namespace Plasma
{
class ScrollWidget;
class ExtenderGroup;
class ExtenderItem;
class Svg;
class Spacer;
class ExtenderGroupPrivate
{
public:
ExtenderGroupPrivate(ExtenderGroup *group);
~ExtenderGroupPrivate();
void addItemToGroup(Plasma::ExtenderItem *item, const QPointF &pos = QPointF(-1, -1));
void removeItemFromGroup(Plasma::ExtenderItem *item);
void themeChanged();
int insertIndexFromPos(const QPointF &pos) const;
Plasma::ExtenderGroup *q;
Spacer *spacerWidget;
Plasma::Svg *svg;
QGraphicsWidget *childsWidget;
QGraphicsLinearLayout *layout;
QTimer *resizeTimer;
bool collapsed;
bool autoHide;
bool autoCollapse;
};
}
#endif

View File

@ -1,102 +0,0 @@
/*
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef LIBS_PLASMA_EXTENDERITEM_P_H
#define LIBS_PLASMA_EXTENDERITEM_P_H
#include <QPointF>
#include <QPoint>
#include <QRect>
#include <QString>
class QGraphicsItem;
class QGraphicsWidget;
class QGraphicsLinearLayout;
class QGraphicsView;
class QTimer;
namespace Plasma
{
class Applet;
class ExtenderGroup;
class ExtenderItem;
class Extender;
class Label;
class IconWidget;
class FrameSvg;
class ExtenderItemToolbox;
class ExtenderItemPrivate
{
public:
ExtenderItemPrivate(ExtenderItem *extenderItem, Extender *hostExtender);
~ExtenderItemPrivate();
QRectF dragHandleRect();
void toggleCollapse();
void updateToolBox();
Applet *hostApplet() const;
void themeChanged();
void sourceAppletRemoved();
void resizeContent(const QSizeF &newSize);
void actionDestroyed(QObject *o);
void updateSizeHints();
void setMovable(bool movable);
ExtenderItem *q;
QWeakPointer<QGraphicsWidget> widget;
ExtenderItemToolbox *toolbox;
QGraphicsLinearLayout *toolboxLayout;
QGraphicsLinearLayout *layout;
Extender *extender;
Applet *sourceApplet;
ExtenderGroup *group;
KConfigGroup config;
KSharedConfig::Ptr transientConfig;
FrameSvg *background;
IconWidget *collapseIcon;
Label *titleLabel;
QHash<QString, QAction*> actions;
QList<QAction*> actionsInOrder;
QString name;
QString iconName;
uint extenderItemId;
QTimer *expirationTimer;
bool dragStarted : 1;
bool destroyActionVisibility : 1;
bool collapsed : 1;
bool transient : 1;
static uint s_maxExtenderItemId;
};
}
#endif // LIB_PLASMA_EXTENDERITEM_P_H

View File

@ -1,75 +0,0 @@
/*
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#include "extenderitemmimedata_p.h"
#include "plasma/extenders/extenderitem.h"
#include <QMimeData>
namespace Plasma
{
ExtenderItemMimeData::ExtenderItemMimeData() : QMimeData()
{
}
ExtenderItemMimeData::~ExtenderItemMimeData()
{
}
QStringList ExtenderItemMimeData::formats() const
{
QStringList list;
list.append(mimeType());
return list;
}
bool ExtenderItemMimeData::hasFormat(const QString &type) const
{
return (type == mimeType());
}
void ExtenderItemMimeData::setExtenderItem(ExtenderItem *item)
{
m_extenderItem = item;
}
void ExtenderItemMimeData::setPointerOffset(const QPoint &p)
{
m_offset = p;
}
QPoint ExtenderItemMimeData::pointerOffset() const
{
return m_offset;
}
ExtenderItem *ExtenderItemMimeData::extenderItem() const
{
return m_extenderItem;
}
QString ExtenderItemMimeData::mimeType()
{
return "plasma/extenderitem";
}
} // namespace Plasma

View File

@ -1,59 +0,0 @@
/*
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
#ifndef EXTENDERITEMMIMEDATA_H
#define EXTENDERITEMMIMEDATA_H
#include <QMimeData>
#include <QPoint>
namespace Plasma
{
class ExtenderItem;
/**
* This class is used to deliver pointers to ExtenderItems to drag/drop event handlers.
*/
class ExtenderItemMimeData : public QMimeData
{
Q_OBJECT
public:
ExtenderItemMimeData();
~ExtenderItemMimeData();
QStringList formats() const;
bool hasFormat(const QString &mimeType) const;
void setExtenderItem(ExtenderItem *item);
ExtenderItem *extenderItem() const;
static QString mimeType();
void setPointerOffset(const QPoint &p);
QPoint pointerOffset() const;
private:
ExtenderItem *m_extenderItem;
QPoint m_offset;
};
} // namespace Plasma
#endif

View File

@ -28,6 +28,9 @@
namespace Plasma
{
class IconWidget;
class Dialog;
class PopupAppletPrivate
{
public:
@ -53,7 +56,7 @@ public:
PopupApplet *q;
Plasma::IconWidget *icon;
QWeakPointer<Plasma::Dialog> dialogPtr;
QWeakPointer<QGraphicsProxyWidget>proxy;
QWeakPointer<QGraphicsProxyWidget> proxy;
QWidget *widget;
QGraphicsWidget *graphicsWidget;
Plasma::PopupPlacement popupPlacement;

View File

@ -22,8 +22,6 @@
#include "kconfig.h"
#include "kconfigdialog.h"
#include "animations/animationscriptengine_p.h"
#include "animator.h"
#include "applet.h"
#include "package.h"
#include "private/applet_p.h"
@ -181,50 +179,6 @@ bool AppletScript::isRegisteredAsDragHandle(QGraphicsItem *item)
return false;
}
Animation *AppletScript::loadAnimationFromPackage(const QString &name, QObject *parent)
{
if (applet()) {
const QString scopedName = applet()->pluginName() + ":" + name;
if (!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
KConfig conf(applet()->package().path() + "/metadata.desktop", KConfig::SimpleConfig);
KConfigGroup animConf(&conf, "Animations");
QString file;
foreach (const QString &possibleFile, animConf.keyList()) {
const QStringList anims = animConf.readEntry(possibleFile, QStringList());
if (anims.contains(name)) {
file = possibleFile;
break;
}
}
if (file.isEmpty()) {
return 0;
}
const QString path = applet()->package().filePath("animations", file);
if (path.isEmpty()) {
#ifndef NDEBUG
kDebug() << "file path was empty for" << file;
#endif
return 0;
}
if (!AnimationScriptEngine::loadScript(path, applet()->pluginName() + ':') ||
!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
#ifndef NDEBUG
kDebug() << "script engine loading failed for" << path;
#endif
return 0;
}
}
Animation *anim = Animator::create(scopedName, parent ? parent : this);
return anim;
}
return 0;
}
void AppletScript::configChanged()
{
}
@ -253,12 +207,6 @@ KPluginInfo AppletScript::description() const
return d->applet->d->appletDescription;
}
Extender *AppletScript::extender() const
{
Q_ASSERT(d->applet);
return d->applet->extender();
}
bool AppletScript::drawWallpaper() const
{
Q_ASSERT(d->applet);

View File

@ -39,7 +39,6 @@ class KConfigDialog;
namespace Plasma
{
class Animation;
class AppletScriptPrivate;
class Extender;
@ -139,11 +138,6 @@ public:
*/
void configNeedsSaving() const;
/**
* @see Applet
*/
Extender *extender() const;
//FIXME plasma2: setWallpaperEnabled and setContainmentType should become public?
/**
* @return true if the applet is a containment AND if the wallpaper is enabled
@ -253,14 +247,6 @@ protected:
*/
bool isRegisteredAsDragHandle(QGraphicsItem *item);
/**
* Loads an animation from the applet package
* @param animation the animation to load
* @return an Animation object on success, a NULL pointer on failure
* @since 4.5
*/
Animation *loadAnimationFromPackage(const QString &name, QObject *parent);
private:
friend class Applet;
friend class PopupApplet;

View File

@ -45,7 +45,6 @@
#include <kwindowsystem.h>
#include "animations/animationscriptengine_p.h"
#include "libplasma-theme-global.h"
#include "private/packages_p.h"
#include "windoweffects.h"
@ -153,7 +152,6 @@ public:
void setThemeName(const QString &themeName, bool writeSettings);
void onAppExitCleanup();
void processWallpaperSettings(KConfigBase *metadata);
void processAnimationSettings(const QString &theme, KConfigBase *metadata);
const QString processStyleSheet(const QString &css);
@ -180,7 +178,6 @@ public:
QHash<QString, QPixmap> pixmapsToCache;
QHash<QString, QString> keysToCache;
QHash<QString, QString> idsToCache;
QHash<QString, QString> animationMapping;
QHash<styles, QString> cachedStyleSheets;
QHash<QString, QString> discoveries;
QTimer *saveTimer;
@ -530,32 +527,6 @@ void ThemePrivate::processWallpaperSettings(KConfigBase *metadata)
defaultWallpaperHeight = cg.readEntry("defaultHeight", DEFAULT_WALLPAPER_HEIGHT);
}
void ThemePrivate::processAnimationSettings(const QString &theme, KConfigBase *metadata)
{
KConfigGroup cg(metadata, "Animations");
const QString animDir = QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/animations/");
foreach (const QString &path, cg.keyList()) {
const QStringList anims = cg.readEntry(path, QStringList());
foreach (const QString &anim, anims) {
if (!animationMapping.contains(anim)) {
#ifndef NDEBUG
kDebug() << "Registering animation. animDir: " << animDir
<< "\tanim: " << anim
<< "\tpath: " << path << "\t*******\n\n\n";
#endif
//key: desktoptheme/default/animations/+ all.js
//value: ZoomAnimation
animationMapping.insert(anim, animDir % path);
} else {
#ifndef NDEBUG
kDebug() << "************Animation already registered!\n\n\n";
#endif
}
}
}
}
void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings)
{
//kDebug() << tempThemeName;
@ -605,10 +576,6 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
processWallpaperSettings(&metadata);
AnimationScriptEngine::clearAnimations();
animationMapping.clear();
processAnimationSettings(themeName, &metadata);
KConfigGroup cg(&metadata, "Settings");
useNativeWidgetStyle = cg.readEntry("UseNativeWidgetStyle", false);
QString fallback = cg.readEntry("FallbackTheme", QString());
@ -634,7 +601,6 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
foreach (const QString &theme, fallbackThemes) {
QString metadataPath(KStandardDirs::locate("data", QLatin1Literal("desktoptheme/") % theme % QLatin1Literal("/metadata.desktop")));
KConfig metadata(metadataPath);
processAnimationSettings(theme, &metadata);
processWallpaperSettings(&metadata);
}
}
@ -726,17 +692,6 @@ QString Theme::styleSheet(const QString &css) const
return d->processStyleSheet(css);
}
QString Theme::animationPath(const QString &name) const
{
const QString path = d->animationMapping.value(name);
if (path.isEmpty()) {
//kError() << "****** FAILED TO FIND IN MAPPING!";
return path;
}
return KStandardDirs::locate("data", path);
}
QString Theme::wallpaperPath(const QSize &size) const
{
QString fullPath;

View File

@ -129,15 +129,6 @@ class PLASMA_EXPORT Theme : public QObject
*/
Q_INVOKABLE QString imagePath(const QString &name) const;
/**
* Retrieves the path for the script file that contains a given
* Javascript animation.
* @param the name of the animation
* @return the full path to the script file, or an emptry string on failure
* @since 4.5
*/
Q_INVOKABLE QString animationPath(const QString &name) const;
/**
* Retrieves the default wallpaper associated with this theme.
*

View File

@ -170,6 +170,12 @@ IconAction::IconAction(IconWidget *icon, QAction *action)
void IconAction::show()
{
rebuildPixmap();
m_visible = true;
/*
FIXME: place this animation back when the icon widget is in the qgv library
Animation *animation = m_animation.data();
if (!animation) {
animation = Plasma::Animator::create(Plasma::Animator::PixmapTransitionAnimation, m_icon);
@ -179,12 +185,10 @@ void IconAction::show()
animation->pause();
}
rebuildPixmap();
m_visible = true;
animation->setProperty("targetPixmap", m_pixmap);
animation->setDirection(QAbstractAnimation::Forward);
animation->start();
*/
}
void IconAction::hide()
@ -342,7 +346,7 @@ void IconAction::paint(QPainter *painter) const
Animation *animation = m_animation.data();
if (m_visible && !animation) {
painter->drawPixmap(m_rect.toRect(), m_pixmap);
} else {
} else if (animation) {
painter->drawPixmap(m_rect.toRect(),
animation->property("currentPixmap").value<QPixmap>());
}