158 lines
4.8 KiB
C++
158 lines
4.8 KiB
C++
#include "sourcecodeeditor.h"
|
|
#include "keywordshightlighter.h"
|
|
|
|
#include <QComboBox>
|
|
#include <QSpinBox>
|
|
#include <QVBoxLayout>
|
|
|
|
using namespace Components;
|
|
using namespace Enhancement;
|
|
|
|
SourceCodeEditor::SourceCodeEditor(Core::FileExtensionFactory *factory)
|
|
: factory_ins(factory),
|
|
highlighter_ins(new KeywordsHightlighter(this))
|
|
{
|
|
highlighter_ins->setDocument(this->textDocument());
|
|
|
|
}
|
|
|
|
void SourceCodeEditor::concept_jump(const QList<QString> &path)
|
|
{
|
|
auto fpath = this->filePath();
|
|
auto core = core_ins->parseCore();
|
|
if(path.size()){
|
|
auto storynode = core->queryStoryConcept(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->queryStoryStrongPoint(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);
|
|
}
|
|
}
|
|
|
|
textView()->setFocus();
|
|
}
|
|
|
|
Core::ExtensionFactory *SourceCodeEditor::factory() const
|
|
{
|
|
return factory_ins;
|
|
}
|
|
|
|
void SourceCodeEditor::reload(QList<Config::Configration *> configs)
|
|
{
|
|
auto family = Config::ConfigHelper::getConfigAsDefaultSequence(configs, {"sourcecodeeditor-setting", "default", "font", "family"}, "微软雅黑");
|
|
auto size = Config::ConfigHelper::getConfigAsDefaultSequence(configs, {"sourcecodeeditor-setting", "default", "font", "size"}, "20");
|
|
|
|
QFont font;
|
|
font.setFamily(family);
|
|
font.setPointSize(size.toUInt());
|
|
this->textDocument()->setDefaultFont(font);
|
|
}
|
|
|
|
void SourceCodeEditor::resetProcsType(const QString &suffix)
|
|
{
|
|
procs_type = suffix;
|
|
}
|
|
|
|
void SourceCodeEditor::modeReset(const QString &type) const
|
|
{
|
|
|
|
}
|
|
|
|
QList<QString> SourceCodeEditor::modes() const
|
|
{
|
|
return QList<QString>() << "源码编辑";
|
|
}
|
|
|
|
QString SourceCodeEditor::currentMode() const
|
|
{
|
|
return "源码编辑";
|
|
}
|
|
|
|
void SourceCodeEditor::jumpTo(const QList<QString> &path)
|
|
{
|
|
if(procs_type == "storyconcept")
|
|
concept_jump(path);
|
|
}
|
|
|
|
void SourceCodeEditor::setSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent)
|
|
{
|
|
static_cast<KeywordsHightlighter*>(highlighter_ins)->reset(core->parseCore()->queryDocument(src));
|
|
FormattedTextEdit::setSource(core, src, parent);
|
|
this->core_ins = core;
|
|
}
|
|
|
|
void SourceCodeEditor::rehighlighter()
|
|
{
|
|
this->highlighter_ins->rehighlight();
|
|
}
|
|
|
|
Core::Extension *SourceCodeEditorFactory::newInstance(Core::AppCore *core)
|
|
{
|
|
return new SourceCodeEditor(this);
|
|
}
|
|
|
|
QList<Core::Scale> SourceCodeEditorFactory::configs() const
|
|
{
|
|
return QList<Core::Scale>() << Core::Scale::Project << Core::Scale::Global;
|
|
}
|
|
|
|
namespace __temp {
|
|
class XMarksConfig : public QWidget
|
|
{
|
|
public:
|
|
XMarksConfig(Config::Configration* port)
|
|
{
|
|
auto layout = new QVBoxLayout(this);
|
|
auto font_family = Config::ConfigHelper::getConfigAsDefault(port, {"sourcecodeeditor-setting", "default", "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({"sourcecodeeditor-setting", "default", "font", "family"}, text);
|
|
});
|
|
layout->addWidget(fontfamily);
|
|
|
|
auto font_size = Config::ConfigHelper::getConfigAsDefault(port, {"sourcecodeeditor-setting", "default", "font", "size"}, "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({"sourcecodeeditor-setting", "default", "font", "size"}, QString("%1").arg(val));
|
|
});
|
|
layout->addWidget(fontsize);
|
|
|
|
layout->addWidget(new QWidget(this), 1);
|
|
}
|
|
};
|
|
}
|
|
|
|
QWidget *SourceCodeEditorFactory::getNewPanel(Config::Configration *config)
|
|
{
|
|
return new __temp::XMarksConfig(config);
|
|
}
|
|
|
|
QString SourceCodeEditorFactory::extensionName() const
|
|
{
|
|
return "源码编辑器";
|
|
}
|
|
|
|
QList<QString> SourceCodeEditorFactory::suffixPeers() const
|
|
{
|
|
return QList<QString>() << "storyconcept";
|
|
}
|