Files
BloomPatched/src/Insight/UserInterfaces/InsightWindow/Widgets/PaneWidget.cpp

110 lines
2.8 KiB
C++
Raw Normal View History

2022-07-16 19:07:09 +01:00
#include "PaneWidget.hpp"
namespace Bloom::Widgets
{
PaneWidget::PaneWidget(PanelWidget* parent)
: QWidget(parent)
, parentPanel(parent)
{
this->setMouseTracking(false);
this->setAttribute(Qt::WA_Hover, true);
QObject::connect(this, &PaneWidget::paneActivated, parent, &PanelWidget::updateVisibility);
QObject::connect(this, &PaneWidget::paneDeactivated, parent, &PanelWidget::updateVisibility);
QObject::connect(this, &PaneWidget::paneAttached, parent, &PanelWidget::updateVisibility);
QObject::connect(this, &PaneWidget::paneDetached, parent, &PanelWidget::updateVisibility);
}
PaneState PaneWidget::getCurrentState() const {
return PaneState(
this->activated,
this->attached,
this->getDetachedWindowState()
);
}
2022-07-16 19:07:09 +01:00
void PaneWidget::activate() {
if (this->activated) {
return;
}
this->show();
this->activated = true;
emit this->paneActivated();
}
void PaneWidget::deactivate() {
if (!this->activated) {
return;
}
this->hide();
this->activated = false;
emit this->paneDeactivated();
}
void PaneWidget::restoreLastPaneState(const PaneState& lastPaneState) {
if (lastPaneState.detachedWindowState.has_value()) {
this->lastDetachedWindowState = lastPaneState.detachedWindowState;
}
if (!lastPaneState.attached && lastPaneState.detachedWindowState.has_value()) {
this->detach();
}
if (lastPaneState.activated) {
this->activate();
}
}
2022-07-16 19:07:09 +01:00
void PaneWidget::detach() {
if (!this->attached) {
return;
}
2022-07-16 19:07:09 +01:00
this->setWindowFlag(Qt::Window);
if (this->lastDetachedWindowState.has_value()) {
this->resize(this->lastDetachedWindowState->size);
this->move(this->lastDetachedWindowState->position);
}
if (this->activated) {
this->show();
}
2022-07-16 19:07:09 +01:00
this->attached = false;
emit this->paneDetached();
}
void PaneWidget::attach() {
if (this->attached) {
return;
}
this->lastDetachedWindowState = this->getDetachedWindowState();
2022-07-16 19:07:09 +01:00
this->setWindowFlag(Qt::Window, false);
if (this->activated) {
this->show();
}
2022-07-16 19:07:09 +01:00
this->attached = true;
emit this->paneAttached();
}
void PaneWidget::closeEvent(QCloseEvent* event) {
this->deactivate();
QWidget::closeEvent(event);
}
std::optional<DetachedWindowState> PaneWidget::getDetachedWindowState() const {
if (!this->attached) {
return DetachedWindowState(this->size(), this->pos());
}
return this->lastDetachedWindowState;
}
2022-07-16 19:07:09 +01:00
}