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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 22:31:36 +01:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 22:31:36 +01:00
|
|
|
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() {
|
2022-07-19 22:31:36 +01:00
|
|
|
if (!this->attached) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-16 19:07:09 +01:00
|
|
|
this->setWindowFlag(Qt::Window);
|
2022-07-19 22:31:36 +01:00
|
|
|
|
|
|
|
|
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() {
|
2022-07-19 22:31:36 +01:00
|
|
|
if (this->attached) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->lastDetachedWindowState = this->getDetachedWindowState();
|
2022-07-16 19:07:09 +01:00
|
|
|
this->setWindowFlag(Qt::Window, false);
|
2022-07-19 22:31:36 +01:00
|
|
|
|
|
|
|
|
if (this->activated) {
|
|
|
|
|
this->show();
|
|
|
|
|
}
|
2022-07-16 19:07:09 +01:00
|
|
|
|
|
|
|
|
this->attached = true;
|
|
|
|
|
emit this->paneAttached();
|
|
|
|
|
}
|
2022-07-19 22:30:23 +01:00
|
|
|
|
|
|
|
|
void PaneWidget::closeEvent(QCloseEvent* event) {
|
|
|
|
|
this->deactivate();
|
|
|
|
|
QWidget::closeEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-19 22:31:36 +01:00
|
|
|
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
|
|
|
}
|