2009-05-13 02:55:25 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Chani Armitage <chani@kde.org>
|
2009-07-04 06:30:57 +02:00
|
|
|
* Copyright 2008, 2009 Aaron Seigo <aseigo@kde.org>
|
2009-05-13 02:55:25 +02:00
|
|
|
*
|
|
|
|
* 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 APPLETINTERFACE_H
|
|
|
|
#define APPLETINTERFACE_H
|
|
|
|
|
2010-01-12 09:04:51 +01:00
|
|
|
#include <QAbstractAnimation>
|
2009-05-13 02:55:25 +02:00
|
|
|
#include <QObject>
|
2009-11-06 19:59:41 +01:00
|
|
|
#include <QSizePolicy>
|
2009-05-13 02:55:25 +02:00
|
|
|
#include <QScriptValue>
|
2009-11-13 22:44:51 +01:00
|
|
|
|
|
|
|
#include <Plasma/Applet>
|
2009-12-16 23:05:46 +01:00
|
|
|
#include <Plasma/PopupApplet>
|
2009-05-13 02:55:25 +02:00
|
|
|
#include <Plasma/DataEngine>
|
|
|
|
|
2009-11-13 23:04:16 +01:00
|
|
|
#include "simplejavascriptapplet.h"
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
class QAction;
|
|
|
|
class SimpleJavaScriptApplet;
|
|
|
|
class QSignalMapper;
|
|
|
|
class QSizeF;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
class ConfigLoader;
|
2010-01-20 22:40:55 +01:00
|
|
|
class Extender;
|
2009-05-13 02:55:25 +02:00
|
|
|
} // namespace Plasa
|
|
|
|
|
|
|
|
class AppletInterface : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_ENUMS(FormFactor)
|
|
|
|
Q_ENUMS(Location)
|
|
|
|
Q_ENUMS(AspectRatioMode)
|
2009-11-13 22:44:51 +01:00
|
|
|
Q_ENUMS(BackgroundHints)
|
2009-05-13 02:55:25 +02:00
|
|
|
Q_ENUMS(QtOrientation)
|
2010-04-02 03:04:06 +02:00
|
|
|
Q_ENUMS(QtModifiers)
|
2009-11-03 04:06:04 +01:00
|
|
|
Q_ENUMS(QtAnchorPoint)
|
2009-11-07 12:46:58 +01:00
|
|
|
Q_ENUMS(QtCorner)
|
2009-11-06 19:59:41 +01:00
|
|
|
Q_ENUMS(QtSizePolicy)
|
2009-05-13 02:55:25 +02:00
|
|
|
Q_ENUMS(QtAlignment)
|
2010-01-21 00:52:32 +01:00
|
|
|
Q_ENUMS(QtMouseButton)
|
2010-01-12 09:04:51 +01:00
|
|
|
Q_ENUMS(AnimationDirection)
|
2010-03-09 23:29:08 +01:00
|
|
|
Q_ENUMS(IntervalAlignment)
|
2009-11-13 23:04:16 +01:00
|
|
|
Q_PROPERTY(AspectRatioMode aspectRatioMode READ aspectRatioMode WRITE setAspectRatioMode)
|
|
|
|
Q_PROPERTY(FormFactor formFactor READ formFactor)
|
|
|
|
Q_PROPERTY(Location location READ location)
|
|
|
|
Q_PROPERTY(QString currentActivity READ currentActivity)
|
|
|
|
Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
|
2009-05-13 02:55:25 +02:00
|
|
|
Q_PROPERTY(QString activeConfig WRITE setActiveConfig READ activeConfig)
|
2009-07-04 06:30:57 +02:00
|
|
|
Q_PROPERTY(bool busy WRITE setBusy READ isBusy)
|
2009-11-13 22:44:51 +01:00
|
|
|
Q_PROPERTY(BackgroundHints backgroundHints WRITE setBackgroundHints READ backgroundHints)
|
2009-11-13 23:04:16 +01:00
|
|
|
Q_PROPERTY(QGraphicsLayout *layout WRITE setLayout READ layout)
|
2009-11-13 23:27:30 +01:00
|
|
|
Q_PROPERTY(bool immutable READ immutable)
|
2010-02-01 17:19:32 +01:00
|
|
|
Q_PROPERTY(bool userConfiguring READ userConfiguring) // @since 4.5
|
2009-11-14 01:24:14 +01:00
|
|
|
Q_PROPERTY(int apiVersion READ apiVersion)
|
2010-02-12 20:19:54 +01:00
|
|
|
Q_PROPERTY(QRectF rect READ rect)
|
|
|
|
Q_PROPERTY(QSizeF size READ size)
|
2009-11-14 01:24:14 +01:00
|
|
|
Q_PROPERTY(QObject *sender READ sender)
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
AppletInterface(SimpleJavaScriptApplet *parent);
|
|
|
|
~AppletInterface();
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//enums copy&pasted from plasma.h because qtscript is evil
|
|
|
|
|
|
|
|
enum FormFactor {
|
|
|
|
Planar = 0, /**< The applet lives in a plane and has two
|
|
|
|
degrees of freedom to grow. Optimize for
|
|
|
|
desktop, laptop or tablet usage: a high
|
|
|
|
resolution screen 1-3 feet distant from the
|
|
|
|
viewer. */
|
|
|
|
MediaCenter, /**< As with Planar, the applet lives in a plane
|
|
|
|
but the interface should be optimized for
|
|
|
|
medium-to-high resolution screens that are
|
|
|
|
5-15 feet distant from the viewer. Sometimes
|
|
|
|
referred to as a "ten foot interface".*/
|
|
|
|
Horizontal, /**< The applet is constrained vertically, but
|
|
|
|
can expand horizontally. */
|
|
|
|
Vertical /**< The applet is constrained horizontally, but
|
|
|
|
can expand vertically. */
|
|
|
|
};
|
2009-11-13 22:44:51 +01:00
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
enum Location {
|
|
|
|
Floating = 0, /**< Free floating. Neither geometry or z-ordering
|
|
|
|
is described precisely by this value. */
|
|
|
|
Desktop, /**< On the planar desktop layer, extending across
|
|
|
|
the full screen from edge to edge */
|
|
|
|
FullScreen, /**< Full screen */
|
|
|
|
TopEdge, /**< Along the top of the screen*/
|
|
|
|
BottomEdge, /**< Along the bottom of the screen*/
|
|
|
|
LeftEdge, /**< Along the left side of the screen */
|
|
|
|
RightEdge /**< Along the right side of the screen */
|
|
|
|
};
|
2009-11-13 22:44:51 +01:00
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
enum AspectRatioMode {
|
|
|
|
InvalidAspectRatioMode = -1, /**< Unsetted mode used for dev convenience
|
|
|
|
when there is a need to store the
|
|
|
|
aspectRatioMode somewhere */
|
|
|
|
IgnoreAspectRatio = 0, /**< The applet can be freely resized */
|
|
|
|
KeepAspectRatio = 1, /**< The applet keeps a fixed aspect ratio */
|
|
|
|
Square = 2, /**< The applet is always a square */
|
|
|
|
ConstrainedSquare = 3, /**< The applet is no wider (in horizontal
|
|
|
|
formfactors) or no higher (in vertical
|
|
|
|
ones) than a square */
|
|
|
|
FixedSize = 4 /** The applet cannot be resized */
|
|
|
|
};
|
|
|
|
|
|
|
|
//From Qt namespace
|
2010-04-02 03:04:06 +02:00
|
|
|
enum QtModifiers {
|
|
|
|
QtNoModifier = Qt::NoModifier,
|
|
|
|
QtShiftModifier = Qt::ShiftModifier,
|
|
|
|
QtControlModifier = Qt::ControlModifier,
|
|
|
|
QtAltModifier = Qt::AltModifier,
|
|
|
|
QtMetaModifier = Qt::MetaModifier
|
|
|
|
};
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
enum QtOrientation {
|
|
|
|
QtHorizontal= Qt::Horizontal,
|
|
|
|
QtVertical = Qt::Vertical
|
|
|
|
};
|
|
|
|
|
2009-11-03 04:06:04 +01:00
|
|
|
enum QtAnchorPoint {
|
|
|
|
QtAnchorLeft = Qt::AnchorLeft,
|
|
|
|
QtAnchorRight = Qt::AnchorRight,
|
|
|
|
QtAnchorBottom = Qt::AnchorBottom,
|
|
|
|
QtAnchorTop = Qt::AnchorTop,
|
|
|
|
QtAnchorHorizontalCenter = Qt::AnchorHorizontalCenter,
|
|
|
|
QtAnchorVerticalCenter = Qt::AnchorVerticalCenter
|
|
|
|
};
|
|
|
|
|
2009-11-07 12:46:58 +01:00
|
|
|
enum QtCorner {
|
|
|
|
QtTopLeftCorner = Qt::TopLeftCorner,
|
|
|
|
QtTopRightCorner = Qt::TopRightCorner,
|
|
|
|
QtBottomLeftCorner = Qt::BottomLeftCorner,
|
|
|
|
QtBottomRightCorner = Qt::BottomRightCorner
|
|
|
|
};
|
|
|
|
|
2009-11-06 19:59:41 +01:00
|
|
|
enum QtSizePolicy {
|
|
|
|
QSizePolicyFixed = QSizePolicy::Fixed,
|
|
|
|
QSizePolicyMinimum = QSizePolicy::Minimum,
|
|
|
|
QSizePolicyMaximum = QSizePolicy::Maximum,
|
|
|
|
QSizePolicyPreferred = QSizePolicy::Preferred,
|
|
|
|
QSizePolicyExpanding = QSizePolicy::Expanding,
|
|
|
|
QSizePolicyMinimumExpanding = QSizePolicy::MinimumExpanding,
|
|
|
|
QSizePolicyIgnored = QSizePolicy::Ignored
|
|
|
|
};
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
enum BackgroundHints {
|
|
|
|
NoBackground = Plasma::Applet::NoBackground,
|
|
|
|
StandardBackground = Plasma::Applet::StandardBackground,
|
|
|
|
TranslucentBackground = Plasma::Applet::TranslucentBackground,
|
|
|
|
DefaultBackground = Plasma::Applet::DefaultBackground
|
|
|
|
};
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
enum QtAlignment {
|
|
|
|
QtAlignLeft = 0x0001,
|
|
|
|
QtAlignRight = 0x0002,
|
|
|
|
QtAlignHCenter = 0x0004,
|
|
|
|
QtAlignJustify = 0x0005,
|
|
|
|
QtAlignTop = 0x0020,
|
|
|
|
QtAlignBottom = 0x0020,
|
|
|
|
QtAlignVCenter = 0x0080
|
|
|
|
};
|
2009-11-03 04:06:04 +01:00
|
|
|
|
2010-01-21 00:52:32 +01:00
|
|
|
enum QtMouseButton {
|
|
|
|
QtNoButton = Qt::NoButton,
|
|
|
|
QtLeftButton = Qt::LeftButton,
|
|
|
|
QtRightButton = Qt::RightButton,
|
|
|
|
QtMidButton = Qt::MidButton,
|
|
|
|
QtXButton1 = Qt::XButton1,
|
|
|
|
QtXButton2 = Qt::XButton2
|
|
|
|
};
|
|
|
|
|
2009-11-14 05:22:31 +01:00
|
|
|
enum QtScrollBarPolicy {
|
|
|
|
QtScrollBarAsNeeded = Qt::ScrollBarAsNeeded,
|
|
|
|
QtScrollBarAlwaysOff = Qt::ScrollBarAlwaysOff,
|
|
|
|
QtScrollBarAlwaysOn = Qt::ScrollBarAlwaysOn
|
|
|
|
};
|
2010-01-12 09:04:51 +01:00
|
|
|
|
|
|
|
enum AnimationDirection {
|
|
|
|
AnimationForward = QAbstractAnimation::Forward,
|
|
|
|
AnimationBackward = QAbstractAnimation::Backward
|
|
|
|
};
|
2010-03-09 23:29:08 +01:00
|
|
|
|
|
|
|
enum IntervalAlignment {
|
|
|
|
NoAlignment = 0,
|
|
|
|
AlignToMinute,
|
|
|
|
AlignToHour
|
|
|
|
};
|
2009-05-13 02:55:25 +02:00
|
|
|
//-------------------------------------------------------------------
|
|
|
|
|
2009-11-18 23:40:38 +01:00
|
|
|
Q_INVOKABLE void gc();
|
2009-11-13 22:44:51 +01:00
|
|
|
Q_INVOKABLE FormFactor formFactor() const;
|
2009-05-13 02:55:25 +02:00
|
|
|
|
2009-11-13 23:04:16 +01:00
|
|
|
Location location() const;
|
|
|
|
QString currentActivity() const;
|
|
|
|
bool shouldConserveResources() const;
|
2009-05-13 02:55:25 +02:00
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
Q_INVOKABLE AspectRatioMode aspectRatioMode() const;
|
2009-05-13 02:55:25 +02:00
|
|
|
Q_INVOKABLE void setAspectRatioMode(AspectRatioMode mode);
|
|
|
|
|
|
|
|
Q_INVOKABLE void setFailedToLaunch(bool failed, const QString &reason = QString());
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
Q_INVOKABLE bool isBusy() const;
|
2009-05-13 02:55:25 +02:00
|
|
|
Q_INVOKABLE void setBusy(bool busy);
|
|
|
|
|
2009-11-13 22:44:51 +01:00
|
|
|
Q_INVOKABLE BackgroundHints backgroundHints() const;
|
|
|
|
Q_INVOKABLE void setBackgroundHints(BackgroundHints hint);
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
Q_INVOKABLE void setConfigurationRequired(bool needsConfiguring, const QString &reason = QString());
|
|
|
|
|
|
|
|
Q_INVOKABLE QSizeF size() const;
|
2009-10-21 01:30:36 +02:00
|
|
|
Q_INVOKABLE QRectF rect() const;
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
Q_INVOKABLE void setAction(const QString &name, const QString &text,
|
|
|
|
const QString &icon = QString(), const QString &shortcut = QString());
|
|
|
|
|
|
|
|
Q_INVOKABLE void removeAction(const QString &name);
|
|
|
|
|
|
|
|
Q_INVOKABLE void resize(qreal w, qreal h);
|
|
|
|
|
|
|
|
Q_INVOKABLE void setMinimumSize(qreal w, qreal h);
|
|
|
|
|
|
|
|
Q_INVOKABLE void setPreferredSize(qreal w, qreal h);
|
|
|
|
|
2009-11-13 23:10:32 +01:00
|
|
|
Q_INVOKABLE void update(const QRectF &rect = QRectF());
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
Q_INVOKABLE QString activeConfig() const;
|
|
|
|
|
|
|
|
Q_INVOKABLE void setActiveConfig(const QString &name);
|
|
|
|
|
|
|
|
Q_INVOKABLE QScriptValue readConfig(const QString &entry) const;
|
|
|
|
|
|
|
|
Q_INVOKABLE void writeConfig(const QString &entry, const QVariant &value);
|
|
|
|
|
|
|
|
Q_INVOKABLE QString file(const QString &fileType);
|
|
|
|
Q_INVOKABLE QString file(const QString &fileType, const QString &filePath);
|
|
|
|
|
2009-11-14 06:19:19 +01:00
|
|
|
Q_INVOKABLE bool include(const QString &script);
|
2009-11-14 08:33:42 +01:00
|
|
|
Q_INVOKABLE bool hasExtension(const QString &extension) const;
|
2009-11-14 06:19:19 +01:00
|
|
|
|
2009-11-14 08:32:00 +01:00
|
|
|
Q_INVOKABLE void debug(const QString &msg);
|
2010-01-06 01:23:31 +01:00
|
|
|
Q_INVOKABLE QObject *findChild(const QString &name) const;
|
2009-11-14 08:32:00 +01:00
|
|
|
|
2010-01-20 22:40:55 +01:00
|
|
|
Q_INVOKABLE Plasma::Extender *extender() const;
|
|
|
|
|
2010-04-01 02:46:44 +02:00
|
|
|
Q_INVOKABLE void addEventListener(const QString &event, const QScriptValue &func);
|
|
|
|
Q_INVOKABLE void removeEventListener(const QString &event, const QScriptValue &func);
|
|
|
|
|
2009-05-13 02:55:25 +02:00
|
|
|
Plasma::DataEngine *dataEngine(const QString &name);
|
|
|
|
|
|
|
|
const Plasma::Package *package() const;
|
|
|
|
QList<QAction*> contextualActions() const;
|
2009-11-13 23:04:16 +01:00
|
|
|
QGraphicsLayout *layout() const;
|
|
|
|
void setLayout(QGraphicsLayout *);
|
2009-11-13 23:27:30 +01:00
|
|
|
bool immutable() const;
|
2010-02-01 17:19:32 +01:00
|
|
|
bool userConfiguring() const;
|
2009-11-14 01:24:14 +01:00
|
|
|
int apiVersion() const;
|
2009-11-13 23:04:16 +01:00
|
|
|
|
|
|
|
inline Plasma::Applet *applet() const { return m_appletScriptEngine->applet(); }
|
2009-05-13 02:55:25 +02:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void releaseVisualFocus();
|
|
|
|
void configNeedsSaving();
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
|
|
|
void dataUpdated(QString source, Plasma::DataEngine::Data data);
|
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
protected:
|
2009-05-13 02:55:25 +02:00
|
|
|
SimpleJavaScriptApplet *m_appletScriptEngine;
|
2009-12-16 23:05:46 +01:00
|
|
|
|
|
|
|
private:
|
2009-05-13 02:55:25 +02:00
|
|
|
QSet<QString> m_actions;
|
|
|
|
QSignalMapper *m_actionSignals;
|
|
|
|
QString m_currentConfig;
|
|
|
|
QMap<QString, Plasma::ConfigLoader*> m_configs;
|
2009-12-16 23:05:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class PopupAppletInterface : public AppletInterface
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QIcon popupIcon READ popupIcon WRITE setPopupIcon)
|
2010-02-28 17:11:48 +01:00
|
|
|
Q_PROPERTY(bool passivePopup READ isPassivePopup WRITE setPassivePopup)
|
|
|
|
Q_PROPERTY(QGraphicsWidget *popupWidget READ popupWidget WRITE setPopupWidget)
|
2009-12-16 23:05:46 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
PopupAppletInterface(SimpleJavaScriptApplet *parent);
|
|
|
|
|
|
|
|
void setPopupIcon(const QIcon &icon);
|
|
|
|
QIcon popupIcon();
|
|
|
|
|
|
|
|
inline Plasma::PopupApplet *popupApplet() const { return static_cast<Plasma::PopupApplet *>(m_appletScriptEngine->applet()); }
|
|
|
|
|
2010-02-28 17:11:48 +01:00
|
|
|
void setPassivePopup(bool passive);
|
|
|
|
bool isPassivePopup() const;
|
|
|
|
|
|
|
|
void setPopupWidget(QGraphicsWidget *widget);
|
|
|
|
QGraphicsWidget *popupWidget();
|
|
|
|
|
2009-12-16 23:05:46 +01:00
|
|
|
public Q_SLOTS:
|
|
|
|
void setPopupIconByName(const QString &name);
|
2010-02-28 17:11:48 +01:00
|
|
|
void togglePopup();
|
|
|
|
void hidePopup();
|
|
|
|
void showPopup();
|
2009-05-13 02:55:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|