181 lines
5.5 KiB
C++
181 lines
5.5 KiB
C++
#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)
|
||
{
|
||
|
||
highter_ins->setDocument(this->textDocument());
|
||
|
||
this->setContexMenuProcess([this](QMenu *menu){
|
||
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();
|
||
}
|
||
|
||
void StoryChainSourceEdit::setSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent)
|
||
{
|
||
FormattedTextEdit::setSource(core, src, parent);
|
||
this->doc_ins = core->parseCore()->queryDocument(src);
|
||
this->core_ins = core;
|
||
static_cast<Enhancement::KeywordsHightlighter*>(this->highter_ins)->reset(doc_ins);
|
||
rehighlighter();
|
||
}
|
||
|
||
FileExtensionFactory *StoryChainSourceEdit::factory() const
|
||
{
|
||
return factory_ins;
|
||
}
|
||
|
||
void StoryChainSourceEdit::reload(QList<Config::Configration *> configs)
|
||
{
|
||
// 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());
|
||
|
||
this->textDocument()->setDefaultFont(default_font);
|
||
this->rehighlighter();
|
||
}
|
||
|
||
void StoryChainSourceEdit::rehighlighter()
|
||
{
|
||
this->highter_ins->rehighlight();
|
||
}
|
||
|
||
void StoryChainSourceEdit::resetProcsType(const QString &suffix)
|
||
{
|
||
|
||
}
|
||
|
||
void StoryChainSourceEdit::jumpTo(const QList<QString> &path)
|
||
{
|
||
auto fpath = this->filePath();
|
||
auto core = core_ins->parseCore();
|
||
if(path.size()){
|
||
auto storynode = core->queryStoryChain(path[0]).first();
|
||
auto first_word = storynode->refered()[0];
|
||
|
||
auto textblock = this->textDocument()->findBlockByNumber(first_word->row());
|
||
auto cur = this->getTextCursor();
|
||
cur.setPosition(textblock.position());
|
||
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
||
this->setTextCursor(cur);
|
||
|
||
if(path.size() > 1){
|
||
auto storypoint = core->queryStoryPoint(storynode, path[1]).first();
|
||
first_word = storypoint->refered()[0];
|
||
|
||
auto textblock = this->textDocument()->findBlockByNumber(first_word->row());
|
||
cur.setPosition(textblock.position());
|
||
cur.select(QTextCursor::SelectionType::LineUnderCursor);
|
||
this->setTextCursor(cur);
|
||
}
|
||
}
|
||
|
||
this->textView()->setFocus();
|
||
}
|
||
|
||
namespace __temp {
|
||
class ChainSrcConfig : public QWidget
|
||
{
|
||
public:
|
||
virtual ~ChainSrcConfig(){
|
||
qDebug() << "析构";
|
||
}
|
||
void init(Config::Configration *port){}
|
||
};
|
||
}
|
||
StoryChainSourceEditFactory::StoryChainSourceEditFactory(){}
|
||
|
||
Core::Extension *Components::StoryChainSourceEditFactory::newInstance(Core::AppCore *core)
|
||
{
|
||
return new StoryChainSourceEdit(this);
|
||
}
|
||
|
||
QList<Core::Scale> Components::StoryChainSourceEditFactory::configs() const
|
||
{
|
||
return QList<Scale>() << Scale::Project << Scale::Global;
|
||
}
|
||
|
||
|
||
namespace __temp {
|
||
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)
|
||
{
|
||
return new __temp::ChainConfigration(config);
|
||
}
|
||
|
||
QString StoryChainSourceEditFactory::extensionName() const
|
||
{
|
||
return "脉络编辑器";
|
||
}
|
||
|
||
QList<QString> StoryChainSourceEditFactory::suffixPeers() const
|
||
{
|
||
return QList<QString>() << "storychain";
|
||
}
|