Skip to content

Commit

Permalink
uilayout: support add widget (back) to dock
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Jan 25, 2024
1 parent 6a8dc2b commit 2dc24a9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
37 changes: 28 additions & 9 deletions src/app/GUI/uilayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QSettings>
#include <QDebug>
Expand All @@ -49,18 +48,17 @@ UIDock::UIDock(QWidget *parent,
const bool &showHeader,
const bool &darkHeader)
: QWidget{parent}
, mWidget(widget)
, mLayout(nullptr)
, mLabel(label)
, mPos(pos)
, mIndex(-1)
{
setObjectName(mLabel);

setContentsMargins(0, 0, 0, 0);
const auto mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mLayout = new QVBoxLayout(this);
mLayout->setContentsMargins(0, 0, 0, 0);
mLayout->setMargin(0);
mLayout->setSpacing(0);

if (showHeader) {
const auto headerWidget = new QWidget(this);
Expand Down Expand Up @@ -126,7 +124,7 @@ UIDock::UIDock(QWidget *parent,
headerLayout->addWidget(upButton);
headerLayout->addWidget(downButton);

mainLayout->addWidget(headerWidget);
mLayout->addWidget(headerWidget);

connect(leftButton, &QPushButton::clicked,
this, [this]() { emit changePosition(mPos, Position::Left); });
Expand All @@ -137,7 +135,7 @@ UIDock::UIDock(QWidget *parent,
connect(downButton, &QPushButton::clicked,
this, [this]() { emit changePosition(mPos, Position::Down); });
}
mainLayout->addWidget(mWidget);
mLayout->addWidget(widget);
}

UIDock::~UIDock()
Expand Down Expand Up @@ -175,6 +173,11 @@ const QString UIDock::getId()
return AppSupport::filterTextAZW(mLabel);
}

void UIDock::addWidget(QWidget *widget)
{
mLayout->addWidget(widget);
}

void UIDock::writeSettings()
{
qDebug() << "==> write dock conf" << mLabel << mPos << mIndex;
Expand Down Expand Up @@ -313,6 +316,12 @@ void UILayout::setDockVisible(const QString &label,
emit updateDockVisibility(label, visible);
}

void UILayout::addDockWidget(const QString &label, QWidget *widget)
{
if (!widget) { return; }
emit updateDockWidget(label, widget);
}

void UILayout::addDock(const Item &item)
{
if (!item.widget) { return; }
Expand Down Expand Up @@ -351,6 +360,16 @@ void UILayout::connectDock(UIDock *dock)
bool visible) {
if (dock->getLabel() == label) { dock->setVisible(visible); }
});
connect(this,
&UILayout::updateDockWidget,
this,
[dock](const QString &label,
QWidget *widget) {
if (dock->getLabel() == label) {
dock->addWidget(widget);
dock->setVisible(true);
}
});
connect(dock,
&UIDock::changePosition,
this,
Expand Down
8 changes: 7 additions & 1 deletion src/app/GUI/uilayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <QWidget>
#include <QSplitter>
#include <QVBoxLayout>
#include <vector>

class UIDock : public QWidget
Expand Down Expand Up @@ -54,13 +55,14 @@ class UIDock : public QWidget
int getIndex();
const QString getLabel();
const QString getId();
void addWidget(QWidget *widget);

signals:
void changePosition(const Position &pos,
const Position &trigger);

private:
QWidget *mWidget;
QVBoxLayout *mLayout;
QString mLabel;
Position mPos;
int mIndex;
Expand Down Expand Up @@ -93,10 +95,14 @@ class UILayout : public QSplitter
void addDocks(std::vector<Item> items);
void setDockVisible(const QString &label,
bool visible);
void addDockWidget(const QString &label,
QWidget *widget);

signals:
void updateDockVisibility(const QString &label,
bool visible);
void updateDockWidget(const QString &label,
QWidget *widget);

private:
QSplitter *mLeft;
Expand Down

0 comments on commit 2dc24a9

Please sign in to comment.