QtNovelUI/WordsIDE/presentcontainer.cpp

106 lines
3.0 KiB
C++
Raw Normal View History

2023-03-17 13:58:38 +00:00
#include "presentcontainer.h"
#include "DocsManager.h"
2023-08-27 14:09:46 +00:00
#include "welcomepanel.h"
2023-03-17 13:58:38 +00:00
#include <QApplication>
2023-08-27 14:09:46 +00:00
#include <QComboBox>
#include <QGridLayout>
2023-03-17 13:58:38 +00:00
#include <QMenu>
2023-08-27 14:09:46 +00:00
#include <QPushButton>
2023-03-17 13:58:38 +00:00
using namespace Components;
using namespace Core;
2023-08-27 14:09:46 +00:00
using namespace SplitFrame;
2023-03-17 13:58:38 +00:00
2023-08-27 14:09:46 +00:00
PresentContainer::PresentContainer(ViewPresent *host, QWidget *parent)
: FnWrap<PresentContainer, true>(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);
2023-03-17 13:58:38 +00:00
2023-08-27 14:09:46 +00:00
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<int>::of(&QComboBox::currentIndexChanged), this, &PresentContainer::change_view);
connect(close_btn, &QPushButton::toggled, this, &PresentContainer::close_current_view);
2023-03-17 13:58:38 +00:00
}
QWidget *PresentContainer::hostWidget() const { return (QWidget *)this; }
2023-08-27 14:09:46 +00:00
#include <libConfig.h>
using namespace Config;
void PresentContainer::append(FilePresent *ins) {
2023-08-27 14:09:46 +00:00
if (!items_store.contains(ins)) {
2023-08-15 14:40:40 +00:00
items_store.append(ins);
2023-08-27 14:09:46 +00:00
title_store->addItem(ins->name());
stack_container->addWidget(ins->widget());
}
throw new SimpleException<bool>("非法操作", "重复添加视图:" + ins->name());
2023-03-17 13:58:38 +00:00
}
bool PresentContainer::active(const FilePresent *ins) {
2023-08-15 14:40:40 +00:00
if (!items_store.contains(ins))
2023-03-17 13:58:38 +00:00
return false;
2023-08-27 14:09:46 +00:00
auto index = items_store.indexOf(ins);
title_store->setCurrentIndex(index);
title_store->setItemText(index, ins->name());
stack_container->setCurrentIndex(index);
2023-03-17 13:58:38 +00:00
return true;
}
void PresentContainer::remove(const FilePresent *ins) {
2023-08-15 14:40:40 +00:00
if (!items_store.contains(ins))
return;
2023-03-17 13:58:38 +00:00
2023-08-27 14:09:46 +00:00
auto index = items_store.indexOf(ins);
items_store.removeAt(index);
title_store->removeItem(index);
stack_container->removeWidget(ins->widget());
2023-03-17 13:58:38 +00:00
}
bool PresentContainer::contains(const FilePresent *ins) const {
2023-03-17 13:58:38 +00:00
for (auto &insit : items_store) {
if (insit == ins)
return true;
}
return false;
}
bool PresentContainer::avaliable(FilePresent *vins) {
if (!QApplication::activeWindow())
return true;
return this->hasFocus();
}
2023-08-27 14:09:46 +00:00
void PresentContainer::change_view(int view_index) {
auto view_inst = items_store[view_index];
active(view_inst);
close_btn->setEnabled(view_index);
}
#include <QMessageBox>
void PresentContainer::close_current_view() {
auto index = title_store->currentIndex();
const_cast<FilePresent *>(items_store[index])->beforeClose();
2023-03-17 13:58:38 +00:00
}