plasma-framework/src/plasmaview/configview.h

190 lines
4.7 KiB
C
Raw Normal View History

/*
* 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>
#include <QJSValue>
2013-02-26 21:48:02 +01:00
#include <QQmlListProperty>
#include <QStandardItemModel>
2013-08-27 21:07:55 +02:00
#include <plasmaview/plasmaview_export.h>
namespace Plasma {
class Applet;
}
class ConfigPropertyMap;
2013-08-27 21:07:55 +02:00
class ConfigCategoryPrivate;
2013-08-27 21:07:55 +02:00
class PLASMAVIEW_EXPORT 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)
Q_PROPERTY(QString pluginName READ pluginName WRITE setPluginName NOTIFY pluginNameChanged)
public:
ConfigCategory(QObject *parent = 0);
~ConfigCategory();
2013-08-30 11:01:13 +02:00
/**
* @return the name of the category
**/
QString name() const;
2013-08-30 11:01:13 +02:00
/**
* @param name the name of the category
**/
void setName(const QString &name);
2013-08-30 11:01:13 +02:00
/**
* @return the icon of the category
**/
QString icon() const;
2013-08-30 11:01:13 +02:00
/**
* @param icon the icon of the category
**/
void setIcon(const QString &icon);
QString source() const;
void setSource(const QString &source);
QString pluginName() const;
void setPluginName(const QString &pluginName);
Q_SIGNALS:
2013-08-30 11:01:13 +02:00
/**
* emitted when the name id changed
**/
void nameChanged();
2013-08-30 11:01:13 +02:00
/**
* emitted when the icon is changed
**/
void iconChanged();
2013-08-30 11:01:13 +02:00
/**
* emitted when the source is changed
**/
void sourceChanged();
2013-08-30 11:01:13 +02:00
/**
* emitted when the plugin is changed
**/
void pluginNameChanged();
private:
2013-08-27 21:07:55 +02:00
ConfigCategoryPrivate *const d;
};
2013-08-27 21:07:55 +02:00
class ConfigModelPrivate;
class PLASMAVIEW_EXPORT 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)
public:
enum Roles {
NameRole = Qt::UserRole+1,
IconRole,
SourceRole,
PluginNameRole
};
ConfigModel(QObject *parent = 0);
~ConfigModel();
2013-08-30 11:01:13 +02:00
/**
* add a new category in the model
* @param ConfigCategory the new category
**/
void appendCategory(ConfigCategory *c);
2013-08-30 11:01:13 +02:00
/**
* clears the model
**/
void clear();
void setApplet(Plasma::Applet *interface);
Plasma::Applet *applet() const;
2013-02-27 18:31:13 +01:00
int count() {return rowCount();}
virtual int rowCount(const QModelIndex &index = QModelIndex()) const;
virtual QVariant data(const QModelIndex&, int) const;
2013-08-30 11:01:13 +02:00
/**
* @param row the row for which the data will be returned
* @raturn the data of the specified row
**/
2013-02-27 18:31:13 +01:00
Q_INVOKABLE QVariant get(int row) const;
QQmlListProperty<ConfigCategory> categories();
2013-08-27 21:07:55 +02:00
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:
2013-08-30 11:01:13 +02:00
/**
* emitted when the count is changed
**/
2013-02-27 18:31:13 +01:00
void countChanged();
private:
2013-08-27 21:07:55 +02:00
friend class ConfigModelPrivate;
ConfigModelPrivate *const d;
};
2013-08-27 21:07:55 +02:00
class ConfigViewPrivate;
//TODO: the config view for the containment should be a subclass
//TODO: is it possible to move this in the shell?
class PLASMAVIEW_EXPORT ConfigView : public QQuickView
{
Q_OBJECT
2013-02-28 21:24:30 +01:00
Q_PROPERTY(ConfigModel *configModel READ configModel CONSTANT)
public:
ConfigView(Plasma::Applet *applet, QWindow *parent = 0);
virtual ~ConfigView();
2013-04-25 15:07:02 +02:00
virtual void init();
ConfigModel *configModel() const;
protected:
void hideEvent(QHideEvent *ev);
void resizeEvent(QResizeEvent *re);
private:
2013-08-27 21:07:55 +02:00
ConfigViewPrivate *const d;
};
#endif // multiple inclusion guard