Merge branch 'mart/qgvremoval2' into frameworks
This commit is contained in:
commit
8e89ac742c
158
CMakeLists.txt
158
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})
|
||||
|
||||
|
@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "abstracttoolbox.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include "containment.h"
|
||||
|
||||
#include <kservicetypetrader.h>
|
||||
|
||||
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<QGraphicsItem *>(parent)),
|
||||
d(new AbstractToolBoxPrivate(qobject_cast<Containment *>(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<AbstractToolBox>(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"
|
@ -1,157 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ABSTRACTTOOLBOX_H
|
||||
#define PLASMA_ABSTRACTTOOLBOX_H
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
#include <QGraphicsItem>
|
||||
|
||||
#include <kplugininfo.h>
|
||||
|
||||
#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<classname>();) \
|
||||
K_EXPORT_PLUGIN(factory("plasma_toolbox_" #libname)) \
|
||||
K_EXPORT_PLUGIN_VERSION(PLASMA_VERSION)
|
||||
|
||||
#endif // multiple inclusion guard
|
||||
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
*
|
||||
* 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 <QMapIterator>
|
||||
#include <QObject>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QSequentialAnimationGroup>
|
||||
#include <QDebug>
|
||||
#include <kdebug.h>
|
||||
#include <kglobalsettings.h>
|
||||
|
||||
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"
|
@ -1,153 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
*
|
||||
* 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 <QGraphicsWidget>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPropertyAnimation>
|
||||
#include <QtCore/QAbstractAnimation>
|
||||
#include <QtCore/QEasingCurve>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/plasma.h>
|
||||
|
||||
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
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "easinganimation_p.h"
|
||||
#include <kdebug.h>
|
||||
|
||||
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"
|
||||
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_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
|
||||
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
*
|
||||
* 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 <QRect>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
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"
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
*
|
||||
* 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 <plasma/animations/easinganimation_p.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
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
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
*
|
||||
* 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 <QRect>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
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"
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
*
|
||||
* 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 <plasma/animations/easinganimation_p.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
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
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
*
|
||||
* 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 <QRect>
|
||||
#include <kdebug.h>
|
||||
|
||||
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"
|
||||
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
*
|
||||
* 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 <plasma/animations/easinganimation_p.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
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
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "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
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Bruno Abinader <bruno.abinader@indt.org.br>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ANIMATIONS_PENDULUMCURVE_P_H
|
||||
#define PLASMA_ANIMATIONS_PENDULUMCURVE_P_H
|
||||
|
||||
#include <QtCore/QEasingCurve>
|
||||
|
||||
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
|
@ -1,179 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
* Copyright 2010 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "pixmaptransition_p.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
#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<PixmapTransition *>(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"
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
* Copyright 2010 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file This file contains the definition for the PixmapTransition effect.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H
|
||||
#define PLASMA_ANIMATIONS_PIXMAPTRANSITION_P_H
|
||||
|
||||
#include <plasma/animations/easinganimation_p.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
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
|
@ -1,144 +0,0 @@
|
||||
/* Copyright (C) 2009 Adenilson Cavalcanti <cavalcantii@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "widgetsnapshot_p.h"
|
||||
#include "pulser_p.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QGraphicsWidget>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QWeakPointer>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
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"
|
@ -1,110 +0,0 @@
|
||||
/* Copyright (C) 2009 Adenilson Cavalcanti <cavalcantii@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file This file contains the definition for the Pulse effect.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ANIMATIONS_PULSER_P_H
|
||||
#define PLASMA_ANIMATIONS_PULSER_P_H
|
||||
|
||||
#include <plasma/animations/easinganimation_p.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
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<WidgetSnapShot> m_under;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PLASMA_ANIMATIONS_PULSER_P_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,167 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <QGraphicsRotation>
|
||||
#include <QEasingCurve>
|
||||
#include <QVector3D>
|
||||
|
||||
#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<QGraphicsTransform *> 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"
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file This file contains the definition for the 2D Rotation effect.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ROTATION_P_H
|
||||
#define PLASMA_ROTATION_P_H
|
||||
|
||||
#include <plasma/animations/easinganimation_p.h>
|
||||
|
||||
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
|
@ -1,188 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "rotationstacked_p.h"
|
||||
#include <QGraphicsRotation>
|
||||
#include <QSequentialAnimationGroup>
|
||||
#include <QWeakPointer>
|
||||
#include <kdebug.h>
|
||||
|
||||
#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<QGraphicsTransform *> frontTransformation;
|
||||
QList<QGraphicsTransform *> backTransformation;
|
||||
|
||||
frontTransformation.append(m_frontRotation);
|
||||
backTransformation.append(m_backRotation);
|
||||
|
||||
targetWidget()->setTransformations(frontTransformation);
|
||||
backWidget()->setTransformations(backTransformation);
|
||||
}
|
||||
|
||||
} //namespace Plasma
|
||||
|
||||
#include "moc_rotationstacked_p.cpp"
|
@ -1,126 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file This file contains the definition for the StackedRotationAnimation.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ROTATIONSTACKED_P_H
|
||||
#define PLASMA_ROTATIONSTACKED_P_H
|
||||
|
||||
#include <plasma/animations/easinganimation_p.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
#include <QGraphicsLayoutItem>
|
||||
|
||||
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<QGraphicsWidget> m_backWidget;
|
||||
/** Layout where widget would be added */
|
||||
QWeakPointer<StackedLayout> 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
|
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
*
|
||||
* 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 <QPointF>
|
||||
#include <kdebug.h>
|
||||
|
||||
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"
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Mehmet Ali Akmanalp <makmanalp@wpi.edu>
|
||||
*
|
||||
* 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
|
@ -1,110 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "stackedlayout.h"
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
#include <QDebug>
|
||||
|
||||
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"
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef STACKEDLAYOUT_H
|
||||
#define STACKEDLAYOUT_H
|
||||
|
||||
/* TODO: document the methods */
|
||||
|
||||
#include <QGraphicsLayout>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
|
||||
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<QGraphicsLayoutItem *> items;
|
||||
qint32 m_currentWidgetIndex;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,128 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "widgetsnapshot_p.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QImage>
|
||||
#include <QPixmap>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QDebug>
|
||||
|
||||
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<QGraphicsItem *> 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<QImage>());
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_WIDGETSNAPSHOT_P_H
|
||||
#define PLASMA_WIDGETSNAPSHOT_P_H
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
|
||||
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
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
*
|
||||
* 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 <kdebug.h>
|
||||
|
||||
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
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
*
|
||||
* 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 <plasma/animations/easinganimation_p.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
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
|
130
animator.cpp
130
animator.cpp
@ -1,130 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "animator.h"
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
#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"
|
100
animator.h
100
animator.h
@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
||||
* 2007 Alexis Ménard <darktears31@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ANIMATOR_H
|
||||
#define PLASMA_ANIMATOR_H
|
||||
|
||||
#include <QImage>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QAbstractAnimation>
|
||||
#include <QtCore/QEasingCurve>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QGraphicsItem;
|
||||
class QGraphicsWidget;
|
||||
class QTimeLine;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AnimatorPrivate;
|
||||
class Animation;
|
||||
|
||||
/**
|
||||
* @class Animator plasma/animator.h <Plasma/Animator>
|
||||
*
|
||||
* @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, /*<<Zoom animation */
|
||||
PixmapTransitionAnimation, /*<< Transition between two pixmaps*/
|
||||
LastAnimation = 1024
|
||||
};
|
||||
|
||||
enum CurveShape {
|
||||
EaseInCurve = 0,
|
||||
EaseOutCurve,
|
||||
EaseInOutCurve,
|
||||
LinearCurve,
|
||||
PendularCurve
|
||||
};
|
||||
|
||||
explicit Animator(QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* Factory to build new animation objects. To control their behavior,
|
||||
* check \ref AbstractAnimation properties.
|
||||
* @since 4.4
|
||||
**/
|
||||
static Plasma::Animation *create(Animator::Animation type, QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* Factory to build new custom easing curves.
|
||||
* @since 4.5
|
||||
*/
|
||||
static QEasingCurve create(Animator::CurveShape type);
|
||||
|
||||
private:
|
||||
AnimatorPrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
||||
|
591
applet.cpp
591
applet.cpp
@ -25,21 +25,15 @@
|
||||
|
||||
#include "config-plasma.h"
|
||||
|
||||
#include <plasma/animations/animation.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QEvent>
|
||||
#include <QFile>
|
||||
#include <QGraphicsGridLayout>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsView>
|
||||
#include <QHostInfo>
|
||||
#include <QLabel>
|
||||
#include <QList>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QPainter>
|
||||
#include <QRegExp>
|
||||
#include <QSize>
|
||||
@ -76,7 +70,6 @@
|
||||
#include <solid/powermanagement.h>
|
||||
#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<Corona*>(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<Corona*>(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<Corona*>(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<Corona*>(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<Plasma::PopupApplet*>(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<QAction*> 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<Plasma::View*>(widget->parent());
|
||||
Containment* c = qobject_cast<Plasma::Containment*>(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<QGraphicsWidget *>(parent());
|
||||
if (!pw) {
|
||||
pw = dynamic_cast<QGraphicsWidget *>(parentItem());
|
||||
}
|
||||
QObject *pw = qobject_cast<QObject *>(parent());
|
||||
Plasma::Applet *parentApplet = qobject_cast<Plasma::Applet *>(pw);
|
||||
//assumption: this loop is usually is -really- short or doesn't run at all
|
||||
while (!parentApplet && pw && pw->parentWidget()) {
|
||||
QGraphicsWidget *parentWidget = qobject_cast<QGraphicsWidget *>(pw->parent());
|
||||
if (!parentWidget) {
|
||||
parentWidget = dynamic_cast<QGraphicsWidget *>(pw->parentItem());
|
||||
}
|
||||
pw = parentWidget;
|
||||
while (!parentApplet && pw && pw->parent()) {
|
||||
pw = pw->parent();
|
||||
parentApplet = qobject_cast<Plasma::Applet *>(pw);
|
||||
}
|
||||
|
||||
|
||||
const PopupApplet *pa = dynamic_cast<const PopupApplet *>(this);
|
||||
//FIXME: port away popupapplet
|
||||
//const PopupApplet *pa = dynamic_cast<const PopupApplet *>(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<PopupApplet *>(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<Containment *>(pw)) {
|
||||
break;
|
||||
} else if (qobject_cast<Applet *>(pw)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(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<QGraphicsSceneHoverEvent*>(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<Corona *>(qvariant_cast<QGraphicsScene*>(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<QGraphicsItem *>()
|
||||
<< name();
|
||||
|
||||
Applet *newC = dynamic_cast<Applet*>(value.value<QGraphicsItem *>());
|
||||
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.
|
||||
|
165
applet.h
165
applet.h
@ -22,8 +22,7 @@
|
||||
#ifndef PLASMA_APPLET_H
|
||||
#define PLASMA_APPLET_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QGraphicsWidget>
|
||||
#include <QObject>
|
||||
#include <QIcon>
|
||||
|
||||
#include <kconfiggroup.h>
|
||||
@ -33,14 +32,12 @@
|
||||
|
||||
#include <plasma/configloader.h>
|
||||
#include <plasma/plasma.h>
|
||||
#include <plasma/animator.h>
|
||||
#include <plasma/version.h>
|
||||
#include <plasma/framesvg.h>
|
||||
|
||||
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;
|
||||
|
393
containment.cpp
393
containment.cpp
@ -28,13 +28,10 @@
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QFile>
|
||||
#include <QGraphicsSceneContextMenuEvent>
|
||||
#include <QGraphicsView>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMimeData>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QGraphicsLayout>
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <qtemporaryfile.h>
|
||||
|
||||
#include <kaction.h>
|
||||
@ -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<Corona*>(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<Corona*>(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<Corona*>(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
|
||||
|
||||
|
||||
|
125
containment.h
125
containment.h
@ -22,15 +22,13 @@
|
||||
#ifndef PLASMA_CONTAINMENT_H
|
||||
#define PLASMA_CONTAINMENT_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
||||
#include <kplugininfo.h>
|
||||
#include <ksharedconfig.h>
|
||||
|
||||
#include <plasma/applet.h>
|
||||
#include <plasma/animator.h>
|
||||
|
||||
|
||||
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 *))
|
||||
|
@ -27,9 +27,9 @@
|
||||
#include <QMetaEnum>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <QGraphicsSceneContextMenuEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <klocalizedstring.h>
|
||||
@ -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<QMouseEvent*>(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<QGraphicsSceneMouseEvent*>(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<QWheelEvent*>(event);
|
||||
@ -198,17 +188,6 @@ QString ContainmentActions::eventToString(QEvent *event)
|
||||
modifiers = e->modifiers();
|
||||
break;
|
||||
}
|
||||
case QEvent::GraphicsSceneWheel:
|
||||
{
|
||||
QGraphicsSceneWheelEvent *e = static_cast<QGraphicsSceneWheelEvent*>(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<QGraphicsSceneMouseEvent*>(event)->screenPos();
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::MouseButtonDblClick:
|
||||
return static_cast<QMouseEvent*>(event)->globalPos();
|
||||
break;
|
||||
case QEvent::GraphicsSceneWheel:
|
||||
return static_cast<QGraphicsSceneWheelEvent*>(event)->screenPos();
|
||||
case QEvent::Wheel:
|
||||
return static_cast<QWheelEvent*>(event)->globalPos();
|
||||
break;
|
||||
case QEvent::GraphicsSceneContextMenu:
|
||||
return static_cast<QGraphicsSceneContextMenuEvent*>(event)->screenPos();
|
||||
case QEvent::ContextMenu:
|
||||
return static_cast<QContextMenuEvent*>(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<QGraphicsSceneMouseEvent*>(event)->scenePos();
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::MouseButtonDblClick:
|
||||
return static_cast<QMouseEvent*>(event)->pos();
|
||||
break;
|
||||
case QEvent::GraphicsSceneWheel:
|
||||
return static_cast<QGraphicsSceneWheelEvent*>(event)->scenePos();
|
||||
case QEvent::Wheel:
|
||||
return static_cast<QWheelEvent*>(event)->pos();
|
||||
break;
|
||||
case QEvent::GraphicsSceneContextMenu:
|
||||
return static_cast<QGraphicsSceneContextMenuEvent*>(event)->scenePos();
|
||||
case QEvent::ContextMenu:
|
||||
return static_cast<QContextMenuEvent*>(event)->pos();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -281,7 +260,7 @@ QPointF scenePosFromEvent(QEvent *event)
|
||||
|
||||
bool isNonSceneEvent(QEvent *event)
|
||||
{
|
||||
return dynamic_cast<QGraphicsSceneEvent *>(event) == 0;
|
||||
return dynamic_cast<QEvent *>(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<QGraphicsSceneContextMenuEvent *>(event)->reason() == QGraphicsSceneContextMenuEvent::Mouse) {
|
||||
if (event->type() != QEvent::ContextMenu ||
|
||||
static_cast<QContextMenuEvent *>(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) {
|
||||
|
@ -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);
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
|
||||
#include <QHash>
|
||||
#include <QEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <QString>
|
||||
|
||||
#include <kdebug.h>
|
||||
@ -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);
|
||||
}
|
||||
|
831
corona.cpp
831
corona.cpp
File diff suppressed because it is too large
Load Diff
97
corona.h
97
corona.h
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2007 Matt Broadstone <mbroadst@gmail.com>
|
||||
* Copyright 2012 Marco MArtin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
@ -18,16 +19,13 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_CORONA_H
|
||||
#define PLASMA_CORONA_H
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#ifndef PLASMA_CORONABASE_H
|
||||
#define PLASMA_CORONABASE_H
|
||||
|
||||
#include <plasma/containment.h>
|
||||
#include <plasma/plasma.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QGraphicsGridLayout;
|
||||
class QAction;
|
||||
|
||||
class KAction;
|
||||
@ -40,11 +38,11 @@ class ContainmentActionsPluginsConfig;
|
||||
class AbstractDialogManager;
|
||||
|
||||
/**
|
||||
* @class Corona plasma/corona.h <Plasma/Corona>
|
||||
* @class CoronaBase plasma/CoronaBase.h <Plasma/CoronaBase>
|
||||
*
|
||||
* @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<Containment*> 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 <QGraphicsWidget *> 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;
|
||||
|
739
coronabase.cpp
739
coronabase.cpp
@ -1,739 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 Matt Broadstone <mbroadst@gmail.com>
|
||||
* Copyright 2007-2011 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2007 Riccardo Iaconelli <riccardo@kde.org>
|
||||
* Copyright (c) 2009 Chani Armitage <chani@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "coronabase.h"
|
||||
#include "private/coronabase_p.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsGridLayout>
|
||||
#include <QMimeData>
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <kaction.h>
|
||||
#include <kdebug.h>
|
||||
#include <klocalizedstring.h>
|
||||
#include <kshortcutsdialog.h>
|
||||
#include <kwindowsystem.h>
|
||||
|
||||
#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<Containment*> 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<Plasma::Containment *> 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<Containment*> 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<Plasma::Location> CoronaBase::freeEdges(int screen) const
|
||||
{
|
||||
QList<Plasma::Location> 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<QAction*> 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<QWeakPointer<KActionCollection> > 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<QWeakPointer<KActionCollection> > 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<Plasma::Containment*>(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<Containment*>(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<Plasma::Containment *> CoronaBasePrivate::importLayout(const KConfigGroup &conf, bool mergeConfig)
|
||||
{
|
||||
if (!conf.isValid()) {
|
||||
return QList<Containment *>();
|
||||
}
|
||||
|
||||
QList<Plasma::Containment *> newContainments;
|
||||
QSet<uint> 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"
|
431
coronabase.h
431
coronabase.h
@ -1,431 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2007 Matt Broadstone <mbroadst@gmail.com>
|
||||
* Copyright 2012 Marco MArtin <mart@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_CORONABASE_H
|
||||
#define PLASMA_CORONABASE_H
|
||||
|
||||
#include <QGraphicsScene>
|
||||
|
||||
#include <plasma/containment.h>
|
||||
#include <plasma/plasma.h>
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QGraphicsGridLayout;
|
||||
class QAction;
|
||||
|
||||
class KAction;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class CoronaBasePrivate;
|
||||
class ContainmentActionsPluginsConfig;
|
||||
class AbstractDialogManager;
|
||||
|
||||
/**
|
||||
* @class CoronaBase plasma/CoronaBase.h <Plasma/CoronaBase>
|
||||
*
|
||||
* @short A QGraphicsScene for Plasma::Applets
|
||||
*/
|
||||
class PLASMA_EXPORT CoronaBase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
//typedef QHash<QString, QList<Plasma::Applet*> > 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<Containment*> 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<Plasma::Location> 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<QAction*> 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<Plasma::Containment *> 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<Containment*> 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
|
||||
|
@ -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 動畫引擎
|
||||
|
492
delegate.cpp
492
delegate.cpp
@ -1,492 +0,0 @@
|
||||
/*
|
||||
Copyright 2007 Robert Knight <robertknight@gmail.com>
|
||||
Copyright 2007 Kevin Ottens <ervin@kde.org>
|
||||
Copyright 2008 Marco Martin <notmart@gmail.com>
|
||||
|
||||
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 <cmath>
|
||||
#include <math.h>
|
||||
|
||||
// Qt
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
#include <QIcon>
|
||||
#include <QModelIndex>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionViewItem>
|
||||
|
||||
// KDE
|
||||
#include <kdebug.h>
|
||||
#include <kglobalsettings.h>
|
||||
#include <kcolorscheme.h>
|
||||
|
||||
// plasma
|
||||
#include <plasma/paintutils.h>
|
||||
#include <plasma/framesvg.h>
|
||||
|
||||
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<int, int> 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>();
|
||||
QString subTitleText = index.data(d->roles[SubTitleRole]).value<QString>();
|
||||
//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<QIcon>();
|
||||
|
||||
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<bool>();
|
||||
} else {
|
||||
bool uniqueTitle = true;
|
||||
QModelIndex sib = index.sibling(index.row() + 1, index.column());
|
||||
if (sib.isValid()) {
|
||||
uniqueTitle = sib.data(Qt::DisplayRole).value<QString>() != titleText;
|
||||
}
|
||||
|
||||
if (uniqueTitle) {
|
||||
sib = index.sibling(index.row() + -1, index.column());
|
||||
if (sib.isValid()) {
|
||||
uniqueTitle = sib.data(Qt::DisplayRole).value<QString>() != 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"
|
131
delegate.h
131
delegate.h
@ -1,131 +0,0 @@
|
||||
/*
|
||||
Copyright 2007 Robert Knight <robertknight@gmail.com>
|
||||
Copyright 2008 Marco Martin <notmart@gmail.com>
|
||||
|
||||
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 <QAbstractItemDelegate>
|
||||
|
||||
// Plasma
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class DelegatePrivate;
|
||||
|
||||
/**
|
||||
* @class Delegate plasma/delegate.h <Plasma/Delegate>
|
||||
*
|
||||
* 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
|
@ -1,193 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2010 Davide Bettio <davide.bettio@kdemail.net>
|
||||
*
|
||||
* 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 <QApplication>
|
||||
#include <QGestureEvent>
|
||||
#include <QPinchGesture>
|
||||
#include <QtWebKit/QWebFrame>
|
||||
|
||||
#include <qwebpage.h>
|
||||
#include <kglobalsettings.h>
|
||||
|
||||
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"
|
||||
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2010 Davide Bettio <davide.bettio@kdemail.net>
|
||||
*
|
||||
* 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 <QGraphicsSceneContextMenuEvent>
|
||||
#include <QGraphicsSceneDragDropEvent>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include <config-plasma.h>
|
||||
|
||||
#if !PLASMA_NO_KDEWEBKIT
|
||||
#include <kgraphicswebview.h>
|
||||
#define GraphicsWebViewBase KGraphicsWebView
|
||||
#else
|
||||
#include <qgraphicswebview.h>
|
||||
#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
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007-2011 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_CORONA_P_H
|
||||
#define PLASMA_CORONA_P_H
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include <kactioncollection.h>
|
||||
|
||||
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<uint, QGraphicsWidget*> offscreenWidgets;
|
||||
CoronaBase *coronaBase;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,322 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "focusindicator_p.h"
|
||||
|
||||
#include <QGraphicsSceneResizeEvent>
|
||||
#include <QPainter>
|
||||
#include <QStringBuilder>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
||||
#include <plasma/theme.h>
|
||||
#include <plasma/framesvg.h>
|
||||
|
||||
#include <plasma/animator.h>
|
||||
|
||||
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<QGraphicsWidget *>(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<QPixmap>());
|
||||
}
|
||||
|
||||
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"
|
||||
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_FOCUSINDICATOR_P
|
||||
#define PLASMA_FOCUSINDICATOR_P
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
|
||||
#include <plasma/animations/animation.h>
|
||||
|
||||
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
|
@ -1,549 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "graphicsviewappletprivate_p.h"
|
||||
|
||||
#include <QGraphicsLinearLayout>
|
||||
#include <QGraphicsGridLayout>
|
||||
|
||||
#include "kwindowsystem.h"
|
||||
|
||||
#include "corona.h"
|
||||
#include "dialog.h"
|
||||
#include "paintutils.h"
|
||||
#include "popupapplet.h"
|
||||
#include "theme.h"
|
||||
#include "tooltipmanager.h"
|
||||
#include "widgets/busywidget.h"
|
||||
#include "widgets/iconwidget.h"
|
||||
#include "widgets/label.h"
|
||||
#include "widgets/pushbutton.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
GraphicsViewAppletPrivate::GraphicsViewAppletPrivate(KService::Ptr service, const KPluginInfo *info, int uniqueID, Applet *applet)
|
||||
: AppletPrivate(service, info, uniqueID, applet),
|
||||
messageOverlay(0),
|
||||
messageOverlayProxy(0),
|
||||
busyWidget(0)
|
||||
{
|
||||
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<Corona *>(q->scene());
|
||||
QGraphicsWidget *mainWidget = new QGraphicsWidget;
|
||||
|
||||
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(mainWidget);
|
||||
mainLayout->setOrientation(Qt::Vertical);
|
||||
mainLayout->addStretch();
|
||||
|
||||
QGraphicsLinearLayout *messageLayout = new QGraphicsLinearLayout();
|
||||
messageLayout->setOrientation(Qt::Horizontal);
|
||||
|
||||
QGraphicsLinearLayout *buttonLayout = new QGraphicsLinearLayout();
|
||||
buttonLayout->setOrientation(Qt::Horizontal);
|
||||
|
||||
mainLayout->addItem(messageLayout);
|
||||
mainLayout->addItem(buttonLayout);
|
||||
mainLayout->addStretch();
|
||||
|
||||
IconWidget *messageIcon = new IconWidget(mainWidget);
|
||||
Label *messageText = new Label(mainWidget);
|
||||
messageText->nativeWidget()->setWordWrap(true);
|
||||
|
||||
messageLayout->addStretch();
|
||||
messageLayout->addItem(messageIcon);
|
||||
messageLayout->addItem(messageText);
|
||||
messageLayout->addStretch();
|
||||
|
||||
messageIcon->setIcon(icon);
|
||||
messageText->setText(message);
|
||||
|
||||
buttonLayout->addStretch();
|
||||
|
||||
if (buttons & ButtonOk) {
|
||||
messageOkButton = new PushButton(mainWidget);
|
||||
messageOkButton.data()->setText(i18n("&OK"));
|
||||
messageOkButton.data()->setIcon(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<Label *>(item);
|
||||
if (l) {
|
||||
l->setText(visibleFailureText(reason));
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//FIXME: q->prepareGeometryChange();
|
||||
|
||||
foreach (QGraphicsItem *item, q->childItems()) {
|
||||
if (!dynamic_cast<AppletHandle *>(item)) {
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
messageOverlay = 0;
|
||||
if (messageDialog) {
|
||||
messageDialog.data()->deleteLater();
|
||||
messageDialog.clear();
|
||||
}
|
||||
|
||||
q->setLayout(0);
|
||||
|
||||
if (failed) {
|
||||
q->setBackgroundHints(StandardBackground);
|
||||
|
||||
QGraphicsLinearLayout *failureLayout = new QGraphicsLinearLayout(q);
|
||||
failureLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
IconWidget *failureIcon = new IconWidget(q);
|
||||
failureIcon->setIcon(KDE::icon("dialog-error"));
|
||||
failureLayout->addItem(failureIcon);
|
||||
|
||||
Label *failureWidget = new Plasma::Label(q);
|
||||
failureWidget->setText(visibleFailureText(reason));
|
||||
QLabel *label = failureWidget->nativeWidget();
|
||||
label->setWordWrap(true);
|
||||
failureLayout->addItem(failureWidget);
|
||||
|
||||
Plasma::ToolTipManager::self()->registerWidget(failureIcon);
|
||||
Plasma::ToolTipContent data(i18n("Unable to load the widget"), reason,
|
||||
KDE::icon("dialog-error"));
|
||||
Plasma::ToolTipManager::self()->setContent(failureIcon, data);
|
||||
|
||||
q->setLayout(failureLayout);
|
||||
q->resize(300, 250);
|
||||
background->resizeFrame(q->geometry().size());
|
||||
}
|
||||
|
||||
q->update();
|
||||
}
|
||||
|
||||
void GraphicsViewAppletPrivate::cleanUpAndDelete()
|
||||
{
|
||||
//kDebug() << "???????????????? DESTROYING APPLET" << q->name() << q->scene() << " ???????????????????????????";
|
||||
QGraphicsWidget *parent = dynamic_cast<QGraphicsWidget *>(q->parentItem());
|
||||
//it probably won't matter, but right now if there are applethandles, *they* are the parent.
|
||||
//not the containment.
|
||||
|
||||
//is the applet in a containment and does the containment have a layout?
|
||||
//if yes, we remove the applet in the layout
|
||||
if (parent && parent->layout()) {
|
||||
QGraphicsLayout *l = parent->layout();
|
||||
for (int i = 0; i < l->count(); ++i) {
|
||||
if (q == l->itemAt(i)) {
|
||||
l->removeAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (configLoader) {
|
||||
configLoader->setDefaults();
|
||||
}
|
||||
|
||||
resetConfigurationObject();
|
||||
|
||||
if (q->scene()) {
|
||||
if (isContainment) {
|
||||
// prematurely emit our destruction if we are a Containment,
|
||||
// giving Corona a chance to remove this Containment from its collection
|
||||
emit q->QObject::destroyed(q);
|
||||
}
|
||||
|
||||
q->scene()->removeItem(q);
|
||||
}
|
||||
|
||||
q->deleteLater();
|
||||
}
|
||||
|
||||
void GraphicsViewAppletPrivate::showConfigurationRequiredMessage(bool show, const QString &reason)
|
||||
{
|
||||
if (!show) {
|
||||
destroyMessageOverlay();
|
||||
return;
|
||||
}
|
||||
|
||||
createMessageOverlay(true);
|
||||
messageOverlay->opacity = 0.4;
|
||||
|
||||
QGraphicsGridLayout *configLayout = new QGraphicsGridLayout(messageOverlay);
|
||||
configLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// configLayout->addStretch();
|
||||
configLayout->setColumnStretchFactor(0, 5);
|
||||
configLayout->setColumnStretchFactor(2, 5);
|
||||
configLayout->setRowStretchFactor(0, 5);
|
||||
configLayout->setRowStretchFactor(3, 5);
|
||||
|
||||
int row = 1;
|
||||
if (!reason.isEmpty()) {
|
||||
Label *explanation = new Label(messageOverlay);
|
||||
explanation->setText(reason);
|
||||
configLayout->addItem(explanation, row, 1);
|
||||
configLayout->setColumnStretchFactor(1, 5);
|
||||
++row;
|
||||
configLayout->setAlignment(explanation, Qt::AlignBottom | Qt::AlignCenter);
|
||||
}
|
||||
|
||||
PushButton *configWidget = new PushButton(messageOverlay);
|
||||
QObject::connect(configWidget, SIGNAL(clicked()), q, SLOT(showConfigurationInterface()));
|
||||
|
||||
const FormFactor formFactor = q->formFactor();
|
||||
if (!qobject_cast<Plasma::PopupApplet *>(q) && (formFactor == Plasma::Horizontal || formFactor == Plasma::Vertical)) {
|
||||
configWidget->setImage("widgets/configuration-icons", "configure");
|
||||
configWidget->setMaximumSize(24,24);
|
||||
configWidget->setMinimumSize(24,24);
|
||||
} else {
|
||||
configWidget->setText(i18n("Configure..."));
|
||||
}
|
||||
|
||||
configLayout->addItem(configWidget, row, 1);
|
||||
|
||||
//configLayout->setAlignment(configWidget, Qt::AlignTop | Qt::AlignCenter);
|
||||
//configLayout->addStretch();
|
||||
|
||||
messageOverlay->show();
|
||||
}
|
||||
|
||||
void GraphicsViewAppletPrivate::createMessageOverlay(bool usePopup)
|
||||
{
|
||||
if (messageOverlay) {
|
||||
qDeleteAll(messageOverlay->children());
|
||||
messageOverlay->setLayout(0);
|
||||
}
|
||||
|
||||
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
|
||||
|
||||
if (!messageOverlay) {
|
||||
if (usePopup && popup) {
|
||||
if (popup->widget()) {
|
||||
messageOverlayProxy = new QGraphicsProxyWidget(q);
|
||||
messageOverlayProxy->setWidget(popup->widget());
|
||||
messageOverlay = new AppletOverlayWidget(messageOverlayProxy);
|
||||
} else if (popup->graphicsWidget()) {
|
||||
messageOverlay = new AppletOverlayWidget(popup->graphicsWidget());
|
||||
}
|
||||
}
|
||||
|
||||
if (!messageOverlay) {
|
||||
messageOverlay = new AppletOverlayWidget(q);
|
||||
}
|
||||
}
|
||||
|
||||
positionMessageOverlay();
|
||||
}
|
||||
|
||||
void GraphicsViewAppletPrivate::positionMessageOverlay()
|
||||
{
|
||||
if (!messageOverlay) {
|
||||
return;
|
||||
}
|
||||
|
||||
PopupApplet *popup = qobject_cast<Plasma::PopupApplet*>(q);
|
||||
const bool usePopup = popup && (messageOverlay->parentItem() != q);
|
||||
QGraphicsItem *topItem = q;
|
||||
|
||||
if (usePopup && popup->widget()) {
|
||||
// popupapplet with widget()
|
||||
//FIXME:topItem = popup->d->proxy.data();
|
||||
messageOverlay->setGeometry(popup->widget()->contentsRect());
|
||||
} else if (usePopup && popup->graphicsWidget()) {
|
||||
// popupapplet with graphicsWidget()
|
||||
topItem = popup->graphicsWidget();
|
||||
QGraphicsWidget *w = dynamic_cast<QGraphicsWidget *>(topItem);
|
||||
messageOverlay->setGeometry(w ? w->contentsRect() : topItem->boundingRect());
|
||||
} else {
|
||||
// normal applet
|
||||
messageOverlay->setGeometry(q->contentsRect());
|
||||
}
|
||||
|
||||
// raise the overlay above all the other children!
|
||||
int zValue = 100;
|
||||
foreach (QGraphicsItem *child, topItem->children()) {
|
||||
if (child->zValue() > zValue) {
|
||||
zValue = child->zValue() + 1;
|
||||
}
|
||||
}
|
||||
messageOverlay->setZValue(zValue);
|
||||
}
|
||||
|
||||
void GraphicsViewAppletPrivate::destroyMessageOverlay()
|
||||
{
|
||||
if (messageDialog) {
|
||||
messageDialog.data()->animatedHide(Plasma::locationToInverseDirection(q->location()));
|
||||
//messageDialog.data()->deleteLater();
|
||||
messageDialog.clear();
|
||||
}
|
||||
|
||||
if (!messageOverlay) {
|
||||
return;
|
||||
}
|
||||
|
||||
messageOverlay->destroy();
|
||||
messageOverlay = 0;
|
||||
|
||||
if (messageOverlayProxy) {
|
||||
messageOverlayProxy->setWidget(0);
|
||||
delete messageOverlayProxy;
|
||||
messageOverlayProxy = 0;
|
||||
}
|
||||
|
||||
MessageButton buttonCode = ButtonNo;
|
||||
//find out if we're disappearing because of a button press
|
||||
PushButton *button = 0;
|
||||
//FIXME: PushButton *button = qobject_cast<PushButton *>(q->sender());
|
||||
if (button) {
|
||||
if (button == messageOkButton.data()) {
|
||||
buttonCode = ButtonOk;
|
||||
}
|
||||
|
||||
if (button == messageYesButton.data()) {
|
||||
buttonCode = ButtonYes;
|
||||
}
|
||||
|
||||
if (button == messageNoButton.data()) {
|
||||
buttonCode = ButtonNo;
|
||||
}
|
||||
|
||||
if (button == messageCancelButton.data()) {
|
||||
buttonCode = ButtonCancel;
|
||||
}
|
||||
|
||||
//FIXME: emit q->messageButtonPressed(buttonCode);
|
||||
} else if (/* FIXME: q->sender() == messageOverlay */ false) {
|
||||
//FIXME: emit q->messageButtonPressed(ButtonCancel);
|
||||
}
|
||||
}
|
||||
|
||||
void GraphicsViewAppletPrivate::setBusy(bool busy)
|
||||
{
|
||||
if (busy) {
|
||||
if (!busyWidget && !busyWidgetTimer.isActive()) {
|
||||
busyWidgetTimer.start(500, this);
|
||||
}
|
||||
} else {
|
||||
busyWidgetTimer.stop();
|
||||
if (busyWidget) {
|
||||
busyWidget = 0;
|
||||
destroyMessageOverlay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool GraphicsViewAppletPrivate::isBusy() const
|
||||
{
|
||||
return busyWidgetTimer.isActive() || (busyWidget && busyWidget->isVisible());
|
||||
}
|
||||
|
||||
void GraphicsViewAppletPrivate::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
if (transient) {
|
||||
busyWidgetTimer.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->timerId() == busyWidgetTimer.timerId()) {
|
||||
if (!busyWidget) {
|
||||
createMessageOverlay(false);
|
||||
messageOverlay->opacity = 0;
|
||||
|
||||
QGraphicsLinearLayout *mainLayout = new QGraphicsLinearLayout(messageOverlay);
|
||||
busyWidget = new Plasma::BusyWidget(messageOverlay);
|
||||
busyWidget->setAcceptHoverEvents(false);
|
||||
busyWidget->setAcceptedMouseButtons(Qt::NoButton);
|
||||
messageOverlay->setAcceptHoverEvents(false);
|
||||
messageOverlay->setAcceptedMouseButtons(Qt::NoButton);
|
||||
|
||||
mainLayout->addStretch();
|
||||
mainLayout->addItem(busyWidget);
|
||||
mainLayout->addStretch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AppletOverlayWidget::AppletOverlayWidget(QGraphicsWidget *parent)
|
||||
: QGraphicsWidget(parent),
|
||||
opacity(0.4)
|
||||
{
|
||||
resize(parent->size());
|
||||
}
|
||||
|
||||
void AppletOverlayWidget::destroy()
|
||||
{
|
||||
/*FIXME: a transitional animation would be nice here .. we used to do this:
|
||||
Animation *anim = Plasma::Animator::create(Plasma::Animator::DisappearAnimation);
|
||||
if (anim) {
|
||||
connect(anim, SIGNAL(finished()), this, SLOT(overlayAnimationComplete()));
|
||||
anim->setTargetWidget(this);
|
||||
anim->start();
|
||||
} else {
|
||||
overlayAnimationComplete();
|
||||
}
|
||||
*/
|
||||
if (scene()) {
|
||||
scene()->removeItem(this);
|
||||
}
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
void AppletOverlayWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
}
|
||||
|
||||
void AppletOverlayWidget::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
|
||||
if (qFuzzyCompare(1, 1+opacity)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QColor wash = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor);
|
||||
wash.setAlphaF(opacity);
|
||||
|
||||
Applet *applet = qobject_cast<Applet *>(parentWidget());
|
||||
|
||||
|
||||
QPainterPath backgroundShape;
|
||||
if (!applet || applet->backgroundHints() == StandardBackground) {
|
||||
//FIXME: a resize here is nasty, but perhaps still better than an eventfilter just for that..
|
||||
if (parentWidget()->contentsRect().size() != size()) {
|
||||
resize(parentWidget()->contentsRect().size());
|
||||
}
|
||||
backgroundShape = PaintUtils::roundedRectangle(contentsRect(), 5);
|
||||
} else {
|
||||
backgroundShape = shape();
|
||||
}
|
||||
|
||||
painter->setRenderHints(QPainter::Antialiasing);
|
||||
painter->fillPath(backgroundShape, wash);
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "graphicsviewappletprivate_p.h"
|
||||
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 by Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_GRAPHICSVIEWAPPLETPRIVATE_H
|
||||
#define PLASMA_GRAPHICSVIEWAPPLETPRIVATE_H
|
||||
|
||||
#include "private/applet_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AppletOverlayWidget : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AppletOverlayWidget(QGraphicsWidget *parent);
|
||||
void destroy();
|
||||
|
||||
qreal opacity;
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
};
|
||||
|
||||
class GraphicsViewAppletPrivate : public QObject, public AppletPrivate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GraphicsViewAppletPrivate(KService::Ptr service, const KPluginInfo *info, int uniqueID, Applet *applet);
|
||||
void cleanUpAndDelete();
|
||||
void showConfigurationRequiredMessage(bool show, const QString &reason);
|
||||
void showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons);
|
||||
void positionMessageOverlay();
|
||||
void setBusy(bool busy);
|
||||
bool isBusy() const;
|
||||
void updateFailedToLaunch(const QString &reason);
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
private:
|
||||
void createMessageOverlay(bool usePopup = true);
|
||||
|
||||
private Q_SLOTS:
|
||||
void destroyMessageOverlay();
|
||||
|
||||
private:
|
||||
// overlays and messages
|
||||
QWeakPointer<Plasma::Dialog> messageDialog;
|
||||
AppletOverlayWidget *messageOverlay;
|
||||
QGraphicsProxyWidget *messageOverlayProxy;
|
||||
Plasma::BusyWidget *busyWidget;
|
||||
QWeakPointer<Plasma::PushButton> messageOkButton;
|
||||
QWeakPointer<Plasma::PushButton> messageYesButton;
|
||||
QWeakPointer<Plasma::PushButton> messageNoButton;
|
||||
QWeakPointer<Plasma::PushButton> messageCancelButton;
|
||||
QWeakPointer<QAction> messageCloseAction;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
||||
|
@ -1,484 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "kineticscroll_p.h"
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/qmetatype.h>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QGraphicsSceneWheelEvent>
|
||||
#include <QTime>
|
||||
#include <QGraphicsWidget>
|
||||
#include <QPoint>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QCursor>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
/* TODO:
|
||||
* - clean up the code(remove duplicated code, constify)
|
||||
* - port to Plasma::Animator
|
||||
*/
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class KineticScrollingPrivate
|
||||
{
|
||||
public:
|
||||
enum Direction {
|
||||
None,
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
};
|
||||
|
||||
enum Gesture {
|
||||
GestureNone = 0,
|
||||
GestureUndefined,
|
||||
GestureScroll,
|
||||
GestureZoom
|
||||
};
|
||||
|
||||
KineticScrollingPrivate()
|
||||
: overshoot(20),
|
||||
hasOvershoot(true),
|
||||
parent(0),
|
||||
forwardingEvent(false),
|
||||
multitouchGesture(GestureNone)
|
||||
{
|
||||
}
|
||||
|
||||
void count()
|
||||
{
|
||||
t = QTime::currentTime();
|
||||
}
|
||||
|
||||
void syncViewportRect()
|
||||
{
|
||||
contentsSize = parent->property("contentsSize").toSizeF();
|
||||
viewportGeometry = parent->property("viewportGeometry").toRectF();
|
||||
}
|
||||
|
||||
bool canScroll(Direction direction, bool hasOvershoot = false) const
|
||||
{
|
||||
QPointF scrollPosition = -parent->property("scrollPosition").value<QPointF>();
|
||||
int offset = (hasOvershoot?overshoot*2:0);
|
||||
|
||||
switch (direction) {
|
||||
case Up:
|
||||
return (scrollPosition.y() < offset);
|
||||
case Down:
|
||||
return (scrollPosition.y() + contentsSize.height() + offset >= viewportGeometry.bottom());
|
||||
case Left:
|
||||
return (scrollPosition.x() < offset);
|
||||
case Right:
|
||||
return (scrollPosition.x() + contentsSize.width() + offset >= viewportGeometry.right());
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QPointF kinMovement;
|
||||
|
||||
enum BounceStatus {
|
||||
Running,
|
||||
Finished
|
||||
};
|
||||
|
||||
BounceStatus bounceStatus;
|
||||
|
||||
QPropertyAnimation *scrollAnimation;
|
||||
|
||||
int overshoot;
|
||||
QPointF cposition;
|
||||
bool hasOvershoot;
|
||||
QGraphicsWidget *parent;
|
||||
QRectF viewportGeometry;
|
||||
QSizeF contentsSize;
|
||||
QPointF maximum, minimum;
|
||||
bool forwardingEvent;
|
||||
Gesture multitouchGesture;
|
||||
|
||||
unsigned int timeDelta;
|
||||
QTime t;
|
||||
};
|
||||
|
||||
|
||||
KineticScrolling::KineticScrolling(QGraphicsWidget *parent)
|
||||
: d(new KineticScrollingPrivate)
|
||||
{
|
||||
setWidget(parent);
|
||||
}
|
||||
|
||||
KineticScrolling::~KineticScrolling()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void KineticScrolling::duration( )
|
||||
{
|
||||
d->timeDelta = d->t.msecsTo(QTime::currentTime());
|
||||
}
|
||||
|
||||
void KineticScrolling::overshoot()
|
||||
{
|
||||
QPointF scrollPosition = -d->parent->property("scrollPosition").value<QPointF>();
|
||||
|
||||
if (!d->canScroll(KineticScrollingPrivate::Down) &&
|
||||
!d->canScroll(KineticScrollingPrivate::Up)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->bounceStatus != KineticScrollingPrivate::Running) {
|
||||
if ((d->cposition.y() > 0 ) || (d->cposition.y() <= d->minimum.y() + d->overshoot)) {
|
||||
QPointF finalPosition;
|
||||
d->scrollAnimation->setEasingCurve( QEasingCurve::OutBounce );
|
||||
|
||||
if (d->cposition.y() > 0) {
|
||||
finalPosition = QPointF(scrollPosition.x(), 0);
|
||||
} else {
|
||||
finalPosition = QPointF(d->cposition.x(),
|
||||
-d->contentsSize.height( ) + d->parent->size().height());
|
||||
}
|
||||
|
||||
resetAnimation(-finalPosition, 900);
|
||||
d->bounceStatus = KineticScrollingPrivate::Running;
|
||||
}
|
||||
} else {
|
||||
d->bounceStatus = KineticScrollingPrivate::Finished;
|
||||
d->scrollAnimation->setEasingCurve(QEasingCurve::OutCirc);
|
||||
}
|
||||
}
|
||||
|
||||
void KineticScrolling::setScrollValue(QPointF value)
|
||||
{
|
||||
const QPointF pos = thresholdPosition(value);
|
||||
QPointF posf(-pos);
|
||||
d->parent->setProperty("scrollPosition", posf);
|
||||
|
||||
if ((pos.y() == d->overshoot) || (pos.y() == d->minimum.y())) {
|
||||
overshoot();
|
||||
}
|
||||
}
|
||||
|
||||
QPointF KineticScrolling::thresholdPosition(QPointF value) const
|
||||
{
|
||||
d->minimum.setX(-d->contentsSize.width() + d->viewportGeometry.width());
|
||||
d->minimum.setY(-d->contentsSize.height() + d->viewportGeometry.height()
|
||||
-d->overshoot);
|
||||
|
||||
d->minimum.setY(qMin((qreal)d->overshoot, d->minimum.y()));
|
||||
d->maximum = value;
|
||||
|
||||
if(d->minimum.x() >= 0) {
|
||||
d->cposition.setX(value.x());
|
||||
} else {
|
||||
d->cposition.setX(qBound(d->minimum.x(), d->maximum.x(), qreal(0)));
|
||||
}
|
||||
|
||||
if((-d->contentsSize.height() + d->viewportGeometry.height() - d->overshoot) >= 0) {
|
||||
d->cposition.setY(value.y());
|
||||
} else {
|
||||
d->cposition.setY(qBound(d->minimum.y(), d->maximum.y(), qreal(d->overshoot)));
|
||||
}
|
||||
|
||||
return d->cposition;
|
||||
}
|
||||
|
||||
void KineticScrolling::resetAnimation(QPointF finalPosition, int duration)
|
||||
{
|
||||
if (d->scrollAnimation->state() != QAbstractAnimation::Stopped) {
|
||||
d->scrollAnimation->stop();
|
||||
}
|
||||
|
||||
d->cposition = -finalPosition;
|
||||
QPointF tmpPosition = d->parent->property("scrollPosition").value<QPointF>();
|
||||
d->scrollAnimation->setStartValue(tmpPosition);
|
||||
|
||||
tmpPosition = finalPosition;
|
||||
|
||||
d->scrollAnimation->setEndValue(tmpPosition);
|
||||
d->scrollAnimation->setDuration(duration);
|
||||
d->scrollAnimation->start();
|
||||
|
||||
}
|
||||
|
||||
void KineticScrolling::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
if (d->scrollAnimation->state() != QAbstractAnimation::Stopped) {
|
||||
d->scrollAnimation->stop();
|
||||
}
|
||||
|
||||
d->syncViewportRect();
|
||||
d->cposition = -d->parent->property("scrollPosition").value<QPointF>();
|
||||
|
||||
d->count();
|
||||
d->kinMovement = QPointF(0,0);
|
||||
d->scrollAnimation->setEasingCurve(QEasingCurve::OutCirc);
|
||||
}
|
||||
|
||||
void KineticScrolling::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QPointF movement = event->lastPos().toPoint() - event->pos().toPoint();
|
||||
const QPointF scrollPosition = -d->parent->property("scrollPosition").value<QPointF>();
|
||||
|
||||
if (!movement.isNull()) {
|
||||
if ((d->contentsSize.width() < d->viewportGeometry.width()) &&
|
||||
(d->contentsSize.height() < d->viewportGeometry.height())) {
|
||||
d->kinMovement = QPointF(0, 0);
|
||||
movement = QPointF(0, 0);
|
||||
} else if (d->contentsSize.height() < d->viewportGeometry.height()) {
|
||||
d->kinMovement += QPointF(movement.x(), 0);
|
||||
movement.setY(0);
|
||||
} else if (d->contentsSize.width() < d->viewportGeometry.width()) {
|
||||
d->kinMovement = QPointF(0, movement.y());
|
||||
movement.setX(0);
|
||||
} else {
|
||||
d->kinMovement += movement;
|
||||
}
|
||||
setScrollValue(scrollPosition - movement);
|
||||
}
|
||||
}
|
||||
|
||||
void KineticScrolling::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
if (d->scrollAnimation->state() != QAbstractAnimation::Running) {
|
||||
duration();
|
||||
|
||||
if (d->kinMovement != QPointF(0, 0)) {
|
||||
const QPointF scrollPosition = -d->parent->property("scrollPosition").toPointF();
|
||||
d->kinMovement = QPointF(d->kinMovement.x()*3, d->kinMovement.y()*3);
|
||||
const QPointF finalPos = thresholdPosition(scrollPosition - d->kinMovement);
|
||||
resetAnimation( -finalPos, d->timeDelta*8 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KineticScrolling::wheelReleaseEvent(QGraphicsSceneWheelEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
d->syncViewportRect();
|
||||
d->kinMovement = QPointF(0,0);
|
||||
|
||||
if((event->orientation() == Qt::Vertical) &&
|
||||
(((event->delta() < 0) && d->canScroll(KineticScrollingPrivate::Down)) ||
|
||||
((event->delta() > 0) && d->canScroll(KineticScrollingPrivate::Up)))) {
|
||||
d->kinMovement.setY(d->kinMovement.y() - event->delta());
|
||||
} else if ((event->orientation() == Qt::Vertical) ||
|
||||
(!d->canScroll(KineticScrollingPrivate::Down) &&
|
||||
!d->canScroll(KineticScrollingPrivate::Up))) {
|
||||
if (((event->delta() < 0) &&
|
||||
d->canScroll(KineticScrollingPrivate::Right)) ||
|
||||
(event->delta() > 0 && d->canScroll(KineticScrollingPrivate::Left))) {
|
||||
d->kinMovement.setX(d->kinMovement.x() - event->delta());
|
||||
} else {
|
||||
event->ignore( );
|
||||
}
|
||||
} else {
|
||||
event->ignore( );
|
||||
return;
|
||||
}
|
||||
|
||||
const QPointF scrollPosition = -d->parent->property("scrollPosition").value<QPointF>();
|
||||
const QPointF pos = scrollPosition - d->kinMovement*2;
|
||||
const QPointF finalPos = thresholdPosition(pos);
|
||||
|
||||
d->scrollAnimation->setEasingCurve(QEasingCurve::OutCirc);
|
||||
resetAnimation(-finalPos, 900);
|
||||
}
|
||||
|
||||
void KineticScrolling::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
const int movement = 30;
|
||||
const int duration = 900;
|
||||
|
||||
QPointF scrollPosition = -d->parent->property("scrollPosition").value<QPointF>();
|
||||
QPointF finalPos;
|
||||
switch (event->key()) {
|
||||
case Qt::Key_Left:
|
||||
scrollPosition.setX(scrollPosition.x() + movement);
|
||||
finalPos = thresholdPosition(scrollPosition);
|
||||
resetAnimation(-finalPos, duration);
|
||||
break;
|
||||
case Qt::Key_Right:
|
||||
scrollPosition.setX(scrollPosition.x() - movement);
|
||||
finalPos = thresholdPosition(scrollPosition);
|
||||
resetAnimation(-finalPos, duration);
|
||||
break;
|
||||
case Qt::Key_Up:
|
||||
scrollPosition.setY(scrollPosition.y() + movement);
|
||||
finalPos = thresholdPosition(scrollPosition);
|
||||
resetAnimation(-finalPos, duration);
|
||||
break;
|
||||
case Qt::Key_Down:
|
||||
scrollPosition.setY(scrollPosition.y() - movement);
|
||||
finalPos = thresholdPosition(scrollPosition);
|
||||
resetAnimation(-finalPos, duration);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void KineticScrolling::setWidget(QGraphicsWidget *parent)
|
||||
{
|
||||
if (d->parent) {
|
||||
d->parent->removeEventFilter(this);
|
||||
disconnect(d->scrollAnimation, SIGNAL(finished()), this, SLOT(overshoot()));
|
||||
disconnect(d->scrollAnimation,
|
||||
SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), this,
|
||||
SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
|
||||
delete d->scrollAnimation;
|
||||
}
|
||||
|
||||
setParent(parent);
|
||||
|
||||
d->parent = parent;
|
||||
|
||||
d->scrollAnimation = new QPropertyAnimation(parent, "scrollPosition", parent);
|
||||
connect(d->scrollAnimation, SIGNAL(finished()), this, SLOT(overshoot()));
|
||||
connect(d->scrollAnimation,
|
||||
SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)), this,
|
||||
SIGNAL(stateChanged(QAbstractAnimation::State,QAbstractAnimation::State)));
|
||||
d->scrollAnimation->setEasingCurve(QEasingCurve::OutCirc);
|
||||
|
||||
if (parent) {
|
||||
d->parent->installEventFilter(this);
|
||||
}
|
||||
/* TODO: add a new property in plasma::ScrollWidget 'hasOvershoot' */
|
||||
}
|
||||
|
||||
void KineticScrolling::stop()
|
||||
{
|
||||
d->scrollAnimation->stop();
|
||||
}
|
||||
|
||||
|
||||
bool KineticScrolling::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
Q_UNUSED(watched);
|
||||
Q_UNUSED(event);
|
||||
|
||||
if (d->forwardingEvent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool notBlocked = true;
|
||||
if (d->multitouchGesture == KineticScrollingPrivate::GestureNone &&
|
||||
d->parent && d->parent->scene()) {
|
||||
d->forwardingEvent = true;
|
||||
notBlocked = d->parent->scene()->sendEvent(d->parent, event);
|
||||
d->forwardingEvent = false;
|
||||
}
|
||||
|
||||
if (event->type() != QEvent::TouchBegin &&
|
||||
event->type() != QEvent::TouchUpdate &&
|
||||
event->type() != QEvent::TouchEnd &&
|
||||
(!notBlocked ||
|
||||
((event->type() != QEvent::GraphicsSceneMousePress && event->isAccepted()) &&
|
||||
(event->type() != QEvent::GraphicsSceneWheel && event->isAccepted())))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QGraphicsSceneMouseEvent *me = static_cast<QGraphicsSceneMouseEvent *>(event);
|
||||
QGraphicsSceneWheelEvent *we = static_cast<QGraphicsSceneWheelEvent *>(event);
|
||||
|
||||
switch (event->type()) {
|
||||
case QEvent::GraphicsSceneMousePress:
|
||||
mousePressEvent(me);
|
||||
break;
|
||||
case QEvent::GraphicsSceneMouseRelease:
|
||||
mouseReleaseEvent(me);
|
||||
break;
|
||||
case QEvent::GraphicsSceneMouseMove:
|
||||
mouseMoveEvent(me);
|
||||
break;
|
||||
case QEvent::TouchBegin:
|
||||
mousePressEvent(0);
|
||||
break;
|
||||
case QEvent::TouchUpdate: {
|
||||
QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
|
||||
if (touchPoints.count() == 2) {
|
||||
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
|
||||
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
|
||||
const QLineF line0(touchPoint0.lastPos(), touchPoint1.lastPos());
|
||||
const QLineF line1(touchPoint0.pos(), touchPoint1.pos());
|
||||
const QLineF startLine(touchPoint0.startPos(), touchPoint1.startPos());
|
||||
const QPointF point = line1.pointAt(0.5);
|
||||
const QPointF lastPoint = line0.pointAt(0.5);
|
||||
|
||||
if (d->multitouchGesture == KineticScrollingPrivate::GestureNone) {
|
||||
d->multitouchGesture = KineticScrollingPrivate::GestureUndefined;
|
||||
}
|
||||
if (d->multitouchGesture == KineticScrollingPrivate::GestureUndefined) {
|
||||
const int zoomDistance = qAbs(line1.length() - startLine.length());
|
||||
const int dragDistance = (startLine.pointAt(0.5) - point).manhattanLength();
|
||||
|
||||
if (zoomDistance - dragDistance > 30) {
|
||||
d->multitouchGesture = KineticScrollingPrivate::GestureZoom;
|
||||
} else if (dragDistance - zoomDistance > 30) {
|
||||
d->multitouchGesture = KineticScrollingPrivate::GestureScroll;
|
||||
}
|
||||
}
|
||||
|
||||
if (d->multitouchGesture == KineticScrollingPrivate::GestureScroll) {
|
||||
QGraphicsSceneMouseEvent fakeEvent;
|
||||
fakeEvent.setPos(point);
|
||||
fakeEvent.setLastPos(lastPoint);
|
||||
mouseMoveEvent(&fakeEvent);
|
||||
} else if (d->multitouchGesture == KineticScrollingPrivate::GestureZoom) {
|
||||
qreal scaleFactor = 1;
|
||||
if (line0.length() > 0) {
|
||||
scaleFactor = line1.length() / line0.length();
|
||||
}
|
||||
|
||||
qreal zoom = d->parent->property("zoomFactor").toReal();
|
||||
d->parent->setProperty("zoomFactor", zoom * scaleFactor);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QEvent::TouchEnd:
|
||||
mouseReleaseEvent(0);
|
||||
d->multitouchGesture = KineticScrollingPrivate::GestureNone;
|
||||
break;
|
||||
|
||||
case QEvent::GraphicsSceneWheel:
|
||||
wheelReleaseEvent(we);
|
||||
break;
|
||||
case QEvent::KeyPress: {
|
||||
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
||||
keyPressEvent(ke);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
||||
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_KINETICSCROLLING_H
|
||||
#define PLASMA_KINETICSCROLLING_H
|
||||
|
||||
class QGraphicsSceneMouseEvent;
|
||||
class QGraphicsWidget;
|
||||
class QGraphicsSceneWheelEvent;
|
||||
class QKeyEvent;
|
||||
#include <QObject>
|
||||
#include <QPointF>
|
||||
#include <QtCore/QAbstractAnimation>
|
||||
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class KineticScrollingPrivate;
|
||||
|
||||
class KineticScrolling: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KineticScrolling(QGraphicsWidget *parent);
|
||||
~KineticScrolling();
|
||||
void setWidget(QGraphicsWidget *parent);
|
||||
void stop();
|
||||
|
||||
Q_SIGNALS:
|
||||
void stateChanged(QAbstractAnimation::State newState,
|
||||
QAbstractAnimation::State oldState);
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void wheelReleaseEvent(QGraphicsSceneWheelEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
private:
|
||||
KineticScrollingPrivate *d;
|
||||
void resetAnimation(QPointF finalPosition, int duration);
|
||||
void setScrollValue(QPointF value);
|
||||
QPointF thresholdPosition(QPointF value) const;
|
||||
void duration();
|
||||
|
||||
private Q_SLOTS:
|
||||
void overshoot();
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,634 +0,0 @@
|
||||
/*
|
||||
Copyright 2007 Robert Knight <robertknight@gmail.com>
|
||||
Copyright 2008 Marco Martin <notmart@gmail.com>
|
||||
|
||||
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 "nativetabbar_p.h"
|
||||
|
||||
// Qt
|
||||
#include <QIcon>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QApplication>
|
||||
#include <QStyleOption>
|
||||
#include <QToolButton>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QWeakPointer>
|
||||
|
||||
#include <QGradient>
|
||||
#include <QLinearGradient>
|
||||
|
||||
// KDE
|
||||
#include <kdebug.h>
|
||||
#include <kiconeffect.h>
|
||||
#include <kiconloader.h>
|
||||
|
||||
#include "plasma/plasma.h"
|
||||
#include "plasma/theme.h"
|
||||
#include "plasma/animator.h"
|
||||
#include "plasma/framesvg.h"
|
||||
#include "plasma/paintutils.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
static const int buttonHMargin = 4;
|
||||
static const int buttonVMargin = 3;
|
||||
static const int iconSpacing = 4;
|
||||
|
||||
class NativeTabBarPrivate
|
||||
{
|
||||
public:
|
||||
NativeTabBarPrivate(NativeTabBar *parent)
|
||||
: q(parent),
|
||||
shape(NativeTabBar::RoundedNorth),
|
||||
backgroundSvg(0),
|
||||
buttonSvg(0),
|
||||
m_highlightSvg(0)
|
||||
{
|
||||
backgroundSvg = new FrameSvg(q);
|
||||
backgroundSvg->setImagePath("widgets/frame");
|
||||
backgroundSvg->setElementPrefix("sunken");
|
||||
|
||||
buttonSvg = new FrameSvg(q);
|
||||
buttonSvg->setImagePath("widgets/button");
|
||||
buttonSvg->setElementPrefix("normal");
|
||||
|
||||
syncBorders();
|
||||
|
||||
lastIndex[0] = -1;
|
||||
lastIndex[1] = -1;
|
||||
}
|
||||
|
||||
~NativeTabBarPrivate()
|
||||
{
|
||||
delete backgroundSvg;
|
||||
delete buttonSvg;
|
||||
}
|
||||
|
||||
void syncBorders();
|
||||
void storeLastIndex();
|
||||
|
||||
FrameSvg *highlightSvg()
|
||||
{
|
||||
if (!m_highlightSvg) {
|
||||
m_highlightSvg = new FrameSvg(q);
|
||||
m_highlightSvg->setImagePath("widgets/button");
|
||||
m_highlightSvg->setElementPrefix("pressed");
|
||||
}
|
||||
|
||||
return m_highlightSvg;
|
||||
}
|
||||
|
||||
NativeTabBar *q;
|
||||
QTabBar::Shape shape; //used to keep track of shape() changes
|
||||
FrameSvg *backgroundSvg;
|
||||
qreal left, top, right, bottom;
|
||||
FrameSvg *buttonSvg;
|
||||
qreal buttonLeft, buttonTop, buttonRight, buttonBottom;
|
||||
|
||||
QList<bool> highlightedTabs;
|
||||
|
||||
QWeakPointer<QPropertyAnimation> anim;
|
||||
|
||||
QRect currentAnimRect;
|
||||
QRect startAnimRect;
|
||||
QPoint mousePressOffset;
|
||||
int lastIndex[2];
|
||||
qreal animProgress;
|
||||
|
||||
FrameSvg *m_highlightSvg;
|
||||
};
|
||||
|
||||
void NativeTabBarPrivate::syncBorders()
|
||||
{
|
||||
backgroundSvg->getMargins(left, top, right, bottom);
|
||||
buttonSvg->getMargins(buttonLeft, buttonTop, buttonRight, buttonBottom);
|
||||
}
|
||||
|
||||
void NativeTabBarPrivate::storeLastIndex()
|
||||
{
|
||||
// if first run, or invalid previous index
|
||||
if (lastIndex[1] < 0 || lastIndex[1] >= q->count()) {
|
||||
lastIndex[0] = q->currentIndex();
|
||||
} else {
|
||||
lastIndex[0] = lastIndex[1];
|
||||
}
|
||||
|
||||
lastIndex[1] = q->currentIndex();
|
||||
}
|
||||
|
||||
NativeTabBar::NativeTabBar(QWidget *parent)
|
||||
: KTabBar(parent),
|
||||
d(new NativeTabBarPrivate(this))
|
||||
{
|
||||
connect(this, SIGNAL(currentChanged(int)), this, SLOT(startAnimation()));
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
}
|
||||
|
||||
NativeTabBar::~NativeTabBar()
|
||||
{
|
||||
d->anim.clear();
|
||||
delete d;
|
||||
}
|
||||
|
||||
QRect NativeTabBar::tabRect(int index) const
|
||||
{
|
||||
QRect rect = KTabBar::tabRect(index).translated(d->left, d->top);
|
||||
|
||||
if (isVertical()) {
|
||||
rect.setWidth(width() - d->left - d->right);
|
||||
|
||||
if (index == count() - 1) {
|
||||
rect.adjust(0, 0, 0, -d->bottom);
|
||||
}
|
||||
} else {
|
||||
rect.setHeight(height() - d->top- d->bottom);
|
||||
|
||||
if (index == count() - 1) {
|
||||
rect.adjust(0, 0, -d->right, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
int NativeTabBar::lastIndex() const
|
||||
{
|
||||
return d->lastIndex[0];
|
||||
}
|
||||
|
||||
QSize NativeTabBar::tabSizeHint(int index) const
|
||||
{
|
||||
//return KTabBar::tabSizeHint(index);
|
||||
QSize hint = tabSize(index);
|
||||
int minwidth = 0;
|
||||
int minheight = 0;
|
||||
int maxwidth = 0;
|
||||
|
||||
Shape s = shape();
|
||||
switch (s) {
|
||||
case RoundedSouth:
|
||||
case TriangularSouth:
|
||||
case RoundedNorth:
|
||||
case TriangularNorth:
|
||||
if (count() > 0) {
|
||||
for (int i = count() - 1; i >= 0; i--) {
|
||||
minwidth += tabSize(i).width();
|
||||
}
|
||||
|
||||
if (minwidth < width() - d->left - d->right) {
|
||||
hint.rwidth() += (width() - d->left - d->right - minwidth) / count();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RoundedWest:
|
||||
case TriangularWest:
|
||||
case RoundedEast:
|
||||
case TriangularEast:
|
||||
if (count() > 0) {
|
||||
for (int i = count() - 1; i >= 0; i--) {
|
||||
minheight += tabSize(i).height();
|
||||
if (tabSize(i).width() > maxwidth) {
|
||||
maxwidth = tabSize(i).width();
|
||||
}
|
||||
}
|
||||
|
||||
if (minheight < height()) {
|
||||
hint.rheight() += (height() - minheight) / count();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return hint;
|
||||
}
|
||||
|
||||
|
||||
QSize NativeTabBar::sizeHint() const
|
||||
{
|
||||
return KTabBar::sizeHint();
|
||||
}
|
||||
|
||||
void NativeTabBar::setTabHighlighted(int index, bool highlight)
|
||||
{
|
||||
if (index < 0 || index >= count()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (highlight != d->highlightedTabs[index]) {
|
||||
d->highlightedTabs[index] = highlight;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
bool NativeTabBar::isTabHighlighted(int index) const
|
||||
{
|
||||
if (index < 0 || index >= count() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return d->highlightedTabs[index];
|
||||
}
|
||||
void NativeTabBar::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
if (!styleSheet().isNull()) {
|
||||
KTabBar::paintEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
QPainter painter(this);
|
||||
//int numTabs = count();
|
||||
//bool ltr = painter.layoutDirection() == Qt::LeftToRight; // Not yet used
|
||||
|
||||
if (drawBase()) {
|
||||
d->backgroundSvg->paintFrame(&painter);
|
||||
}
|
||||
|
||||
// Drawing Tabborders
|
||||
QRect movingRect;
|
||||
|
||||
if (d->currentAnimRect.isNull() || !d->anim || d->anim.data()->state() != QAbstractAnimation::Running) {
|
||||
movingRect = tabRect(currentIndex());
|
||||
} else {
|
||||
movingRect = d->currentAnimRect;
|
||||
}
|
||||
|
||||
//resizing here because in resizeevent the first time is invalid (still no tabs)
|
||||
d->buttonSvg->resizeFrame(movingRect.size());
|
||||
d->buttonSvg->paintFrame(&painter, movingRect.topLeft());
|
||||
|
||||
QFontMetrics metrics(painter.font());
|
||||
|
||||
|
||||
QRect scrollButtonsRect;
|
||||
foreach (QObject *child, children()) {
|
||||
QToolButton *childWidget = qobject_cast<QToolButton *>(child);
|
||||
if (childWidget) {
|
||||
if (!childWidget->isVisible()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (scrollButtonsRect.isValid()) {
|
||||
scrollButtonsRect = scrollButtonsRect.united(childWidget->geometry());
|
||||
} else {
|
||||
scrollButtonsRect = childWidget->geometry();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QColor buttonText = Plasma::Theme::defaultTheme()->color(Theme::ButtonTextColor);
|
||||
const QColor textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor);
|
||||
const QColor highlightColor = Plasma::Theme::defaultTheme()->color(Theme::HighlightColor);
|
||||
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
const bool isHighlighted = d->highlightedTabs[i];
|
||||
QRect rect = tabRect(i).adjusted(d->buttonLeft + buttonHMargin, d->buttonTop + buttonVMargin,
|
||||
-(d->buttonRight + buttonHMargin), -(d->buttonBottom + buttonVMargin));
|
||||
|
||||
// draw tab icon
|
||||
QRect iconRect = QRect(rect.x(), rect.y(), iconSize().width(), iconSize().height());
|
||||
iconRect.moveCenter(QPoint(iconRect.center().x(), rect.center().y()));
|
||||
|
||||
if (!tabIcon(i).isNull()) {
|
||||
if (isHighlighted) {
|
||||
QRect iconRectAdjusted = iconRect.adjusted(-buttonHMargin, -buttonVMargin, buttonHMargin, buttonVMargin);
|
||||
d->highlightSvg()->resizeFrame(iconRectAdjusted.size());
|
||||
d->highlightSvg()->paintFrame(&painter, iconRectAdjusted.topLeft());
|
||||
QPixmap iconPix = tabIcon(i).pixmap(iconRect.size());
|
||||
KIconEffect *effect = KIconLoader::global()->iconEffect();
|
||||
iconPix = effect->apply(iconPix, KIconLoader::Panel, KIconLoader::ActiveState);
|
||||
painter.drawPixmap(iconRect.topLeft(), iconPix);
|
||||
} else {
|
||||
tabIcon(i).paint(&painter, iconRect);
|
||||
painter.setOpacity(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
// draw tab text
|
||||
if (i == currentIndex() && d->animProgress == 1) {
|
||||
painter.setPen(isHighlighted ? highlightColor : buttonText);
|
||||
} else {
|
||||
QColor color = (isHighlighted ? highlightColor : textColor);
|
||||
if (!isTabEnabled(i)) {
|
||||
color.setAlpha(140);
|
||||
}
|
||||
|
||||
painter.setPen(color);
|
||||
}
|
||||
QRect textRect = rect;
|
||||
|
||||
if (!tabIcon(i).isNull()) {
|
||||
textRect.setLeft(iconRect.right() + iconSpacing);
|
||||
}
|
||||
|
||||
|
||||
painter.setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
|
||||
|
||||
int endTabSpace = contentsRect().right() - scrollButtonsRect.width();
|
||||
if (textRect.left() < endTabSpace) {
|
||||
if (textRect.left() < contentsRect().left() || textRect.right() > endTabSpace) {
|
||||
QPixmap buffer(textRect.size());
|
||||
buffer.fill(Qt::transparent);
|
||||
|
||||
QPainter buffPainter(&buffer);
|
||||
buffPainter.drawText(buffer.rect(), Qt::AlignCenter | Qt::TextHideMnemonic, tabText(i));
|
||||
buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
QLinearGradient gradient(buffer.rect().topLeft(), buffer.rect().topRight());
|
||||
|
||||
if (textRect.left() < contentsRect().left()) {
|
||||
gradient.setColorAt(0, Qt::transparent);
|
||||
gradient.setColorAt(qBound(qreal(0), (-(qreal)textRect.left())/(qreal)textRect.width(), qreal(1)), Qt::transparent);
|
||||
gradient.setColorAt(1, Qt::black);
|
||||
} else {
|
||||
gradient.setColorAt(0, Qt::black);
|
||||
gradient.setColorAt(qBound(qreal(0), 1 - (qreal)(textRect.right() - endTabSpace)/(qreal)textRect.width(), qreal(1)), Qt::transparent);
|
||||
gradient.setColorAt(1, Qt::transparent);
|
||||
}
|
||||
|
||||
buffPainter.setBrush(gradient);
|
||||
buffPainter.setPen(Qt::NoPen);
|
||||
buffPainter.drawRect(buffer.rect());
|
||||
buffPainter.end();
|
||||
|
||||
painter.drawPixmap(textRect, buffer, buffer.rect());
|
||||
} else {
|
||||
painter.drawText(textRect, Qt::AlignCenter | Qt::TextHideMnemonic, tabText(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollButtonsRect.isValid()) {
|
||||
scrollButtonsRect.adjust(2, 4, -2, -4);
|
||||
painter.save();
|
||||
|
||||
QColor background(Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor));
|
||||
background.setAlphaF(0.75);
|
||||
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.fillPath(PaintUtils::roundedRectangle(scrollButtonsRect, 5), background);
|
||||
painter.restore();
|
||||
|
||||
QStyleOption so;
|
||||
so.initFrom(this);
|
||||
so.palette.setColor(QPalette::ButtonText,
|
||||
Plasma::Theme::defaultTheme()->color(Theme::TextColor));
|
||||
|
||||
so.rect = scrollButtonsRect.adjusted(0, 0, -scrollButtonsRect.width() / 2, 0);
|
||||
style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &so, &painter, this);
|
||||
|
||||
so.rect = scrollButtonsRect.adjusted(scrollButtonsRect.width() / 2, 0, 0, 0);
|
||||
style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &so, &painter, this);
|
||||
}
|
||||
}
|
||||
|
||||
void NativeTabBar::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
KTabBar::resizeEvent(event);
|
||||
d->currentAnimRect = tabRect(currentIndex());
|
||||
d->backgroundSvg->resizeFrame(size());
|
||||
d->syncBorders();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void NativeTabBar::tabInserted(int index)
|
||||
{
|
||||
d->highlightedTabs.insert(index, false);
|
||||
KTabBar::tabInserted(index);
|
||||
emit sizeHintChanged();
|
||||
|
||||
d->currentAnimRect = tabRect(currentIndex());
|
||||
d->backgroundSvg->resizeFrame(size());
|
||||
d->syncBorders();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void NativeTabBar::tabRemoved(int index)
|
||||
{
|
||||
d->highlightedTabs.removeAt(index);
|
||||
KTabBar::tabRemoved(index);
|
||||
emit sizeHintChanged();
|
||||
|
||||
d->currentAnimRect = tabRect(currentIndex());
|
||||
d->backgroundSvg->resizeFrame(size());
|
||||
d->syncBorders();
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void NativeTabBar::tabLayoutChange()
|
||||
{
|
||||
KTabBar::tabLayoutChange();
|
||||
|
||||
if (shape() != d->shape) {
|
||||
d->shape = shape();
|
||||
emit shapeChanged(d->shape);
|
||||
}
|
||||
}
|
||||
|
||||
void NativeTabBar::startAnimation()
|
||||
{
|
||||
d->storeLastIndex();
|
||||
|
||||
QPropertyAnimation *anim = d->anim.data();
|
||||
if (anim) {
|
||||
anim->stop();
|
||||
d->anim.clear();
|
||||
}
|
||||
|
||||
anim = new QPropertyAnimation(this, "onValueChanged", this);
|
||||
d->anim = anim;
|
||||
anim->setDuration(150);
|
||||
|
||||
QRect rect = tabRect(currentIndex());
|
||||
QRect lastRect = d->startAnimRect.isNull() ? tabRect(lastIndex())
|
||||
: d->startAnimRect;
|
||||
int x = isHorizontal() ? (int)(lastRect.x() - (lastRect.x() - rect.x())) : rect.x();
|
||||
int y = isHorizontal() ? rect.y() : (int)(lastRect.y() - (lastRect.y() - rect.y()));
|
||||
QSizeF sz = lastRect.size() - (lastRect.size() - rect.size());
|
||||
d->currentAnimRect = QRect(x, y, (int)(sz.width()), (int)(sz.height()));
|
||||
|
||||
anim->setStartValue(lastRect);
|
||||
anim->setEndValue(d->currentAnimRect);
|
||||
anim->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
|
||||
void NativeTabBar::setOnValueChanged(QRectF value)
|
||||
{
|
||||
if (value == d->anim.data()->endValue()) {
|
||||
d->animProgress = 1;
|
||||
animationFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
d->currentAnimRect = value.toRect();
|
||||
update();
|
||||
}
|
||||
|
||||
QRectF NativeTabBar::onValueChanged() const
|
||||
{
|
||||
return d->currentAnimRect;
|
||||
}
|
||||
|
||||
void NativeTabBar::animationFinished()
|
||||
{
|
||||
d->startAnimRect = QRect();
|
||||
d->currentAnimRect = QRect();
|
||||
update();
|
||||
}
|
||||
|
||||
bool NativeTabBar::isVertical() const
|
||||
{
|
||||
switch (shape()) {
|
||||
case RoundedWest:
|
||||
case RoundedEast:
|
||||
case TriangularWest:
|
||||
case TriangularEast:
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NativeTabBar::isHorizontal() const
|
||||
{
|
||||
return !isVertical();
|
||||
}
|
||||
|
||||
QSize NativeTabBar::tabSize(int index) const
|
||||
{
|
||||
QSize hint;
|
||||
const QFontMetrics metrics(QApplication::font());
|
||||
const QSize textSize = metrics.size(Qt::TextHideMnemonic, tabText(index));
|
||||
hint.rwidth() = textSize.width() + iconSpacing + iconSize().width() + buttonHMargin * 2;
|
||||
hint.rheight() = qMax(iconSize().height(), textSize.height()) + buttonVMargin * 2;
|
||||
hint.rwidth() += d->buttonLeft + d->buttonRight;
|
||||
hint.rheight() += d->buttonTop + d->buttonBottom;
|
||||
|
||||
if (isVertical()) {
|
||||
hint.rwidth() = qMax(hint.width(), int(minimumWidth() - d->left - d->right));
|
||||
} else {
|
||||
hint.rheight() = qMax(hint.height(), int(minimumHeight() - d->top - d->bottom));
|
||||
}
|
||||
|
||||
return hint;
|
||||
}
|
||||
|
||||
void NativeTabBar::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (d->currentAnimRect.isNull()) {
|
||||
QRect rect = tabRect(currentIndex());
|
||||
|
||||
if (rect.contains(event->pos())) {
|
||||
d->mousePressOffset = event->pos();
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
KTabBar::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void NativeTabBar::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (d->mousePressOffset != QPoint()) {
|
||||
d->currentAnimRect = tabRect(currentIndex());
|
||||
|
||||
if (isVertical()) {
|
||||
int pos = qBound(0, d->currentAnimRect.top() + (event->pos().y() - d->mousePressOffset.y()),
|
||||
height() - d->currentAnimRect.height());
|
||||
d->currentAnimRect.moveTop(pos);
|
||||
} else {
|
||||
int pos = qBound(0, d->currentAnimRect.left() + (event->pos().x() - d->mousePressOffset.x()),
|
||||
width() - d->currentAnimRect.width());
|
||||
d->currentAnimRect.moveLeft(pos);
|
||||
}
|
||||
update();
|
||||
} else {
|
||||
KTabBar::mouseMoveEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void NativeTabBar::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (d->mousePressOffset != QPoint()) {
|
||||
int index = -1;
|
||||
|
||||
if (isVertical()) {
|
||||
bool top = event->pos().y() - d->mousePressOffset.y() < 0;
|
||||
index = tabAt(QPoint(1, top ? d->currentAnimRect.top() : d->currentAnimRect.bottom()));
|
||||
} else {
|
||||
bool left = event->pos().x() - d->mousePressOffset.x() < 0;
|
||||
index = tabAt(QPoint(left ? d->currentAnimRect.left() : d->currentAnimRect.right(), 1));
|
||||
}
|
||||
|
||||
d->mousePressOffset = QPoint();
|
||||
|
||||
if (index != currentIndex() && isTabEnabled(index)) {
|
||||
d->startAnimRect = d->currentAnimRect;
|
||||
setCurrentIndex(index);
|
||||
} else {
|
||||
d->currentAnimRect = QRect();
|
||||
}
|
||||
|
||||
update();
|
||||
} else {
|
||||
KTabBar::mouseReleaseEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void NativeTabBar::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (underMouse()) {
|
||||
//Cycle tabs with the circular array tecnique
|
||||
if (event->delta() < 0) {
|
||||
int index = currentIndex();
|
||||
//search for an enabled tab
|
||||
for (int i = 0; i < count()-1; ++i) {
|
||||
index = (index + 1) % count();
|
||||
if (isTabEnabled(index)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentIndex(index);
|
||||
} else {
|
||||
int index = currentIndex();
|
||||
for (int i = 0; i < count()-1; ++i) {
|
||||
index = (count() + index -1) % count();
|
||||
if (isTabEnabled(index)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
} else {
|
||||
QTabBar::wheelEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "moc_nativetabbar_p.cpp"
|
||||
|
@ -1,98 +0,0 @@
|
||||
/*
|
||||
Copyright 2007 Robert Knight <robertknight@gmail.com>
|
||||
Copyright 2008 Marco Martin <notmart@gmail.com>
|
||||
|
||||
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 NATIVETABBAR_H
|
||||
#define NATIVETABBAR_H
|
||||
|
||||
#include <ktabbar.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class NativeTabBarPrivate;
|
||||
|
||||
class NativeTabBar : public KTabBar
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QRectF onValueChanged READ onValueChanged WRITE setOnValueChanged)
|
||||
|
||||
public:
|
||||
NativeTabBar(QWidget *parent = 0);
|
||||
~NativeTabBar();
|
||||
|
||||
QRect tabRect(int index) const;
|
||||
QSize tabSizeHint(int index) const;
|
||||
QSize sizeHint() const;
|
||||
|
||||
/**
|
||||
* Highlight the specified tab
|
||||
* @param index of the tab to highlight
|
||||
* @param highlight true if it should be highlighted, wrong if not
|
||||
* @since 4.7
|
||||
*/
|
||||
void setTabHighlighted(int index, bool highlight);
|
||||
|
||||
/**
|
||||
* @return if the tab at index is highlighted
|
||||
* @since 4.7
|
||||
*/
|
||||
bool isTabHighlighted(int index) const;
|
||||
|
||||
protected:
|
||||
int lastIndex() const;
|
||||
|
||||
// reimplemented from QTabBar
|
||||
virtual void paintEvent(QPaintEvent *event);
|
||||
virtual void resizeEvent(QResizeEvent *event);
|
||||
void tabInserted(int index);
|
||||
void tabRemoved(int index);
|
||||
void tabLayoutChange();
|
||||
|
||||
bool isHorizontal() const;
|
||||
bool isVertical() const;
|
||||
void wheelEvent(QWheelEvent *event);
|
||||
|
||||
void mousePressEvent(QMouseEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
protected slots:
|
||||
void animationFinished();
|
||||
void startAnimation();
|
||||
void setOnValueChanged(QRectF val);
|
||||
QRectF onValueChanged() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void sizeHintChanged();
|
||||
void shapeChanged(QTabBar::Shape shape);
|
||||
|
||||
private:
|
||||
QSize tabSize(int index) const;
|
||||
|
||||
NativeTabBarPrivate * const d;
|
||||
|
||||
friend class NativeTabBarPrivate;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void syncBorders())
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // TABBAR_H
|
@ -1,418 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
|
||||
* Copyright © 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "style_p.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionComplex>
|
||||
#include <QSpinBox>
|
||||
#include <QComboBox>
|
||||
#include <QApplication>
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
#include <plasma/framesvg.h>
|
||||
#include <plasma/theme.h>
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
class StylePrivate
|
||||
{
|
||||
public:
|
||||
StylePrivate(Style *style)
|
||||
: q(style),
|
||||
scrollbar(0),
|
||||
textBox(0)
|
||||
{
|
||||
}
|
||||
|
||||
~StylePrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void createScrollbar()
|
||||
{
|
||||
if (!scrollbar) {
|
||||
scrollbar = new Plasma::FrameSvg(q);
|
||||
scrollbar->setImagePath("widgets/scrollbar");
|
||||
scrollbar->setCacheAllRenderedFrames(true);
|
||||
}
|
||||
}
|
||||
|
||||
void createTextBox()
|
||||
{
|
||||
if (!textBox) {
|
||||
textBox = new Plasma::FrameSvg(q);
|
||||
textBox->setImagePath("widgets/lineedit");
|
||||
textBox->setElementPrefix("base");
|
||||
}
|
||||
}
|
||||
|
||||
Style *q;
|
||||
Plasma::FrameSvg *scrollbar;
|
||||
Plasma::FrameSvg *textBox;
|
||||
static Plasma::Style::Ptr s_sharedStyle;
|
||||
};
|
||||
|
||||
Style::Ptr StylePrivate::s_sharedStyle(0);
|
||||
|
||||
Style::Ptr Style::sharedStyle()
|
||||
{
|
||||
if (!StylePrivate::s_sharedStyle) {
|
||||
StylePrivate::s_sharedStyle = new Style();
|
||||
}
|
||||
|
||||
return StylePrivate::s_sharedStyle;
|
||||
}
|
||||
|
||||
void Style::doneWithSharedStyle()
|
||||
{
|
||||
if (StylePrivate::s_sharedStyle.isUnique()) {
|
||||
StylePrivate::s_sharedStyle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
Style::Style()
|
||||
: QCommonStyle(),
|
||||
d(new StylePrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
Style::~Style()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Style::drawComplexControl(ComplexControl control,
|
||||
const QStyleOptionComplex *option,
|
||||
QPainter *painter,
|
||||
const QWidget *widget) const
|
||||
{
|
||||
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
|
||||
qApp->style()->drawComplexControl(control, option, painter, widget);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (control) {
|
||||
case CC_ScrollBar: {
|
||||
d->createScrollbar();
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
const bool sunken = option->state & State_Sunken;
|
||||
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
|
||||
QString prefix;
|
||||
|
||||
if (option->state & State_MouseOver) {
|
||||
prefix= "mouseover-";
|
||||
}
|
||||
|
||||
QRect subLine;
|
||||
QRect addLine;
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
||||
subLine = d->scrollbar->elementRect(prefix + "arrow-left").toRect();
|
||||
addLine = d->scrollbar->elementRect(prefix + "arrow-right").toRect();
|
||||
} else {
|
||||
subLine = d->scrollbar->elementRect(prefix + "arrow-up").toRect();
|
||||
addLine = d->scrollbar->elementRect(prefix + "arrow-down").toRect();
|
||||
}
|
||||
|
||||
subLine.moveCenter(subControlRect(control, option, SC_ScrollBarSubLine, widget).center());
|
||||
addLine.moveCenter(subControlRect(control, option, SC_ScrollBarAddLine, widget).center());
|
||||
|
||||
QRect slider = subControlRect(control, option, SC_ScrollBarSlider, widget);
|
||||
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
||||
slider.adjust(0, 1, 0, -1);
|
||||
} else {
|
||||
slider.adjust(1, 0, -1, 0);
|
||||
}
|
||||
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal && d->scrollbar->hasElement("background-horizontal-center")) {
|
||||
d->scrollbar->setElementPrefix("background-horizontal");
|
||||
} else if (scrollOption && scrollOption->orientation == Qt::Vertical && d->scrollbar->hasElement("background-vertical-center")) {
|
||||
d->scrollbar->setElementPrefix("background-vertical");
|
||||
} else {
|
||||
d->scrollbar->setElementPrefix("background");
|
||||
}
|
||||
d->scrollbar->resizeFrame(option->rect.size());
|
||||
d->scrollbar->paintFrame(painter);
|
||||
|
||||
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSlider) {
|
||||
d->scrollbar->setElementPrefix("sunken-slider");
|
||||
} else {
|
||||
d->scrollbar->setElementPrefix(prefix + "slider");
|
||||
}
|
||||
|
||||
d->scrollbar->resizeFrame(slider.size());
|
||||
d->scrollbar->paintFrame(painter, slider.topLeft());
|
||||
|
||||
if (scrollOption && scrollOption->orientation == Qt::Horizontal) {
|
||||
if (sunken && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
|
||||
d->scrollbar->paint(painter, addLine, "sunken-arrow-right");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, addLine, prefix + "arrow-right");
|
||||
}
|
||||
|
||||
if (sunken && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
|
||||
d->scrollbar->paint(painter, subLine, "sunken-arrow-left");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, subLine, prefix + "arrow-left");
|
||||
}
|
||||
} else {
|
||||
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarAddLine) {
|
||||
d->scrollbar->paint(painter, addLine, "sunken-arrow-down");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, addLine, prefix + "arrow-down");
|
||||
}
|
||||
|
||||
if (sunken && scrollOption && scrollOption->activeSubControls & SC_ScrollBarSubLine) {
|
||||
d->scrollbar->paint(painter, subLine, "sunken-arrow-up");
|
||||
} else {
|
||||
d->scrollbar->paint(painter, subLine, prefix + "arrow-up");
|
||||
}
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
break;
|
||||
}
|
||||
case CC_SpinBox: {
|
||||
d->createTextBox();
|
||||
|
||||
d->textBox->resizeFrame(option->rect.size());
|
||||
d->textBox->paintFrame(painter);
|
||||
|
||||
const QStyleOptionSpinBox *spinOpt = qstyleoption_cast<const QStyleOptionSpinBox *>(option);
|
||||
bool upSunken = (spinOpt->activeSubControls & SC_SpinBoxUp) &&
|
||||
(spinOpt->state & (State_Sunken | State_On));
|
||||
bool downSunken = (spinOpt->activeSubControls & SC_SpinBoxDown) &&
|
||||
(spinOpt->state & (State_Sunken | State_On));
|
||||
|
||||
const QSpinBox *spin = qobject_cast<const QSpinBox *>(widget);
|
||||
PrimitiveElement pe;
|
||||
if (spin->buttonSymbols() == QSpinBox::PlusMinus) {
|
||||
pe = PE_IndicatorSpinPlus;
|
||||
} else {
|
||||
pe = PE_IndicatorArrowUp;
|
||||
}
|
||||
|
||||
QStyleOption upOpt;
|
||||
upOpt = *option;
|
||||
upOpt.rect = subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
|
||||
|
||||
if (upSunken) {
|
||||
upOpt.state = State_Sunken|State_Enabled;
|
||||
} else {
|
||||
upOpt.state = State_Enabled;
|
||||
}
|
||||
|
||||
qApp->style()->drawPrimitive(pe, &upOpt, painter, widget);
|
||||
|
||||
if (spin->buttonSymbols() == QSpinBox::PlusMinus) {
|
||||
pe = PE_IndicatorSpinMinus;
|
||||
} else {
|
||||
pe = PE_IndicatorArrowDown;
|
||||
}
|
||||
|
||||
QStyleOption downOpt;
|
||||
downOpt= *option;
|
||||
downOpt.rect = subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
|
||||
|
||||
if (downSunken) {
|
||||
downOpt.state = State_Sunken|State_Enabled;
|
||||
} else {
|
||||
downOpt.state = State_Enabled;
|
||||
}
|
||||
|
||||
qApp->style()->drawPrimitive(pe, &downOpt, painter, widget);
|
||||
break;
|
||||
}
|
||||
case CC_ComboBox: {
|
||||
const QComboBox *combo = qobject_cast<const QComboBox *>(widget);
|
||||
if (!combo->isEditable()) {
|
||||
qApp->style()->drawComplexControl(control, option, painter, widget);
|
||||
} else {
|
||||
d->createTextBox();
|
||||
d->textBox->resizeFrame(option->rect.size());
|
||||
d->textBox->paintFrame(painter);
|
||||
|
||||
QStyleOption arrowOpt;
|
||||
arrowOpt = *option;
|
||||
arrowOpt.rect = subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget);
|
||||
qApp->style()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qApp->style()->drawComplexControl(control, option, painter, widget);
|
||||
}
|
||||
}
|
||||
|
||||
void Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
|
||||
{
|
||||
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
|
||||
qApp->style()->drawPrimitive(element, option, painter, widget);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (element) {
|
||||
case PE_PanelLineEdit:
|
||||
//comboboxes draws their own frame
|
||||
if (qobject_cast<QComboBox *>(widget->parent())) {
|
||||
return;
|
||||
}
|
||||
d->createTextBox();
|
||||
|
||||
d->textBox->resizeFrame(option->rect.size());
|
||||
d->textBox->paintFrame(painter);
|
||||
break;
|
||||
default:
|
||||
qApp->style()->drawPrimitive(element, option, painter, widget);
|
||||
}
|
||||
}
|
||||
|
||||
QRect Style::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
|
||||
SubControl subControl, const QWidget *widget) const
|
||||
{
|
||||
QRect rect(QCommonStyle::subControlRect(control, option, subControl, widget));
|
||||
switch (control) {
|
||||
case CC_Slider: {
|
||||
const QStyleOptionSlider *sliderOpt = qstyleoption_cast<const QStyleOptionSlider *>(option);
|
||||
if (sliderOpt) {
|
||||
if (sliderOpt->orientation == Qt::Horizontal) {
|
||||
rect.moveCenter(QPoint(rect.center().x(), option->rect.center().y()));
|
||||
} else {
|
||||
rect.moveCenter(QPoint(option->rect.center().x(), rect.center().y()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CC_ScrollBar: {
|
||||
const bool hasButtons = d->scrollbar->hasElement("arrow-up");
|
||||
switch (subControl) {
|
||||
//If one of the arrows is missing, don't reserve space for them
|
||||
case SC_ScrollBarAddLine:
|
||||
if (!hasButtons) {
|
||||
rect.setRect(0,0,0,0);
|
||||
}
|
||||
break;
|
||||
|
||||
case SC_ScrollBarSubLine:
|
||||
if (!hasButtons) {
|
||||
rect.setRect(0,0,0,0);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return rect;
|
||||
|
||||
}
|
||||
|
||||
int Style::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const
|
||||
{
|
||||
switch (hint) {
|
||||
case SH_RequestSoftwareInputPanel:
|
||||
return RSIP_OnMouseClick;
|
||||
default:
|
||||
return QCommonStyle::styleHint(hint, option, widget, returnData);
|
||||
}
|
||||
}
|
||||
|
||||
int Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
if (Theme::defaultTheme()->useNativeWidgetStyle()) {
|
||||
return qApp->style()->pixelMetric(metric, option, widget);
|
||||
}
|
||||
|
||||
switch (metric) {
|
||||
case PM_ScrollBarExtent: {
|
||||
d->createScrollbar();
|
||||
const QSizeF hintSize = d->scrollbar->elementSize("hint-scrollbar-size");
|
||||
const QStyleOptionSlider *scrollOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
|
||||
|
||||
if (scrollOption && scrollOption->orientation == Qt::Vertical) {
|
||||
if (hintSize.isEmpty()) {
|
||||
return d->scrollbar->elementSize("arrow-down").width() + 2;
|
||||
} else {
|
||||
return hintSize.width();
|
||||
}
|
||||
} else {
|
||||
if (hintSize.isEmpty()) {
|
||||
return d->scrollbar->elementSize("arrow-left").height() + 2;
|
||||
} else {
|
||||
return hintSize.height();
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
return qApp->style()->pixelMetric(metric, option, widget);
|
||||
}
|
||||
}
|
||||
|
||||
QRect Style::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
|
||||
{
|
||||
switch (element) {
|
||||
case SE_LineEditContents: {
|
||||
d->createTextBox();
|
||||
|
||||
qreal left, top, right, bottom;
|
||||
d->textBox->getMargins(left, top, right, bottom);
|
||||
return option->rect.adjusted(left + 2, top + 2, -(right + 2), -(bottom + 2));
|
||||
}
|
||||
default:
|
||||
return qApp->style()->subElementRect(element, option, widget);
|
||||
}
|
||||
}
|
||||
|
||||
QSize Style::sizeFromContents(ContentsType type, const QStyleOption *option,
|
||||
const QSize &contentsSize, const QWidget *widget) const
|
||||
{
|
||||
switch (type) {
|
||||
case CT_SpinBox: {
|
||||
d->createTextBox();
|
||||
|
||||
qreal left, top, right, bottom;
|
||||
d->textBox->getMargins(left, top, right, bottom);
|
||||
return contentsSize + QSize(left + right - 2, top + bottom - 2);
|
||||
}
|
||||
case CT_LineEdit: {
|
||||
d->createTextBox();
|
||||
|
||||
qreal left, top, right, bottom;
|
||||
d->textBox->getMargins(left, top, right, bottom);
|
||||
return contentsSize + QSize(left + right + 4, top + bottom + 4);
|
||||
}
|
||||
default:
|
||||
return qApp->style()->sizeFromContents(type, option, contentsSize, widget);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "moc_style_p.cpp"
|
||||
|
||||
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2008 Fredrik Höglund <fredrik@kde.org>
|
||||
* Copyright © 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_STYLE_P_H
|
||||
#define PLASMA_STYLE_P_H
|
||||
|
||||
#include <QtCore/QSharedData>
|
||||
#include <QCommonStyle>
|
||||
|
||||
#include <ksharedptr.h>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class StylePrivate;
|
||||
|
||||
class Style : public QCommonStyle, public QSharedData
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
typedef KSharedPtr<Style> Ptr;
|
||||
|
||||
static Style::Ptr sharedStyle();
|
||||
static void doneWithSharedStyle();
|
||||
|
||||
explicit Style();
|
||||
~Style();
|
||||
|
||||
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = 0) const;
|
||||
int styleHint(StyleHint hint, const QStyleOption *option=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const;
|
||||
|
||||
protected:
|
||||
void drawComplexControl(ComplexControl control,
|
||||
const QStyleOptionComplex *option,
|
||||
QPainter *painter,
|
||||
const QWidget *widget) const;
|
||||
|
||||
int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const;
|
||||
QRect subControlRect(ComplexControl control, const QStyleOptionComplex *option,
|
||||
SubControl subControl, const QWidget *widget) const;
|
||||
|
||||
QRect subElementRect(SubElement element, const QStyleOption * option, const QWidget *widget = 0) const;
|
||||
QSize sizeFromContents(ContentsType, const QStyleOption *option, const QSize &contentsSize,
|
||||
const QWidget *widget = 0) const;
|
||||
private:
|
||||
StylePrivate *d;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif // multiple inclusion guard
|
@ -1,222 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2010 Adenilson Cavalcanti <cavalcantii@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/* TODO:
|
||||
*
|
||||
* - cleanup debug messages
|
||||
*/
|
||||
|
||||
#include "animationscriptengine_p.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QMetaEnum>
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QPauseAnimation>
|
||||
#include <QSequentialAnimationGroup>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <klocalizedstring.h>
|
||||
|
||||
#include "animator.h"
|
||||
#include "javascriptanimation_p.h"
|
||||
#include "bindings/animationgroup_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
QScriptValue constructEasingCurveClass(QScriptEngine *engine);
|
||||
|
||||
namespace AnimationScriptEngine
|
||||
{
|
||||
|
||||
QScriptEngine* inst = 0;
|
||||
QHash<QString, QScriptValue> s_animFuncs;
|
||||
QSet<QString> s_animFailures;
|
||||
QString s_prefix;
|
||||
|
||||
QScriptValue animation(const QString &anim)
|
||||
{
|
||||
return s_animFuncs.value(anim);
|
||||
}
|
||||
|
||||
bool isAnimationRegistered(const QString &anim)
|
||||
{
|
||||
return s_animFuncs.contains(anim);
|
||||
}
|
||||
|
||||
void addToLoadFailures(const QString &anim)
|
||||
{
|
||||
s_animFailures.insert(anim);
|
||||
}
|
||||
|
||||
bool animationFailedToLoad(const QString &anim)
|
||||
{
|
||||
return s_animFailures.contains(anim);
|
||||
}
|
||||
|
||||
void clearAnimations()
|
||||
{
|
||||
s_animFuncs.clear();
|
||||
s_animFailures.clear();
|
||||
delete inst;
|
||||
inst = 0;
|
||||
}
|
||||
|
||||
QScriptValue registerAnimation(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() > 1) {
|
||||
const QString name = s_prefix + context->argument(0).toString();
|
||||
|
||||
if (!s_animFuncs.contains(name)) {
|
||||
const QScriptValue func = context->argument(1);
|
||||
if (func.isFunction()) {
|
||||
s_animFuncs.insert(name, func);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
QObject *extractParent(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
Q_UNUSED(engine)
|
||||
return context->thisObject().property("__plasma_javascriptanimation").toQObject();
|
||||
}
|
||||
|
||||
QScriptValue animationGroup(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
QObject *parent = extractParent(context, engine);
|
||||
if (!parent) {
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
QSequentialAnimationGroup *group = new SequentialAnimationGroup(parent);
|
||||
return engine->newQObject(group);
|
||||
}
|
||||
|
||||
QScriptValue parallelAnimationGroup(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
QObject *parent = extractParent(context, engine);
|
||||
if (!parent) {
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
|
||||
ParallelAnimationGroup *group = new ParallelAnimationGroup(parent);
|
||||
return engine->newQObject(group);
|
||||
}
|
||||
|
||||
void registerEnums(QScriptValue &scriptValue, const QMetaObject &meta)
|
||||
{
|
||||
//manually create enum values. ugh
|
||||
QScriptEngine *engine = scriptValue.engine();
|
||||
for (int i = 0; i < meta.enumeratorCount(); ++i) {
|
||||
QMetaEnum e = meta.enumerator(i);
|
||||
//kDebug() << e.name();
|
||||
for (int i=0; i < e.keyCount(); ++i) {
|
||||
//kDebug() << e.key(i) << e.value(i);
|
||||
scriptValue.setProperty(e.key(i), QScriptValue(engine, e.value(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QScriptValue animation(QScriptContext *context, QScriptEngine *engine)
|
||||
{
|
||||
if (context->argumentCount() != 1) {
|
||||
return context->throwError(i18n("animation() takes one argument"));
|
||||
}
|
||||
|
||||
QObject *parent = extractParent(context, engine);
|
||||
QAbstractAnimation *anim = 0;
|
||||
if (context->argument(0).isString()) {
|
||||
const QString animName = context->argument(0).toString();
|
||||
anim = Plasma::Animator::create(animName, parent);
|
||||
} else {
|
||||
int animId = context->argument(0).toInt32();
|
||||
if (animId == JavascriptAnimation::PauseAnimation) {
|
||||
anim = new QPauseAnimation(parent);
|
||||
} else if (animId == JavascriptAnimation::PropertyAnimation) {
|
||||
anim = new QPropertyAnimation(parent);
|
||||
} else {
|
||||
anim = Plasma::Animator::create(static_cast<Animator::Animation>(animId), parent);
|
||||
}
|
||||
}
|
||||
|
||||
if (anim) {
|
||||
QScriptValue value = engine->newQObject(anim);
|
||||
registerEnums(value, *anim->metaObject());
|
||||
return value;
|
||||
}
|
||||
|
||||
return context->throwError(i18n("%1 is not a known animation type", context->argument(0).isString()));
|
||||
}
|
||||
|
||||
QScriptEngine *globalEngine()
|
||||
{
|
||||
if (!inst) {
|
||||
inst = new QScriptEngine;
|
||||
QScriptValue global = inst->globalObject();
|
||||
global.setProperty("registerAnimation", inst->newFunction(AnimationScriptEngine::registerAnimation));
|
||||
global.setProperty("AnimationGroup", inst->newFunction(AnimationScriptEngine::animationGroup));
|
||||
global.setProperty("ParallelAnimationGroup", inst->newFunction(AnimationScriptEngine::parallelAnimationGroup));
|
||||
global.setProperty("QEasingCurve", constructEasingCurveClass(inst));
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "........... first js animation, creating the engine!";
|
||||
#endif
|
||||
}
|
||||
|
||||
return inst;
|
||||
}
|
||||
|
||||
bool loadScript(const QString &path, const QString &prefix)
|
||||
{
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
kError() << "failed to open script file" << path;
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream buffer(&file);
|
||||
QString tmp(buffer.readAll());
|
||||
|
||||
QScriptEngine *engine = AnimationScriptEngine::globalEngine();
|
||||
engine->pushContext();
|
||||
s_prefix = prefix;
|
||||
QScriptValue def(engine->evaluate(tmp, path));
|
||||
s_prefix.clear();
|
||||
engine->popContext();
|
||||
if (engine->hasUncaughtException()) {
|
||||
const QScriptValue error = engine->uncaughtException();
|
||||
QString file = error.property("fileName").toString();
|
||||
const QString failureMsg = QString("Error in %1 on line %2.\n%3")
|
||||
.arg(file)
|
||||
.arg(error.property("lineNumber").toString())
|
||||
.arg(error.toString());
|
||||
kError() << failureMsg;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace AnimationEngine
|
||||
} // namespace Plasma
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
|
||||
* Copyright 2010 Adenilson Cavalcanti <cavalcantii@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __ENGINE__
|
||||
#define __ENGINE__
|
||||
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptString>
|
||||
#include <QScriptValue>
|
||||
#include <QScriptContext>
|
||||
#include <QDebug>
|
||||
|
||||
/* Plasma-shell will have an engine */
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
namespace AnimationScriptEngine
|
||||
{
|
||||
|
||||
void clearAnimations();
|
||||
bool isAnimationRegistered(const QString &anim);
|
||||
QScriptEngine* globalEngine();
|
||||
QScriptValue animation(const QString &anim);
|
||||
bool loadScript(const QString &path, const QString &prefix = QString());
|
||||
void addToLoadFailures(const QString &anim);
|
||||
bool animationFailedToLoad(const QString &anim);
|
||||
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
@ -1,93 +0,0 @@
|
||||
#include "animations/animationscriptengine_p.h"
|
||||
#include "animator.h"
|
||||
|
||||
/**
|
||||
* Loads an animation from the applet package
|
||||
* @param animation the animation to load
|
||||
* @return an Animation object on success, a NULL pointer on failure
|
||||
* @since 4.5
|
||||
*/
|
||||
Animation *loadAnimationFromPackage(const QString &name, QObject *parent);
|
||||
|
||||
|
||||
Animation *AppletScript::loadAnimationFromPackage(const QString &name, QObject *parent)
|
||||
{
|
||||
if (applet()) {
|
||||
const QString scopedName = applet()->pluginName() + ":" + name;
|
||||
if (!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
|
||||
KConfig conf(applet()->package().path() + "/metadata.desktop", KConfig::SimpleConfig);
|
||||
KConfigGroup animConf(&conf, "Animations");
|
||||
QString file;
|
||||
foreach (const QString &possibleFile, animConf.keyList()) {
|
||||
const QStringList anims = animConf.readEntry(possibleFile, QStringList());
|
||||
if (anims.contains(name)) {
|
||||
file = possibleFile;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (file.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const QString path = applet()->package().filePath("animations", file);
|
||||
if (path.isEmpty()) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "file path was empty for" << file;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!AnimationScriptEngine::loadScript(path, applet()->pluginName() + ':') ||
|
||||
!AnimationScriptEngine::isAnimationRegistered(scopedName)) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "script engine loading failed for" << path;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Animation *anim = Animator::create(scopedName, parent ? parent : this);
|
||||
return anim;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory to build new animation objects from Javascript files. To control their behavior,
|
||||
* check \ref AbstractAnimation properties.
|
||||
* @since 4.5
|
||||
**/
|
||||
static Plasma::Animation *create(const QString &animationName, QObject *parent = 0);
|
||||
|
||||
Plasma::Animation *Animator::create(const QString &anim, QObject *parent)
|
||||
{
|
||||
if (AnimationScriptEngine::animationFailedToLoad(anim)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
|
||||
const QString path = Theme::defaultTheme()->animationPath(anim);
|
||||
if (path.isEmpty()) {
|
||||
AnimationScriptEngine::addToLoadFailures(anim);
|
||||
//kError() << "************ failed to find script file for animation" << anim;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!AnimationScriptEngine::loadScript(path)) {
|
||||
AnimationScriptEngine::addToLoadFailures(anim);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!AnimationScriptEngine::isAnimationRegistered(anim)) {
|
||||
//kError() << "successfully loaded script file" << path << ", but did not get animation object for" << anim;
|
||||
AnimationScriptEngine::addToLoadFailures(anim);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return new Plasma::JavascriptAnimation(anim, parent);
|
||||
}
|
||||
|
||||
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 "animationgroup_p.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
ParallelAnimationGroup::ParallelAnimationGroup(QObject *parent)
|
||||
: QParallelAnimationGroup(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void ParallelAnimationGroup::addAnimation(QAbstractAnimation *animation)
|
||||
{
|
||||
QParallelAnimationGroup::addAnimation(animation);
|
||||
}
|
||||
|
||||
QAbstractAnimation *ParallelAnimationGroup::animationAt(int index) const
|
||||
{
|
||||
return QParallelAnimationGroup::animationAt(index);
|
||||
}
|
||||
|
||||
int ParallelAnimationGroup::animationCount() const
|
||||
{
|
||||
return QParallelAnimationGroup::animationCount();
|
||||
}
|
||||
|
||||
void ParallelAnimationGroup::clear()
|
||||
{
|
||||
QParallelAnimationGroup::clear();
|
||||
}
|
||||
|
||||
int ParallelAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const
|
||||
{
|
||||
return QParallelAnimationGroup::indexOfAnimation(animation);
|
||||
}
|
||||
|
||||
void ParallelAnimationGroup::insertAnimation(int index, QAbstractAnimation *animation)
|
||||
{
|
||||
QParallelAnimationGroup::insertAnimation(index, animation);
|
||||
}
|
||||
|
||||
void ParallelAnimationGroup::removeAnimation(QAbstractAnimation *animation)
|
||||
{
|
||||
QParallelAnimationGroup::removeAnimation(animation);
|
||||
}
|
||||
|
||||
|
||||
SequentialAnimationGroup::SequentialAnimationGroup(QObject *parent)
|
||||
: QSequentialAnimationGroup(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void SequentialAnimationGroup::addAnimation(QAbstractAnimation *animation)
|
||||
{
|
||||
QSequentialAnimationGroup::addAnimation(animation);
|
||||
}
|
||||
|
||||
QAbstractAnimation *SequentialAnimationGroup::animationAt(int index) const
|
||||
{
|
||||
return QSequentialAnimationGroup::animationAt(index);
|
||||
}
|
||||
|
||||
int SequentialAnimationGroup::animationCount() const
|
||||
{
|
||||
return QSequentialAnimationGroup::animationCount();
|
||||
}
|
||||
|
||||
void SequentialAnimationGroup::clear()
|
||||
{
|
||||
QSequentialAnimationGroup::clear();
|
||||
}
|
||||
|
||||
int SequentialAnimationGroup::indexOfAnimation(QAbstractAnimation *animation) const
|
||||
{
|
||||
return QSequentialAnimationGroup::indexOfAnimation(animation);
|
||||
}
|
||||
|
||||
void SequentialAnimationGroup::insertAnimation(int index, QAbstractAnimation *animation)
|
||||
{
|
||||
QSequentialAnimationGroup::insertAnimation(index, animation);
|
||||
}
|
||||
|
||||
void SequentialAnimationGroup::removeAnimation(QAbstractAnimation *animation)
|
||||
{
|
||||
QSequentialAnimationGroup::removeAnimation(animation);
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "moc_animationgroup_p.cpp"
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright 2009 Aaron J. Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 JAVASCRIPTANIMATIONBINDINGS_P_H
|
||||
#define JAVASCRIPTANIMATIONBINDINGS_P_H
|
||||
|
||||
#include <QParallelAnimationGroup>
|
||||
#include <QSequentialAnimationGroup>
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ParallelAnimationGroup : public QParallelAnimationGroup
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ParallelAnimationGroup(QObject *parent);
|
||||
|
||||
public Q_SLOTS:
|
||||
void addAnimation(QAbstractAnimation * animation);
|
||||
QAbstractAnimation *animationAt(int index) const;
|
||||
int animationCount() const;
|
||||
void clear();
|
||||
int indexOfAnimation(QAbstractAnimation *animation) const;
|
||||
void insertAnimation(int index, QAbstractAnimation * animation);
|
||||
void removeAnimation(QAbstractAnimation * animation);
|
||||
};
|
||||
|
||||
class SequentialAnimationGroup : public QSequentialAnimationGroup
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SequentialAnimationGroup(QObject *parent);
|
||||
|
||||
public Q_SLOTS:
|
||||
void addAnimation(QAbstractAnimation * animation);
|
||||
QAbstractAnimation *animationAt(int index) const;
|
||||
int animationCount() const;
|
||||
void clear();
|
||||
int indexOfAnimation(QAbstractAnimation *animation) const;
|
||||
void insertAnimation(int index, QAbstractAnimation * animation);
|
||||
void removeAnimation(QAbstractAnimation * animation);
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif
|
||||
|
@ -1,172 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License version 2 as
|
||||
* published by the Free Software Foundation
|
||||
*
|
||||
* 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 <QEasingCurve>
|
||||
#include <QMetaEnum>
|
||||
#include <QScriptValue>
|
||||
#include <QScriptEngine>
|
||||
#include <QScriptContext>
|
||||
#include <QScriptable>
|
||||
|
||||
Q_DECLARE_METATYPE(QEasingCurve)
|
||||
Q_DECLARE_METATYPE(QEasingCurve*)
|
||||
#define ADD_ENUM_VALUE(__c__, __ns__, __v__) \
|
||||
__c__.setProperty(#__v__, QScriptValue(__c__.engine(), __ns__::__v__))
|
||||
|
||||
#define DECLARE_SELF(Class, __fn__) \
|
||||
Class* self = qscriptvalue_cast<Class*>(ctx->thisObject()); \
|
||||
if (!self) { \
|
||||
return ctx->throwError(QScriptContext::TypeError, \
|
||||
QString::fromLatin1("%0.prototype.%1: this object is not a %0") \
|
||||
.arg(#Class).arg(#__fn__)); \
|
||||
}
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
if (ctx->argumentCount() > 0) {
|
||||
QScriptValue arg = ctx->argument(0);
|
||||
if (arg.isNumber()) {
|
||||
qint32 type = arg.toInt32();
|
||||
if (type > -1 && type < QEasingCurve::Custom) {
|
||||
return qScriptValueFromValue(eng, QEasingCurve(static_cast<QEasingCurve::Type>(type)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return qScriptValueFromValue(eng, QEasingCurve());
|
||||
}
|
||||
|
||||
static QScriptValue toString(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(QEasingCurve, toString);
|
||||
return QScriptValue(eng, QString::fromLatin1("QEasingCurve(type=%0)").arg(self->type()));
|
||||
}
|
||||
|
||||
static QScriptValue type(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(QEasingCurve, type);
|
||||
|
||||
if (ctx->argumentCount()) {
|
||||
QScriptValue arg = ctx->argument(0);
|
||||
|
||||
qint32 type = -1;
|
||||
if (arg.isNumber()) {
|
||||
type = arg.toInt32();
|
||||
} else if (arg.isString()) {
|
||||
QMetaObject meta = QEasingCurve::staticMetaObject;
|
||||
QMetaEnum easingCurveEnum = meta.enumerator(meta.indexOfEnumerator("Type"));
|
||||
|
||||
type = easingCurveEnum.keyToValue(arg.toString().toAscii().data());
|
||||
}
|
||||
if (type > -1 && type < QEasingCurve::Custom) {
|
||||
self->setType(static_cast<QEasingCurve::Type>(type));
|
||||
}
|
||||
}
|
||||
|
||||
return QScriptValue(eng, self->type());
|
||||
}
|
||||
|
||||
static QScriptValue valueForProgress(QScriptContext *ctx, QScriptEngine *eng)
|
||||
{
|
||||
DECLARE_SELF(QEasingCurve, valueForProgress);
|
||||
if (ctx->argumentCount() < 1 || !ctx->argument(0).isNumber()) {
|
||||
return eng->undefinedValue();
|
||||
}
|
||||
|
||||
return self->valueForProgress(ctx->argument(0).toNumber());
|
||||
}
|
||||
|
||||
QScriptValue constructEasingCurveClass(QScriptEngine *eng)
|
||||
{
|
||||
QScriptValue proto = qScriptValueFromValue(eng, QEasingCurve());
|
||||
QScriptValue::PropertyFlags getter = QScriptValue::PropertyGetter;
|
||||
QScriptValue::PropertyFlags setter = QScriptValue::PropertySetter;
|
||||
|
||||
proto.setProperty("type", eng->newFunction(type), getter | setter);
|
||||
proto.setProperty("toString", eng->newFunction(toString), getter);
|
||||
proto.setProperty("valueForProgress", eng->newFunction(valueForProgress), getter);
|
||||
|
||||
QScriptValue ctorFun = eng->newFunction(ctor, proto);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, Linear);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InQuad);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutQuad);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutQuad);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInQuad);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InCubic);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutCubic);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutCubic);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInCubic);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InQuart);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutQuart);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutQuart);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInQuart);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InQuint);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutQuint);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutQuint);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInQuint);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InSine);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutSine);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutSine);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInSine);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InExpo);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutExpo);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutExpo);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInExpo);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InCirc);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutCirc);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutCirc);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInCirc);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InElastic);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutElastic);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutElastic);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInElastic);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InBack);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutBack);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutBack);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutInBack);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InBounce);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutBounce);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InOutBounce);
|
||||
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, InCurve);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, OutCurve);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, SineCurve);
|
||||
ADD_ENUM_VALUE(ctorFun, QEasingCurve, CosineCurve);
|
||||
|
||||
eng->setDefaultPrototype(qMetaTypeId<QEasingCurve>(), proto);
|
||||
eng->setDefaultPrototype(qMetaTypeId<QEasingCurve*>(), proto);
|
||||
|
||||
return ctorFun;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Adenilson Cavalcanti <cavalcantii@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "javascriptanimation_p.h"
|
||||
|
||||
#include <kdebug.h>
|
||||
|
||||
#include "animationscriptengine_p.h"
|
||||
/* TODO:
|
||||
* - support passing more parameters to the js animation object
|
||||
* - support more properties: angle, direction, etc
|
||||
* - support calling a 'resetAnimation' in js class when animation is stopped
|
||||
*/
|
||||
#define ADD_ENUM_VALUE(__c__, __ns__, __v__) \
|
||||
__c__.setProperty(#__v__, QScriptValue(__c__.engine(), __ns__::__v__))
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
JavascriptAnimation::JavascriptAnimation(const QString &name, QObject *parent)
|
||||
: EasingAnimation(parent),
|
||||
#ifdef PLASMA_JSANIM_FPS
|
||||
m_fps(0),
|
||||
#endif
|
||||
m_name(name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
JavascriptAnimation::~JavascriptAnimation()
|
||||
{
|
||||
}
|
||||
|
||||
void JavascriptAnimation::prepInstance()
|
||||
{
|
||||
QScriptEngine *engine = AnimationScriptEngine::globalEngine();
|
||||
m_instance.setProperty("__plasma_javascriptanimation", engine->newQObject(this),
|
||||
QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, FadeAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, AppearAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, DisappearAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, ActivateAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, FadeAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, GrowAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, PulseAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, RotationAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, RotationStackedAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, SlideAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, GeometryAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, ZoomAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, Plasma::Animator, PixmapTransitionAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, JavascriptAnimation, PauseAnimation);
|
||||
ADD_ENUM_VALUE(m_instance, JavascriptAnimation, PropertyAnimation);
|
||||
}
|
||||
|
||||
void JavascriptAnimation::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
|
||||
{
|
||||
//kDebug() << ".................. state: " << newState;
|
||||
if (oldState == Stopped && newState == Running) {
|
||||
if (!m_method.isFunction()) {
|
||||
//Define the class and create an instance
|
||||
m_instance = AnimationScriptEngine::animation(m_name).construct();
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "trying for" << m_name << m_instance.isFunction();
|
||||
#endif
|
||||
|
||||
//Get the method of the object
|
||||
m_method = m_instance.property(QString("updateCurrentTime"));
|
||||
if (!m_method.isFunction()) {
|
||||
qDebug() << "**************** ERROR! Name: " << m_name << " ************";
|
||||
m_instance = m_method = QScriptValue();
|
||||
} else {
|
||||
prepInstance();
|
||||
|
||||
//TODO: this really should be done in the bindings provided
|
||||
//Center the widget for transformation
|
||||
qreal x = targetWidget()->geometry().height()/2;
|
||||
qreal y = targetWidget()->geometry().width()/2;
|
||||
targetWidget()->setTransformOriginPoint(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_method.isFunction()) {
|
||||
m_instance.setProperty("duration", duration(), QScriptValue::ReadOnly);
|
||||
m_instance.setProperty("target", m_instance.engine()->newQObject(targetWidget()), QScriptValue::ReadOnly);
|
||||
}
|
||||
#ifdef PLASMA_JSANIM_FPS
|
||||
m_fps = 0;
|
||||
} else if (oldState == Running && newState == Stopped) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << ".........." << m_name << " fps: " << m_fps * 1000/duration();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void JavascriptAnimation::updateEffectiveTime(int currentTime)
|
||||
{
|
||||
if (m_method.isFunction()) {
|
||||
#ifdef PLASMA_JSANIM_FPS
|
||||
++m_fps;
|
||||
#endif
|
||||
QScriptValueList args;
|
||||
args << currentTime;
|
||||
|
||||
m_method.call(m_instance, args);
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace Plasma
|
||||
|
||||
#include "moc_javascriptanimation_p.cpp"
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Adenilson Cavalcanti <cavalcantii@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ANIMATIONS_JS_P_H
|
||||
#define PLASMA_ANIMATIONS_JS_P_H
|
||||
|
||||
#include <QScriptValue>
|
||||
|
||||
#include "animator.h"
|
||||
#include "easinganimation_p.h"
|
||||
#include "plasma_export.h"
|
||||
|
||||
class QString;
|
||||
class QScriptEngine;
|
||||
|
||||
//#define PLASMA_JSANIM_FPS
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class JavascriptAnimation: public EasingAnimation
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum { PauseAnimation = Animator::LastAnimation + 1,
|
||||
PropertyAnimation = Animator::LastAnimation + 2
|
||||
};
|
||||
|
||||
explicit JavascriptAnimation(const QString &name, QObject *parent = 0);
|
||||
|
||||
~JavascriptAnimation();
|
||||
|
||||
protected:
|
||||
void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState);
|
||||
void updateEffectiveTime(int currentTime);
|
||||
|
||||
private:
|
||||
void prepInstance();
|
||||
|
||||
#ifdef PLASMA_JSANIM_FPS
|
||||
int m_fps;
|
||||
#endif
|
||||
QString m_name;
|
||||
QScriptValue m_instance;
|
||||
QScriptValue m_method;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -22,8 +22,8 @@
|
||||
#define PLASMA_PAINTUTILS_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QGraphicsItem>
|
||||
#include <QPainterPath>
|
||||
#include <QColor>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
#include "theme.h"
|
||||
|
21
plasma.cpp
21
plasma.cpp
@ -20,8 +20,6 @@
|
||||
#include <plasma/plasma.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
#include <QMenu>
|
||||
|
||||
#include "containment.h"
|
||||
@ -73,23 +71,4 @@ Direction locationToInverseDirection(Location location)
|
||||
return Up;
|
||||
}
|
||||
|
||||
QGraphicsView *viewFor(const QGraphicsItem *item)
|
||||
{
|
||||
if (!item || !item->scene()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
QGraphicsView *found = 0;
|
||||
foreach (QGraphicsView *view, item->scene()->views()) {
|
||||
if (view->sceneRect().intersects(item->sceneBoundingRect()) ||
|
||||
view->sceneRect().contains(item->scenePos())) {
|
||||
if (!found || view->isActiveWindow()) {
|
||||
found = view;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
} // Plasma namespace
|
||||
|
15
plasma.h
15
plasma.h
@ -22,13 +22,11 @@
|
||||
|
||||
/** @header plasma/plasma.h <Plasma/Plasma> */
|
||||
|
||||
#include <QGraphicsItem>
|
||||
#include <QPainterPath>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QAction;
|
||||
class QGraphicsView;
|
||||
|
||||
/**
|
||||
* Namespace for everything in libplasma
|
||||
@ -163,11 +161,6 @@ enum IntervalAlignment {
|
||||
AlignToHour /**< Align to the hour **/
|
||||
};
|
||||
|
||||
enum ItemTypes {
|
||||
AppletType = QGraphicsItem::UserType + 1,
|
||||
LineEditType = QGraphicsItem::UserType + 2
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines the immutability of items like applets, corona and containments
|
||||
* they can be free to modify, locked down by the user or locked down by the
|
||||
@ -289,14 +282,6 @@ PLASMA_EXPORT Direction locationToDirection(Location location);
|
||||
**/
|
||||
PLASMA_EXPORT Direction locationToInverseDirection(Location location);
|
||||
|
||||
/**
|
||||
* Returns the most appropriate QGraphicsView for the item.
|
||||
*
|
||||
* @param item the QGraphicsItem to locate a view for
|
||||
* @return pointer to a view, or 0 if none was found
|
||||
*/
|
||||
PLASMA_EXPORT QGraphicsView *viewFor(const QGraphicsItem *item);
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Constraints)
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "containmentactions.h"
|
||||
#include "dataengine.h"
|
||||
#include "package.h"
|
||||
#include "popupapplet.h"
|
||||
#include "private/applet_p.h"
|
||||
#include "private/packages_p.h"
|
||||
#include "private/service_p.h" // for NullService
|
||||
@ -151,8 +150,6 @@ Applet *PluginLoader::loadApplet(const QString &name, uint appletId, const QVari
|
||||
} else {
|
||||
if (offer->serviceTypes().contains("Plasma/Containment")) {
|
||||
return new Containment(0, allArgs);
|
||||
} else if (offer->serviceTypes().contains("Plasma/PopupApplet")) {
|
||||
return new PopupApplet(0, allArgs);
|
||||
} else {
|
||||
return new Applet(0, allArgs);
|
||||
}
|
||||
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ABSTRACTANIMATIONPRIVATE_P_H
|
||||
#define PLASMA_ABSTRACTANIMATIONPRIVATE_P_H
|
||||
|
||||
#include <QEasingCurve>
|
||||
#include <QWeakPointer>
|
||||
class QAbstractAnimation;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AnimationPrivate
|
||||
{
|
||||
public:
|
||||
|
||||
AbstractAnimationPrivate();
|
||||
/**
|
||||
* Object the animation(s) should act upon.
|
||||
*/
|
||||
QWeakPointer<QGraphicsWidget> animObject;
|
||||
|
||||
/**
|
||||
* Animation direction: where the animation will move.
|
||||
*/
|
||||
qint8 animDirection;
|
||||
|
||||
/**
|
||||
* Animation distance: displacement factor for animations where
|
||||
* there is change in the position of animated widget.
|
||||
*/
|
||||
qreal animDistance;
|
||||
|
||||
/**
|
||||
* Animation easing curve type
|
||||
*/
|
||||
QEasingCurve easingCurve;
|
||||
|
||||
/**
|
||||
* Animation direction, the idea is to offer a way
|
||||
* to rewind the animation by setDirection(QAbstractAnimation::Backward).
|
||||
*/
|
||||
bool forwards;
|
||||
|
||||
/**
|
||||
* Duration of the animation. Default is 250ms.
|
||||
*/
|
||||
int duration;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PLASMA_ABSTRACTANIMATIONPRIVATE_P_H
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
Copyright (C) 2009 Adenilson Cavalcanti <adenilson.silva@idnt.org.br>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_ANIMATIONPRIVATE_P_H
|
||||
#define PLASMA_ANIMATIONPRIVATE_P_H
|
||||
|
||||
#include <QEasingCurve>
|
||||
#include <QWeakPointer>
|
||||
class QAbstractAnimation;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class AnimationPrivate
|
||||
{
|
||||
public:
|
||||
|
||||
AnimationPrivate();
|
||||
/**
|
||||
* Object the animation(s) should act upon.
|
||||
*/
|
||||
QWeakPointer<QGraphicsWidget> animObject;
|
||||
|
||||
/**
|
||||
* Animation easing curve type
|
||||
*/
|
||||
QEasingCurve easingCurve;
|
||||
|
||||
/**
|
||||
* Duration of the animation. Default is 250ms.
|
||||
*/
|
||||
int duration;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PLASMA_ANIMATIONPRIVATE_P_H
|
@ -25,8 +25,7 @@
|
||||
|
||||
#include <config-plasma.h>
|
||||
|
||||
#include <QGraphicsLayout>
|
||||
#include <QGraphicsView>
|
||||
#include <QFile>
|
||||
#include <QHostInfo>
|
||||
#include <qstandardpaths.h>
|
||||
|
||||
@ -35,7 +34,6 @@
|
||||
#include <kkeysequencewidget.h>
|
||||
#include <kstandarddirs.h>
|
||||
|
||||
#include "abstracttoolbox.h"
|
||||
#include "containment.h"
|
||||
#include "corona.h"
|
||||
#include "pluginloader.h"
|
||||
@ -56,12 +54,10 @@ AppletPrivate::AppletPrivate(KService::Ptr service, const KPluginInfo *info, int
|
||||
: appletId(uniqueID),
|
||||
q(applet),
|
||||
remotingService(0),
|
||||
preferredBackgroundHints(StandardBackground),
|
||||
backgroundHints(NoBackground),
|
||||
backgroundHints(StandardBackground),
|
||||
aspectRatioMode(Plasma::KeepAspectRatio),
|
||||
immutability(Mutable),
|
||||
appletDescription(info ? *info : KPluginInfo(service)),
|
||||
background(0),
|
||||
mainConfig(0),
|
||||
pendingConstraints(NoConstraint),
|
||||
script(0),
|
||||
@ -131,7 +127,6 @@ void AppletPrivate::init(const QString &packagePath)
|
||||
<< "You probably want to be passing in a Service::Ptr "
|
||||
<< "or a QVariantList with a valid storageid as arg[0].";
|
||||
#endif
|
||||
q->resize(size);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -140,7 +135,6 @@ void AppletPrivate::init(const QString &packagePath)
|
||||
size = s.toSize();
|
||||
}
|
||||
//kDebug() << "size" << size;
|
||||
q->resize(size);
|
||||
|
||||
QString api = appletDescription.property("X-Plasma-API").toString();
|
||||
|
||||
@ -205,15 +199,11 @@ void AppletPrivate::init(const QString &packagePath)
|
||||
}
|
||||
}
|
||||
|
||||
void AppletPrivate::setFocus()
|
||||
{
|
||||
//kDebug() << "setting focus";
|
||||
q->setFocus(Qt::ShortcutFocusReason);
|
||||
}
|
||||
|
||||
void AppletPrivate::selectItemToDestroy()
|
||||
{
|
||||
//FIXME: this will not work nicely with multiple screens and being zoomed out!
|
||||
//TODO: port away from QGV
|
||||
/*
|
||||
if (isContainment) {
|
||||
QGraphicsView *view = q->view();
|
||||
if (view && view->transform().isScaling() &&
|
||||
@ -229,16 +219,11 @@ void AppletPrivate::selectItemToDestroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
q->destroy();
|
||||
}
|
||||
|
||||
void AppletPrivate::updateRect(const QRectF &rect)
|
||||
{
|
||||
q->update(rect);
|
||||
}
|
||||
|
||||
void AppletPrivate::cleanUpAndDelete()
|
||||
{
|
||||
// reimplemented in the UI specific library
|
||||
@ -304,14 +289,14 @@ KActionCollection* AppletPrivate::defaultActions(QObject *parent)
|
||||
configAction->setText(i18n("Widget Settings"));
|
||||
configAction->setIcon(KDE::icon("configure"));
|
||||
configAction->setShortcut(KShortcut("alt+d, s"));
|
||||
configAction->setData(AbstractToolBox::ConfigureTool);
|
||||
configAction->setData(Containment::ConfigureTool);
|
||||
|
||||
KAction *closeApplet = actions->addAction("remove");
|
||||
closeApplet->setAutoRepeat(false);
|
||||
closeApplet->setText(i18n("Remove this Widget"));
|
||||
closeApplet->setIcon(KDE::icon("edit-delete"));
|
||||
closeApplet->setShortcut(KShortcut("alt+d, r"));
|
||||
closeApplet->setData(AbstractToolBox::DestructiveTool);
|
||||
closeApplet->setData(Containment::DestructiveTool);
|
||||
|
||||
KAction *runAssociatedApplication = actions->addAction("run associated application");
|
||||
runAssociatedApplication->setAutoRepeat(false);
|
||||
@ -320,7 +305,7 @@ KActionCollection* AppletPrivate::defaultActions(QObject *parent)
|
||||
runAssociatedApplication->setShortcut(KShortcut("alt+d, t"));
|
||||
runAssociatedApplication->setVisible(false);
|
||||
runAssociatedApplication->setEnabled(false);
|
||||
runAssociatedApplication->setData(AbstractToolBox::ControlTool);
|
||||
runAssociatedApplication->setData(Containment::ControlTool);
|
||||
|
||||
return actions;
|
||||
}
|
||||
@ -684,7 +669,7 @@ KConfigGroup *AppletPrivate::mainConfigGroup()
|
||||
}
|
||||
|
||||
if (isContainment) {
|
||||
Corona *corona = qobject_cast<Corona*>(q->scene());
|
||||
Corona *corona = static_cast<Containment*>(q)->corona();
|
||||
KConfigGroup containmentConfig;
|
||||
//kDebug() << "got a corona, baby?" << (QObject*)corona << (QObject*)q;
|
||||
|
||||
@ -733,22 +718,6 @@ QString AppletPrivate::visibleFailureText(const QString &reason)
|
||||
return text;
|
||||
}
|
||||
|
||||
void AppletPrivate::themeChanged()
|
||||
{
|
||||
if (background) {
|
||||
//do again the translucent background fallback
|
||||
q->setBackgroundHints(backgroundHints);
|
||||
|
||||
qreal left;
|
||||
qreal right;
|
||||
qreal top;
|
||||
qreal bottom;
|
||||
background->getMargins(left, top, right, bottom);
|
||||
q->setContentsMargins(left, right, top, bottom);
|
||||
}
|
||||
q->update();
|
||||
}
|
||||
|
||||
void AppletPrivate::resetConfigurationObject()
|
||||
{
|
||||
// make sure mainConfigGroup exists in all cases
|
||||
@ -758,24 +727,15 @@ void AppletPrivate::resetConfigurationObject()
|
||||
delete mainConfig;
|
||||
mainConfig = 0;
|
||||
|
||||
Corona * corona = qobject_cast<Corona*>(q->scene());
|
||||
if (!q->containment()) {
|
||||
return;
|
||||
}
|
||||
Corona * corona = q->containment()->corona();
|
||||
if (corona) {
|
||||
corona->requireConfigSync();
|
||||
}
|
||||
}
|
||||
|
||||
void AppletPrivate::handleDisappeared(AppletHandle *h)
|
||||
{
|
||||
if (h == handle.data()) {
|
||||
h->detachApplet();
|
||||
QGraphicsScene *scene = q->scene();
|
||||
if (scene && h->scene() == scene) {
|
||||
scene->removeItem(h);
|
||||
}
|
||||
h->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
uint AppletPrivate::s_maxAppletId = 0;
|
||||
int AppletPrivate::s_maxZValue = 0;
|
||||
int AppletPrivate::s_minZValue = 0;
|
||||
|
@ -23,13 +23,14 @@
|
||||
#define PLASMA_APPLET_P_H
|
||||
|
||||
#include <QBasicTimer>
|
||||
#include <QGraphicsProxyWidget>
|
||||
|
||||
#include <kactioncollection.h>
|
||||
#include <kconfigdialog.h>
|
||||
#include <kconfigskeleton.h>
|
||||
#include <kservice.h>
|
||||
#include <kplugininfo.h>
|
||||
|
||||
#include "plasma/animator.h"
|
||||
#include "plasma/private/applethandle_p.h"
|
||||
#include "plasma/applet.h"
|
||||
#include "plasma/dataengineconsumer.h"
|
||||
#include "plasma/ui_publish.h"
|
||||
|
||||
@ -100,18 +101,14 @@ public:
|
||||
*/
|
||||
void setIsContainment(bool isContainment, bool forceUpdate = false);
|
||||
|
||||
void handleDisappeared(AppletHandle *handle);
|
||||
QString globalName() const;
|
||||
QString instanceName();
|
||||
void scheduleConstraintsUpdate(Plasma::Constraints c);
|
||||
void scheduleModificationNotification();
|
||||
KConfigGroup *mainConfigGroup();
|
||||
QString visibleFailureText(const QString &reason);
|
||||
void themeChanged();
|
||||
void resetConfigurationObject();
|
||||
void selectItemToDestroy();
|
||||
void updateRect(const QRectF &rect);
|
||||
void setFocus();
|
||||
void addGlobalShortcutsPage(KConfigDialog *dialog);
|
||||
void addPublishPage(KConfigDialog *dialog);
|
||||
void configDialogFinished();
|
||||
@ -140,7 +137,6 @@ public:
|
||||
|
||||
// applet attributes
|
||||
Service *remotingService;
|
||||
BackgroundHints preferredBackgroundHints;
|
||||
BackgroundHints backgroundHints;
|
||||
AspectRatioMode aspectRatioMode;
|
||||
ImmutabilityType immutability;
|
||||
@ -151,8 +147,6 @@ public:
|
||||
QString name;
|
||||
|
||||
// bookkeeping
|
||||
QSet<QGraphicsItem*> registeredAsDragHandle;
|
||||
Plasma::FrameSvg *background;
|
||||
KConfigGroup *mainConfig;
|
||||
Plasma::Constraints pendingConstraints;
|
||||
|
||||
@ -160,7 +154,6 @@ public:
|
||||
AppletScript *script;
|
||||
Package *package;
|
||||
ConfigLoader *configLoader;
|
||||
QWeakPointer<AppletHandle> handle;
|
||||
|
||||
// actions stuff; put activationAction into actions?
|
||||
KActionCollection *actions;
|
||||
@ -181,7 +174,6 @@ public:
|
||||
|
||||
// timerEvent bookkeeping
|
||||
QBasicTimer constraintsTimer;
|
||||
QBasicTimer busyWidgetTimer;
|
||||
QBasicTimer *modificationsTimer;
|
||||
|
||||
// a great green field of booleans :)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007 by Kevin Ottens <ervin@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_APPLETHANDLE_P_H
|
||||
#define PLASMA_APPLETHANDLE_P_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QGraphicsObject>
|
||||
#include <QTimer>
|
||||
#include <QWeakPointer>
|
||||
#include <QPropertyAnimation>
|
||||
|
||||
#include "animator.h"
|
||||
#include "applet.h"
|
||||
#include "svg.h"
|
||||
|
||||
class QGraphicsView;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class Containment;
|
||||
class FrameSvg;
|
||||
class View;
|
||||
|
||||
class AppletHandle : public QGraphicsObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(qreal fadeAnimation READ fadeAnimation WRITE setFadeAnimation)
|
||||
Q_INTERFACES(QGraphicsItem)
|
||||
public:
|
||||
enum FadeType {
|
||||
FadeIn,
|
||||
FadeOut
|
||||
};
|
||||
enum ButtonType {
|
||||
NoButton,
|
||||
MoveButton,
|
||||
RotateButton,
|
||||
ConfigureButton,
|
||||
RemoveButton,
|
||||
ResizeButton,
|
||||
MaximizeButton
|
||||
};
|
||||
|
||||
AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos);
|
||||
virtual ~AppletHandle();
|
||||
|
||||
bool shown() const;
|
||||
|
||||
void detachApplet();
|
||||
Applet *applet() const;
|
||||
|
||||
QRectF boundingRect() const;
|
||||
QPainterPath shape() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
void startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide = false);
|
||||
void setHoverPos(const QPointF &hoverPos);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
|
||||
bool sceneEvent(QEvent*);
|
||||
|
||||
Q_SIGNALS:
|
||||
void disappearDone(AppletHandle *self);
|
||||
|
||||
private Q_SLOTS:
|
||||
void setFadeAnimation(qreal progress);
|
||||
qreal fadeAnimation() const;
|
||||
void appletDestroyed();
|
||||
void appletResized();
|
||||
void hoverTimeout();
|
||||
void leaveTimeout();
|
||||
void emitDisappear();
|
||||
void scheduleUpdate();
|
||||
|
||||
private:
|
||||
static const int HANDLE_MARGIN = 3;
|
||||
|
||||
void calculateSize();
|
||||
ButtonType mapToButton(const QPointF &point) const;
|
||||
void forceDisappear();
|
||||
int minimumHeight();
|
||||
|
||||
/**
|
||||
* move our applet to another containment
|
||||
* @param containment the containment to move to
|
||||
* @param pos the (scene-relative) position to place it at
|
||||
*/
|
||||
void switchContainment(Containment *containment, const QPointF &pos);
|
||||
bool leaveCurrentView(const QPoint &pos) const;
|
||||
|
||||
QRectF m_rect;
|
||||
QRectF m_decorationRect;
|
||||
QRectF m_totalRect;
|
||||
ButtonType m_pressedButton;
|
||||
Containment *m_containment;
|
||||
Applet *m_applet;
|
||||
int m_iconSize;
|
||||
qreal m_opacity;
|
||||
FadeType m_animType;
|
||||
QWeakPointer<QPropertyAnimation> m_anim;
|
||||
qreal m_angle;
|
||||
QColor m_gradientColor;
|
||||
QTimer *m_hoverTimer;
|
||||
QTimer *m_leaveTimer;
|
||||
QPixmap *m_backgroundBuffer;
|
||||
QWeakPointer<QGraphicsView> m_currentView;
|
||||
|
||||
Svg *m_configureIcons;
|
||||
FrameSvg *m_background;
|
||||
|
||||
QPoint m_mousePos; //mousepos relative to applet
|
||||
QPointF m_entryPos; //where the hover in event occurred
|
||||
qreal m_zValue; //current zValue of the applet, so it can be restored after drag.
|
||||
QRectF m_originalGeom;
|
||||
QTransform m_originalTransform;
|
||||
|
||||
// used for both resize and rotate
|
||||
QPointF m_origAppletCenter;
|
||||
QPointF m_origAppletSize;
|
||||
|
||||
// used for resize
|
||||
QPointF m_resizeStaticPoint;
|
||||
QPointF m_resizeGrabPoint;
|
||||
// used for rotate
|
||||
qreal m_rotateAngleOffset; // applet angle minus cursor angle
|
||||
|
||||
bool m_buttonsOnRight : 1;
|
||||
bool m_pendingFade : 1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // multiple inclusion guard
|
@ -24,10 +24,9 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QGraphicsSceneDragDropEvent>
|
||||
#include <QMimeData>
|
||||
#include <QMimeDatabase>
|
||||
#include <QGraphicsView>
|
||||
#include <QDropEvent>
|
||||
#include <qtemporaryfile.h>
|
||||
|
||||
#include <kaction.h>
|
||||
@ -44,7 +43,6 @@
|
||||
#include "kio/scheduler.h"
|
||||
#endif
|
||||
|
||||
#include "abstracttoolbox.h"
|
||||
#include "containmentactions.h"
|
||||
#include "containmentactionspluginsconfig.h"
|
||||
#include "corona.h"
|
||||
@ -94,19 +92,19 @@ void ContainmentPrivate::addDefaultActions(KActionCollection *actions, Containme
|
||||
appletBrowserAction->setText(i18n("Add Widgets..."));
|
||||
appletBrowserAction->setIcon(KDE::icon("list-add"));
|
||||
appletBrowserAction->setShortcut(KShortcut("alt+d, a"));
|
||||
appletBrowserAction->setData(AbstractToolBox::AddTool);
|
||||
appletBrowserAction->setData(Containment::AddTool);
|
||||
|
||||
KAction *action = actions->addAction("next applet");
|
||||
action->setText(i18n("Next Widget"));
|
||||
//no icon
|
||||
action->setShortcut(KShortcut("alt+d, n"));
|
||||
action->setData(AbstractToolBox::ControlTool);
|
||||
action->setData(Containment::ControlTool);
|
||||
|
||||
action = actions->addAction("previous applet");
|
||||
action->setText(i18n("Previous Widget"));
|
||||
//no icon
|
||||
action->setShortcut(KShortcut("alt+d, p"));
|
||||
action->setData(AbstractToolBox::ControlTool);
|
||||
action->setData(Containment::ControlTool);
|
||||
}
|
||||
|
||||
void ContainmentPrivate::initApplets()
|
||||
@ -134,13 +132,12 @@ void ContainmentPrivate::checkContainmentFurniture()
|
||||
{
|
||||
if (q->isContainment() &&
|
||||
(type == Containment::DesktopContainment || type == Containment::PanelContainment)) {
|
||||
createToolBox();
|
||||
}
|
||||
}
|
||||
|
||||
void ContainmentPrivate::addContainmentActions(KMenu &desktopMenu, QEvent *event)
|
||||
{
|
||||
if (static_cast<Corona*>(q->scene())->immutability() != Mutable &&
|
||||
if (q->corona()->immutability() != Mutable &&
|
||||
!KAuthorized::authorizeKAction("plasma/containment_actions")) {
|
||||
//kDebug() << "immutability";
|
||||
return;
|
||||
@ -213,6 +210,8 @@ void ContainmentPrivate::addAppletActions(KMenu &desktopMenu, Applet *applet, QE
|
||||
|
||||
Applet* ContainmentPrivate::appletAt(const QPointF &point)
|
||||
{
|
||||
return 0;
|
||||
/*TODO: port away qgv
|
||||
Applet *applet = 0;
|
||||
|
||||
QGraphicsItem *item = q->scene()->itemAt(point);
|
||||
@ -239,6 +238,7 @@ Applet* ContainmentPrivate::appletAt(const QPointF &point)
|
||||
item = item->parentItem();
|
||||
}
|
||||
return applet;
|
||||
*/
|
||||
}
|
||||
|
||||
void ContainmentPrivate::setScreen(int newScreen, int newDesktop, bool preventInvalidDesktops)
|
||||
@ -257,9 +257,11 @@ void ContainmentPrivate::setScreen(int newScreen, int newDesktop, bool preventIn
|
||||
Q_ASSERT(corona);
|
||||
|
||||
//if it's an offscreen widget, don't allow to claim a screen, after all it's *off*screen
|
||||
//TODO: port away qgv
|
||||
/* should decide in a different way if this is a dashboard containment
|
||||
if (corona->offscreenWidgets().contains(q)) {
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
int numScreens = corona->numScreens();
|
||||
if (newScreen < -1) {
|
||||
@ -277,15 +279,6 @@ void ContainmentPrivate::setScreen(int newScreen, int newDesktop, bool preventIn
|
||||
const bool isDesktopContainment = type == Containment::DesktopContainment ||
|
||||
type == Containment::CustomContainment;
|
||||
if (isDesktopContainment) {
|
||||
// we want to listen to changes in work area if our screen changes
|
||||
if (toolBox) {
|
||||
if (screen < 0 && newScreen > -1) {
|
||||
QObject::connect(KWindowSystem::self(), SIGNAL(workAreaChanged()), toolBox.data(), SLOT(reposition()), Qt::UniqueConnection);
|
||||
} else if (newScreen < 0) {
|
||||
QObject::disconnect(KWindowSystem::self(), SIGNAL(workAreaChanged()), toolBox.data(), SLOT(reposition()));
|
||||
}
|
||||
}
|
||||
|
||||
if (newScreen > -1) {
|
||||
// sanity check to make sure someone else doesn't have this screen already!
|
||||
Containment *currently = corona->containmentForScreen(newScreen, newDesktop);
|
||||
@ -354,13 +347,12 @@ void ContainmentPrivate::showDropZoneDelayed()
|
||||
dropPoints.remove(0);
|
||||
}
|
||||
|
||||
void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsSceneDragDropEvent *dropEvent)
|
||||
void ContainmentPrivate::dropData(QPoint screenPos, QDropEvent *dropEvent)
|
||||
{
|
||||
if (q->immutability() != Mutable) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPointF pos = q->mapFromScene(scenePos);
|
||||
const QMimeData *mimeData = 0;
|
||||
|
||||
if (dropEvent) {
|
||||
@ -388,7 +380,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
const QStringList appletNames = data.split('\n', QString::SkipEmptyParts);
|
||||
foreach (const QString &appletName, appletNames) {
|
||||
//kDebug() << "doing" << appletName;
|
||||
QRectF geom(pos, QSize(0, 0));
|
||||
QRectF geom(screenPos, QSize(0, 0));
|
||||
q->addApplet(appletName, QVariantList(), geom);
|
||||
}
|
||||
if (dropEvent) {
|
||||
@ -404,7 +396,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
if (dropEvent) {
|
||||
dropPoints[job] = dropEvent->pos();
|
||||
} else {
|
||||
dropPoints[job] = scenePos;
|
||||
dropPoints[job] = screenPos;
|
||||
}
|
||||
QObject::connect(AccessManager::self(), SIGNAL(finished(Plasma::AccessAppletJob*)),
|
||||
q, SLOT(remoteAppletReady(Plasma::AccessAppletJob*)));
|
||||
@ -414,7 +406,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
QMimeDatabase db;
|
||||
QMimeType mime = db.mimeTypeForUrl(url);
|
||||
QString mimeName = mime.name();
|
||||
QRectF geom(pos, QSize());
|
||||
QRectF geom(screenPos, QSize());
|
||||
QVariantList args;
|
||||
args << url.toString();
|
||||
#ifndef NDEBUG
|
||||
@ -427,7 +419,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
if (dropEvent) {
|
||||
dropPoints[job] = dropEvent->pos();
|
||||
} else {
|
||||
dropPoints[job] = scenePos;
|
||||
dropPoints[job] = screenPos;
|
||||
}
|
||||
|
||||
QObject::connect(job, SIGNAL(result(KJob*)), q, SLOT(dropJobResult(KJob*)));
|
||||
@ -437,7 +429,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
KMenu *choices = new KMenu("Content dropped");
|
||||
choices->addAction(KDE::icon("process-working"), i18n("Fetching file type..."));
|
||||
if (dropEvent) {
|
||||
choices->popup(dropEvent->screenPos());
|
||||
choices->popup(dropEvent->pos());
|
||||
} else {
|
||||
choices->popup(screenPos);
|
||||
}
|
||||
@ -516,7 +508,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
|
||||
stream.writeRawData(data, data.size());
|
||||
}
|
||||
|
||||
QRectF geom(pos, QSize());
|
||||
QRectF geom(screenPos, QSize());
|
||||
QVariantList args;
|
||||
args << tempFile.fileName();
|
||||
#ifndef NDEBUG
|
||||
@ -797,32 +789,6 @@ void ContainmentPrivate::checkStatus(Plasma::ItemStatus appletStatus)
|
||||
q->setStatus(appletStatus);
|
||||
}
|
||||
|
||||
void ContainmentPrivate::createToolBox()
|
||||
{
|
||||
if (!toolBox && KAuthorized::authorizeKAction("plasma/containment_context_menu")) {
|
||||
toolBox = Plasma::AbstractToolBox::load(q->corona()->preferredToolBoxPlugin(type), QVariantList(), q);
|
||||
|
||||
if (toolBox) {
|
||||
QObject::connect(toolBox.data(), SIGNAL(toggled()), q, SIGNAL(toolBoxToggled()));
|
||||
QObject::connect(toolBox.data(), SIGNAL(toggled()), q, SLOT(updateToolBoxVisibility()));
|
||||
|
||||
positionToolBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ContainmentPrivate::positionToolBox()
|
||||
{
|
||||
if (toolBox) {
|
||||
toolBox.data()->reposition();
|
||||
}
|
||||
}
|
||||
|
||||
void ContainmentPrivate::updateToolBoxVisibility()
|
||||
{
|
||||
emit q->toolBoxVisibilityChanged(toolBox.data()->isShowing());
|
||||
}
|
||||
|
||||
void ContainmentPrivate::triggerShowAddWidgets()
|
||||
{
|
||||
emit q->showAddWidgetsInterface(QPointF());
|
||||
@ -865,14 +831,6 @@ void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constra
|
||||
}
|
||||
}
|
||||
|
||||
if (toolBox && (constraints & Plasma::SizeConstraint ||
|
||||
constraints & Plasma::FormFactorConstraint ||
|
||||
constraints & Plasma::ScreenConstraint ||
|
||||
constraints & Plasma::StartupCompletedConstraint)) {
|
||||
//kDebug() << "Positioning toolbox";
|
||||
positionToolBox();
|
||||
}
|
||||
|
||||
if (constraints & Plasma::StartupCompletedConstraint && type < Containment::CustomContainment) {
|
||||
q->addToolBoxAction(q->action("remove"));
|
||||
checkRemoveAction();
|
||||
@ -893,15 +851,7 @@ Applet *ContainmentPrivate::addApplet(const QString &name, const QVariantList &a
|
||||
return 0;
|
||||
}
|
||||
|
||||
QGraphicsView *v = q->view();
|
||||
if (v) {
|
||||
v->setCursor(Qt::BusyCursor);
|
||||
}
|
||||
|
||||
Applet *applet = PluginLoader::self()->loadApplet(name, id, args);
|
||||
if (v) {
|
||||
v->unsetCursor();
|
||||
}
|
||||
|
||||
if (!applet) {
|
||||
#ifndef NDEBUG
|
||||
@ -946,125 +896,11 @@ void ContainmentPrivate::appletAppeared(Applet *applet)
|
||||
emit q->configNeedsSaving();
|
||||
}
|
||||
|
||||
void ContainmentPrivate::positionPanel(bool force)
|
||||
{
|
||||
if (!q->scene()) {
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "no scene yet";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// already positioning the panel - avoid infinite loops
|
||||
if (ContainmentPrivate::s_positioningPanels) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we position panels in negative coordinates, and stack all horizontal
|
||||
// and all vertical panels with each other.
|
||||
|
||||
|
||||
const QPointF p = q->pos();
|
||||
|
||||
if (!force &&
|
||||
p.y() + q->size().height() < -INTER_CONTAINMENT_MARGIN &&
|
||||
q->scene()->collidingItems(q).isEmpty()) {
|
||||
// already positioned and not running into any other panels
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QPointF newPos = preferredPanelPos(q->corona());
|
||||
if (p != newPos) {
|
||||
ContainmentPrivate::s_positioningPanels = true;
|
||||
q->setPos(newPos);
|
||||
ContainmentPrivate::s_positioningPanels = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ContainmentPrivate::isPanelContainment() const
|
||||
{
|
||||
return type == Containment::PanelContainment || type == Containment::CustomPanelContainment;
|
||||
}
|
||||
|
||||
QPointF ContainmentPrivate::preferredPos(Corona *corona) const
|
||||
{
|
||||
Q_ASSERT(corona);
|
||||
|
||||
if (isPanelContainment()) {
|
||||
//kDebug() << "is a panel, so put it at" << preferredPanelPos(corona);
|
||||
return preferredPanelPos(corona);
|
||||
}
|
||||
|
||||
QPointF pos(0, 0);
|
||||
QTransform t;
|
||||
while (QGraphicsItem *i = corona->itemAt(pos, t)) {
|
||||
pos.setX(i->scenePos().x() + i->boundingRect().width() + 10);
|
||||
}
|
||||
|
||||
//kDebug() << "not a panel, put it at" << pos;
|
||||
return pos;
|
||||
}
|
||||
|
||||
QPointF ContainmentPrivate::preferredPanelPos(Corona *corona) const
|
||||
{
|
||||
Q_ASSERT(corona);
|
||||
|
||||
//TODO: research how non-Horizontal, non-Vertical (e.g. Planar) panels behave here
|
||||
bool horiz = formFactor == Plasma::Horizontal;
|
||||
qreal bottom = horiz ? 0 : VERTICAL_STACKING_OFFSET;
|
||||
qreal lastHeight = 0;
|
||||
|
||||
// this should be ok for small numbers of panels, but if we ever end
|
||||
// up managing hundreds of them, this simplistic alogrithm will
|
||||
// likely be too slow.
|
||||
foreach (const Containment *other, corona->containments()) {
|
||||
if (other == q ||
|
||||
!other->d->isPanelContainment() ||
|
||||
horiz != (other->formFactor() == Plasma::Horizontal)) {
|
||||
// only line up with panels of the same orientation
|
||||
continue;
|
||||
}
|
||||
|
||||
if (horiz) {
|
||||
qreal y = other->pos().y();
|
||||
if (y < bottom) {
|
||||
lastHeight = other->size().height();
|
||||
bottom = y;
|
||||
}
|
||||
} else {
|
||||
qreal width = other->size().width();
|
||||
qreal x = other->pos().x() + width;
|
||||
if (x > bottom) {
|
||||
lastHeight = width;
|
||||
bottom = x + lastHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// give a space equal to the height again of the last item so there is
|
||||
// room to grow.
|
||||
QPointF newPos;
|
||||
if (horiz) {
|
||||
bottom -= lastHeight + INTER_CONTAINMENT_MARGIN;
|
||||
//TODO: fix x position for non-flush-left panels
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "moved to" << QPointF(0, bottom - q->size().height());
|
||||
#endif
|
||||
newPos = QPointF(0, bottom - q->size().height());
|
||||
} else {
|
||||
bottom += lastHeight + INTER_CONTAINMENT_MARGIN;
|
||||
//TODO: fix y position for non-flush-top panels
|
||||
#ifndef NDEBUG
|
||||
kDebug() << "moved to" << QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
||||
#endif
|
||||
newPos = QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
||||
}
|
||||
|
||||
return newPos;
|
||||
}
|
||||
|
||||
|
||||
bool ContainmentPrivate::prepareContainmentActions(const QString &trigger, const QPoint &screenPos, KMenu *menu)
|
||||
{
|
||||
ContainmentActions *plugin = actionPlugins()->value(trigger);
|
||||
|
@ -21,6 +21,7 @@
|
||||
#ifndef CONTAINMENT_P_H
|
||||
#define CONTAINMENT_P_H
|
||||
|
||||
#include <kactioncollection.h>
|
||||
#include <kmenu.h>
|
||||
|
||||
#include "plasma.h"
|
||||
@ -28,7 +29,6 @@
|
||||
#include "corona.h"
|
||||
|
||||
static const int INTER_CONTAINMENT_MARGIN = 6;
|
||||
static const int TOOLBOX_MARGIN = 150;
|
||||
static const int CONTAINMENT_COLUMNS = 2;
|
||||
static const int VERTICAL_STACKING_OFFSET = 10000;
|
||||
|
||||
@ -44,7 +44,6 @@ namespace Plasma
|
||||
|
||||
class AccessAppletJob;
|
||||
class Containment;
|
||||
class AbstractToolBox;
|
||||
|
||||
class ContainmentPrivate
|
||||
{
|
||||
@ -79,9 +78,6 @@ public:
|
||||
dropMenus.clear();
|
||||
}
|
||||
|
||||
void createToolBox();
|
||||
void positionToolBox();
|
||||
void updateToolBoxVisibility();
|
||||
void triggerShowAddWidgets();
|
||||
void requestConfiguration();
|
||||
void checkStatus(Plasma::ItemStatus status);
|
||||
@ -97,10 +93,7 @@ public:
|
||||
void initApplets();
|
||||
void checkContainmentFurniture();
|
||||
bool regionIsEmpty(const QRectF ®ion, Applet *ignoredApplet=0) const;
|
||||
void positionPanel(bool force = false);
|
||||
bool isPanelContainment() const;
|
||||
QPointF preferredPos(Corona *corona) const;
|
||||
QPointF preferredPanelPos(Corona *corona) const;
|
||||
void setLockToolText();
|
||||
void appletDeleted(Applet*);
|
||||
void appletAppeared(Applet*);
|
||||
@ -131,11 +124,10 @@ public:
|
||||
|
||||
/**
|
||||
* Handles dropped/pasted mimetype data
|
||||
* @param scenePos scene-relative position
|
||||
* @param screenPos screen-relative position
|
||||
* @param dropEvent the drop event (if null, the clipboard is used instead)
|
||||
*/
|
||||
void dropData(QPointF scenePos, QPoint screenPos, QGraphicsSceneDragDropEvent *dropEvent = 0);
|
||||
void dropData(QPoint screenPos, QDropEvent *dropEvent = 0);
|
||||
|
||||
/**
|
||||
* inits the containmentactions if necessary
|
||||
@ -171,7 +163,7 @@ public:
|
||||
int lastScreen;
|
||||
int desktop;
|
||||
int lastDesktop;
|
||||
QWeakPointer<AbstractToolBox> toolBox;
|
||||
QList<QAction *> toolBoxActions;
|
||||
QString activityId;
|
||||
Containment::Type type;
|
||||
QHash<KJob*, QPointF> dropPoints;
|
||||
|
@ -25,17 +25,18 @@
|
||||
#include <kactioncollection.h>
|
||||
|
||||
class KShortcutsDialog;
|
||||
class QGraphicsWidget;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class Containment;
|
||||
|
||||
class CoronaBasePrivate
|
||||
class CoronaPrivate
|
||||
{
|
||||
public:
|
||||
CoronaBasePrivate(CoronaBase *corona);
|
||||
~CoronaBasePrivate();
|
||||
CoronaPrivate(Corona *corona);
|
||||
~CoronaPrivate();
|
||||
|
||||
void init();
|
||||
void showShortcutConfig();
|
||||
@ -50,7 +51,7 @@ public:
|
||||
|
||||
static bool s_positioningContainments;
|
||||
|
||||
CoronaBase *q;
|
||||
Corona *q;
|
||||
ImmutabilityType immutability;
|
||||
QString mimetype;
|
||||
QString configName;
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2007 Petri Damsten <damu@iki.fi>
|
||||
*
|
||||
* 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_METER_PRIVATE_H
|
||||
#define PLASMA_METER_PRIVATE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QRectF;
|
||||
class QString;
|
||||
class QPainter;
|
||||
class QPropertyAnimation;
|
||||
|
||||
namespace Plasma {
|
||||
|
||||
class Meter;
|
||||
class FrameSvg;
|
||||
|
||||
class MeterPrivate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int meterValue READ meterValue WRITE setMeterValue)
|
||||
|
||||
public:
|
||||
MeterPrivate(Meter *m);
|
||||
void progressChanged(int progress);
|
||||
void paint(QPainter *p, const QString &elementID);
|
||||
void text(QPainter *p, int index);
|
||||
QRectF barRect();
|
||||
void paintBackground(QPainter *p);
|
||||
void paintBar(QPainter *p, const QString &prefix);
|
||||
void paintForeground(QPainter *p);
|
||||
void setSizePolicyAndPreferredSize();
|
||||
void setMeterValue(int value);
|
||||
int meterValue() const;
|
||||
|
||||
int minimum;
|
||||
int maximum;
|
||||
int value;
|
||||
int targetValue;
|
||||
QStringList labels;
|
||||
QList<Qt::Alignment> alignments;
|
||||
QList<QColor> colors;
|
||||
QList<QFont> fonts;
|
||||
QString svg;
|
||||
Meter::MeterType meterType;
|
||||
Plasma::FrameSvg *image;
|
||||
int minrotate;
|
||||
int maxrotate;
|
||||
Meter *meter;
|
||||
int movementId;
|
||||
QPropertyAnimation *animation;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "servicejob.h"
|
||||
#include "service.h"
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
#include <QMap>
|
||||
#include <QMultiHash>
|
||||
#include <QWidget>
|
||||
@ -95,7 +94,7 @@ public:
|
||||
|
||||
void associatedWidgetDestroyed(QObject *obj);
|
||||
|
||||
void associatedGraphicsWidgetDestroyed(QObject *obj);
|
||||
void associatedItemDestroyed(QObject *obj);
|
||||
|
||||
void publish(AnnouncementMethods methods, const QString &name,
|
||||
const KPluginInfo &metadata = KPluginInfo());
|
||||
@ -115,7 +114,7 @@ public:
|
||||
DNSSD::PublicService *publicService;
|
||||
ServiceProvider *serviceProvider;
|
||||
QMultiHash<QWidget *, QString> associatedWidgets;
|
||||
QMultiHash<QGraphicsObject *, QString> associatedGraphicsWidgets;
|
||||
QMultiHash<QGraphicsObject *, QString> associatedItems;
|
||||
QSet<QString> disabledOperations;
|
||||
};
|
||||
|
||||
|
@ -1,85 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2011 by Aaron Seigo <aseigo@kde.org> *
|
||||
* *
|
||||
* 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. *
|
||||
*******************************************************************************/
|
||||
|
||||
#include "themedwidgetinterface_p.h"
|
||||
|
||||
#include "theme.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
PaletteHelper *PaletteHelper::s_paletteHelper = 0;
|
||||
|
||||
PaletteHelper::PaletteHelper()
|
||||
: QObject()
|
||||
{
|
||||
generatePalettes();
|
||||
connect(Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(generatePalettes()));
|
||||
connect(KGlobalSettings::self(), SIGNAL(kdisplayPaletteChanged()), this, SLOT(generatePalettes()));
|
||||
}
|
||||
|
||||
PaletteHelper *PaletteHelper::self()
|
||||
{
|
||||
if (!s_paletteHelper) {
|
||||
s_paletteHelper = new PaletteHelper;
|
||||
}
|
||||
|
||||
return s_paletteHelper;
|
||||
}
|
||||
|
||||
void PaletteHelper::generatePalettes()
|
||||
{
|
||||
Theme *theme = Theme::defaultTheme();
|
||||
|
||||
QColor color = theme->color(Theme::TextColor);
|
||||
palette = qApp->palette();
|
||||
palette.setColor(QPalette::Normal, QPalette::WindowText, color);
|
||||
palette.setColor(QPalette::Inactive, QPalette::WindowText, color);
|
||||
|
||||
palette.setColor(QPalette::Normal, QPalette::Link, theme->color(Theme::LinkColor));
|
||||
palette.setColor(QPalette::Normal, QPalette::LinkVisited, theme->color(Theme::VisitedLinkColor));
|
||||
|
||||
qreal alpha = color.alphaF();
|
||||
color.setAlphaF(0.6);
|
||||
palette.setColor(QPalette::Disabled, QPalette::WindowText, color);
|
||||
color.setAlphaF(alpha);
|
||||
|
||||
palette.setColor(QPalette::Normal, QPalette::Text, color);
|
||||
palette.setColor(QPalette::Inactive, QPalette::Text, color);
|
||||
|
||||
const QColor buttonColor = Theme::defaultTheme()->color(Theme::ButtonTextColor);
|
||||
palette.setColor(QPalette::Normal, QPalette::ButtonText, buttonColor);
|
||||
palette.setColor(QPalette::Inactive, QPalette::ButtonText, buttonColor);
|
||||
|
||||
//FIXME: hardcoded colors .. looks incorrect
|
||||
palette.setColor(QPalette::Normal, QPalette::Base, QColor(0,0,0,0));
|
||||
palette.setColor(QPalette::Inactive, QPalette::Base, QColor(0,0,0,0));
|
||||
|
||||
buttonPalette = palette;
|
||||
buttonPalette.setColor(QPalette::Normal, QPalette::Text, buttonColor);
|
||||
buttonPalette.setColor(QPalette::Inactive, QPalette::Text, buttonColor);
|
||||
|
||||
emit palettesUpdated();
|
||||
}
|
||||
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#include "moc_themedwidgetinterface_p.cpp"
|
||||
|
@ -1,131 +0,0 @@
|
||||
/******************************************************************************
|
||||
* Copyright 2009 by Aaron Seigo <aseigo@kde.org> *
|
||||
* *
|
||||
* 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 THEMEDWIDGETINTERFACE_P_H
|
||||
#define THEMEDWIDGETINTERFACE_P_H
|
||||
|
||||
#include "kglobalsettings.h"
|
||||
#include <QApplication>
|
||||
|
||||
#include "theme.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class PaletteHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static PaletteHelper *self();
|
||||
|
||||
public Q_SLOTS:
|
||||
void generatePalettes();
|
||||
|
||||
Q_SIGNALS:
|
||||
void palettesUpdated();
|
||||
|
||||
public:
|
||||
QPalette palette;
|
||||
QPalette buttonPalette;
|
||||
|
||||
private:
|
||||
PaletteHelper();
|
||||
static PaletteHelper *s_paletteHelper;
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class ThemedWidgetInterface
|
||||
{
|
||||
public:
|
||||
ThemedWidgetInterface(T *publicClass)
|
||||
: q(publicClass),
|
||||
customPalette(false),
|
||||
customFont(false),
|
||||
buttonColorForText(false),
|
||||
internalPaletteChange(false)
|
||||
{
|
||||
QObject::connect(PaletteHelper::self(), SIGNAL(palettesUpdated()), q, SLOT(setPalette()));
|
||||
}
|
||||
|
||||
void initTheming()
|
||||
{
|
||||
customPalette = false;
|
||||
customFont = false;
|
||||
setPalette();
|
||||
}
|
||||
|
||||
void setPalette()
|
||||
{
|
||||
if (!customPalette) {
|
||||
internalPaletteChange = true;
|
||||
q->setPalette((buttonColorForText ? PaletteHelper::self()->buttonPalette
|
||||
: PaletteHelper::self()->palette));
|
||||
internalPaletteChange = false;
|
||||
}
|
||||
|
||||
if (!customFont) {
|
||||
q->setFont(Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont));
|
||||
customFont = false;
|
||||
}
|
||||
}
|
||||
|
||||
void changeEvent(QEvent *event)
|
||||
{
|
||||
switch (event->type()) {
|
||||
case QEvent::FontChange:
|
||||
customFont = q->font() != QApplication::font();
|
||||
break;
|
||||
|
||||
case QEvent::PaletteChange:
|
||||
if (!internalPaletteChange &&
|
||||
q->palette() != (buttonColorForText ? PaletteHelper::self()->buttonPalette : PaletteHelper::self()->palette)) {
|
||||
customPalette = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setWidget(QWidget *widget)
|
||||
{
|
||||
internalPaletteChange = true;
|
||||
q->setWidget(widget);
|
||||
internalPaletteChange = false;
|
||||
}
|
||||
|
||||
void event(QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::Show) {
|
||||
customFont = q->font() != QApplication::font();
|
||||
}
|
||||
}
|
||||
|
||||
T *q;
|
||||
bool customPalette : 1;
|
||||
bool customFont : 1;
|
||||
bool buttonColorForText : 1;
|
||||
bool internalPaletteChange : 1;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
#endif
|
||||
|
@ -86,17 +86,6 @@ QList<QAction*> AppletScript::contextualActions()
|
||||
return QList<QAction*>();
|
||||
}
|
||||
|
||||
QPainterPath AppletScript::shape() const
|
||||
{
|
||||
if (applet()) {
|
||||
QPainterPath path;
|
||||
path.addRect(applet()->boundingRect());
|
||||
return path;
|
||||
}
|
||||
|
||||
return QPainterPath();
|
||||
}
|
||||
|
||||
void AppletScript::setHasConfigurationInterface(bool hasInterface)
|
||||
{
|
||||
if (applet()) {
|
||||
@ -157,28 +146,6 @@ void AppletScript::showMessage(const QIcon &icon, const QString &message, const
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::registerAsDragHandle(QGraphicsItem *item)
|
||||
{
|
||||
if (applet()) {
|
||||
applet()->registerAsDragHandle(item);
|
||||
}
|
||||
}
|
||||
|
||||
void AppletScript::unregisterAsDragHandle(QGraphicsItem *item)
|
||||
{
|
||||
if (applet()) {
|
||||
applet()->unregisterAsDragHandle(item);
|
||||
}
|
||||
}
|
||||
|
||||
bool AppletScript::isRegisteredAsDragHandle(QGraphicsItem *item)
|
||||
{
|
||||
if (applet()) {
|
||||
return applet()->isRegisteredAsDragHandle(item);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AppletScript::configChanged()
|
||||
{
|
||||
}
|
||||
|
@ -110,11 +110,6 @@ public:
|
||||
*/
|
||||
virtual QList<QAction*> contextualActions();
|
||||
|
||||
/**
|
||||
* Returns the shape of the widget, defaults to the bounding rect
|
||||
*/
|
||||
virtual QPainterPath shape() const;
|
||||
|
||||
/**
|
||||
* Sets whether or not this script has a configuration interface or not
|
||||
*
|
||||
@ -230,21 +225,6 @@ protected:
|
||||
*/
|
||||
void showMessage(const QIcon &icon, const QString &message, const MessageButtons buttons);
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void registerAsDragHandle(QGraphicsItem *item);
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
void unregisterAsDragHandle(QGraphicsItem *item);
|
||||
|
||||
/**
|
||||
* @see Applet
|
||||
*/
|
||||
bool isRegisteredAsDragHandle(QGraphicsItem *item);
|
||||
|
||||
private:
|
||||
friend class Applet;
|
||||
friend class PopupApplet;
|
||||
|
@ -94,22 +94,22 @@ QWidget *WallpaperScript::createConfigurationInterface(QWidget *parent)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WallpaperScript::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
void WallpaperScript::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
}
|
||||
|
||||
void WallpaperScript::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
void WallpaperScript::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
}
|
||||
|
||||
void WallpaperScript::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
void WallpaperScript::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
}
|
||||
|
||||
void WallpaperScript::wheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
void WallpaperScript::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public:
|
||||
*
|
||||
* @param event the mouse event object
|
||||
*/
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||
|
||||
/**
|
||||
* Mouse press event. To prevent further propagation of the even,
|
||||
@ -118,7 +118,7 @@ public:
|
||||
*
|
||||
* @param event the mouse event object
|
||||
*/
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mousePressEvent(QMouseEvent *event);
|
||||
|
||||
/**
|
||||
* Mouse release event. To prevent further propagation of the event,
|
||||
@ -126,7 +126,7 @@ public:
|
||||
*
|
||||
* @param event the mouse event object
|
||||
*/
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
/**
|
||||
* Mouse wheel event. To prevent further propagation of the event,
|
||||
@ -134,7 +134,7 @@ public:
|
||||
*
|
||||
* @param event the wheel event object
|
||||
*/
|
||||
virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
|
||||
virtual void wheelEvent(QWheelEvent *event);
|
||||
|
||||
/**
|
||||
* Adds urls (e.g. from a drop)
|
||||
|
52
service.cpp
52
service.cpp
@ -24,7 +24,7 @@
|
||||
#include "config-plasma.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QGraphicsWidget>
|
||||
#include <QGraphicsObject>
|
||||
#include <QTimer>
|
||||
|
||||
#include <kdebug.h>
|
||||
@ -76,9 +76,9 @@ void ServicePrivate::associatedWidgetDestroyed(QObject *obj)
|
||||
associatedWidgets.remove(static_cast<QWidget*>(obj));
|
||||
}
|
||||
|
||||
void ServicePrivate::associatedGraphicsWidgetDestroyed(QObject *obj)
|
||||
void ServicePrivate::associatedItemDestroyed(QObject *obj)
|
||||
{
|
||||
associatedGraphicsWidgets.remove(static_cast<QGraphicsObject*>(obj));
|
||||
associatedItems.remove(static_cast<QGraphicsObject*>(obj));
|
||||
}
|
||||
|
||||
void ServicePrivate::publish(AnnouncementMethods methods, const QString &name, const KPluginInfo &metadata)
|
||||
@ -252,40 +252,6 @@ ServiceJob *Service::startOperationCall(const KConfigGroup &description, QObject
|
||||
return job;
|
||||
}
|
||||
|
||||
void Service::associateWidget(QWidget *widget, const QString &operation)
|
||||
{
|
||||
if (!widget) {
|
||||
return;
|
||||
}
|
||||
|
||||
disassociateWidget(widget);
|
||||
d->associatedWidgets.insert(widget, operation);
|
||||
connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(associatedWidgetDestroyed(QObject*)));
|
||||
|
||||
widget->setEnabled(!d->disabledOperations.contains(operation));
|
||||
}
|
||||
|
||||
void Service::disassociateWidget(QWidget *widget)
|
||||
{
|
||||
if (!widget) {
|
||||
return;
|
||||
}
|
||||
|
||||
disconnect(widget, SIGNAL(destroyed(QObject*)),
|
||||
this, SLOT(associatedWidgetDestroyed(QObject*)));
|
||||
d->associatedWidgets.remove(widget);
|
||||
}
|
||||
|
||||
void Service::associateWidget(QGraphicsWidget *widget, const QString &operation)
|
||||
{
|
||||
associateItem(widget, operation);
|
||||
}
|
||||
|
||||
void Service::disassociateWidget(QGraphicsWidget *widget)
|
||||
{
|
||||
disassociateItem(widget);
|
||||
}
|
||||
|
||||
void Service::associateItem(QGraphicsObject *widget, const QString &operation)
|
||||
{
|
||||
if (!widget) {
|
||||
@ -293,9 +259,9 @@ void Service::associateItem(QGraphicsObject *widget, const QString &operation)
|
||||
}
|
||||
|
||||
disassociateItem(widget);
|
||||
d->associatedGraphicsWidgets.insert(widget, operation);
|
||||
d->associatedItems.insert(widget, operation);
|
||||
connect(widget, SIGNAL(destroyed(QObject*)),
|
||||
this, SLOT(associatedGraphicsWidgetDestroyed(QObject*)));
|
||||
this, SLOT(associatedItemDestroyed(QObject*)));
|
||||
|
||||
widget->setEnabled(!d->disabledOperations.contains(operation));
|
||||
}
|
||||
@ -307,8 +273,8 @@ void Service::disassociateItem(QGraphicsObject *widget)
|
||||
}
|
||||
|
||||
disconnect(widget, SIGNAL(destroyed(QObject*)),
|
||||
this, SLOT(associatedGraphicsWidgetDestroyed(QObject*)));
|
||||
d->associatedGraphicsWidgets.remove(widget);
|
||||
this, SLOT(associatedItemDestroyed(QObject*)));
|
||||
d->associatedItems.remove(widget);
|
||||
}
|
||||
|
||||
QString Service::name() const
|
||||
@ -355,7 +321,7 @@ void Service::setOperationEnabled(const QString &operation, bool enable)
|
||||
}
|
||||
|
||||
{
|
||||
QHashIterator<QGraphicsObject *, QString> it(d->associatedGraphicsWidgets);
|
||||
QHashIterator<QGraphicsObject *, QString> it(d->associatedItems);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
if (it.value() == operation) {
|
||||
@ -392,7 +358,7 @@ void Service::setOperationsScheme(QIODevice *xml)
|
||||
}
|
||||
|
||||
{
|
||||
QHashIterator<QGraphicsObject *, QString> it(d->associatedGraphicsWidgets);
|
||||
QHashIterator<QGraphicsObject *, QString> it(d->associatedItems);
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
it.key()->setEnabled(d->config->hasGroup(it.value()));
|
||||
|
40
service.h
40
service.h
@ -29,10 +29,10 @@
|
||||
#include <plasma/plasma_export.h>
|
||||
#include <plasma/plasma.h>
|
||||
|
||||
class QGraphicsObject;
|
||||
class QIODevice;
|
||||
class QWidget;
|
||||
class QUrl;
|
||||
class QGraphicsObject;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
@ -156,42 +156,6 @@ public:
|
||||
*/
|
||||
Q_INVOKABLE QString name() const;
|
||||
|
||||
/**
|
||||
* Assoicates a widget with an operation, which allows the service to
|
||||
* automatically manage, for example, the enabled state of a widget.
|
||||
*
|
||||
* This will remove any previous associations the widget had with
|
||||
* operations on this engine.
|
||||
*
|
||||
* @param widget the QWidget to associate with the service
|
||||
* @param operation the operation to associate the widget with
|
||||
*/
|
||||
Q_INVOKABLE void associateWidget(QWidget *widget, const QString &operation);
|
||||
|
||||
/**
|
||||
* Disassociates a widget if it has been associated with an operation
|
||||
* on this service.
|
||||
*
|
||||
* This will not change the enabled state of the widget.
|
||||
*
|
||||
* @param widget the QWidget to disassociate.
|
||||
*/
|
||||
Q_INVOKABLE void disassociateWidget(QWidget *widget);
|
||||
|
||||
/**
|
||||
* This method only exists to maintain binary compatibility.
|
||||
*
|
||||
* @see associateItem
|
||||
*/
|
||||
Q_INVOKABLE void associateWidget(QGraphicsWidget *widget, const QString &operation);
|
||||
|
||||
/**
|
||||
* This method only exists to maintain binary compatibility.
|
||||
*
|
||||
* @see disassociateItem
|
||||
*/
|
||||
Q_INVOKABLE void disassociateWidget(QGraphicsWidget *widget);
|
||||
|
||||
/**
|
||||
* Associates a graphics item with an operation, which allows the service to
|
||||
* automatically manage, for example, the enabled state of the item.
|
||||
@ -289,7 +253,7 @@ protected:
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void associatedWidgetDestroyed(QObject *))
|
||||
Q_PRIVATE_SLOT(d, void associatedGraphicsWidgetDestroyed(QObject *))
|
||||
Q_PRIVATE_SLOT(d, void associatedItemDestroyed(QObject *))
|
||||
|
||||
ServicePrivate * const d;
|
||||
|
||||
|
@ -342,28 +342,28 @@ QWidget *Wallpaper::createConfigurationInterface(QWidget *parent)
|
||||
}
|
||||
}
|
||||
|
||||
void Wallpaper::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||
void Wallpaper::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (d->script) {
|
||||
return d->script->mouseMoveEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Wallpaper::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
void Wallpaper::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (d->script) {
|
||||
return d->script->mousePressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Wallpaper::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
void Wallpaper::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (d->script) {
|
||||
return d->script->mouseReleaseEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Wallpaper::wheelEvent(QGraphicsSceneWheelEvent *event)
|
||||
void Wallpaper::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (d->script) {
|
||||
return d->script->wheelEvent(event);
|
||||
|
13
wallpaper.h
13
wallpaper.h
@ -21,12 +21,17 @@
|
||||
#ifndef PLASMA_WALLPAPER_H
|
||||
#define PLASMA_WALLPAPER_H
|
||||
|
||||
#include <QColor>
|
||||
|
||||
#include <kplugininfo.h>
|
||||
|
||||
#include <plasma/package.h>
|
||||
#include <plasma/plasma.h>
|
||||
#include <plasma/version.h>
|
||||
|
||||
class QMouseEvent;
|
||||
class QWheelEvent;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
@ -249,7 +254,7 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
||||
*
|
||||
* @param event the mouse event object
|
||||
*/
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||
|
||||
/**
|
||||
* Mouse press event. To prevent further propagation of the even,
|
||||
@ -257,7 +262,7 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
||||
*
|
||||
* @param event the mouse event object
|
||||
*/
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mousePressEvent(QMouseEvent *event);
|
||||
|
||||
/**
|
||||
* Mouse release event. To prevent further propagation of the event,
|
||||
@ -265,7 +270,7 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
||||
*
|
||||
* @param event the mouse event object
|
||||
*/
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event);
|
||||
|
||||
/**
|
||||
* Mouse wheel event. To prevent further propagation of the event,
|
||||
@ -273,7 +278,7 @@ class PLASMA_EXPORT Wallpaper : public QObject
|
||||
*
|
||||
* @param event the wheel event object
|
||||
*/
|
||||
virtual void wheelEvent(QGraphicsSceneWheelEvent *event);
|
||||
virtual void wheelEvent(QWheelEvent *event);
|
||||
|
||||
/**
|
||||
* Loads the given DataEngine
|
||||
|
@ -1,222 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "busywidget.h"
|
||||
|
||||
//Qt
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
#include <QGraphicsSceneResizeEvent>
|
||||
#include <QTextOption>
|
||||
|
||||
//Plasma
|
||||
#include "plasma/theme.h"
|
||||
#include "plasma/svg.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class BusyWidgetPrivate
|
||||
{
|
||||
public:
|
||||
BusyWidgetPrivate()
|
||||
: svg(0),
|
||||
timerId(0),
|
||||
rotationAngle(0),
|
||||
rotation(0),
|
||||
running(true)
|
||||
{
|
||||
}
|
||||
|
||||
~BusyWidgetPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void themeChanged()
|
||||
{
|
||||
frames.clear();
|
||||
rotationAngle = svg->elementSize("hint-rotation-angle").width();
|
||||
|
||||
//use an angle near to rotationAngle but that it fits an integer number of times in 360
|
||||
int nFrames = 360/rotationAngle;
|
||||
rotationAngle = 360/nFrames;
|
||||
}
|
||||
|
||||
Svg *svg;
|
||||
QString styleSheet;
|
||||
int timerId;
|
||||
QHash<int, QPixmap> frames;
|
||||
qreal rotationAngle;
|
||||
qreal rotation;
|
||||
bool running;
|
||||
QString label;
|
||||
};
|
||||
|
||||
|
||||
BusyWidget::BusyWidget(QGraphicsWidget *parent)
|
||||
: QGraphicsWidget(parent),
|
||||
d(new BusyWidgetPrivate)
|
||||
{
|
||||
d->svg = new Plasma::Svg(this);
|
||||
d->svg->setImagePath("widgets/busywidget");
|
||||
d->svg->setContainsMultipleImages(true);
|
||||
d->themeChanged();
|
||||
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(themeChanged()));
|
||||
}
|
||||
|
||||
BusyWidget::~BusyWidget()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void BusyWidget::setRunning(bool running)
|
||||
{
|
||||
if (running && !d->timerId && isVisible()) {
|
||||
d->timerId = startTimer(150);
|
||||
} else if (!running && d->timerId) {
|
||||
killTimer(d->timerId);
|
||||
d->timerId = 0;
|
||||
}
|
||||
d->running = running;
|
||||
}
|
||||
|
||||
bool BusyWidget::isRunning() const
|
||||
{
|
||||
return d->running;
|
||||
}
|
||||
|
||||
void BusyWidget::setLabel(const QString &label)
|
||||
{
|
||||
d->label = label;
|
||||
update();
|
||||
}
|
||||
|
||||
QString BusyWidget::label() const
|
||||
{
|
||||
return d->label;
|
||||
}
|
||||
|
||||
void BusyWidget::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
if (event->timerId() != d->timerId) {
|
||||
QObject::timerEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
d->rotation += d->rotationAngle;
|
||||
|
||||
qreal overflow = d->rotation - 360;
|
||||
if ( overflow > 0) {
|
||||
d->rotation = overflow;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void BusyWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
|
||||
int intRotation = int(d->rotation);
|
||||
|
||||
QRectF spinnerRect(QPoint(0, 0), QSize(qMin(size().width(), size().height()), qMin(size().width(), size().height())));
|
||||
spinnerRect.moveCenter(boundingRect().center());
|
||||
|
||||
if (!isEnabled()) {
|
||||
painter->setOpacity(painter->opacity() / 2);
|
||||
}
|
||||
|
||||
if (!d->running && d->svg->hasElement("paused")) {
|
||||
d->svg->paint(painter, spinnerRect, "paused");
|
||||
} else {
|
||||
if (!d->frames[intRotation]) {
|
||||
QPointF translatedPos(spinnerRect.width()/2, spinnerRect.height()/2);
|
||||
|
||||
d->frames[intRotation] = QPixmap(spinnerRect.size().toSize());
|
||||
d->frames[intRotation].fill(Qt::transparent);
|
||||
|
||||
QPainter buffPainter(&d->frames[intRotation]);
|
||||
|
||||
buffPainter.setRenderHints(QPainter::SmoothPixmapTransform);
|
||||
buffPainter.translate(translatedPos);
|
||||
|
||||
if (d->svg->hasElement("busywidget-shadow")) {
|
||||
buffPainter.save();
|
||||
buffPainter.translate(1,1);
|
||||
buffPainter.rotate(intRotation);
|
||||
d->svg->paint(&buffPainter, QRectF(-translatedPos.toPoint(), spinnerRect.size()), "busywidget-shadow");
|
||||
buffPainter.restore();
|
||||
}
|
||||
|
||||
buffPainter.rotate(intRotation);
|
||||
d->svg->paint(&buffPainter, QRectF(-translatedPos.toPoint(), spinnerRect.size()), "busywidget");
|
||||
}
|
||||
|
||||
painter->drawPixmap(spinnerRect.topLeft().toPoint(), d->frames[intRotation]);
|
||||
}
|
||||
|
||||
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::TextColor));
|
||||
Qt::Alignment align(Qt::AlignVCenter | Qt::AlignHCenter);
|
||||
painter->drawText(boundingRect(), d->label, QTextOption(align));
|
||||
}
|
||||
|
||||
void BusyWidget::showEvent(QShowEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (d->running) {
|
||||
d->timerId = startTimer(150);
|
||||
}
|
||||
}
|
||||
|
||||
void BusyWidget::hideEvent(QHideEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
if (d->timerId) {
|
||||
killTimer(d->timerId);
|
||||
}
|
||||
|
||||
d->timerId = 0;
|
||||
}
|
||||
|
||||
void BusyWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
d->frames.clear();
|
||||
}
|
||||
|
||||
void BusyWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
event->setAccepted(true);
|
||||
}
|
||||
|
||||
void BusyWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
if ((event->button() & Qt::LeftButton) ||
|
||||
(event->buttons() & Qt::LeftButton)) {
|
||||
emit clicked();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
|
||||
|
||||
|
||||
#include "moc_busywidget.cpp"
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 Marco Martin <notmart@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_BUSYWIDGET_H
|
||||
#define PLASMA_BUSYWIDGET_H
|
||||
|
||||
#include <QGraphicsWidget>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QFrame;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class BusyWidgetPrivate;
|
||||
|
||||
/**
|
||||
* @class BusyWidget plasma/widgets/spinner.h <Plasma/Widgets/BusyWidget>
|
||||
*
|
||||
* @short A widget that provides a waiting spinner
|
||||
*
|
||||
* A simple spinner widget that can be used to represent a wait of unknown length
|
||||
*/
|
||||
class PLASMA_EXPORT BusyWidget : public QGraphicsWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool running READ isRunning WRITE setRunning)
|
||||
Q_PROPERTY(QString label READ label WRITE setLabel)
|
||||
|
||||
public:
|
||||
/**
|
||||
* Constructs a new BusyWidget
|
||||
*
|
||||
* @param parent the parent of this widget
|
||||
*/
|
||||
explicit BusyWidget(QGraphicsWidget *parent = 0);
|
||||
~BusyWidget();
|
||||
|
||||
/**
|
||||
* @param running whether or not the spinner has to be animated. defaults to true.
|
||||
*/
|
||||
void setRunning(bool running);
|
||||
|
||||
/**
|
||||
* @return whether or not the spinner is animated.
|
||||
*/
|
||||
bool isRunning() const;
|
||||
|
||||
/**
|
||||
* @param label a string to be shown in front of the icon.
|
||||
*/
|
||||
void setLabel(const QString &label);
|
||||
|
||||
/**
|
||||
* @param label the string that is shown in front of the icon.
|
||||
*/
|
||||
QString label() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget = 0);
|
||||
|
||||
void showEvent(QShowEvent *event);
|
||||
void hideEvent(QHideEvent *event);
|
||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||
|
||||
|
||||
protected Q_SLOTS:
|
||||
void timerEvent(QTimerEvent *event);
|
||||
|
||||
private:
|
||||
BusyWidgetPrivate * const d;
|
||||
|
||||
Q_PRIVATE_SLOT(d, void themeChanged())
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif // multiple inclusion guard
|
@ -1,188 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "checkbox.h"
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QPainter>
|
||||
#include <QDir>
|
||||
|
||||
#include <qmimedatabase.h>
|
||||
|
||||
#include "private/themedwidgetinterface_p.h"
|
||||
#include "svg.h"
|
||||
#include "theme.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class CheckBoxPrivate : public ThemedWidgetInterface<CheckBox>
|
||||
{
|
||||
public:
|
||||
CheckBoxPrivate(CheckBox *c)
|
||||
: ThemedWidgetInterface<CheckBox>(c),
|
||||
svg(0)
|
||||
{
|
||||
}
|
||||
|
||||
~CheckBoxPrivate()
|
||||
{
|
||||
delete svg;
|
||||
}
|
||||
|
||||
void setPixmap()
|
||||
{
|
||||
if (imagePath.isEmpty()) {
|
||||
delete svg;
|
||||
svg = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
QMimeDatabase db;
|
||||
QMimeType mime = db.mimeTypeForFile(absImagePath);
|
||||
QPixmap pm(q->size().toSize());
|
||||
|
||||
if (mime.inherits("image/svg+xml") || mime.inherits("image/svg+xml-compressed")) {
|
||||
if (!svg || svg->imagePath() != imagePath) {
|
||||
delete svg;
|
||||
svg = new Svg();
|
||||
svg->setImagePath(imagePath);
|
||||
QObject::connect(svg, SIGNAL(repaintNeeded()), q, SLOT(setPixmap()));
|
||||
}
|
||||
|
||||
QPainter p(&pm);
|
||||
svg->paint(&p, pm.rect());
|
||||
} else {
|
||||
delete svg;
|
||||
svg = 0;
|
||||
pm = QPixmap(absImagePath);
|
||||
}
|
||||
|
||||
static_cast<QCheckBox*>(q->widget())->setIcon(QIcon(pm));
|
||||
}
|
||||
|
||||
QString imagePath;
|
||||
QString absImagePath;
|
||||
Svg *svg;
|
||||
};
|
||||
|
||||
CheckBox::CheckBox(QGraphicsWidget *parent)
|
||||
: QGraphicsProxyWidget(parent),
|
||||
d(new CheckBoxPrivate(this))
|
||||
{
|
||||
QCheckBox *native = new QCheckBox;
|
||||
connect(native, SIGNAL(toggled(bool)), this, SIGNAL(toggled(bool)));
|
||||
d->setWidget(native);
|
||||
native->setWindowIcon(QIcon());
|
||||
native->setAttribute(Qt::WA_NoSystemBackground);
|
||||
|
||||
d->initTheming();
|
||||
}
|
||||
|
||||
CheckBox::~CheckBox()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
void CheckBox::setText(const QString &text)
|
||||
{
|
||||
static_cast<QCheckBox*>(widget())->setText(text);
|
||||
}
|
||||
|
||||
QString CheckBox::text() const
|
||||
{
|
||||
return static_cast<QCheckBox*>(widget())->text();
|
||||
}
|
||||
|
||||
void CheckBox::setImage(const QString &path)
|
||||
{
|
||||
if (d->imagePath == path) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete d->svg;
|
||||
d->svg = 0;
|
||||
d->imagePath = path;
|
||||
|
||||
bool absolutePath = !path.isEmpty() &&
|
||||
#ifdef Q_OS_WIN
|
||||
!QDir::isRelativePath(path)
|
||||
#else
|
||||
(path[0] == '/' || path.startsWith(QLatin1String(":/")))
|
||||
#endif
|
||||
;
|
||||
|
||||
if (absolutePath) {
|
||||
d->absImagePath = path;
|
||||
} else {
|
||||
//TODO: package support
|
||||
d->absImagePath = Theme::defaultTheme()->imagePath(path);
|
||||
}
|
||||
|
||||
d->setPixmap();
|
||||
}
|
||||
|
||||
QString CheckBox::image() const
|
||||
{
|
||||
return d->imagePath;
|
||||
}
|
||||
|
||||
void CheckBox::setStyleSheet(const QString &stylesheet)
|
||||
{
|
||||
widget()->setStyleSheet(stylesheet);
|
||||
}
|
||||
|
||||
QString CheckBox::styleSheet()
|
||||
{
|
||||
return widget()->styleSheet();
|
||||
}
|
||||
|
||||
QCheckBox *CheckBox::nativeWidget() const
|
||||
{
|
||||
return static_cast<QCheckBox*>(widget());
|
||||
}
|
||||
|
||||
void CheckBox::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
{
|
||||
d->setPixmap();
|
||||
QGraphicsProxyWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
void CheckBox::setChecked(bool checked)
|
||||
{
|
||||
static_cast<QCheckBox*>(widget())->setChecked(checked);
|
||||
}
|
||||
|
||||
bool CheckBox::isChecked() const
|
||||
{
|
||||
return static_cast<QCheckBox*>(widget())->isChecked();
|
||||
}
|
||||
|
||||
void CheckBox::changeEvent(QEvent *event)
|
||||
{
|
||||
d->changeEvent(event);
|
||||
QGraphicsProxyWidget::changeEvent(event);
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
|
||||
|
||||
|
||||
#include "moc_checkbox.cpp"
|
@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef PLASMA_CHECKBOX_H
|
||||
#define PLASMA_CHECKBOX_H
|
||||
|
||||
#include <QGraphicsProxyWidget>
|
||||
|
||||
#include <plasma/plasma_export.h>
|
||||
|
||||
class QCheckBox;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class CheckBoxPrivate;
|
||||
|
||||
/**
|
||||
* @class CheckBox plasma/widgets/checkbox.h <Plasma/Widgets/CheckBox>
|
||||
*
|
||||
* @short Provides a Plasma-themed checkbox.
|
||||
*/
|
||||
class PLASMA_EXPORT CheckBox : public QGraphicsProxyWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QGraphicsWidget *parentWidget READ parentWidget)
|
||||
Q_PROPERTY(QString text READ text WRITE setText)
|
||||
Q_PROPERTY(QString image READ image WRITE setImage)
|
||||
Q_PROPERTY(QString styleSheet READ styleSheet WRITE setStyleSheet)
|
||||
Q_PROPERTY(QCheckBox *nativeWidget READ nativeWidget)
|
||||
Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled)
|
||||
|
||||
public:
|
||||
explicit CheckBox(QGraphicsWidget *parent = 0);
|
||||
~CheckBox();
|
||||
|
||||
/**
|
||||
* Sets the display text for this CheckBox
|
||||
*
|
||||
* @param text the text to display; should be translated.
|
||||
*/
|
||||
void setText(const QString &text);
|
||||
|
||||
/**
|
||||
* @return the display text
|
||||
*/
|
||||
QString text() const;
|
||||
|
||||
/**
|
||||
* Sets the path to an image to display.
|
||||
*
|
||||
* @param path the path to the image; if a relative path, then a themed image will be loaded.
|
||||
*/
|
||||
void setImage(const QString &path);
|
||||
|
||||
/**
|
||||
* @return the image path being displayed currently, or an empty string if none.
|
||||
*/
|
||||
QString image() const;
|
||||
|
||||
/**
|
||||
* Sets the stylesheet used to control the visual display of this CheckBox
|
||||
*
|
||||
* @param stylesheet a CSS string
|
||||
*/
|
||||
void setStyleSheet(const QString &stylesheet);
|
||||
|
||||
/**
|
||||
* @return the stylesheet currently used with this widget
|
||||
*/
|
||||
QString styleSheet();
|
||||
|
||||
/**
|
||||
* @return the native widget wrapped by this CheckBox
|
||||
*/
|
||||
QCheckBox *nativeWidget() const;
|
||||
|
||||
/**
|
||||
* Sets the checked state.
|
||||
*
|
||||
* @param checked true if checked, false if not
|
||||
*/
|
||||
void setChecked(bool checked);
|
||||
|
||||
/**
|
||||
* @return the checked state
|
||||
*/
|
||||
bool isChecked() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void toggled(bool);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||
void changeEvent(QEvent *event);
|
||||
|
||||
private:
|
||||
Q_PRIVATE_SLOT(d, void setPalette())
|
||||
Q_PRIVATE_SLOT(d, void setPixmap())
|
||||
|
||||
CheckBoxPrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
#endif // multiple inclusion guard
|
@ -1,356 +0,0 @@
|
||||
/*
|
||||
* Copyright 2008 Aaron Seigo <aseigo@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "combobox.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include <kcombobox.h>
|
||||
#include <kiconeffect.h>
|
||||
#include <kiconloader.h>
|
||||
|
||||
#include "applet.h"
|
||||
#include "framesvg.h"
|
||||
#include "graphicsview/private/style_p.h"
|
||||
#include "graphicsview/private/focusindicator_p.h"
|
||||
#include "private/themedwidgetinterface_p.h"
|
||||
#include "theme.h"
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
|
||||
class ComboBoxPrivate : public ThemedWidgetInterface<ComboBox>
|
||||
{
|
||||
public:
|
||||
ComboBoxPrivate(ComboBox *comboBox)
|
||||
: ThemedWidgetInterface<ComboBox>(comboBox),
|
||||
background(0),
|
||||
underMouse(false)
|
||||
{
|
||||
}
|
||||
|
||||
~ComboBoxPrivate()
|
||||
{
|
||||
}
|
||||
|
||||
void syncActiveRect();
|
||||
void syncBorders();
|
||||
|
||||
FrameSvg *background;
|
||||
FrameSvg *lineEditBackground;
|
||||
FocusIndicator *focusIndicator;
|
||||
int animId;
|
||||
qreal opacity;
|
||||
QRectF activeRect;
|
||||
Style::Ptr style;
|
||||
bool underMouse;
|
||||
};
|
||||
|
||||
void ComboBoxPrivate::syncActiveRect()
|
||||
{
|
||||
background->setElementPrefix("normal");
|
||||
|
||||
qreal left, top, right, bottom;
|
||||
background->getMargins(left, top, right, bottom);
|
||||
|
||||
background->setElementPrefix("active");
|
||||
qreal activeLeft, activeTop, activeRight, activeBottom;
|
||||
background->getMargins(activeLeft, activeTop, activeRight, activeBottom);
|
||||
|
||||
activeRect = QRectF(QPointF(0, 0), q->size());
|
||||
activeRect.adjust(left - activeLeft, top - activeTop,
|
||||
-(right - activeRight), -(bottom - activeBottom));
|
||||
|
||||
background->setElementPrefix("normal");
|
||||
}
|
||||
|
||||
void ComboBoxPrivate::syncBorders()
|
||||
{
|
||||
//set margins from the normal element
|
||||
qreal left, top, right, bottom;
|
||||
|
||||
background->setElementPrefix("normal");
|
||||
background->getMargins(left, top, right, bottom);
|
||||
q->setContentsMargins(left, top, right, bottom);
|
||||
|
||||
//calc the rect for the over effect
|
||||
syncActiveRect();
|
||||
|
||||
if (customFont) {
|
||||
q->setFont(q->font());
|
||||
} else {
|
||||
q->setFont(Theme::defaultTheme()->font(Theme::DefaultFont));
|
||||
customFont = false;
|
||||
}
|
||||
|
||||
if (q->nativeWidget()->isEditable()) {
|
||||
focusIndicator->setFrameSvg(lineEditBackground);
|
||||
} else {
|
||||
focusIndicator->setFrameSvg(background);
|
||||
}
|
||||
focusIndicator->setFlag(QGraphicsItem::ItemStacksBehindParent, !q->nativeWidget()->isEditable() || !lineEditBackground->hasElement("hint-focus-over-base"));
|
||||
}
|
||||
|
||||
|
||||
ComboBox::ComboBox(QGraphicsWidget *parent)
|
||||
: QGraphicsProxyWidget(parent),
|
||||
d(new ComboBoxPrivate(this))
|
||||
{
|
||||
d->background = new FrameSvg(this);
|
||||
d->background->setImagePath("widgets/button");
|
||||
d->background->setCacheAllRenderedFrames(true);
|
||||
d->background->setElementPrefix("normal");
|
||||
d->lineEditBackground = new FrameSvg(this);
|
||||
d->lineEditBackground->setImagePath("widgets/lineedit");
|
||||
d->lineEditBackground->setCacheAllRenderedFrames(true);
|
||||
setZValue(900);
|
||||
|
||||
setAcceptHoverEvents(true);
|
||||
|
||||
d->style = Style::sharedStyle();
|
||||
|
||||
d->focusIndicator = new FocusIndicator(this, d->background);
|
||||
setNativeWidget(new KComboBox);
|
||||
connect(d->background, SIGNAL(repaintNeeded()), SLOT(syncBorders()));
|
||||
d->initTheming();
|
||||
}
|
||||
|
||||
ComboBox::~ComboBox()
|
||||
{
|
||||
delete d;
|
||||
Style::doneWithSharedStyle();
|
||||
}
|
||||
|
||||
QString ComboBox::text() const
|
||||
{
|
||||
return static_cast<KComboBox*>(widget())->currentText();
|
||||
}
|
||||
|
||||
void ComboBox::setStyleSheet(const QString &stylesheet)
|
||||
{
|
||||
widget()->setStyleSheet(stylesheet);
|
||||
}
|
||||
|
||||
QString ComboBox::styleSheet()
|
||||
{
|
||||
return widget()->styleSheet();
|
||||
}
|
||||
|
||||
void ComboBox::setNativeWidget(KComboBox *nativeWidget)
|
||||
{
|
||||
if (widget()) {
|
||||
widget()->deleteLater();
|
||||
}
|
||||
|
||||
connect(nativeWidget, SIGNAL(activated(QString)), this, SIGNAL(activated(QString)));
|
||||
connect(nativeWidget, SIGNAL(currentIndexChanged(int)),
|
||||
this, SIGNAL(currentIndexChanged(int)));
|
||||
connect(nativeWidget, SIGNAL(currentIndexChanged(QString)),
|
||||
this, SIGNAL(textChanged(QString)));
|
||||
|
||||
d->setWidget(nativeWidget);
|
||||
nativeWidget->setWindowIcon(QIcon());
|
||||
|
||||
nativeWidget->setAttribute(Qt::WA_NoSystemBackground);
|
||||
nativeWidget->setStyle(d->style.data());
|
||||
|
||||
d->syncBorders();
|
||||
}
|
||||
|
||||
KComboBox *ComboBox::nativeWidget() const
|
||||
{
|
||||
return static_cast<KComboBox*>(widget());
|
||||
}
|
||||
|
||||
void ComboBox::addItem(const QString &text)
|
||||
{
|
||||
static_cast<KComboBox*>(widget())->addItem(text);
|
||||
}
|
||||
|
||||
void ComboBox::clear()
|
||||
{
|
||||
static_cast<KComboBox*>(widget())->clear();
|
||||
}
|
||||
|
||||
void ComboBox::resizeEvent(QGraphicsSceneResizeEvent *event)
|
||||
{
|
||||
if (d->background) {
|
||||
//resize needed panels
|
||||
d->syncActiveRect();
|
||||
|
||||
d->background->setElementPrefix("focus");
|
||||
d->background->resizeFrame(size());
|
||||
|
||||
d->background->setElementPrefix("active");
|
||||
d->background->resizeFrame(d->activeRect.size());
|
||||
|
||||
d->background->setElementPrefix("normal");
|
||||
d->background->resizeFrame(size());
|
||||
}
|
||||
|
||||
QGraphicsProxyWidget::resizeEvent(event);
|
||||
}
|
||||
|
||||
void ComboBox::paint(QPainter *painter,
|
||||
const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget)
|
||||
{
|
||||
|
||||
if (!styleSheet().isNull() ||
|
||||
Theme::defaultTheme()->useNativeWidgetStyle()) {
|
||||
QGraphicsProxyWidget::paint(painter, option, widget);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nativeWidget()->isEditable()) {
|
||||
QGraphicsProxyWidget::paint(painter, option, widget);
|
||||
return;
|
||||
}
|
||||
|
||||
QPixmap bufferPixmap;
|
||||
|
||||
//normal button
|
||||
if (isEnabled()) {
|
||||
d->background->setElementPrefix("normal");
|
||||
|
||||
d->background->paintFrame(painter);
|
||||
//disabled widget
|
||||
} else {
|
||||
bufferPixmap = QPixmap(rect().size().toSize());
|
||||
bufferPixmap.fill(Qt::transparent);
|
||||
|
||||
QPainter buffPainter(&bufferPixmap);
|
||||
d->background->paintFrame(&buffPainter);
|
||||
buffPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
||||
buffPainter.fillRect(bufferPixmap.rect(), QColor(0, 0, 0, 128));
|
||||
|
||||
painter->drawPixmap(0, 0, bufferPixmap);
|
||||
}
|
||||
|
||||
painter->setPen(Theme::defaultTheme()->color(Theme::ButtonTextColor));
|
||||
|
||||
QStyleOptionComboBox comboOpt;
|
||||
|
||||
comboOpt.initFrom(nativeWidget());
|
||||
|
||||
comboOpt.palette.setColor(
|
||||
QPalette::ButtonText, Theme::defaultTheme()->color(Theme::ButtonTextColor));
|
||||
comboOpt.currentIcon = nativeWidget()->itemIcon(
|
||||
nativeWidget()->currentIndex());
|
||||
comboOpt.currentText = nativeWidget()->itemText(
|
||||
nativeWidget()->currentIndex());
|
||||
comboOpt.editable = false;
|
||||
|
||||
nativeWidget()->style()->drawControl(
|
||||
QStyle::CE_ComboBoxLabel, &comboOpt, painter, nativeWidget());
|
||||
comboOpt.rect = nativeWidget()->style()->subControlRect(
|
||||
QStyle::CC_ComboBox, &comboOpt, QStyle::SC_ComboBoxArrow, nativeWidget());
|
||||
nativeWidget()->style()->drawPrimitive(
|
||||
QStyle::PE_IndicatorArrowDown, &comboOpt, painter, nativeWidget());
|
||||
}
|
||||
|
||||
void ComboBox::focusInEvent(QFocusEvent *event)
|
||||
{
|
||||
QGraphicsProxyWidget::focusInEvent(event);
|
||||
}
|
||||
|
||||
void ComboBox::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
QGraphicsWidget *widget = parentWidget();
|
||||
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
|
||||
|
||||
while (!applet && widget) {
|
||||
widget = widget->parentWidget();
|
||||
applet = qobject_cast<Plasma::Applet *>(widget);
|
||||
}
|
||||
|
||||
if (applet) {
|
||||
applet->setStatus(Plasma::UnknownStatus);
|
||||
}
|
||||
|
||||
if (nativeWidget()->isEditable()) {
|
||||
QEvent closeEvent(QEvent::CloseSoftwareInputPanel);
|
||||
if (qApp) {
|
||||
if (QGraphicsView *view = qobject_cast<QGraphicsView*>(qApp->focusWidget())) {
|
||||
if (view->scene() && view->scene() == scene()) {
|
||||
QApplication::sendEvent(view, &closeEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QGraphicsProxyWidget::focusOutEvent(event);
|
||||
}
|
||||
|
||||
void ComboBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
d->underMouse = true;
|
||||
QGraphicsProxyWidget::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
void ComboBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
d->underMouse = false;
|
||||
QGraphicsProxyWidget::hoverLeaveEvent(event);
|
||||
}
|
||||
|
||||
void ComboBox::changeEvent(QEvent *event)
|
||||
{
|
||||
d->changeEvent(event);
|
||||
QGraphicsProxyWidget::changeEvent(event);
|
||||
}
|
||||
|
||||
void ComboBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||
{
|
||||
QGraphicsWidget *widget = parentWidget();
|
||||
Plasma::Applet *applet = qobject_cast<Plasma::Applet *>(widget);
|
||||
|
||||
while (!applet && widget) {
|
||||
widget = widget->parentWidget();
|
||||
applet = qobject_cast<Plasma::Applet *>(widget);
|
||||
}
|
||||
|
||||
if (applet) {
|
||||
applet->setStatus(Plasma::AcceptingInputStatus);
|
||||
}
|
||||
QGraphicsProxyWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
int ComboBox::count() const
|
||||
{
|
||||
return nativeWidget()->count();
|
||||
}
|
||||
|
||||
int ComboBox::currentIndex() const
|
||||
{
|
||||
return nativeWidget()->currentIndex();
|
||||
}
|
||||
|
||||
void ComboBox::setCurrentIndex(int index)
|
||||
{
|
||||
nativeWidget()->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
} // namespace Plasma
|
||||
|
||||
|
||||
|
||||
|
||||
#include "moc_combobox.cpp"
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user