#include "mainwindow.h" #include "srcedit_defaulttext.h" #include "srcedit_storyboard.h" #include "xapp.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "command_list.h" using namespace Project; using namespace MakeTools; using namespace Components; using namespace Core; using namespace Tools; using namespace CommandList; using namespace DataModel; using namespace bridge; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), sync_kernel(new StatusSyncCore(this)), parse_service(new ParseBridge()), split_first(new QSplitter(Qt::Horizontal, this)), split_second(new QSplitter(Qt::Vertical, this)), split_third(new QSplitter(Qt::Horizontal, this)), project_manager(new XMLProjectManager(this)), center_frame(new PresentContainer(QTabWidget::North, this)), messages_frame(new QTabWidget(this)), active_docscollect(new DocumentsManager(project_manager)), welcome_list(new WelcomePanel()), errors_present(new MessagesPresent(parse_service->errorsPresentModel(), this)), project_present(new ProjectPresent(XApp::disp_core, active_docscollect, this)) { QApplication::instance()->installEventFilter(this); initial_commandlist(XApp::disp_core); XApp::disp_core->registerMember(active_docscollect); setMinimumSize(1000, 600); setWindowTitle("提线木偶"); project_present->widget()->setVisible(false); errors_present->setVisible(false); auto mbar = menuBar(); initial_menubar(mbar); setCentralWidget(this->split_first); this->split_first->addWidget(project_present); this->split_first->addWidget(this->split_second); this->split_second->addWidget(this->split_third); this->split_second->addWidget(this->errors_present); this->split_third->addWidget(this->center_frame->hostWidget()); this->split_third->addWidget(this->messages_frame); this->messages_frame->setTabPosition(QTabWidget::TabPosition::South); this->active_docscollect->setPresent(this); } MainWindow::~MainWindow() {} void MainWindow::initial_menubar(QMenuBar *mbar) { // 项目菜单树 auto project = mbar->addMenu("项目"); auto opnp = project->addAction("打开项目", [this]() { auto file = QFileDialog::getOpenFileName(this, "打开项目", QString(), "小说项目(*.nsf)"); if (file == "") return; XApp::disp_core->postCommand(OpenProject(file)); }); sync_kernel->actionEnableSync(opnp, [this]() -> bool { return !project_manager->isOpenning(); }); auto newp = project->addAction("新建项目", [this]() { auto name = QInputDialog::getText(this, "输入项目名称", "项目名称"); if (name == "") return; auto dir_path = QFileDialog::getExistingDirectory(this, "指定项目存储路径"); if (dir_path == "") return; XApp::disp_core->postCommand(NewProject(QDir(dir_path), name)); }); sync_kernel->actionEnableSync(newp, [this]() -> bool { return !project_manager->isOpenning(); }); auto clsp = project->addAction("关闭项目", [this]() { XApp::disp_core->postCommand(CloseProject()); }); sync_kernel->actionEnableSync(clsp, [this]() -> bool { return project_manager->isOpenning(); }); project->addSeparator(); auto pnew = project->addAction("新建路径", [this]() { auto packages = QInputDialog::getText(this, "输入包路径名称/PackA/PackB/PackC", "包路径:"); if (packages != "") XApp::disp_core->postCommand(NewPackage(packages)); }); sync_kernel->actionEnableSync(pnew, [this]() -> bool { return project_manager->isOpenning(); }); auto _xnew = project->addMenu("新建文件"); _xnew->setEnabled(project_manager->isOpenning()); auto types = active_docscollect->fileTypes(); for (auto &t : types) { _xnew->addAction(t, [this, &t]() { auto name = QInputDialog::getText(this, "输入名称", "名称:"); if (name == "") return; auto idx = project_present->currentIndex(); if (!idx.isValid()) idx = project_manager->model()->item(0)->index(); auto group_path = active_docscollect->convertPath(idx); XApp::disp_core->postCommand(NewFile(group_path, name, t)); }); } sync_kernel->widgetEnableSync(_xnew, [this]() -> bool { return project_manager->isOpenning(); }); project->addSeparator(); auto sav = project->addAction("保存全部", [this]() { XApp::disp_core->postCommand(SaveAll()); }); sav->setShortcut(QKeySequence::StandardKey::Save); sync_kernel->actionEnableSync(sav, [this]() -> bool { return project_manager->isOpenning(); }); project->addSeparator(); project->addAction("退出", [this]() { XApp::disp_core->postCommand(SaveAll()); QApplication::exit(0); }); // 编辑菜单 auto edit = mbar->addMenu("编辑"); edit->addAction("撤销一步"); edit->addAction("重做一步"); edit->addSeparator(); edit->addAction("查找关键词"); edit->addAction("替换关键词"); // 视图菜单 auto view = mbar->addMenu("视图"); auto area = view->addMenu("区域管理"); auto xtool = new QToolBar(this); xtool->setVisible(false); addToolBar(Qt::ToolBarArea::TopToolBarArea, xtool); auto act_tool = area->addAction("工具栏"); sync_kernel->actionCheckSync(act_tool, [xtool]() -> bool { return xtool->isVisible(); }); connect(act_tool, &QAction::triggered, [xtool](bool v) { xtool->setVisible(v); }); auto xstatus = statusBar(); xstatus->setVisible(false); xstatus->addWidget(new QLabel("文本消息", this)); auto act_status = area->addAction("状态栏"); sync_kernel->actionCheckSync(act_status, [xstatus]() -> bool { return xstatus->isVisible(); }); connect(act_status, &QAction::triggered, [xstatus](bool v) { xstatus->setVisible(v); }); view->addSeparator(); auto change = view->addMenu("内容切换"); change->addAction("序列视图"); change->addAction("编辑视图"); view->addSeparator(); auto func = view->addMenu("功能视图"); sync_kernel->widgetEnableSync(func, [this]() { return this->project_manager->isOpenning(); }); // 项目管理 { auto project_v = func->addAction("项目管理", [this](bool v) { XApp::disp_core->postCommand(CompVisible(this, project_present, v)); }); sync_kernel->actionCheckSync(project_v, [this]() -> bool { return this->project_present->isVisible(); }); } func->addAction("引用统计"); func->addAction("脉络分蘖"); // 工具菜单 auto tool = mbar->addMenu("工具"); auto word = tool->addMenu("敏感词检测"); word->addAction("工具配置"); word->addAction("敏感词编辑"); auto vcs = tool->addMenu("版本管理"); vcs->addAction("工具配置"); vcs->addAction("启用"); auto exp = tool->addMenu("导入导出"); exp->addAction("导入WsOutlines"); exp->addSeparator(); exp->addAction("导出TXT大纲"); exp->addAction("导出Web大纲"); exp->addAction("导出WsOutlines"); exp->addSeparator(); exp->addAction("导出TXT内容"); // 窗口菜单 auto window = mbar->addMenu("窗口"); window->addAction("新建窗口"); window->addAction("关闭窗口"); window->addSeparator(); window->addAction("布局管理"); window->addMenu("布局切换"); window->addMenu("窗口切换"); // 系统 auto sys = mbar->addMenu("系统"); sys->addAction("软件激活"); sys->addAction("系统信息"); sys->addSeparator(); sys->addAction("关于……"); } void MainWindow::initial_commandlist(Schedule::CommandsDispatcher *host) { host->registerCommand(new CloseProject()); host->registerCommand(new CompVisible(this, welcome_list, true)); host->registerCommand(new CompVisible(this, errors_present, true)); host->registerCommand(new CompVisible(this, project_present, true)); host->registerCommand(new NewFile(Route(), "", "")); host->registerCommand(new NewPackage("")); host->registerCommand(new NewProject(QDir(), "")); host->registerCommand(new OpenFile(Route())); host->registerCommand(new OpenProject("")); host->registerCommand(new SaveAll()); } void MainWindow::append(PresentBase *ins) { this->center_frame->append(ins); } bool MainWindow::active(const PresentBase *ins) { center_frame->active(ins); return true; } void MainWindow::remove(const PresentBase *ins) { this->center_frame->remove(ins); } bool MainWindow::contains(const PresentBase *ins) const { return this->center_frame->contains(ins); } QWidget *MainWindow::hostWidget() const { return (QWidget *)this; } void MainWindow::closeEvent(QCloseEvent *event) { // 关闭事件 if (project_manager->isOpenning()) { XApp::disp_core->postCommand(CloseProject()); } QMainWindow::closeEvent(event); } bool MainWindow::eventFilter(QObject *watched, QEvent *event) { auto ev = event->type(); switch (ev) { case QEvent::Type::MouseButtonPress: case QEvent::Type::MouseButtonRelease: case QEvent::Type::Wheel: case QEvent::Type::MouseMove: case QEvent::Type::KeyPress: case QEvent::Type::KeyRelease: sync_kernel->sync(); break; default: break; } return QMainWindow::eventFilter(watched, event); }