QtNovelUI/WordsIDE/presentcontainer.cpp

64 lines
1.5 KiB
C++
Raw Normal View History

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