#include "storypresent.h" #include #include #include #include using namespace dags; using namespace xast_parse; StoryPresent::StoryPresent(QWidget* parent) : QMainWindow(parent), _story_present(new DAGActiveView(this)) { setCentralWidget(_story_present); auto mbar = menuBar(); auto view = mbar->addMenu(u8"视图"); view->addAction(u8"缩小", this, &StoryPresent::lesser, Qt::CTRL + Qt::Key_N); view->addAction(u8"放大", this, &StoryPresent::bigger, Qt::CTRL + Qt::Key_P); } StoryPresent::~StoryPresent() {} #include "xast_parse.h" void StoryPresent::loadXAST(const QString& ast_path) { QFileInfo finfo(ast_path); if (!finfo.exists() || !finfo.isFile()) { QMessageBox::critical(this, u8"文件错误", QString(u8"指定文件(%1)非法!").arg(ast_path)); return; } xast_parse::XAST_Parser t(ast_path); this->_story_graph = t.storyGraph(); QList arrows; for (auto& key : this->_story_graph.keys()) { auto story_line = this->_story_graph[key]; auto arrow_start = story_line->name(); auto frag_temp = story_line->firstChild(); while (frag_temp) { switch (frag_temp->type()) { case SliceType::FragmentDefines: { auto arrow_tail = std::dynamic_pointer_cast(frag_temp)->name() + u8"@" + story_line->name(); arrows << graph_data::Arrow(arrow_start, arrow_tail); arrow_start = arrow_tail; }break; case SliceType::FragmentRefers: { auto conv_refer = std::dynamic_pointer_cast(frag_temp); auto arrow_tail = conv_refer->fragmentRefer() + u8"@" + conv_refer->storyRefer(); arrows << graph_data::Arrow(arrow_start, arrow_tail); arrow_start = arrow_tail; }break; default: break; } frag_temp = frag_temp->nextSlice(); } } this->_story_present->updateWithEdges(arrows); } #include void StoryPresent::bigger() { _scale_value *= 1.1; QTransform trans_base; trans_base.scale(_scale_value, _scale_value); this->_story_present->setTransform(trans_base); } void StoryPresent::lesser() { _scale_value /= 1.1; QTransform trans_base; trans_base.scale(_scale_value, _scale_value); this->_story_present->setTransform(trans_base); }