2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2020 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QString>
|
2023-04-25 10:15:07 +02:00
|
|
|
#include <QtGlobal>
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2022-08-26 10:30:00 +02:00
|
|
|
#include <optional>
|
|
|
|
|
|
2023-04-25 10:15:07 +02:00
|
|
|
#if defined(UTILS_LIBRARY)
|
|
|
|
|
# define QTCREATOR_UTILS_EXPORT Q_DECL_EXPORT
|
2023-05-25 17:17:52 +02:00
|
|
|
#elif defined(UTILS_STATIC_LIBRARY)
|
|
|
|
|
# define QTCREATOR_UTILS_EXPORT
|
2023-04-25 10:15:07 +02:00
|
|
|
#else
|
|
|
|
|
# define QTCREATOR_UTILS_EXPORT Q_DECL_IMPORT
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QLayout;
|
2023-06-01 19:12:52 +02:00
|
|
|
class QMargins;
|
2023-04-27 08:24:43 +02:00
|
|
|
class QObject;
|
2020-09-18 12:11:40 +02:00
|
|
|
class QWidget;
|
2023-04-27 08:24:43 +02:00
|
|
|
template <class T> T qobject_cast(QObject *object);
|
2020-09-18 12:11:40 +02:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2023-04-25 10:15:07 +02:00
|
|
|
namespace Layouting {
|
2022-07-26 11:35:19 +02:00
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
// LayoutItem
|
2023-04-24 16:40:01 +02:00
|
|
|
|
2023-05-03 07:53:28 +02:00
|
|
|
class LayoutBuilder;
|
|
|
|
|
class LayoutItem;
|
2023-04-27 08:24:43 +02:00
|
|
|
using LayoutItems = QList<LayoutItem>;
|
2022-07-26 11:35:19 +02:00
|
|
|
|
2023-01-19 13:51:52 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT LayoutItem
|
2020-09-18 12:11:40 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2022-08-10 17:13:21 +02:00
|
|
|
using Setter = std::function<void(QObject *target)>;
|
2023-04-24 16:40:01 +02:00
|
|
|
|
2023-01-19 13:51:52 +01:00
|
|
|
LayoutItem();
|
2023-04-27 08:24:43 +02:00
|
|
|
~LayoutItem();
|
|
|
|
|
|
|
|
|
|
LayoutItem(const LayoutItem &t);
|
|
|
|
|
LayoutItem &operator=(const LayoutItem &t) = default;
|
2023-04-24 16:40:01 +02:00
|
|
|
|
|
|
|
|
template <class T> LayoutItem(const T &t)
|
|
|
|
|
{
|
2023-04-27 08:24:43 +02:00
|
|
|
if constexpr (std::is_base_of_v<LayoutItem, T>)
|
2023-04-24 16:40:01 +02:00
|
|
|
LayoutItem::operator=(t);
|
2023-04-27 08:24:43 +02:00
|
|
|
else
|
|
|
|
|
createItem(this, t);
|
2023-04-24 16:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-02 12:51:03 +02:00
|
|
|
void attachTo(QWidget *w) const;
|
|
|
|
|
QWidget *emerge();
|
2023-04-27 08:24:43 +02:00
|
|
|
|
|
|
|
|
void addItem(const LayoutItem &item);
|
|
|
|
|
void addItems(const LayoutItems &items);
|
|
|
|
|
void addRow(const LayoutItems &items);
|
|
|
|
|
|
|
|
|
|
std::function<void(LayoutBuilder &)> onAdd;
|
|
|
|
|
std::function<void(LayoutBuilder &)> onExit;
|
|
|
|
|
std::function<void(QObject *target)> setter;
|
|
|
|
|
LayoutItems subItems;
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-03 07:53:28 +02:00
|
|
|
// Special items
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Space
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit Space(int space) : space(space) {}
|
|
|
|
|
const int space;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Stretch
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit Stretch(int stretch = 1) : stretch(stretch) {}
|
|
|
|
|
const int stretch;
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT Span
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Span(int span, const LayoutItem &item) : span(span), item(item) {}
|
|
|
|
|
const int span;
|
|
|
|
|
LayoutItem item;
|
|
|
|
|
};
|
2023-01-19 13:51:52 +01:00
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT Column : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Column(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Row : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Row(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-16 12:51:21 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT Flow : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Flow(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT Grid : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Grid() : Grid({}) {}
|
|
|
|
|
Grid(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Form : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Form() : Form({}) {}
|
|
|
|
|
Form(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
2023-01-19 13:51:52 +01:00
|
|
|
|
2023-05-11 16:55:01 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT Widget : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Widget(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT Stack : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Stack() : Stack({}) {}
|
|
|
|
|
Stack(std::initializer_list<LayoutItem> items);
|
2023-01-19 13:51:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Tab : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
2023-04-27 08:24:43 +02:00
|
|
|
Tab(const QString &tabName, const LayoutItem &item);
|
2023-01-19 13:51:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Group : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Group(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-25 16:58:21 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT TextEdit : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TextEdit(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-19 13:51:52 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT PushButton : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
PushButton(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-04 08:55:10 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT SpinBox : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SpinBox(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-19 13:51:52 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Splitter : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Splitter(std::initializer_list<LayoutItem> items);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT TabWidget : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
2023-04-25 17:21:39 +02:00
|
|
|
TabWidget(std::initializer_list<LayoutItem> items);
|
2023-01-19 13:51:52 +01:00
|
|
|
};
|
|
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT Application : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Application(std::initializer_list<LayoutItem> items);
|
2022-07-22 18:54:04 +02:00
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
int exec(int &argc, char *argv[]);
|
|
|
|
|
};
|
2023-01-19 13:51:52 +01:00
|
|
|
|
2023-05-03 07:53:28 +02:00
|
|
|
|
|
|
|
|
void QTCREATOR_UTILS_EXPORT createItem(LayoutItem *item, const std::function<void(QObject *target)> &t);
|
|
|
|
|
void QTCREATOR_UTILS_EXPORT createItem(LayoutItem *item, QWidget *t);
|
|
|
|
|
void QTCREATOR_UTILS_EXPORT createItem(LayoutItem *item, QLayout *t);
|
|
|
|
|
void QTCREATOR_UTILS_EXPORT createItem(LayoutItem *item, LayoutItem(*t)());
|
|
|
|
|
void QTCREATOR_UTILS_EXPORT createItem(LayoutItem *item, const QString &t);
|
|
|
|
|
void QTCREATOR_UTILS_EXPORT createItem(LayoutItem *item, const Span &t);
|
|
|
|
|
void QTCREATOR_UTILS_EXPORT createItem(LayoutItem *item, const Space &t);
|
|
|
|
|
void QTCREATOR_UTILS_EXPORT createItem(LayoutItem *item, const Stretch &t);
|
|
|
|
|
|
|
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
// "Singletons"
|
2023-01-19 13:51:52 +01:00
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem br();
|
|
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem st();
|
|
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem empty();
|
|
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem hr();
|
2023-05-02 12:51:03 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem noMargin();
|
|
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem normalMargin();
|
2023-06-01 19:12:52 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem customMargin(const QMargins &margin);
|
2023-05-02 12:51:03 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem withFormAlignment();
|
2023-04-27 08:24:43 +02:00
|
|
|
|
2023-05-05 15:19:58 +02:00
|
|
|
// "Setters"
|
2023-04-25 17:21:39 +02:00
|
|
|
|
|
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem title(const QString &title);
|
|
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem text(const QString &text);
|
|
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem tooltip(const QString &toolTip);
|
2023-04-27 08:24:43 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem resize(int, int);
|
2023-05-02 17:20:57 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem columnStretch(int column, int stretch);
|
2023-04-27 08:24:43 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem spacing(int);
|
|
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem windowTitle(const QString &windowTitle);
|
2023-05-04 08:55:10 +02:00
|
|
|
|
2023-05-05 15:19:58 +02:00
|
|
|
// "Getters"
|
|
|
|
|
|
2023-05-09 18:22:42 +02:00
|
|
|
class ID
|
2023-05-05 15:19:58 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QObject *ob = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-09 18:22:42 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem id(ID &out);
|
2023-05-05 15:19:58 +02:00
|
|
|
|
2023-05-09 18:22:42 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT void setText(ID id, const QString &text);
|
2023-05-05 15:19:58 +02:00
|
|
|
|
|
|
|
|
|
2023-05-04 08:55:10 +02:00
|
|
|
// "Signals"
|
|
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem onClicked(const std::function<void()> &,
|
|
|
|
|
QObject *guard = nullptr);
|
2023-05-04 08:55:10 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem onTextChanged(const std::function<void(const QString &)> &,
|
|
|
|
|
QObject *guard = nullptr);
|
|
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem onValueChanged(const std::function<void(int)> &,
|
|
|
|
|
QObject *guard = nullptr);
|
2023-01-19 13:51:52 +01:00
|
|
|
|
2023-05-09 18:22:42 +02:00
|
|
|
QTCREATOR_UTILS_EXPORT LayoutItem onTextChanged(ID &id, QVariant(*sig)(QObject *));
|
2023-05-05 15:19:58 +02:00
|
|
|
|
2023-01-19 13:51:52 +01:00
|
|
|
// Convenience
|
|
|
|
|
|
|
|
|
|
QTCREATOR_UTILS_EXPORT QWidget *createHr(QWidget *parent = nullptr);
|
|
|
|
|
|
2023-04-27 08:24:43 +02:00
|
|
|
template <class T>
|
|
|
|
|
LayoutItem bindTo(T **out)
|
|
|
|
|
{
|
|
|
|
|
return [out](QObject *target) { *out = qobject_cast<T *>(target); };
|
|
|
|
|
}
|
2023-01-19 13:51:52 +01:00
|
|
|
|
2023-05-05 15:19:58 +02:00
|
|
|
|
2023-04-25 10:15:07 +02:00
|
|
|
} // Layouting
|