155 lines
4.9 KiB
C++
155 lines
4.9 KiB
C++
|
#include "storyboardsourceedit.h"
|
|||
|
#include "keywordshightlighter.h"
|
|||
|
#include <QComboBox>
|
|||
|
#include <QMenu>
|
|||
|
#include <QSpinBox>
|
|||
|
#include <QVBoxLayout>
|
|||
|
|
|||
|
using namespace Components;
|
|||
|
using namespace Parse::Result;
|
|||
|
using namespace Enhancement;
|
|||
|
using namespace Core;
|
|||
|
|
|||
|
|
|||
|
StoryBoardSourceEdit::StoryBoardSourceEdit(FileExtensionFactory *factory)
|
|||
|
: words_highlighter(new KeywordsHightlighter(this)), factory_ins(factory)
|
|||
|
{
|
|||
|
words_highlighter->setDocument(this->edit_square->document());
|
|||
|
|
|||
|
edit_square->setContextMenuPolicy(Qt::CustomContextMenu);
|
|||
|
connect(edit_square, &QTextEdit::customContextMenuRequested, [this](const QPoint &pos){
|
|||
|
auto menu = edit_square->createStandardContextMenu();
|
|||
|
menu->addSeparator();
|
|||
|
menu->addAction("刷新", [this](){words_highlighter->rehighlight();});
|
|||
|
menu->exec(edit_square->mapToGlobal(pos));
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
FileExtensionFactory *StoryBoardSourceEdit::factory() const
|
|||
|
{
|
|||
|
return factory_ins;
|
|||
|
}
|
|||
|
|
|||
|
void StoryBoardSourceEdit::reload(QList<Config::Configration *> configs)
|
|||
|
{
|
|||
|
this->configrations_host = configs;
|
|||
|
|
|||
|
// TODO: 设置格式
|
|||
|
auto font_family = Config::ConfigHelper::getConfigAsDefaultSequence
|
|||
|
(configs, {"sourcecode_boardedit","default_font","font_family"}, "微软雅黑");
|
|||
|
auto font_size = Config::ConfigHelper::getConfigAsDefaultSequence(
|
|||
|
configs, {"sourcecode_boardedit","default_font","font_sizept"}, "20");
|
|||
|
QFont default_font;
|
|||
|
default_font.setFamily(font_family);
|
|||
|
default_font.setPointSize(font_size.toInt());
|
|||
|
|
|||
|
this->edit_square->document()->setDefaultFont(default_font);
|
|||
|
this->rehighlighter();
|
|||
|
}
|
|||
|
|
|||
|
void StoryBoardSourceEdit::modeReset(const QString &) const{}
|
|||
|
|
|||
|
QList<QString> StoryBoardSourceEdit::modes() const
|
|||
|
{
|
|||
|
return QList<QString>() << "源码";
|
|||
|
}
|
|||
|
|
|||
|
QString StoryBoardSourceEdit::currentMode() const
|
|||
|
{
|
|||
|
return modes()[0];
|
|||
|
}
|
|||
|
|
|||
|
QString StoryBoardSourceEdit::title() const
|
|||
|
{
|
|||
|
return source_target.fileName();
|
|||
|
}
|
|||
|
|
|||
|
void StoryBoardSourceEdit::setSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent)
|
|||
|
{
|
|||
|
this->source_target = src;
|
|||
|
this->core_temp = core;
|
|||
|
FormattedTextEdit::setSource(core, src, parent);
|
|||
|
static_cast<KeywordsHightlighter*>(words_highlighter)
|
|||
|
->reset(core->parseCore()->queryDocument(src));
|
|||
|
rehighlighter();
|
|||
|
}
|
|||
|
|
|||
|
void StoryBoardSourceEdit::jumpTo(const QList<QString> &path)
|
|||
|
{
|
|||
|
auto fpath = this->filePath();
|
|||
|
auto core = core_temp->parseCore();
|
|||
|
if(path.size()){
|
|||
|
auto storynode = core->queryStoryBoard(path[0]).first();
|
|||
|
auto first_word = storynode->refered()[0];
|
|||
|
|
|||
|
auto textblock = this->edit_square->document()->findBlockByNumber(first_word->row());
|
|||
|
auto cur = this->edit_square->textCursor();
|
|||
|
cur.setPosition(textblock.position());
|
|||
|
this->edit_square->setTextCursor(cur);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void StoryBoardSourceEdit::rehighlighter()
|
|||
|
{
|
|||
|
this->words_highlighter->rehighlight();
|
|||
|
}
|
|||
|
|
|||
|
FileExtension *StoryBoardSourceEditFactory::newInstance(Core::AppCore *core)
|
|||
|
{
|
|||
|
return new StoryBoardSourceEdit(this);
|
|||
|
}
|
|||
|
|
|||
|
QList<Scale> StoryBoardSourceEditFactory::configs() const
|
|||
|
{
|
|||
|
return QList<Scale>() << Scale::Project << Scale::Global;
|
|||
|
}
|
|||
|
|
|||
|
namespace __temp {
|
|||
|
class BoardConfigration : public QWidget
|
|||
|
{
|
|||
|
public:
|
|||
|
BoardConfigration(Config::Configration* port)
|
|||
|
{
|
|||
|
auto layout = new QVBoxLayout(this);
|
|||
|
auto font_family = Config::ConfigHelper::getConfigAsDefault
|
|||
|
(port, {"sourcecode_boardedit","default_font","font_family"}, "微软雅黑");
|
|||
|
|
|||
|
auto fontfamily = new QComboBox(this);
|
|||
|
auto families = QFontDatabase().families(QFontDatabase::WritingSystem::SimplifiedChinese);
|
|||
|
fontfamily->addItems(families);
|
|||
|
fontfamily->setCurrentText(font_family);
|
|||
|
connect(fontfamily, &QComboBox::currentTextChanged, [port](const QString &text){
|
|||
|
port->setConfig({"sourcecode_boardedit","default_font","font_family"}, text);
|
|||
|
});
|
|||
|
layout->addWidget(fontfamily);
|
|||
|
|
|||
|
auto font_size = Config::ConfigHelper::getConfigAsDefault
|
|||
|
(port, {"sourcecode_boardedit","default_font","font_sizept"}, "20");
|
|||
|
auto fontsize = new QSpinBox(this);
|
|||
|
fontsize->setRange(10, 200);
|
|||
|
fontsize->setSingleStep(1);
|
|||
|
fontsize->setValue(font_size.toInt());
|
|||
|
connect(fontsize, QOverload<int>::of(&QSpinBox::valueChanged), [port](int val){
|
|||
|
port->setConfig({"sourcecode_boardedit","default_font","font_sizept"}, QString("%1").arg(val));
|
|||
|
});
|
|||
|
layout->addWidget(fontsize);
|
|||
|
|
|||
|
layout->addWidget(new QWidget(this), 1);
|
|||
|
}
|
|||
|
};
|
|||
|
}
|
|||
|
QWidget *StoryBoardSourceEditFactory::getNewPanel(Config::Configration *config)
|
|||
|
{
|
|||
|
return new __temp::BoardConfigration(config);
|
|||
|
}
|
|||
|
|
|||
|
QString StoryBoardSourceEditFactory::extensionName() const
|
|||
|
{
|
|||
|
return "故事编辑";
|
|||
|
}
|
|||
|
|
|||
|
QString StoryBoardSourceEditFactory::suffixPeers() const
|
|||
|
{
|
|||
|
return "storyboard";
|
|||
|
}
|