355 lines
9.0 KiB
C++
355 lines
9.0 KiB
C++
#include "SourceEditView.h"
|
||
#include "keywordshightlighter.h"
|
||
#include <QComboBox>
|
||
#include <QFont>
|
||
#include <QMenu>
|
||
|
||
using namespace Components;
|
||
using namespace Parse::Result;
|
||
using namespace Enhancement;
|
||
using namespace Core;
|
||
|
||
StoryChainSourceEdit::StoryChainSourceEdit(const QFileInfo &file, QWidget *parent)
|
||
: MakeTools::VariedTextView(file,parent), edit_square(new QTextEdit(parent)),
|
||
highter_ins(new KeywordsHightlighter(this)),
|
||
core_ins(nullptr)
|
||
{
|
||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||
emit this->dataChanged(this->core_ins->filePath());
|
||
});
|
||
|
||
highter_ins->setDocument(this->edit_square->document());
|
||
|
||
edit_square->setContextMenuPolicy(Qt::CustomContextMenu);
|
||
connect(edit_square, &QTextEdit::customContextMenuRequested, [this](const QPoint &pos){
|
||
auto menu = edit_square->createStandardContextMenu();
|
||
menu->addSeparator();
|
||
menu->addAction("刷新", [this](){highter_ins->rehighlight();});
|
||
menu->exec(edit_square->mapToGlobal(pos));
|
||
});
|
||
}
|
||
|
||
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 core_ins->filePath();
|
||
}
|
||
|
||
void StoryChainSourceEdit::reset(Parse::Result::DocCore *syntax_base)
|
||
{
|
||
this->core_ins = syntax_base;
|
||
static_cast<Enhancement::KeywordsHightlighter*>(this->highter_ins)->reset(core_ins);
|
||
}
|
||
|
||
QWidget *StoryChainSourceEdit::textView() const
|
||
{
|
||
return edit_square;
|
||
}
|
||
|
||
QString StoryChainSourceEdit::textContent() const
|
||
{
|
||
return edit_square->toPlainText();
|
||
}
|
||
|
||
void StoryChainSourceEdit::textContentReset(const QString &value)
|
||
{
|
||
this->edit_square->setText(value);
|
||
}
|
||
|
||
ConfigHost *StoryChainSourceEdit::getConfigHost() const
|
||
{
|
||
return nullptr;
|
||
}
|
||
|
||
TextContentEdit::TextContentEdit(const QFileInfo &refer, QWidget *parent)
|
||
: FormattedTextEdit(refer, parent){}
|
||
|
||
void TextContentEdit::modeReset(const QString &) const
|
||
{
|
||
|
||
}
|
||
|
||
QList<QString> TextContentEdit::modes() const
|
||
{
|
||
return QList<QString>() << "文本";
|
||
}
|
||
|
||
QString TextContentEdit::currentMode() const
|
||
{
|
||
return modes()[0];
|
||
}
|
||
|
||
QString TextContentEdit::title() const
|
||
{
|
||
return source_target.fileName();
|
||
}
|
||
|
||
void TextContentEdit::reset(Parse::Result::DocCore *syntax_base)
|
||
{
|
||
|
||
}
|
||
|
||
void TextContentEdit::rehighlighter()
|
||
{
|
||
|
||
}
|
||
|
||
StoryUnitSourceEdit::StoryUnitSourceEdit(const QFileInfo &refer, QWidget *parent)
|
||
: MakeTools::VariedTextView(refer,parent),
|
||
words_highlighter(new KeywordsHightlighter(this)),
|
||
edit_square(new QTextEdit(parent)), source_target(refer)
|
||
{
|
||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||
emit this->dataChanged(this->source_target.absoluteFilePath());
|
||
});
|
||
|
||
words_highlighter->setDocument(this->edit_square->document());
|
||
|
||
edit_square->setContextMenuPolicy(Qt::CustomContextMenu);
|
||
connect(edit_square, &QTextEdit::customContextMenuRequested, [this](const QPoint &pos){
|
||
auto menu = edit_square->createStandardContextMenu();
|
||
menu->addSeparator();
|
||
menu->addAction("刷新", [this](){words_highlighter->rehighlight();});
|
||
menu->exec(edit_square->mapToGlobal(pos));
|
||
});
|
||
}
|
||
|
||
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();
|
||
}
|
||
|
||
ConfigHost *StoryUnitSourceEdit::getConfigHost() const
|
||
{
|
||
return nullptr;
|
||
}
|
||
|
||
void StoryUnitSourceEdit::reset(Parse::Result::DocCore *syntax_base)
|
||
{
|
||
|
||
static_cast<KeywordsHightlighter*>(words_highlighter)->reset(syntax_base);
|
||
}
|
||
|
||
QWidget *StoryUnitSourceEdit::textView() const
|
||
{
|
||
return edit_square;
|
||
}
|
||
|
||
QString StoryUnitSourceEdit::textContent() const
|
||
{
|
||
return edit_square->toPlainText();
|
||
}
|
||
|
||
void StoryUnitSourceEdit::textContentReset(const QString &value)
|
||
{
|
||
edit_square->setText(value);
|
||
}
|
||
|
||
StoryBoardSourceEdit::StoryBoardSourceEdit(const QFileInfo &refer, QWidget *parent)
|
||
: MakeTools::VariedTextView(refer,parent),
|
||
words_highlighter(new KeywordsHightlighter(this)),
|
||
edit_square(new QTextEdit(parent)), source_target(refer)
|
||
{
|
||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||
emit this->dataChanged(this->source_target.absoluteFilePath());
|
||
});
|
||
|
||
words_highlighter->setDocument(this->edit_square->document());
|
||
|
||
edit_square->setContextMenuPolicy(Qt::CustomContextMenu);
|
||
connect(edit_square, &QTextEdit::customContextMenuRequested, [this](const QPoint &pos){
|
||
auto menu = edit_square->createStandardContextMenu();
|
||
menu->addSeparator();
|
||
menu->addAction("刷新", [this](){words_highlighter->rehighlight();});
|
||
menu->exec(edit_square->mapToGlobal(pos));
|
||
});
|
||
}
|
||
|
||
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();
|
||
}
|
||
|
||
ConfigHost *StoryBoardSourceEdit::getConfigHost() const
|
||
{
|
||
return nullptr;
|
||
}
|
||
|
||
void StoryBoardSourceEdit::reset(Parse::Result::DocCore *syntax_base)
|
||
{
|
||
static_cast<KeywordsHightlighter*>(words_highlighter)->reset(syntax_base);
|
||
}
|
||
|
||
QWidget *StoryBoardSourceEdit::textView() const
|
||
{
|
||
return edit_square;
|
||
}
|
||
|
||
QString StoryBoardSourceEdit::textContent() const
|
||
{
|
||
return edit_square->toPlainText();
|
||
}
|
||
|
||
void StoryBoardSourceEdit::textContentReset(const QString &value)
|
||
{
|
||
this->edit_square->setText(value);
|
||
}
|
||
|
||
StoryVolumeSourceEdit::StoryVolumeSourceEdit(const QFileInfo &refer, QWidget *parent)
|
||
: MakeTools::VariedTextView(refer,parent),
|
||
words_highlighter(new KeywordsHightlighter(this)),
|
||
edit_square(new QTextEdit(parent)), source_target(refer)
|
||
{
|
||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||
emit this->dataChanged(this->source_target.absoluteFilePath());
|
||
});
|
||
|
||
words_highlighter->setDocument(this->edit_square->document());
|
||
|
||
edit_square->setContextMenuPolicy(Qt::CustomContextMenu);
|
||
connect(edit_square, &QTextEdit::customContextMenuRequested, [this](const QPoint &pos){
|
||
auto menu = edit_square->createStandardContextMenu();
|
||
menu->addSeparator();
|
||
menu->addAction("刷新", [this](){words_highlighter->rehighlight();});
|
||
menu->exec(edit_square->mapToGlobal(pos));
|
||
});
|
||
}
|
||
|
||
void StoryVolumeSourceEdit::modeReset(const QString &) const{}
|
||
|
||
QList<QString> StoryVolumeSourceEdit::modes() const
|
||
{
|
||
return QList<QString>() << "源码";
|
||
}
|
||
|
||
QString StoryVolumeSourceEdit::currentMode() const
|
||
{
|
||
return modes()[0];
|
||
}
|
||
|
||
QString StoryVolumeSourceEdit::title() const
|
||
{
|
||
return source_target.fileName();
|
||
}
|
||
|
||
ConfigHost *StoryVolumeSourceEdit::getConfigHost() const
|
||
{
|
||
return nullptr;
|
||
}
|
||
|
||
void StoryVolumeSourceEdit::reset(Parse::Result::DocCore *syntax_base)
|
||
{
|
||
static_cast<KeywordsHightlighter*>(words_highlighter)->reset(syntax_base);
|
||
}
|
||
|
||
QWidget *StoryVolumeSourceEdit::textView() const
|
||
{
|
||
return edit_square;
|
||
}
|
||
|
||
QString StoryVolumeSourceEdit::textContent() const
|
||
{
|
||
return edit_square->toPlainText();
|
||
}
|
||
|
||
void StoryVolumeSourceEdit::textContentReset(const QString &value)
|
||
{
|
||
this->edit_square->setText(value);
|
||
}
|
||
|
||
FormattedTextEdit::FormattedTextEdit(const QFileInfo &file, QWidget *parent)
|
||
: MakeTools::VariedTextView(file, parent), edit_square(new QTextEdit(parent)), source_target(file)
|
||
{
|
||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||
emit this->dataChanged(this->source_target.absoluteFilePath());
|
||
});
|
||
}
|
||
|
||
Core::ConfigHost *FormattedTextEdit::getConfigHost() const
|
||
{
|
||
return const_cast<FormattedTextEdit*>(this);
|
||
}
|
||
|
||
QWidget *FormattedTextEdit::textView() const
|
||
{
|
||
return edit_square;
|
||
}
|
||
|
||
QString FormattedTextEdit::textContent() const
|
||
{
|
||
return edit_square->toPlainText();
|
||
}
|
||
|
||
void FormattedTextEdit::textContentReset(const QString &value)
|
||
{
|
||
edit_square->setPlainText(value);
|
||
}
|
||
|
||
QList<Core::Scale> FormattedTextEdit::configs() const
|
||
{
|
||
return QList<Scale>() << Scale::Global << Scale::Project;
|
||
}
|
||
|
||
void FormattedTextEdit::reload(QList<Config::Configration *> configs)
|
||
{
|
||
this->configrations_host = configs;
|
||
|
||
// TODO: 设置格式
|
||
auto font_family = Config::ConfigHelper::getConfigAsDefaultSequence
|
||
(configs, {"sourcecode_edit","default_font","font_family"}, "微软雅黑");
|
||
QFont default_font;
|
||
default_font.setFamily(font_family);
|
||
|
||
this->edit_square->document()->setDefaultFont(default_font);
|
||
this->rehighlighter();
|
||
}
|
||
|
||
QWidget *FormattedTextEdit::getPanel(Config::Configration *config)
|
||
{
|
||
auto combobox = new QComboBox();
|
||
combobox->addItems(QFontDatabase().families(QFontDatabase::WritingSystem::SimplifiedChinese));
|
||
connect(combobox, &QComboBox::currentTextChanged, [this](const QString &text){
|
||
this->edit_square->setFont(QFont(text));
|
||
});
|
||
|
||
return combobox;
|
||
}
|