#include "presentcontainerview.h" #include "DocsManager.h" #include "welcomepanel.h" #include #include #include #include #include using namespace Components; using namespace Core; using namespace SplitFrame; using namespace Presents; PresentContainerView::PresentContainerView(ViewPresent *host, QWidget *parent) : FnWrap(host, parent), title_store(new QComboBox(this)), stack_container(new QStackedWidget(this)), welcome_list(new WelcomePanel(this)), close_btn(new QPushButton("X", this)) { auto layout = new QGridLayout(this); layout->setSpacing(0); layout->setMargin(0); layout->addWidget(title_store, 0, 0, 1, 3); layout->addWidget(close_btn, 0, 3); close_btn->setMaximumSize(QSize(30, 30)); items_store << welcome_list; stack_container->addWidget(welcome_list->widget()); title_store->addItem(welcome_list->name()); layout->setRowStretch(0, 0); layout->setRowStretch(1, 1); layout->setColumnStretch(0, 1); layout->setColumnStretch(1, 1); layout->setColumnStretch(2, 1); layout->setColumnStretch(3, 0); connect(title_store, QOverload::of(&QComboBox::currentIndexChanged), this, &PresentContainerView::change_view); connect(close_btn, &QPushButton::toggled, this, &PresentContainerView::close_current_view); } QWidget *PresentContainerView::hostWidget() const { return (QWidget *)this; } #include using namespace Config; void PresentContainerView::append(FilePresent *ins) { if (!items_store.contains(ins)) { items_store.append(ins); title_store->addItem(ins->name()); stack_container->addWidget(ins->widget()); } throw new SimpleException("非法操作", "重复添加视图:" + ins->name()); } bool PresentContainerView::active(const FilePresent *ins) { if (!items_store.contains(ins)) return false; auto index = items_store.indexOf(ins); title_store->setCurrentIndex(index); title_store->setItemText(index, ins->name()); stack_container->setCurrentIndex(index); return true; } void PresentContainerView::remove(const FilePresent *ins) { if (!items_store.contains(ins)) return; auto index = items_store.indexOf(ins); items_store.removeAt(index); title_store->removeItem(index); stack_container->removeWidget(ins->widget()); } bool PresentContainerView::contains(const FilePresent *ins) const { for (auto &insit : items_store) { if (insit == ins) return true; } return false; } bool PresentContainerView::avaliable(FilePresent *vins) { if (!QApplication::activeWindow()) return true; return this->hasFocus(); } void PresentContainerView::change_view(int view_index) { auto view_inst = items_store[view_index]; active(view_inst); close_btn->setEnabled(view_index); } #include void PresentContainerView::close_current_view() { auto index = title_store->currentIndex(); const_cast(items_store[index])->beforeClose(); }