2022-11-22 03:42:48 +00:00
|
|
|
|
#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)
|
|
|
|
|
{
|
2022-11-25 07:30:33 +00:00
|
|
|
|
words_highlighter->setDocument(this->textDocument());
|
2022-11-22 03:42:48 +00:00
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
|
|
|
|
|
this->setContexMenuProcess([this](QMenu *menu){
|
2022-11-22 03:42:48 +00:00
|
|
|
|
menu->addSeparator();
|
|
|
|
|
menu->addAction("刷新", [this](){words_highlighter->rehighlight();});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileExtensionFactory *StoryBoardSourceEdit::factory() const
|
|
|
|
|
{
|
|
|
|
|
return factory_ins;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 03:47:12 +00:00
|
|
|
|
void StoryBoardSourceEdit::reloadConfigrations(QList<Config::Configration *> configs)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
// 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());
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
this->textDocument()->setDefaultFont(default_font);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 03:47:12 +00:00
|
|
|
|
void StoryBoardSourceEdit::initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
this->source_target = src;
|
|
|
|
|
this->core_temp = core;
|
2022-11-29 03:47:12 +00:00
|
|
|
|
FormattedTextEdit::initSource(core, src, parent);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
static_cast<KeywordsHightlighter*>(words_highlighter)
|
|
|
|
|
->reset(core->parseCore()->queryDocument(src));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryBoardSourceEdit::jumpTo(const QList<QString> &path)
|
|
|
|
|
{
|
2022-12-31 13:05:58 +00:00
|
|
|
|
auto fpath = this->absoluteFilePath();
|
2022-11-22 03:42:48 +00:00
|
|
|
|
auto core = core_temp->parseCore();
|
|
|
|
|
if(path.size()){
|
|
|
|
|
auto storynode = core->queryStoryBoard(path[0]).first();
|
|
|
|
|
auto first_word = storynode->refered()[0];
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
auto textblock = this->textDocument()->findBlockByNumber(first_word->row());
|
|
|
|
|
auto cur = this->getTextCursor();
|
2022-11-22 03:42:48 +00:00
|
|
|
|
cur.setPosition(textblock.position());
|
2022-11-25 07:30:33 +00:00
|
|
|
|
this->setTextCursor(cur);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryBoardSourceEdit::rehighlighter()
|
|
|
|
|
{
|
|
|
|
|
this->words_highlighter->rehighlight();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
void StoryBoardSourceEdit::resetProcsType(const QString &suffix)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 01:18:54 +00:00
|
|
|
|
Extension *StoryBoardSourceEditFactory::newInstance(Core::AppCore *core)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
return new StoryBoardSourceEdit(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Scale> StoryBoardSourceEditFactory::configs() const
|
|
|
|
|
{
|
|
|
|
|
return QList<Scale>() << Scale::Project << Scale::Global;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-25 09:44:18 +00:00
|
|
|
|
namespace __impl_temp {
|
2022-11-22 03:42:48 +00:00
|
|
|
|
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)
|
|
|
|
|
{
|
2023-02-25 09:44:18 +00:00
|
|
|
|
return new __impl_temp::BoardConfigration(config);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StoryBoardSourceEditFactory::extensionName() const
|
|
|
|
|
{
|
|
|
|
|
return "故事编辑";
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 01:32:42 +00:00
|
|
|
|
QList<QString> StoryBoardSourceEditFactory::suffixPeers() const
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
2022-11-25 01:32:42 +00:00
|
|
|
|
return QList<QString>() << "storyboard";
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|