2022-11-22 03:42:48 +00:00
|
|
|
|
#include "storychainsourceeditor.h"
|
|
|
|
|
#include "keywordshightlighter.h"
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QSpinBox>
|
|
|
|
|
|
|
|
|
|
using namespace Enhancement;
|
|
|
|
|
using namespace Parse::Result;
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Components;
|
|
|
|
|
|
|
|
|
|
StoryChainSourceEdit::StoryChainSourceEdit(Core::FileExtensionFactory *factory)
|
|
|
|
|
: highter_ins(new KeywordsHightlighter(this)), doc_ins(nullptr), factory_ins(factory)
|
|
|
|
|
{
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
highter_ins->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](){highter_ins->rehighlight();});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryChainSourceEdit::modeReset(const QString &) const{}
|
|
|
|
|
|
|
|
|
|
QList<QString> StoryChainSourceEdit::modes() const
|
|
|
|
|
{
|
|
|
|
|
return QList<QString>() << "源码";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StoryChainSourceEdit::currentMode() const
|
|
|
|
|
{
|
|
|
|
|
return modes()[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StoryChainSourceEdit::title() const
|
|
|
|
|
{
|
|
|
|
|
return doc_ins->filePath();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 03:47:12 +00:00
|
|
|
|
void StoryChainSourceEdit::initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
2022-11-29 03:47:12 +00:00
|
|
|
|
FormattedTextEdit::initSource(core, src, parent);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
this->doc_ins = core->parseCore()->queryDocument(src);
|
|
|
|
|
this->core_ins = core;
|
|
|
|
|
static_cast<Enhancement::KeywordsHightlighter*>(this->highter_ins)->reset(doc_ins);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileExtensionFactory *StoryChainSourceEdit::factory() const
|
|
|
|
|
{
|
|
|
|
|
return factory_ins;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 03:47:12 +00:00
|
|
|
|
void StoryChainSourceEdit::reloadConfigrations(QList<Config::Configration *> configs)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
// TODO: 设置格式
|
|
|
|
|
auto font_family = Config::ConfigHelper::getConfigAsDefaultSequence
|
|
|
|
|
(configs, {"sourcecode_chainedit","default_font","font_family"}, "微软雅黑");
|
|
|
|
|
auto font_size = Config::ConfigHelper::getConfigAsDefaultSequence(
|
|
|
|
|
configs, {"sourcecode_chainedit","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 StoryChainSourceEdit::rehighlighter()
|
|
|
|
|
{
|
|
|
|
|
this->highter_ins->rehighlight();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
void StoryChainSourceEdit::resetProcsType(const QString &suffix)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
void StoryChainSourceEdit::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_ins->parseCore();
|
|
|
|
|
if(path.size()){
|
|
|
|
|
auto storynode = core->queryStoryChain(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-22 06:15:36 +00:00
|
|
|
|
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
2022-11-25 07:30:33 +00:00
|
|
|
|
this->setTextCursor(cur);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
|
|
|
|
|
if(path.size() > 1){
|
|
|
|
|
auto storypoint = core->queryStoryPoint(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 03:42:48 +00:00
|
|
|
|
cur.setPosition(textblock.position());
|
2022-11-22 06:15:36 +00:00
|
|
|
|
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
2022-11-25 07:30:33 +00:00
|
|
|
|
this->setTextCursor(cur);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-22 06:15:36 +00:00
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
this->textView()->setFocus();
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-25 09:44:18 +00:00
|
|
|
|
namespace __impl_temp {
|
2022-11-22 03:42:48 +00:00
|
|
|
|
class ChainSrcConfig : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual ~ChainSrcConfig(){
|
|
|
|
|
qDebug() << "析构";
|
|
|
|
|
}
|
|
|
|
|
void init(Config::Configration *port){}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
StoryChainSourceEditFactory::StoryChainSourceEditFactory(){}
|
|
|
|
|
|
2022-11-25 01:18:54 +00:00
|
|
|
|
Core::Extension *Components::StoryChainSourceEditFactory::newInstance(Core::AppCore *core)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
return new StoryChainSourceEdit(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Core::Scale> Components::StoryChainSourceEditFactory::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 ChainConfigration : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ChainConfigration(Config::Configration* port)
|
|
|
|
|
{
|
|
|
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
|
|
|
|
|
|
auto family = Config::ConfigHelper::getConfigAsDefault(
|
|
|
|
|
port, {"sourcecode_chainedit","default_font","font_family"}, "微软雅黑");
|
|
|
|
|
auto fontfamily = new QComboBox(this);
|
|
|
|
|
layout->addWidget(fontfamily);
|
|
|
|
|
auto families = QFontDatabase().families(QFontDatabase::WritingSystem::SimplifiedChinese);
|
|
|
|
|
fontfamily->addItems(families);
|
|
|
|
|
fontfamily->setCurrentText(family);
|
|
|
|
|
connect(fontfamily, &QComboBox::currentTextChanged, [port](const QString &text){
|
|
|
|
|
port->setConfig({"sourcecode_chainedit","default_font","font_family"}, text);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto size = Config::ConfigHelper::getConfigAsDefault(
|
|
|
|
|
port, {"sourcecode_chainedit","default_font","font_sizept"}, "20");
|
|
|
|
|
auto fontsize = new QSpinBox(this);
|
|
|
|
|
layout->addWidget(fontsize);
|
|
|
|
|
fontsize->setRange(10, 200);
|
|
|
|
|
fontsize->setSingleStep(1);
|
|
|
|
|
fontsize->setValue(size.toInt());
|
|
|
|
|
connect(fontsize, QOverload<int>::of(&QSpinBox::valueChanged), [port](int val){
|
|
|
|
|
port->setConfig({"sourcecode_chainedit","default_font","font_sizept"}, QString("%1").arg(val));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
layout->addWidget(new QWidget(this), 1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
QWidget *Components::StoryChainSourceEditFactory::getNewPanel(Config::Configration *config)
|
|
|
|
|
{
|
2023-02-25 09:44:18 +00:00
|
|
|
|
return new __impl_temp::ChainConfigration(config);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StoryChainSourceEditFactory::extensionName() const
|
|
|
|
|
{
|
|
|
|
|
return "脉络编辑器";
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 01:32:42 +00:00
|
|
|
|
QList<QString> StoryChainSourceEditFactory::suffixPeers() const
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
2022-11-25 01:32:42 +00:00
|
|
|
|
return QList<QString>() << "storychain";
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|