2021-04-01 00:28:01 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2021-04-14 15:52:31 +00:00
|
|
|
#include <QCommandLineParser>
|
|
|
|
|
2021-04-01 00:28:01 +00:00
|
|
|
#include <QGuiApplication>
|
2021-04-14 15:52:31 +00:00
|
|
|
#include <QPainter>
|
2021-04-15 08:58:57 +00:00
|
|
|
#include <QRasterWindow>
|
2021-04-14 15:52:31 +00:00
|
|
|
#include <QTimer>
|
2021-04-15 08:58:57 +00:00
|
|
|
#include <QWindow>
|
2021-04-14 15:52:31 +00:00
|
|
|
|
|
|
|
#include <QMetaEnum>
|
|
|
|
|
2021-04-01 00:28:01 +00:00
|
|
|
#include <interfaces/shell.h>
|
|
|
|
#include <interfaces/window.h>
|
|
|
|
|
2021-04-14 15:52:31 +00:00
|
|
|
using namespace LayerShellQt;
|
|
|
|
|
|
|
|
QStringList enumsToStringList(QMetaEnum metaEnum)
|
|
|
|
{
|
|
|
|
QStringList ret;
|
|
|
|
ret.reserve(metaEnum.keyCount());
|
|
|
|
for (int i = 0; i < metaEnum.keyCount(); ++i) {
|
|
|
|
ret.append(metaEnum.key(i));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T stringToEnum(QMetaEnum metaEnum, const QString &str)
|
|
|
|
{
|
|
|
|
T ret = {};
|
|
|
|
const auto splitted = str.split(QLatin1Char('|'));
|
|
|
|
for (const auto &value : splitted) {
|
|
|
|
ret |= T(metaEnum.keyToValue(qPrintable(value)));
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
class BasicWindow : public QRasterWindow
|
|
|
|
{
|
2021-04-15 08:58:57 +00:00
|
|
|
void paintEvent(QPaintEvent *)
|
|
|
|
{
|
2021-04-14 15:52:31 +00:00
|
|
|
QPainter p(this);
|
2021-04-15 08:58:57 +00:00
|
|
|
p.fillRect(QRect(0, 0, width(), height()), Qt::red);
|
2021-04-14 15:52:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-04-06 11:39:27 +00:00
|
|
|
int main(int argc, char **argv)
|
2021-04-01 00:28:01 +00:00
|
|
|
{
|
2021-04-14 15:52:31 +00:00
|
|
|
Shell::useLayerShell();
|
2021-04-01 00:28:01 +00:00
|
|
|
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
2021-04-14 15:52:31 +00:00
|
|
|
const auto layerMetaEnum = QMetaEnum::fromType<Window::Layer>();
|
|
|
|
const auto anchorMetaEnum = QMetaEnum::fromType<Window::Anchor>();
|
|
|
|
|
|
|
|
QCommandLineParser parser;
|
|
|
|
QCommandLineOption marginsOption(QStringLiteral("margins"), QStringLiteral("Window margins"), QStringLiteral("pixels"), QStringLiteral("0"));
|
|
|
|
QCommandLineOption scopeOption(QStringLiteral("scope"), QStringLiteral("Window scope"), QStringLiteral("namespace"), QStringLiteral("normal"));
|
|
|
|
QCommandLineOption anchorsOption(QStringLiteral("anchors"),
|
|
|
|
QStringLiteral("Either ") + enumsToStringList(anchorMetaEnum).join(QLatin1String("|")),
|
|
|
|
QStringLiteral("anchors"),
|
|
|
|
QStringLiteral("AnchorTop|AnchorBottom|AnchorLeft|AnchorRight"));
|
|
|
|
QCommandLineOption layerOption(QStringLiteral("layer"),
|
|
|
|
QStringLiteral("One of ") + enumsToStringList(layerMetaEnum).join(QLatin1String("|")),
|
|
|
|
QStringLiteral("layer"),
|
|
|
|
QStringLiteral("LayerTop"));
|
|
|
|
parser.addOptions({marginsOption, scopeOption, anchorsOption, layerOption});
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.process(app);
|
|
|
|
|
|
|
|
BasicWindow window;
|
|
|
|
|
2021-04-15 08:58:57 +00:00
|
|
|
LayerShellQt::Window *layerShell = LayerShellQt::Window::get(&window);
|
2021-04-14 15:52:31 +00:00
|
|
|
if (parser.isSet(marginsOption)) {
|
|
|
|
int margins = parser.value(marginsOption).toInt();
|
|
|
|
layerShell->setMargins({margins, margins, margins, margins});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(scopeOption)) {
|
|
|
|
layerShell->setScope(parser.value(scopeOption));
|
|
|
|
}
|
|
|
|
if (parser.isSet(layerOption)) {
|
|
|
|
layerShell->setLayer(Window::Layer(layerMetaEnum.keyToValue(qPrintable(parser.value(layerOption)))));
|
|
|
|
}
|
|
|
|
if (parser.isSet(anchorsOption)) {
|
2021-04-15 08:58:57 +00:00
|
|
|
layerShell->setAnchors(stringToEnum<Window::Anchors>(anchorMetaEnum, parser.value(anchorsOption)));
|
2021-04-14 15:52:31 +00:00
|
|
|
}
|
|
|
|
window.show();
|
|
|
|
|
|
|
|
// just so you don't block yourself out whilst testing
|
|
|
|
QTimer::singleShot(5000, &app, &QGuiApplication::quit);
|
2021-04-01 00:28:01 +00:00
|
|
|
return app.exec();
|
|
|
|
}
|