105 lines
2.9 KiB
C++
105 lines
2.9 KiB
C++
#include "storypresent.h"
|
||
#include <QFileInfo>
|
||
#include <QMessageBox>
|
||
#include <QMenu>
|
||
#include <QMenuBar>
|
||
|
||
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);
|
||
|
||
auto layout = mbar->addMenu(u8"布局调整");
|
||
layout->addAction(u8"正向布局", this, &StoryPresent::forwardLayout, Qt::CTRL + Qt::Key_F);
|
||
layout->addAction(u8"逆向布局", this, &StoryPresent::backwardLayout, Qt::CTRL + Qt::Key_B);
|
||
layout->addAction(u8"调整布局", this, &StoryPresent::adjustLayout, Qt::CTRL+Qt::Key_A);
|
||
}
|
||
|
||
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<graph_data::Arrow> 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<FragmentDefine>(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<FragmentRefer>(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 <QTransform>
|
||
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);
|
||
}
|
||
|
||
void StoryPresent::forwardLayout()
|
||
{
|
||
this->_story_present->layoutEngine()->forwardsLayoutImpls();
|
||
this->_story_present->refreshGraph();
|
||
}
|
||
|
||
void StoryPresent::backwardLayout()
|
||
{
|
||
this->_story_present->layoutEngine()->backwardsLayoutImpls();
|
||
this->_story_present->refreshGraph();
|
||
}
|
||
|
||
void StoryPresent::adjustLayout()
|
||
{
|
||
this->_story_present->layoutEngine()->adjustLayoutImpls();
|
||
this->_story_present->refreshGraph();
|
||
}
|