Commit 028922b7 authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Port away from KDeclarative.

The KDeclarative dependency is too heavy when porting to mobile
plattforms like Android. Hence, this patch takes the only used
class from KDeclarative, namely the QtQuick QIconItem component, and
embeds it within the application specific components.
parent 26db67ea
......@@ -55,7 +55,6 @@ find_package(KF5 REQUIRED COMPONENTS
Config
ConfigWidgets
Crash
Declarative
I18n
NewStuff
WidgetsAddons
......
......@@ -55,6 +55,11 @@ set(artikulateCore_SRCS
core/resources/skeletonresource.cpp
core/player.cpp
core/recorder.cpp
qmlcontrols/iconitem.cpp
qmlcontrols/imagetexturescache.cpp
qmlcontrols/managedtexturenode.cpp
artikulate_debug.cpp
)
......@@ -66,6 +71,7 @@ target_link_libraries(artikulatecore
artikulatelearnerprofile
artikulatesound
Qt5::XmlPatterns
Qt5::Quick
KF5::Archive
KF5::ConfigGui
)
......@@ -164,7 +170,6 @@ target_link_libraries(artikulate
Qt5::Qml
Qt5::Quick
KF5::Crash
KF5::Declarative
KF5::NewStuff
KF5::XmlGui
)
......@@ -180,7 +185,6 @@ target_link_libraries(artikulate_editor
Qt5::QuickWidgets
KF5::ConfigWidgets
KF5::Crash
KF5::Declarative
KF5::NewStuff
KF5::XmlGui
)
......
......@@ -47,6 +47,7 @@
#include "models/phonemeunitmodel.h"
#include "models/profilemodel.h"
#include "models/skeletonmodel.h"
#include "qmlcontrols/iconitem.h"
#include "liblearnerprofile/src/learner.h"
#include "liblearnerprofile/src/profilemanager.h"
......@@ -56,7 +57,6 @@
#include <QQmlComponent>
#include <QQmlContext>
#include <QQmlEngine>
#include <KDeclarative/KDeclarative>
#include <QGraphicsDropShadowEffect>
Application::Application(int& argc, char** argv)
......@@ -83,6 +83,7 @@ void Application::registerQmlTypes()
qmlRegisterType<TrainingSession>("artikulate", 1, 0, "TrainingSession");
qmlRegisterType<Player>("artikulate", 1, 0, "Player");
qmlRegisterType<Recorder>("artikulate", 1, 0, "Recorder");
qmlRegisterType<IconItem>("artikulate", 1, 0, "Icon");
qmlRegisterType<CourseModel>("artikulate", 1, 0, "CourseModel");
qmlRegisterType<CourseFilterModel>("artikulate", 1, 0, "CourseFilterModel");
......
......@@ -21,7 +21,7 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
id: root
......@@ -57,7 +57,7 @@ Item {
width: parent.width
height: Math.max(label.height, label.height)
QIconItem {
Icon {
id: iconItem
visible: !!root.iconName
anchors {
......
......@@ -20,7 +20,6 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
......@@ -57,7 +56,7 @@ Item {
width: root.width - buttonLeft.width - buttonRight.width
height: theme.mediumIconSize
spacing: 10
QIconItem {
Icon {
id: icon
icon: "artikulate-course"
width: theme.smallMediumIconSize
......
......@@ -22,7 +22,6 @@ import QtQuick 2.1
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.2
import QtQml.Models 2.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item
......
......@@ -20,7 +20,7 @@
import QtQuick 2.5
import QtQuick.Controls 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
id: root
......@@ -71,18 +71,18 @@ Item {
height: paintedHeight
width: paintedWidth
}
QIconItem {
Icon {
id: iconItem
visible: !!root.iconName
width: height
height: root.iconSize
anchors {
left: textLabel.right
leftMargin: 10
verticalCenter: textLabel.verticalCenter
}
state: root.enabled ? QIconItem.DefaultState : QIconItem.DisabledState//TODO KF5.15 change to "enabled:"
enabled: root.enabled
icon: root.iconName
width: root.iconSize
height: root.iconSize
}
}
......
......@@ -20,7 +20,6 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
......@@ -70,7 +69,7 @@ Item {
height: theme.mediumIconSize
spacing: 10
QIconItem {
Icon {
id: icon
icon: "artikulate-language"
width: theme.mediumIconSize
......@@ -111,7 +110,7 @@ Item {
left: languageView.left
top: languageView.top
}
QIconItem {
Icon {
id: icon
icon: "dialog-information"
width: theme.mediumIconSize
......
......@@ -21,7 +21,7 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
id: root
......@@ -54,7 +54,7 @@ Item {
leftMargin: 10
}
QIconItem {
Icon {
id: iconItem
visible: !!root.iconName
anchors {
......
......@@ -22,7 +22,6 @@ import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.2
import QtQml.Models 2.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
ApplicationWindow {
......@@ -104,7 +103,7 @@ ApplicationWindow {
property int progress: isUnit ? 0 : phraseModel.phrase(styleData.index).progress
Repeater {
model: 3
QIconItem {
Icon {
width: 16
height: width
icon: progress > index ? "rating" : "rating-unrated"
......
......@@ -21,7 +21,6 @@
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
ToolBar{
......@@ -31,7 +30,7 @@ ToolBar{
Layout.preferredHeight: langIcon.height
spacing: 20
QIconItem {
Icon {
id: langIcon
icon: "artikulate-language"
width: 48
......
......@@ -20,7 +20,6 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
......@@ -50,7 +49,7 @@ Item {
Component {
id: dummyImage
QIconItem {
Icon {
anchors.fill: parent
icon: "user-identity"
}
......
......@@ -21,7 +21,6 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
......
......@@ -20,7 +20,6 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
......
......@@ -20,7 +20,6 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
......
......@@ -22,7 +22,6 @@
import QtQuick 2.1
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.2
import org.kde.kquickcontrolsaddons 2.0
import artikulate 1.0
Item {
......
/*
* Copyright 2011 Marco Martin <mart@kde.org>
* Copyright 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.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 "iconitem.h"
#include <QSGSimpleTextureNode>
#include <qquickwindow.h>
#include <QIcon>
#include "imagetexturescache.h"
#include "managedtexturenode.h"
Q_GLOBAL_STATIC(ImageTexturesCache, s_iconImageCache)
IconItem::IconItem(QQuickItem *parent)
: QQuickItem(parent),
m_smooth(false),
m_state(DefaultState),
m_changed(false)
{
setFlag(ItemHasContents, true);
}
IconItem::~IconItem()
{
}
void IconItem::setIcon(const QVariant &icon)
{
if(icon.canConvert<QIcon>()) {
m_icon = icon.value<QIcon>();
} else if(icon.canConvert<QString>()) {
m_icon = QIcon::fromTheme(icon.toString());
} else {
m_icon = QIcon();
}
m_changed = true;
update();
}
QIcon IconItem::icon() const
{
return m_icon;
}
IconItem::State IconItem::state() const
{
return m_state;
}
void IconItem::setState(IconItem::State state)
{
if (m_state == state) {
return;
}
m_state = state;
m_changed = true;
emit stateChanged(state);
update();
}
bool IconItem::enabled() const
{
return (m_state == DefaultState);
}
void IconItem::setEnabled(bool enabled)
{
if (enabled) {
setState(DefaultState);
} else {
setState(DisabledState);
}
}
int IconItem::implicitWidth() const
{
return 32;
}
int IconItem::implicitHeight() const
{
return 32;
}
void IconItem::setSmooth(const bool smooth)
{
if (smooth == m_smooth) {
return;
}
m_smooth = smooth;
m_changed = true;
update();
}
bool IconItem::smooth() const
{
return m_smooth;
}
QSGNode* IconItem::updatePaintNode(QSGNode* node, QQuickItem::UpdatePaintNodeData* /*data*/)
{
if (m_icon.isNull()) {
delete node;
return Q_NULLPTR;
}
if (m_changed || node == 0) {
m_changed = false;
ManagedTextureNode* mNode = dynamic_cast<ManagedTextureNode*>(node);
if(!mNode) {
delete node;
mNode = new ManagedTextureNode;
}
QIcon::Mode mode;
switch(m_state) {
case DefaultState:
mode = QIcon::Normal;
break;
case ActiveState:
mode = QIcon::Active;
break;
case DisabledState:
mode = QIcon::Disabled;
break;
}
QImage img;
const QSize size(width(), height());
if (!size.isEmpty()) {
img = m_icon.pixmap(size, mode, QIcon::On).toImage();
}
mNode->setTexture(s_iconImageCache->loadTexture(window(), img));
mNode->setRect(QRect(QPoint(0,0), size));
node = mNode;
}
return node;
}
void IconItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
if (newGeometry.size() != oldGeometry.size()) {
m_changed = true;
update();
}
QQuickItem::geometryChanged(newGeometry, oldGeometry);
}
/***************************************************************************
* Copyright 2011 Marco Martin <mart@kde.org> *
* *
* 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, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#ifndef ICONITEM_H
#define ICONITEM_H
#include <QIcon>
#include <QQuickItem>
#include <QVariant>
#include "artikulatecore_export.h"
class ARTIKULATECORE_EXPORT IconItem : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(QVariant icon READ icon WRITE setIcon)
Q_PROPERTY(bool smooth READ smooth WRITE setSmooth)
Q_PROPERTY(int implicitWidth READ implicitWidth CONSTANT)
Q_PROPERTY(int implicitHeight READ implicitHeight CONSTANT)
Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged)
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY stateChanged)
Q_ENUMS(State)
public:
enum State {
DefaultState, ///The default state.
ActiveState, ///Icon is active.
DisabledState ///Icon is disabled.
};
explicit IconItem(QQuickItem *parent = nullptr);
~IconItem();
void setIcon(const QVariant &icon);
QIcon icon() const;
IconItem::State state() const;
void setState(State state);
int implicitWidth() const;
int implicitHeight() const;
void setSmooth(const bool smooth);
bool smooth() const;
void setEnabled(bool enabled = true);
bool enabled() const;
QSGNode* updatePaintNode(QSGNode* node, UpdatePaintNodeData* data) Q_DECL_OVERRIDE;
Q_SIGNALS:
void stateChanged(State state);
protected:
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
private:
QIcon m_icon;
bool m_smooth;
State m_state;
bool m_changed;
};
#endif
/*
* Copyright 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.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 "imagetexturescache.h"
#include <QSGTexture>
#include <QDebug>
typedef QHash<qint64, QHash<QWindow*, QWeakPointer<QSGTexture> > > TexturesCache;
struct ImageTexturesCachePrivate
{
TexturesCache cache;
};
ImageTexturesCache::ImageTexturesCache()
: d(new ImageTexturesCachePrivate)
{
}
ImageTexturesCache::~ImageTexturesCache()
{
}
QSharedPointer<QSGTexture> ImageTexturesCache::loadTexture(QQuickWindow *window, const QImage &image, QQuickWindow::CreateTextureOptions options)
{
qint64 id = image.cacheKey();
QSharedPointer<QSGTexture> texture = d->cache.value(id).value(window).toStrongRef();
if (!texture) {
auto cleanAndDelete = [this, window, id](QSGTexture* texture) {
QHash<QWindow*, QWeakPointer<QSGTexture> >& textures = (d->cache)[id];
textures.remove(window);
if (textures.isEmpty())
d->cache.remove(id);
delete texture;
};
texture = QSharedPointer<QSGTexture>(window->createTextureFromImage(image, options), cleanAndDelete);
(d->cache)[id][window] = texture.toWeakRef();
}
//if we have a cache in an atlas but our request cannot use an atlassed texture
//create a new texture and use that
//don't use removedFromAtlas() as that requires keeping a reference to the non atlased version
if (!(options & QQuickWindow::TextureCanUseAtlas) && texture->isAtlasTexture()) {
texture = QSharedPointer<QSGTexture>(window->createTextureFromImage(image, options));
}
return texture;
}
QSharedPointer<QSGTexture> ImageTexturesCache::loadTexture(QQuickWindow *window, const QImage &image)
{
return loadTexture(window, image, 0);
}
/*
* Copyright 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.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 IMAGETEXTURESCACHE_H
#define IMAGETEXTURESCACHE_H
#include <QSharedPointer>
#include <QQuickWindow>