#include "SourceEditView.h" #include "keywordshightlighter.h" #include #include #include #include #include using namespace Components; using namespace Parse::Result; using namespace Enhancement; using namespace Core; TextContentEdit::TextContentEdit(FileExtensionFactory *factory) : factory_ins(factory){} FileExtensionFactory *TextContentEdit::factory() const { return factory_ins; } void TextContentEdit::modeReset(const QString &) const { } QList TextContentEdit::modes() const { return QList() << "文本"; } QString TextContentEdit::currentMode() const { return modes()[0]; } QString TextContentEdit::title() const { return source_target.fileName(); } void TextContentEdit::jumpTo(const QList &path) { } void TextContentEdit::reload(QList configs) { this->configrations_host = configs; // TODO: 设置格式 auto font_family = Config::ConfigHelper::getConfigAsDefaultSequence (configs, {"sourcecode_edit","default_font","font_family"}, "微软雅黑"); auto font_size = Config::ConfigHelper::getConfigAsDefaultSequence( configs, {"sourcecode_edit","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 TextContentEdit::rehighlighter() { } FormattedTextEdit::FormattedTextEdit() : edit_square(new QTextEdit()) { connect(edit_square, &QTextEdit::textChanged, [this](){ emit this->dataChanged(this->filePath()); }); } void FormattedTextEdit::resetHighlighter(QSyntaxHighlighter *lighter) { lighter->setDocument(this->edit_square->document()); } QTextDocument *FormattedTextEdit::textDocument() const { return edit_square->document(); } 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); } namespace __temp { class TextEditConfigration : public QWidget { public: TextEditConfigration(Config::Configration* port) { auto layout = new QVBoxLayout(this); auto fontfamily = new QComboBox(this); auto families = QFontDatabase().families(QFontDatabase::WritingSystem::SimplifiedChinese); fontfamily->addItems(families); auto family = Config::ConfigHelper::getConfigAsDefault( port, {"sourcecode_edit","default_font","font_family"}, "微软雅黑"); fontfamily->setCurrentText(family); connect(fontfamily, &QComboBox::currentTextChanged, [port](const QString &text){ port->setConfig({"sourcecode_edit","default_font","font_family"}, text); }); layout->addWidget(fontfamily); auto fontsize = new QSpinBox(this); fontsize->setRange(10, 200); fontsize->setSingleStep(1); auto size = Config::ConfigHelper::getConfigAsDefault( port, {"sourcecode_edit","default_font","font_sizept"}, "20"); fontsize->setValue(size.toInt()); connect(fontsize, QOverload::of(&QSpinBox::valueChanged), [port](int val){ port->setConfig({"sourcecode_edit","default_font","font_sizept"}, QString("%1").arg(val)); }); layout->addWidget(fontsize); layout->addWidget(new QWidget(this), 1); } }; } TextContentEditFactory::TextContentEditFactory() { } Extension *TextContentEditFactory::newInstance(Core::AppCore *core) { return new TextContentEdit(this); } QList TextContentEditFactory::configs() const { return QList() << Scale::Global << Scale::Project; } QWidget *TextContentEditFactory::getNewPanel(Config::Configration *config) { return new __temp::TextEditConfigration(config); } QString TextContentEditFactory::extensionName() const { return "文本编辑器"; } QList TextContentEditFactory::suffixPeers() const { return QList() << "*"; }