#include "presentcontainer.h" #include "DocsManager.h" #include using namespace Components; using namespace Core; using namespace MakeTools; PresentContainer::PresentContainer(TabPosition pos, QWidget *parent) : QTabWidget(parent) { setTabPosition(pos); setTabsClosable(true); setMovable(true); connect(this, &QTabWidget::tabCloseRequested, this, &PresentContainer::accept_close_action); } QWidget *PresentContainer::hostWidget() const { return (QWidget *)this; } void PresentContainer::append(PresentBase *ins) { addTab(ins->widget(), ins->name()); if (!items_store.contains(ins)) items_store.append(ins); } bool PresentContainer::active(const PresentBase *ins) { if (!items_store.contains(ins)) return false; ins->widget()->setVisible(true); auto index = indexOf(ins->widget()); setCurrentIndex(index); setTabText(index, ins->name()); return true; } void PresentContainer::remove(const PresentBase *ins) { if (!items_store.contains(ins)) return; auto index = indexOf(ins->widget()); removeTab(index); items_store.removeAll(ins); } bool PresentContainer::contains(const PresentBase *ins) const { for (auto &insit : items_store) { if (insit == ins) return true; } return false; } void PresentContainer::accept_close_action(int index) { auto disp = widget(index); for (auto &ins : items_store) { if (ins->widget() == disp) { items_store.removeAll(ins); removeTab(index); } } }