forked from qt-creator/qt-creator
Utils: Introduce a Layouting::WithFormAlignment AttachType
Useful for layouts that should appear as forms but are using QGridLayout for further alignment in the fields as e.g. the Kit settings does. Change-Id: Iec3195b1528dfe052eed5a34379a946db6bf8e54 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -227,6 +227,7 @@ static void flushPendingFormItems(QFormLayout *formLayout,
|
|||||||
|
|
||||||
static void doLayoutHelper(QLayout *layout,
|
static void doLayoutHelper(QLayout *layout,
|
||||||
const LayoutBuilder::LayoutItems &items,
|
const LayoutBuilder::LayoutItems &items,
|
||||||
|
const Layouting::AttachType attachType,
|
||||||
int currentGridRow = 0)
|
int currentGridRow = 0)
|
||||||
{
|
{
|
||||||
int currentGridColumn = 0;
|
int currentGridColumn = 0;
|
||||||
@@ -252,15 +253,15 @@ static void doLayoutHelper(QLayout *layout,
|
|||||||
QWidget *widget = item.widget;
|
QWidget *widget = item.widget;
|
||||||
|
|
||||||
if (gridLayout) {
|
if (gridLayout) {
|
||||||
Qt::Alignment align;
|
Qt::Alignment align = {};
|
||||||
if (item.align == LayoutBuilder::AlignmentType::AlignAsFormLabel)
|
if (attachType == Layouting::WithFormAlignment && currentGridColumn == 0)
|
||||||
align = Qt::Alignment(widget->style()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
|
align = Qt::Alignment(widget->style()->styleHint(QStyle::SH_FormLayoutLabelAlignment));
|
||||||
if (widget)
|
if (widget)
|
||||||
gridLayout->addWidget(widget, currentGridRow, currentGridColumn, 1, item.span, align);
|
gridLayout->addWidget(widget, currentGridRow, currentGridColumn, 1, item.span, align);
|
||||||
else if (item.layout)
|
else if (item.layout)
|
||||||
gridLayout->addLayout(item.layout, currentGridRow, currentGridColumn, 1, item.span, align);
|
gridLayout->addLayout(item.layout, currentGridRow, currentGridColumn, 1, item.span, align);
|
||||||
else if (!item.text.isEmpty())
|
else if (!item.text.isEmpty())
|
||||||
gridLayout->addWidget(new QLabel(item.text));
|
gridLayout->addWidget(new QLabel(item.text), currentGridRow, currentGridColumn, 1, 1, align);
|
||||||
currentGridColumn += item.span;
|
currentGridColumn += item.span;
|
||||||
} else if (boxLayout) {
|
} else if (boxLayout) {
|
||||||
addItemToBoxLayout(boxLayout, item);
|
addItemToBoxLayout(boxLayout, item);
|
||||||
@@ -280,7 +281,7 @@ static void doLayoutHelper(QLayout *layout,
|
|||||||
LayoutBuilder::LayoutItem::LayoutItem(const LayoutBuilder &builder)
|
LayoutBuilder::LayoutItem::LayoutItem(const LayoutBuilder &builder)
|
||||||
{
|
{
|
||||||
layout = builder.createLayout();
|
layout = builder.createLayout();
|
||||||
doLayoutHelper(layout, builder.m_items);
|
doLayoutHelper(layout, builder.m_items, Layouting::WithoutMargins);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -384,7 +385,7 @@ void LayoutBuilder::doLayout(QWidget *parent, Layouting::AttachType attachType)
|
|||||||
QLayout *layout = createLayout();
|
QLayout *layout = createLayout();
|
||||||
parent->setLayout(layout);
|
parent->setLayout(layout);
|
||||||
|
|
||||||
doLayoutHelper(layout, m_items);
|
doLayoutHelper(layout, m_items, attachType);
|
||||||
if (attachType == Layouting::WithoutMargins)
|
if (attachType == Layouting::WithoutMargins)
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
@@ -424,8 +425,8 @@ QWidget *LayoutBuilder::emerge(Layouting::AttachType attachType)
|
|||||||
new items will be added below existing ones.
|
new items will be added below existing ones.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LayoutExtender::LayoutExtender(QLayout *layout)
|
LayoutExtender::LayoutExtender(QLayout *layout, Layouting::AttachType attachType)
|
||||||
: m_layout(layout)
|
: m_layout(layout), m_attachType(attachType)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
LayoutExtender::~LayoutExtender()
|
LayoutExtender::~LayoutExtender()
|
||||||
@@ -434,7 +435,7 @@ LayoutExtender::~LayoutExtender()
|
|||||||
int currentGridRow = 0;
|
int currentGridRow = 0;
|
||||||
if (auto gridLayout = qobject_cast<QGridLayout *>(m_layout))
|
if (auto gridLayout = qobject_cast<QGridLayout *>(m_layout))
|
||||||
currentGridRow = gridLayout->rowCount();
|
currentGridRow = gridLayout->rowCount();
|
||||||
doLayoutHelper(m_layout, m_items, currentGridRow);
|
doLayoutHelper(m_layout, m_items, m_attachType, currentGridRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special items
|
// Special items
|
||||||
@@ -462,12 +463,6 @@ LayoutBuilder::Span::Span(int span_, const LayoutItem &item)
|
|||||||
span = span_;
|
span = span_;
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutBuilder::AlignAsFormLabel::AlignAsFormLabel(const LayoutItem &item)
|
|
||||||
{
|
|
||||||
LayoutBuilder::LayoutItem::operator=(item);
|
|
||||||
align = AlignmentType::AlignAsFormLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Layouting {
|
namespace Layouting {
|
||||||
|
|
||||||
// "Widgets"
|
// "Widgets"
|
||||||
|
@@ -48,6 +48,7 @@ namespace Layouting {
|
|||||||
enum AttachType {
|
enum AttachType {
|
||||||
WithMargins,
|
WithMargins,
|
||||||
WithoutMargins,
|
WithoutMargins,
|
||||||
|
WithFormAlignment, // Handle Grid similar to QFormLayout, i.e. use special alignment for the first column on Mac
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Layouting
|
} // Layouting
|
||||||
@@ -93,7 +94,6 @@ public:
|
|||||||
|
|
||||||
QString text; // FIXME: Use specialValue for that
|
QString text; // FIXME: Use specialValue for that
|
||||||
int span = 1;
|
int span = 1;
|
||||||
AlignmentType align = AlignmentType::DefaultAlignment;
|
|
||||||
SpecialType specialType = SpecialType::NotSpecial;
|
SpecialType specialType = SpecialType::NotSpecial;
|
||||||
QVariant specialValue;
|
QVariant specialValue;
|
||||||
};
|
};
|
||||||
@@ -135,12 +135,6 @@ public:
|
|||||||
Span(int span, const LayoutItem &item);
|
Span(int span, const LayoutItem &item);
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT AlignAsFormLabel : public LayoutItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AlignAsFormLabel(const LayoutItem &item);
|
|
||||||
};
|
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT Stretch : public LayoutItem
|
class QTCREATOR_UTILS_EXPORT Stretch : public LayoutItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -176,11 +170,12 @@ protected:
|
|||||||
class QTCREATOR_UTILS_EXPORT LayoutExtender : public LayoutBuilder
|
class QTCREATOR_UTILS_EXPORT LayoutExtender : public LayoutBuilder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit LayoutExtender(QLayout *layout);
|
explicit LayoutExtender(QLayout *layout, Layouting::AttachType attachType);
|
||||||
~LayoutExtender();
|
~LayoutExtender();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLayout *m_layout = nullptr;
|
QLayout *m_layout = nullptr;
|
||||||
|
Layouting::AttachType m_attachType = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Layouting {
|
namespace Layouting {
|
||||||
@@ -236,7 +231,6 @@ public:
|
|||||||
|
|
||||||
using Space = LayoutBuilder::Space;
|
using Space = LayoutBuilder::Space;
|
||||||
using Span = LayoutBuilder::Span;
|
using Span = LayoutBuilder::Span;
|
||||||
using AlignAsFormLabel = LayoutBuilder::AlignAsFormLabel;
|
|
||||||
|
|
||||||
using Stretch = LayoutBuilder::Stretch; // FIXME: Remove
|
using Stretch = LayoutBuilder::Stretch; // FIXME: Remove
|
||||||
using Break = LayoutBuilder::Break; // FIXME: Remove
|
using Break = LayoutBuilder::Break; // FIXME: Remove
|
||||||
|
@@ -771,7 +771,7 @@ void KitAspectWidget::addToLayoutWithLabel(QWidget *parent)
|
|||||||
emit labelLinkActivated(link);
|
emit labelLinkActivated(link);
|
||||||
});
|
});
|
||||||
|
|
||||||
LayoutExtender builder(parent->layout());
|
LayoutExtender builder(parent->layout(), Layouting::WithFormAlignment);
|
||||||
builder.finishRow();
|
builder.finishRow();
|
||||||
builder.addItem(label);
|
builder.addItem(label);
|
||||||
addToLayout(builder);
|
addToLayout(builder);
|
||||||
|
@@ -87,13 +87,10 @@ KitManagerConfigWidget::KitManagerConfigWidget(Kit *k) :
|
|||||||
this, &KitManagerConfigWidget::setFileSystemFriendlyName);
|
this, &KitManagerConfigWidget::setFileSystemFriendlyName);
|
||||||
|
|
||||||
using namespace Layouting;
|
using namespace Layouting;
|
||||||
Grid{AlignAsFormLabel(label),
|
Grid {
|
||||||
m_nameEdit,
|
label, m_nameEdit, m_iconButton, br,
|
||||||
m_iconButton,
|
fsLabel, m_fileSystemFriendlyNameLineEdit
|
||||||
br,
|
}.attachTo(this, WithFormAlignment);
|
||||||
AlignAsFormLabel(fsLabel),
|
|
||||||
m_fileSystemFriendlyNameLineEdit}
|
|
||||||
.attachTo(this);
|
|
||||||
|
|
||||||
m_iconButton->setToolTip(tr("Kit icon."));
|
m_iconButton->setToolTip(tr("Kit icon."));
|
||||||
auto setIconAction = new QAction(tr("Select Icon..."), this);
|
auto setIconAction = new QAction(tr("Select Icon..."), this);
|
||||||
|
Reference in New Issue
Block a user