2020-09-18 12:11:40 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "utils_global.h"
|
|
|
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QString>
|
2021-03-02 12:48:46 +01:00
|
|
|
#include <QVariant>
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
2021-02-18 14:18:34 +01:00
|
|
|
class QBoxLayout;
|
2020-09-18 12:11:40 +02:00
|
|
|
class QFormLayout;
|
|
|
|
|
class QGridLayout;
|
|
|
|
|
class QLayout;
|
|
|
|
|
class QWidget;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
|
|
|
|
|
class BaseAspect;
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT LayoutBuilder
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-02-18 14:18:34 +01:00
|
|
|
enum LayoutType {
|
|
|
|
|
Form, // Plain QFormLayout, without contentMargins
|
|
|
|
|
Grid, // Plain QGridLayout, without contentMargins
|
|
|
|
|
HBox, // Plain QHBoxLayout, without contentMargins
|
|
|
|
|
VBox, // Plain QVBoxLayout, without contentMargins
|
|
|
|
|
HBoxWithMargins, // QHBoxLayout with margins
|
|
|
|
|
VBoxWithMargins, // QVBoxLayout with margins
|
|
|
|
|
// Compat
|
|
|
|
|
FormLayout = Form, // FIXME: Remove
|
|
|
|
|
GridLayout = Grid, // FIXME: Remove
|
|
|
|
|
};
|
2020-10-08 07:24:19 +02:00
|
|
|
enum Alignment { DefaultAlignment, AlignAsFormLabel };
|
|
|
|
|
|
2021-03-02 12:48:46 +01:00
|
|
|
enum class SpecialType {
|
|
|
|
|
NotSpecial,
|
|
|
|
|
Align,
|
|
|
|
|
Space,
|
|
|
|
|
Span,
|
|
|
|
|
Stretch,
|
|
|
|
|
Break,
|
|
|
|
|
Title
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-25 14:58:04 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT LayoutItem
|
2020-09-18 12:11:40 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2020-09-21 09:39:54 +02:00
|
|
|
LayoutItem();
|
2020-10-08 07:24:19 +02:00
|
|
|
LayoutItem(QLayout *layout, int span = 1, Alignment align = {});
|
|
|
|
|
LayoutItem(QWidget *widget, int span = 1, Alignment align = {});
|
2021-02-18 14:18:34 +01:00
|
|
|
LayoutItem(BaseAspect *aspect, int span = 1, Alignment align = {}); // Remove
|
|
|
|
|
LayoutItem(BaseAspect &aspect, int span = 1, Alignment align = {});
|
|
|
|
|
LayoutItem(const QString &text, int span = 1, Alignment align = {});
|
|
|
|
|
LayoutItem(const LayoutBuilder &builder, int span = 1, Alignment align = {});
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
QLayout *layout = nullptr;
|
|
|
|
|
QWidget *widget = nullptr;
|
|
|
|
|
BaseAspect *aspect = nullptr;
|
2021-03-02 12:48:46 +01:00
|
|
|
QString text; // FIXME: Use specialValue for that
|
2020-09-18 12:11:40 +02:00
|
|
|
int span = 1;
|
2020-10-08 07:24:19 +02:00
|
|
|
Alignment align;
|
2021-03-02 12:48:46 +01:00
|
|
|
SpecialType specialType = SpecialType::NotSpecial;
|
|
|
|
|
QVariant specialValue;
|
2021-02-18 14:18:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using LayoutItems = QList<LayoutItem>;
|
|
|
|
|
|
|
|
|
|
explicit LayoutBuilder(QWidget *parent, LayoutType layoutType = Form);
|
|
|
|
|
explicit LayoutBuilder(QLayout *layout); // Adds to existing layout.
|
|
|
|
|
explicit LayoutBuilder(LayoutType layoutType, const LayoutItems &items = {});
|
|
|
|
|
|
|
|
|
|
LayoutBuilder(const LayoutBuilder &) = delete;
|
|
|
|
|
LayoutBuilder(LayoutBuilder &&) = default;
|
|
|
|
|
LayoutBuilder &operator=(const LayoutBuilder &) = delete;
|
|
|
|
|
LayoutBuilder &operator=(LayoutBuilder &&) = default;
|
|
|
|
|
|
|
|
|
|
~LayoutBuilder();
|
|
|
|
|
|
2020-09-18 04:54:41 +02:00
|
|
|
LayoutBuilder &addItem(const LayoutItem &item);
|
2021-02-18 14:18:34 +01:00
|
|
|
LayoutBuilder &addItems(const LayoutItems &items);
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2020-09-18 04:54:41 +02:00
|
|
|
LayoutBuilder &finishRow();
|
2020-09-18 12:11:40 +02:00
|
|
|
LayoutBuilder &addRow(const LayoutItem &item);
|
2021-02-18 14:18:34 +01:00
|
|
|
LayoutBuilder &addRow(const LayoutItems &items);
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
QLayout *layout() const;
|
2021-02-18 14:18:34 +01:00
|
|
|
QWidget *parentWidget() const;
|
|
|
|
|
|
|
|
|
|
void attachTo(QWidget *w, bool stretchAtBottom = true);
|
2020-09-18 12:11:40 +02:00
|
|
|
|
2021-03-02 12:48:46 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Space : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit Space(int space);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Stretch : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit Stretch(int stretch = 1);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Break : public LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Break();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Title : public LayoutBuilder::LayoutItem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit Title(const QString &title);
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-18 12:11:40 +02:00
|
|
|
private:
|
|
|
|
|
void flushPendingFormItems();
|
2021-02-18 14:18:34 +01:00
|
|
|
void init(QWidget *parent, LayoutType layoutType);
|
2020-09-18 12:11:40 +02:00
|
|
|
|
|
|
|
|
QFormLayout *m_formLayout = nullptr;
|
|
|
|
|
QGridLayout *m_gridLayout = nullptr;
|
2021-02-18 14:18:34 +01:00
|
|
|
QBoxLayout *m_boxLayout = nullptr;
|
|
|
|
|
LayoutItems m_pendingFormItems;
|
2020-09-18 12:11:40 +02:00
|
|
|
int m_currentGridRow = 0;
|
|
|
|
|
int m_currentGridColumn = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2021-02-18 14:18:34 +01:00
|
|
|
namespace Layouting {
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Group : public LayoutBuilder
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Group(std::initializer_list<LayoutBuilder::LayoutItem> items);
|
|
|
|
|
|
|
|
|
|
Group &withTitle(const QString &title);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Box : public LayoutBuilder
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Box(LayoutType type, const LayoutItems &items);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Column : public Box
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Column(std::initializer_list<LayoutItem> items)
|
|
|
|
|
: Box(VBox, items)
|
|
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Row : public Box
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Row(std::initializer_list<LayoutItem> items)
|
|
|
|
|
: Box(HBox, items)
|
|
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QTCREATOR_UTILS_EXPORT Grid : public Box
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Grid(std::initializer_list<LayoutItem> items)
|
|
|
|
|
: Box(GridLayout, items)
|
|
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
|
2021-03-02 12:48:46 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Form : public Box
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Form(std::initializer_list<LayoutItem> items)
|
|
|
|
|
: Box(FormLayout, items)
|
|
|
|
|
{}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using Item = LayoutBuilder::LayoutItem;
|
2021-02-18 14:18:34 +01:00
|
|
|
using Stretch = LayoutBuilder::Stretch;
|
|
|
|
|
using Space = LayoutBuilder::Space;
|
|
|
|
|
using Break = LayoutBuilder::Break;
|
2021-03-02 12:48:46 +01:00
|
|
|
using Title = LayoutBuilder::Title;
|
2021-02-18 14:18:34 +01:00
|
|
|
|
|
|
|
|
}
|
2020-09-18 12:11:40 +02:00
|
|
|
} // namespace Utils
|