2022-07-16 19:07:09 +01:00
|
|
|
#include "PaneWidget.hpp"
|
|
|
|
|
|
|
|
|
|
namespace Bloom::Widgets
|
|
|
|
|
{
|
2022-08-08 22:26:32 +01:00
|
|
|
PaneWidget::PaneWidget(PaneState& state, PanelWidget* parent)
|
|
|
|
|
: state(state)
|
2022-07-16 19:07:09 +01:00
|
|
|
, parentPanel(parent)
|
2022-08-08 22:26:32 +01:00
|
|
|
, QWidget(parent)
|
2022-07-16 19:07:09 +01:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaneWidget::activate() {
|
|
|
|
|
this->show();
|
2022-08-08 22:26:32 +01:00
|
|
|
this->state.activated = true;
|
2022-07-16 19:07:09 +01:00
|
|
|
emit this->paneActivated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaneWidget::deactivate() {
|
2022-08-14 17:37:25 +01:00
|
|
|
this->hide();
|
2022-07-16 19:07:09 +01:00
|
|
|
|
2022-08-08 22:26:32 +01:00
|
|
|
this->state.activated = false;
|
2022-07-16 19:07:09 +01:00
|
|
|
emit this->paneDeactivated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaneWidget::detach() {
|
|
|
|
|
this->setWindowFlag(Qt::Window);
|
2022-07-19 22:31:36 +01:00
|
|
|
|
2022-08-08 22:26:32 +01:00
|
|
|
if (this->state.detachedWindowState.has_value()) {
|
|
|
|
|
this->resize(this->state.detachedWindowState->size);
|
|
|
|
|
this->move(this->state.detachedWindowState->position);
|
2022-07-19 22:31:36 +01:00
|
|
|
|
2022-08-08 22:26:32 +01:00
|
|
|
} else {
|
|
|
|
|
this->state.detachedWindowState = DetachedWindowState(this->size(), this->pos());
|
2022-07-19 22:31:36 +01:00
|
|
|
}
|
2022-07-16 19:07:09 +01:00
|
|
|
|
2022-08-08 22:26:32 +01:00
|
|
|
this->state.attached = false;
|
2022-08-14 17:37:25 +01:00
|
|
|
|
|
|
|
|
if (this->state.activated) {
|
|
|
|
|
this->show();
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-16 19:07:09 +01:00
|
|
|
emit this->paneDetached();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaneWidget::attach() {
|
|
|
|
|
this->setWindowFlag(Qt::Window, false);
|
2022-07-19 22:31:36 +01:00
|
|
|
|
2022-08-08 22:26:32 +01:00
|
|
|
this->state.attached = true;
|
2022-08-14 17:37:25 +01:00
|
|
|
|
|
|
|
|
if (this->state.activated) {
|
|
|
|
|
this->show();
|
|
|
|
|
}
|
2022-07-16 19:07:09 +01:00
|
|
|
emit this->paneAttached();
|
|
|
|
|
}
|
2022-07-19 22:30:23 +01:00
|
|
|
|
2022-08-08 22:26:32 +01:00
|
|
|
void PaneWidget::resizeEvent(QResizeEvent* event) {
|
|
|
|
|
if (!this->state.attached && this->state.detachedWindowState.has_value()) {
|
|
|
|
|
this->state.detachedWindowState->size = this->size();
|
|
|
|
|
}
|
2022-08-13 18:35:37 +01:00
|
|
|
|
|
|
|
|
QWidget::resizeEvent(event);
|
2022-07-19 22:30:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-08-08 22:26:32 +01:00
|
|
|
void PaneWidget::moveEvent(QMoveEvent* event) {
|
|
|
|
|
if (!this->state.attached && this->state.detachedWindowState.has_value()) {
|
|
|
|
|
this->state.detachedWindowState->position = this->pos();
|
2022-07-19 22:31:36 +01:00
|
|
|
}
|
2022-08-13 18:35:37 +01:00
|
|
|
|
|
|
|
|
QWidget::moveEvent(event);
|
2022-08-08 22:26:32 +01:00
|
|
|
}
|
2022-07-19 22:31:36 +01:00
|
|
|
|
2022-08-08 22:26:32 +01:00
|
|
|
void PaneWidget::closeEvent(QCloseEvent* event) {
|
|
|
|
|
this->deactivate();
|
|
|
|
|
QWidget::closeEvent(event);
|
2022-07-19 22:31:36 +01:00
|
|
|
}
|
2022-07-16 19:07:09 +01:00
|
|
|
}
|