feat: Set up catalog app (sandbox)

Closes #5
This commit is contained in:
B.Melnik 2021-05-04 21:31:15 +03:00 committed by Michał Cieślak
parent afe2388c1b
commit 6c62e1c20b
13 changed files with 307 additions and 0 deletions

11
ui/StatusQ/.gitignore vendored
View File

@ -1 +1,12 @@
.DS_Store
moc_*
*.pro.user
qrc_*
*.o
build-*
*.qmlc
bin
*.app
*.autosave
Makefile
.qmake.stash

View File

@ -0,0 +1,22 @@
import QtQuick 2.14
import QtQuick.Layouts 1.14
import StatusQ.Core 0.1
GridLayout {
columns: 6
columnSpacing: 5
rowSpacing: 5
property color iconColor
Repeater {
model: ["activity", "add-circle", "add-contact", "add",
"address", "admin", "airdrop", "animals-and-nature",
"browser", "arbitrator", "camera", "chat", "channel",
"chatbot", "checkmark", "clear", "code", "communities"]
delegate: StatusIcon {
icon: modelData
color: iconColor
}
}
}

View File

@ -0,0 +1,6 @@
#include "handler.h"
Handler::Handler(QObject *parent) : QObject(parent)
{
}

View File

@ -0,0 +1,16 @@
#ifndef HANDLER_H
#define HANDLER_H
#include <QObject>
class Handler : public QObject
{
Q_OBJECT
public:
explicit Handler(QObject *parent = nullptr);
signals:
void restartQml();
};
#endif // HANDLER_H

View File

@ -0,0 +1,17 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QDebug>
#include "sandboxapp.h"
int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
SandboxApp app(argc, argv);
app.startEngine();
return app.exec();
}

135
ui/StatusQ/sandbox/main.qml Normal file
View File

@ -0,0 +1,135 @@
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.14
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
Window {
id: rootWindow
width: 640
height: 480
visible: true
title: qsTr("Status App Sandbox")
ButtonGroup {
id: topicsGroup
buttons: tabs.children
}
Flow {
id: tabs
width: parent.width
Button {
text: "Reload QML"
onClicked: app.restartQml()
}
Button {
id: iconsTab
checkable: true
text: "Icons"
}
}
ScrollView {
width: parent.width
anchors.top: tabs.bottom
anchors.bottom: parent.bottom
contentHeight: rootWindow.height * rootWindow.factor
contentWidth: rootWindow.width * rootWindow.factor
clip: true
SplitView {
width: parent.width
height: rootWindow.height
handle: Item {}
scale: rootWindow.factor
Rectangle {
id: lightThemeBg
SplitView.minimumWidth: rootWindow.width / 2
height: parent.height
color: lightTheme.baseColor5
clip: true
Loader {
active: true
anchors.centerIn: parent
property var currentTheme: StatusLightTheme { id: lightTheme }
sourceComponent: {
switch(topicsGroup.checkedButton) {
case iconsTab:
return iconsComponent;
default:
return null;
}
}
}
}
Rectangle {
id: darkThemeBg
SplitView.fillWidth: true
SplitView.minimumWidth: rootWindow.width / 2
height: parent.height
color: darkTheme.baseColor5
clip: true
Loader {
active: true
anchors.centerIn: parent
property var currentTheme: StatusDarkTheme { id: darkTheme }
sourceComponent: {
switch(topicsGroup.checkedButton) {
case iconsTab:
return iconsComponent;
default:
return null;
}
}
}
}
}
}
readonly property real maxFactor: 2.0
readonly property real minFactor: 0.5
property real factor: 1.0
Action {
shortcut: "CTRL+="
onTriggered: {
if (rootWindow.factor < 2.0)
rootWindow.factor += 0.2
}
}
Action {
shortcut: "CTRL+-"
onTriggered: {
if (rootWindow.factor > 0.5)
rootWindow.factor -= 0.2
}
}
Action {
shortcut: "CTRL+0"
onTriggered: {
rootWindow.factor = 1.0
}
}
Component {
id: iconsComponent
Icons {
anchors.centerIn: parent
iconColor: parent? parent.currentTheme.primaryColor1 : "#ffffff"
}
}
}

View File

@ -0,0 +1,6 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>Icons.qml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,28 @@
QT += quick
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
handler.cpp \
main.cpp \
sandboxapp.cpp
RESOURCES += qml.qrc
DESTDIR = $$PWD/bin
CONFIG -= app_bundle
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
OTHER_FILES += $$files($$PWD/../src/*, true)
HEADERS += \
handler.h \
sandboxapp.h

View File

@ -0,0 +1,36 @@
#include "sandboxapp.h"
#include <QQmlContext>
#include <QDebug>
SandboxApp::SandboxApp(int &argc, char **argv)
: QGuiApplication(argc, argv),
m_handler(new Handler(this))
{
connect(m_handler, &Handler::restartQml, this, &SandboxApp::restartEngine, Qt::QueuedConnection);
}
void SandboxApp::startEngine()
{
const QUrl url(applicationDirPath() + "/../main.qml");
m_engine.rootContext()->setContextProperty("app", m_handler);
m_engine.addImportPath(applicationDirPath() + "/../../src");
qDebug() << m_engine.importPathList();
QObject::connect(&m_engine, &QQmlApplicationEngine::objectCreated,
this, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
m_engine.load(url);
}
void SandboxApp::restartEngine()
{
const QUrl url(applicationDirPath() + "/../main.qml");
m_engine.rootObjects().at(0)->deleteLater();
m_engine.clearComponentCache();
m_engine.load(url);
}

View File

@ -0,0 +1,24 @@
#ifndef SANDBOXAPP_H
#define SANDBOXAPP_H
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "handler.h"
class SandboxApp : public QGuiApplication
{
public:
SandboxApp(int &argc, char **argv);
void startEngine();
public slots:
void restartEngine();
private:
QQmlApplicationEngine m_engine;
Handler *m_handler;
};
#endif // SANDBOXAPP_H

View File

@ -1,3 +1,5 @@
module StatusQ.Core.Theme
singleton StatusColors 0.1 StatusColors.qml
ThemePalette 0.1 ThemePalette.qml
StatusLightTheme 0.1 StatusLightTheme.qml

View File

@ -1,2 +1,4 @@
module StatusQ.Core
StatusIcon 0.1 StatusIcon.qml

View File

@ -0,0 +1,2 @@
module StatusQ