diff --git a/libSplitView/SplitWindow.cpp b/libSplitView/SplitWindow.cpp index 19d0dc3..aa18cdc 100644 --- a/libSplitView/SplitWindow.cpp +++ b/libSplitView/SplitWindow.cpp @@ -25,14 +25,28 @@ SplitWindow::SplitWindow(QWidget *parent) view_root(nullptr) { accept_port->setVisible(false); this->addToolBar(Qt::ToolBarArea::LeftToolBarArea, unused_stack); + + this->addListener(this); } SplitWindow::~SplitWindow() {this->active = false;} void SplitWindow::tempShow(split_frame::DockType t, split_frame::ViewBase *target) { - this->temp_show = target; - target->setVisible(true); + if(target){ + this->temp_show = target; + + auto center_w = centralWidget(); + auto size = center_w->size(); + this->temp_show->widget()->setParent(center_w); + this->temp_show->widget()->setGeometry(0, 0, size.width()/3, size.height()); + target->setVisible(true); + } + else if(temp_show){ + this->temp_show->widget()->setParent(nullptr); + this->temp_show->setVisible(false); + this->temp_show = nullptr; + } } void SplitWindow::setPresentTarget(split_frame::ViewRes *inst) @@ -231,3 +245,46 @@ void SplitWindow::setAdjustView(split_frame::ViewBase *target) { this->adjust_target = target; } + +void SplitWindow::freedomAppend(split_frame::ViewBase *ins) +{ + if(!freedom_list.contains(ins->hashCode())){ + freedom_list[ins->hashCode()]=ins; + + auto act = this->unused_stack->addAction(ins->title(), [this, ins](bool state) { + if (state) { + this->tempShow(split_frame::DockType::LEFT, ins); + } else { + this->tempShow(split_frame::DockType::LEFT, nullptr); + } + }); + act->setData(ins->hashCode()); + act->setIcon(ins->icon()); + act->setCheckable(true); + } +} + +void SplitWindow::freedomRemove(split_frame::ViewBase *ins) +{ + if(freedom_list.contains(ins->hashCode())){ + auto allacts = unused_stack->actions(); + for(auto &act : allacts){ + if(act->data().toULongLong() == ins->hashCode()){ + unused_stack->removeAction(act); + break; + } + } + + freedom_list.remove(ins->hashCode()); + } +} + +void SplitWindow::aboutToBeDelete(split_frame::ViewBase *inst) +{ + this->freedomRemove(inst); +} + +void SplitWindow::hasBeenAppend(split_frame::ViewBase *inst) +{ + +} diff --git a/libSplitView/SplitWindow.h b/libSplitView/SplitWindow.h index fdb6425..b11b5c8 100644 --- a/libSplitView/SplitWindow.h +++ b/libSplitView/SplitWindow.h @@ -14,7 +14,7 @@ namespace split_window { /** * @brief 窗口即视图资源管理器 */ - class SPLITVIEW_EXPORT SplitWindow : public QMainWindow, public split_frame::ResManager { + class SPLITVIEW_EXPORT SplitWindow : public QMainWindow, public split_frame::ResManager, public split_frame::FreedomViewsListener { typedef float pos; typedef float width; @@ -28,6 +28,9 @@ namespace split_window { split_frame::ViewRes *view_root = nullptr, *temp_show = nullptr; split_frame::ViewBase *adjust_target = nullptr; + // freedom-list + QHash freedom_list; + public: SplitWindow(QWidget *parent = nullptr); @@ -61,6 +64,13 @@ namespace split_window { virtual void siblingAttach(split_frame::ViewBase *view, split_frame::ViewBase *pos, split_frame::SplitType ori) override; virtual split_frame::ViewBase *adjustView() const override; virtual void setAdjustView(split_frame::ViewBase *target) override; + + // FreedomViewsListener interface + public: + virtual void freedomAppend(split_frame::ViewBase *ins) override; + virtual void freedomRemove(split_frame::ViewBase *ins) override; + virtual void aboutToBeDelete(split_frame::ViewBase *inst) override; + virtual void hasBeenAppend(split_frame::ViewBase *inst) override; }; } // namespace split_panel