summaryrefslogtreecommitdiff
path: root/prototype_2016/third_party/fluid/core
diff options
context:
space:
mode:
Diffstat (limited to 'prototype_2016/third_party/fluid/core')
-rw-r--r--prototype_2016/third_party/fluid/core/CMakeLists.txt32
-rw-r--r--prototype_2016/third_party/fluid/core/Object.qml38
-rw-r--r--prototype_2016/third_party/fluid/core/PlatformExtensions.qml51
-rw-r--r--prototype_2016/third_party/fluid/core/Utils.qml106
-rw-r--r--prototype_2016/third_party/fluid/core/clipboard.cpp54
-rw-r--r--prototype_2016/third_party/fluid/core/clipboard.h41
-rw-r--r--prototype_2016/third_party/fluid/core/core.pri19
-rw-r--r--prototype_2016/third_party/fluid/core/core.qrc8
-rw-r--r--prototype_2016/third_party/fluid/core/device.cpp152
-rw-r--r--prototype_2016/third_party/fluid/core/device.h67
-rw-r--r--prototype_2016/third_party/fluid/core/doc/fluidcore.qdocconf47
-rw-r--r--prototype_2016/third_party/fluid/core/iconsimageprovider.cpp67
-rw-r--r--prototype_2016/third_party/fluid/core/iconsimageprovider.h25
-rw-r--r--prototype_2016/third_party/fluid/core/plugin.cpp90
-rw-r--r--prototype_2016/third_party/fluid/core/plugins.qmltypes268
-rw-r--r--prototype_2016/third_party/fluid/core/qmldateutils.cpp34
-rw-r--r--prototype_2016/third_party/fluid/core/qmldateutils.h42
-rw-r--r--prototype_2016/third_party/fluid/core/qmldir8
-rw-r--r--prototype_2016/third_party/fluid/core/qmldir_noplugin5
-rw-r--r--prototype_2016/third_party/fluid/core/qqmlsortfilterproxymodel.cpp283
-rw-r--r--prototype_2016/third_party/fluid/core/qqmlsortfilterproxymodel.h129
-rw-r--r--prototype_2016/third_party/fluid/core/standardpaths.cpp36
-rw-r--r--prototype_2016/third_party/fluid/core/standardpaths.h51
23 files changed, 1653 insertions, 0 deletions
diff --git a/prototype_2016/third_party/fluid/core/CMakeLists.txt b/prototype_2016/third_party/fluid/core/CMakeLists.txt
new file mode 100644
index 0000000..21bd974
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/CMakeLists.txt
@@ -0,0 +1,32 @@
1include_directories(
2 "${CMAKE_CURRENT_BINARY_DIR}/../src"
3 "${CMAKE_CURRENT_BINARY_DIR}/../src/Fluid"
4)
5
6add_definitions(-DQT_PLUGIN)
7
8set(SOURCES
9 plugin.cpp
10 clipboard.cpp
11 qmldateutils.cpp
12 device.cpp
13 iconsimageprovider.cpp
14 qqmlsortfilterproxymodel.cpp
15 standardpaths.cpp
16)
17
18add_library(fluidcore SHARED ${SOURCES})
19target_link_libraries(fluidcore Qt5::Svg Qt5::Gui Qt5::Quick Fluid)
20
21set(FILES
22 plugins.qmltypes
23 qmldir
24 Object.qml
25 PlatformExtensions.qml
26 Utils.qml
27)
28
29install(TARGETS fluidcore LIBRARY
30 DESTINATION ${QML_INSTALL_DIR}/Fluid/Core)
31install(FILES ${FILES}
32 DESTINATION ${QML_INSTALL_DIR}/Fluid/Core)
diff --git a/prototype_2016/third_party/fluid/core/Object.qml b/prototype_2016/third_party/fluid/core/Object.qml
new file mode 100644
index 0000000..abfcdde
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/Object.qml
@@ -0,0 +1,38 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15import QtQuick 2.0
16
17/*!
18 \qmltype Object
19 \inqmlmodule Fluid.Core
20 \ingroup fluidcore
21
22 \brief A QtObject with children.
23
24 The \l Object type is a non-visual element that extends \l QtObject
25 with the ability to hold children objects.
26*/
27QtObject {
28 default property alias children: object.__children
29
30 /*!
31 \qmlproperty list<QtObject> Object::children
32
33 Children objects.
34 */
35 property list<QtObject> __children: [QtObject {}]
36
37 id: object
38}
diff --git a/prototype_2016/third_party/fluid/core/PlatformExtensions.qml b/prototype_2016/third_party/fluid/core/PlatformExtensions.qml
new file mode 100644
index 0000000..ba9dcdb
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/PlatformExtensions.qml
@@ -0,0 +1,51 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2015-2016 Michael Spencer <sonrisesoftware@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15import QtQuick 2.0
16import Fluid.Core 1.0
17
18Object {
19 id: platform
20
21 property var platformExtensions
22
23 property color decorationColor
24 property var window: null
25
26 onDecorationColorChanged: {
27 if (platformExtensions && color != "#000000") {
28 platformExtensions.decorationColor = decorationColor
29 }
30 }
31
32 onWindowChanged: {
33 if (platformExtensions) {
34 platformExtensions.window = window
35 }
36 }
37
38 Component.onCompleted: {
39 try {
40 var code = 'import Liri.Platform 1.0; PlatformExtensions {}'
41 platformExtensions = Qt.createQmlObject(code, platform, "LiriExtensions");
42
43 platformExtensions.window = window
44 if (decorationColor != "#000000")
45 platformExtensions.decorationColor = decorationColor
46 } catch (error) {
47 // Ignore the error; it only means that the Papyros
48 // platform extensions are not available
49 }
50 }
51}
diff --git a/prototype_2016/third_party/fluid/core/Utils.qml b/prototype_2016/third_party/fluid/core/Utils.qml
new file mode 100644
index 0000000..7d3a480
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/Utils.qml
@@ -0,0 +1,106 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 * Copyright (C) 2017 Michael Spencer <sonrisesoftware@gmail.com>
6 *
7 * $BEGIN_LICENSE:MPL2$
8 *
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 *
13 * $END_LICENSE$
14 */
15
16import QtQuick 2.0
17
18pragma Singleton
19
20/*!
21 \qmltype Utils
22 \inqmlmodule Fluid.Core
23 \ingroup fluidcore
24
25 \brief A collection of helpful utility methods.
26
27 Currently the only utility methods are for working with colors.
28*/
29QtObject {
30 /*!
31 Make sure we have a real \l color object to work with (versus a string like "#ccc")
32 */
33 function asColor(color) {
34 return Qt.darker(color, 1)
35 }
36
37 /*!
38 A utility method for changing the alpha on colors. Returns a new object, and does not
39 modify the original color at all.
40 */
41 function alpha(color, alpha) {
42 color = asColor(color)
43
44 color.a = alpha
45
46 return color
47 }
48
49 /*!
50 Blend \a color1 and \a color2 together and set alpha to \a a.
51 */
52 function blendColors(color1, color2, a) {
53 return alpha(Qt.tint(color1, color2), a)
54 }
55
56 /*!
57 Calculate luminance of \a color.
58 */
59 function luminance(color) {
60 color = asColor(color)
61 return (color.r * 0.2126) + (color.g * 0.7152) + (color.b * 0.0722)
62 }
63
64 /*!
65 Select a color depending on whether \a background color is light or dark.
66 Returns \a lightColor if \a background is a light color, otherwise
67 returns \a darkColor.
68 */
69 function lightDark(background, lightColor, darkColor) {
70 return isDarkColor(background) ? darkColor : lightColor
71 }
72
73 /*!
74 Returns \c true if \a color is dark and should have light content on top.
75 */
76 function isDarkColor(color) {
77 color = asColor(color)
78
79 var a = 1 - (0.299 * color.r + 0.587 * color.g + 0.114 * color.b)
80
81 return color.a > 0 && a >= 0.3
82 }
83
84 /*!
85 Returns a source suitable for an \l Image from an icon name.
86 If \a name is an URL it will be returned verbatim, instead if it
87 contains a slash character an icon relative to Fluid icons/ directory
88 will be returned, otherwise an image://fluidicontheme/\a name URL.
89 */
90 function getSourceForIconName(name) {
91 return name ? name.indexOf("/") === 0 || name.indexOf("file://") === 0 || name.indexOf("qrc") === 0
92 ? name
93 : name.indexOf("/") !== -1 ? "image://fluidicons/" + name
94 : "image://fluidicontheme/" + name
95 : ""
96 }
97
98 /*!
99 Scale \a percent in the range between \a start and \a end.
100 */
101 function scale(percent, start, end) {
102 var diff = end - start
103
104 return start + percent * diff
105 }
106}
diff --git a/prototype_2016/third_party/fluid/core/clipboard.cpp b/prototype_2016/third_party/fluid/core/clipboard.cpp
new file mode 100644
index 0000000..79280d3
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/clipboard.cpp
@@ -0,0 +1,54 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 * Copyright (C) 2017 Michael Spencer <sonrisesoftware@gmail.com>
6 *
7 * $BEGIN_LICENSE:MPL2$
8 *
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 *
13 * $END_LICENSE$
14 */
15
16#include "clipboard.h"
17
18#include <QGuiApplication>
19
20/*!
21 \qmltype Clipboard
22 \inqmlmodule Fluid.Core
23 \ingroup fluidcore
24
25 \brief Clipboard.
26*/
27
28Clipboard::Clipboard(QObject *parent)
29 : QObject(parent)
30 , m_clipboard(QGuiApplication::clipboard())
31{
32 connect(m_clipboard, &QClipboard::dataChanged, this, &Clipboard::textChanged);
33}
34
35/*!
36 \qmlproperty string Clipboard::text
37
38 This property holds the clipboard text.
39*/
40
41QString Clipboard::text() const
42{
43 return m_clipboard->text();
44}
45
46void Clipboard::clear()
47{
48 m_clipboard->clear();
49}
50
51void Clipboard::setText(const QString &text)
52{
53 m_clipboard->setText(text);
54}
diff --git a/prototype_2016/third_party/fluid/core/clipboard.h b/prototype_2016/third_party/fluid/core/clipboard.h
new file mode 100644
index 0000000..72b19e7
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/clipboard.h
@@ -0,0 +1,41 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Michael Spencer <sonrisesoftware@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#pragma once
16
17#include <QObject>
18#include <QClipboard>
19
20class Clipboard : public QObject
21{
22 Q_OBJECT
23
24 Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
25
26public:
27 explicit Clipboard(QObject *parent = nullptr);
28
29 QString text() const;
30
31 Q_INVOKABLE void clear();
32
33public Q_SLOTS:
34 void setText(const QString &text);
35
36Q_SIGNALS:
37 void textChanged();
38
39private:
40 QClipboard *m_clipboard = nullptr;
41};
diff --git a/prototype_2016/third_party/fluid/core/core.pri b/prototype_2016/third_party/fluid/core/core.pri
new file mode 100644
index 0000000..16b7b9d
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/core.pri
@@ -0,0 +1,19 @@
1HEADERS += \
2 $$PWD/clipboard.h \
3 $$PWD/device.h \
4 $$PWD/iconsimageprovider.h \
5 $$PWD/qmldateutils.h \
6 $$PWD/qqmlsortfilterproxymodel.h \
7 $$PWD/standardpaths.h
8
9SOURCES += \
10 $$PWD/clipboard.cpp \
11 $$PWD/device.cpp \
12 $$PWD/iconsimageprovider.cpp \
13 $$PWD/plugin.cpp \
14 $$PWD/qmldateutils.cpp \
15 $$PWD/qqmlsortfilterproxymodel.cpp \
16 $$PWD/standardpaths.cpp
17
18RESOURCES += \
19 $$PWD/core.qrc
diff --git a/prototype_2016/third_party/fluid/core/core.qrc b/prototype_2016/third_party/fluid/core/core.qrc
new file mode 100644
index 0000000..3b17685
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/core.qrc
@@ -0,0 +1,8 @@
1<RCC>
2 <qresource prefix="/Fluid/Core">
3 <file>Object.qml</file>
4 <file>PlatformExtensions.qml</file>
5 <file>Utils.qml</file>
6 <file alias="qmldir">qmldir_noplugin</file>
7 </qresource>
8</RCC>
diff --git a/prototype_2016/third_party/fluid/core/device.cpp b/prototype_2016/third_party/fluid/core/device.cpp
new file mode 100644
index 0000000..07046b8
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/device.cpp
@@ -0,0 +1,152 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Michael Spencer <sonrisesoftware@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#include "device.h"
16
17Device::Device(QObject *parent)
18 : QObject(parent)
19{
20 m_screen = qGuiApp->primaryScreen();
21
22 connect(qGuiApp, &QGuiApplication::primaryScreenChanged, this, &Device::screenChanged);
23}
24
25Device::FormFactor Device::formFactor() const
26{
27 float diagonal = calculateDiagonal();
28
29 if (diagonal >= 3.5 && diagonal < 5) {
30 // iPhone 1st generation to phablet
31 return Device::Phone;
32 } else if (diagonal >= 5 && diagonal < 6.5) {
33 return Device::Phablet;
34 } else if (diagonal >= 6.5 && diagonal < 10.1) {
35 return Device::Tablet;
36 } else if (diagonal >= 10.1 && diagonal < 29) {
37 return Device::Computer;
38 } else if (diagonal >= 29 && diagonal < 92) {
39 return Device::TV;
40 } else {
41 return Device::Unknown;
42 }
43}
44
45QString Device::name() const
46{
47 switch (formFactor()) {
48 case Phone:
49 return tr("phone");
50 case Phablet:
51 return tr("phablet");
52 case Tablet:
53 return tr("tablet");
54 case Computer:
55 return tr("computer");
56 case TV:
57 return tr("TV");
58 case Unknown:
59 return tr("device");
60 default:
61 return tr("unknown");
62 }
63}
64
65QString Device::iconName() const
66{
67 switch (formFactor()) {
68 case Phone:
69 return "hardware/smartphone";
70 case Phablet:
71 return "hardware/tablet";
72 case Tablet:
73 return "hardware/tablet";
74 case Computer:
75 return "hardware/desktop_windows";
76 case TV:
77 return "hardware/tv";
78 case Unknown:
79 default:
80 return "hardware/computer";
81 }
82}
83
84bool Device::isPortrait() const
85{
86 return m_screen->physicalSize().height() > m_screen->physicalSize().width();
87}
88
89bool Device::hasTouchScreen() const
90{
91// QTBUG-36007
92#if defined(Q_OS_ANDROID)
93 return true;
94#else
95 const auto devices = QTouchDevice::devices();
96 foreach (const QTouchDevice *dev, devices) {
97 if (dev->type() == QTouchDevice::TouchScreen)
98 return true;
99 }
100 return false;
101#endif
102}
103
104bool Device::isMobile() const
105{
106#if defined(Q_OS_IOS) || defined(Q_OS_ANDROID) || defined(Q_OS_BLACKBERRY) || defined(Q_OS_QNX) \
107 || defined(Q_OS_WINRT)
108 return true;
109#else
110 if (qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MOBILE")) {
111 return true;
112 }
113 return false;
114#endif
115}
116
117bool Device::hoverEnabled() const
118{
119 return !isMobile() || !hasTouchScreen();
120}
121
122int Device::gridUnit() const
123{
124 Device::FormFactor formFactor = this->formFactor();
125
126 if (formFactor == Device::Phone || formFactor == Device::Phablet) {
127 return isPortrait() ? 56 : 48;
128 } else if (formFactor == Device::Tablet) {
129 return 64;
130 } else {
131 return hasTouchScreen() ? 64 : 48;
132 }
133}
134
135void Device::screenChanged()
136{
137 if (m_screen)
138 m_screen->disconnect(this);
139
140 m_screen = qGuiApp->primaryScreen();
141
142 connect(m_screen, &QScreen::geometryChanged, this, &Device::geometryChanged);
143
144 emit geometryChanged();
145}
146
147float Device::calculateDiagonal() const
148{
149 return sqrt(pow((m_screen->physicalSize().width()), 2)
150 + pow((m_screen->physicalSize().height()), 2))
151 * 0.039370;
152}
diff --git a/prototype_2016/third_party/fluid/core/device.h b/prototype_2016/third_party/fluid/core/device.h
new file mode 100644
index 0000000..113de03
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/device.h
@@ -0,0 +1,67 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Michael Spencer <sonrisesoftware@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#pragma once
16
17#include <QObject>
18
19#include <cmath>
20#include <QQmlEngine>
21#include <QGuiApplication>
22#include <QScreen>
23#include <QTouchDevice>
24
25class Device : public QObject
26{
27 Q_OBJECT
28
29 Q_PROPERTY(FormFactor formFactor READ formFactor NOTIFY geometryChanged)
30 Q_PROPERTY(QString name READ name NOTIFY geometryChanged)
31 Q_PROPERTY(QString iconName READ iconName NOTIFY geometryChanged)
32
33 Q_PROPERTY(bool isPortrait READ isPortrait NOTIFY geometryChanged)
34 Q_PROPERTY(bool isMobile READ isMobile CONSTANT)
35 Q_PROPERTY(bool hasTouchScreen READ hasTouchScreen CONSTANT)
36 Q_PROPERTY(bool hoverEnabled READ hoverEnabled CONSTANT)
37
38 Q_PROPERTY(int gridUnit READ gridUnit NOTIFY geometryChanged)
39
40public:
41 enum FormFactor { Phone, Phablet, Tablet, Computer, TV, Unknown };
42 Q_ENUM(FormFactor)
43
44 Device(QObject *parent = nullptr);
45
46 FormFactor formFactor() const;
47 QString name() const;
48 QString iconName() const;
49
50 bool isPortrait() const;
51 bool hasTouchScreen() const;
52 bool isMobile() const;
53 bool hoverEnabled() const;
54
55 int gridUnit() const;
56
57Q_SIGNALS:
58 void geometryChanged();
59
60private Q_SLOTS:
61 void screenChanged();
62
63private:
64 float calculateDiagonal() const;
65
66 QScreen *m_screen;
67};
diff --git a/prototype_2016/third_party/fluid/core/doc/fluidcore.qdocconf b/prototype_2016/third_party/fluid/core/doc/fluidcore.qdocconf
new file mode 100644
index 0000000..ffeb2b0
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/doc/fluidcore.qdocconf
@@ -0,0 +1,47 @@
1include(../../doc/defaults.qdocconf)
2
3project = FluidCore
4description = Fluid Core Reference Documentation
5version = $FLUID_VERSION
6
7qhp.projects = FluidCore
8
9qhp.Fluid.file = fluidcore.qhp
10qhp.Fluid.namespace = io.liri.fluidcore.$FLUID_VERSION_TAG
11qhp.Fluid.virtualFolder = fluidcore
12qhp.Fluid.indexTitle = Fluid Core
13qhp.Fluid.indexRoot =
14
15qhp.Fluid.filterAttributes = fluidcore $FLUID_VERSION qtrefdoc
16qhp.Fluid.customFilters.Qt.name = FluidCore $FLUID_VERSION
17qhp.Fluid.customFilters.Qt.filterAttributes = fluidcore $FLUID_VERSION
18
19qhp.Fluid.subprojects = qmltypes classes examples
20qhp.Fluid.subprojects.qmltypes.title = QML Types
21qhp.Fluid.subprojects.qmltypes.indexTitle = Fluid Core QML Types
22qhp.Fluid.subprojects.qmltypes.selectors = qmlclass
23qhp.Fluid.subprojects.qmltypes.sortPages = true
24qhp.Fluid.subprojects.classes.title = C++ Classes
25qhp.Fluid.subprojects.classes.indexTitle = Fluid Core C++ Classes
26qhp.Fluid.subprojects.classes.selectors = class fake:headerfile
27qhp.Fluid.subprojects.classes.sortPages = true
28qhp.Fluid.subprojects.examples.title = Examples
29qhp.Fluid.subprojects.examples.indexTitle = Fluid Core Examples
30qhp.Fluid.subprojects.examples.selectors = fake:example
31
32# Specify the install path under QT_INSTALL_EXAMPLES
33# Note: paths passed to \example command must contain the parent directory, e.g.
34# \example controls/tabs
35#exampledirs += snippets
36
37#examplesinstallpath = fluid
38
39headerdirs += .
40
41sourcedirs += . src
42
43imagedirs += images
44
45navigation.landingpage = "Fluid Core"
46navigation.qmltypespage = "Fluid Core QML Types"
47navigation.cppclassespage = "Fluid Core C++ Classes"
diff --git a/prototype_2016/third_party/fluid/core/iconsimageprovider.cpp b/prototype_2016/third_party/fluid/core/iconsimageprovider.cpp
new file mode 100644
index 0000000..2ffbe10
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/iconsimageprovider.cpp
@@ -0,0 +1,67 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#include <QtCore/QDir>
16#include <QtSvg/QSvgRenderer>
17#include <QtGui/QPainter>
18#include <QtQml/QQmlEngine>
19
20#include "iconsimageprovider.h"
21
22IconsImageProvider::IconsImageProvider()
23 : QQuickImageProvider(QQuickImageProvider::Image)
24{
25}
26
27QImage IconsImageProvider::requestImage(const QString &id, QSize *realSize,
28 const QSize &requestedSize)
29{
30 // Sanitize requested size
31 QSize size(requestedSize);
32 if (size.width() < 1)
33 size.setWidth(1);
34 if (size.height() < 1)
35 size.setHeight(1);
36
37 // Return real size
38 if (realSize)
39 *realSize = size;
40
41#ifdef FLUID_LOCAL
42 QSvgRenderer renderer(QLatin1String("qrc:/Fluid/Controls/") + id + QLatin1String(".svg"));
43 QImage image(size, QImage::Format_ARGB32);
44 image.fill(Qt::transparent);
45 QPainter painter(&image);
46 renderer.render(&painter);
47 return image;
48#else
49 const QString targetPath = QStringLiteral("Fluid/Controls/icons");
50 const QStringList importPaths = QQmlEngine().importPathList();
51
52 for (const QString &importPath: importPaths) {
53 QDir dir(importPath);
54 if (dir.exists(targetPath)) {
55 QDir targetDir(dir.absoluteFilePath(targetPath));
56 QSvgRenderer renderer(targetDir.absoluteFilePath(id + QLatin1String(".svg")));
57 QImage image(size, QImage::Format_ARGB32);
58 image.fill(Qt::transparent);
59 QPainter painter(&image);
60 renderer.render(&painter);
61 return image;
62 }
63 }
64
65 return QImage();
66#endif
67}
diff --git a/prototype_2016/third_party/fluid/core/iconsimageprovider.h b/prototype_2016/third_party/fluid/core/iconsimageprovider.h
new file mode 100644
index 0000000..f30a705
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/iconsimageprovider.h
@@ -0,0 +1,25 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#pragma once
16
17#include <QtQuick/QQuickImageProvider>
18
19class IconsImageProvider : public QQuickImageProvider
20{
21public:
22 IconsImageProvider();
23
24 QImage requestImage(const QString &id, QSize *realSize, const QSize &requestedSize);
25};
diff --git a/prototype_2016/third_party/fluid/core/plugin.cpp b/prototype_2016/third_party/fluid/core/plugin.cpp
new file mode 100644
index 0000000..511b439
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/plugin.cpp
@@ -0,0 +1,90 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#include <QtQml/QQmlExtensionPlugin>
16#include <QtQml/qqml.h>
17
18#include "clipboard.h"
19#include "device.h"
20#include "iconsimageprovider.h"
21#include "qmldateutils.h"
22#include "qqmlsortfilterproxymodel.h"
23#include "standardpaths.h"
24
25static QObject *dateUtilsProvider(QQmlEngine *engine, QJSEngine *jsEngine)
26{
27 Q_UNUSED(engine);
28 Q_UNUSED(jsEngine);
29
30 return new DateUtils();
31}
32
33static QObject *deviceProvider(QQmlEngine *engine, QJSEngine *jsEngine)
34{
35 Q_UNUSED(engine);
36 Q_UNUSED(jsEngine);
37
38 return new Device();
39}
40
41static QObject *standardPathsProvider(QQmlEngine *engine, QJSEngine *jsEngine)
42{
43 Q_UNUSED(engine);
44 Q_UNUSED(jsEngine);
45
46 return new StandardPaths();
47}
48
49class FluidCorePlugin : public QQmlExtensionPlugin
50{
51 Q_OBJECT
52 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
53public:
54 void initializeEngine(QQmlEngine *engine, const char *uri);
55 void registerTypes(const char *uri);
56};
57
58void FluidCorePlugin::initializeEngine(QQmlEngine *engine, const char *uri)
59{
60 Q_ASSERT(QByteArray(uri) == QByteArrayLiteral("Fluid.Core"));
61
62 engine->addImageProvider(QLatin1String("fluidicons"), new IconsImageProvider());
63}
64
65void FluidCorePlugin::registerTypes(const char *uri)
66{
67 Q_ASSERT(QByteArray("Fluid.Core") == QByteArray(uri));
68
69 // @uri Fluid.Core
70
71 qmlRegisterType<Clipboard>(uri, 1, 0, "Clipboard");
72
73 qmlRegisterType<QAbstractItemModel>();
74 qmlRegisterType<QQmlSortFilterProxyModel>(uri, 1, 0, "SortFilterProxyModel");
75
76 qmlRegisterSingletonType<DateUtils>(uri, 1, 0, "DateUtils", dateUtilsProvider);
77 qmlRegisterSingletonType<Device>(uri, 1, 0, "Device", deviceProvider);
78 qmlRegisterSingletonType<StandardPaths>(uri, 1, 0, "StandardPaths", standardPathsProvider);
79}
80
81#ifdef FLUID_LOCAL
82static void registerFluidCoreTypes() {
83 FluidCorePlugin fluidCore;
84 fluidCore.registerTypes("Fluid.Core");
85}
86
87Q_COREAPP_STARTUP_FUNCTION(registerFluidCoreTypes)
88#endif
89
90#include "plugin.moc"
diff --git a/prototype_2016/third_party/fluid/core/plugins.qmltypes b/prototype_2016/third_party/fluid/core/plugins.qmltypes
new file mode 100644
index 0000000..f8f71ef
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/plugins.qmltypes
@@ -0,0 +1,268 @@
1import QtQuick.tooling 1.2
2
3// This file describes the plugin-supplied types contained in the library.
4// It is used for QML tooling purposes only.
5//
6// This file was auto-generated by:
7// 'qmlplugindump-qt5 -nonrelocatable Fluid.Core 1.0'
8
9Module {
10 dependencies: ["QtQuick 2.0"]
11 Component {
12 name: "Clipboard"
13 prototype: "QObject"
14 exports: ["Fluid.Core/Clipboard 1.0"]
15 exportMetaObjectRevisions: [0]
16 Property { name: "text"; type: "string" }
17 Method {
18 name: "setText"
19 Parameter { name: "text"; type: "string" }
20 }
21 Method { name: "clear" }
22 }
23 Component {
24 name: "DateUtils"
25 prototype: "QObject"
26 exports: ["Fluid.Core/DateUtils 1.0"]
27 isCreatable: false
28 isSingleton: true
29 exportMetaObjectRevisions: [0]
30 Enum {
31 name: "DurationFormat"
32 values: {
33 "Long": 0,
34 "Short": 1
35 }
36 }
37 Enum {
38 name: "DurationType"
39 values: {
40 "Seconds": 0,
41 "Minutes": 1,
42 "Hours": 2,
43 "Any": 3
44 }
45 }
46 Method {
47 name: "formatDuration"
48 type: "string"
49 Parameter { name: "duration"; type: "qlonglong" }
50 Parameter { name: "format"; type: "DurationFormat" }
51 Parameter { name: "type"; type: "DurationType" }
52 }
53 Method {
54 name: "formatDuration"
55 type: "string"
56 Parameter { name: "duration"; type: "qlonglong" }
57 Parameter { name: "format"; type: "DurationFormat" }
58 }
59 Method {
60 name: "formatDuration"
61 type: "string"
62 Parameter { name: "duration"; type: "qlonglong" }
63 }
64 }
65 Component {
66 name: "Device"
67 prototype: "QObject"
68 exports: ["Fluid.Core/Device 1.0"]
69 isCreatable: false
70 isSingleton: true
71 exportMetaObjectRevisions: [0]
72 Enum {
73 name: "FormFactor"
74 values: {
75 "Phone": 0,
76 "Phablet": 1,
77 "Tablet": 2,
78 "Computer": 3,
79 "TV": 4,
80 "Unknown": 5
81 }
82 }
83 Property { name: "formFactor"; type: "FormFactor"; isReadonly: true }
84 Property { name: "name"; type: "string"; isReadonly: true }
85 Property { name: "iconName"; type: "string"; isReadonly: true }
86 Property { name: "isPortrait"; type: "bool"; isReadonly: true }
87 Property { name: "isMobile"; type: "bool"; isReadonly: true }
88 Property { name: "hasTouchScreen"; type: "bool"; isReadonly: true }
89 Property { name: "hoverEnabled"; type: "bool"; isReadonly: true }
90 Property { name: "gridUnit"; type: "int"; isReadonly: true }
91 Signal { name: "geometryChanged" }
92 }
93 Component {
94 name: "QAbstractProxyModel"
95 prototype: "QAbstractItemModel"
96 Property { name: "sourceModel"; type: "QAbstractItemModel"; isPointer: true }
97 Method {
98 name: "mapToSource"
99 type: "QModelIndex"
100 Parameter { name: "proxyIndex"; type: "QModelIndex" }
101 }
102 Method {
103 name: "mapFromSource"
104 type: "QModelIndex"
105 Parameter { name: "sourceIndex"; type: "QModelIndex" }
106 }
107 Method {
108 name: "mapSelectionToSource"
109 type: "QItemSelection"
110 Parameter { name: "selection"; type: "QItemSelection" }
111 }
112 Method {
113 name: "mapSelectionFromSource"
114 type: "QItemSelection"
115 Parameter { name: "selection"; type: "QItemSelection" }
116 }
117 }
118 Component {
119 name: "QQmlSortFilterProxyModel"
120 prototype: "QSortFilterProxyModel"
121 exports: ["Fluid.Core/SortFilterProxyModel 1.0"]
122 exportMetaObjectRevisions: [0]
123 Enum {
124 name: "PatternSyntax"
125 values: {
126 "RegExp": 0,
127 "Wildcard": 1,
128 "FixedString": 2,
129 "RegExp2": 3,
130 "WildcardUnix": 4,
131 "W3CXmlSchema11": 5
132 }
133 }
134 Property { name: "count"; type: "int"; isReadonly: true }
135 Property { name: "filterRoleName"; type: "string" }
136 Property { name: "filterPattern"; type: "string" }
137 Property { name: "filterPatternSyntax"; type: "PatternSyntax" }
138 Property { name: "filterValue"; type: "QVariant" }
139 Property { name: "filterExpression"; type: "QQmlScriptString" }
140 Property { name: "sortRoleName"; type: "string" }
141 Property { name: "sortOrder"; type: "Qt::SortOrder" }
142 Property { name: "sortExpression"; type: "QQmlScriptString" }
143 }
144 Component {
145 name: "QSortFilterProxyModel"
146 prototype: "QAbstractProxyModel"
147 Property { name: "filterRegExp"; type: "QRegExp" }
148 Property { name: "filterKeyColumn"; type: "int" }
149 Property { name: "dynamicSortFilter"; type: "bool" }
150 Property { name: "filterCaseSensitivity"; type: "Qt::CaseSensitivity" }
151 Property { name: "sortCaseSensitivity"; type: "Qt::CaseSensitivity" }
152 Property { name: "isSortLocaleAware"; type: "bool" }
153 Property { name: "sortRole"; type: "int" }
154 Property { name: "filterRole"; type: "int" }
155 Method {
156 name: "setFilterRegExp"
157 Parameter { name: "pattern"; type: "string" }
158 }
159 Method {
160 name: "setFilterWildcard"
161 Parameter { name: "pattern"; type: "string" }
162 }
163 Method {
164 name: "setFilterFixedString"
165 Parameter { name: "pattern"; type: "string" }
166 }
167 Method { name: "clear" }
168 Method { name: "invalidate" }
169 }
170 Component {
171 name: "StandardPaths"
172 prototype: "QObject"
173 exports: ["Fluid.Core/StandardPaths 1.0"]
174 isCreatable: false
175 isSingleton: true
176 exportMetaObjectRevisions: [0]
177 Enum {
178 name: "StandardLocation"
179 values: {
180 "DesktopLocation": 0,
181 "DocumentsLocation": 1,
182 "FontsLocation": 2,
183 "ApplicationsLocation": 3,
184 "MusicLocation": 4,
185 "MoviesLocation": 5,
186 "PicturesLocation": 6,
187 "TempLocation": 7,
188 "HomeLocation": 8,
189 "DataLocation": 9,
190 "CacheLocation": 10,
191 "GenericDataLocation": 11,
192 "RuntimeLocation": 12,
193 "ConfigLocation": 13,
194 "DownloadLocation": 14,
195 "GenericCacheLocation": 15,
196 "GenericConfigLocation": 16
197 }
198 }
199 Method {
200 name: "locateFile"
201 type: "string"
202 Parameter { name: "type"; type: "StandardLocation" }
203 Parameter { name: "fileName"; type: "string" }
204 }
205 Method {
206 name: "locateDirectory"
207 type: "string"
208 Parameter { name: "type"; type: "StandardLocation" }
209 Parameter { name: "dirName"; type: "string" }
210 }
211 }
212 Component {
213 prototype: "QObject"
214 name: "Utils 1.0"
215 exports: ["Utils 1.0"]
216 exportMetaObjectRevisions: [0]
217 isComposite: true
218 isCreatable: false
219 isSingleton: true
220 Method {
221 name: "asColor"
222 type: "QVariant"
223 Parameter { name: "color"; type: "QVariant" }
224 }
225 Method {
226 name: "alpha"
227 type: "QVariant"
228 Parameter { name: "color"; type: "QVariant" }
229 Parameter { name: "alpha"; type: "QVariant" }
230 }
231 Method {
232 name: "blendColors"
233 type: "QVariant"
234 Parameter { name: "color1"; type: "QVariant" }
235 Parameter { name: "color2"; type: "QVariant" }
236 Parameter { name: "a"; type: "QVariant" }
237 }
238 Method {
239 name: "luminance"
240 type: "QVariant"
241 Parameter { name: "color"; type: "QVariant" }
242 }
243 Method {
244 name: "lightDark"
245 type: "QVariant"
246 Parameter { name: "background"; type: "QVariant" }
247 Parameter { name: "lightColor"; type: "QVariant" }
248 Parameter { name: "darkColor"; type: "QVariant" }
249 }
250 Method {
251 name: "isDarkColor"
252 type: "QVariant"
253 Parameter { name: "color"; type: "QVariant" }
254 }
255 Method {
256 name: "getSourceForIconName"
257 type: "QVariant"
258 Parameter { name: "name"; type: "QVariant" }
259 }
260 Method {
261 name: "scale"
262 type: "QVariant"
263 Parameter { name: "percent"; type: "QVariant" }
264 Parameter { name: "start"; type: "QVariant" }
265 Parameter { name: "end"; type: "QVariant" }
266 }
267 }
268}
diff --git a/prototype_2016/third_party/fluid/core/qmldateutils.cpp b/prototype_2016/third_party/fluid/core/qmldateutils.cpp
new file mode 100644
index 0000000..a060f26
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/qmldateutils.cpp
@@ -0,0 +1,34 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 * Copyright (C) 2017 Michael Spencer <sonrisesoftware@gmail.com>
6 *
7 * $BEGIN_LICENSE:MPL2$
8 *
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 *
13 * $END_LICENSE$
14 */
15
16#include "qmldateutils.h"
17
18DateUtils::DateUtils(QObject *parent)
19 : QObject(parent)
20{
21}
22
23QString DateUtils::formatDuration(qlonglong duration, DurationFormat format,
24 DurationType type) const
25{
26 return Fluid::DateUtils::formatDuration(duration,
27 static_cast<Fluid::DateUtils::DurationFormat>(format),
28 static_cast<Fluid::DateUtils::DurationType>(type));
29}
30
31QString DateUtils::friendlyTime(const QDateTime &time, bool standalone) const
32{
33 return Fluid::DateUtils::friendlyTime(time, standalone);
34}
diff --git a/prototype_2016/third_party/fluid/core/qmldateutils.h b/prototype_2016/third_party/fluid/core/qmldateutils.h
new file mode 100644
index 0000000..29fffbe
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/qmldateutils.h
@@ -0,0 +1,42 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 * Copyright (C) 2017 Michael Spencer <sonrisesoftware@gmail.com>
6 *
7 * $BEGIN_LICENSE:MPL2$
8 *
9 * This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 *
13 * $END_LICENSE$
14 */
15
16#pragma once
17
18#ifdef FLUID_LOCAL
19 #include "../src/dateutils.h"
20#else
21 #include <Fluid/DateUtils>
22#endif
23#include <QtCore/QObject>
24
25class DateUtils : public QObject
26{
27 Q_OBJECT
28
29public:
30 enum DurationFormat { Long, Short };
31 Q_ENUM(DurationFormat)
32
33 enum DurationType { Seconds, Minutes, Hours, Any };
34 Q_ENUM(DurationType)
35
36 DateUtils(QObject *parent = nullptr);
37
38 Q_INVOKABLE QString formatDuration(qlonglong duration,
39 DurationFormat format = DurationFormat::Short,
40 DurationType type = DurationType::Any) const;
41 Q_INVOKABLE QString friendlyTime(const QDateTime &time, bool standalone) const;
42};
diff --git a/prototype_2016/third_party/fluid/core/qmldir b/prototype_2016/third_party/fluid/core/qmldir
new file mode 100644
index 0000000..07b5022
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/qmldir
@@ -0,0 +1,8 @@
1module Fluid.Core
2plugin fluidcore
3class FluidCorePlugin
4typeinfo plugins.qmltypes
5
6Object 1.0 Object.qml
7PlatformExtensions 1.0 PlatformExtensions.qml
8singleton Utils 1.0 Utils.qml
diff --git a/prototype_2016/third_party/fluid/core/qmldir_noplugin b/prototype_2016/third_party/fluid/core/qmldir_noplugin
new file mode 100644
index 0000000..c22216e
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/qmldir_noplugin
@@ -0,0 +1,5 @@
1module Fluid.Core
2typeinfo plugins.qmltypes
3
4Object 1.0 Object.qml
5singleton Utils 1.0 Utils.qml
diff --git a/prototype_2016/third_party/fluid/core/qqmlsortfilterproxymodel.cpp b/prototype_2016/third_party/fluid/core/qqmlsortfilterproxymodel.cpp
new file mode 100644
index 0000000..0f88cc0
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/qqmlsortfilterproxymodel.cpp
@@ -0,0 +1,283 @@
1/****************************************************************************
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pierre-Yves Siret
5 *
6 * $BEGIN_LICENSE:MIT$
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 *
26 * $END_LICENSE$
27 ***************************************************************************/
28
29#include "qqmlsortfilterproxymodel.h"
30#include <QtQml>
31
32QQmlSortFilterProxyModel::QQmlSortFilterProxyModel(QObject *parent)
33 : QSortFilterProxyModel(parent)
34 , m_filterExpression(0)
35 , m_compareExpression(0)
36{
37 connect(this, &QAbstractProxyModel::sourceModelChanged, this,
38 &QQmlSortFilterProxyModel::updateRoles);
39 connect(this, &QAbstractItemModel::modelReset, this, &QQmlSortFilterProxyModel::updateRoles);
40 connect(this, &QAbstractItemModel::rowsInserted, this, &QQmlSortFilterProxyModel::countChanged);
41 connect(this, &QAbstractItemModel::rowsRemoved, this, &QQmlSortFilterProxyModel::countChanged);
42 connect(this, &QAbstractItemModel::modelReset, this, &QQmlSortFilterProxyModel::countChanged);
43 connect(this, &QAbstractItemModel::layoutChanged, this,
44 &QQmlSortFilterProxyModel::countChanged);
45 setDynamicSortFilter(true);
46}
47
48int QQmlSortFilterProxyModel::count() const
49{
50 return rowCount();
51}
52
53const QString &QQmlSortFilterProxyModel::filterRoleName() const
54{
55 return m_filterRoleName;
56}
57
58void QQmlSortFilterProxyModel::setFilterRoleName(const QString &filterRoleName)
59{
60 if (m_filterRoleName == filterRoleName)
61 return;
62
63 m_filterRoleName = filterRoleName;
64 updateFilterRole();
65 emit filterRoleNameChanged();
66}
67
68QString QQmlSortFilterProxyModel::filterPattern() const
69{
70 return filterRegExp().pattern();
71}
72
73void QQmlSortFilterProxyModel::setFilterPattern(const QString &filterPattern)
74{
75 QRegExp regExp = filterRegExp();
76 if (regExp.pattern() == filterPattern)
77 return;
78
79 regExp.setPattern(filterPattern);
80 QSortFilterProxyModel::setFilterRegExp(regExp);
81 emit filterPatternChanged();
82}
83
84QQmlSortFilterProxyModel::PatternSyntax QQmlSortFilterProxyModel::filterPatternSyntax() const
85{
86 return static_cast<PatternSyntax>(filterRegExp().patternSyntax());
87}
88
89void QQmlSortFilterProxyModel::setFilterPatternSyntax(
90 QQmlSortFilterProxyModel::PatternSyntax patternSyntax)
91{
92 QRegExp regExp = filterRegExp();
93 QRegExp::PatternSyntax patternSyntaxTmp = static_cast<QRegExp::PatternSyntax>(patternSyntax);
94 if (regExp.patternSyntax() == patternSyntaxTmp)
95 return;
96
97 regExp.setPatternSyntax(patternSyntaxTmp);
98 QSortFilterProxyModel::setFilterRegExp(regExp);
99 emit filterPatternSyntaxChanged();
100}
101
102const QVariant &QQmlSortFilterProxyModel::filterValue() const
103{
104 return m_filterValue;
105}
106
107void QQmlSortFilterProxyModel::setFilterValue(const QVariant &filterValue)
108{
109 if (m_filterValue == filterValue)
110 return;
111
112 m_filterValue = filterValue;
113 invalidateFilter();
114 emit filterValueChanged();
115}
116
117const QQmlScriptString &QQmlSortFilterProxyModel::filterExpression() const
118{
119 return m_filterScriptString;
120}
121
122void QQmlSortFilterProxyModel::setFilterExpression(const QQmlScriptString &filterScriptString)
123{
124 if (m_filterScriptString == filterScriptString)
125 return;
126
127 m_filterScriptString = filterScriptString;
128 QQmlContext *context = new QQmlContext(qmlContext(this));
129
130 QVariantMap map;
131 Q_FOREACH (const QByteArray &roleName, roleNames().values())
132 map.insert(roleName, QVariant());
133
134 context->setContextProperty("model", map);
135 context->setContextProperty("index", -1);
136
137 delete (m_filterExpression);
138 m_filterExpression = new QQmlExpression(m_filterScriptString, context, 0, this);
139 connect(m_filterExpression, &QQmlExpression::valueChanged, this,
140 &QQmlSortFilterProxyModel::invalidateFilter);
141 m_filterExpression->setNotifyOnValueChanged(true);
142 m_filterExpression->evaluate();
143
144 emit filterExpressionChanged();
145}
146
147const QString &QQmlSortFilterProxyModel::sortRoleName() const
148{
149 return m_sortRoleName;
150}
151
152void QQmlSortFilterProxyModel::setSortRoleName(const QString &sortRoleName)
153{
154 if (m_sortRoleName == sortRoleName)
155 return;
156
157 m_sortRoleName = sortRoleName;
158 updateSortRole();
159 emit sortRoleNameChanged();
160}
161
162void QQmlSortFilterProxyModel::setSortOrder(Qt::SortOrder sortOrder)
163{
164 if (!m_sortRoleName.isEmpty())
165 sort(0, sortOrder);
166}
167
168const QQmlScriptString &QQmlSortFilterProxyModel::sortExpression() const
169{
170 return m_compareScriptString;
171}
172
173void QQmlSortFilterProxyModel::setSortExpression(const QQmlScriptString &compareScriptString)
174{
175 if (m_compareScriptString == compareScriptString)
176 return;
177
178 m_compareScriptString = compareScriptString;
179 QQmlContext *context = new QQmlContext(qmlContext(this));
180
181 QVariantMap map;
182 Q_FOREACH (const QByteArray &roleName, roleNames().values())
183 map.insert(roleName, QVariant());
184
185 context->setContextProperty("modelLeft", map);
186 context->setContextProperty("indexLeft", -1);
187 context->setContextProperty("modelRight", map);
188 context->setContextProperty("indexRight", -1);
189
190 delete (m_compareExpression);
191 m_compareExpression = new QQmlExpression(m_compareScriptString, context, 0, this);
192 connect(m_compareExpression, &QQmlExpression::valueChanged, this,
193 &QQmlSortFilterProxyModel::invalidate);
194 m_compareExpression->setNotifyOnValueChanged(true);
195 m_compareExpression->evaluate();
196
197 emit sortExpressionChanged();
198}
199
200bool QQmlSortFilterProxyModel::filterAcceptsRow(int source_row,
201 const QModelIndex &source_parent) const
202{
203 QModelIndex modelIndex = sourceModel()->index(source_row, 0, source_parent);
204 bool valueAccepted = !m_filterValue.isValid()
205 || (m_filterValue == sourceModel()->data(modelIndex, filterRole()));
206 bool baseAcceptsRow =
207 valueAccepted && QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
208 if (baseAcceptsRow && !m_filterScriptString.isEmpty()) {
209 QVariantMap map = modelDataMap(modelIndex);
210
211 QQmlContext context(qmlContext(this));
212 context.setContextProperty("model", map);
213 context.setContextProperty("index", source_row);
214 QQmlExpression expression(m_filterScriptString, &context, 0);
215 QVariant result = expression.evaluate();
216
217 if (!expression.hasError())
218 return result.toBool();
219 else
220 qWarning() << expression.error();
221 }
222 return baseAcceptsRow;
223}
224
225bool QQmlSortFilterProxyModel::lessThan(const QModelIndex &source_left,
226 const QModelIndex &source_right) const
227{
228 if (!m_compareScriptString.isEmpty()) {
229 QQmlContext context(qmlContext(this));
230 context.setContextProperty("modelLeft", modelDataMap(source_left));
231 context.setContextProperty("indexLeft", source_left.row());
232 context.setContextProperty("modelRight", modelDataMap(source_right));
233 context.setContextProperty("indexRight", source_right.row());
234
235 QQmlExpression expression(m_compareScriptString, &context, 0);
236 QVariant result = expression.evaluate();
237
238 if (!expression.hasError())
239 return result.toBool();
240 else
241 qWarning() << expression.error();
242 }
243 return QSortFilterProxyModel::lessThan(source_left, source_right);
244}
245
246void QQmlSortFilterProxyModel::invalidateFilter()
247{
248 QSortFilterProxyModel::invalidateFilter();
249}
250
251void QQmlSortFilterProxyModel::updateFilterRole()
252{
253 QList<int> filterRoles = roleNames().keys(m_filterRoleName.toUtf8());
254 if (!filterRoles.empty()) {
255 setFilterRole(filterRoles.first());
256 }
257}
258
259void QQmlSortFilterProxyModel::updateSortRole()
260{
261 QList<int> sortRoles = roleNames().keys(m_sortRoleName.toUtf8());
262 if (!sortRoles.empty()) {
263 setSortRole(sortRoles.first());
264 sort(0, sortOrder());
265 }
266}
267
268void QQmlSortFilterProxyModel::updateRoles()
269{
270 updateFilterRole();
271 updateSortRole();
272}
273
274QVariantMap QQmlSortFilterProxyModel::modelDataMap(const QModelIndex &modelIndex) const
275{
276 QVariantMap map;
277 QHash<int, QByteArray> roles = roleNames();
278 for (QHash<int, QByteArray>::const_iterator it = roles.begin(); it != roles.end(); ++it)
279 map.insert(it.value(), sourceModel()->data(modelIndex, it.key()));
280 return map;
281}
282
283#include "moc_qqmlsortfilterproxymodel.cpp"
diff --git a/prototype_2016/third_party/fluid/core/qqmlsortfilterproxymodel.h b/prototype_2016/third_party/fluid/core/qqmlsortfilterproxymodel.h
new file mode 100644
index 0000000..58f09e7
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/qqmlsortfilterproxymodel.h
@@ -0,0 +1,129 @@
1/****************************************************************************
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pierre-Yves Siret
5 *
6 * $BEGIN_LICENSE:MIT$
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 *
26 * $END_LICENSE$
27 ***************************************************************************/
28
29#ifndef QQMLSORTFILTERPROXYMODEL_H
30#define QQMLSORTFILTERPROXYMODEL_H
31
32#include <QSortFilterProxyModel>
33#include <QQmlExpression>
34
35class QQmlSortFilterProxyModel : public QSortFilterProxyModel
36{
37 Q_OBJECT
38 Q_PROPERTY(int count READ count NOTIFY countChanged)
39 Q_PROPERTY(QString filterRoleName READ filterRoleName WRITE setFilterRoleName NOTIFY
40 filterRoleNameChanged)
41 Q_PROPERTY(
42 QString filterPattern READ filterPattern WRITE setFilterPattern NOTIFY filterPatternChanged)
43 Q_PROPERTY(PatternSyntax filterPatternSyntax READ filterPatternSyntax WRITE
44 setFilterPatternSyntax NOTIFY filterPatternSyntaxChanged)
45 Q_PROPERTY(QVariant filterValue READ filterValue WRITE setFilterValue NOTIFY filterValueChanged)
46 Q_PROPERTY(QQmlScriptString filterExpression READ filterExpression WRITE setFilterExpression
47 NOTIFY filterExpressionChanged)
48
49 Q_PROPERTY(
50 QString sortRoleName READ sortRoleName WRITE setSortRoleName NOTIFY sortRoleNameChanged)
51 Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder)
52 Q_PROPERTY(QQmlScriptString sortExpression READ sortExpression WRITE setSortExpression NOTIFY
53 sortExpressionChanged)
54
55public:
56 enum PatternSyntax {
57 RegExp = QRegExp::RegExp,
58 Wildcard = QRegExp::Wildcard,
59 FixedString = QRegExp::FixedString,
60 RegExp2 = QRegExp::RegExp2,
61 WildcardUnix = QRegExp::WildcardUnix,
62 W3CXmlSchema11 = QRegExp::W3CXmlSchema11
63 };
64 Q_ENUM(PatternSyntax)
65
66 QQmlSortFilterProxyModel(QObject *parent = 0);
67
68 int count() const;
69
70 const QString &filterRoleName() const;
71 void setFilterRoleName(const QString &filterRoleName);
72
73 QString filterPattern() const;
74 void setFilterPattern(const QString &filterPattern);
75
76 PatternSyntax filterPatternSyntax() const;
77 void setFilterPatternSyntax(PatternSyntax patternSyntax);
78
79 const QVariant &filterValue() const;
80 void setFilterValue(const QVariant &filterValue);
81
82 const QQmlScriptString &filterExpression() const;
83 void setFilterExpression(const QQmlScriptString &filterScriptString);
84
85 const QString &sortRoleName() const;
86 void setSortRoleName(const QString &sortRoleName);
87
88 void setSortOrder(Qt::SortOrder sortOrder);
89
90 const QQmlScriptString &sortExpression() const;
91 void setSortExpression(const QQmlScriptString &compareScriptString);
92
93signals:
94 void countChanged();
95
96 void filterRoleNameChanged();
97 void filterPatternSyntaxChanged();
98 void filterPatternChanged();
99 void filterValueChanged();
100 void filterExpressionChanged();
101
102 void sortRoleNameChanged();
103 void sortExpressionChanged();
104
105protected:
106 bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
107 bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const;
108
109private slots:
110 void invalidateFilter();
111 void updateFilterRole();
112 void updateSortRole();
113 void updateRoles();
114
115private:
116 QVariantMap modelDataMap(const QModelIndex &modelIndex) const;
117
118 QString m_filterRoleName;
119 QString m_sortRoleName;
120
121 QQmlScriptString m_filterScriptString;
122 QQmlExpression *m_filterExpression;
123
124 QQmlScriptString m_compareScriptString;
125 QQmlExpression *m_compareExpression;
126 QVariant m_filterValue;
127};
128
129#endif // QQMLSORTFILTERPROXYMODEL_H
diff --git a/prototype_2016/third_party/fluid/core/standardpaths.cpp b/prototype_2016/third_party/fluid/core/standardpaths.cpp
new file mode 100644
index 0000000..ec67683
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/standardpaths.cpp
@@ -0,0 +1,36 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#include <QtCore/QStandardPaths>
16
17#include "standardpaths.h"
18
19StandardPaths::StandardPaths(QObject *parent)
20 : QObject(parent)
21{
22}
23
24QString StandardPaths::locateFile(StandardLocation type, const QString &fileName)
25{
26 QStandardPaths::StandardLocation qtype = static_cast<QStandardPaths::StandardLocation>(type);
27 return QStandardPaths::locate(qtype, fileName);
28}
29
30QString StandardPaths::locateDirectory(StandardLocation type, const QString &dirName)
31{
32 QStandardPaths::StandardLocation qtype = static_cast<QStandardPaths::StandardLocation>(type);
33 return QStandardPaths::locate(qtype, dirName, QStandardPaths::LocateDirectory);
34}
35
36#include "moc_standardpaths.cpp"
diff --git a/prototype_2016/third_party/fluid/core/standardpaths.h b/prototype_2016/third_party/fluid/core/standardpaths.h
new file mode 100644
index 0000000..6f3d0bc
--- /dev/null
+++ b/prototype_2016/third_party/fluid/core/standardpaths.h
@@ -0,0 +1,51 @@
1/*
2 * This file is part of Fluid.
3 *
4 * Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
5 *
6 * $BEGIN_LICENSE:MPL2$
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 *
12 * $END_LICENSE$
13 */
14
15#ifndef STANDARDPATHS_H
16#define STANDARDPATHS_H
17
18#include <QtCore/QObject>
19
20class StandardPaths : public QObject
21{
22 Q_OBJECT
23public:
24 enum StandardLocation {
25 DesktopLocation,
26 DocumentsLocation,
27 FontsLocation,
28 ApplicationsLocation,
29 MusicLocation,
30 MoviesLocation,
31 PicturesLocation,
32 TempLocation,
33 HomeLocation,
34 DataLocation,
35 CacheLocation,
36 GenericDataLocation,
37 RuntimeLocation,
38 ConfigLocation,
39 DownloadLocation,
40 GenericCacheLocation,
41 GenericConfigLocation
42 };
43 Q_ENUM(StandardLocation)
44
45 StandardPaths(QObject *parent = 0);
46
47 Q_INVOKABLE QString locateFile(StandardLocation type, const QString &fileName);
48 Q_INVOKABLE QString locateDirectory(StandardLocation type, const QString &dirName);
49};
50
51#endif // STANDARDPATHS_H