207 lines
4.9 KiB
C++
207 lines
4.9 KiB
C++
#include "SourceEditView.h"
|
||
#include "keywordshightlighter.h"
|
||
#include <QComboBox>
|
||
#include <QFont>
|
||
#include <QGridLayout>
|
||
#include <QMenu>
|
||
#include <QSpinBox>
|
||
|
||
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<QString> TextContentEdit::modes() const
|
||
{
|
||
return QList<QString>() << "文本";
|
||
}
|
||
|
||
QString TextContentEdit::currentMode() const
|
||
{
|
||
return modes()[0];
|
||
}
|
||
|
||
QString TextContentEdit::title() const
|
||
{
|
||
return source_target.fileName();
|
||
}
|
||
|
||
void TextContentEdit::jumpTo(const QList<QString> &path)
|
||
{
|
||
|
||
}
|
||
|
||
void TextContentEdit::reloadConfigrations(QList<Config::Configration *> 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);
|
||
}
|
||
|
||
void TextContentEdit::rehighlighter()
|
||
{
|
||
|
||
}
|
||
|
||
void TextContentEdit::resetProcsType(const QString &suffix)
|
||
{
|
||
|
||
}
|
||
|
||
|
||
FormattedTextEdit::FormattedTextEdit()
|
||
: edit_square(new QTextEdit())
|
||
{
|
||
ex_unit = [](QMenu*){};
|
||
connect(edit_square, &QTextEdit::textChanged, [this](){
|
||
emit this->dataChanged(this->absoluteFilePath());
|
||
});
|
||
|
||
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));
|
||
});
|
||
}
|
||
|
||
FormattedTextEdit::~FormattedTextEdit()
|
||
{
|
||
if(edit_square){
|
||
delete edit_square;
|
||
edit_square = nullptr;
|
||
}
|
||
}
|
||
|
||
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);
|
||
}
|
||
|
||
QString FormattedTextEdit::title() const
|
||
{
|
||
return docName();
|
||
}
|
||
|
||
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<int>::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<Scale> TextContentEditFactory::configs() const
|
||
{
|
||
return QList<Scale>() << Scale::Global << Scale::Project;
|
||
}
|
||
|
||
QWidget *TextContentEditFactory::getNewPanel(Config::Configration *config)
|
||
{
|
||
return new __temp::TextEditConfigration(config);
|
||
}
|
||
|
||
QString TextContentEditFactory::extensionName() const
|
||
{
|
||
return "文本编辑器";
|
||
}
|
||
|
||
QList<QString> TextContentEditFactory::suffixPeers() const
|
||
{
|
||
return QList<QString>() << "*";
|
||
}
|