mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-08 01:26:04 -05:00
Add helpers to add and remove trailing spacer items in QBoxLayouts
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <QCursor>
|
||||
#include <QMainWindow>
|
||||
#include <QScreen>
|
||||
#include <QSpacerItem>
|
||||
#include <unordered_map>
|
||||
#include <regex>
|
||||
#include <set>
|
||||
@@ -255,6 +256,33 @@ void SetLayoutVisible(QLayout *layout, bool visible)
|
||||
}
|
||||
}
|
||||
|
||||
void AddStretchIfNecessary(QBoxLayout *layout)
|
||||
{
|
||||
int itemCount = layout->count();
|
||||
if (itemCount > 0) {
|
||||
auto lastItem = layout->itemAt(itemCount - 1);
|
||||
auto lastSpacer = dynamic_cast<QSpacerItem *>(lastItem);
|
||||
if (!lastSpacer) {
|
||||
layout->addStretch();
|
||||
}
|
||||
} else {
|
||||
layout->addStretch();
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveStretchIfPresent(QBoxLayout *layout)
|
||||
{
|
||||
int itemCount = layout->count();
|
||||
if (itemCount > 0) {
|
||||
auto lastItem = layout->itemAt(itemCount - 1);
|
||||
auto lastSpacer = dynamic_cast<QSpacerItem *>(lastItem);
|
||||
if (lastSpacer) {
|
||||
layout->removeItem(lastItem);
|
||||
delete lastItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MinimizeSizeOfColumn(QGridLayout *layout, int idx)
|
||||
{
|
||||
if (idx >= layout->columnCount()) {
|
||||
|
||||
@@ -88,6 +88,8 @@ void PlaceWidgets(std::string text, QBoxLayout *layout,
|
||||
void DeleteLayoutItemWidget(QLayoutItem *item);
|
||||
void ClearLayout(QLayout *layout, int afterIdx = 0);
|
||||
void SetLayoutVisible(QLayout *layout, bool visible);
|
||||
void AddStretchIfNecessary(QBoxLayout *layout);
|
||||
void RemoveStretchIfPresent(QBoxLayout *layout);
|
||||
void MinimizeSizeOfColumn(QGridLayout *layout, int idx);
|
||||
QMetaObject::Connection PulseWidget(QWidget *widget, QColor startColor,
|
||||
QColor endColor = QColor(0, 0, 0, 0),
|
||||
|
||||
Reference in New Issue
Block a user