QtNovelUI/WordsIDE/SourceEditView.cpp

355 lines
9.0 KiB
C++
Raw Normal View History

2022-11-17 08:26:05 +00:00
#include "SourceEditView.h"
2022-11-18 05:43:27 +00:00
#include "keywordshightlighter.h"
2022-11-18 23:47:32 +00:00
#include <QComboBox>
#include <QFont>
2022-11-18 05:43:27 +00:00
#include <QMenu>
2022-11-17 08:26:05 +00:00
using namespace Components;
using namespace Parse::Result;
2022-11-18 05:43:27 +00:00
using namespace Enhancement;
2022-11-18 23:47:32 +00:00
using namespace Core;
2022-11-17 08:26:05 +00:00
StoryChainSourceEdit::StoryChainSourceEdit(const QFileInfo &file, QWidget *parent)
: MakeTools::VariedTextView(file,parent), edit_square(new QTextEdit(parent)),
2022-11-18 05:43:27 +00:00
highter_ins(new KeywordsHightlighter(this)),
2022-11-17 08:26:05 +00:00
core_ins(nullptr)
{
connect(edit_square, &QTextEdit::textChanged, [this](){
emit this->dataChanged(this->core_ins->filePath());
});
highter_ins->setDocument(this->edit_square->document());
2022-11-18 05:43:27 +00:00
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));
});
2022-11-17 08:26:05 +00:00
}
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;
2022-11-18 05:43:27 +00:00
static_cast<Enhancement::KeywordsHightlighter*>(this->highter_ins)->reset(core_ins);
2022-11-17 08:26:05 +00:00
}
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);
}
2022-11-18 23:47:32 +00:00
ConfigHost *StoryChainSourceEdit::getConfigHost() const
2022-11-17 08:26:05 +00:00
{
2022-11-18 23:47:32 +00:00
return nullptr;
2022-11-17 08:26:05 +00:00
}
2022-11-18 23:47:32 +00:00
TextContentEdit::TextContentEdit(const QFileInfo &refer, QWidget *parent)
: FormattedTextEdit(refer, parent){}
2022-11-17 08:26:05 +00:00
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)
{
}
2022-11-18 23:47:32 +00:00
void TextContentEdit::rehighlighter()
2022-11-17 08:26:05 +00:00
{
}
StoryUnitSourceEdit::StoryUnitSourceEdit(const QFileInfo &refer, QWidget *parent)
2022-11-18 23:47:32 +00:00
: MakeTools::VariedTextView(refer,parent),
words_highlighter(new KeywordsHightlighter(this)),
edit_square(new QTextEdit(parent)), source_target(refer)
2022-11-17 08:26:05 +00:00
{
connect(edit_square, &QTextEdit::textChanged, [this](){
emit this->dataChanged(this->source_target.absoluteFilePath());
});
2022-11-18 23:47:32 +00:00
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));
});
2022-11-17 08:26:05 +00:00
}
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();
}
2022-11-18 23:47:32 +00:00
ConfigHost *StoryUnitSourceEdit::getConfigHost() const
{
return nullptr;
}
2022-11-17 08:26:05 +00:00
void StoryUnitSourceEdit::reset(Parse::Result::DocCore *syntax_base)
{
2022-11-18 23:47:32 +00:00
static_cast<KeywordsHightlighter*>(words_highlighter)->reset(syntax_base);
2022-11-17 08:26:05 +00:00
}
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)
2022-11-18 23:47:32 +00:00
: MakeTools::VariedTextView(refer,parent),
words_highlighter(new KeywordsHightlighter(this)),
edit_square(new QTextEdit(parent)), source_target(refer)
2022-11-17 08:26:05 +00:00
{
connect(edit_square, &QTextEdit::textChanged, [this](){
emit this->dataChanged(this->source_target.absoluteFilePath());
});
2022-11-18 23:47:32 +00:00
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));
});
2022-11-17 08:26:05 +00:00
}
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();
}
2022-11-18 23:47:32 +00:00
ConfigHost *StoryBoardSourceEdit::getConfigHost() const
2022-11-17 08:26:05 +00:00
{
2022-11-18 23:47:32 +00:00
return nullptr;
}
2022-11-17 08:26:05 +00:00
2022-11-18 23:47:32 +00:00
void StoryBoardSourceEdit::reset(Parse::Result::DocCore *syntax_base)
{
static_cast<KeywordsHightlighter*>(words_highlighter)->reset(syntax_base);
2022-11-17 08:26:05 +00:00
}
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)
2022-11-18 23:47:32 +00:00
: MakeTools::VariedTextView(refer,parent),
words_highlighter(new KeywordsHightlighter(this)),
edit_square(new QTextEdit(parent)), source_target(refer)
2022-11-17 08:26:05 +00:00
{
connect(edit_square, &QTextEdit::textChanged, [this](){
emit this->dataChanged(this->source_target.absoluteFilePath());
});
2022-11-18 23:47:32 +00:00
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));
});
2022-11-17 08:26:05 +00:00
}
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();
}
2022-11-18 23:47:32 +00:00
ConfigHost *StoryVolumeSourceEdit::getConfigHost() const
2022-11-17 08:26:05 +00:00
{
2022-11-18 23:47:32 +00:00
return nullptr;
}
2022-11-17 08:26:05 +00:00
2022-11-18 23:47:32 +00:00
void StoryVolumeSourceEdit::reset(Parse::Result::DocCore *syntax_base)
{
static_cast<KeywordsHightlighter*>(words_highlighter)->reset(syntax_base);
2022-11-17 08:26:05 +00:00
}
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);
}
2022-11-18 23:47:32 +00:00
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;
}