2013-02-22 18:23:35 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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 CONFIGUILOADER_H
|
|
|
|
#define CONFIGUILOADER_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <QQuickView>
|
2013-02-22 20:58:54 +01:00
|
|
|
#include <QJSValue>
|
2013-02-26 21:48:02 +01:00
|
|
|
#include <QQmlListProperty>
|
2013-02-27 17:39:16 +01:00
|
|
|
#include <QStandardItemModel>
|
2013-02-22 18:23:35 +01:00
|
|
|
|
|
|
|
class AppletInterface;
|
|
|
|
|
2013-02-27 17:39:16 +01:00
|
|
|
|
|
|
|
class ConfigCategory : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
|
|
|
Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
|
|
|
|
Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
|
|
|
|
|
|
|
|
public:
|
|
|
|
ConfigCategory(QObject *parent = 0);
|
|
|
|
~ConfigCategory();
|
|
|
|
|
|
|
|
QString name() const;
|
|
|
|
void setName(const QString &name);
|
|
|
|
|
|
|
|
QString icon() const;
|
|
|
|
void setIcon(const QString &icon);
|
|
|
|
|
|
|
|
QString source() const;
|
|
|
|
void setSource(const QString &source);
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void nameChanged();
|
|
|
|
void iconChanged();
|
|
|
|
void sourceChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_name;
|
|
|
|
QString m_icon;
|
|
|
|
QString m_source;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConfigModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QQmlListProperty<ConfigCategory> categories READ categories CONSTANT)
|
|
|
|
Q_CLASSINFO("DefaultProperty", "categories")
|
2013-02-27 18:31:13 +01:00
|
|
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
|
|
|
|
2013-02-27 17:39:16 +01:00
|
|
|
public:
|
|
|
|
enum Roles {
|
|
|
|
NameRole = Qt::UserRole+1,
|
|
|
|
IconRole,
|
|
|
|
SourceRole
|
|
|
|
};
|
|
|
|
ConfigModel(QObject *parent = 0);
|
|
|
|
~ConfigModel();
|
|
|
|
|
|
|
|
void appendCategory(ConfigCategory *c);
|
|
|
|
void clear();
|
|
|
|
|
2013-02-27 18:31:13 +01:00
|
|
|
void setAppletInterface(AppletInterface *interface);
|
|
|
|
AppletInterface *appletInterface() const;
|
|
|
|
|
|
|
|
int count() {return rowCount();}
|
|
|
|
virtual int rowCount(const QModelIndex &index = QModelIndex()) const;
|
2013-02-27 17:39:16 +01:00
|
|
|
virtual QVariant data(const QModelIndex&, int) const;
|
2013-02-27 18:31:13 +01:00
|
|
|
Q_INVOKABLE QVariant get(int row) const;
|
2013-02-27 17:39:16 +01:00
|
|
|
|
|
|
|
QQmlListProperty<ConfigCategory> categories();
|
|
|
|
|
|
|
|
static ConfigCategory *categories_at(QQmlListProperty<ConfigCategory> *prop, int index);
|
|
|
|
static void categories_append(QQmlListProperty<ConfigCategory> *prop, ConfigCategory *o);
|
|
|
|
static int categories_count(QQmlListProperty<ConfigCategory> *prop);
|
|
|
|
static void categories_clear(QQmlListProperty<ConfigCategory> *prop);
|
|
|
|
|
2013-02-27 18:31:13 +01:00
|
|
|
Q_SIGNALS:
|
|
|
|
void countChanged();
|
|
|
|
|
2013-02-27 17:39:16 +01:00
|
|
|
private:
|
|
|
|
QList<ConfigCategory*>m_categories;
|
2013-02-27 18:31:13 +01:00
|
|
|
QWeakPointer<AppletInterface> m_appletInterface;
|
2013-02-27 17:39:16 +01:00
|
|
|
};
|
|
|
|
|
2013-03-01 20:01:54 +01:00
|
|
|
|
|
|
|
//TODO: the config view for the containment should be a subclass
|
|
|
|
//TODO: is it possible to move this in the shell?
|
2013-02-22 18:23:35 +01:00
|
|
|
class ConfigView : public QQuickView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2013-02-28 21:24:30 +01:00
|
|
|
Q_PROPERTY(ConfigModel *configModel READ configModel CONSTANT)
|
|
|
|
Q_PROPERTY(ConfigModel *wallpaperConfigModel READ wallpaperConfigModel CONSTANT)
|
2013-03-01 20:01:54 +01:00
|
|
|
Q_PROPERTY(QObject *wallpaperConfiguration READ wallpaperConfiguration CONSTANT)
|
2013-02-22 18:23:35 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
ConfigView(AppletInterface *scriptEngine, QWindow *parent = 0);
|
|
|
|
virtual ~ConfigView();
|
|
|
|
|
2013-02-28 21:24:30 +01:00
|
|
|
ConfigModel *configModel() const;
|
|
|
|
ConfigModel *wallpaperConfigModel();
|
2013-03-01 20:01:54 +01:00
|
|
|
QObject *wallpaperConfiguration() const;
|
2013-02-22 20:58:54 +01:00
|
|
|
|
2013-02-26 12:47:08 +01:00
|
|
|
protected:
|
|
|
|
void hideEvent(QHideEvent *ev);
|
2013-02-27 14:03:36 +01:00
|
|
|
void resizeEvent(QResizeEvent *re);
|
2013-02-26 12:47:08 +01:00
|
|
|
|
2013-02-22 18:23:35 +01:00
|
|
|
private:
|
|
|
|
AppletInterface *m_appletInterface;
|
2013-02-27 18:31:13 +01:00
|
|
|
ConfigModel *m_configModel;
|
2013-02-28 21:24:30 +01:00
|
|
|
ConfigModel *m_wallpaperConfigModel;
|
2013-02-22 18:23:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|