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-22 03:42:48 +00:00
|
|
|
|
#include <QGridLayout>
|
2022-11-18 05:43:27 +00:00
|
|
|
|
#include <QMenu>
|
2022-11-22 03:42:48 +00:00
|
|
|
|
#include <QSpinBox>
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
TextContentEdit::TextContentEdit(FileExtensionFactory *factory)
|
|
|
|
|
: factory_ins(factory){}
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
FileExtensionFactory *TextContentEdit::factory() const
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
2022-11-22 03:42:48 +00:00
|
|
|
|
return factory_ins;
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
void TextContentEdit::jumpTo(const QList<QString> &path)
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 03:47:12 +00:00
|
|
|
|
void TextContentEdit::reloadConfigrations(QList<Config::Configration *> configs)
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
2022-11-22 03:42:48 +00:00
|
|
|
|
// 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());
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-25 01:18:54 +00:00
|
|
|
|
this->textDocument()->setDefaultFont(default_font);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
void TextContentEdit::rehighlighter()
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
void TextContentEdit::resetProcsType(const QString &suffix)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
FormattedTextEdit::FormattedTextEdit()
|
|
|
|
|
: edit_square(new QTextEdit())
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
2022-11-25 07:30:33 +00:00
|
|
|
|
ex_unit = [](QMenu*){};
|
2022-11-17 08:26:05 +00:00
|
|
|
|
connect(edit_square, &QTextEdit::textChanged, [this](){
|
2022-12-31 13:05:58 +00:00
|
|
|
|
emit this->dataChanged(this->absoluteFilePath());
|
2022-11-18 23:47:32 +00:00
|
|
|
|
});
|
2022-11-25 07:30:33 +00:00
|
|
|
|
|
|
|
|
|
edit_square->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
connect(edit_square, &QTextEdit::customContextMenuRequested,
|
|
|
|
|
[this](const QPoint& p){
|
|
|
|
|
auto menu = edit_square->createStandardContextMenu();
|
|
|
|
|
ex_unit(menu);
|
|
|
|
|
|
|
|
|
|
menu->exec(edit_square->mapToGlobal(p));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-01 05:10:31 +00:00
|
|
|
|
FormattedTextEdit::~FormattedTextEdit()
|
|
|
|
|
{
|
|
|
|
|
if(edit_square){
|
|
|
|
|
delete edit_square;
|
|
|
|
|
edit_square = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
void FormattedTextEdit::setContexMenuProcess(std::function<void (QMenu *)> exu)
|
|
|
|
|
{
|
|
|
|
|
this->ex_unit = exu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTextCursor FormattedTextEdit::getTextCursor()
|
|
|
|
|
{
|
|
|
|
|
return edit_square->textCursor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FormattedTextEdit::setTextCursor(QTextCursor s)
|
|
|
|
|
{
|
|
|
|
|
edit_square->setTextCursor(s);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
QString FormattedTextEdit::title() const
|
2022-11-25 01:18:54 +00:00
|
|
|
|
{
|
2022-11-25 07:30:33 +00:00
|
|
|
|
return docName();
|
2022-11-25 01:18:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTextDocument *FormattedTextEdit::textDocument() const
|
|
|
|
|
{
|
|
|
|
|
return edit_square->document();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
QWidget *FormattedTextEdit::textView() const
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
|
|
|
|
return edit_square;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
QString FormattedTextEdit::textContent() const
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
|
|
|
|
return edit_square->toPlainText();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
void FormattedTextEdit::textContentReset(const QString &value)
|
2022-11-17 08:26:05 +00:00
|
|
|
|
{
|
2022-11-22 03:42:48 +00:00
|
|
|
|
edit_square->setPlainText(value);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-25 09:44:18 +00:00
|
|
|
|
namespace __impl_temp {
|
2022-11-22 03:42:48 +00:00
|
|
|
|
class TextEditConfigration : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TextEditConfigration(Config::Configration* port)
|
|
|
|
|
{
|
|
|
|
|
auto layout = new QVBoxLayout(this);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
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);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
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<int>::of(&QSpinBox::valueChanged), [port](int val){
|
|
|
|
|
port->setConfig({"sourcecode_edit","default_font","font_sizept"}, QString("%1").arg(val));
|
|
|
|
|
});
|
|
|
|
|
layout->addWidget(fontsize);
|
2022-11-17 08:26:05 +00:00
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
layout->addWidget(new QWidget(this), 1);
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-11-17 08:26:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-18 23:47:32 +00:00
|
|
|
|
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
TextContentEditFactory::TextContentEditFactory()
|
2022-11-18 23:47:32 +00:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 01:18:54 +00:00
|
|
|
|
Extension *TextContentEditFactory::newInstance(Core::AppCore *core)
|
2022-11-18 23:47:32 +00:00
|
|
|
|
{
|
2022-11-22 03:42:48 +00:00
|
|
|
|
return new TextContentEdit(this);
|
2022-11-18 23:47:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
QList<Scale> TextContentEditFactory::configs() const
|
2022-11-18 23:47:32 +00:00
|
|
|
|
{
|
2022-11-22 03:42:48 +00:00
|
|
|
|
return QList<Scale>() << Scale::Global << Scale::Project;
|
2022-11-18 23:47:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
QWidget *TextContentEditFactory::getNewPanel(Config::Configration *config)
|
2022-11-18 23:47:32 +00:00
|
|
|
|
{
|
2023-02-25 09:44:18 +00:00
|
|
|
|
return new __impl_temp::TextEditConfigration(config);
|
2022-11-18 23:47:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
QString TextContentEditFactory::extensionName() const
|
2022-11-18 23:47:32 +00:00
|
|
|
|
{
|
2022-11-22 03:42:48 +00:00
|
|
|
|
return "文本编辑器";
|
2022-11-18 23:47:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 01:32:42 +00:00
|
|
|
|
QList<QString> TextContentEditFactory::suffixPeers() const
|
2022-11-18 23:47:32 +00:00
|
|
|
|
{
|
2022-11-25 01:32:42 +00:00
|
|
|
|
return QList<QString>() << "*";
|
2022-11-18 23:47:32 +00:00
|
|
|
|
}
|