2022-11-22 03:42:48 +00:00
|
|
|
|
#include "storyunitsourceedit.h"
|
|
|
|
|
#include "keywordshightlighter.h"
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QSpinBox>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Parse::Result;
|
|
|
|
|
using namespace Components;
|
|
|
|
|
using namespace Enhancement;
|
|
|
|
|
|
|
|
|
|
StoryUnitSourceEdit::StoryUnitSourceEdit(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 *StoryUnitSourceEdit::factory() const
|
|
|
|
|
{
|
|
|
|
|
return factory_ins;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryUnitSourceEdit::reload(QList<Config::Configration *> configs)
|
|
|
|
|
{
|
|
|
|
|
// TODO: 设置格式
|
|
|
|
|
auto font_family = Config::ConfigHelper::getConfigAsDefaultSequence
|
|
|
|
|
(configs, {"sourcecode_unitedit","default_font","font_family"}, "微软雅黑");
|
|
|
|
|
auto font_size = Config::ConfigHelper::getConfigAsDefaultSequence(
|
|
|
|
|
configs, {"sourcecode_unitedit","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
|
|
|
|
this->rehighlighter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryUnitSourceEdit::modeReset(const QString &) const
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QString> StoryUnitSourceEdit::modes() const
|
|
|
|
|
{
|
|
|
|
|
return QList<QString>() << "源码";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StoryUnitSourceEdit::currentMode() const
|
|
|
|
|
{
|
|
|
|
|
return modes()[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StoryUnitSourceEdit::title() const
|
|
|
|
|
{
|
|
|
|
|
return source_target.fileName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryUnitSourceEdit::rehighlighter()
|
|
|
|
|
{
|
|
|
|
|
this->words_highlighter->rehighlight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryUnitSourceEdit::setSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
this->source_target = src;
|
2022-11-22 06:15:36 +00:00
|
|
|
|
this->core_ins = core;
|
2022-11-22 03:42:48 +00:00
|
|
|
|
FormattedTextEdit::setSource(core, src, parent);
|
|
|
|
|
static_cast<KeywordsHightlighter*>(words_highlighter)
|
|
|
|
|
->reset(core->parseCore()->queryDocument(src));
|
|
|
|
|
rehighlighter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryUnitSourceEdit::jumpTo(const QList<QString> &path)
|
|
|
|
|
{
|
2022-11-22 06:15:36 +00:00
|
|
|
|
auto fpath = this->filePath();
|
|
|
|
|
auto core = core_ins->parseCore();
|
|
|
|
|
if(path.size()){
|
|
|
|
|
auto storynode = core->queryStoryUnit(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 06:15:36 +00:00
|
|
|
|
cur.setPosition(textblock.position());
|
|
|
|
|
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
2022-11-25 07:30:33 +00:00
|
|
|
|
this->setTextCursor(cur);
|
2022-11-22 06:15:36 +00:00
|
|
|
|
|
|
|
|
|
if(path.size() > 1){
|
|
|
|
|
auto storypoint = core->queryStoryFragment(storynode, path[1]).first();
|
|
|
|
|
first_word = storypoint->refered()[0];
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
auto textblock = this->textDocument()->findBlockByNumber(first_word->row());
|
2022-11-22 06:15:36 +00:00
|
|
|
|
cur.setPosition(textblock.position());
|
|
|
|
|
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
2022-11-25 07:30:33 +00:00
|
|
|
|
this->setTextCursor(cur);
|
2022-11-22 06:15:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
textView()->setFocus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryUnitSourceEdit::resetProcsType(const QString &suffix)
|
|
|
|
|
{
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 01:18:54 +00:00
|
|
|
|
Extension *StoryUnitSourceEditFactory::newInstance(Core::AppCore *core)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
return new StoryUnitSourceEdit(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Scale> StoryUnitSourceEditFactory::configs() const
|
|
|
|
|
{
|
|
|
|
|
return QList<Scale>() << Scale::Project << Scale::Global;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace __temp {
|
|
|
|
|
class UnitConfigration : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
UnitConfigration(Config::Configration* port)
|
|
|
|
|
{
|
|
|
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
|
|
auto fontfamily = new QComboBox(this);
|
|
|
|
|
auto families = QFontDatabase().families(QFontDatabase::WritingSystem::SimplifiedChinese);
|
|
|
|
|
fontfamily->addItems(families);
|
|
|
|
|
auto family = Config::ConfigHelper::getConfigAsDefault(
|
|
|
|
|
port, {"sourcecode_unitedit","default_font","font_family"}, "微软雅黑");
|
|
|
|
|
fontfamily->setCurrentText(family);
|
|
|
|
|
connect(fontfamily, &QComboBox::currentTextChanged, [port](const QString &text){
|
|
|
|
|
port->setConfig({"sourcecode_unitedit","default_font","font_family"}, text);
|
|
|
|
|
});
|
|
|
|
|
layout->addWidget(fontfamily);
|
|
|
|
|
|
|
|
|
|
auto fontsize = new QSpinBox(this);
|
|
|
|
|
fontsize->setRange(10, 200);
|
|
|
|
|
fontsize->setSingleStep(1);
|
|
|
|
|
auto size = Config::ConfigHelper::getConfigAsDefault(
|
|
|
|
|
port,{"sourcecode_unitedit","default_font","font_sizept"}, "20");
|
|
|
|
|
fontsize->setValue(size.toInt());
|
|
|
|
|
connect(fontsize, QOverload<int>::of(&QSpinBox::valueChanged), [port](int val){
|
|
|
|
|
port->setConfig({"sourcecode_unitedit","default_font","font_sizept"}, QString("%1").arg(val));
|
|
|
|
|
});
|
|
|
|
|
layout->addWidget(fontsize);
|
|
|
|
|
|
|
|
|
|
layout->addWidget(new QWidget(this), 1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
QWidget *StoryUnitSourceEditFactory::getNewPanel(Config::Configration *config)
|
|
|
|
|
{
|
|
|
|
|
return new __temp::UnitConfigration(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StoryUnitSourceEditFactory::extensionName() const
|
|
|
|
|
{
|
|
|
|
|
return "单元编辑器";
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 01:32:42 +00:00
|
|
|
|
QList<QString> StoryUnitSourceEditFactory::suffixPeers() const
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
2022-11-25 01:32:42 +00:00
|
|
|
|
return QList<QString>() << "storyunit";
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|