2013-06-25 14:07:48 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* KWin - the KDE window manager *
|
|
|
|
* This file is part of the KDE project. *
|
|
|
|
* *
|
|
|
|
* Copyright (C) 2013 Antonis Tsiapaliokas <kok3rs@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, 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 General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef MODEL_H
|
|
|
|
#define MODEL_H
|
2013-09-13 10:34:40 +00:00
|
|
|
|
2014-01-08 17:06:08 +00:00
|
|
|
#include <KColorScheme>
|
|
|
|
#include <KSharedConfig>
|
2013-08-09 12:29:05 +00:00
|
|
|
#include <QAbstractItemModel>
|
2013-06-25 14:07:48 +00:00
|
|
|
#include <QHash>
|
|
|
|
#include <QList>
|
|
|
|
#include <QQuickView>
|
2013-08-09 12:29:05 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2013-06-25 14:07:48 +00:00
|
|
|
#include <QString>
|
2015-09-18 13:23:50 +00:00
|
|
|
#include <KPluginInfo>
|
2013-06-25 14:07:48 +00:00
|
|
|
|
2013-08-07 16:52:45 +00:00
|
|
|
namespace KWin {
|
|
|
|
namespace Compositing {
|
|
|
|
|
2014-06-11 06:44:04 +00:00
|
|
|
enum class EffectStatus {
|
|
|
|
Disabled = Qt::Unchecked,
|
|
|
|
EnabledUndeterminded = Qt::PartiallyChecked,
|
|
|
|
Enabled = Qt::Checked
|
|
|
|
};
|
|
|
|
|
2013-08-07 16:52:45 +00:00
|
|
|
struct EffectData {
|
2013-06-25 14:07:48 +00:00
|
|
|
QString name;
|
|
|
|
QString description;
|
|
|
|
QString authorName;
|
|
|
|
QString authorEmail;
|
|
|
|
QString license;
|
|
|
|
QString version;
|
|
|
|
QString category;
|
2013-08-07 16:52:45 +00:00
|
|
|
QString serviceName;
|
2014-06-11 06:44:04 +00:00
|
|
|
EffectStatus effectStatus;
|
2013-12-02 14:59:31 +00:00
|
|
|
bool enabledByDefault;
|
2014-06-11 06:44:04 +00:00
|
|
|
bool enabledByDefaultFunction;
|
2013-12-03 06:56:21 +00:00
|
|
|
QUrl video;
|
2014-03-09 09:02:12 +00:00
|
|
|
bool supported;
|
2014-03-11 12:06:18 +00:00
|
|
|
QString exclusiveGroup;
|
2014-03-13 18:50:17 +00:00
|
|
|
bool internal;
|
2014-03-17 12:13:17 +00:00
|
|
|
bool configurable;
|
2014-03-17 18:23:46 +00:00
|
|
|
bool scripted;
|
2014-06-11 07:36:39 +00:00
|
|
|
bool changed = false;
|
2013-06-25 14:07:48 +00:00
|
|
|
};
|
|
|
|
|
2013-08-28 07:36:53 +00:00
|
|
|
class EffectModel : public QAbstractItemModel
|
|
|
|
{
|
2013-06-25 14:07:48 +00:00
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum EffectRoles {
|
2013-08-07 16:52:45 +00:00
|
|
|
NameRole = Qt::UserRole + 1,
|
|
|
|
DescriptionRole,
|
|
|
|
AuthorNameRole,
|
|
|
|
AuthorEmailRole,
|
|
|
|
LicenseRole,
|
|
|
|
VersionRole,
|
|
|
|
CategoryRole,
|
|
|
|
ServiceNameRole,
|
2013-08-22 10:31:01 +00:00
|
|
|
EffectStatusRole,
|
2014-03-09 09:02:12 +00:00
|
|
|
VideoRole,
|
2014-03-11 12:06:18 +00:00
|
|
|
SupportedRole,
|
2014-03-13 18:50:17 +00:00
|
|
|
ExclusiveRole,
|
2014-03-17 12:13:17 +00:00
|
|
|
InternalRole,
|
2014-03-17 18:23:46 +00:00
|
|
|
ConfigurableRole,
|
|
|
|
ScriptedRole
|
2013-06-25 14:07:48 +00:00
|
|
|
};
|
|
|
|
|
2013-08-08 09:08:54 +00:00
|
|
|
explicit EffectModel(QObject *parent = 0);
|
2013-08-09 12:29:05 +00:00
|
|
|
|
2013-08-27 09:59:24 +00:00
|
|
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QModelIndex parent(const QModelIndex &child) const override;
|
|
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
|
2013-08-07 16:52:45 +00:00
|
|
|
QString serviceName(const QString &effectName);
|
2013-06-25 14:07:48 +00:00
|
|
|
|
2013-08-27 09:57:21 +00:00
|
|
|
virtual QHash< int, QByteArray > roleNames() const override;
|
|
|
|
|
2014-06-11 06:44:04 +00:00
|
|
|
void updateEffectStatus(const QModelIndex &rowIndex, EffectStatus effectState);
|
2013-08-28 09:01:08 +00:00
|
|
|
void syncEffectsToKWin();
|
2013-08-27 18:21:07 +00:00
|
|
|
void syncConfig();
|
2013-12-02 14:40:16 +00:00
|
|
|
void loadEffects();
|
2013-12-02 14:59:31 +00:00
|
|
|
void defaults();
|
2013-08-07 17:25:04 +00:00
|
|
|
|
2013-06-25 14:07:48 +00:00
|
|
|
private:
|
2015-09-18 13:23:50 +00:00
|
|
|
void loadBuiltInEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs);
|
|
|
|
void loadJavascriptEffects(const KConfigGroup &kwinConfig);
|
|
|
|
void loadPluginEffects(const KConfigGroup &kwinConfig, const KPluginInfo::List &configs);
|
2013-08-22 10:31:01 +00:00
|
|
|
int findRowByServiceName(const QString &serviceName);
|
2013-08-07 16:52:45 +00:00
|
|
|
QList<EffectData> m_effectsList;
|
2013-08-28 09:01:08 +00:00
|
|
|
QList<EffectData> m_effectsChanged;
|
2013-08-27 18:21:07 +00:00
|
|
|
|
2013-06-25 14:07:48 +00:00
|
|
|
};
|
|
|
|
|
2013-08-28 07:36:53 +00:00
|
|
|
class EffectView : public QQuickView
|
|
|
|
{
|
2013-06-25 14:07:48 +00:00
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2014-03-07 09:09:47 +00:00
|
|
|
enum ViewType {
|
|
|
|
DesktopEffectsView,
|
|
|
|
CompositingSettingsView
|
|
|
|
};
|
|
|
|
EffectView(ViewType type, QWindow *parent = 0);
|
2013-09-13 12:29:53 +00:00
|
|
|
|
2013-12-02 14:27:58 +00:00
|
|
|
void save();
|
2013-12-02 14:40:16 +00:00
|
|
|
void load();
|
2013-12-02 14:59:31 +00:00
|
|
|
void defaults();
|
2013-12-02 14:27:58 +00:00
|
|
|
|
2013-12-02 10:26:37 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void changed();
|
2014-03-26 11:06:01 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void slotImplicitSizeChanged();
|
2013-12-02 10:27:36 +00:00
|
|
|
private:
|
2014-03-07 09:09:47 +00:00
|
|
|
void init(ViewType type);
|
2013-06-25 14:07:48 +00:00
|
|
|
};
|
2013-08-07 16:52:45 +00:00
|
|
|
|
2013-08-09 12:29:05 +00:00
|
|
|
|
|
|
|
class EffectFilterModel : public QSortFilterProxyModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged)
|
2014-03-09 09:02:12 +00:00
|
|
|
/**
|
|
|
|
* If @c true not supported effects are excluded, if @c false no restriction on supported.
|
|
|
|
* Default value is @c true.
|
|
|
|
**/
|
2014-03-13 18:50:17 +00:00
|
|
|
Q_PROPERTY(bool filterOutUnsupported MEMBER m_filterOutUnsupported NOTIFY filterOutUnsupportedChanged)
|
|
|
|
/**
|
|
|
|
* If @c true internal effects are excluded, if @c false no restriction on internal.
|
|
|
|
* Default value is @c true.
|
|
|
|
**/
|
|
|
|
Q_PROPERTY(bool filterOutInternal MEMBER m_filterOutInternal NOTIFY filterOutInternalChanged)
|
2013-09-13 10:34:40 +00:00
|
|
|
Q_PROPERTY(QColor backgroundActiveColor READ backgroundActiveColor CONSTANT);
|
|
|
|
Q_PROPERTY(QColor backgroundNormalColor READ backgroundNormalColor CONSTANT);
|
|
|
|
Q_PROPERTY(QColor backgroundAlternateColor READ backgroundAlternateColor CONSTANT);
|
2014-03-11 08:02:23 +00:00
|
|
|
Q_PROPERTY(QColor sectionColor READ sectionColor CONSTANT)
|
2013-08-09 12:29:05 +00:00
|
|
|
public:
|
|
|
|
EffectFilterModel(QObject *parent = 0);
|
|
|
|
const QString &filter() const;
|
|
|
|
|
2014-06-11 06:44:04 +00:00
|
|
|
Q_INVOKABLE void updateEffectStatus(int rowIndex, int effectState);
|
2013-08-27 18:21:07 +00:00
|
|
|
Q_INVOKABLE void syncConfig();
|
2014-01-12 19:27:10 +00:00
|
|
|
Q_INVOKABLE void load();
|
2013-08-27 18:21:07 +00:00
|
|
|
|
2013-09-13 10:34:40 +00:00
|
|
|
QColor backgroundActiveColor() { return KColorScheme(QPalette::Active, KColorScheme::Selection, KSharedConfigPtr(0)).background(KColorScheme::LinkBackground).color(); };
|
|
|
|
QColor backgroundNormalColor() { return KColorScheme(QPalette::Active, KColorScheme::View, KSharedConfigPtr(0)).background(KColorScheme::NormalBackground).color(); };
|
|
|
|
QColor backgroundAlternateColor() { return KColorScheme(QPalette::Active, KColorScheme::View, KSharedConfigPtr(0)).background(KColorScheme::AlternateBackground).color(); };
|
|
|
|
|
2014-03-11 08:02:23 +00:00
|
|
|
QColor sectionColor() const {
|
|
|
|
QColor color = KColorScheme(QPalette::Active).foreground().color();
|
|
|
|
color.setAlphaF(0.6);
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2013-12-02 14:59:31 +00:00
|
|
|
void defaults();
|
2013-12-02 14:40:16 +00:00
|
|
|
|
2013-08-09 12:29:05 +00:00
|
|
|
public Q_SLOTS:
|
|
|
|
void setFilter(const QString &filter);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
|
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void effectModelChanged();
|
|
|
|
void filterChanged();
|
2014-03-13 18:50:17 +00:00
|
|
|
void filterOutUnsupportedChanged();
|
|
|
|
void filterOutInternalChanged();
|
2013-08-09 12:29:05 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
EffectModel *m_effectModel;
|
|
|
|
QString m_filter;
|
2014-03-13 18:50:17 +00:00
|
|
|
bool m_filterOutUnsupported;
|
|
|
|
bool m_filterOutInternal;
|
2013-08-09 12:29:05 +00:00
|
|
|
};
|
2013-08-07 16:52:45 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-25 14:07:48 +00:00
|
|
|
#endif
|