添加了自由视图的管理和临时显示隐藏的机制

This commit is contained in:
codeboss 2024-02-10 17:18:59 +08:00
parent 6242c1d2d1
commit 6100d40e31
2 changed files with 70 additions and 3 deletions

View File

@ -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)
{
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)
{
}

View File

@ -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<qulonglong, split_frame::ViewBase*> 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