diff --git a/CMakeLists.txt b/CMakeLists.txt index 604ff6f4f..c5230dcbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,7 +105,6 @@ set(plasma_LIB_SRCS configloader.cpp containmentactions.cpp containmentactionspluginsconfig.cpp - coronabase.cpp datacontainer.cpp dataengine.cpp dataengineconsumer.cpp @@ -168,7 +167,8 @@ set(plasma_LIB_SRCS svg.cpp theme.cpp tooltipcontent.cpp - tooltipmanager.cpp + #FIXME: re-enable + #tooltipmanager.cpp version.cpp wallpaper.cpp @@ -188,75 +188,31 @@ set(plasma_LIB_SRCS private/qtjolie-branch/qtjolie/serverthread.cpp #FIXME: all these must move into the qgv library - private/themedwidgetinterface.cpp - widgets/iconwidget.cpp - abstracttoolbox.cpp - view.cpp + #view.cpp applet.cpp containment.cpp corona.cpp - dialog.cpp - popupapplet.cpp - private/applethandle.cpp + #dialog.cpp + #should popupapplet still exist? + #popupapplet.cpp ) -set (plasmaqgv_LIB_SRCS - delegate.cpp - #FIXME: this is duplicated with libplasma because iconwidget requires it! - private/themedwidgetinterface.cpp - - graphicsview/private/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/declarative/declarativenetworkaccessmanagerfactory.cpp - private/declarative/dataenginebindings.cpp - graphicsview/private/animablegraphicswebview.cpp - graphicsview/private/focusindicator.cpp - graphicsview/private/nativetabbar.cpp - graphicsview/private/style.cpp - graphicsview/private/kineticscroll.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 - widgets/flashinglabel.cpp - widgets/frame.cpp - widgets/groupbox.cpp - widgets/itembackground.cpp - widgets/lineedit.cpp - widgets/meter.cpp - widgets/pushbutton.cpp - widgets/radiobutton.cpp - widgets/signalplotter.cpp - widgets/slider.cpp - widgets/spinbox.cpp - widgets/toolbutton.cpp - widgets/separator.cpp - widgets/tabbar.cpp - widgets/treeview.cpp - widgets/webview.cpp -) +#TODO: all those files will have to be deleted +# set (plasmaqgv_LIB_SRCS +# dialog.cpp +# view.cpp +# private/themedwidgetinterface.cpp +# widgets/iconwidget.cpp +# #FIXME: this is duplicated with libplasma because iconwidget requires it! +# private/themedwidgetinterface.cpp +# +# graphicsview/private/graphicsviewappletprivate.cpp +# +# private/declarative/declarativenetworkaccessmanagerfactory.cpp +# private/declarative/dataenginebindings.cpp +# +# widgets/declarativewidget.cpp +# ) kconfig_add_kcfg_files(plasma_LIB_SRCS data/kconfigxt/libplasma-theme-global.kcfgc) @@ -272,28 +228,14 @@ kde4_add_ui_files(plasma_LIB_SRCS #) -if (PHONON_FOUND) - message(STATUS "Adding support for Phonon to libplasma") - include_directories(${KDE4_PHONON_INCLUDES}) - set(plasmaqgv_LIB_SRCS - ${plasmaqgv_LIB_SRCS} - widgets/videowidget.cpp) -endif(PHONON_FOUND) - kde4_add_library(plasma ${LIBRARY_TYPE} ${plasma_LIB_SRCS}) -kde4_add_library(plasmaqgv ${LIBRARY_TYPE} ${plasmaqgv_LIB_SRCS}) - target_link_libraries(plasma ${QT_QTUITOOLS_LIBRARY} ${QT_QTWEBKIT_LIBRARY} ${QT_QTSCRIPT_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTXML_LIBRARY} ${QT_QTSQL_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KDEUI_LIBS} kdnssd threadweaver kauth kwindowsystem ${PLASMA_EXTRA_LIBS} kcoreaddons ${QtMimeTypes_LIBRARY}) #FIXME gpgme++ is in kdepimlibs, neeeds to be elsewhere target_link_libraries(plasma ${KDEPIMLIBS_GPGMEPP_LIBS} kdeclarative karchive) -target_link_libraries(plasmaqgv plasma ${QT_QTUITOOLS_LIBRARY} ${QT_QTWEBKIT_LIBRARY} - ${QT_QTSCRIPT_LIBRARY} ${QT_QTNETWORK_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} - ${KDE4_KDEUI_LIBS} kdeclarative ${PLASMA_EXTRA_LIBS} kcoreaddons ${QtMimeTypes_LIBRARY}) - if(QCA2_FOUND) target_link_libraries(plasma ${QCA2_LIBRARIES}) endif(QCA2_FOUND) @@ -302,10 +244,6 @@ if(X11_FOUND) target_link_libraries(plasma ${X11_LIBRARIES}) endif(X11_FOUND) -if(PHONON_FOUND) - target_link_libraries(plasmaqgv ${KDE4_PHONON_LIBS}) -endif(PHONON_FOUND) - if(DL_LIBRARY) target_link_libraries(plasma ${DL_LIBRARY}) endif(DL_LIBRARY) @@ -318,13 +256,7 @@ set_target_properties(plasma PROPERTIES SOVERSION 4 ) -set_target_properties(plasmaqgv PROPERTIES - VERSION 1.0.0 - SOVERSION 1 - ) - install(TARGETS plasma EXPORT kdelibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) -install(TARGETS plasmaqgv EXPORT kdelibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### generate_export_header(plasma) @@ -332,9 +264,6 @@ generate_export_header(plasma) set(plasma_LIB_INCLUDES abstractdialogmanager.h abstractrunner.h - abstracttoolbox.h - animations/animation.h - animator.h applet.h configloader.h containment.h @@ -343,7 +272,6 @@ set(plasma_LIB_INCLUDES corona.h datacontainer.h dataengine.h - delegate.h dialog.h pluginloader.h paintutils.h @@ -380,35 +308,6 @@ install(FILES ${plasma_LIB_INCLUDES} DESTINATION ${INCLUDE_INSTALL_DIR}/plasma COMPONENT Devel) -install(FILES - widgets/checkbox.h - widgets/combobox.h - widgets/declarativewidget.h - widgets/flashinglabel.h - widgets/frame.h - widgets/groupbox.h - widgets/iconwidget.h - widgets/itembackground.h - widgets/label.h - widgets/lineedit.h - widgets/meter.h - widgets/pushbutton.h - widgets/toolbutton.h - widgets/radiobutton.h - widgets/scrollbar.h - widgets/signalplotter.h - widgets/slider.h - widgets/spinbox.h - widgets/busywidget.h - widgets/separator.h - widgets/svgwidget.h - widgets/scrollwidget.h - widgets/tabbar.h - widgets/textbrowser.h - widgets/treeview.h - widgets/textedit.h - widgets/webview.h - DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/widgets COMPONENT Devel) install(FILES scripting/appletscript.h @@ -418,19 +317,7 @@ install(FILES scripting/scriptengine.h DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/scripting COMPONENT Devel) -if(PHONON_FOUND) - install (FILES - widgets/videowidget.h - DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/widgets COMPONENT Devel) -endif(PHONON_FOUND) - install(FILES - animations/animation.h - DESTINATION ${INCLUDE_INSTALL_DIR}/plasma/animations COMPONENT Devel) - - -install(FILES - data/servicetypes/plasma-animator.desktop data/servicetypes/plasma-applet.desktop data/servicetypes/plasma-applet-popupapplet.desktop data/servicetypes/plasma-containment.desktop @@ -440,7 +327,6 @@ install(FILES data/servicetypes/plasma-runner.desktop data/servicetypes/plasma-scriptengine.desktop data/servicetypes/plasma-service.desktop - data/servicetypes/plasma-toolbox.desktop data/servicetypes/plasma-wallpaper.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR}) diff --git a/abstracttoolbox.cpp b/abstracttoolbox.cpp deleted file mode 100644 index a51b81417..000000000 --- a/abstracttoolbox.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2008 by Marco Martin - * - * 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 "abstracttoolbox.h" - -#include - -#include "containment.h" - -#include - -namespace Plasma -{ - -class AbstractToolBoxPrivate -{ -public: - AbstractToolBoxPrivate(Containment *c) - : containment(c) - {} - - Containment *containment; -}; - -AbstractToolBox::AbstractToolBox(Containment *parent) - : QGraphicsWidget(parent), - d(new AbstractToolBoxPrivate(parent)) -{ -} - -AbstractToolBox::AbstractToolBox(QObject *parent, const QVariantList & /*args*/) - : QGraphicsWidget(dynamic_cast(parent)), - d(new AbstractToolBoxPrivate(qobject_cast(parent))) -{ - if (!parentItem()) { - setParent(parent); - } -} - -AbstractToolBox::~AbstractToolBox() -{ - delete d; -} - -AbstractToolBox *AbstractToolBox::load(const QString &name, const QVariantList &args, Plasma::Containment *containment) -{ - const QString constraint = name.isEmpty() ? QString() : QString("[X-KDE-PluginInfo-Name] == '%1'").arg(name); - KService::List offers = KServiceTypeTrader::self()->query("Plasma/ToolBox", constraint); - - if (!offers.isEmpty()) { - KService::Ptr offer = offers.first(); - - KPluginLoader plugin(*offer); - if (Plasma::isPluginVersionCompatible(plugin.pluginVersion())) { - return offer->createInstance(containment, args); - } - } - - return 0; -} - -KPluginInfo::List AbstractToolBox::listToolBoxInfo(const QString - &parentApp) -{ - KPluginInfo::List list; - - if (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName()) { - list = KPluginInfo::List(); - } - - QString constraint; - if (parentApp.isEmpty()) { - constraint.append("not exist [X-KDE-ParentApp]"); - } else { - constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'"); - } - - KService::List offers = KServiceTypeTrader::self()->query("Plasma/ToolBox", constraint); - return list + KPluginInfo::fromServices(offers); -} - -Containment *AbstractToolBox::containment() const -{ - return d->containment; -} - -void AbstractToolBox::restore(const KConfigGroup &group) -{ - Q_UNUSED(group) -} - -void AbstractToolBox::save(const KConfigGroup &group) -{ - Q_UNUSED(group) -} - -void AbstractToolBox::reposition() -{} - -} // plasma namespace - - - -#include "moc_abstracttoolbox.cpp" diff --git a/abstracttoolbox.h b/abstracttoolbox.h deleted file mode 100644 index 277c17a64..000000000 --- a/abstracttoolbox.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2008 by Marco Martin - * - * 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_ABSTRACTTOOLBOX_H -#define PLASMA_ABSTRACTTOOLBOX_H - -#include -#include - -#include - -#include "plasma/plasma_export.h" - -class QAction; - -class KConfigGroup; - -namespace Plasma -{ - -class AbstractToolBoxPrivate; -class Containment; - -class PLASMA_EXPORT AbstractToolBox : public QGraphicsWidget -{ - Q_OBJECT - Q_INTERFACES(QGraphicsItem) - Q_PROPERTY(bool showing READ isShowing WRITE setShowing) - -public: - enum ToolType { - AddTool = 0, - ConfigureTool = 100, - ControlTool = 200, - MiscTool = 300, - DestructiveTool = 400, - UserToolType = DestructiveTool + 1000 - }; - Q_ENUMS(ToolType) - - explicit AbstractToolBox(Containment *parent); - explicit AbstractToolBox(QObject *parent = 0, - const QVariantList &args = QVariantList()); - ~AbstractToolBox(); - - /** - * Create a new AbstractToolBox, loading the proper plugin - * @param name the plugin name - * @param args the plugin arguments - * @param containment the containment parent of the toolbox - * @since 4.6 - */ - static AbstractToolBox *load(const QString &name, const QVariantList &args=QVariantList(), Plasma::Containment *containment=0); - - /** - * Returns a list of all installed ToolBox plugins - * - * @param parentApp the application to filter applets on. Uses the - * X-KDE-ParentApp entry (if any) in the plugin info. - * The default value of QString() will result in a - * list containing only applets not specifically - * registered to an application. - * - * @since 4.6 - */ - static KPluginInfo::List listToolBoxInfo(const QString &parentApp = QString()); - - /** - * create a toolbox tool from the given action - * @p action the action to associate the tool with - */ - virtual void addTool(QAction *action) = 0; - - /** - * remove the tool associated with this action - */ - virtual void removeTool(QAction *action) = 0; - - /** - * @return true if the ToolBox is open and shown the actions list - */ - virtual bool isShowing() const = 0; - - /** - * Opens or closes the ToolBox - */ - virtual void setShowing(const bool show) = 0; - - /** - * Restore the ToolBox settings - * It has to be reimplemented in toolboxes that need it - * @since 4.6 - */ - virtual void restore(const KConfigGroup &group); - - /** - * Save the ToolBox settings - * It has to be reimplemented in toolboxes that need it - * @since 4.6 - */ - virtual void save(const KConfigGroup &group); - - /** - * Inform the ToolBox it has to reposition itlself - * It has to be reimplemented in toolboxes that need it - * @since 4.6 - */ - virtual void reposition(); - -Q_SIGNALS: - /** - * Toolbox opened or closed - */ - void toggled(); - - /** - * Toolbox opened or closed - * @param open tells if the toolbox opened or closed - */ - void visibilityChanged(bool open); - -protected: - Containment *containment() const; - -private: - AbstractToolBoxPrivate * const d; - -}; - -} // Plasma namespace - -/** - * Register an applet when it is contained in a loadable module - */ -#define K_EXPORT_PLASMA_TOOLBOX(libname, classname) \ -K_PLUGIN_FACTORY(factory, registerPlugin();) \ -K_EXPORT_PLUGIN(factory("plasma_toolbox_" #libname)) \ -K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION) - -#endif // multiple inclusion guard - diff --git a/animations/animation.cpp b/animations/animation.cpp deleted file mode 100644 index 3332f645e..000000000 --- a/animations/animation.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * - * 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 "animation.h" -#include "private/animationprivate_p.h" - -#include -#include -#include -#include -#include -#include -#include - -namespace Plasma -{ - - -AnimationPrivate::AnimationPrivate() - : easingCurve(QEasingCurve::Linear), - duration(250) -{ -} - -Animation::Animation(QObject* parent) - : QAbstractAnimation(parent), - d(new AnimationPrivate) -{ -} - -Animation::~Animation() -{ - delete d; -} - -int Animation::duration() const -{ - return d->duration; -} - -void Animation::setDuration(int duration) -{ - d->duration = qMax(0, duration); -} - -void Animation::setTargetWidget(QGraphicsWidget* widget) -{ - d->animObject = widget; - if (parent() == 0) { - setParent(widget); - } -} - -QGraphicsWidget* Animation::targetWidget() const -{ - return d->animObject.data(); -} - -void Animation::setEasingCurve(const QEasingCurve &curve) -{ - d->easingCurve = curve; -} - -QEasingCurve Animation::easingCurve() const -{ - return d->easingCurve; -} - -void Animation::updateCurrentTime(int currentTime) -{ - Q_UNUSED(currentTime) -} - -} //namespace Plasma - - -#include "moc_animation.cpp" diff --git a/animations/animation.h b/animations/animation.h deleted file mode 100644 index 55a926208..000000000 --- a/animations/animation.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * - * 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. - */ - -/** - * @file This file contains the abstract base class for all singular - * animations. - */ - -#ifndef PLASMA_ANIMATION_H -#define PLASMA_ANIMATION_H - -#include -#include -#include -#include -#include - -#include -#include - -namespace Plasma -{ - -class AnimationPrivate; - -/** - * @brief Abstract representation of a single animation. - * @since 4.4 - */ -class PLASMA_EXPORT Animation : public QAbstractAnimation -{ - - Q_OBJECT - Q_ENUMS(Reference) - Q_ENUMS(MovementDirection) - Q_PROPERTY(int duration READ duration WRITE setDuration) - Q_PROPERTY(QEasingCurve easingCurve READ easingCurve WRITE setEasingCurve) - Q_PROPERTY(QGraphicsWidget *targetWidget READ targetWidget WRITE setTargetWidget) - -public: - /** - * Get the animation duration. It can be set using the property duration. - * @return duration in ms. - */ - int duration() const; - - /** - * Animation movement reference (used by \ref RotationAnimation). - */ - enum ReferenceFlag { - Center = 0, - Up = 0x1, - Down = 0x2, - Left = 0x4, - Right = 0x8 - }; - - Q_DECLARE_FLAGS(Reference, ReferenceFlag) - - /** - * Animation movement direction. - */ - enum MovementDirectionFlag { - MoveAny = 0, - MoveUp = 0x1, - MoveRight = 0x2, - MoveDown = 0x4, - MoveLeft = 0x8 - }; - - Q_DECLARE_FLAGS(MovementDirection, MovementDirectionFlag) - - /** - * Default constructor. - * - * @param parent Object parent (might be set when using - * \ref Animator::create factory). - * - */ - explicit Animation(QObject* parent = 0); - - /** - * Destructor. - */ - ~Animation() = 0; - - /** - * Set the widget on which the animation is to be performed. - * @param widget The QGraphicsWidget to be animated. - */ - void setTargetWidget(QGraphicsWidget* widget); - - /** - * @return The widget that the animation will be performed upon - */ - QGraphicsWidget *targetWidget() const; - - /** - * Set the animation easing curve type - */ - void setEasingCurve(const QEasingCurve &curve); - - /** - * Get the animation easing curve type - */ - QEasingCurve easingCurve() const; - -protected: - /** - * Change the animation duration. Default is 250ms. - * @param duration The new duration of the animation. - */ - virtual void setDuration(int duration = 250); - - /** - * QAbstractAnimation will call this method while the animation - * is running. Each specialized animation class should implement - * the correct behavior for it. - * @param currentTime Slapsed time using the \ref duration as reference - * (it will be from duration up to zero if the animation is running - * backwards). - */ - virtual void updateCurrentTime(int currentTime); - -private: - - /** - * Internal pimple (actually is used as a data structure, see - * \ref AnimationPrivate). - */ - AnimationPrivate *const d; - -}; - -} //namespace Plasma - -#endif diff --git a/animations/easinganimation.cpp b/animations/easinganimation.cpp deleted file mode 100644 index 125222ff1..000000000 --- a/animations/easinganimation.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2010 Aaron Seigo - * - * 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 "easinganimation_p.h" -#include - -namespace Plasma -{ - -EasingAnimation::EasingAnimation(QObject *parent) - : Animation(parent) -{ -} - -void EasingAnimation::updateCurrentTime(int currentTime) -{ - updateEffectiveTime(easingCurve().valueForProgress(currentTime / qreal(qMax(1, duration()))) * duration()); -} - -} // namespace Plasma - -#include "moc_easinganimation_p.cpp" - diff --git a/animations/easinganimation_p.h b/animations/easinganimation_p.h deleted file mode 100644 index 99ac3b2f4..000000000 --- a/animations/easinganimation_p.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2010 Aaron Seigo - * - * 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_EASINGANIMATION_H -#define PLASMA_EASINGANIMATION_H - -#include "animation.h" - -namespace Plasma -{ - - -class EasingAnimation : public Animation -{ - Q_OBJECT - -public: - explicit EasingAnimation(QObject *parent = 0); - -protected: - virtual void updateEffectiveTime(int currentTime) = 0; - -private: - void updateCurrentTime(int currentTime); -}; - -} // namespace Plasma - -#endif // PLASMA_EASINGANIMATION_H - diff --git a/animations/fade.cpp b/animations/fade.cpp deleted file mode 100644 index 44ef63d40..000000000 --- a/animations/fade.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * - * 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 "fade_p.h" - -#include - -#include - -namespace Plasma -{ - -FadeAnimation::FadeAnimation(QObject *parent) - : EasingAnimation(parent), - m_startOpacity(0), - m_targetOpacity(1) -{ -} - -FadeAnimation::~FadeAnimation() -{ -} - -void FadeAnimation::setStartOpacity(qreal factor) -{ - m_startOpacity = qBound(qreal(0.0), factor, qreal(1.0)); -} - -qreal FadeAnimation::startOpacity() const -{ - return m_startOpacity; -} - -void FadeAnimation::setTargetOpacity(qreal factor) -{ - m_targetOpacity = qBound(qreal(0.0), factor, qreal(1.0)); -} - -qreal FadeAnimation::targetOpacity() const -{ - return m_targetOpacity; -} - -void FadeAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) -{ - QGraphicsWidget *w = targetWidget(); - if (!w) { - return; - } - - if (oldState == Stopped && newState == Running) { - w->setOpacity(direction() == Forward ? m_startOpacity : m_targetOpacity); - } else if (newState == Stopped) { - w->setOpacity(direction() == Forward ? m_targetOpacity : m_startOpacity); - } -} - -void FadeAnimation::updateEffectiveTime(int currentTime) -{ - QGraphicsWidget *w = targetWidget(); - if (w) { - qreal delta = currentTime / qreal(duration()); - delta *= m_startOpacity - m_targetOpacity; - w->setOpacity(m_startOpacity - delta); - } -} - -} //namespace Plasma - -#include "moc_fade_p.cpp" diff --git a/animations/fade_p.h b/animations/fade_p.h deleted file mode 100644 index 27af7d297..000000000 --- a/animations/fade_p.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * - * 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. - */ - -/** - * @file This file contains the definition for the Fade effect. - */ - -#ifndef PLASMA_ANIMATIONS_FADE_P_H -#define PLASMA_ANIMATIONS_FADE_P_H - -#include -#include - -namespace Plasma -{ - -/** - * @class Fade plasma/animations/fade.h - * @short Fade effect - * - * Effect that slowly transforms the opacity of the object from a starting - * value to a target value. The range is 0 (full translucent) to 1 (full - * opaque). - */ -class FadeAnimation : public EasingAnimation -{ - Q_OBJECT - Q_PROPERTY(qreal startOpacity READ startOpacity WRITE setStartOpacity) - Q_PROPERTY(qreal targetOpacity READ targetOpacity WRITE setTargetOpacity) - -public: - /** Default constructor */ - explicit FadeAnimation(QObject *parent = 0); - - /** Destructor */ - virtual ~FadeAnimation(); - - /** - * Access start opacity of the target widget. - * - * You can set both a start and an end opacity for an widget when - * using this animation class. See \ref setStartOpacity. - * @return The opacity (range is 0 to 1). - */ - qreal startOpacity() const; - /** - * Set the start opacity of the target widget. - * - * See also \ref targetOpacity. - * @param qreal The opacity (range is 0 to 1). - */ - void setStartOpacity(qreal); - - /** - * Access final opacity of the target widget. - * - * You can set both a start and an end opacity for an widget when - * using this animation class. See \ref setTargetOpacity. - * @return The opacity (range is 0 to 1). - */ - qreal targetOpacity() const; - /** - * Set the final opacity of the target widget. - * - * See also \ref startOpacity. - * @param qreal The opacity (range is 0 to 1). - */ - void setTargetOpacity(qreal); - -protected: - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - void updateEffectiveTime(int currentTime); - -private: - /** Initial opacity */ - qreal m_startOpacity; - /** Final opacity */ - qreal m_targetOpacity; -}; - -} - -#endif // PLASMA_ANIMATIONS_FADE_P_H diff --git a/animations/geometry.cpp b/animations/geometry.cpp deleted file mode 100644 index a417904d3..000000000 --- a/animations/geometry.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2009 Igor Trindade Oliveira - * - * 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 "geometry_p.h" - -#include - -#include - -namespace Plasma -{ - -GeometryAnimation::GeometryAnimation(QObject *parent) - : EasingAnimation(parent), - m_startGeometry(-1, -1, -1, -1) -{ -} - -GeometryAnimation::~GeometryAnimation() -{ -} - -void GeometryAnimation::setStartGeometry(const QRectF &geometry) -{ - m_startGeometry = geometry; -} - -QRectF GeometryAnimation::startGeometry() const -{ - return m_startGeometry; -} - -void GeometryAnimation::setTargetGeometry(const QRectF &geometry) -{ - m_targetGeometry = geometry; -} - -QRectF GeometryAnimation::targetGeometry() const -{ - return m_targetGeometry; -} - -void GeometryAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) -{ - QGraphicsWidget *w = targetWidget(); - if (!w) { - return; - } - - if (m_startGeometry == QRectF(-1, -1, -1, -1)) { - m_startGeometry = w->geometry(); - } - - if (oldState == Stopped && newState == Running) { - w->setGeometry(direction() == Forward ? m_startGeometry : m_targetGeometry); - } else if (newState == Stopped) { - w->setGeometry(direction() == Forward ? m_targetGeometry : m_startGeometry); - } -} - -void GeometryAnimation::updateEffectiveTime(int currentTime) -{ - QGraphicsWidget *w = targetWidget(); - if (w) { - const qreal delta = currentTime / qreal(duration()); - - QRectF newGeo; - - newGeo.moveTopLeft(QPointF(m_startGeometry.left()*(1-delta) + m_targetGeometry.left()*(delta), - m_startGeometry.top()*(1-delta) + m_targetGeometry.top()*(delta))); - if (m_startGeometry.size() != m_targetGeometry.size()) { - newGeo.setSize(QSizeF(m_startGeometry.width()*(1-delta) + m_targetGeometry.width()*(delta), - m_startGeometry.height()*(1-delta) + m_targetGeometry.height()*(delta))); - } else { - newGeo.setSize(m_targetGeometry.size()); - } - w->setGeometry(newGeo); - } -} - -} //namespace Plasma - -#include "moc_geometry_p.cpp" diff --git a/animations/geometry_p.h b/animations/geometry_p.h deleted file mode 100644 index 52a405b84..000000000 --- a/animations/geometry_p.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2009 Igor Trindade Oliveira - * - * 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. - */ - -/** - * @file This file contains the definition for the Geometry effect. - */ - -#ifndef PLASMA_ANIMATIONS_GEOMETRY_P_H -#define PLASMA_ANIMATIONS_GEOMETRY_P_H - -#include -#include - -namespace Plasma -{ - -/** - * @class GeometryAnimation plasma/animations/geo_p.h - * @short Geometry Animation - * Use this class when you want to change the geometry of an QGraphicsWidget - * in an animated way (you should at least set the target geometry). - */ -class GeometryAnimation : public EasingAnimation -{ - Q_OBJECT - Q_PROPERTY(QRectF startGeometry READ startGeometry WRITE setStartGeometry) - Q_PROPERTY(QRectF targetGeometry READ targetGeometry WRITE setTargetGeometry) - -public: - /** Default constructor */ - explicit GeometryAnimation(QObject *parent = 0); - - /** Destructor */ - virtual ~GeometryAnimation(); - - /** - * Access the initial geometry of animated widget. - * - * If no geometry is set, it will use the widget current geometry - * when the animation is first run). - * @return Start geometry. - */ - QRectF startGeometry() const; - /** - * Set the initial geometry of animated widget. - * - * If no geometry is set, it will use the widget current geometry - * when the animation is first run). - * @param geometry The initial geometry. - */ - void setStartGeometry(const QRectF &geometry); - - /** - * Access the final geometry of animated widget. - * - * \todo: check if it was set and case negative, handle the error. - * @return Target geometry. - */ - QRectF targetGeometry() const; - /** - * Set the final geometry of animated widget. - * - * See also \ref setStartGeometry. - * @param geometry Returns the target geometry of animated widget. - */ - void setTargetGeometry(const QRectF &geometry); - -protected: - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - void updateEffectiveTime(int currentTime); - -private: - /** Initial geometry */ - QRectF m_startGeometry; - /** Final geometry */ - QRectF m_targetGeometry; -}; - -} // PLASMA_ANIMATIONS_GEOMETRY_P_H - -#endif diff --git a/animations/grow.cpp b/animations/grow.cpp deleted file mode 100644 index 40a576b4b..000000000 --- a/animations/grow.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * - * 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 "grow_p.h" - -#include -#include - -namespace Plasma -{ - -GrowAnimation::GrowAnimation(QObject *parent, qreal factor) - : EasingAnimation(parent), m_animFactor(factor) -{ -} - -void GrowAnimation::setFactor(const qreal factor) -{ - m_animFactor = qMax(qreal(0.0), factor); -} - -qreal GrowAnimation::factor() const -{ - return m_animFactor; -} - -void GrowAnimation::updateEffectiveTime(int currentTime) -{ - QGraphicsWidget *w = targetWidget(); - if (w && state() == QAbstractAnimation::Running) { - const qreal delta = currentTime / qreal(duration()); - QRectF geometry; - geometry.setTopLeft(m_startGeometry.topLeft() * (1-delta) + (m_targetGeometry.topLeft() * delta)); - geometry.setSize(m_startGeometry.size() * (1-delta) + (m_targetGeometry.size() * delta)); - w->setGeometry(geometry); - } -} - -void GrowAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) -{ - if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) { - QGraphicsWidget *widget = targetWidget(); - if (!widget) { - return; - } - - QSizeF minimum = widget->effectiveSizeHint(Qt::MinimumSize); - QSizeF maximum = widget->effectiveSizeHint(Qt::MaximumSize); - m_startGeometry = widget->geometry(); - qreal w = m_startGeometry.width(); - qreal h = m_startGeometry.height(); - qreal factor = m_animFactor; - - //compute new geometry values - qreal newWidth; - qreal newHeight; - if (direction() == QAbstractAnimation::Forward) { - newWidth = qBound(minimum.width(), w * factor, maximum.width()); - newHeight = qBound(minimum.height(), h * factor, maximum.height()); - } else { - newWidth = qBound(minimum.width(), w / factor, maximum.width()); - newHeight = qBound(minimum.height(), h / factor, maximum.height()); - } - - qreal newX; - qreal newY; - newX = m_startGeometry.x() - (newWidth - w)/2; - newY = m_startGeometry.y() - (newHeight - h)/2; - - if (direction() == QAbstractAnimation::Forward) { - //the end geometry gets rounded to prevent things looking ugly - m_targetGeometry = QRect(newX, newY, newWidth, newHeight); - } else { - m_targetGeometry = m_startGeometry; - m_startGeometry = QRectF(newX, newY, newWidth, newHeight); - } - } -} - -} //namespace Plasma - -#include "moc_grow_p.cpp" - diff --git a/animations/grow_p.h b/animations/grow_p.h deleted file mode 100644 index f16094e57..000000000 --- a/animations/grow_p.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * - * 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. - */ - -/** - * @file This file contains the definition for the Grow effect. - */ - -#ifndef PLASMA_ANIMATIONS_GROW_P_H -#define PLASMA_ANIMATIONS_GROW_P_H - -#include -#include - -namespace Plasma -{ - -/** - * @class GrowAnimation plasma/animations/grow.h - * @short Grow effect - * - * Effect that grows any QGraphicsWidget by a multiple given in the - * constructor. The center of the object stays in place while the sides grow - * (it does the animation by changing the objects geometry). Also see - * \ref ZoomAnimation. - */ -class GrowAnimation : public EasingAnimation -{ - Q_OBJECT - Q_PROPERTY(qreal factor READ factor WRITE setFactor) - -public: - /** Default Constructor - * @param parent Animation object parent. - * @param factor Expand factor (default is twice the size of - * animated widget). - */ - explicit GrowAnimation(QObject *parent = 0, qreal factor = 2); - - /** Destructor */ - virtual ~GrowAnimation(){}; - - /** - * Access expansion factor of the shadow pulsable copy. - * - * If not set, the default is twice (2x) the size of animated widget. - * See \ref setFactor. - * @return Expansion factor. - */ - qreal factor() const; - /** - * Set expansion factor of target widget. - * - * If not set, the default is twice (2x) the size of animated widget. - * @param factor A expansion factor - */ - void setFactor(const qreal factor); - -protected: - void updateEffectiveTime(int currentTime); - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - -private: - /** Animation grow factor */ - qreal m_animFactor; - /** Widget start geometry */ - QRectF m_startGeometry; - /** Widget final geometry */ - QRectF m_targetGeometry; -}; - -} - -#endif // PLASMA_ANIMATIONS_GROW_P_H diff --git a/animations/pendulumcurve.cpp b/animations/pendulumcurve.cpp deleted file mode 100644 index 8a328843c..000000000 --- a/animations/pendulumcurve.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2010 Bruno Abinader - * - * 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 . - */ - -#include "pendulumcurve_p.h" - -/** - * This static method is used to create a custom easing curve type. - * @param progress animation progress value - * @return pendulum easing curve progress value - */ -static qreal pendulumFunction(qreal progress) -{ - if (progress <= 0.25) { - progress *= 4; - } else if (progress <= 0.50) { - progress -= 0.25; - progress *= 4; - progress = 1 - progress; - } else if (progress <= 0.75) { - progress -= 0.50; - progress *= -4; - } else { - progress -= 0.75; - progress *= 4; - progress = 1 - progress; - progress *= -1; - } - return progress; -} - -namespace Plasma -{ - -PendulumCurve::PendulumCurve() - : QEasingCurve() -{ - setCustomType(pendulumFunction); -} - -} // namespace Plasma diff --git a/animations/pendulumcurve_p.h b/animations/pendulumcurve_p.h deleted file mode 100644 index b46d6912a..000000000 --- a/animations/pendulumcurve_p.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2010 Bruno Abinader - * - * 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 . - */ - -#ifndef PLASMA_ANIMATIONS_PENDULUMCURVE_P_H -#define PLASMA_ANIMATIONS_PENDULUMCURVE_P_H - -#include - -namespace Plasma -{ - -/* - * @class PendulumCurve plasma/animations/pendulumcurve.h - * @shot Pendulum Easing Curve - * - * This easing curve provides values which are split in 4 parts: - * from 0 to 1, from 1 to 0, from 0 to -1, and from -1 to 0, in a linear way. - */ -class PendulumCurve : public QEasingCurve -{ -public: - /** - * default constructor - */ - PendulumCurve(); -}; - -} // namespace Plasma - -#endif // PLASMA_ANIMATIONS_PENDULUMCURVE_P_H diff --git a/animations/pixmaptransition.cpp b/animations/pixmaptransition.cpp deleted file mode 100644 index c56d8ce7b..000000000 --- a/animations/pixmaptransition.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * Copyright 2010 Marco Martin - * - * 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 "pixmaptransition_p.h" - -#include -#include - -#include - -#include "paintutils.h" - -namespace Plasma -{ - -PixmapTransition::PixmapTransition(QObject *parent) - : EasingAnimation(parent), - m_cache(false), - m_dirty(false) -{ -} - -PixmapTransition::~PixmapTransition() -{ -} - -void PixmapTransition::setStartPixmap(const QPixmap &pixmap) -{ - if (state() == Running) { - stop(); - } - - m_startPixmap = pixmap; - - //this will center the pixmaps if needed - updateEffectiveTime(0); -} - -QPixmap PixmapTransition::startPixmap() const -{ - return m_startPixmap; -} - -void PixmapTransition::setTargetPixmap(const QPixmap &pixmap) -{ - if (state() == Running) { - stop(); - } - - m_targetPixmap = pixmap; - - updateEffectiveTime(0); -} - -void PixmapTransition::setUsesCache(bool cache) -{ - m_cache = cache; -} - -bool PixmapTransition::usesCache() const -{ - return m_cache; -} - -QPixmap PixmapTransition::targetPixmap() const -{ - return m_targetPixmap; -} - -QPixmap PixmapTransition::currentPixmap() const -{ - if (m_cache && !m_dirty) { - return m_currentPixmap; - } - - QPixmap currentPixmap; - qreal delta = currentTime() / qreal(duration()); - if (!m_startPixmap.isNull() && !m_targetPixmap.isNull()) { - //kDebug() << "transitioning"; - currentPixmap = Plasma::PaintUtils::transition(m_startPixmap, m_targetPixmap, delta); - } else if (m_startPixmap.isNull()) { - if (qFuzzyCompare(delta, qreal(1.0))) { - currentPixmap = alignedTargetPixmap(); - return currentPixmap; - } - - if (currentPixmap.isNull()) { - currentPixmap = QPixmap(m_pixmapSize); - } - - currentPixmap.fill(QColor(0, 0, 0, (int)(((qreal)255)*delta))); - QPainter p(¤tPixmap); - p.setCompositionMode(QPainter::CompositionMode_SourceIn); - //kDebug() << "painting" << m_targetPixmap.rect() << "into" << m_targetRect << "in size" << currentPixmap.size(); - p.drawPixmap(m_targetRect, m_targetPixmap); - p.end(); - } else if (m_targetPixmap.isNull()) { - currentPixmap = alignedStartPixmap(); - if (qFuzzyCompare(delta, qreal(1.0))) { - return m_currentPixmap; - } - //kDebug() << "painting" << m_startPixmap.rect() << "into" << m_targetRect << "in size" << currentPixmap.size(); - QPainter p(¤tPixmap); - p.setCompositionMode(QPainter::CompositionMode_DestinationIn); - p.fillRect(currentPixmap.rect(), QColor(0, 0, 0, (int)(254 - ((qreal)254)*delta))); - p.end(); - } - - if (m_cache) { - const_cast(this)->m_currentPixmap = currentPixmap; - } - - return currentPixmap; -} - -QPixmap PixmapTransition::alignedTargetPixmap() const -{ - QPixmap pm(m_pixmapSize); - pm.fill(Qt::transparent); - QPainter p(&pm); - p.drawPixmap(m_targetRect, m_targetPixmap); - return pm; -} - -QPixmap PixmapTransition::alignedStartPixmap() const -{ - QPixmap pm(m_pixmapSize); - pm.fill(Qt::transparent); - QPainter p(&pm); - p.drawPixmap(m_startRect, m_startPixmap); - return pm; -} - -void PixmapTransition::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) -{ - if (oldState == Stopped && newState == Running) { - m_targetRect = m_targetPixmap.rect(); - m_startRect = m_startPixmap.rect(); - m_pixmapSize = m_startRect.size().expandedTo(m_targetRect.size()); - QRect actualRect = QRect(QPoint(0,0), m_pixmapSize); - m_targetRect.moveCenter(actualRect.center()); - m_startRect.moveCenter(actualRect.center()); - } else if (QGraphicsWidget *w = targetWidget()) { - w->update(); - } - - m_dirty = true; -} - -void PixmapTransition::updateEffectiveTime(int currentTime) -{ - Q_UNUSED(currentTime) - m_dirty = true; - QGraphicsWidget *w = targetWidget(); - if (w) { - w->update(); - } -} - -} //namespace Plasma - -#include "moc_pixmaptransition_p.cpp" diff --git a/animations/pixmaptransition_p.h b/animations/pixmaptransition_p.h deleted file mode 100644 index 281b676c8..000000000 --- a/animations/pixmaptransition_p.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * Copyright 2010 Marco Martin - * - * 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. - */ - -/** - * @file This file contains the definition for the PixmapTransition effect. - */ - -#ifndef PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H -#define PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H - -#include -#include - -namespace Plasma -{ - -/** - * @class Fade plasma/animations/pixmaptransition.h - * @short PixmapTransition effect - * - * Effect that paints a transition between two pixmaps - */ -class PixmapTransition : public EasingAnimation -{ - Q_OBJECT - Q_PROPERTY(QPixmap startPixmap READ startPixmap WRITE setStartPixmap) - Q_PROPERTY(QPixmap targetPixmap READ targetPixmap WRITE setTargetPixmap) - Q_PROPERTY(bool usesCache READ usesCache WRITE setUsesCache) - Q_PROPERTY(QPixmap currentPixmap READ currentPixmap) - -public: - explicit PixmapTransition(QObject *parent = 0); - - virtual ~PixmapTransition(); - - /** - * @return The first pixmap of the animation - */ - QPixmap startPixmap() const; - - /** - * Set the first pixmap of the animation - */ - void setStartPixmap(const QPixmap &); - - /** - * The pixmap the animation will evolve to - */ - QPixmap targetPixmap() const; - - /** - * Set the pixmap the animation will evolve to - */ - void setTargetPixmap(const QPixmap &); - - /** - * @return the current pixmap - */ - QPixmap currentPixmap() const; - - /** - * Enable caching of the resulting pixmap, otherwise it will be regenerated on - * each call to currentPixmap; for elements which already have their own caching - * this is not a problem. - */ - void setUsesCache(bool cache); - - /** - * @return whether or not caching is on - */ - bool usesCache() const; - -protected: - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - void updateEffectiveTime(int currentTime); - -private: - QPixmap alignedTargetPixmap() const; - QPixmap alignedStartPixmap() const; - -private: - QPixmap m_startPixmap; - QPixmap m_targetPixmap; - QPixmap m_currentPixmap; - QRect m_startRect; - QRect m_targetRect; - QSize m_pixmapSize; - bool m_cache; - bool m_dirty; -}; - -} - -#endif // PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H diff --git a/animations/pulser.cpp b/animations/pulser.cpp deleted file mode 100644 index 7bacf34c1..000000000 --- a/animations/pulser.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* Copyright (C) 2009 Adenilson Cavalcanti - * - * 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 "widgetsnapshot_p.h" -#include "pulser_p.h" - -#include -#include -#include -#include -#include - -#include - -namespace Plasma -{ - -PulseAnimation::PulseAnimation(QObject *parent) - : EasingAnimation(parent), - m_zvalue(0), - m_scale(0), - m_opacity(0), - m_endScale(1.5) -{ -} - -PulseAnimation::~PulseAnimation() -{ - delete m_under.data(); -} - -void PulseAnimation::setTargetScale(qreal scale) -{ - m_endScale = scale; -} - -qreal PulseAnimation::targetScale() const -{ - return m_endScale; -} - -void PulseAnimation::setCopy() -{ - QGraphicsWidget *target = targetWidget(); - - if (!target) { - m_under.clear(); - return; - } - - if (!m_under.data()) { - m_under = new WidgetSnapShot; - } - - m_under.data()->setTarget(target); - - m_zvalue = target->zValue() - 1; - m_scale = target->scale(); - - m_under.data()->setOpacity(m_opacity); - m_under.data()->setScale(m_scale); - m_under.data()->setZValue(m_zvalue); -} - -void PulseAnimation::resetPulser() -{ - if (m_under.data()) { - m_under.data()->setOpacity(m_opacity); - m_under.data()->setScale(m_scale); - m_under.data()->setZValue(m_zvalue); - m_under.data()->hide(); - } -} - -void PulseAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) -{ - if (!targetWidget()) { - return; - } - - if (oldState == Stopped && newState == Running) { - if (!m_under.data() || m_under.data()->target() != targetWidget() || m_under.data()->size() != targetWidget()->size()) { - setCopy(); - } - - if (m_under.data()->isIconBigger()) { - m_under.data()->setScale(0); - m_endScale = 1.0; - - } else { - m_scale = 0; - m_endScale = 1.5; - } - - if (m_under.data()->isVisible() == false) { - m_under.data()->setVisible(true); - } - - m_under.data()->setOpacity(direction() == Forward ? 1 : 0); - m_under.data()->setScale(direction() == Forward ? m_scale : m_endScale); - } else if (newState == Stopped) { - resetPulser(); - } -} - -void PulseAnimation::updateEffectiveTime(int currentTime) -{ - if (m_under.data()) { - qreal delta = currentTime / qreal(duration()); - - if (m_under.data()->isIconBigger()) { - m_under.data()->setScale(delta); - } else { - m_under.data()->setScale(delta); - delta = (1 - m_endScale) * delta; - m_under.data()->setScale(1 - delta); - } - - delta = currentTime / qreal(duration()); - if (direction() == Forward) { - m_under.data()->setOpacity(1.0 - delta); - } else if (direction() == Backward) { - m_under.data()->setOpacity(delta); - } - } -} - -} //namespace Plasma - -#include "moc_pulser_p.cpp" diff --git a/animations/pulser_p.h b/animations/pulser_p.h deleted file mode 100644 index 6636999bb..000000000 --- a/animations/pulser_p.h +++ /dev/null @@ -1,110 +0,0 @@ -/* Copyright (C) 2009 Adenilson Cavalcanti - * - * 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. - */ - -/** - * @file This file contains the definition for the Pulse effect. - */ - -#ifndef PLASMA_ANIMATIONS_PULSER_P_H -#define PLASMA_ANIMATIONS_PULSER_P_H - -#include -#include - -namespace Plasma -{ - -class WidgetSnapShot; - -/** - * @class PulseAnimation plasma/animations/pulser_p.h - * @short Pulse effect - * - * Effect that pulses a shadow copy of any QGraphicsWidget making - * it more translucent and bigger along the time until it vanishes. - */ -class PulseAnimation : public EasingAnimation -{ - Q_OBJECT - Q_PROPERTY(qreal targetScale READ targetScale WRITE setTargetScale) - -public: - /** Default Constructor */ - explicit PulseAnimation(QObject *parent = 0); - - /** Destructor */ - ~PulseAnimation(); - - /** Pulse scale factor. - * - * How much the pulsed shadow will expand (the default is 1.5x the - * size of pulsed widget). - * - * @param scale Pulse scale value (should be bigger than 1.0). - */ - void setTargetScale(qreal scale); - - /** Returns pulsed scale factor. - * - * The amount of pulsed shadow factor used (default is 1.5x the size - * of widget). - */ - qreal targetScale() const; - - /** - * Resets the shadow widget to its initial state (full translucent - * and with same geometry as the target widget). It is executed - * when the animation is over. - */ - void resetPulser(); - -protected: - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - void updateEffectiveTime(int currentTime); - void setCopy(); - -private: - /** Zvalue (tipically -1 than the target widget) */ - qreal m_zvalue; - - /** Original widget scale */ - qreal m_scale; - - /** Opacity of shadow widget (full translucent) */ - qreal m_opacity; - - /** Target scale of shadow widget (default is 1.5x the animated - * widget scale). - */ - qreal m_endScale; - - /** The shadow copy (it really is a QGraphicsWidget with a pixmap - * copy of the original widget). - */ - QWeakPointer m_under; -}; - -} - -#endif // PLASMA_ANIMATIONS_PULSER_P_H - - - - - - diff --git a/animations/rotation.cpp b/animations/rotation.cpp deleted file mode 100644 index 2930cab86..000000000 --- a/animations/rotation.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - Copyright (C) 2009 Igor Trindade Oliveira - Copyright (C) 2009 Adenilson Cavalcanti - - 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 . -*/ - -#include -#include -#include - -#include "kdebug.h" - -#include "rotation_p.h" - -namespace Plasma -{ - -RotationAnimation::RotationAnimation(QObject *parent, qint8 reference, Qt::Axis axis, qreal angle) - : EasingAnimation(parent), - m_rotation(new QGraphicsRotation(this)), - m_angle(angle), - m_axis(axis), - m_reference(reference) -{ -} - -RotationAnimation::~RotationAnimation() -{ -} - -Qt::Axis RotationAnimation::axis() const -{ - return m_axis; -} - -void RotationAnimation::setAxis(const Qt::Axis &axis) -{ - m_axis = axis; -} - -qint8 RotationAnimation::reference() const -{ - return m_reference; -} - -void RotationAnimation::setReference(const qint8 &reference) -{ - m_reference = reference; -} - -qreal RotationAnimation::angle() const -{ - return m_angle; -} - -void RotationAnimation::setAngle(const qreal &angle) -{ - m_angle = angle; -} - -void RotationAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) -{ - Q_UNUSED(newState) - Q_UNUSED(oldState) - QGraphicsWidget *m_object = targetWidget(); - - if (!m_object) { - return; - } - - QVector3D vector(0, 0, 0); - - const qreal widgetWidth = m_object->size().width(); - const qreal widgetHeight = m_object->size().height(); - - if (axis() == Qt::XAxis) { - switch (reference()) { - case Center: - vector.setX(widgetWidth/2); - vector.setY(widgetHeight/2); - break; - case Up: - vector.setX(widgetWidth/2); - vector.setY(0); - break; - case Down: - vector.setX(widgetWidth/2); - vector.setY(widgetHeight); - break; - } - - } else if(axis() == Qt::YAxis) { - switch (reference()) { - case Center: - vector.setX(widgetWidth/2); - vector.setY(widgetHeight/2); - break; - case Left: - vector.setX(0); - vector.setY(widgetHeight/2); - break; - case Right: - vector.setX(widgetWidth); - vector.setY(widgetHeight/2); - break; - } - - } else if (axis() == Qt::ZAxis) { - switch (reference()) { - case Center: - vector.setX(widgetWidth/2); - vector.setY(widgetHeight/2); - break; - - case Center|Up: - vector.setX(widgetWidth/2); - vector.setY(0); - break; - - case Center|Down: - vector.setX(widgetWidth/2); - vector.setY(widgetHeight); - break; - - case Center|Left: - vector.setX(0); - vector.setY(widgetHeight/2); - break; - - case Center|Right: - vector.setX(widgetWidth); - vector.setY(widgetHeight/2); - break; - } - } - - m_rotation->setOrigin(vector); - m_rotation->setAxis(axis()); - - QList transformation; - transformation.append(m_rotation); - m_object->setTransformations(transformation); -} - -void RotationAnimation::updateEffectiveTime(int currentTime) -{ - if (targetWidget()) { - qreal delta = currentTime * angle() / qreal(duration()); - m_rotation->setAngle(delta); - } -} - -} - -#include "moc_rotation_p.cpp" diff --git a/animations/rotation_p.h b/animations/rotation_p.h deleted file mode 100644 index 30d3d7930..000000000 --- a/animations/rotation_p.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - Copyright (C) 2009 Igor Trindade Oliveira - Copyright (C) 2009 Adenilson Cavalcanti - - 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 . -*/ - -/** - * @file This file contains the definition for the 2D Rotation effect. - */ - -#ifndef PLASMA_ROTATION_P_H -#define PLASMA_ROTATION_P_H - -#include - -class QGraphicsRotation; - -namespace Plasma { -/** - * @class RotationAnimation plasma/animations/rotation_p.h - * @short 2D rotation animation. - * - * This animation rotates a QGraphicsWidget in a axis (reference and - * axis can be defined using properties). See also - * \ref StackedRotationAnimation. - */ -class RotationAnimation : public EasingAnimation -{ - - Q_OBJECT - Q_PROPERTY(Qt::Axis axis READ axis WRITE setAxis) - Q_PROPERTY(qint8 reference READ reference WRITE setReference) - Q_PROPERTY(qreal angle READ angle WRITE setAngle) - -public: - /** - * Default constructor - * - * @param parent Animation object parent. - * @param reference See \ref Animation::Reference. - * @param axis Which axis to rotate (XAxis, YAxis, ZAxis). - * @param angle Rotation angle (0 to 360) - * - */ - explicit RotationAnimation(QObject *parent = 0, - qint8 reference = Center, - Qt::Axis axis = Qt::ZAxis, - qreal angle = 180); - - /** Destructor */ - ~RotationAnimation(); - - /** - * get animation rotation axis (e.g. YAxis, ZAxis, XAxis) - */ - Qt::Axis axis() const; - - /** - * Rotation reference (e.g. Center, Up, Down, Left, Right) can - * be combined (i.e. Center|Up) - */ - qint8 reference() const; - - /** - * Animation rotation angle (e.g. 45, 180, etc) - */ - qreal angle() const; - - /** - * Reimplemented from Plasma::Animation - * @param curve Easing curve - */ - void setEasingCurve(const QEasingCurve &curve); - -public slots: - /** - * set animation rotation axis - * @param axis Rotation (e.g. YAxis, ZAxis, XAxis) - */ - void setAxis(const Qt::Axis &axis); - - /** - * Set rotation reference (e.g. Center, Up, Down, Left, Right) can - * be combined (i.e. Center|Up) - * @param reference The reference - */ - void setReference(const qint8 &reference); - - /** - * Set animation rotation angle (e.g. 45, 180, etc) - * @param angle The angle - */ - void setAngle(const qreal &angle); - -protected: - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - void updateEffectiveTime(int currentTime); - -private: - /** Rotation transform object */ - QGraphicsRotation *m_rotation; - /** Rotation angle */ - qreal m_angle; - /** Axis where to perform the rotation */ - Qt::Axis m_axis; - /** Reference, the default is Up (see \ref Animation::Reference) */ - qint8 m_reference; -}; -} // Plasma - -#endif diff --git a/animations/rotationstacked.cpp b/animations/rotationstacked.cpp deleted file mode 100644 index 70cac4539..000000000 --- a/animations/rotationstacked.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/* - Copyright (C) 2009 Igor Trindade Oliveira - - 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 . -*/ - -#include "rotationstacked_p.h" -#include -#include -#include -#include - -#include "stackedlayout.h" -#include "plasma.h" - -namespace Plasma -{ - -const int RotationStackedAnimation::s_sideAngle = 90; - -RotationStackedAnimation::RotationStackedAnimation(QObject *parent) - : EasingAnimation(parent) -{ - m_backRotation = new QGraphicsRotation(this); - m_frontRotation = new QGraphicsRotation(this); - m_wLayout = new StackedLayout; -} - -RotationStackedAnimation::~RotationStackedAnimation() -{ - delete m_wLayout.data(); -} - -void RotationStackedAnimation::setMovementDirection(const Animation::MovementDirection &direction) -{ - m_animDirection = direction; - - QVector3D animDirection(0, 0, 0); - - if (m_animDirection.testFlag(MoveUp)) { - animDirection.setX(1); - } else if (m_animDirection.testFlag(MoveDown)) { - animDirection.setX(-1); - } - - if (m_animDirection.testFlag(MoveLeft)) { - animDirection.setY(-1); - } else if (m_animDirection.testFlag(MoveRight)) { - animDirection.setY(1); - } - - m_frontRotation->setAxis(animDirection); - m_backRotation->setAxis(animDirection); - - updateTransformations(); -} - -Animation::MovementDirection RotationStackedAnimation::movementDirection() const -{ - return m_animDirection; -} - -void RotationStackedAnimation::setReference(const Animation::Reference &reference) -{ - m_animReference = reference; - - if (!targetWidget() || !backWidget()) { - return; - } - - const QSizeF transformArea = targetWidget()->size().expandedTo(backWidget()->size()); - - QVector3D frontTransformOrigin(transformArea.width()/2, transformArea.height()/2, 0); - QVector3D backTransformOrigin(transformArea.width()/2, transformArea.height()/2, 0); - - if (m_animReference.testFlag(Up)) { - frontTransformOrigin.setY(0); - backTransformOrigin.setY(0); - } else if (m_animReference.testFlag(Down)) { - frontTransformOrigin.setY(transformArea.height()); - backTransformOrigin.setY(transformArea.height()); - } - - if (m_animReference.testFlag(Left)) { - frontTransformOrigin.setX(0); - backTransformOrigin.setX(0); - } else if (m_animReference.testFlag(Right)) { - frontTransformOrigin.setX(transformArea.width()); - backTransformOrigin.setX(transformArea.width()); - } - - m_frontRotation->setOrigin(frontTransformOrigin); - m_backRotation->setOrigin(backTransformOrigin); - - updateTransformations(); -} - -Animation::Reference RotationStackedAnimation::reference() const -{ - return m_animReference; -} - -QGraphicsWidget *RotationStackedAnimation::backWidget() -{ - return m_backWidget.data(); -} - -void RotationStackedAnimation::setBackWidget(QGraphicsWidget *backWidget) -{ - m_backWidget = backWidget; - - StackedLayout *layout = m_wLayout.data(); - - if(targetWidget() && backWidget && layout) { - layout->addWidget(targetWidget()); - layout->addWidget(backWidget); - } -} - -QGraphicsLayoutItem *RotationStackedAnimation::layout() -{ - return m_wLayout.data(); -} - -void RotationStackedAnimation::updateState(QAbstractAnimation::State newState, - QAbstractAnimation::State oldState) -{ - if (oldState == Stopped && newState == Running) { - setReference(reference()); - } -} - -void RotationStackedAnimation::updateEffectiveTime(int currentTime) -{ - if (!targetWidget() || !backWidget()) { - return; - } - - StackedLayout *layout = m_wLayout.data(); - if (!layout) { - return; - } - - qreal delta; - if (currentTime <= duration()/2) { - layout->setCurrentWidgetIndex(0); - delta = (currentTime*2) / qreal(duration()); - delta *= s_sideAngle; - m_frontRotation->setAngle(delta); - } else { - layout->setCurrentWidgetIndex(1); - delta = 1 - (((currentTime*2) - duration()) / qreal(duration())); - delta = -delta; - delta *= s_sideAngle; - m_backRotation->setAngle(delta); - } -} - -void RotationStackedAnimation::updateTransformations() -{ - if (!targetWidget() || !backWidget()) { - return; - } - - QList frontTransformation; - QList backTransformation; - - frontTransformation.append(m_frontRotation); - backTransformation.append(m_backRotation); - - targetWidget()->setTransformations(frontTransformation); - backWidget()->setTransformations(backTransformation); -} - -} //namespace Plasma - -#include "moc_rotationstacked_p.cpp" diff --git a/animations/rotationstacked_p.h b/animations/rotationstacked_p.h deleted file mode 100644 index 9ebefde75..000000000 --- a/animations/rotationstacked_p.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - Copyright (C) 2009 Igor Trindade Oliveira - - 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 . -*/ - -/** - * @file This file contains the definition for the StackedRotationAnimation. - */ - -#ifndef PLASMA_ROTATIONSTACKED_P_H -#define PLASMA_ROTATIONSTACKED_P_H - -#include -#include - -#include - -class QGraphicsRotation; -class StackedLayout; - -namespace Plasma { - -/* TODO: - * create a parent class for rotations - */ -/** - * @class RotationStackedAnimation plasma/animations/rotationstacked_p.h - * @short 3D like rotation animation - * Use this class when you want to rotate a widget along an axis (e.g. Y) - * and display a 'hidden' widget behind it. See also \ref RotationAnimation. - */ -class RotationStackedAnimation : public EasingAnimation -{ - Q_OBJECT - Q_PROPERTY(MovementDirection movementDirection READ movementDirection WRITE setMovementDirection) - Q_PROPERTY(Reference reference READ reference WRITE setReference) - Q_PROPERTY(QGraphicsLayoutItem* layout READ layout) - Q_PROPERTY(QGraphicsWidget* backWidget READ backWidget WRITE setBackWidget) - -public: - explicit RotationStackedAnimation(QObject *parent = 0); - - ~RotationStackedAnimation(); - - /** - * Set the animation movement direction (e.g. MoveAny, MoveUp, MoveDown, - * MoveLeft, MoveRight) which can be combined (i.e. MoveUp|MoveLeft). - * @param direction animation direction - */ - void setMovementDirection(const Animation::MovementDirection &direction); - - /** - * Get the animation movement direction. - */ - Animation::MovementDirection movementDirection() const; - - /** - * Set the animation rotation reference (e.g. Center, Up, Down, Left, - * Right) which can be combined (i.e. Center|Up). - * @param reference animation reference - */ - void setReference(const Animation::Reference &reference); - - /** - * Get the animation rotation reference. - */ - Animation::Reference reference() const; - - /** - * Get the layout where the widgetToAnimate and backWidget are. - */ - QGraphicsLayoutItem *layout(); - - /** - * Get the back widget - */ - - QGraphicsWidget *backWidget(); - - /** - * Set the back widget that is used after the animation to be finished - * @param backWidget The back widget - */ - void setBackWidget(QGraphicsWidget *backWidget); - -protected: - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - void updateEffectiveTime(int currentTime); - -private: - /** - * Updates the front and back widget rotation animation transformations, - * according to the given animation reference point and direction. - */ - void updateTransformations(); - - /** Animation reference (see \ref Animation::Reference) */ - Animation::Reference m_animReference; - /** Animation movement direction (see \ref Animation::MovementDirection) */ - Animation::MovementDirection m_animDirection; - /** Object the animation(s) should act upon. */ - QWeakPointer m_backWidget; - /** Layout where widget would be added */ - QWeakPointer m_wLayout; - /** Back Widget Rotation transform object */ - QGraphicsRotation *m_backRotation; - /** Front Widget Rotation transform object */ - QGraphicsRotation *m_frontRotation; - - static const int s_sideAngle; -}; -} // Plasma - -#endif // PLASMA_ROTATIONSTACKED_P_H diff --git a/animations/slide.cpp b/animations/slide.cpp deleted file mode 100644 index ee350f5ab..000000000 --- a/animations/slide.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * - * 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 "slide_p.h" - -#include -#include - -namespace Plasma -{ - -void SlideAnimation::setDistance(qreal distance) -{ - m_animDistance = QPointF(distance, 0.0); -} - -qreal SlideAnimation::distance() const -{ - return m_animDistance.x(); -} - -void SlideAnimation::setDistancePointF(const QPointF &distance) -{ - m_animDistance = distance; -} - -QPointF SlideAnimation::distancePointF() const -{ - return m_animDistance; -} - -SlideAnimation::~SlideAnimation() -{ -} - -SlideAnimation::SlideAnimation(QObject *parent, - MovementDirection direction, - qreal distance) : EasingAnimation(parent) -{ - setMovementDirection(direction); - setDistance(distance); - setEasingCurve(QEasingCurve::OutCirc); -} - -void SlideAnimation::setMovementDirection(const Animation::MovementDirection &direction) -{ - m_animDirection = direction; -} - -Animation::MovementDirection SlideAnimation::movementDirection() const -{ - return m_animDirection; -} - -void SlideAnimation::updateEffectiveTime(int currentTime) -{ - QGraphicsWidget *w = targetWidget(); - if (w && state() == QAbstractAnimation::Running) { - const qreal delta = currentTime / qreal(duration()); - w->setPos(m_startPos * (1-delta) + (m_targetPos * delta)); - } -} - -void SlideAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) -{ - if (oldState == QAbstractAnimation::Stopped && newState == QAbstractAnimation::Running) { - if (!targetWidget()) { - return; - } - m_startPos = targetWidget()->pos(); - - qreal newX = m_startPos.x(); - qreal newY = m_startPos.y(); - - QPointF actualDistance = (direction() == \ - QAbstractAnimation::Forward ? \ - distancePointF():-distancePointF()); - - bool moveAnyOnly = true; - - if (m_animDirection.testFlag(MoveUp)) { - newY -= actualDistance.x(); - moveAnyOnly = false; - } else if (m_animDirection.testFlag(MoveDown)) { - newY += actualDistance.x(); - moveAnyOnly = false; - } - - if (m_animDirection.testFlag(MoveRight)) { - newX += actualDistance.x(); - moveAnyOnly = false; - } else if (m_animDirection.testFlag(MoveLeft)) { - newX -= actualDistance.x(); - moveAnyOnly = false; - } - - if (moveAnyOnly && m_animDirection.testFlag(MoveAny)) { - newX += actualDistance.x(); - newY += actualDistance.y(); - } - - if (direction() == QAbstractAnimation::Forward) { - m_targetPos = QPointF(newX, newY); - } else { - m_targetPos = m_startPos; - m_startPos = QPointF(newX, newY); - } - } -} - -} //namespace Plasma - -#include "moc_slide_p.cpp" diff --git a/animations/slide_p.h b/animations/slide_p.h deleted file mode 100644 index 23952613d..000000000 --- a/animations/slide_p.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2009 Mehmet Ali Akmanalp - * - * 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. - */ - -/** - * @file This file contains the definition for the Slide effect. - */ - -#ifndef PLASMA_ANIMATIONS_SLIDE_P_H -#define PLASMA_ANIMATIONS_SLIDE_P_H - -#include "plasma/animations/easinganimation_p.h" -#include "plasma/plasma_export.h" -#include "plasma/plasma.h" - -namespace Plasma -{ - -class SlideAnimationPrivate; -/** - * @class Slide plasma/animations/slide.h - * @short Slide effect - * - * Effect that moves the object a specific distance in a given direction. The - * object is optionally made invisible at the beginning or at the end. - */ -class SlideAnimation : public EasingAnimation -{ - Q_OBJECT - Q_PROPERTY(qreal distance READ distance WRITE setDistance) - Q_PROPERTY(MovementDirection movementDirection READ movementDirection WRITE setMovementDirection) - Q_PROPERTY(QPointF distancePointF READ distancePointF WRITE setDistancePointF) - -public: - explicit SlideAnimation(QObject *parent = 0, MovementDirection direction = MoveUp, qreal distance = 0); - ~SlideAnimation(); - - /** - * Set the animation distance - * @distance animation distance - */ - void setDistance(qreal distance); - - /** - * Get the animation distance - */ - qreal distance() const; - - void setDistancePointF(const QPointF &distance); - QPointF distancePointF() const; - - /** - * Set the animation direction - * @param direction animation direction - */ - void setMovementDirection(const Animation::MovementDirection&direction); - - /** - * Get the animation direction - */ - Animation::MovementDirection movementDirection() const; - -protected: - void updateEffectiveTime(int currentTime); - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - -private: - /** - * Animation direction: where the animation will move. - */ - Animation::MovementDirection m_animDirection; - - /** - * Animation distance: displacement factor for animations where - * there is change in the position of animated widget. - */ - QPointF m_animDistance; - QPointF m_startPos; - QPointF m_targetPos; -}; - -} - -#endif // PLASMA_ANIMATIONS_SLIDE_P_H diff --git a/animations/stackedlayout.cpp b/animations/stackedlayout.cpp deleted file mode 100644 index 46cb9ff67..000000000 --- a/animations/stackedlayout.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - Copyright (C) 2009 Igor Trindade Oliveira - - 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 . -*/ - -#include "stackedlayout.h" - -#include -#include - -StackedLayout::StackedLayout(QGraphicsLayoutItem *parent) - : QObject(0), - QGraphicsLayout(parent), - m_currentWidgetIndex(-1) -{ -} - -StackedLayout::~StackedLayout() -{ -} - -void StackedLayout::setGeometry(const QRectF &rect) -{ - QGraphicsLayout::setGeometry(rect); - - const QRectF effectiveRect = geometry(); - - for(int i = 0; i < items.size(); i++) { - itemAt(i)->setGeometry(effectiveRect); - } -} - -QSizeF StackedLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const -{ - Q_UNUSED(which); - Q_UNUSED(constraint); - - qreal left, top, right, bottom; - getContentsMargins(&left, &top, &right, &bottom); - - if (m_currentWidgetIndex <= 0 || !itemAt(m_currentWidgetIndex)) { - return QSizeF(); - } - - QSizeF currentWidgetSize = itemAt(m_currentWidgetIndex)->effectiveSizeHint(which, constraint); - - return QSizeF( left + right + currentWidgetSize.width(), right + bottom + currentWidgetSize.height()); -} - -int StackedLayout::count() const -{ - return items.count(); -} - -QGraphicsLayoutItem *StackedLayout::itemAt(int i) const -{ - return items.at(i); -} - -void StackedLayout::insertWidget(QGraphicsLayoutItem *item, int pos) -{ - if(!pos && (m_currentWidgetIndex == -1)) { - m_currentWidgetIndex = 0; - } else { - item->graphicsItem()->hide(); - } - - items.insert(pos, item); - activate(); -} - -void StackedLayout::addWidget(QGraphicsLayoutItem *item) -{ - insertWidget(item, items.size()); -} - -void StackedLayout::removeAt(int index) -{ - items.removeAt(index); -} - -void StackedLayout::setCurrentWidgetIndex(qint32 index) -{ - QGraphicsItem *currentWidget = itemAt(m_currentWidgetIndex)->graphicsItem(); - QGraphicsItem *hiddenWidget = itemAt(index)->graphicsItem(); - - currentWidget->hide(); - hiddenWidget->show(); - - m_currentWidgetIndex = index; -} - -qint32 StackedLayout::currentWidgetIndex() const -{ - return m_currentWidgetIndex; -} - -#include "moc_stackedlayout.cpp" diff --git a/animations/stackedlayout.h b/animations/stackedlayout.h deleted file mode 100644 index 465ef229a..000000000 --- a/animations/stackedlayout.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright (C) 2009 Igor Trindade Oliveira - - 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 . -*/ - -#ifndef STACKEDLAYOUT_H -#define STACKEDLAYOUT_H - -/* TODO: document the methods */ - -#include -#include -#include - -class StackedLayout : public QObject, public QGraphicsLayout -{ - Q_OBJECT - Q_INTERFACES(QGraphicsLayout) - -public: - explicit StackedLayout(QGraphicsLayoutItem *parent = 0); - ~StackedLayout(); - - void setGeometry(const QRectF &rect); - QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const; - int count() const; - QGraphicsLayoutItem *itemAt(int i) const; - - void insertWidget(QGraphicsLayoutItem *item, int pos); - void addWidget(QGraphicsLayoutItem *item); - - void removeAt(int index); - - qint32 currentWidgetIndex() const; - void setCurrentWidgetIndex(qint32 index); - - private: - QList items; - qint32 m_currentWidgetIndex; -}; - -#endif diff --git a/animations/widgetsnapshot.cpp b/animations/widgetsnapshot.cpp deleted file mode 100644 index a6416db52..000000000 --- a/animations/widgetsnapshot.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - Copyright (C) 2009 Adenilson Cavalcanti - - 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 . -*/ - -#include "widgetsnapshot_p.h" - -#include -#include -#include -#include -#include - -static const int RECURSION_MAX = 20; - -namespace Plasma -{ - -WidgetSnapShot::WidgetSnapShot(QGraphicsItem *parent) - : QGraphicsWidget(parent), - m_iconBig(false), - stack(0), - m_target(0) -{ -} - -WidgetSnapShot::~WidgetSnapShot() -{ -} - -void WidgetSnapShot::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(widget); - - painter->setRenderHint(QPainter::Antialiasing); - painter->drawPixmap(option->exposedRect, m_snapShot, option->exposedRect); -} - -void WidgetSnapShot::paintSubChildren(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QGraphicsItem *target) -{ - ++stack; - QList list = target->childItems(); - QGraphicsItem *tmp; - if (list.size() > 0) { - for (int i = 0; i < list.size(); ++i) { - tmp = list.value(i); - - if ((tmp->childItems().size() > 0) && (stack < RECURSION_MAX)) { - paintSubChildren(painter, option, tmp); - } - - if (tmp->isVisible()) { - tmp->paint(painter, option, 0); - } - } - } - --stack; -} - -void WidgetSnapShot::setTarget(QGraphicsWidget *target) -{ - stack = 0; - m_target = target; - setParentItem(target); - QSize size(target->size().toSize()); - m_iconBig = false; - - if (m_target->property("iconRepresentation").isValid()) { - m_iconBig = true; - m_snapShot = QPixmap::fromImage( - m_target->property("iconRepresentation").value()); - if ((m_snapShot.height() > 0) && (m_snapShot.width() > 0)) { - resize(m_snapShot.size()); - setTransformOriginPoint(target->geometry().center()); - return; - } - } - - resize(target->size()); - - m_snapShot = QPixmap(size); - m_snapShot.fill(Qt::transparent); - - QPainter painter(&m_snapShot); - painter.setCompositionMode(QPainter::CompositionMode_SourceOver); - painter.fillRect(target->rect(), Qt::transparent); - - QStyleOptionGraphicsItem style; - style.exposedRect = target->boundingRect(); - style.rect = target->rect().toRect(); - - target->paint(&painter, &style, 0); - paintSubChildren(&painter, &style, target); - painter.end(); - setTransformOriginPoint(geometry().center()); -} - -QGraphicsWidget *WidgetSnapShot::target() const -{ - return m_target; -} - - -bool WidgetSnapShot::isIconBigger() const -{ - return m_iconBig; -} - -QPixmap WidgetSnapShot::snapShot() const -{ - return m_snapShot; -} - -} diff --git a/animations/widgetsnapshot_p.h b/animations/widgetsnapshot_p.h deleted file mode 100644 index c65157bf4..000000000 --- a/animations/widgetsnapshot_p.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright (C) 2009 Adenilson Cavalcanti - - 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 . -*/ - -#ifndef PLASMA_WIDGETSNAPSHOT_P_H -#define PLASMA_WIDGETSNAPSHOT_P_H - -#include - -namespace Plasma -{ - -class WidgetSnapShot : public QGraphicsWidget -{ - Q_OBJECT - Q_PROPERTY(QGraphicsWidget *target READ target WRITE setTarget) - -public: - explicit WidgetSnapShot(QGraphicsItem *parent = 0); - virtual ~WidgetSnapShot(); - - virtual void setTarget(QGraphicsWidget *target); - QGraphicsWidget *target() const; - - virtual void paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QWidget *widget); - - bool isIconBigger() const; - - QPixmap snapShot() const; - -private: - void paintSubChildren(QPainter *painter, - const QStyleOptionGraphicsItem *option, - QGraphicsItem *target); - - bool m_iconBig; - int stack; - QPixmap m_snapShot; - QGraphicsWidget *m_target; -}; - -} // namespace Plasma - -#endif // PLASMA_WIDGETSNAPSHOT_P_H diff --git a/animations/zoom.cpp b/animations/zoom.cpp deleted file mode 100644 index 8f07317d5..000000000 --- a/animations/zoom.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2009 Igor Trindade Oliveira - * - * 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 "zoom_p.h" - -#include - -namespace Plasma -{ - -ZoomAnimation::ZoomAnimation(QObject *parent) - : EasingAnimation(parent), - m_zoom(0) -{ -} - -ZoomAnimation::~ZoomAnimation() -{ -} - -void ZoomAnimation::setZoom(qreal zoom) -{ - m_zoom = zoom; -} - -qreal ZoomAnimation::zoom() const -{ - return m_zoom; -} - -void ZoomAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) -{ - QGraphicsWidget *w = targetWidget(); - if (!w) { - return; - } - - if (oldState == Stopped && newState == Running) { - w->setTransformOriginPoint(w->size().width()/2, w->size().height()/2); - w->setScale(direction() == Forward ? 1 : m_zoom); - } else if (newState == Stopped) { - w->setScale(direction() == Forward ? m_zoom : 1); - } -} - -void ZoomAnimation::updateEffectiveTime(int currentTime) -{ - QGraphicsWidget *w = targetWidget(); - if (w) { - qreal delta = currentTime / qreal(duration()); - if (m_zoom != 1) { - delta = (1 - m_zoom) * delta; - w->setScale(1 - delta); - } else { - w->setScale(delta); - } - } -} - -} //namespace Plasma diff --git a/animations/zoom_p.h b/animations/zoom_p.h deleted file mode 100644 index 2c5868fe4..000000000 --- a/animations/zoom_p.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2009 Igor Trindade Oliveira - * - * 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. - */ - -/** - * @file This file contains the definition for the Zoom animation. - */ - -#ifndef PLASMA_ANIMATIONS_ZOOM_P_H -#define PLASMA_ANIMATIONS_ZOOM_P_H - -#include -#include - -namespace Plasma -{ - -/** - * @class ZoomAnimation plasma/animations/zoom_p.h - * @short Zoom Animation - * - */ -class ZoomAnimation : public EasingAnimation -{ - Q_OBJECT - Q_PROPERTY(qreal zoom READ zoom WRITE setZoom) - -public: - explicit ZoomAnimation(QObject *parent = 0); - virtual ~ZoomAnimation(); - - qreal zoom() const; - void setZoom(qreal); - -protected: - void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); - void updateEffectiveTime(int currentTime); - -private: - qreal m_zoom; -}; - -} - -#endif // PLASMA_ANIMATIONS_ZOOM_P_H diff --git a/animator.cpp b/animator.cpp deleted file mode 100644 index 99898070e..000000000 --- a/animator.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - Copyright (C) 2009 Adenilson Cavalcanti - - 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 . -*/ - -#include "animator.h" - -#include - -#include "animations/animation.h" -#include "animations/fade_p.h" -#include "animations/grow_p.h" -#include "animations/pulser_p.h" -#include "animations/rotation_p.h" -#include "animations/slide_p.h" -#include "animations/rotationstacked_p.h" -#include "animations/geometry_p.h" -#include "animations/zoom_p.h" -#include "animations/pixmaptransition_p.h" -#include "animations/pendulumcurve_p.h" -#include "theme.h" - -namespace Plasma -{ - -Animator::Animator(QObject *parent) - : QObject(parent), - d(0) -{ -} - -Plasma::Animation* Animator::create(Animator::Animation type, QObject *parent) -{ - Plasma::Animation *result = 0; - - switch (type) { - case FadeAnimation: - result = new Plasma::FadeAnimation(parent); - break; - - case GrowAnimation: - result = new Plasma::GrowAnimation(parent); - break; - - case PulseAnimation: - result = new Plasma::PulseAnimation(parent); - break; - - case RotationAnimation: - result = new Plasma::RotationAnimation(parent); - break; - - case RotationStackedAnimation: - result = new Plasma::RotationStackedAnimation(parent); - break; - - case SlideAnimation: - result = new Plasma::SlideAnimation(parent); - break; - - case GeometryAnimation: - result = new Plasma::GeometryAnimation(parent); - break; - - case ZoomAnimation: - result = new Plasma::ZoomAnimation(parent); - break; - - case PixmapTransitionAnimation: - result = new Plasma::PixmapTransition(parent); - break; - - default: - //kDebug() << "Unsupported animation type."; - break; - } - - return result; -} - -QEasingCurve Animator::create(Animator::CurveShape type) -{ - QEasingCurve result; - - switch (type) { - case EaseInCurve: - result.setType(QEasingCurve::InQuad); - break; - - case EaseOutCurve: - result.setType(QEasingCurve::OutQuad); - break; - - case EaseInOutCurve: - result.setType(QEasingCurve::InOutQuad); - break; - - case LinearCurve: - result.setType(QEasingCurve::Linear); - break; - - case PendularCurve: - result = PendulumCurve(); - break; - - default: -#ifndef NDEBUG - kDebug() << "Unsupported easing curve type."; -#endif - break; - } - - return result; -} - -} // namespace Plasma - -#include "moc_animator.cpp" diff --git a/animator.h b/animator.h deleted file mode 100644 index 6c4db6434..000000000 --- a/animator.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright 2007 Aaron Seigo - * 2007 Alexis Ménard - * - * 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_ANIMATOR_H -#define PLASMA_ANIMATOR_H - -#include -#include -#include -#include - -#include - -class QGraphicsItem; -class QGraphicsWidget; -class QTimeLine; - -namespace Plasma -{ - -class AnimatorPrivate; -class Animation; - -/** - * @class Animator plasma/animator.h - * - * @short A system for applying effects to Plasma elements - */ -class PLASMA_EXPORT Animator : public QObject -{ - Q_OBJECT - Q_ENUMS(Animation) - Q_ENUMS(CurveShape) - -public: - enum Animation { - AppearAnimation = 0, /*<< Animate the appearance of an element */ - DisappearAnimation, /*<< Animate the disappearance of an element */ - ActivateAnimation, /*<< When something is activated or launched, - such as an app icon being clicked */ - FadeAnimation, /*<< Can be used for both fade in and out */ - GrowAnimation, /*<< Grow animated object geometry */ - PulseAnimation, /*<< Pulse animated object (opacity/geometry/scale) */ - RotationAnimation, /*<< Rotate an animated object */ - RotationStackedAnimation, /*<< for flipping one object with another */ - SlideAnimation, /*<< Move the position of animated object */ - GeometryAnimation, /*<< Geometry animation*/ - ZoomAnimation, /*< - #include #include #include #include #include -#include -#include -#include #include #include #include -#include #include #include #include @@ -76,7 +70,6 @@ #include #endif -#include "abstracttoolbox.h" #include "authorizationrule.h" #include "configloader.h" #include "containment.h" @@ -87,15 +80,10 @@ #include "scripting/appletscript.h" #include "svg.h" #include "framesvg.h" -#include "popupapplet.h" -#include "private/applethandle_p.h" #include "private/framesvg_p.h" #include "remote/authorizationmanager.h" #include "remote/authorizationmanager_p.h" #include "theme.h" -#include "view.h" -#include "widgets/iconwidget.h" -#include "widgets/label.h" #include "tooltipmanager.h" #include "wallpaper.h" #include "paintutils.h" @@ -107,7 +95,6 @@ #include "private/package_p.h" #include "private/packages_p.h" #include "private/plasmoidservice_p.h" -#include "private/popupapplet_p.h" #include "private/remotedataengine_p.h" #include "private/service_p.h" #include "ui_publish.h" @@ -116,8 +103,8 @@ namespace Plasma { -Applet::Applet(const KPluginInfo &info, QGraphicsItem *parent, uint appletId) - : QGraphicsWidget(parent), +Applet::Applet(const KPluginInfo &info, QObject *parent, uint appletId) + : QObject(parent), d(new AppletPrivate(KService::Ptr(), &info, appletId, this)) { // WARNING: do not access config() OR globalConfig() in this method! @@ -125,8 +112,8 @@ Applet::Applet(const KPluginInfo &info, QGraphicsItem *parent, uint appletId) d->init(); } -Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId) - : QGraphicsWidget(parent), +Applet::Applet(QObject *parent, const QString &serviceID, uint appletId) + : QObject(parent), d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this)) { // WARNING: do not access config() OR globalConfig() in this method! @@ -134,8 +121,8 @@ Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId) d->init(); } -Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId, const QVariantList &args) - : QGraphicsWidget(parent), +Applet::Applet(QObject *parent, const QString &serviceID, uint appletId, const QVariantList &args) + : QObject(parent), d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this)) { // WARNING: do not access config() OR globalConfig() in this method! @@ -156,7 +143,7 @@ Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId, c } Applet::Applet(QObject *parentObject, const QVariantList &args) - : QGraphicsWidget(0), + : QObject(0), d(new AppletPrivate( KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()), 0, args.count() > 1 ? args[1].toInt() : 0, this)) @@ -186,7 +173,7 @@ Applet::Applet(QObject *parentObject, const QVariantList &args) } Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args) - : QGraphicsWidget(0), + : QObject(0), d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), 0, appletId, this)) { Q_UNUSED(args) // FIXME? @@ -205,7 +192,6 @@ Applet::~Applet() void Applet::init() { - setFlag(ItemIsMovable, true); if (d->script) { d->setupScriptSupport(); @@ -360,7 +346,11 @@ KConfigGroup Applet::globalConfig() const KConfigGroup globalAppletConfig; QString group = isContainment() ? "ContainmentGlobals" : "AppletGlobals"; - Corona *corona = qobject_cast(scene()); + Containment *cont = containment(); + Corona *corona = 0; + if (cont) { + corona = cont->corona(); + } if (corona) { KSharedConfig::Ptr coronaConfig = corona->config(); globalAppletConfig = KConfigGroup(coronaConfig, group); @@ -371,6 +361,87 @@ KConfigGroup Applet::globalConfig() const return KConfigGroup(&globalAppletConfig, d->globalName()); } +QSizeF Applet::size() const +{ + return QSizeF(); +} + +QRectF Applet::geometry() const +{ + return QRectF(); +} + +void Applet::setGeometry(const QRectF &rect) +{ + +} + +QRectF Applet::boundingRect() const +{ + return QRectF(); +} + +void Applet::resize(const QSizeF &size) +{ + +} + +int Applet::zValue() const +{ + return 0; +} + +void Applet::setZValue(int val) +{ + +} + +QTransform Applet::transform() const +{ + return QTransform(); +} + +void Applet::setTransform(const QTransform &transform) +{ + +} + +QPointF Applet::pos() const +{ + return QPointF(); +} + +void Applet::setPos(const QPointF &pos) +{ + +} + +void Applet::setPos(int x, int y) +{ + +} + +bool Applet::hasFocus() const +{ + return false; +} + +void Applet::setFocus(Qt::FocusReason) +{ + +} + +void Applet::setSizePolicy(const QSizePolicy& policy) +{ + +} + +QSizePolicy Applet::sizePolicy() const +{ + return QSizePolicy(); +} + + void Applet::destroy() { if (immutability() != Mutable || d->transient || !d->started) { @@ -402,47 +473,6 @@ Package Applet::package() const return d->package ? *d->package : Package(); } -QGraphicsView *Applet::view() const -{ - // It's assumed that we won't be visible on more than one view here. - // Anything that actually needs view() should only really care about - // one of them anyway though. - if (!scene()) { - return 0; - } - - QGraphicsView *found = 0; - QGraphicsView *possibleFind = 0; - //kDebug() << "looking through" << scene()->views().count() << "views"; - foreach (QGraphicsView *view, scene()->views()) { - //kDebug() << " checking" << view << view->sceneRect() - // << "against" << sceneBoundingRect() << scenePos(); - if (view->sceneRect().intersects(sceneBoundingRect()) || - view->sceneRect().contains(scenePos())) { - //kDebug() << " found something!" << view->isActiveWindow(); - if (view->isActiveWindow()) { - found = view; - } else { - possibleFind = view; - } - } - } - - return found ? found : possibleFind; -} - -QRectF Applet::mapFromView(const QGraphicsView *view, const QRect &rect) const -{ - // Why is this adjustment needed? Qt calculation error? - return mapFromScene(view->mapToScene(rect)).boundingRect().adjusted(0, 0, 1, 1); -} - -QRect Applet::mapToView(const QGraphicsView *view, const QRectF &rect) const -{ - // Why is this adjustment needed? Qt calculation error? - return view->mapFromScene(mapToScene(rect)).boundingRect().adjusted(0, 0, -1, -1); -} - QPoint Applet::popupPosition(const QSize &s) const { return popupPosition(s, Qt::AlignLeft); @@ -450,10 +480,16 @@ QPoint Applet::popupPosition(const QSize &s) const QPoint Applet::popupPosition(const QSize &s, Qt::AlignmentFlag alignment) const { - Corona * corona = qobject_cast(scene()); + Containment *cont = containment(); + Corona *corona = 0; + if (cont) { + corona = cont->corona(); + } Q_ASSERT(corona); - return corona->popupPosition(this, s, alignment); + return QPoint(); + //FIXME: port away from QGV + //return corona->popupPosition(this, s, alignment); } void Applet::updateConstraints(Plasma::Constraints constraints) @@ -589,8 +625,6 @@ ImmutabilityType Applet::immutability() const if (cont) { upperImmutability = cont->immutability(); - } else if (Corona *corona = qobject_cast(scene())) { - upperImmutability = corona->immutability(); } if (upperImmutability != Mutable) { @@ -628,48 +662,6 @@ void Applet::setBackgroundHints(const Plasma::BackgroundHints hints) } d->backgroundHints = hints; - d->preferredBackgroundHints = hints; - - //Draw the standard background? - if ((hints & StandardBackground) || (hints & TranslucentBackground)) { - if (!d->background) { - d->background = new Plasma::FrameSvg(this); - QObject::connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(themeChanged())); - } - - if ((hints & TranslucentBackground) && - Plasma::Theme::defaultTheme()->currentThemeHasImage("widgets/translucentbackground")) { - d->background->setImagePath("widgets/translucentbackground"); - } else { - d->background->setImagePath("widgets/background"); - } - - d->background->setEnabledBorders(Plasma::FrameSvg::AllBorders); - qreal left, top, right, bottom; - d->background->getMargins(left, top, right, bottom); - setContentsMargins(left, right, top, bottom); - QSizeF fitSize(left + right, top + bottom); - d->background->resizeFrame(boundingRect().size()); - - //if the background has an "overlay" element decide a random position for it and then save it so it's consistent across plasma starts - if (d->background->hasElement("overlay")) { - QSize overlaySize = d->background->elementSize("overlay"); - - //position is in the boundaries overlaySize.width()*2, overlaySize.height() - qsrand(id()); - d->background->d->overlayPos.rx() = - (overlaySize.width() /2) + (overlaySize.width() /4) * (qrand() % (4 + 1)); - d->background->d->overlayPos.ry() = (- (overlaySize.height() /2) + (overlaySize.height() /4) * (qrand() % (4 + 1)))/2; - } - } else if (d->background) { - qreal left, top, right, bottom; - d->background->getMargins(left, top, right, bottom); - - delete d->background; - d->background = 0; - setContentsMargins(0, 0, 0, 0); - } - - update(); } bool Applet::hasFailedToLaunch() const @@ -758,7 +750,11 @@ void Applet::flushPendingConstraintsEvents() } d->updateShortcuts(); - Corona * corona = qobject_cast(scene()); + Containment *cont = containment(); + Corona *corona = 0; + if (cont) { + corona = cont->corona(); + } if (corona) { connect(corona, SIGNAL(shortcutsChanged()), this, SLOT(updateShortcuts()), Qt::UniqueConnection); } @@ -779,46 +775,15 @@ void Applet::flushPendingConstraintsEvents() action->setEnabled(canConfig); } - if (!unlocked && d->handle) { - AppletHandle *h = d->handle.data(); - disconnect(this); - - QGraphicsScene *s = scene(); - if (s && h->scene() == s) { - s->removeItem(h); - } - - h->deleteLater(); - } - emit immutabilityChanged(immutability()); } if (c & Plasma::SizeConstraint) { d->positionMessageOverlay(); - - if (d->started && layout()) { - layout()->updateGeometry(); - } } if (c & Plasma::FormFactorConstraint) { FormFactor f = formFactor(); - if (!d->isContainment && f != Vertical && f != Horizontal) { - setBackgroundHints(d->preferredBackgroundHints); - } else { - BackgroundHints hints = d->preferredBackgroundHints; - setBackgroundHints(NoBackground); - d->preferredBackgroundHints = hints; - } - - if (d->failed) { - if (f == Vertical || f == Horizontal) { - QGraphicsLayoutItem *item = layout()->itemAt(1); - layout()->removeAt(1); - delete item; - } - } // avoid putting rotated applets in panels if (f == Vertical || f == Horizontal) { @@ -853,7 +818,6 @@ void Applet::flushPendingConstraintsEvents() setSizePolicy(d->preferredSizePolicy); } } - updateGeometry(); } // now take care of constraints in special subclasses: Contaiment and PopupApplet @@ -862,10 +826,12 @@ void Applet::flushPendingConstraintsEvents() containment->d->containmentConstraintsEvent(c); } + //FIXME: port away from popupapplet + /* PopupApplet* popup = qobject_cast(this); if (popup) { popup->d->popupConstraintsEvent(c); - } + }*/ // pass the constraint on to the actual subclass constraintsEvent(c); @@ -882,11 +848,6 @@ void Applet::flushPendingConstraintsEvents() } } -int Applet::type() const -{ - return Type; -} - QList Applet::contextualActions() { //kDebug() << "empty context actions"; @@ -903,105 +864,20 @@ void Applet::addAction(QString name, QAction *action) d->actions->addAction(name, action); } -void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - if (!d->started) { - //kDebug() << "not started"; - return; - } - - if (transform().isRotating()) { - painter->setRenderHint(QPainter::SmoothPixmapTransform); - painter->setRenderHint(QPainter::Antialiasing); - } - - if (d->background && - formFactor() != Plasma::Vertical && - formFactor() != Plasma::Horizontal) { - //kDebug() << "option rect is" << option->rect; - d->background->paintFrame(painter); - } - - if (d->failed) { - //kDebug() << "failed!"; - return; - } - - qreal left, top, right, bottom; - getContentsMargins(&left, &top, &right, &bottom); - QRect contentsRect = QRectF(QPointF(0, 0), - boundingRect().size()).adjusted(left, top, -right, -bottom).toRect(); - - if (widget && d->isContainment) { - // note that the widget we get is actually the viewport of the view, not the view itself - View* v = qobject_cast(widget->parent()); - Containment* c = qobject_cast(this); - - if (!v || v->isWallpaperEnabled()) { - - // paint the wallpaper - if (c && c->drawWallpaper() && c->wallpaper()) { - Wallpaper *w = c->wallpaper(); - if (!w->isInitialized()) { - // delayed paper initialization - KConfigGroup wallpaperConfig = c->config(); - wallpaperConfig = KConfigGroup(&wallpaperConfig, "Wallpaper"); - wallpaperConfig = KConfigGroup(&wallpaperConfig, w->pluginName()); - w->restore(wallpaperConfig); - disconnect(w, SIGNAL(update(QRectF)), this, SLOT(updateRect(QRectF))); - connect(w, SIGNAL(update(QRectF)), this, SLOT(updateRect(QRectF))); - } - - painter->save(); - c->wallpaper()->paint(painter, option->exposedRect); - painter->restore(); - } - - // .. and now paint the actual containment interface, but with - // a Containment style option based on the one we get - // the view must be assigned only if its containment is actually our own - Containment::StyleOption coption(*option); - if (v && v->containment() == containment()) { - coption.view = v; - } - paintInterface(painter, &coption, contentsRect); - } - } else { - //kDebug() << "paint interface of" << (QObject*) this; - // paint the applet's interface - paintInterface(painter, option, contentsRect); - } -} - -void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) -{ - if (d->script) { - d->script->paintInterface(painter, option, contentsRect); - } else { - //kDebug() << "Applet::paintInterface() default impl"; - } -} - FormFactor Applet::formFactor() const { Containment *c = containment(); - QGraphicsWidget *pw = qobject_cast(parent()); - if (!pw) { - pw = dynamic_cast(parentItem()); - } + QObject *pw = qobject_cast(parent()); Plasma::Applet *parentApplet = qobject_cast(pw); //assumption: this loop is usually is -really- short or doesn't run at all - while (!parentApplet && pw && pw->parentWidget()) { - QGraphicsWidget *parentWidget = qobject_cast(pw->parent()); - if (!parentWidget) { - parentWidget = dynamic_cast(pw->parentItem()); - } - pw = parentWidget; + while (!parentApplet && pw && pw->parent()) { + pw = pw->parent(); parentApplet = qobject_cast(pw); } - const PopupApplet *pa = dynamic_cast(this); + //FIXME: port away popupapplet + //const PopupApplet *pa = dynamic_cast(this); //if the applet is in a widget that isn't a containment //try to retrieve the formFactor from the parent size @@ -1009,10 +885,10 @@ FormFactor Applet::formFactor() const // a popupapplet can always be constrained. // a normal applet should to but //FIXME: not always constrained to not break systemmonitor - if (parentApplet && parentApplet != c && c != this && (pa || layout())) { - if (pa || (parentApplet->size().height() < layout()->effectiveSizeHint(Qt::MinimumSize).height())) { + if (parentApplet && parentApplet != c && c != this) { + if (parentApplet->size().height() < sizeHint(Qt::MinimumSize).height()) { return Plasma::Horizontal; - } else if (pa || (parentApplet->size().width() < layout()->effectiveSizeHint(Qt::MinimumSize).width())) { + } else if (parentApplet->size().width() < sizeHint(Qt::MinimumSize).width()) { return Plasma::Vertical; } return parentApplet->formFactor(); @@ -1030,7 +906,7 @@ Containment *Applet::containment() const } } - QGraphicsItem *parent = parentItem(); + QObject *parent = this->parent(); Containment *c = 0; while (parent) { @@ -1039,7 +915,7 @@ Containment *Applet::containment() const c = possibleC; break; } - parent = parent->parentItem(); + parent = parent->parent(); } if (!c) { @@ -1122,43 +998,17 @@ Plasma::AspectRatioMode Applet::aspectRatioMode() const void Applet::setAspectRatioMode(Plasma::AspectRatioMode mode) { + //FIXME: port away from popupapplet + /* PopupApplet *popup = qobject_cast(this); if (popup && popup->d->dialogPtr) { popup->d->dialogPtr.data()->setAspectRatioMode(mode); popup->d->savedAspectRatio = mode; - } + }*/ d->aspectRatioMode = mode; } -void Applet::registerAsDragHandle(QGraphicsItem *item) -{ - if (!item || d->registeredAsDragHandle.contains(item)) { - return; - } - - d->registeredAsDragHandle.insert(item); - item->installSceneEventFilter(this); -} - -void Applet::unregisterAsDragHandle(QGraphicsItem *item) -{ - if (!item) { - return; - } - - if (d->registeredAsDragHandle.remove(item)) { - if (item != this) { - item->removeSceneEventFilter(this); - } - } -} - -bool Applet::isRegisteredAsDragHandle(QGraphicsItem *item) -{ - return d->registeredAsDragHandle.contains(item); -} - bool Applet::hasConfigurationInterface() const { return d->hasConfigurationInterface; @@ -1220,107 +1070,6 @@ void Applet::setHasConfigurationInterface(bool hasInterface) d->hasConfigurationInterface = hasInterface; } -bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event) -{ - if (watched == this) { - switch (event->type()) { - case QEvent::GraphicsSceneHoverEnter: - //kDebug() << "got hoverenterEvent" << immutability() << " " << immutability(); - if (immutability() == Mutable) { - QGraphicsWidget *pw = this; - //This is for the rare case of applet in applet (systray) - //if the applet is in an applet that is not a containment, don't create the handle BUG:301648 - while (pw = pw->parentWidget()) { - if (qobject_cast(pw)) { - break; - } else if (qobject_cast(pw)) { - return false; - } - } - - QGraphicsSceneHoverEvent *he = static_cast(event); - if (d->handle) { - d->handle.data()->setHoverPos(he->pos()); - } else { - //kDebug() << "generated applet handle"; - AppletHandle *handle = new AppletHandle(containment(), this, he->pos()); - connect(handle, SIGNAL(disappearDone(AppletHandle*)), - this, SLOT(handleDisappeared(AppletHandle*))); - connect(this, SIGNAL(geometryChanged()), - handle, SLOT(appletResized())); - d->handle = handle; - } - } - break; - - case QEvent::GraphicsSceneHoverMove: - if (d->handle && !d->handle.data()->shown() && immutability() == Mutable) { - QGraphicsSceneHoverEvent *he = static_cast(event); - d->handle.data()->setHoverPos(he->pos()); - } - break; - - default: - break; - } - - } - - switch (event->type()) { - case QEvent::GraphicsSceneMouseMove: - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseRelease: - { - // don't move when the containment is not mutable, - // in the rare case the containment doesn't exists consider it as mutable - if ((flags() & ItemIsMovable) && d->registeredAsDragHandle.contains(watched)) { - Containment *c = containment(); - if (!c || c->immutability() == Mutable) { - scene()->sendEvent(this, event); - return false; - } - } - break; - } - - default: - break; - } - - return QGraphicsItem::sceneEventFilter(watched, event); -} - -void Applet::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if (immutability() == Mutable && formFactor() == Plasma::Planar && (flags() & ItemIsMovable)) { - QGraphicsWidget::mouseMoveEvent(event); - } -} - -void Applet::focusInEvent(QFocusEvent *event) -{ - if (!isContainment() && containment()) { - //focusing an applet may trigger this event again, but we won't be here more than twice - containment()->d->focusApplet(this); - } - - QGraphicsWidget::focusInEvent(event); -} - -void Applet::resizeEvent(QGraphicsSceneResizeEvent *event) -{ - QGraphicsWidget::resizeEvent(event); - - if (d->background) { - d->background->resizeFrame(boundingRect().size()); - } - - updateConstraints(Plasma::SizeConstraint); - - d->scheduleModificationNotification(); - emit geometryChanged(); -} - bool Applet::isUserConfiguring() const { return KConfigDialog::exists(d->configDialogId()); @@ -1622,9 +1371,10 @@ Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantL if (types.contains("Plasma/Containment")) { return new Containment(path, appletId, args); - } else if (types.contains("Plasma/PopupApplet")) { + }//FIXME: port away popupapplet + /* else if (types.contains("Plasma/PopupApplet")) { return new PopupApplet(path, appletId, args); - } else { + }*/ else { return new Applet(path, appletId, args); } } @@ -1632,82 +1382,9 @@ Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantL return 0; } -QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value) -{ - QVariant ret = QGraphicsWidget::itemChange(change, value); - - //kDebug() << change; - switch (change) { - case ItemSceneHasChanged: { - Corona *newCorona = qobject_cast(qvariant_cast(value)); - if (newCorona && newCorona->immutability() != Mutable) { - updateConstraints(ImmutableConstraint); - } - } - break; - case ItemParentChange: - if (!d->isContainment) { - Containment *c = containment(); - if (d->mainConfig && !c) { - kWarning() << "Configuration object was requested prior to init(), which is too early. " - "Please fix this item:" << parentItem() << value.value() - << name(); - - Applet *newC = dynamic_cast(value.value()); - if (newC) { - // if this is an applet, and we've just been assigned to our first containment, - // but the applet did something stupid like ask for the config() object prior to - // this happening (e.g. inits ctor) then let's repair that situation for them. - KConfigGroup *old = d->mainConfig; - KConfigGroup appletConfig = newC->config(); - appletConfig = KConfigGroup(&appletConfig, "Applets"); - d->mainConfig = new KConfigGroup(&appletConfig, QString::number(d->appletId)); - old->copyTo(d->mainConfig); - old->deleteGroup(); - delete old; - } - } - } - break; - case ItemParentHasChanged: - { - if (isContainment()) { - removeSceneEventFilter(this); - } else { - Containment *c = containment(); - if (c && c->containmentType() == Containment::DesktopContainment) { - installSceneEventFilter(this); - } else { - removeSceneEventFilter(this); - } - } - } - break; - case ItemPositionHasChanged: - emit geometryChanged(); - // fall through! - case ItemTransformHasChanged: - d->scheduleModificationNotification(); - break; - default: - break; - }; - - return ret; -} - -QPainterPath Applet::shape() const -{ - if (d->script) { - return d->script->shape(); - } - - return QGraphicsWidget::shape(); -} - QSizeF Applet::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { - QSizeF hint = QGraphicsWidget::sizeHint(which, constraint); + QSizeF hint(-1, -1); const FormFactor ff = formFactor(); // in panels make sure that the contents won't exit from the panel @@ -1739,16 +1416,6 @@ QSizeF Applet::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const return hint; } -void Applet::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) -} - -void Applet::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) -} - void Applet::timerEvent(QTimerEvent *event) { if (d->transient) { @@ -1779,6 +1446,8 @@ void Applet::timerEvent(QTimerEvent *event) QRect Applet::screenRect() const { + //TODO: port away QGV + /* QGraphicsView *v = view(); if (v) { @@ -1789,7 +1458,7 @@ QRect Applet::screenRect() const QPoint tL = v->mapToGlobal(v->mapFromScene(pos())); QPoint bR = v->mapToGlobal(v->mapFromScene(bottomRight)); return QRect(QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y())); - } + }*/ //The applet doesn't have a view on it. //So a screenRect isn't relevant. diff --git a/applet.h b/applet.h index bc4e04416..f7f4d66d7 100644 --- a/applet.h +++ b/applet.h @@ -22,8 +22,7 @@ #ifndef PLASMA_APPLET_H #define PLASMA_APPLET_H -#include -#include +#include #include #include @@ -33,14 +32,12 @@ #include #include -#include #include #include class QWidget; class KConfigDialog; -class QGraphicsView; class KActionCollection; namespace Plasma @@ -70,7 +67,7 @@ class Package; * * See techbase.kde.org for tutorials on writing Applets using this class. */ -class PLASMA_EXPORT Applet : public QGraphicsWidget +class PLASMA_EXPORT Applet : public QObject { Q_OBJECT Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface) @@ -173,28 +170,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget **/ Package package() const; - /** - * Returns the view this widget is visible on, or 0 if none can be found. - * @warning do NOT assume this will always return a view! - * a null view probably means that either plasma isn't finished loading, or your applet is - * on an activity that's not being shown anywhere. - */ - QGraphicsView *view() const; - - /** - * Maps a QRect from a view's coordinates to local coordinates. - * @param view the view from which rect should be mapped - * @param rect the rect to be mapped - */ - QRectF mapFromView(const QGraphicsView *view, const QRect &rect) const; - - /** - * Maps a QRectF from local coordinates to a view's coordinates. - * @param view the view to which rect should be mapped - * @param rect the rect to be mapped - */ - QRect mapToView(const QGraphicsView *view, const QRectF &rect) const; - /** * Reccomended position for a popup window like a menu or a tooltip * given its size @@ -340,18 +315,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget */ static QString category(const QString &appletName); - /** - * This method is called when the interface should be painted. - * - * @param painter the QPainter to use to do the paintiner - * @param option the style options object - * @param contentsRect the rect to paint within; automatically adjusted for - * the background, if any - **/ - virtual void paintInterface(QPainter *painter, - const QStyleOptionGraphicsItem *option, - const QRect &contentsRect); - /** * Returns the user-visible name for the applet, as specified in the * .desktop file. Can be changed with @see setName @@ -466,21 +429,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget * This method returns screen coordinates for the widget; this method can be somewhat * expensive and should ONLY be called when screen coordinates are required. For * example when positioning top level widgets on top of the view to create the - * appearance of unit. This should NOT be used for popups (@see popupPosition) or - * for normal widget use (use Plasma:: widgets or QGraphicsProxyWidget instead). + * appearance of unit. * * @return a rect of the applet in screen coordinates. */ QRect screenRect() const; - /** - * Reimplemented from QGraphicsItem - **/ - int type() const; - enum { - Type = Plasma::AppletType - }; - /** * @return the Containment, if any, this applet belongs to **/ @@ -517,25 +471,25 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget virtual void removeAssociatedWidget(QWidget *widget); /** - * @param parent the QGraphicsItem this applet is parented to + * @param parent the QObject this applet is parented to * @param serviceId the name of the .desktop file containing the * information about the widget * @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(QObject *parent = 0, const QString &serviceId = QString(), uint appletId = 0); /** - * @param parent the QGraphicsItem this applet is parented to + * @param parent the QObject this applet is parented to * @param info the plugin information object for this Applet * @param appletId a unique id used to differentiate between multiple * instances of the same Applet type * @since 4.6 */ - explicit Applet(const KPluginInfo &info, QGraphicsItem *parent = 0, uint appletId = 0); + explicit Applet(const KPluginInfo &info, QObject *parent = 0, uint appletId = 0); /** - * @param parent the QGraphicsItem this applet is parented to + * @param parent the QObject this applet is parented to * @param serviceId the name of the .desktop file containing the * information about the widget * @param appletId a unique id used to differentiate between multiple @@ -544,7 +498,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(QObject *parent, const QString &serviceId, uint appletId, const QVariantList &args); /** @@ -690,6 +644,8 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget * @since 4.4 */ void immutabilityChanged(Plasma::ImmutabilityType immutable); + + void geometryChanged(); public Q_SLOTS: /** @@ -754,7 +710,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget /** * This method is called once the applet is loaded and added to a Corona. - * If the applet requires a QGraphicsScene or has an particularly intensive + * If the applet requires a Scene or has an particularly intensive * set of initialization routines to go through, consider implementing it * in this method instead of the constructor. * @@ -815,6 +771,25 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget */ void runAssociatedApplication(); + bool hasFocus() const; + void setFocus(Qt::FocusReason); + + //Geometry functions: FIXME: to remove? + QSizeF size() const; + QRectF geometry() const; + void setGeometry(const QRectF &rect); + QRectF boundingRect() const; + void resize(const QSizeF &size); + int zValue() const; + void setZValue(int val); + QTransform transform() const; + void setTransform(const QTransform &transform); + QPointF pos() const; + void setPos(const QPointF &pos); + void setPos(int x, int y); + QSizePolicy sizePolicy() const; + void setSizePolicy(const QSizePolicy &policy); + protected: /** * This constructor is to be used with the plugin loading systems @@ -913,75 +888,9 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget */ virtual void constraintsEvent(Plasma::Constraints constraints); - /** - * Register the widgets that manage mouse clicks but you still want - * to be able to drag the applet around when holding the mouse pointer - * on that widget. - * - * Calling this results in an eventFilter being places on the widget. - * - * @param item the item to watch for mouse move - */ - void registerAsDragHandle(QGraphicsItem *item); - /** - * Unregister a widget registered with registerAsDragHandle. - * - * @param item the item to unregister - */ - void unregisterAsDragHandle(QGraphicsItem *item); - - /** - * @param item the item to look for if it is registered or not - * @return true if it is registered, false otherwise - */ - bool isRegisteredAsDragHandle(QGraphicsItem *item); - - /** - * @internal scene event filter; used to manage applet dragging - */ - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event); - - /** - * @internal manage the mouse movement to drag the applet around - */ - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - - /** - * Reimplemented from QGraphicsItem - */ - void focusInEvent(QFocusEvent *event); - - /** - * Reimplemented from QGraphicsItem - */ - void resizeEvent(QGraphicsSceneResizeEvent *event); - - /** - * Reimplemented from QGraphicsItem - */ - QVariant itemChange(GraphicsItemChange change, const QVariant &value); - - /** - * Reimplemented from QGraphicsItem - */ - QPainterPath shape() const; - - /** - * Reimplemented from QGraphicsLayoutItem - */ QSizeF sizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const; - /** - * Reimplemented from QGraphicsLayoutItem - */ - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - - /** - * Reimplemented from QGraphicsLayoutItem - */ - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - /** * Reimplemented from QObject */ @@ -999,30 +908,20 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget */ Applet(const QString &packagePath, uint appletId, const QVariantList &args); - Q_PRIVATE_SLOT(d, void setFocus()) - Q_PRIVATE_SLOT(d, void themeChanged()) 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 configDialogFinished()) Q_PRIVATE_SLOT(d, void updateShortcuts()) Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state)) Q_PRIVATE_SLOT(d, void globalShortcutChanged()) Q_PRIVATE_SLOT(d, void propagateConfigChanged()) - Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle)) - - /** - * Reimplemented from QGraphicsItem - **/ - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); AppletPrivate *const d; //Corona needs to access setFailedToLaunch and init friend class Corona; friend class CoronaPrivate; - friend class CoronaBase; - friend class CoronaBasePrivate; + friend class Corona; friend class Containment; friend class ContainmentPrivate; friend class AppletScript; diff --git a/containment.cpp b/containment.cpp index 838528591..8bf3617c2 100644 --- a/containment.cpp +++ b/containment.cpp @@ -28,13 +28,10 @@ #include #include #include -#include -#include +#include #include #include #include -#include -#include #include #include @@ -52,8 +49,6 @@ #include "kio/scheduler.h" #endif -#include "abstracttoolbox.h" -#include "animator.h" #include "containmentactions.h" #include "containmentactionspluginsconfig.h" #include "corona.h" @@ -73,31 +68,7 @@ namespace Plasma { -Containment::StyleOption::StyleOption() - : QStyleOptionGraphicsItem(), - view(0) -{ - version = Version; - type = Type; -} - -Containment::StyleOption::StyleOption(const Containment::StyleOption & other) - : QStyleOptionGraphicsItem(other), - view(other.view) -{ - version = Version; - type = Type; -} - -Containment::StyleOption::StyleOption(const QStyleOptionGraphicsItem &other) - : QStyleOptionGraphicsItem(other), - view(0) -{ - version = Version; - type = Type; -} - -Containment::Containment(QGraphicsItem *parent, +Containment::Containment(QObject *parent, const QString &serviceId, uint containmentId) : Applet(parent, serviceId, containmentId), @@ -148,11 +119,7 @@ void Containment::init() return; } - setCacheMode(NoCache); - setFlag(QGraphicsItem::ItemIsMovable, false); - setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); setAcceptDrops(true); - setAcceptsHoverEvents(true); if (d->type == NoContainmentType) { setContainmentType(DesktopContainment); @@ -273,10 +240,7 @@ void Containment::restore(KConfigGroup &group) resize(geo.size()); - //are we an offscreen containment? - if (containmentType() != PanelContainment && containmentType() != CustomPanelContainment && geo.right() < 0) { - corona()->addOffscreenWidget(this); - } + //FIXME: unbreak containments just for dashboard setLocation((Plasma::Location)group.readEntry("location", (int)d->location)); setFormFactor((Plasma::FormFactor)group.readEntry("formfactor", (int)d->formFactor)); @@ -293,10 +257,6 @@ void Containment::restore(KConfigGroup &group) setWallpaper(group.readEntry("wallpaperplugin", ContainmentPrivate::defaultWallpaper), group.readEntry("wallpaperpluginmode", ContainmentPrivate::defaultWallpaperMode)); - if (d->toolBox) { - d->toolBox.data()->restore(group); - } - KConfigGroup cfg; if (containmentType() == PanelContainment || containmentType() == CustomPanelContainment) { //don't let global desktop actions conflict with panels @@ -383,10 +343,6 @@ void Containment::save(KConfigGroup &g) const group.writeEntry("location", (int)d->location); group.writeEntry("activityId", d->activityId); - if (d->toolBox) { - d->toolBox.data()->save(group); - } - if (d->wallpaper) { group.writeEntry("wallpaperplugin", d->wallpaper->pluginName()); @@ -450,86 +406,13 @@ void Containment::setContainmentType(Containment::Type type) return; } - delete d->toolBox.data(); d->type = type; d->checkContainmentFurniture(); } Corona *Containment::corona() const { - return qobject_cast(scene()); -} - -void Containment::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - event->ignore(); - if (d->wallpaper && d->wallpaper->isInitialized()) { - QGraphicsItem *item = scene()->itemAt(event->scenePos()); - if (item == this) { - d->wallpaper->mouseMoveEvent(event); - } - } - - if (!event->isAccepted()) { - event->accept(); - Applet::mouseMoveEvent(event); - } -} - -void Containment::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - //close a toolbox if exists, to emulate qmenu behavior - if (d->toolBox) { - d->toolBox.data()->setShowing(false); - } - event->ignore(); - if (d->appletAt(event->scenePos())) { - return; //no unexpected click-throughs - } - - if (d->wallpaper && d->wallpaper->isInitialized() && !event->isAccepted()) { - d->wallpaper->mousePressEvent(event); - } - - if (event->isAccepted()) { - setFocus(Qt::MouseFocusReason); - } else if (event->button() == Qt::RightButton && event->modifiers() == Qt::NoModifier) { - // we'll catch this in the context menu even - Applet::mousePressEvent(event); - } else { - QString trigger = ContainmentActions::eventToString(event); - if (d->prepareContainmentActions(trigger, event->screenPos())) { - d->actionPlugins()->value(trigger)->contextEvent(event); - } - - if (!event->isAccepted()) { - Applet::mousePressEvent(event); - } - } -} - -void Containment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - event->ignore(); - - if (d->appletAt(event->scenePos())) { - return; //no unexpected click-throughs - } - - QString trigger = ContainmentActions::eventToString(event); - - if (d->wallpaper && d->wallpaper->isInitialized()) { - d->wallpaper->mouseReleaseEvent(event); - } - - if (!event->isAccepted() && isContainment()) { - if (d->prepareContainmentActions(trigger, event->screenPos())) { - d->actionPlugins()->value(trigger)->contextEvent(event); - } - - event->accept(); - Applet::mouseReleaseEvent(event); - } + return qobject_cast(parent()); } void Containment::showDropZone(const QPoint pos) @@ -541,24 +424,21 @@ void Containment::showDropZone(const QPoint pos) void Containment::showContextMenu(const QPointF &containmentPos, const QPoint &screenPos) { //kDebug() << containmentPos << screenPos; - QGraphicsSceneContextMenuEvent gvevent; - gvevent.setScreenPos(screenPos); - gvevent.setScenePos(mapToScene(containmentPos)); - gvevent.setPos(containmentPos); - gvevent.setReason(QGraphicsSceneContextMenuEvent::Mouse); - gvevent.setWidget(view()); + QContextMenuEvent gvevent(QContextMenuEvent::Mouse, screenPos); + + //FIXME: do we need views here? + //gvevent.setWidget(view()); contextMenuEvent(&gvevent); } -void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +void Containment::contextMenuEvent(QContextMenuEvent *event) { if (!isContainment() || !KAuthorized::authorizeKAction("plasma/containment_context_menu")) { - Applet::contextMenuEvent(event); return; } KMenu desktopMenu; - Applet *applet = d->appletAt(event->scenePos()); + Applet *applet = d->appletAt(event->pos()); //kDebug() << "context menu event " << (QObject*)applet; if (applet) { @@ -576,20 +456,20 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) } if (!menu->isEmpty()) { - QPoint pos = event->screenPos(); + QPoint pos = event->globalPos(); if (applet && d->isPanelContainment()) { menu->adjustSize(); pos = applet->popupPosition(menu->size()); - if (event->reason() == QGraphicsSceneContextMenuEvent::Mouse) { + if (event->reason() == QContextMenuEvent::Mouse) { // if the menu pops up way away from the mouse press, then move it // to the mouse press if (d->formFactor == Vertical) { - if (pos.y() + menu->height() < event->screenPos().y()) { - pos.setY(event->screenPos().y()); + if (pos.y() + menu->height() < event->globalPos().y()) { + pos.setY(event->globalPos().y()); } } else if (d->formFactor == Horizontal) { - if (pos.x() + menu->width() < event->screenPos().x()) { - pos.setX(event->screenPos().x()); + if (pos.x() + menu->width() < event->globalPos().x()) { + pos.setX(event->globalPos().x()); } } } @@ -597,8 +477,6 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) menu->exec(pos); event->accept(); - } else { - Applet::contextMenuEvent(event); } } @@ -611,16 +489,6 @@ void Containment::setFormFactor(FormFactor formFactor) //kDebug() << "switching FF to " << formFactor; d->formFactor = formFactor; - if (isContainment() && - (d->type == PanelContainment || d->type == CustomPanelContainment)) { - // we are a panel and we have chaged our orientation - d->positionPanel(true); - } - - if (d->toolBox) { - d->toolBox.data()->reposition(); - } - updateConstraints(Plasma::FormFactorConstraint); KConfigGroup c = config(); @@ -720,7 +588,6 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit) disconnect(applet, 0, currentContainment, 0); KConfigGroup oldConfig = applet->config(); currentContainment->d->applets.removeAll(applet); - applet->setParentItem(this); applet->setParent(this); // now move the old config to the new location @@ -731,7 +598,6 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit) disconnect(applet, SIGNAL(activate()), currentContainment, SIGNAL(activate())); } else { - applet->setParentItem(this); applet->setParent(this); } @@ -754,7 +620,6 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit) d->appletAppeared(applet); } - applet->setFlag(QGraphicsItem::ItemIsMovable, true); applet->updateConstraints(Plasma::AllConstraints); if (!delayInit) { applet->flushPendingConstraintsEvents(); @@ -869,114 +734,16 @@ QStringList Containment::listContainmentTypes() return types.toList(); } -void Containment::dragEnterEvent(QGraphicsSceneDragDropEvent *event) -{ - //kDebug() << immutability() << Mutable << (immutability() == Mutable); - event->setAccepted(immutability() == Mutable && - (event->mimeData()->hasFormat(static_cast(scene())->appletMimeType()) || - event->mimeData()->hasUrls())); - - if (!event->isAccepted()) { - // check to see if we have an applet that accepts the format. - QStringList formats = event->mimeData()->formats(); - - foreach (const QString &format, formats) { - KPluginInfo::List appletList = Applet::listAppletInfoForMimeType(format); - if (!appletList.isEmpty()) { - event->setAccepted(true); - break; - } - } - - if (!event->isAccepted()) { - foreach (const QString &format, formats) { - KPluginInfo::List wallpaperList = Wallpaper::listWallpaperInfoForMimeType(format); - if (!wallpaperList.isEmpty()) { - event->setAccepted(true); - break; - } - } - } - } - - if (event->isAccepted()) { - if (d->dropZoneStarted) { - showDropZone(event->pos().toPoint()); - } else { - if (!d->showDropZoneDelayTimer) { - d->showDropZoneDelayTimer = new QTimer(this); - d->showDropZoneDelayTimer->setInterval(300); - d->showDropZoneDelayTimer->setSingleShot(true); - connect(d->showDropZoneDelayTimer, SIGNAL(timeout()), this, SLOT(showDropZoneDelayed())); - } - - d->dropPoints.insert(0, event->pos()); - d->showDropZoneDelayTimer->start(); - } - } -} - -void Containment::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) -{ - //kDebug() << event->pos() << size().height() << size().width(); - if (d->showDropZoneDelayTimer) { - d->showDropZoneDelayTimer->stop(); - } - - if (event->pos().y() < 1 || event->pos().y() > size().height() || - event->pos().x() < 1 || event->pos().x() > size().width()) { - showDropZone(QPoint()); - d->dropZoneStarted = false; - } -} - -void Containment::dragMoveEvent(QGraphicsSceneDragDropEvent *event) -{ - QGraphicsItem *item = scene()->itemAt(event->scenePos()); - event->setAccepted(item == this || item == d->toolBox.data() || !item); - //kDebug() << event->isAccepted() << d->showDropZoneDelayTimer->isActive(); - if (!event->isAccepted()) { - if (d->showDropZoneDelayTimer) { - d->showDropZoneDelayTimer->stop(); - } - } else if (!d->showDropZoneDelayTimer->isActive() && immutability() == Plasma::Mutable) { - showDropZone(event->pos().toPoint()); - } -} - -void Containment::dropEvent(QGraphicsSceneDragDropEvent *event) +void Containment::dropEvent(QDropEvent *event) { if (isContainment()) { - d->dropData(event->scenePos(), event->screenPos(), event); - } else { - Applet::dropEvent(event); + d->dropData(event->pos(), event); } } -void Containment::setToolBox(AbstractToolBox *toolBox) +void Containment::resizeEvent(QResizeEvent *event) { - if (d->toolBox.data()) { - d->toolBox.data()->deleteLater(); - } - d->toolBox = toolBox; -} - -AbstractToolBox *Containment::toolBox() const -{ - return d->toolBox.data(); -} - -void Containment::resizeEvent(QGraphicsSceneResizeEvent *event) -{ - Applet::resizeEvent(event); - if (isContainment()) { - if (d->isPanelContainment()) { - d->positionPanel(); - } else if (corona()) { - corona()->layoutContainments(); - } - if (d->wallpaper) { d->wallpaper->setBoundingRect(QRectF(QPointF(0, 0), size())); } @@ -997,59 +764,30 @@ void Containment::keyPressEvent(QKeyEvent *event) } } -void Containment::wheelEvent(QGraphicsSceneWheelEvent *event) +void Containment::wheelEvent(QWheelEvent *event) { event->ignore(); - if (d->appletAt(event->scenePos())) { + if (d->appletAt(event->pos())) { return; //no unexpected click-throughs } if (d->wallpaper && d->wallpaper->isInitialized()) { - QGraphicsItem *item = scene()->itemAt(event->scenePos()); - if (item == this) { - event->ignore(); - d->wallpaper->wheelEvent(event); + event->ignore(); + d->wallpaper->wheelEvent(event); - if (event->isAccepted()) { - return; - } + if (event->isAccepted()) { + return; } } QString trigger = ContainmentActions::eventToString(event); - if (d->prepareContainmentActions(trigger, event->screenPos())) { + if (d->prepareContainmentActions(trigger, event->globalPos())) { d->actionPlugins()->value(trigger)->contextEvent(event); event->accept(); - } else { - event->ignore(); - Applet::wheelEvent(event); } } -QVariant Containment::itemChange(GraphicsItemChange change, const QVariant &value) -{ - //FIXME if the applet is moved to another containment we need to unfocus it - - if (isContainment() && - (change == QGraphicsItem::ItemSceneHasChanged || - change == QGraphicsItem::ItemPositionHasChanged)) { - switch (d->type) { - case PanelContainment: - case CustomPanelContainment: - d->positionPanel(); - break; - default: - if (corona()) { - corona()->layoutContainments(); - } - break; - } - } - - return Applet::itemChange(change, value); -} - void Containment::enableAction(const QString &name, bool enable) { QAction *action = this->action(name); @@ -1061,47 +799,12 @@ void Containment::enableAction(const QString &name, bool enable) void Containment::addToolBoxAction(QAction *action) { - d->createToolBox(); - if (d->toolBox) { - d->toolBox.data()->addTool(action); - } + d->toolBoxActions << action; } void Containment::removeToolBoxAction(QAction *action) { - if (d->toolBox) { - d->toolBox.data()->removeTool(action); - } -} - -void Containment::setToolBoxOpen(bool open) -{ - if (open) { - openToolBox(); - } else { - closeToolBox(); - } -} - -bool Containment::isToolBoxOpen() const -{ - return (d->toolBox && d->toolBox.data()->isShowing()); -} - -void Containment::openToolBox() -{ - if (d->toolBox && !d->toolBox.data()->isShowing()) { - d->toolBox.data()->setShowing(true); - emit toolBoxVisibilityChanged(true); - } -} - -void Containment::closeToolBox() -{ - if (d->toolBox && d->toolBox.data()->isShowing()) { - d->toolBox.data()->setShowing(false); - emit toolBoxVisibilityChanged(false); - } + d->toolBoxActions.removeAll(action); } void Containment::addAssociatedWidget(QWidget *widget) @@ -1194,8 +897,6 @@ void Containment::setWallpaper(const QString &pluginName, const QString &mode) cfg.writeEntry("wallpaperpluginmode", mode); } } - - update(); } if (!d->wallpaper) { @@ -1284,10 +985,6 @@ void Containment::setActivity(const QString &activityId) KConfigGroup c = config(); c.writeEntry("activityId", activityId); - if (d->toolBox) { - d->toolBox.data()->update(); - } - emit configNeedsSaving(); } @@ -1347,7 +1044,8 @@ void Containment::destroy(bool confirm) const QString title = i18nc("@title:window %1 is the name of the containment", "Remove %1", name()); KGuiItem remove = KStandardGuiItem::remove(); remove.setText(title); - if (KMessageBox::warningContinueCancel(view(), + //FIXME: make the view accessible? + if (KMessageBox::warningContinueCancel(0/*view()*/, i18nc("%1 is the name of the containment", "Do you really want to remove this %1?", name()), title, remove) != KMessageBox::Continue) { return; @@ -1376,6 +1074,37 @@ KConfigGroup Containment::containmentActionsConfig() return cfg; } +void Containment::setAcceptDrops(bool accept) +{ + +} + +bool Containment::acceptDrops() const +{ + return false; +} + +void Containment::setMaximumSize(QSizeF size) +{ + +} + +QSizeF Containment::maximumSize() const +{ + return QSizeF(); +} + +void Containment::setMinimumSize(QSizeF size) +{ + +} + +QSizeF Containment::minimumSize() const +{ + return QSizeF(); +} + + } // Plasma namespace diff --git a/containment.h b/containment.h index aee6466bc..c6e1a35ce 100644 --- a/containment.h +++ b/containment.h @@ -22,15 +22,13 @@ #ifndef PLASMA_CONTAINMENT_H #define PLASMA_CONTAINMENT_H -#include +#include #include -#include #include #include #include -#include namespace Plasma @@ -73,27 +71,6 @@ class PLASMA_EXPORT Containment : public Applet Q_OBJECT public: - class PLASMA_EXPORT StyleOption : public QStyleOptionGraphicsItem - { - public: - explicit StyleOption(); - explicit StyleOption(const StyleOption &other); - explicit StyleOption(const QStyleOptionGraphicsItem &other); - - enum StyleOptionType { - Type = SO_CustomBase + 1 - }; - enum StyleOptionVersion { - Version = QStyleOptionGraphicsItem::Version + 1 - }; - - /** - * The View, if any, that this containment is currently - * being rendered into. Note: this may be NULL, so be - * sure to check it before using it! - */ - Plasma::View *view; - }; enum Type { NoContainmentType = -1, /**< @internal */ @@ -104,14 +81,24 @@ class PLASMA_EXPORT Containment : public Applet CustomPanelContainment = 128 /**< A customized desktop panel */ }; + enum ToolType { + AddTool = 0, + ConfigureTool = 100, + ControlTool = 200, + MiscTool = 300, + DestructiveTool = 400, + UserToolType = DestructiveTool + 1000 + }; + Q_ENUMS(ToolType) + /** - * @param parent the QGraphicsItem this applet is parented to + * @param parent the QObject this applet is parented to * @param serviceId the name of the .desktop file containing the * information about the widget * @param containmentId a unique id used to differentiate between multiple * instances of the same Applet type */ - explicit Containment(QGraphicsItem *parent = 0, + explicit Containment(QObject *parent = 0, const QString &serviceId = QString(), uint containmentId = 0); @@ -299,29 +286,6 @@ class PLASMA_EXPORT Containment : public Applet */ void removeToolBoxAction(QAction *action); - /** - * Sets the open or closed state of the Containment's toolbox - * - * @param open true to open the ToolBox, false to close it - */ - void setToolBoxOpen(bool open); - - /** - * @return true if the toolbox is open - * @since 4.5 - */ - bool isToolBoxOpen() const; - - /** - * Open the Containment's toolbox - */ - void openToolBox(); - - /** - * Closes Containment's toolbox - */ - void closeToolBox(); - /** * associate actions with this widget, including ones added after this call. * needed to make keyboard shortcuts work. @@ -409,6 +373,9 @@ class PLASMA_EXPORT Containment : public Applet */ KConfigGroup containmentActionsConfig(); + void setAcceptDrops(bool accept); + bool acceptDrops() const; + Q_SIGNALS: /** * This signal is emitted when a new applet is created by the containment @@ -542,59 +509,23 @@ Q_SIGNALS: */ virtual void restoreContents(KConfigGroup &group); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); + //FIXME: events should go away + void contextMenuEvent(QContextMenuEvent *event); void keyPressEvent(QKeyEvent *event); - void wheelEvent(QGraphicsSceneWheelEvent *event); - QVariant itemChange(GraphicsItemChange change, const QVariant &value); + void wheelEvent(QWheelEvent *event); + void dropEvent(QDropEvent *event); /** * @reimp - * @sa QGraphicsItem::dragEnterEvent() + * @sa QObject::resizeEvent() */ - void dragEnterEvent(QGraphicsSceneDragDropEvent *event); + void resizeEvent(QResizeEvent *event); - /** - * @reimp - * @sa QGraphicsItem::dragLeaveEvent() - */ - void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); - - /** - * @reimp - * @sa QGraphicsItem::dragMoveEvent() - */ - void dragMoveEvent(QGraphicsSceneDragDropEvent *event); - - /** - * @reimp - * @sa QGraphicsItem::dropEvent() - */ - void dropEvent(QGraphicsSceneDragDropEvent *event); - - /** - * @reimp - * @sa QGraphicsItem::resizeEvent() - */ - void resizeEvent(QGraphicsSceneResizeEvent *event); - - /** - * Sets a custom ToolBox - * if there was an old one it will be deleted - * and the new one won't have any actions in it - * - * @param item the new toolbox item - * @since 4.4 - */ - void setToolBox(AbstractToolBox *toolBox); - - /** - * @return the ToolBox - * @since 4.4 - */ - AbstractToolBox *toolBox() const; + //FIXME: kill those + QSizeF maximumSize() const; + void setMaximumSize(QSizeF size); + QSizeF minimumSize() const; + void setMinimumSize(QSizeF size); private: /** @@ -609,9 +540,7 @@ Q_SIGNALS: Q_PRIVATE_SLOT(d, void appletDeleted(Plasma::Applet*)) Q_PRIVATE_SLOT(d, void triggerShowAddWidgets()) - Q_PRIVATE_SLOT(d, void positionToolBox()) Q_PRIVATE_SLOT(d, void requestConfiguration()) - Q_PRIVATE_SLOT(d, void updateToolBoxVisibility()) Q_PRIVATE_SLOT(d, void showDropZoneDelayed()) Q_PRIVATE_SLOT(d, void checkStatus(Plasma::ItemStatus)) Q_PRIVATE_SLOT(d, void remoteAppletReady(Plasma::AccessAppletJob *)) diff --git a/containmentactions.cpp b/containmentactions.cpp index 76ab618e8..08df0b1d4 100644 --- a/containmentactions.cpp +++ b/containmentactions.cpp @@ -27,9 +27,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include @@ -169,6 +169,7 @@ QString ContainmentActions::eventToString(QEvent *event) switch (event->type()) { case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: + case QEvent::MouseButtonDblClick: { QMouseEvent *e = static_cast(event); int m = QObject::staticQtMetaObject.indexOfEnumerator("MouseButtons"); @@ -177,17 +178,6 @@ QString ContainmentActions::eventToString(QEvent *event) modifiers = e->modifiers(); break; } - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseRelease: - case QEvent::GraphicsSceneMouseDoubleClick: - { - QGraphicsSceneMouseEvent *e = static_cast(event); - int m = QObject::staticQtMetaObject.indexOfEnumerator("MouseButtons"); - QMetaEnum mouse = QObject::staticQtMetaObject.enumerator(m); - trigger += mouse.valueToKey(e->button()); - modifiers = e->modifiers(); - break; - } case QEvent::Wheel: { QWheelEvent *e = static_cast(event); @@ -198,17 +188,6 @@ QString ContainmentActions::eventToString(QEvent *event) modifiers = e->modifiers(); break; } - case QEvent::GraphicsSceneWheel: - { - QGraphicsSceneWheelEvent *e = static_cast(event); - int o = QObject::staticQtMetaObject.indexOfEnumerator("Orientations"); - QMetaEnum orient = QObject::staticQtMetaObject.enumerator(o); - trigger = "wheel:"; - trigger += orient.valueToKey(e->orientation()); - modifiers = e->modifiers(); - break; - } - case QEvent::GraphicsSceneContextMenu: case QEvent::ContextMenu: { int m = QObject::staticQtMetaObject.indexOfEnumerator("MouseButtons"); @@ -233,23 +212,23 @@ void ContainmentActions::paste(QPointF scenePos, QPoint screenPos) { Containment *c = containment(); if (c) { - c->d->dropData(scenePos, screenPos); + c->d->dropData(screenPos); } } QPoint screenPosFromEvent(QEvent *event) { switch (event->type()) { - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseRelease: - case QEvent::GraphicsSceneMouseDoubleClick: - return static_cast(event)->screenPos(); + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseButtonDblClick: + return static_cast(event)->globalPos(); break; - case QEvent::GraphicsSceneWheel: - return static_cast(event)->screenPos(); + case QEvent::Wheel: + return static_cast(event)->globalPos(); break; - case QEvent::GraphicsSceneContextMenu: - return static_cast(event)->screenPos(); + case QEvent::ContextMenu: + return static_cast(event)->globalPos(); break; default: break; @@ -261,16 +240,16 @@ QPoint screenPosFromEvent(QEvent *event) QPointF scenePosFromEvent(QEvent *event) { switch (event->type()) { - case QEvent::GraphicsSceneMousePress: - case QEvent::GraphicsSceneMouseRelease: - case QEvent::GraphicsSceneMouseDoubleClick: - return static_cast(event)->scenePos(); + case QEvent::MouseButtonPress: + case QEvent::MouseButtonRelease: + case QEvent::MouseButtonDblClick: + return static_cast(event)->pos(); break; - case QEvent::GraphicsSceneWheel: - return static_cast(event)->scenePos(); + case QEvent::Wheel: + return static_cast(event)->pos(); break; - case QEvent::GraphicsSceneContextMenu: - return static_cast(event)->scenePos(); + case QEvent::ContextMenu: + return static_cast(event)->pos(); break; default: break; @@ -281,7 +260,7 @@ QPointF scenePosFromEvent(QEvent *event) bool isNonSceneEvent(QEvent *event) { - return dynamic_cast(event) == 0; + return dynamic_cast(event) == 0; } QPoint ContainmentActions::popupPosition(const QSize &s, QEvent *event) @@ -300,8 +279,8 @@ QPoint ContainmentActions::popupPosition(const QSize &s, QEvent *event) QPoint pos = screenPos; if (applet && containment()->d->isPanelContainment()) { pos = applet->popupPosition(s); - if (event->type() != QEvent::GraphicsSceneContextMenu || - static_cast(event)->reason() == QGraphicsSceneContextMenuEvent::Mouse) { + if (event->type() != QEvent::ContextMenu || + static_cast(event)->reason() == QContextMenuEvent::Mouse) { // if the menu pops up way away from the mouse press, then move it // to the mouse press if (c->formFactor() == Vertical) { diff --git a/containmentactions.h b/containmentactions.h index a67c5c879..3e387ae1c 100644 --- a/containmentactions.h +++ b/containmentactions.h @@ -117,7 +117,7 @@ class PLASMA_EXPORT ContainmentActions : public QObject * Implement this to respond to events. * The user can configure whatever button and modifier they like, so please don't look at * those parameters. - * The event may be a QGraphicsSceneMouseEvent or a QGraphicsSceneWheelEvent. + * The event may be a QMouseEvent or a QWheelEvent. */ virtual void contextEvent(QEvent *event); diff --git a/containmentactionspluginsconfig.cpp b/containmentactionspluginsconfig.cpp index ec0be87df..c0a014a0a 100644 --- a/containmentactionspluginsconfig.cpp +++ b/containmentactionspluginsconfig.cpp @@ -22,8 +22,8 @@ #include #include -#include -#include +#include +#include #include #include @@ -76,18 +76,15 @@ void ContainmentActionsPluginsConfig::addPlugin(QEvent *trigger, const QString & void ContainmentActionsPluginsConfig::addPlugin(Qt::KeyboardModifiers modifiers, Qt::MouseButton button, const QString &name) { - QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); - event.setButton(button); - event.setModifiers(modifiers); + QMouseEvent event(QEvent::MouseButtonPress, QPoint(), button, button, modifiers); QString s = ContainmentActions::eventToString(&event); d->plugins.insert(s, name); } void ContainmentActionsPluginsConfig::addPlugin(Qt::KeyboardModifiers modifiers, Qt::Orientation wheelDirection, const QString &name) { - QGraphicsSceneWheelEvent event(QEvent::GraphicsSceneWheel); - event.setOrientation(wheelDirection); - event.setModifiers(modifiers); + //most of those parameters are just fillers + QWheelEvent event(QPoint(0,0), 0, Qt::NoButton, modifiers, wheelDirection); QString s = ContainmentActions::eventToString(&event); d->plugins.insert(s, name); } diff --git a/corona.cpp b/corona.cpp index dcf7a61e9..6da7ee624 100644 --- a/corona.cpp +++ b/corona.cpp @@ -21,7 +21,7 @@ */ #include "corona.h" -#include "graphicsview/private/corona_p.h" +#include "private/corona_p.h" #include #include @@ -36,10 +36,10 @@ #include #include #include +#include +#include -#include "coronabase.h" #include "abstractdialogmanager.h" -#include "abstracttoolbox.h" #include "containment.h" #include "containmentactionspluginsconfig.h" #include "pluginloader.h" @@ -56,13 +56,12 @@ namespace Plasma bool CoronaPrivate::s_positioningContainments = false; Corona::Corona(QObject *parent) - : QGraphicsScene(parent), + : QObject(parent), d(new CoronaPrivate(this)) { #ifndef NDEBUG kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Corona ctor start"; #endif - d->coronaBase = new CoronaBase(this); d->init(); //setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel))); } @@ -72,238 +71,208 @@ Corona::~Corona() KConfigGroup trans(KSharedConfig::openConfig(), "PlasmaTransientsConfig"); trans.deleteGroup(); - // FIXME: Same fix as in Plasma::View - make sure that when the focused widget is - // destroyed we don't try to transfer it to something that's already been - // deleted. - clearFocus(); delete d; } void Corona::setAppletMimeType(const QString &type) { - d->coronaBase->setAppletMimeType(type); + d->mimetype = type; } QString Corona::appletMimeType() { - return d->coronaBase->appletMimeType(); + return d->mimetype; } void Corona::setDefaultContainmentPlugin(const QString &name) { - d->coronaBase->setDefaultContainmentPlugin(name); + // we could check if it is in: + // Containment::listContainments().contains(name) || + // Containment::listContainments(QString(), QCoreApplication::instance()->applicationName()).contains(name) + // but that seems like overkill + d->defaultContainmentPlugin = name; } QString Corona::defaultContainmentPlugin() const { - return d->coronaBase->defaultContainmentPlugin(); + return d->defaultContainmentPlugin; } void Corona::saveLayout(const QString &configName) const { - d->coronaBase->saveLayout(configName); + KSharedConfigPtr c; + + if (configName.isEmpty() || configName == d->configName) { + c = config(); + } else { + c = KSharedConfig::openConfig(configName, KConfig::SimpleConfig); + } + + d->saveLayout(c); } void Corona::exportLayout(KConfigGroup &config, QList containments) { - d->coronaBase->exportLayout(config, containments); + foreach (const QString &group, config.groupList()) { + KConfigGroup cg(&config, group); + cg.deleteGroup(); + } + + //temporarily unlock so that removal works + ImmutabilityType oldImm = immutability(); + d->immutability = Mutable; + + KConfigGroup dest(&config, "Containments"); + KConfigGroup dummy; + foreach (Plasma::Containment *c, containments) { + c->save(dummy); + c->config().reparent(&dest); + + //ensure the containment is unlocked + //this is done directly because we have to bypass any SystemImmutable checks + c->Applet::d->immutability = Mutable; + foreach (Applet *a, c->applets()) { + a->d->immutability = Mutable; + } + + c->destroy(false); + } + + //restore immutability + d->immutability = oldImm; + + config.sync(); } void Corona::requestConfigSync() { - d->coronaBase->requestConfigSync(); + // constant controlling how long between requesting a configuration sync + // and one happening should occur. currently 10 seconds + static const int CONFIG_SYNC_TIMEOUT = 10000; + + // TODO: should we check into our immutability before doing this? + + //NOTE: this is a pretty simplistic model: we simply save no more than CONFIG_SYNC_TIMEOUT + // after the first time this is called. not much of a heuristic for save points, but + // it should at least compress these activities a bit and provide a way for applet + // authors to ween themselves from the sync() disease. A more interesting/dynamic + // algorithm for determining when to actually sync() to disk might be better, though. + if (!d->configSyncTimer.isActive()) { + d->configSyncTimer.start(CONFIG_SYNC_TIMEOUT); + } } void Corona::requireConfigSync() { - d->coronaBase->requestConfigSync(); + d->syncConfig(); } void Corona::initializeLayout(const QString &configName) { - d->coronaBase->initializeLayout(); -} + clearContainments(); + loadLayout(configName); -bool containmentSortByPosition(const Containment *c1, const Containment *c2) -{ - return c1->id() < c2->id(); -} - -void Corona::layoutContainments() -{ - if (CoronaPrivate::s_positioningContainments) { - return; - } - - CoronaPrivate::s_positioningContainments = true; - - //TODO: we should avoid running this too often; consider compressing requests - // with a timer. - QList c = containments(); - QMutableListIterator it(c); - - while (it.hasNext()) { - Containment *containment = it.next(); - if (containment->containmentType() == Containment::PanelContainment || - containment->containmentType() == Containment::CustomPanelContainment || - offscreenWidgets().contains(containment)) { - // weed out all containments we don't care about at all - // e.g. Panels and ourself - it.remove(); - continue; + if (d->containments.isEmpty()) { + loadDefaultLayout(); + if (!d->containments.isEmpty()) { + requestConfigSync(); } } - qSort(c.begin(), c.end(), containmentSortByPosition); - - if (c.isEmpty()) { - CoronaPrivate::s_positioningContainments = false; - return; + if (config()->isImmutable()) { + setImmutability(SystemImmutable); + } else { + KConfigGroup coronaConfig(config(), "General"); + setImmutability((ImmutabilityType)coronaConfig.readEntry("immutability", (int)Mutable)); } - - int column = 0; - int x = 0; - int y = 0; - int rowHeight = 0; - - it.toFront(); - while (it.hasNext()) { - Containment *containment = it.next(); - containment->setPos(x, y); - //kDebug() << ++count << "setting to" << x << y; - - int height = containment->size().height(); - if (height > rowHeight) { - rowHeight = height; - } - - ++column; - - if (column == CONTAINMENT_COLUMNS) { - column = 0; - x = 0; - y += rowHeight + INTER_CONTAINMENT_MARGIN + TOOLBOX_MARGIN; - rowHeight = 0; - } else { - x += containment->size().width() + INTER_CONTAINMENT_MARGIN; - } - //kDebug() << "column: " << column << "; x " << x << "; y" << y << "; width was" - // << containment->size().width(); - } - - CoronaPrivate::s_positioningContainments = false; } - void Corona::loadLayout(const QString &configName) { - d->coronaBase->loadLayout(); + if (!configName.isEmpty() && configName != d->configName) { + // if we have a new config name passed in, then use that as the config file for this Corona + d->config = 0; + d->configName = configName; + } + + KConfigGroup conf(config(), QString()); + d->importLayout(conf, false); } QList Corona::importLayout(const KConfigGroup &conf) { - return d->coronaBase->importLayout(conf); + return d->importLayout(conf, true); } Containment *Corona::containmentForScreen(int screen, int desktop) const { - return d->coronaBase->containmentForScreen(screen, desktop); + foreach (Containment *containment, d->containments) { + if (containment->screen() == screen && + (desktop < 0 || containment->desktop() == desktop) && + (containment->containmentType() == Containment::DesktopContainment || + containment->containmentType() == Containment::CustomContainment)) { + return containment; + } + } + + return 0; } Containment *Corona::containmentForScreen(int screen, int desktop, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs) { - return d->coronaBase->containmentForScreen(screen, desktop, defaultPluginIfNonExistent, defaultArgs); + Containment *containment = containmentForScreen(screen, desktop); + if (!containment && !defaultPluginIfNonExistent.isEmpty()) { + // screen requests are allowed to bypass immutability + if (screen >= 0 && screen < numScreens() && + desktop >= -1 && desktop < KWindowSystem::numberOfDesktops()) { + containment = d->addContainment(defaultPluginIfNonExistent, defaultArgs, 0, false); + if (containment) { + containment->setScreen(screen, desktop); + } + } + } + + return containment; } QList Corona::containments() const { - return d->coronaBase->containments(); + return d->containments; } void Corona::clearContainments() { - d->coronaBase->clearContainments(); + foreach (Containment *containment, d->containments) { + containment->clearApplets(); + } } KSharedConfigPtr Corona::config() const { - return d->coronaBase->config(); + if (!d->config) { + d->config = KSharedConfig::openConfig(d->configName, KConfig::SimpleConfig); + } + + return d->config; } Containment *Corona::addContainment(const QString &name, const QVariantList &args) { - Plasma::Containment *containment = d->coronaBase->addContainment(name, args); - addItem(containment); - return containment; + if (d->immutability == Mutable) { + return d->addContainment(name, args, 0, false); + } + + return 0; } Containment *Corona::addContainmentDelayed(const QString &name, const QVariantList &args) { - Plasma::Containment *containment = d->coronaBase->addContainmentDelayed(name, args); - addItem(containment); - return containment; -} - -void Corona::addOffscreenWidget(QGraphicsWidget *widget) -{ - foreach (QGraphicsWidget *w, d->offscreenWidgets) { - if (w == widget) { -#ifndef NDEBUG - kDebug() << "widget is already an offscreen widget!"; -#endif - return; - } + if (d->immutability == Mutable) { + return d->addContainment(name, args, 0, true); } - //search for an empty spot in the topleft quadrant of the scene. each 'slot' is QWIDGETSIZE_MAX - //x QWIDGETSIZE_MAX, so we're guaranteed to never have to move widgets once they're placed here. - int i = 0; - while (d->offscreenWidgets.contains(i)) { - i++; - } - - d->offscreenWidgets[i] = widget; - widget->setPos((-i - 1) * QWIDGETSIZE_MAX, -QWIDGETSIZE_MAX); - - QGraphicsWidget *pw = widget->parentWidget(); - widget->setParentItem(0); - if (pw) { - widget->setParent(pw); - } - - //kDebug() << "adding offscreen widget at slot " << i; - if (!widget->scene()) { - addItem(widget); - } - - connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(offscreenWidgetDestroyed(QObject*))); -} - -void Corona::removeOffscreenWidget(QGraphicsWidget *widget) -{ - QMutableHashIterator it(d->offscreenWidgets); - - while (it.hasNext()) { - if (it.next().value() == widget) { - it.remove(); - return; - } - } -} - -QList Corona::offscreenWidgets() const -{ - return d->offscreenWidgets.values(); -} - -void CoronaPrivate::offscreenWidgetDestroyed(QObject *o) -{ - // at this point, it's just a QObject, not a QGraphicsWidget, but we still need - // a pointer of the appropriate type. - // WARNING: DO NOT USE THE WIDGET POINTER FOR ANYTHING OTHER THAN POINTER COMPARISONS - QGraphicsWidget *widget = static_cast(o); - q->removeOffscreenWidget(widget); + return 0; } int Corona::numScreens() const @@ -313,15 +282,8 @@ int Corona::numScreens() const QRect Corona::screenGeometry(int id) const { - Q_UNUSED(id); - QGraphicsView *v = views().value(0); - if (v) { - QRect r = sceneRect().toRect(); - r.moveTo(v->mapToGlobal(QPoint(0, 0))); - return r; - } - - return sceneRect().toRect(); + //This is unreliable, give better implementations in subclasses + return qApp->desktop()->screenGeometry(id); } QRegion Corona::availableScreenRegion(int id) const @@ -329,266 +291,445 @@ QRegion Corona::availableScreenRegion(int id) const return QRegion(screenGeometry(id)); } -QPoint Corona::popupPosition(const QGraphicsItem *item, const QSize &s, Qt::AlignmentFlag alignment) -{ - const QGraphicsItem *actualItem = item; - const QGraphicsView *v = viewFor(item); - - if (!v) { - return QPoint(0, 0); - } - - //its own view could be hidden, for instance if item is in an hidden Dialog - //try to position it using the parent applet as the item - if (!v->isVisible()) { - actualItem = item->parentItem(); - if (!actualItem) { - const QGraphicsWidget *widget = qgraphicsitem_cast(item); - if (widget) { - actualItem = qobject_cast(widget->parent()); - } - } - -#ifndef NDEBUG - kDebug() << actualItem; -#endif - - if (actualItem) { - v = viewFor(actualItem); - if (!v) { - return QPoint(0, 0); - } - } - } - - if (!actualItem) { - actualItem = item; - } - - QPoint pos; - QTransform sceneTransform = actualItem->sceneTransform(); - - //swap direction if necessary - if (QApplication::isRightToLeft() && alignment != Qt::AlignCenter) { - if (alignment == Qt::AlignRight) { - alignment = Qt::AlignLeft; - } else { - alignment = Qt::AlignRight; - } - } - - //if the applet is rotated the popup position has to be un-transformed - if (sceneTransform.isRotating()) { - qreal angle = acos(sceneTransform.m11()); - QTransform newTransform; - QPointF center = actualItem->sceneBoundingRect().center(); - - newTransform.translate(center.x(), center.y()); - newTransform.rotateRadians(-angle); - newTransform.translate(-center.x(), -center.y()); - pos = v->mapFromScene(newTransform.inverted().map(actualItem->scenePos())); - } else { - pos = v->mapFromScene(actualItem->scenePos()); - } - - pos = v->mapToGlobal(pos); - //kDebug() << "==> position is" << actualItem->scenePos() << v->mapFromScene(actualItem->scenePos()) << pos; - const Plasma::View *pv = qobject_cast(v); - - Plasma::Location loc = Floating; - if (pv && pv->containment()) { - loc = pv->containment()->location(); - } - - switch (loc) { - case BottomEdge: - case TopEdge: { - if (alignment == Qt::AlignCenter) { - pos.setX(pos.x() + actualItem->boundingRect().width()/2 - s.width()/2); - } else if (alignment == Qt::AlignRight) { - pos.setX(pos.x() + actualItem->boundingRect().width() - s.width()); - } - - if (pos.x() + s.width() > v->geometry().x() + v->geometry().width()) { - pos.setX((v->geometry().x() + v->geometry().width()) - s.width()); - } else { - pos.setX(qMax(pos.x(), v->geometry().left())); - } - break; - } - case LeftEdge: - case RightEdge: { - if (alignment == Qt::AlignCenter) { - pos.setY(pos.y() + actualItem->boundingRect().height()/2 - s.height()/2); - } else if (alignment == Qt::AlignRight) { - pos.setY(pos.y() + actualItem->boundingRect().height() - s.height()); - } - - if (pos.y() + s.height() > v->geometry().y() + v->geometry().height()) { - pos.setY((v->geometry().y() + v->geometry().height()) - s.height()); - } else { - pos.setY(qMax(pos.y(), v->geometry().top())); - } - break; - } - default: - if (alignment == Qt::AlignCenter) { - pos.setX(pos.x() + actualItem->boundingRect().width()/2 - s.width()/2); - } else if (alignment == Qt::AlignRight) { - pos.setX(pos.x() + actualItem->boundingRect().width() - s.width()); - } - break; - } - - - //are we out of screen? - int screen = ((pv && pv->containment()) ? pv->containment()->screen() : -1); - if (screen == -1) { - if (pv) { - screen = pv->screen(); - } else { - // fall back to asking the actual system what screen the view is on - // in the case we are dealing with a non-PlasmaView QGraphicsView - screen = QApplication::desktop()->screenNumber(v); - } - } - - QRect screenRect = screenGeometry(screen); - - switch (loc) { - case BottomEdge: - pos.setY(v->geometry().y() - s.height()); - break; - case TopEdge: - pos.setY(v->geometry().y() + v->geometry().height()); - break; - case LeftEdge: - pos.setX(v->geometry().x() + v->geometry().width()); - break; - case RightEdge: - pos.setX(v->geometry().x() - s.width()); - break; - default: - if (pos.y() - s.height() > screenRect.top()) { - pos.ry() = pos.y() - s.height(); - } else { - pos.ry() = pos.y() + (int)actualItem->boundingRect().size().height() + 1; - } - } - - //kDebug() << "==> rect for" << screen << "is" << screenRect; - - if (loc != LeftEdge && pos.x() + s.width() > screenRect.x() + screenRect.width()) { - pos.rx() -= ((pos.x() + s.width()) - (screenRect.x() + screenRect.width())); - } - - if (loc != TopEdge && pos.y() + s.height() > screenRect.y() + screenRect.height()) { - pos.ry() -= ((pos.y() + s.height()) - (screenRect.y() + screenRect.height())); - } - - pos.rx() = qMax(0, pos.x()); - pos.ry() = qMax(0, pos.y()); - return pos; -} - void Corona::loadDefaultLayout() { } void Corona::setPreferredToolBoxPlugin(const Containment::Type type, const QString &plugin) { - d->coronaBase->setPreferredToolBoxPlugin(type, plugin); + d->toolBoxPlugins[type] = plugin; + //TODO: react to plugin changes on the fly? still don't see the use case (maybe for laptops that become tablets?) } QString Corona::preferredToolBoxPlugin(const Containment::Type type) const { - return d->coronaBase->preferredToolBoxPlugin(type); + return d->toolBoxPlugins.value(type); } ImmutabilityType Corona::immutability() const { - return d->coronaBase->immutability(); + return d->immutability; } void Corona::setImmutability(const ImmutabilityType immutable) { - d->coronaBase->setImmutability(immutable); + if (d->immutability == immutable || d->immutability == SystemImmutable) { + return; + } + +#ifndef NDEBUG + kDebug() << "setting immutability to" << immutable; +#endif + d->immutability = immutable; + d->updateContainmentImmutability(); + //tell non-containments that might care (like plasmaapp or a custom corona) + emit immutabilityChanged(immutable); + + //update our actions + QAction *action = d->actions.action("lock widgets"); + if (action) { + if (d->immutability == SystemImmutable) { + action->setEnabled(false); + action->setVisible(false); + } else { + bool unlocked = d->immutability == Mutable; + action->setText(unlocked ? i18n("Lock Widgets") : i18n("Unlock Widgets")); + action->setIcon(KDE::icon(unlocked ? "object-locked" : "object-unlocked")); + action->setEnabled(true); + action->setVisible(true); + } + } + + if (d->immutability != SystemImmutable) { + KConfigGroup cg(config(), "General"); + + // we call the dptr member directly for locked since isImmutable() + // also checks kiosk and parent containers + cg.writeEntry("immutability", (int)d->immutability); + requestConfigSync(); + } } QList Corona::freeEdges(int screen) const { - return d->coronaBase->freeEdges(screen); + QList freeEdges; + freeEdges << Plasma::TopEdge << Plasma::BottomEdge + << Plasma::LeftEdge << Plasma::RightEdge; + + foreach (Containment *containment, containments()) { + if (containment->screen() == screen && + freeEdges.contains(containment->location())) { + freeEdges.removeAll(containment->location()); + } + } + + return freeEdges; } QAction *Corona::action(QString name) const { - return d->coronaBase->action(name); + return d->actions.action(name); } void Corona::addAction(QString name, QAction *action) { - d->coronaBase->addAction(name, action); + d->actions.addAction(name, action); } KAction* Corona::addAction(QString name) { - return d->coronaBase->addAction(name); + return d->actions.addAction(name); } QList Corona::actions() const { - return d->coronaBase->actions(); + return d->actions.actions(); } void Corona::enableAction(const QString &name, bool enable) { - d->coronaBase->enableAction(name, enable); + QAction *action = d->actions.action(name); + if (action) { + action->setEnabled(enable); + action->setVisible(enable); + } } void Corona::updateShortcuts() { - d->coronaBase->updateShortcuts(); + QMutableListIterator > it(d->actionCollections); + while (it.hasNext()) { + it.next(); + KActionCollection *collection = it.value().data(); + if (!collection) { + // get rid of KActionCollections that have been deleted behind our backs + it.remove(); + continue; + } + + collection->readSettings(); + if (d->shortcutsDlg) { + d->shortcutsDlg.data()->addCollection(collection); + } + } } void Corona::addShortcuts(KActionCollection *newShortcuts) { - d->coronaBase->addShortcuts(newShortcuts); + d->actionCollections << newShortcuts; + if (d->shortcutsDlg) { + d->shortcutsDlg.data()->addCollection(newShortcuts); + } } void Corona::setContainmentActionsDefaults(Containment::Type containmentType, const ContainmentActionsPluginsConfig &config) { - d->coronaBase->setContainmentActionsDefaults(containmentType, config); + d->containmentActionsDefaults.insert(containmentType, config); } ContainmentActionsPluginsConfig Corona::containmentActionsDefaults(Containment::Type containmentType) { - return d->coronaBase->containmentActionsDefaults(containmentType); + return d->containmentActionsDefaults.value(containmentType); } void Corona::setDialogManager(AbstractDialogManager *dialogManager) { - d->coronaBase->setDialogManager(dialogManager); + d->dialogManager = dialogManager; } AbstractDialogManager *Corona::dialogManager() { - return d->coronaBase->dialogManager(); + return d->dialogManager.data(); } CoronaPrivate::CoronaPrivate(Corona *corona) - : q(corona) + : q(corona), + immutability(Mutable), + mimetype("text/x-plasmoidservicename"), + defaultContainmentPlugin("desktop"), + config(0), + actions(corona) { + if (QCoreApplication::instance()) { + configName = QCoreApplication::instance()->applicationName() + "-appletsrc"; + } else { + configName = "plasma-appletsrc"; + } } CoronaPrivate::~CoronaPrivate() { + qDeleteAll(containments); } void CoronaPrivate::init() { - q->setStickyFocus(true); + configSyncTimer.setSingleShot(true); + QObject::connect(&configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig())); + + //some common actions + actions.setConfigGroup("Shortcuts"); + + KAction *lockAction = actions.addAction("lock widgets"); + QObject::connect(lockAction, SIGNAL(triggered(bool)), q, SLOT(toggleImmutability())); + lockAction->setText(i18n("Lock Widgets")); + lockAction->setAutoRepeat(true); + lockAction->setIcon(KDE::icon("object-locked")); + lockAction->setData(Containment::ControlTool); + lockAction->setShortcut(KShortcut("alt+d, l")); + lockAction->setShortcutContext(Qt::ApplicationShortcut); + + //FIXME this doesn't really belong here. desktop KCM maybe? + //but should the shortcuts be per-app or really-global? + //I don't know how to make kactioncollections use plasmarc + KAction *action = actions.addAction("configure shortcuts"); + QObject::connect(action, SIGNAL(triggered()), q, SLOT(showShortcutConfig())); + action->setText(i18n("Shortcut Settings")); + action->setIcon(KDE::icon("configure-shortcuts")); + action->setAutoRepeat(false); + action->setData(Containment::ConfigureTool); + //action->setShortcut(KShortcut("ctrl+h")); + action->setShortcutContext(Qt::ApplicationShortcut); + + //fake containment/applet actions + KActionCollection *containmentActions = AppletPrivate::defaultActions(q); //containment has to start with applet stuff + ContainmentPrivate::addDefaultActions(containmentActions); //now it's really containment + actionCollections << &actions << AppletPrivate::defaultActions(q) << containmentActions; + q->updateShortcuts(); } +void CoronaPrivate::showShortcutConfig() +{ + //show a kshortcutsdialog with the actions + KShortcutsDialog *dlg = shortcutsDlg.data(); + if (!dlg) { + dlg = new KShortcutsDialog(); + dlg->setModal(false); + dlg->setAttribute(Qt::WA_DeleteOnClose, true); + QObject::connect(dlg, SIGNAL(saved()), q, SIGNAL(shortcutsChanged())); + + dlg->addCollection(&actions); + QMutableListIterator > it(actionCollections); + while (it.hasNext()) { + it.next(); + KActionCollection *collection = it.value().data(); + if (!collection) { + // get rid of KActionCollections that have been deleted behind our backs + it.remove(); + continue; + } + + dlg->addCollection(collection); + } + } + + KWindowSystem::setOnDesktop(dlg->winId(), KWindowSystem::currentDesktop()); + dlg->configure(); + dlg->raise(); +} + +void CoronaPrivate::toggleImmutability() +{ + if (immutability == Mutable) { + q->setImmutability(UserImmutable); + } else { + q->setImmutability(Mutable); + } +} + +void CoronaPrivate::saveLayout(KSharedConfigPtr cg) const +{ + KConfigGroup containmentsGroup(cg, "Containments"); + foreach (const Containment *containment, containments) { + QString cid = QString::number(containment->id()); + KConfigGroup containmentConfig(&containmentsGroup, cid); + containment->save(containmentConfig); + } +} + +void CoronaPrivate::updateContainmentImmutability() +{ + foreach (Containment *c, containments) { + // we need to tell each containment that immutability has been altered + c->updateConstraints(ImmutableConstraint); + } +} + +void CoronaPrivate::containmentDestroyed(QObject *obj) +{ + // we do a static_cast here since it really isn't an Containment by this + // point anymore since we are in the qobject dtor. we don't actually + // try and do anything with it, we just need the value of the pointer + // so this unsafe looking code is actually just fine. + Containment* containment = static_cast(obj); + int index = containments.indexOf(containment); + + if (index > -1) { + containments.removeAt(index); + q->requestConfigSync(); + } + } + +void CoronaPrivate::syncConfig() +{ + q->config()->sync(); + emit q->configSynced(); +} + +Containment *CoronaPrivate::addContainment(const QString &name, const QVariantList &args, uint id, bool delayedInit) +{ + QString pluginName = name; + Containment *containment = 0; + Applet *applet = 0; + + //kDebug() << "Loading" << name << args << id; + + if (pluginName.isEmpty() || pluginName == "default") { + // default to the desktop containment + pluginName = defaultContainmentPlugin; + } + + bool loadingNull = pluginName == "null"; + if (!loadingNull) { + applet = PluginLoader::self()->loadApplet(pluginName, id, args); + containment = dynamic_cast(applet); + } + + if (!containment) { + if (!loadingNull) { +#ifndef NDEBUG + kDebug() << "loading of containment" << name << "failed."; +#endif + } + + // in case we got a non-Containment from Applet::loadApplet or + // a null containment was requested + if (applet) { + // the applet probably doesn't know what's hit it, so let's pretend it can be + // initialized to make assumptions in the applet's dtor safer + applet->init(); + delete applet; + } + applet = containment = new Containment(0, 0, id); + + if (loadingNull) { + containment->setDrawWallpaper(false); + } else { + containment->setFailedToLaunch(false); + } + + // we want to provide something and don't care about the failure to launch + containment->setFormFactor(Plasma::Planar); + } + + // if this is a new containment, we need to ensure that there are no stale + // configuration data around + if (id == 0) { + KConfigGroup conf(q->config(), "Containments"); + conf = KConfigGroup(&conf, QString::number(containment->id())); + conf.deleteGroup(); + } + + applet->d->isContainment = true; + applet->d->setIsContainment(true, true); + containments.append(containment); + + if (!delayedInit) { + containment->init(); + KConfigGroup cg = containment->config(); + containment->restore(cg); + containment->updateConstraints(Plasma::StartupCompletedConstraint); + containment->save(cg); + q->requestConfigSync(); + containment->flushPendingConstraintsEvents(); + } + + QObject::connect(containment, SIGNAL(destroyed(QObject*)), + q, SLOT(containmentDestroyed(QObject*))); + QObject::connect(containment, SIGNAL(configNeedsSaving()), + q, SLOT(requestConfigSync())); + QObject::connect(containment, SIGNAL(releaseVisualFocus()), + q, SIGNAL(releaseVisualFocus())); + QObject::connect(containment, SIGNAL(screenChanged(int,int,Plasma::Containment*)), + q, SIGNAL(screenOwnerChanged(int,int,Plasma::Containment*))); + + if (!delayedInit) { + emit q->containmentAdded(containment); + } + + return containment; +} + +QList CoronaPrivate::importLayout(const KConfigGroup &conf, bool mergeConfig) +{ + if (!conf.isValid()) { + return QList(); + } + + QList newContainments; + QSet containmentsIds; + + foreach (Containment *containment, containments) { + containmentsIds.insert(containment->id()); + } + + KConfigGroup containmentsGroup(&conf, "Containments"); + + foreach (const QString &group, containmentsGroup.groupList()) { + KConfigGroup containmentConfig(&containmentsGroup, group); + + if (containmentConfig.entryMap().isEmpty()) { + continue; + } + + uint cid = group.toUInt(); + if (containmentsIds.contains(cid)) { + cid = ++AppletPrivate::s_maxAppletId; + } else if (cid > AppletPrivate::s_maxAppletId) { + AppletPrivate::s_maxAppletId = cid; + } + + if (mergeConfig) { + KConfigGroup realConf(q->config(), "Containments"); + realConf = KConfigGroup(&realConf, QString::number(cid)); + // in case something was there before us + realConf.deleteGroup(); + containmentConfig.copyTo(&realConf); + } + + //kDebug() << "got a containment in the config, trying to make a" << containmentConfig.readEntry("plugin", QString()) << "from" << group; +#ifndef NDEBUG + kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Adding Containment" << containmentConfig.readEntry("plugin", QString()); +#endif + Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid, true); + if (!c) { + continue; + } + + newContainments.append(c); + containmentsIds.insert(c->id()); + + c->init(); +#ifndef NDEBUG + kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Init Containment" << c->pluginName(); +#endif + c->restore(containmentConfig); +#ifndef NDEBUG + kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Restored Containment" << c->pluginName(); +#endif + } + + foreach (Containment *containment, newContainments) { + containment->updateConstraints(Plasma::StartupCompletedConstraint); + containment->d->initApplets(); + emit q->containmentAdded(containment); +#ifndef NDEBUG + kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Containment" << containment->name(); +#endif + } + + return newContainments; +} } // namespace Plasma diff --git a/corona.h b/corona.h index bf8b40efb..525131d52 100644 --- a/corona.h +++ b/corona.h @@ -1,6 +1,7 @@ /* * Copyright 2007 Aaron Seigo * Copyright 2007 Matt Broadstone + * Copyright 2012 Marco MArtin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -18,16 +19,13 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef PLASMA_CORONA_H -#define PLASMA_CORONA_H - -#include +#ifndef PLASMA_CORONABASE_H +#define PLASMA_CORONABASE_H #include #include #include -class QGraphicsGridLayout; class QAction; class KAction; @@ -40,11 +38,11 @@ class ContainmentActionsPluginsConfig; class AbstractDialogManager; /** - * @class Corona plasma/corona.h + * @class CoronaBase plasma/CoronaBase.h * - * @short A QGraphicsScene for Plasma::Applets + * @short A bookkeeping Scene for Plasma::Applets */ -class PLASMA_EXPORT Corona : public QGraphicsScene +class PLASMA_EXPORT Corona : public QObject { Q_OBJECT @@ -72,22 +70,22 @@ public: QString defaultContainmentPlugin() const; /** - * @return all containments on this Corona + * @return all containments on this CoronaBase */ QList containments() const; /** - * Clear the Corona from all applets. + * Clear the CoronaBase from all applets. */ void clearContainments(); /** - * Returns the config file used to store the configuration for this Corona + * Returns the config file used to store the configuration for this CoronaBase */ KSharedConfig::Ptr config() const; /** - * Adds a Containment to the Corona + * Adds a Containment to the CoronaBase * * @param name the plugin name for the containment, as given by * KPluginInfo::pluginName(). If an empty string is passed in, the default @@ -148,25 +146,6 @@ public: Containment *containmentForScreen(int screen, int desktop, const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs = QVariantList()); - /** - * Adds a widget in the topleft quadrant in the scene. Widgets in the topleft quadrant are - * normally never shown unless you specifically aim a view at it, which makes it ideal for - * toplevel views etc. - * @param widget the widget to add. - */ - void addOffscreenWidget(QGraphicsWidget *widget); - - /** - * Removes a widget from the topleft quadrant in the scene. - * @param widget the widget to remove. - */ - void removeOffscreenWidget(QGraphicsWidget *widget); - - /** - * @return the list of all offscreen widgets - * @since 4.3 - */ - QList offscreenWidgets() const; /** * Returns the number of screens available to plasma. @@ -193,17 +172,6 @@ public: */ virtual QRegion availableScreenRegion(int id) const; - /** - * @since 4.4 - * Recommended position for a popup window like a menu or a tooltip - * given its size - * @param item the item that the popup should appear adjacent to (an applet, say) - * @param size size of the popup - * @param alignment alignment of the popup, valid flags are Qt::AlignLeft, Qt::AlignRight and Qt::AlignCenter - * @returns reccomended position - */ - QPoint popupPosition(const QGraphicsItem *item, const QSize &size, Qt::AlignmentFlag alignment = Qt::AlignCenter); - /** * This method is useful in order to retrieve the list of available * screen edges for panel type containments. @@ -237,8 +205,8 @@ public: /** * @since 4.3 - * Updates keyboard shortcuts for all the corona's actions. - * If you've added actions to the corona you'll need to + * Updates keyboard shortcuts for all the CoronaBase's actions. + * If you've added actions to the CoronaBase you'll need to * call this for them to be configurable. */ void updateShortcuts(); @@ -246,7 +214,7 @@ public: /** * @since 4.3 * Adds a set of actions to the shortcut config dialog. - * don't use this on actions in the corona's own actioncollection, + * don't use this on actions in the CoronaBase's own actioncollection, * those are handled automatically. this is for stuff outside of that. */ void addShortcuts(KActionCollection *newShortcuts); @@ -342,12 +310,12 @@ public Q_SLOTS: void saveLayout(const QString &config = QString()) const; /** - * @return The type of immutability of this Corona + * @return The type of immutability of this CoronaBase */ ImmutabilityType immutability() const; /** - * Sets the immutability type for this Corona (not immutable, + * Sets the immutability type for this CoronaBase (not immutable, * user immutable or system immutable) * @param immutable the new immutability type of this applet */ @@ -368,18 +336,10 @@ public Q_SLOTS: */ void requireConfigSync(); - /** - * @since 4.5 - * Layout the containments on this corona. The default implementation - * organizes them in a grid-like view, but subclasses can reimplement - * this slot to provide their own layout. - */ - virtual void layoutContainments(); - Q_SIGNALS: /** * This signal indicates a new containment has been added to - * the Corona + * the CoronaBase */ void containmentAdded(Plasma::Containment *containment); @@ -423,7 +383,7 @@ Q_SIGNALS: * @since 4.3 * emitted when the user changes keyboard shortcut settings * connect to this if you've put some extra shortcuts in your app - * that are NOT in corona's actioncollection. + * that are NOT in CoronaBase's actioncollection. * if your code's not in shells/ it probably shouldn't be using this function. * @see addShortcuts */ @@ -435,24 +395,6 @@ protected: **/ virtual void loadDefaultLayout(); - /** - * 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. @@ -470,7 +412,10 @@ protected: private: CoronaPrivate *const d; - Q_PRIVATE_SLOT(d, void offscreenWidgetDestroyed(QObject *)) + Q_PRIVATE_SLOT(d, void containmentDestroyed(QObject*)) + Q_PRIVATE_SLOT(d, void syncConfig()) + Q_PRIVATE_SLOT(d, void toggleImmutability()) + Q_PRIVATE_SLOT(d, void showShortcutConfig()) friend class CoronaPrivate; friend class View; diff --git a/coronabase.cpp b/coronabase.cpp deleted file mode 100644 index 318194d71..000000000 --- a/coronabase.cpp +++ /dev/null @@ -1,739 +0,0 @@ -/* - * Copyright 2007 Matt Broadstone - * Copyright 2007-2011 Aaron Seigo - * Copyright 2007 Riccardo Iaconelli - * Copyright (c) 2009 Chani Armitage - * - * 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 "coronabase.h" -#include "private/coronabase_p.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "abstractdialogmanager.h" -#include "abstracttoolbox.h" -#include "containment.h" -#include "containmentactionspluginsconfig.h" -#include "pluginloader.h" -#include "private/applet_p.h" -#include "private/containment_p.h" -#include "tooltipmanager.h" -#include "view.h" - -using namespace Plasma; - -namespace Plasma -{ - -bool CoronaBasePrivate::s_positioningContainments = false; - -CoronaBase::CoronaBase(QObject *parent) - : QObject(parent), - d(new CoronaBasePrivate(this)) -{ -#ifndef NDEBUG - kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Corona ctor start"; -#endif - d->init(); - //setViewport(new QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel))); -} - -CoronaBase::~CoronaBase() -{ - KConfigGroup trans(KSharedConfig::openConfig(), "PlasmaTransientsConfig"); - trans.deleteGroup(); - - delete d; -} - -void CoronaBase::setAppletMimeType(const QString &type) -{ - d->mimetype = type; -} - -QString CoronaBase::appletMimeType() -{ - return d->mimetype; -} - -void CoronaBase::setDefaultContainmentPlugin(const QString &name) -{ - // we could check if it is in: - // Containment::listContainments().contains(name) || - // Containment::listContainments(QString(), QCoreApplication::instance()->applicationName()).contains(name) - // but that seems like overkill - d->defaultContainmentPlugin = name; -} - -QString CoronaBase::defaultContainmentPlugin() const -{ - return d->defaultContainmentPlugin; -} - -void CoronaBase::saveLayout(const QString &configName) const -{ - KSharedConfigPtr c; - - if (configName.isEmpty() || configName == d->configName) { - c = config(); - } else { - c = KSharedConfig::openConfig(configName, KConfig::SimpleConfig); - } - - d->saveLayout(c); -} - -void CoronaBase::exportLayout(KConfigGroup &config, QList containments) -{ - foreach (const QString &group, config.groupList()) { - KConfigGroup cg(&config, group); - cg.deleteGroup(); - } - - //temporarily unlock so that removal works - ImmutabilityType oldImm = immutability(); - d->immutability = Mutable; - - KConfigGroup dest(&config, "Containments"); - KConfigGroup dummy; - foreach (Plasma::Containment *c, containments) { - c->save(dummy); - c->config().reparent(&dest); - - //ensure the containment is unlocked - //this is done directly because we have to bypass any SystemImmutable checks - c->Applet::d->immutability = Mutable; - foreach (Applet *a, c->applets()) { - a->d->immutability = Mutable; - } - - c->destroy(false); - } - - //restore immutability - d->immutability = oldImm; - - config.sync(); -} - -void CoronaBase::requestConfigSync() -{ - // constant controlling how long between requesting a configuration sync - // and one happening should occur. currently 10 seconds - static const int CONFIG_SYNC_TIMEOUT = 10000; - - // TODO: should we check into our immutability before doing this? - - //NOTE: this is a pretty simplistic model: we simply save no more than CONFIG_SYNC_TIMEOUT - // after the first time this is called. not much of a heuristic for save points, but - // it should at least compress these activities a bit and provide a way for applet - // authors to ween themselves from the sync() disease. A more interesting/dynamic - // algorithm for determining when to actually sync() to disk might be better, though. - if (!d->configSyncTimer.isActive()) { - d->configSyncTimer.start(CONFIG_SYNC_TIMEOUT); - } -} - -void CoronaBase::requireConfigSync() -{ - d->syncConfig(); -} - -void CoronaBase::initializeLayout(const QString &configName) -{ - clearContainments(); - loadLayout(configName); - - if (d->containments.isEmpty()) { - loadDefaultLayout(); - if (!d->containments.isEmpty()) { - requestConfigSync(); - } - } - - if (config()->isImmutable()) { - setImmutability(SystemImmutable); - } else { - KConfigGroup coronaConfig(config(), "General"); - setImmutability((ImmutabilityType)coronaConfig.readEntry("immutability", (int)Mutable)); - } -} - -void CoronaBase::loadLayout(const QString &configName) -{ - if (!configName.isEmpty() && configName != d->configName) { - // if we have a new config name passed in, then use that as the config file for this Corona - d->config = 0; - d->configName = configName; - } - - KConfigGroup conf(config(), QString()); - d->importLayout(conf, false); -} - -QList CoronaBase::importLayout(const KConfigGroup &conf) -{ - return d->importLayout(conf, true); -} - -Containment *CoronaBase::containmentForScreen(int screen, int desktop) const -{ - foreach (Containment *containment, d->containments) { - if (containment->screen() == screen && - (desktop < 0 || containment->desktop() == desktop) && - (containment->containmentType() == Containment::DesktopContainment || - containment->containmentType() == Containment::CustomContainment)) { - return containment; - } - } - - return 0; -} - -Containment *CoronaBase::containmentForScreen(int screen, int desktop, - const QString &defaultPluginIfNonExistent, const QVariantList &defaultArgs) -{ - Containment *containment = containmentForScreen(screen, desktop); - if (!containment && !defaultPluginIfNonExistent.isEmpty()) { - // screen requests are allowed to bypass immutability - if (screen >= 0 && screen < numScreens() && - desktop >= -1 && desktop < KWindowSystem::numberOfDesktops()) { - containment = d->addContainment(defaultPluginIfNonExistent, defaultArgs, 0, false); - if (containment) { - containment->setScreen(screen, desktop); - } - } - } - - return containment; -} - -QList CoronaBase::containments() const -{ - return d->containments; -} - -void CoronaBase::clearContainments() -{ - foreach (Containment *containment, d->containments) { - containment->clearApplets(); - } -} - -KSharedConfigPtr CoronaBase::config() const -{ - if (!d->config) { - d->config = KSharedConfig::openConfig(d->configName, KConfig::SimpleConfig); - } - - return d->config; -} - -Containment *CoronaBase::addContainment(const QString &name, const QVariantList &args) -{ - if (d->immutability == Mutable) { - return d->addContainment(name, args, 0, false); - } - - return 0; -} - -Containment *CoronaBase::addContainmentDelayed(const QString &name, const QVariantList &args) -{ - if (d->immutability == Mutable) { - return d->addContainment(name, args, 0, true); - } - - return 0; -} - -int CoronaBase::numScreens() const -{ - return 1; -} - -QRect CoronaBase::screenGeometry(int id) const -{ - //This is unreliable, give better implementations in subclasses - return qApp->desktop()->screenGeometry(id); -} - -QRegion CoronaBase::availableScreenRegion(int id) const -{ - return QRegion(screenGeometry(id)); -} - -void CoronaBase::loadDefaultLayout() -{ -} - -void CoronaBase::setPreferredToolBoxPlugin(const Containment::Type type, const QString &plugin) -{ - d->toolBoxPlugins[type] = plugin; - //TODO: react to plugin changes on the fly? still don't see the use case (maybe for laptops that become tablets?) -} - -QString CoronaBase::preferredToolBoxPlugin(const Containment::Type type) const -{ - return d->toolBoxPlugins.value(type); -} - -ImmutabilityType CoronaBase::immutability() const -{ - return d->immutability; -} - -void CoronaBase::setImmutability(const ImmutabilityType immutable) -{ - if (d->immutability == immutable || d->immutability == SystemImmutable) { - return; - } - -#ifndef NDEBUG - kDebug() << "setting immutability to" << immutable; -#endif - d->immutability = immutable; - d->updateContainmentImmutability(); - //tell non-containments that might care (like plasmaapp or a custom corona) - emit immutabilityChanged(immutable); - - //update our actions - QAction *action = d->actions.action("lock widgets"); - if (action) { - if (d->immutability == SystemImmutable) { - action->setEnabled(false); - action->setVisible(false); - } else { - bool unlocked = d->immutability == Mutable; - action->setText(unlocked ? i18n("Lock Widgets") : i18n("Unlock Widgets")); - action->setIcon(KDE::icon(unlocked ? "object-locked" : "object-unlocked")); - action->setEnabled(true); - action->setVisible(true); - } - } - - if (d->immutability != SystemImmutable) { - KConfigGroup cg(config(), "General"); - - // we call the dptr member directly for locked since isImmutable() - // also checks kiosk and parent containers - cg.writeEntry("immutability", (int)d->immutability); - requestConfigSync(); - } -} - -QList CoronaBase::freeEdges(int screen) const -{ - QList freeEdges; - freeEdges << Plasma::TopEdge << Plasma::BottomEdge - << Plasma::LeftEdge << Plasma::RightEdge; - - foreach (Containment *containment, containments()) { - if (containment->screen() == screen && - freeEdges.contains(containment->location())) { - freeEdges.removeAll(containment->location()); - } - } - - return freeEdges; -} - -QAction *CoronaBase::action(QString name) const -{ - return d->actions.action(name); -} - -void CoronaBase::addAction(QString name, QAction *action) -{ - d->actions.addAction(name, action); -} - -KAction* CoronaBase::addAction(QString name) -{ - return d->actions.addAction(name); -} - -QList CoronaBase::actions() const -{ - return d->actions.actions(); -} - -void CoronaBase::enableAction(const QString &name, bool enable) -{ - QAction *action = d->actions.action(name); - if (action) { - action->setEnabled(enable); - action->setVisible(enable); - } -} - -void CoronaBase::updateShortcuts() -{ - QMutableListIterator > it(d->actionCollections); - while (it.hasNext()) { - it.next(); - KActionCollection *collection = it.value().data(); - if (!collection) { - // get rid of KActionCollections that have been deleted behind our backs - it.remove(); - continue; - } - - collection->readSettings(); - if (d->shortcutsDlg) { - d->shortcutsDlg.data()->addCollection(collection); - } - } -} - -void CoronaBase::addShortcuts(KActionCollection *newShortcuts) -{ - d->actionCollections << newShortcuts; - if (d->shortcutsDlg) { - d->shortcutsDlg.data()->addCollection(newShortcuts); - } -} - -void CoronaBase::setContainmentActionsDefaults(Containment::Type containmentType, const ContainmentActionsPluginsConfig &config) -{ - d->containmentActionsDefaults.insert(containmentType, config); -} - -ContainmentActionsPluginsConfig CoronaBase::containmentActionsDefaults(Containment::Type containmentType) -{ - return d->containmentActionsDefaults.value(containmentType); -} - -void CoronaBase::setDialogManager(AbstractDialogManager *dialogManager) -{ - d->dialogManager = dialogManager; -} - -AbstractDialogManager *CoronaBase::dialogManager() -{ - return d->dialogManager.data(); -} - -CoronaBasePrivate::CoronaBasePrivate(CoronaBase *corona) - : q(corona), - immutability(Mutable), - mimetype("text/x-plasmoidservicename"), - defaultContainmentPlugin("desktop"), - config(0), - actions(corona) -{ - if (QCoreApplication::instance()) { - configName = QCoreApplication::instance()->applicationName() + "-appletsrc"; - } else { - configName = "plasma-appletsrc"; - } -} - -CoronaBasePrivate::~CoronaBasePrivate() -{ - qDeleteAll(containments); -} - -void CoronaBasePrivate::init() -{ - configSyncTimer.setSingleShot(true); - QObject::connect(&configSyncTimer, SIGNAL(timeout()), q, SLOT(syncConfig())); - - //some common actions - actions.setConfigGroup("Shortcuts"); - - KAction *lockAction = actions.addAction("lock widgets"); - QObject::connect(lockAction, SIGNAL(triggered(bool)), q, SLOT(toggleImmutability())); - lockAction->setText(i18n("Lock Widgets")); - lockAction->setAutoRepeat(true); - lockAction->setIcon(KDE::icon("object-locked")); - lockAction->setData(AbstractToolBox::ControlTool); - lockAction->setShortcut(KShortcut("alt+d, l")); - lockAction->setShortcutContext(Qt::ApplicationShortcut); - - //FIXME this doesn't really belong here. desktop KCM maybe? - //but should the shortcuts be per-app or really-global? - //I don't know how to make kactioncollections use plasmarc - KAction *action = actions.addAction("configure shortcuts"); - QObject::connect(action, SIGNAL(triggered()), q, SLOT(showShortcutConfig())); - action->setText(i18n("Shortcut Settings")); - action->setIcon(KDE::icon("configure-shortcuts")); - action->setAutoRepeat(false); - action->setData(AbstractToolBox::ConfigureTool); - //action->setShortcut(KShortcut("ctrl+h")); - action->setShortcutContext(Qt::ApplicationShortcut); - - //fake containment/applet actions - KActionCollection *containmentActions = AppletPrivate::defaultActions(q); //containment has to start with applet stuff - ContainmentPrivate::addDefaultActions(containmentActions); //now it's really containment - actionCollections << &actions << AppletPrivate::defaultActions(q) << containmentActions; - q->updateShortcuts(); -} - -void CoronaBasePrivate::showShortcutConfig() -{ - //show a kshortcutsdialog with the actions - KShortcutsDialog *dlg = shortcutsDlg.data(); - if (!dlg) { - dlg = new KShortcutsDialog(); - dlg->setModal(false); - dlg->setAttribute(Qt::WA_DeleteOnClose, true); - QObject::connect(dlg, SIGNAL(saved()), q, SIGNAL(shortcutsChanged())); - - dlg->addCollection(&actions); - QMutableListIterator > it(actionCollections); - while (it.hasNext()) { - it.next(); - KActionCollection *collection = it.value().data(); - if (!collection) { - // get rid of KActionCollections that have been deleted behind our backs - it.remove(); - continue; - } - - dlg->addCollection(collection); - } - } - - KWindowSystem::setOnDesktop(dlg->winId(), KWindowSystem::currentDesktop()); - dlg->configure(); - dlg->raise(); -} - -void CoronaBasePrivate::toggleImmutability() -{ - if (immutability == Mutable) { - q->setImmutability(UserImmutable); - } else { - q->setImmutability(Mutable); - } -} - -void CoronaBasePrivate::saveLayout(KSharedConfigPtr cg) const -{ - KConfigGroup containmentsGroup(cg, "Containments"); - foreach (const Containment *containment, containments) { - QString cid = QString::number(containment->id()); - KConfigGroup containmentConfig(&containmentsGroup, cid); - containment->save(containmentConfig); - } -} - -void CoronaBasePrivate::updateContainmentImmutability() -{ - foreach (Containment *c, containments) { - // we need to tell each containment that immutability has been altered - c->updateConstraints(ImmutableConstraint); - } -} - -void CoronaBasePrivate::containmentDestroyed(QObject *obj) -{ - // we do a static_cast here since it really isn't an Containment by this - // point anymore since we are in the qobject dtor. we don't actually - // try and do anything with it, we just need the value of the pointer - // so this unsafe looking code is actually just fine. - Containment* containment = static_cast(obj); - int index = containments.indexOf(containment); - - if (index > -1) { - containments.removeAt(index); - q->requestConfigSync(); - } - } - -void CoronaBasePrivate::syncConfig() -{ - q->config()->sync(); - emit q->configSynced(); -} - -Containment *CoronaBasePrivate::addContainment(const QString &name, const QVariantList &args, uint id, bool delayedInit) -{ - QString pluginName = name; - Containment *containment = 0; - Applet *applet = 0; - - //kDebug() << "Loading" << name << args << id; - - if (pluginName.isEmpty() || pluginName == "default") { - // default to the desktop containment - pluginName = defaultContainmentPlugin; - } - - bool loadingNull = pluginName == "null"; - if (!loadingNull) { - applet = PluginLoader::self()->loadApplet(pluginName, id, args); - containment = dynamic_cast(applet); - } - - if (!containment) { - if (!loadingNull) { -#ifndef NDEBUG - kDebug() << "loading of containment" << name << "failed."; -#endif - } - - // in case we got a non-Containment from Applet::loadApplet or - // a null containment was requested - if (applet) { - // the applet probably doesn't know what's hit it, so let's pretend it can be - // initialized to make assumptions in the applet's dtor safer - applet->init(); - delete applet; - } - applet = containment = new Containment(0, 0, id); - - if (loadingNull) { - containment->setDrawWallpaper(false); - } else { - containment->setFailedToLaunch(false); - } - - // we want to provide something and don't care about the failure to launch - containment->setFormFactor(Plasma::Planar); - } - - // if this is a new containment, we need to ensure that there are no stale - // configuration data around - if (id == 0) { - KConfigGroup conf(q->config(), "Containments"); - conf = KConfigGroup(&conf, QString::number(containment->id())); - conf.deleteGroup(); - } - - applet->d->isContainment = true; - applet->d->setIsContainment(true, true); - containments.append(containment); - - if (!delayedInit) { - containment->init(); - KConfigGroup cg = containment->config(); - containment->restore(cg); - containment->updateConstraints(Plasma::StartupCompletedConstraint); - containment->save(cg); - q->requestConfigSync(); - containment->flushPendingConstraintsEvents(); - } - - QObject::connect(containment, SIGNAL(destroyed(QObject*)), - q, SLOT(containmentDestroyed(QObject*))); - QObject::connect(containment, SIGNAL(configNeedsSaving()), - q, SLOT(requestConfigSync())); - QObject::connect(containment, SIGNAL(releaseVisualFocus()), - q, SIGNAL(releaseVisualFocus())); - QObject::connect(containment, SIGNAL(screenChanged(int,int,Plasma::Containment*)), - q, SIGNAL(screenOwnerChanged(int,int,Plasma::Containment*))); - - if (!delayedInit) { - emit q->containmentAdded(containment); - } - - return containment; -} - -QList CoronaBasePrivate::importLayout(const KConfigGroup &conf, bool mergeConfig) -{ - if (!conf.isValid()) { - return QList(); - } - - QList newContainments; - QSet containmentsIds; - - foreach (Containment *containment, containments) { - containmentsIds.insert(containment->id()); - } - - KConfigGroup containmentsGroup(&conf, "Containments"); - - foreach (const QString &group, containmentsGroup.groupList()) { - KConfigGroup containmentConfig(&containmentsGroup, group); - - if (containmentConfig.entryMap().isEmpty()) { - continue; - } - - uint cid = group.toUInt(); - if (containmentsIds.contains(cid)) { - cid = ++AppletPrivate::s_maxAppletId; - } else if (cid > AppletPrivate::s_maxAppletId) { - AppletPrivate::s_maxAppletId = cid; - } - - if (mergeConfig) { - KConfigGroup realConf(q->config(), "Containments"); - realConf = KConfigGroup(&realConf, QString::number(cid)); - // in case something was there before us - realConf.deleteGroup(); - containmentConfig.copyTo(&realConf); - } - - //kDebug() << "got a containment in the config, trying to make a" << containmentConfig.readEntry("plugin", QString()) << "from" << group; -#ifndef NDEBUG - kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Adding Containment" << containmentConfig.readEntry("plugin", QString()); -#endif - Containment *c = addContainment(containmentConfig.readEntry("plugin", QString()), QVariantList(), cid, true); - if (!c) { - continue; - } - - newContainments.append(c); - containmentsIds.insert(c->id()); - - c->init(); -#ifndef NDEBUG - kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Init Containment" << c->pluginName(); -#endif - c->restore(containmentConfig); -#ifndef NDEBUG - kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Restored Containment" << c->pluginName(); -#endif - } - - foreach (Containment *containment, newContainments) { - containment->updateConstraints(Plasma::StartupCompletedConstraint); - containment->d->initApplets(); - emit q->containmentAdded(containment); -#ifndef NDEBUG - kDebug() << "!!{} STARTUP TIME" << QTime().msecsTo(QTime::currentTime()) << "Containment" << containment->name(); -#endif - } - - return newContainments; -} - -} // namespace Plasma - - - -#include "moc_coronabase.cpp" diff --git a/coronabase.h b/coronabase.h index 4b6d4d4e1..e69de29bb 100644 --- a/coronabase.h +++ b/coronabase.h @@ -1,431 +0,0 @@ -/* - * Copyright 2007 Aaron Seigo - * Copyright 2007 Matt Broadstone - * Copyright 2012 Marco MArtin - * - * 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_CORONABASE_H -#define PLASMA_CORONABASE_H - -#include - -#include -#include -#include - -class QGraphicsGridLayout; -class QAction; - -class KAction; - -namespace Plasma -{ - -class CoronaBasePrivate; -class ContainmentActionsPluginsConfig; -class AbstractDialogManager; - -/** - * @class CoronaBase plasma/CoronaBase.h - * - * @short A QGraphicsScene for Plasma::Applets - */ -class PLASMA_EXPORT CoronaBase : public QObject -{ - Q_OBJECT - -//typedef QHash > layouts; - -public: - explicit CoronaBase(QObject * parent = 0); - ~CoronaBase(); - - /** - * Sets the mimetype of Drag/Drop items. Default is - * text/x-plasmoidservicename - */ - void setAppletMimeType(const QString &mimetype); - - /** - * The current mime type of Drag/Drop items. - */ - QString appletMimeType(); - - /** - * @return the default containment plugin type - * @since 4.7 - */ - QString defaultContainmentPlugin() const; - - /** - * @return all containments on this CoronaBase - */ - QList containments() const; - - /** - * Clear the CoronaBase from all applets. - */ - void clearContainments(); - - /** - * Returns the config file used to store the configuration for this CoronaBase - */ - KSharedConfig::Ptr config() const; - - /** - * Adds a Containment to the CoronaBase - * - * @param name the plugin name for the containment, as given by - * KPluginInfo::pluginName(). If an empty string is passed in, the default - * containment plugin will be used (usually DesktopContainment). If the - * string literal "null" is passed in, then no plugin will be loaded and - * a simple Containment object will be created instead. - * @param args argument list to pass to the containment - * - * @return a pointer to the containment on success, or 0 on failure. Failure can be - * caused by too restrictive of an Immutability type, as containments cannot be added - * when widgets are locked, or if the requested containment plugin can not be located - * or successfully loaded. - */ - Containment *addContainment(const QString &name, const QVariantList &args = QVariantList()); - - /** - * Loads a containment with delayed initialization, primarily useful - * for implementations of loadDefaultLayout. The caller is responsible - * for all initializating, saving and notification of a new containment. - * - * @param name the plugin name for the containment, as given by - * KPluginInfo::pluginName(). If an empty string is passed in, the defalt - * containment plugin will be used (usually DesktopContainment). If the - * string literal "null" is passed in, then no plugin will be loaded and - * a simple Containment object will be created instead. - * @param args argument list to pass to the containment - * - * @return a pointer to the containment on success, or 0 on failure. Failure can - * be caused by the Immutability type being too restrictive, as containments can't be added - * when widgets are locked, or if the requested containment plugin can not be located - * or successfully loaded. - * @see addContainment - **/ - Containment *addContainmentDelayed(const QString &name, - const QVariantList &args = QVariantList()); - - /** - * Returns the Containment, if any, for a given physical screen and desktop - * - * @param screen number of the physical screen to locate - * @param desktop the virtual desktop) to locate; if < 0 then it will - * simply return the first Containment associated with screen - */ - Containment *containmentForScreen(int screen, int desktop = -1) const; - - /** - * Returns the Containment for a given physical screen and desktop, creating one - * if none exists - * - * @param screen number of the physical screen to locate - * @param desktop the virtual desktop) to locate; if < 0 then it will - * simply return the first Containment associated with screen - * @param defaultPluginIfNonExistent the plugin to load by default; "null" is an empty - * Containment and "default" creates the default plugin - * @param defaultArgs optional arguments to pass in when creating a Containment if needed - * @since 4.6 - */ - Containment *containmentForScreen(int screen, int desktop, - const QString &defaultPluginIfNonExistent, - const QVariantList &defaultArgs = QVariantList()); - - /** - * Returns the number of screens available to plasma. - * Subclasses should override this method as the default - * implementation returns a meaningless value. - */ - virtual int numScreens() const; - - /** - * Returns the geometry of a given screen. - * Valid screen ids are 0 to numScreen()-1, or -1 for the full desktop geometry. - * Subclasses should override this method as the default - * implementation returns a meaningless value. - */ - virtual QRect screenGeometry(int id) const; - - /** - * Returns the available region for a given screen. - * The available region excludes panels and similar windows. - * Valid screen ids are 0 to numScreens()-1. - * By default this method returns a rectangular region - * equal to screenGeometry(id); subclasses that need another - * behavior should override this method. - */ - virtual QRegion availableScreenRegion(int id) const; - - /** - * This method is useful in order to retrieve the list of available - * screen edges for panel type containments. - * @param screen the id of the screen to look for free edges. - * @returns a list of free edges not filled with panel type containments. - */ - QList freeEdges(int screen) const; - - /** - * Returns the QAction with the given name from our collection - */ - QAction *action(QString name) const; - - /** - * Adds the action to our collection under the given name - */ - void addAction(QString name, QAction *action); - - /** - * Returns all the actions in our collection - */ - QList actions() const; - - /** - * convenience function - enables or disables an action by name - * - * @param name the name of the action in our collection - * @param enable true to enable, false to disable - */ - void enableAction(const QString &name, bool enable); - - /** - * @since 4.3 - * Updates keyboard shortcuts for all the CoronaBase's actions. - * If you've added actions to the CoronaBase you'll need to - * call this for them to be configurable. - */ - void updateShortcuts(); - - /** - * @since 4.3 - * Adds a set of actions to the shortcut config dialog. - * don't use this on actions in the CoronaBase's own actioncollection, - * those are handled automatically. this is for stuff outside of that. - */ - void addShortcuts(KActionCollection *newShortcuts); - - /** - * @since 4.3 - * Creates an action in our collection under the given name - * @return the new action - * FIXME I'm wrapping so much of kactioncollection API now, maybe I should just expose the - * collection itself :P - */ - KAction* addAction(QString name); - - /** - * @since 4.4 - * Sets the default containmentactions plugins for the given containment type - */ - void setContainmentActionsDefaults(Containment::Type containmentType, const ContainmentActionsPluginsConfig &config); - - /** - * @since 4.4 - * Returns the default containmentactions plugins for the given containment type - */ - ContainmentActionsPluginsConfig containmentActionsDefaults(Containment::Type containmentType); - - /** - * @param the AbstractDialogManager implementaion - * - * @since 4.5 - */ - void setDialogManager(AbstractDialogManager *manager); - - /** - * @return the AbstractDialogManager that will show dialogs used by applets, like configuration dialogs - * - * @since 4.5 - */ - AbstractDialogManager *dialogManager(); - - /** - * Returns the name of the preferred plugin to be used as containment toolboxes. - * CustomContainments and CustomPanelContainments can still override it as their liking. It's also not guaranteed that the plugin will actually exist. - * - * @param type the containment type of which we want to know the associated toolbox plugin - * @since 4.6 - */ - QString preferredToolBoxPlugin(const Containment::Type type) const; - - /** - * Imports an applet layout from a config file. The results will be added to the - * current set of Containments. - * - * @param config the name of the config file to load from, - * or the default config file if QString() - * @return the list of containments that were loaded - * @since 4.6 - */ - QList importLayout(const KConfigGroup &config); - - /** - * Exports a set of containments to a config file. - * - * @param config the config group to save to - * @param containments the list of containments to save - * @since 4.6 - */ - void exportLayout(KConfigGroup &config, QList containments); - -public Q_SLOTS: - /** - * Initializes the layout from a config file. This will first clear any existing - * Containments, load a layout from the requested configuration file, request the - * default layout if needed and update immutability. - * - * @param config the name of the config file to load from, - * or the default config file if QString() - */ - void initializeLayout(const QString &config = QString()); - - /** - * Load applet layout from a config file. The results will be added to the - * current set of Containments. - * - * @param config the name of the config file to load from, - * or the default config file if QString() - */ - void loadLayout(const QString &config = QString()); - - /** - * Save applets layout to file - * @param config the file to save to, or the default config file if QString() - */ - void saveLayout(const QString &config = QString()) const; - - /** - * @return The type of immutability of this CoronaBase - */ - ImmutabilityType immutability() const; - - /** - * Sets the immutability type for this CoronaBase (not immutable, - * user immutable or system immutable) - * @param immutable the new immutability type of this applet - */ - void setImmutability(const ImmutabilityType immutable); - - /** - * Schedules a flush-to-disk synchronization of the configuration state - * at the next convenient moment. - */ - void requestConfigSync(); - - /** - * Schedules a time sensitive flush-to-disk synchronization of the - * configuration state. Since this method does not provide any sort of - * event compression, it should only be used when an *immediate* disk - * sync is *absolutely* required. Otherwise, use @see requestConfigSync() - * which does do event compression. - */ - void requireConfigSync(); - -Q_SIGNALS: - /** - * This signal indicates a new containment has been added to - * the CoronaBase - */ - void containmentAdded(Plasma::Containment *containment); - - /** - * This signal indicates that a containment has been newly - * associated (or dissociated) with a physical screen. - * - * @param wasScreen the screen it was associated with - * @param isScreen the screen it is now associated with - * @param containment the containment switching screens - */ - void screenOwnerChanged(int wasScreen, int isScreen, Plasma::Containment *containment); - - /** - * This signal indicates that an application launch, window - * creation or window focus event was triggered. This is used, for instance, - * to ensure that the Dashboard view in Plasma hides when such an event is - * triggered by an item it is displaying. - */ - void releaseVisualFocus(); - - /** - * This signal indicates that the configuration file was flushed to disc. - */ - void configSynced(); - - /** - * This signal inicates that a change in available screen goemetry occurred. - */ - void availableScreenRegionChanged(); - - /** - * emitted when immutability changes. - * this is for use by things that don't get contraints events, like plasmaapp. - * it's NOT for containments or applets or any of the other stuff on the scene. - * if your code's not in shells/ it probably shouldn't be using it. - */ - void immutabilityChanged(Plasma::ImmutabilityType immutability); - - /** - * @since 4.3 - * emitted when the user changes keyboard shortcut settings - * connect to this if you've put some extra shortcuts in your app - * that are NOT in CoronaBase's actioncollection. - * if your code's not in shells/ it probably shouldn't be using this function. - * @see addShortcuts - */ - void shortcutsChanged(); - -protected: - /** - * Loads the default (system wide) layout for this user - **/ - virtual void loadDefaultLayout(); - - /** - * @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. - * @param plugin the toolbox plugin name - * @since 4.6 - */ - void setPreferredToolBoxPlugin(const Containment::Type type, const QString &plugin); - - /** - * Sets the default containment plugin to try and load - * @since 4.7 - */ - void setDefaultContainmentPlugin(const QString &name); - -private: - CoronaBasePrivate *const d; - - Q_PRIVATE_SLOT(d, void containmentDestroyed(QObject*)) - Q_PRIVATE_SLOT(d, void syncConfig()) - Q_PRIVATE_SLOT(d, void toggleImmutability()) - Q_PRIVATE_SLOT(d, void showShortcutConfig()) - - friend class CoronaBasePrivate; - friend class Corona; - friend class View; -}; - -} // namespace Plasma - -#endif - diff --git a/data/servicetypes/plasma-animator.desktop b/data/servicetypes/plasma-animator.desktop deleted file mode 100644 index 00dc23215..000000000 --- a/data/servicetypes/plasma-animator.desktop +++ /dev/null @@ -1,81 +0,0 @@ -[Desktop Entry] -Type=ServiceType -X-KDE-ServiceType=Plasma/Animator - -Comment=Plasma Animation Engine -Comment[ar]=محرك تحريك البلازما -Comment[as]=Plasma Animation Engine -Comment[ast]=Motor d'animación Plasma -Comment[be@latin]=Systema animacyi „Plasma” -Comment[bg]=Ядро за анимации на Plasma -Comment[bn]=প্লাসমা অ্যানিমেশন ইঞ্জিন -Comment[bn_IN]=Plasma অ্যানিমেশন ইঞ্জিন -Comment[bs]=Plazma motor animacija -Comment[ca]=Motor d'animació del Plasma -Comment[ca@valencia]=Motor d'animació del Plasma -Comment[cs]=Animační nástroj Plasma -Comment[da]=Plasma-animationsmotor -Comment[de]=Plasma-Animations-Treiber -Comment[el]=Μηχανή εφέ κίνησης του Plasma -Comment[en_GB]=Plasma Animation Engine -Comment[eo]=Viviga motoro de Plasma -Comment[es]=Motor de animación para Plasma -Comment[et]=Plasma animatsiooni mootor -Comment[eu]=Plasma animazio motorra -Comment[fi]=Plasma-animointimoottori -Comment[fr]=Moteur d'animation Plasma -Comment[fy]=Plasma animaasje motor -Comment[ga]=Inneall Beochana Plasma -Comment[gl]=Motor de animación de Plasma -Comment[gu]=પ્લાઝમા એનિમેશન એન્જિન -Comment[he]=מנוע אנימציה של Plasma -Comment[hne]=प्लाज्मा एनिमेशन इंजिन -Comment[hr]=Plasmin animatorski mehanizam -Comment[hsb]=Plasma-engine za animacije -Comment[hu]=Plasma animációkezelő -Comment[ia]=Motor de animation Plasma -Comment[id]=Mesin Animasi Plasma -Comment[is]=Plasma hreyfingastjóri -Comment[it]=Motore animazione Plasma -Comment[ja]=Plasma アニメーションエンジン -Comment[kk]=Plasma анимация тетігі -Comment[km]=ម៉ាស៊ីន​ចលនា​របស់ប្លាស្មា -Comment[kn]=ಪ್ಲಾಸ್ಮಾ ಸಜೀವನ (ಅನಿಮೇಷನ್) ಯಂತ್ರ -Comment[ko]=Plasma 애니메이션 엔진 -Comment[ku]=Motora Zindîkirina Plasma -Comment[lt]=Plasma animacijos varikliukas -Comment[lv]=Plasma animācijas dzinējs -Comment[mai]=प्लाजमा भावचिन्ह इंजन -Comment[ml]=പ്ലാസ്മ അനിമേഷന്‍ എഞ്ചിന്‍ -Comment[nb]=Plasma animasjonsmotor -Comment[nds]=Plasma-Animeerkarn -Comment[nl]=Plasma-animatie-engine -Comment[nn]=Plasma-animasjonsmotor -Comment[pa]=ਪਲਾਜ਼ਮਾ ਐਨੀਮੇਸ਼ਨ ਇੰਜਣ -Comment[pl]=Silnik animacji Plazmy -Comment[pt]=Motor de Animação do Plasma -Comment[pt_BR]=Mecanismo de animação do Plasma -Comment[ro]=Motor de animație Plasma -Comment[ru]=Движок анимации для Plasma -Comment[se]=Plasma-animerenmohtor -Comment[si]=Plasma සජිවීකරණ එන්ජිම -Comment[sk]=Animačný nástroj Plasma -Comment[sl]=Animacijski pogon za Plasmo -Comment[sr]=Плазма мотор анимација -Comment[sr@ijekavian]=Плазма мотор анимација -Comment[sr@ijekavianlatin]=Plasma motor animacija -Comment[sr@latin]=Plasma motor animacija -Comment[sv]=Animeringsgränssnitt i Plasma -Comment[ta]=பிளாஸ்மா அசைவூட்ட இயந்திரம் -Comment[tg]=Системаи аниматсионии Plasma -Comment[th]=กลไกแสดงความเคลื่อนไหวของพลาสมา -Comment[tr]=Plasma Canlandırma Motoru -Comment[tt]=Plasma анимация өчен корал -Comment[ug]=Plasma جانلاندۇرۇم ماتورى -Comment[uk]=Рушій анімації Плазми -Comment[vi]=Cơ chế hoạt ảnh Plasma -Comment[wa]=Moteur d' animåcion di Plasma -Comment[x-test]=xxPlasma Animation Enginexx -Comment[zh_CN]=Plasma 动画引擎 -Comment[zh_TW]=Plasma 動畫引擎 - diff --git a/delegate.cpp b/delegate.cpp deleted file mode 100644 index b4aea5c2c..000000000 --- a/delegate.cpp +++ /dev/null @@ -1,492 +0,0 @@ -/* - Copyright 2007 Robert Knight - Copyright 2007 Kevin Ottens - Copyright 2008 Marco Martin - - This library 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 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -// Own -#include "delegate.h" - -#include -#include - -// Qt -#include -#include -#include -#include -#include -#include - -// KDE -#include -#include -#include - -// plasma -#include -#include - -namespace Plasma -{ - -class DelegatePrivate -{ - public: - DelegatePrivate() { } - - ~DelegatePrivate() { } - - QFont fontForSubTitle(const QFont &titleFont) const; - QRect titleRect(const QStyleOptionViewItem &option, const QModelIndex &index) const; - QRect subTitleRect(const QStyleOptionViewItem &option, const QModelIndex &index) const; - - QMap roles; - - static const int ICON_TEXT_MARGIN = 10; - static const int TEXT_RIGHT_MARGIN = 5; - static const int ACTION_ICON_SIZE = 22; - - static const int ITEM_LEFT_MARGIN = 5; - static const int ITEM_RIGHT_MARGIN = 5; - static const int ITEM_TOP_MARGIN = 5; - static const int ITEM_BOTTOM_MARGIN = 5; - - bool m_showToolTip; - FrameSvg *svg; -}; - -QFont DelegatePrivate::fontForSubTitle(const QFont &titleFont) const -{ - QFont subTitleFont = titleFont; - subTitleFont.setPointSize(qMax(subTitleFont.pointSize() - 2, - KGlobalSettings::smallestReadableFont().pointSize())); - return subTitleFont; -} - -QRect DelegatePrivate::titleRect(const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - QFont font(option.font); - font.setBold(true); - QFontMetrics fm(font); - - Qt::Alignment textAlignment = - option.decorationAlignment & Qt::AlignRight ? Qt::AlignRight : Qt::AlignLeft; - - QRect emptyRect; - if (option.direction == Qt::LeftToRight) { - emptyRect = option.rect.adjusted( - option.decorationSize.width() + ICON_TEXT_MARGIN + ITEM_LEFT_MARGIN, - ITEM_TOP_MARGIN, -ITEM_RIGHT_MARGIN, -ITEM_BOTTOM_MARGIN); - } else { - emptyRect = option.rect.adjusted( - ITEM_LEFT_MARGIN, ITEM_TOP_MARGIN, - -ITEM_RIGHT_MARGIN - option.decorationSize.width() - ICON_TEXT_MARGIN, -ITEM_BOTTOM_MARGIN); - } - - if (emptyRect.width() < 0) { - emptyRect.setWidth(0); - return emptyRect; - } - - QRect textRect = QStyle::alignedRect( - option.direction, - textAlignment, - fm.boundingRect(index.data(Qt::DisplayRole).toString()).size(), - emptyRect); - - textRect.setWidth(textRect.width() + TEXT_RIGHT_MARGIN); - textRect.setHeight(emptyRect.height() / 2); - return textRect; -} - -QRect DelegatePrivate::subTitleRect(const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - QString subTitle = index.data(roles[Delegate::SubTitleRole]).toString(); - - QFontMetrics fm(fontForSubTitle(option.font)); - - QRect textRect = titleRect(option, index); - int right = textRect.right(); - - //if title=subtitle subtitle won't be displayed - if (subTitle != index.data(Qt::DisplayRole).toString()) { - textRect.setWidth(fm.width(" " + subTitle) + TEXT_RIGHT_MARGIN); - } else { - textRect.setWidth(0); - } - textRect.translate(0, textRect.height()); - - if (option.direction == Qt::RightToLeft) { - textRect.moveRight(right); - } - - return textRect; -} - -Delegate::Delegate(QObject *parent) - : QAbstractItemDelegate(parent), - d(new DelegatePrivate) -{ - d->svg = new FrameSvg(this); - d->svg->setImagePath("widgets/viewitem"); - d->svg->setElementPrefix("hover"); -} - -Delegate::~Delegate() -{ - delete d; -} - -void Delegate::setRoleMapping(SpecificRoles role, int actual) -{ - d->roles[role] = actual; -} - -int Delegate::roleMapping(SpecificRoles role) const -{ - return d->roles[role]; -} - -QRect Delegate::rectAfterTitle(const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - QRect textRect = d->titleRect(option, index); - - QRect emptyRect(0, textRect.top(), option.rect.width() - textRect.width() - DelegatePrivate::ITEM_LEFT_MARGIN - DelegatePrivate::ITEM_RIGHT_MARGIN - option.decorationSize.width() - DelegatePrivate::ICON_TEXT_MARGIN, textRect.height()); - - if (option.direction == Qt::LeftToRight) { - emptyRect.moveLeft(textRect.right()); - } else { - emptyRect.moveRight(textRect.left()); - } - - if (emptyRect.width() < 0) { - emptyRect.setWidth(0); - } - - return emptyRect; -} - -QRect Delegate::rectAfterSubTitle(const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - QRect textRect = d->subTitleRect(option, index); - - QRect emptyRect(0, textRect.top(), option.rect.width() - textRect.width() - DelegatePrivate::ITEM_LEFT_MARGIN - DelegatePrivate::ITEM_RIGHT_MARGIN - option.decorationSize.width() - DelegatePrivate::ICON_TEXT_MARGIN, textRect.height()); - - if (option.direction == Qt::LeftToRight) { - emptyRect.moveLeft(textRect.right()); - } else { - emptyRect.moveRight(textRect.left()); - } - - if (emptyRect.width() < 0) { - emptyRect.setWidth(0); - } - - return emptyRect; -} - -QRect Delegate::emptyRect(const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - QRect afterTitleRect = rectAfterTitle(option, index); - QRect afterSubTitleRect = rectAfterSubTitle(option, index); - - afterTitleRect.setHeight(afterTitleRect.height() * 2); - afterSubTitleRect.setTop(afterTitleRect.top()); - - return afterTitleRect.intersected(afterSubTitleRect); -} - -void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const -{ - const bool hover = option.state & (QStyle::State_MouseOver | QStyle::State_Selected); - - QRect contentRect = option.rect; - contentRect.setBottom(contentRect.bottom() - 1); - - QRect decorationRect = - QStyle::alignedRect(option.direction, - option.decorationPosition == QStyleOptionViewItem::Left ? - Qt::AlignLeft : Qt::AlignRight, - option.decorationSize, - contentRect.adjusted(DelegatePrivate::ITEM_LEFT_MARGIN, DelegatePrivate::ITEM_TOP_MARGIN, -DelegatePrivate::ITEM_RIGHT_MARGIN, -DelegatePrivate::ITEM_BOTTOM_MARGIN)); - decorationRect.moveTop(contentRect.top() + qMax(0, (contentRect.height() - decorationRect.height())) / 2); - - QString titleText = index.data(Qt::DisplayRole).value(); - QString subTitleText = index.data(d->roles[SubTitleRole]).value(); - //kDebug() << subTitleText; - - QRect titleRect = d->titleRect(option, index); - titleRect.moveTopLeft(titleRect.topLeft()-option.rect.topLeft()); - QRect subTitleRect = d->subTitleRect(option, index); - subTitleRect.moveTopLeft(subTitleRect.topLeft()-option.rect.topLeft()); - - if (subTitleText == titleText) { - subTitleText.clear(); - } - - QFont titleFont(option.font); - - // draw icon - QIcon decorationIcon = index.data(Qt::DecorationRole).value(); - - if (index.data(d->roles[ColumnTypeRole]).toInt() == SecondaryActionColumn) { - if (hover) { - // Only draw on hover - const int delta = floor((qreal)(option.decorationSize.width() - DelegatePrivate::ACTION_ICON_SIZE) / 2.0); - decorationRect.adjust(delta, delta-1, -delta-1, -delta); - decorationIcon.paint(painter, decorationRect, option.decorationAlignment); - } - } else { - // as default always draw as main column - decorationIcon.paint(painter, decorationRect, option.decorationAlignment); - } - - QPixmap buffer(option.rect.size()); - buffer.fill(Qt::transparent); - QPainter p(&buffer); - // draw title - p.setFont(titleFont); - if (option.palette.color(QPalette::Base).alpha() > 0) { - p.setPen(QPen(KColorScheme(QPalette::Active).foreground(KColorScheme::NormalText), 1)); - } else { - p.setPen(Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor)); - } - p.drawText(titleRect, Qt::AlignLeft|Qt::AlignVCenter, titleText); - - // draw sub-title, BUT only if: - // * SubTitleMandatoryRole is defined and model returns 'true' - // * SubTitleMandatoryRole is not defined and the adjasent model indexes - // have the same contents of the Qt::DisplayRole - // * when model doesn't provide a valid data for SubTitleMandatory role - // we also show title on mouse hover - // - // the rationale for this is that subtitle text should in most cases not be - // required to understand the item itself and that showing all the subtexts in a - // listing makes the information density very high, impacting both the speed at - // which one can scan the list visually and the aesthetic qualities of the listing. - bool drawSubTitle = !subTitleText.isEmpty(); - - if (drawSubTitle && !hover) { - // If the model wants to have exact control for subtitles showing - // it is expected to return a valid data for SubTitleMandatoryRole. - // If it doesn't return a valid data for this role - // then by default we well be showing a subtitles for - // adjasent items with the same content (see comments below too) - QVariant mandatoryRoleData = index.data(d->roles[SubTitleMandatoryRole]); - if (mandatoryRoleData.isValid()) { - drawSubTitle = mandatoryRoleData.value(); - } else { - bool uniqueTitle = true; - QModelIndex sib = index.sibling(index.row() + 1, index.column()); - if (sib.isValid()) { - uniqueTitle = sib.data(Qt::DisplayRole).value() != titleText; - } - - if (uniqueTitle) { - sib = index.sibling(index.row() + -1, index.column()); - if (sib.isValid()) { - uniqueTitle = sib.data(Qt::DisplayRole).value() != titleText; - } - } - - drawSubTitle = !uniqueTitle; - } - } - - - if (drawSubTitle) { - if (option.palette.color(QPalette::Base).alpha() > 0) { - p.setPen(QPen(KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText), 1)); - } else { - QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); - textColor.setAlphaF(0.6); - p.setPen(textColor); - } - - const QFont subTitleFont = d->fontForSubTitle(option.font); - p.setFont(subTitleFont); - p.drawText(subTitleRect, Qt::AlignLeft|Qt::AlignVCenter, subTitleText); - } - p.end(); - - - d->m_showToolTip = false; - - const QColor gradientColor = KColorScheme(QPalette::Active).background(KColorScheme::NormalBackground).color(); - - if (option.direction == Qt::LeftToRight) { - if (((titleRect.width() + decorationRect.width() + 10) > option.rect.width() || - (subTitleRect.width() + decorationRect.width() + 15) > option.rect.width()) && - (titleRect.width() > 120 || subTitleRect.width() > 120)) { - QPainter p(&buffer); - p.setCompositionMode(QPainter::CompositionMode_DestinationOut); - p.setPen(Qt::NoPen); - QLinearGradient gr; - QRect gradientRect(option.rect.width() - 60, titleRect.y(), - 80, titleRect.height() + subTitleRect.height()); - // draw it on the right side - gr.setStart(gradientRect.topLeft()); - gr.setFinalStop(gradientRect.topRight()); - gr.setColorAt(0.0, Qt::transparent); - gr.setColorAt(0.7, gradientColor); - p.setBrush(QBrush(gr)); - p.drawRect(gradientRect); - d->m_showToolTip = true; - p.end(); - } - - } else { - if (((titleRect.width() + decorationRect.width() + 10) > option.rect.width() || - (subTitleRect.width() + decorationRect.width() + 15 )> option.rect.width()) && - (titleRect.width() > 120 || subTitleRect.width() > 120)) { - buffer.fill(Qt::transparent); - QPainter p(&buffer); - p.setCompositionMode(QPainter::CompositionMode_DestinationOut); - p.setPen(Qt::NoPen); - QLinearGradient gr; - QRect gradientRect(option.rect.x() - 55, titleRect.y(), - 60, titleRect.height() + subTitleRect.height()); - gr.setStart(gradientRect.topRight()); - gr.setFinalStop(gradientRect.topLeft()); - gr.setColorAt(0.0, Qt::transparent); - gr.setColorAt(0.6, gradientColor); - p.setBrush(QBrush(gr)); - p.drawRect(gradientRect); - - d->m_showToolTip = true; - p.end(); - } - } - - painter->drawPixmap(option.rect, buffer, buffer.rect()); - - if (hover) { - painter->save(); - painter->setRenderHint(QPainter::Antialiasing); - - const int column = index.column(); - const int columns = index.model()->columnCount(); - int roundedRadius = 5; - const bool useSvg = option.palette.color(QPalette::Base).alpha() == 0; - - // use a slightly translucent version of the palette's highlight color - // for the background - QColor backgroundColor = option.palette.color(QPalette::Highlight); - backgroundColor.setAlphaF(0.2); - - QColor backgroundColor2 = option.palette.color(QPalette::Highlight); - backgroundColor2.setAlphaF(0.5); - - QRect highlightRect = option.rect; - if (!useSvg) { - highlightRect.adjust(2, 2, -2, -2); - } - - QPen outlinePen(backgroundColor, 2); - - if (column == 0) { - //clip right (or left for rtl languages) to make the connection with the next column - if (columns > 1) { - if (useSvg) { - roundedRadius = d->svg->marginSize(Plasma::RightMargin); - } - painter->setClipRect(option.rect); - highlightRect.adjust(0, 0, roundedRadius, 0); - } - - QLinearGradient gradient(highlightRect.topLeft(), highlightRect.topRight()); - - //reverse the gradient - if (option.direction == Qt::RightToLeft) { - gradient.setStart(highlightRect.topRight()); - gradient.setFinalStop(highlightRect.topLeft()); - } - - gradient.setColorAt(0, backgroundColor); - gradient.setColorAt(((qreal)titleRect.width()/3.0) / (qreal)highlightRect.width(), backgroundColor2); - gradient.setColorAt(0.7, backgroundColor); - outlinePen.setBrush(gradient); - //last column, clip left (right for rtl) - } else if (column == columns-1) { - if (useSvg) { - roundedRadius = d->svg->marginSize(Plasma::LeftMargin); - } - painter->setClipRect(option.rect); - highlightRect.adjust(-roundedRadius, 0, 0, 0); - - //column < columns-1; clip both ways - } else { - if (useSvg) { - roundedRadius = d->svg->marginSize(Plasma::LeftMargin); - } - painter->setClipRect(option.rect); - highlightRect.adjust(-roundedRadius, 0, +roundedRadius, 0); - } - - //if the view is transparent paint as plasma, otherwise paint with kde colors - if (useSvg) { - d->svg->resizeFrame(highlightRect.size()); - d->svg->paintFrame(painter, highlightRect.topLeft()); - } else { - painter->setPen(outlinePen); - painter->drawPath(PaintUtils::roundedRectangle(highlightRect, roundedRadius)); - } - - painter->restore(); - } - - -} - -QSize Delegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const -{ - Q_UNUSED(index) - QSize size = option.rect.size(); - - QFontMetrics metrics(option.font); - - QFontMetrics subMetrics(d->fontForSubTitle(option.font)); - size.setHeight(qMax(option.decorationSize.height(), qMax(size.height(), metrics.height() + subMetrics.ascent()) + 3) + 4); -// kDebug() << "size hint is" << size << (metrics.height() + subMetrics.ascent()); - - const bool useSvg = option.palette.color(QPalette::Base).alpha() == 0; - - if (useSvg) { - qreal left, top, right, bottom; - d->svg->getMargins(left, top, right, bottom); - size += QSize(left+right, top+bottom); - } else { - size *= 1.1; - } - - return size; -} - -bool Delegate::showToolTip() const -{ - return d->m_showToolTip; -} - -} - - - -#include "moc_delegate.cpp" diff --git a/delegate.h b/delegate.h deleted file mode 100644 index 4aadd300d..000000000 --- a/delegate.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - Copyright 2007 Robert Knight - Copyright 2008 Marco Martin - - This library 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 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef PLASMA_DELEGATE_H -#define PLASMA_DELEGATE_H - -// Qt -#include - -// Plasma -#include - -namespace Plasma -{ - -class DelegatePrivate; - -/** - * @class Delegate plasma/delegate.h - * - * Item delegate for rendering items in Plasma menus implemented with item views. - * - * The delegate makes use of its own data roles that are: - * SubTitleRole: the text of the subtitle - * SubTitleMandatoryRole: if the subtitle is to always be displayed - * (as default the subtitle is displayed only on mouse over) - * NOTE: if model doesn't return a valid data for SubTitleMandatoryRole (i.e. if it returns QVaraint()) - * then subtitles will be shown for adjasent items with the same content and not shown - * otherwise. - * - * ColumnTypeRole: if the column is a main column (with title and subtitle) - * or a secondary action column (only a little icon that appears on mouse - * over is displayed) - */ -class PLASMA_EXPORT Delegate : public QAbstractItemDelegate -{ - Q_OBJECT -public: - - enum SpecificRoles { - SubTitleRole = Qt::UserRole + 1, - SubTitleMandatoryRole = Qt::UserRole + 2, - ColumnTypeRole = Qt::UserRole + 3 - }; - - enum ColumnType { - MainColumn = 1, - SecondaryActionColumn = 2 - }; - - Delegate(QObject *parent = 0); - ~Delegate(); - - /** - * Maps an arbitrary role to a role belonging to SpecificRoles. - * Using this function you can use any model with this delegate. - * - * @param role a role belonging to SpecificRoles - * @param actual an arbitrary role of the model we are using - */ - void setRoleMapping(SpecificRoles role, int actual); - - int roleMapping(SpecificRoles role) const; - - //Reimplemented - virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; - - /** - * @return true if a tooltip should be shown - */ - bool showToolTip() const; - -protected: - /** - * Returns the empty area after the title. - * The height is the height of the subtitle. - * It can be used by subclasses that wants to paint additional data after - * calling the paint function of the superclass. - * - * @param option options for the title text - * @param index model index that we want to compute the free area - */ - QRect rectAfterTitle(const QStyleOptionViewItem &option, const QModelIndex &index) const; - - /** - * Returns the empty area after the subtitle. - * The height is the height of the subtitle. - * It can be used by subclasses, that wants to paint additional data. - * - * @param option options for the subtitle text - * @param index model index that we want to compute the free area - */ - QRect rectAfterSubTitle(const QStyleOptionViewItem &option, const QModelIndex &index) const; - - /** - * Returns the empty area after both the title and the subtitle. - * The height is the height of the item. - * It can be used by subclasses that wants to paint additional data - * - * @param option options for the title and subtitle text - * @param index model index that we want to compute the free area - */ - QRect emptyRect(const QStyleOptionViewItem &option, const QModelIndex &index) const; - - virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; - -private: - DelegatePrivate *const d; -}; - -} - -#endif // PLASMA_DELEGATE_H diff --git a/graphicsview/private/animablegraphicswebview.cpp b/graphicsview/private/animablegraphicswebview.cpp deleted file mode 100644 index 744cd2fdb..000000000 --- a/graphicsview/private/animablegraphicswebview.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2006-2007 Aaron Seigo - * Copyright 2010 Davide Bettio - * - * 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 "animablegraphicswebview_p.h" - -#include -#include -#include -#include - -#include -#include - -using namespace Plasma; - -AnimableGraphicsWebView::AnimableGraphicsWebView(QGraphicsItem * parent) - : GraphicsWebViewBase(parent) -{ - setAcceptTouchEvents(true); - m_dragToScroll = false; -} - -void AnimableGraphicsWebView::setDragToScroll(bool enable) -{ - m_dragToScroll = enable; -} - -bool AnimableGraphicsWebView::dragToScroll() const -{ - return m_dragToScroll; -} - -QSizeF AnimableGraphicsWebView::contentsSize() const -{ - if (!page()) { - return QSizeF(); - } else { - return page()->mainFrame()->contentsSize(); - } -} - -void AnimableGraphicsWebView::setScrollPosition(const QPointF &position) -{ - if (!page()) { - return; - } else { - page()->mainFrame()->setScrollPosition(position.toPoint()); - } -} - -QPointF AnimableGraphicsWebView::scrollPosition() const -{ - if (!page() || !page()->mainFrame()) { - return QPointF(); - } else { - return page()->mainFrame()->scrollPosition(); - } -} - -qreal AnimableGraphicsWebView::zoom() const -{ - return GraphicsWebViewBase::zoomFactor(); -} - -void AnimableGraphicsWebView::setZoom(const qreal zoom) -{ - GraphicsWebViewBase::setZoomFactor(zoom); -} - -QRectF AnimableGraphicsWebView::viewportGeometry() const -{ - QRectF result; - if (!page()) { - return result; - } else { - return page()->mainFrame()->geometry(); - } -} - -void AnimableGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if (!page()) { - GraphicsWebViewBase::mouseMoveEvent(event); - return; - } - - if (m_dragToScroll) { - return; - } - - QMouseEvent me(QEvent::MouseMove, event->pos().toPoint(), event->button(), - event->buttons(), event->modifiers()); - page()->event(&me); - - if (me.isAccepted()) { - event->accept(); - } -} - -void AnimableGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if (!page()) { - GraphicsWebViewBase::mousePressEvent(event); - return; - } - - m_lastScrollPosition = scrollPosition(); - setFocus(); - - QMouseEvent me(QEvent::MouseButtonPress, event->pos().toPoint(), - event->button(), event->buttons(), event->modifiers()); - - page()->event(&me); - if (me.isAccepted() && !m_dragToScroll) { - event->accept(); - } -} - -void AnimableGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - if (!page()) { - GraphicsWebViewBase::mouseReleaseEvent(event); - return; - } - - QMouseEvent me(QEvent::MouseButtonRelease, event->pos().toPoint(), - event->button(),event->buttons(), event->modifiers()); - - if (!m_dragToScroll || (scrollPosition() - m_lastScrollPosition).manhattanLength() < QApplication::startDragDistance()) { - page()->event(&me); - } - - if (me.isAccepted() && !m_dragToScroll) { - event->accept(); - } -} - -void AnimableGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent *event) -{ - if (!page()) { - GraphicsWebViewBase::wheelEvent(event); - return; - } - - QWheelEvent we(event->pos().toPoint(), event->delta(), event->buttons(), - event->modifiers(), event->orientation()); - page()->event(&we); - - event->setAccepted(!m_dragToScroll); -} - -qreal AnimableGraphicsWebView::scrollPositionX() const -{ - return page()->mainFrame()->scrollPosition().x(); -} - -void AnimableGraphicsWebView::setScrollPositionX(qreal position) -{ - QPointF pt(position, scrollPositionY()); - setScrollPosition(pt); -} - -qreal AnimableGraphicsWebView::scrollPositionY() const -{ - return page()->mainFrame()->scrollPosition().y(); -} - -void AnimableGraphicsWebView::setScrollPositionY(qreal position) -{ - QPointF pt(scrollPositionX(), position); - setScrollPosition(pt); -} - - -#include "moc_animablegraphicswebview_p.cpp" - diff --git a/graphicsview/private/animablegraphicswebview_p.h b/graphicsview/private/animablegraphicswebview_p.h deleted file mode 100644 index 5b199b43d..000000000 --- a/graphicsview/private/animablegraphicswebview_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2006-2007 Aaron Seigo - * Copyright 2010 Davide Bettio - * - * 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 ANIMABLEWEBVIEW_P_H -#define ANIMABLEWEBVIEW_P_H - -#include -#include -#include -#include -#include - -#include - -#if !PLASMA_NO_KDEWEBKIT -#include -#define GraphicsWebViewBase KGraphicsWebView -#else -#include -#define GraphicsWebViewBase QGraphicsWebView -#endif - -namespace Plasma -{ - -class AnimableGraphicsWebView : public GraphicsWebViewBase -{ - Q_OBJECT - - Q_PROPERTY(qreal zoomFactor READ zoom WRITE setZoom) - Q_PROPERTY(QPointF scrollPosition READ scrollPosition WRITE setScrollPosition) - Q_PROPERTY(qreal scrollPositionX READ scrollPositionX WRITE setScrollPositionX) - Q_PROPERTY(qreal scrollPositionY READ scrollPositionY WRITE setScrollPositionY) - Q_PROPERTY(QSizeF contentsSize READ contentsSize) - Q_PROPERTY(QRectF viewportGeometry READ viewportGeometry) - -public: - AnimableGraphicsWebView(QGraphicsItem * parent = 0); - - QPointF scrollPosition() const; - void setScrollPosition(const QPointF &position); - qreal scrollPositionX() const; - void setScrollPositionX(qreal position); - qreal scrollPositionY() const; - void setScrollPositionY(qreal position); - QSizeF contentsSize() const; - QRectF viewportGeometry() const; - void setDragToScroll(bool enable); - bool dragToScroll() const; - qreal zoom() const; - void setZoom(const qreal zoom); - -protected: - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void wheelEvent(QGraphicsSceneWheelEvent *event); - -private: - bool m_dragToScroll; - QPointF m_lastScrollPosition; -}; - -} - -#endif diff --git a/graphicsview/private/corona_p.h b/graphicsview/private/corona_p.h deleted file mode 100644 index d2d19abfa..000000000 --- a/graphicsview/private/corona_p.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2007-2011 Aaron Seigo - * - * 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_CORONA_P_H -#define PLASMA_CORONA_P_H - -#include - -#include - -class KShortcutsDialog; - -namespace Plasma -{ - -class Containment; -class CoronaBase; - -class CoronaPrivate -{ -public: - CoronaPrivate(Corona *corona); - ~CoronaPrivate(); - - void init(); - void offscreenWidgetDestroyed(QObject *); - - static bool s_positioningContainments; - - Corona *q; - QHash offscreenWidgets; - CoronaBase *coronaBase; -}; - -} - -#endif diff --git a/graphicsview/private/focusindicator.cpp b/graphicsview/private/focusindicator.cpp deleted file mode 100644 index 05f678d8a..000000000 --- a/graphicsview/private/focusindicator.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Copyright 2009 Marco Martin - * - * 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 "focusindicator_p.h" - -#include -#include -#include -#include - -#include -#include - -#include - -namespace Plasma -{ - -FocusIndicator::FocusIndicator(QGraphicsWidget *parent, const QString &widget) - : QGraphicsWidget(parent), - m_parent(parent), - m_background(new Plasma::FrameSvg(this)), - m_isUnderMouse(false) -{ - m_background->setImagePath(widget); - init(parent); -} - -FocusIndicator::FocusIndicator(QGraphicsWidget *parent, FrameSvg *svg) - : QGraphicsWidget(parent), - m_parent(parent), - m_background(svg), - m_isUnderMouse(false) -{ - init(parent); -} - -void FocusIndicator::init(QGraphicsWidget *parent) -{ - setVisible(!Theme::defaultTheme()->useNativeWidgetStyle()); - setFlag(QGraphicsItem::ItemStacksBehindParent); - setAcceptsHoverEvents(true); - - m_background->setCacheAllRenderedFrames(true); - - m_fade = Animator::create(Animator::FadeAnimation, this); - m_fade->setTargetWidget(this); - m_fade->setProperty("startOpacity", 0.0); - m_fade->setProperty("targetOpacity", 1.0); - - m_hoverAnimation = Animator::create(Animator::PixmapTransitionAnimation); - m_hoverAnimation->setProperty("duration", 250); - m_hoverAnimation->setTargetWidget(this); - - m_testPrefix = "hover"; - if (m_background->hasElementPrefix("shadow") || - m_background->hasElement("shadow")) { - m_prefix = "shadow"; - } - - parent->installEventFilter(this); - connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(syncGeometry())); -} - -FocusIndicator::~FocusIndicator() -{ - m_parent->removeEventFilter(this); - delete m_fade; -} - -void FocusIndicator::setCustomGeometry(const QRectF &geometry) -{ - if (m_customGeometry == geometry) { - return; - } - - m_customGeometry = geometry; - syncGeometry(); -} - -void FocusIndicator::setCustomPrefix(const QString &prefix) -{ - QString was = m_prefix; - if (!m_prefix.isEmpty() && !m_customPrefix.isEmpty()) { - m_prefix.remove(m_customPrefix); - } - - m_customPrefix = prefix; - - if (!m_prefix.isEmpty()) { - m_prefix.prepend(m_customPrefix); - } - - m_testPrefix = m_customPrefix % "hover"; - if (m_prefix.isEmpty()) { - m_prefix = m_customPrefix % "shadow"; - } - - if (m_prefix == was) { - return; - } - - syncGeometry(); - resizeEvent(0); -} - -bool FocusIndicator::eventFilter(QObject *watched, QEvent *event) -{ - if (Theme::defaultTheme()->useNativeWidgetStyle() || - static_cast(watched) != m_parent || !m_parent ) { - return false; - } - - if (event->type() == QEvent::GraphicsSceneHoverEnter) { - m_isUnderMouse = true; - } else if (event->type() == QEvent::GraphicsSceneHoverLeave) { - m_isUnderMouse = false; - } - - switch (event->type()) { - case QEvent::GraphicsSceneHoverEnter: - if (!m_parent->hasFocus()) { - m_prefix = m_customPrefix % "hover"; - syncGeometry(); - m_hoverAnimation->stop(); - if (m_background->hasElementPrefix(m_testPrefix)) { - m_background->setElementPrefix(m_customPrefix % "shadow"); - m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap()); - m_background->setElementPrefix(m_customPrefix % "hover"); - m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap()); - } else if (m_background->hasElement(m_testPrefix)) { - m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "shadow")); - m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "hover")); - } - - m_hoverAnimation->start(); - } - break; - - case QEvent::GraphicsSceneHoverLeave: - if (!m_parent->hasFocus()) { - m_prefix = m_customPrefix % "shadow"; - syncGeometry(); - m_hoverAnimation->stop(); - - if (m_background->hasElementPrefix(m_testPrefix)) { - m_background->setElementPrefix(m_customPrefix % "hover"); - m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap()); - m_background->setElementPrefix(m_customPrefix % "shadow"); - m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap()); - } else if (m_background->hasElement(m_testPrefix)) { - m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "hover")); - m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "shadow")); - } - m_hoverAnimation->start(); - } - break; - - case QEvent::GraphicsSceneResize: - syncGeometry(); - break; - - case QEvent::FocusIn: - m_prefix = m_customPrefix % "focus"; - syncGeometry(); - m_hoverAnimation->stop(); - - if (m_background->hasElementPrefix(m_customPrefix % "focus")) { - //m_background->setElementPrefix(m_customPrefix % "shadow"); - m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap()); - m_background->setElementPrefix(m_customPrefix % "focus"); - m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap()); - } else if (m_background->hasElement(m_customPrefix % "focus")) { - //m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "shadow")); - m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "focus")); - } - - m_hoverAnimation->start(); - break; - - case QEvent::FocusOut: - if (!m_isUnderMouse) { - m_prefix = m_customPrefix % "shadow"; - syncGeometry(); - m_hoverAnimation->stop(); - - if (m_background->hasElementPrefix(m_customPrefix % "focus")) { - m_background->setElementPrefix("focus"); - m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap()); - m_background->setElementPrefix("shadow"); - m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap()); - } else if (m_background->hasElement(m_customPrefix % "focus")) { - m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_customPrefix % "focus")); - m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_customPrefix % "shadow")); - } - - m_hoverAnimation->start(); - } - break; - - default: - break; - }; - - return false; -} - -void FocusIndicator::resizeEvent(QGraphicsSceneResizeEvent *) -{ - if (m_background->hasElementPrefix(m_customPrefix % "shadow")) { - m_background->setElementPrefix(m_customPrefix % "shadow"); - m_background->resizeFrame(size()); - } - - if (m_background->hasElementPrefix(m_customPrefix % "hover")) { - m_background->setElementPrefix(m_customPrefix % "hover"); - m_background->resizeFrame(size()); - } - - if (m_background->hasElementPrefix(m_customPrefix % "focus")) { - m_background->setElementPrefix(m_customPrefix % "focus"); - m_background->resizeFrame(size()); - } - - if (m_hoverAnimation->state() == QAbstractAnimation::Running) { - m_hoverAnimation->stop(); - } - - if (m_background->hasElementPrefix(m_testPrefix)) { - m_background->setElementPrefix(m_prefix); - m_hoverAnimation->setProperty("startPixmap", m_background->framePixmap()); - m_hoverAnimation->setProperty("targetPixmap", m_background->framePixmap()); - } else if (m_background->hasElement(m_testPrefix)) { - m_hoverAnimation->setProperty("startPixmap", m_background->pixmap(m_prefix)); - m_hoverAnimation->setProperty("targetPixmap", m_background->pixmap(m_prefix)); - } -} - -void FocusIndicator::animateVisibility(const bool visible) -{ - m_fade->setProperty("startOpacity", opacity()); - - if (visible) { - m_fade->setProperty("targetOpacity", 1.0); - } else { - m_fade->setProperty("targetOpacity", 0); - } - m_fade->start(); -} - -void FocusIndicator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(option) - Q_UNUSED(widget) - - painter->drawPixmap( - option->rect, - m_hoverAnimation->property("currentPixmap").value()); -} - -void FocusIndicator::syncGeometry() -{ - if (Theme::defaultTheme()->useNativeWidgetStyle()) { - hide(); - return; - } else if (!isVisible()) { - show(); - } - - QRectF geom; - if (!m_customGeometry.isEmpty()) { - geom = m_customGeometry; - } else { - geom = m_parent->boundingRect(); - } - - if (m_background->hasElementPrefix(m_testPrefix)) { - //always take borders from hover to make it stable - m_background->setElementPrefix(m_testPrefix); - qreal left, top, right, bottom; - m_background->getMargins(left, top, right, bottom); - m_background->setElementPrefix(m_prefix); - setGeometry(QRectF(geom.topLeft() + QPointF(-left, -top), geom.size() + QSize(left+right, top+bottom))); - } else if (m_background->hasElement(m_testPrefix)) { - QRectF elementRect = m_background->elementRect(m_testPrefix); - elementRect.moveCenter(geom.center()); - setGeometry(elementRect); - } -} - -void FocusIndicator::setFrameSvg(FrameSvg *frameSvg) -{ - if (m_background != frameSvg) { - m_background = frameSvg; - } -} - -FrameSvg *FocusIndicator::frameSvg() const -{ - return m_background; -} - -} - -#include "moc_focusindicator_p.cpp" - diff --git a/graphicsview/private/focusindicator_p.h b/graphicsview/private/focusindicator_p.h deleted file mode 100644 index 12a81d088..000000000 --- a/graphicsview/private/focusindicator_p.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2009 Marco Martin - * - * 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_FOCUSINDICATOR_P -#define PLASMA_FOCUSINDICATOR_P - -#include - -#include - -namespace Plasma -{ - class FrameSvg; - class FadeAnimation; - -class FocusIndicator : public QGraphicsWidget -{ - Q_OBJECT -public: - FocusIndicator(QGraphicsWidget *parent, const QString &widget); - FocusIndicator(QGraphicsWidget *parent, FrameSvg *svg); - ~FocusIndicator(); - - void setCustomGeometry(const QRectF &geometry); - void setCustomPrefix(const QString &prefix); - - void animateVisibility(const bool visible); - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - - void setFrameSvg(FrameSvg *svg); - FrameSvg *frameSvg() const; - -protected: - bool eventFilter(QObject *watched, QEvent *event); - void resizeEvent(QGraphicsSceneResizeEvent *event); - -private Q_SLOTS: - void syncGeometry(); - -private: - void init(QGraphicsWidget *parent); - QGraphicsWidget *m_parent; - Plasma::FrameSvg *m_background; - Animation *m_fade; - Animation *m_hoverAnimation; - QRectF m_customGeometry; - QString m_prefix; - QString m_customPrefix; - QString m_testPrefix; - bool m_isUnderMouse; -}; -} -#endif diff --git a/graphicsview/private/graphicsviewappletprivate.cpp b/graphicsview/private/graphicsviewappletprivate.cpp deleted file mode 100644 index 66c4a4c6e..000000000 --- a/graphicsview/private/graphicsviewappletprivate.cpp +++ /dev/null @@ -1,549 +0,0 @@ -/* - * Copyright 2011 by Aaron Seigo - * - * 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 -#include - -#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) -{ - q->setCacheMode(QGraphicsItem::DeviceCoordinateCache); - q->setAcceptsHoverEvents(true); - q->setFlag(QGraphicsItem::ItemIsFocusable, true); - q->setFocusPolicy(Qt::ClickFocus); - // FIXME: adding here because nothing seems to be doing it in QGraphicsView, - // but it doesn't actually work anyways =/ - q->setLayoutDirection(qApp->layoutDirection()); -} - -void GraphicsViewAppletPrivate::showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons) -{ - if (message.isEmpty()) { - destroyMessageOverlay(); - return; - } - - Corona *corona = qobject_cast(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(KDE::icon("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(KDE::icon("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(KDE::icon("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