2022-11-22 03:42:48 +00:00
|
|
|
|
#include "storyvolumesourceedit.h"
|
|
|
|
|
#include "keywordshightlighter.h"
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QSpinBox>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
using namespace Components;
|
|
|
|
|
using namespace Parse::Result;
|
|
|
|
|
using namespace Enhancement;
|
|
|
|
|
using namespace Core;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FileExtensionFactory *StoryVolumeSourceEdit::factory() const
|
|
|
|
|
{
|
|
|
|
|
return factory_ins;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 03:47:12 +00:00
|
|
|
|
void StoryVolumeSourceEdit::reloadConfigrations(QList<Config::Configration *> configs)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
// TODO: 设置格式
|
|
|
|
|
auto font_family = Config::ConfigHelper::getConfigAsDefaultSequence
|
|
|
|
|
(configs, {"sourcecode_voledit","default_font","font_family"}, "微软雅黑");
|
|
|
|
|
auto font_size = Config::ConfigHelper::getConfigAsDefaultSequence(
|
|
|
|
|
configs, {"sourcecode_voledit","default_font","font_sizept"}, "20");
|
|
|
|
|
QFont default_font;
|
|
|
|
|
default_font.setFamily(font_family);
|
|
|
|
|
default_font.setPointSize(font_size.toInt());
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
this->textDocument()->setDefaultFont(default_font);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
void StoryVolumeSourceEdit::resetProcsType(const QString &suffix)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 03:42:48 +00:00
|
|
|
|
StoryVolumeSourceEdit::StoryVolumeSourceEdit(FileExtensionFactory *factory)
|
|
|
|
|
: words_highlighter(new KeywordsHightlighter(this)), factory_ins(factory)
|
|
|
|
|
{
|
2022-11-25 07:30:33 +00:00
|
|
|
|
words_highlighter->setDocument(this->textDocument());
|
2022-11-22 03:42:48 +00:00
|
|
|
|
|
2022-11-25 07:30:33 +00:00
|
|
|
|
this->setContexMenuProcess([this](QMenu *menu){
|
2022-11-22 03:42:48 +00:00
|
|
|
|
menu->addSeparator();
|
|
|
|
|
menu->addAction("刷新", [this](){words_highlighter->rehighlight();});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-29 03:47:12 +00:00
|
|
|
|
void StoryVolumeSourceEdit::initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
this->source_target = src;
|
2022-11-29 03:47:12 +00:00
|
|
|
|
FormattedTextEdit::initSource(core, src, parent);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
static_cast<KeywordsHightlighter*>(words_highlighter)
|
|
|
|
|
->reset(core->parseCore()->queryDocument(src));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryVolumeSourceEdit::rehighlighter()
|
|
|
|
|
{
|
|
|
|
|
this->words_highlighter->rehighlight();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StoryVolumeSourceEdit::jumpTo(const QList<QString> &path)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-11-25 01:18:54 +00:00
|
|
|
|
Extension *StoryVolumeSourceEditFactory::newInstance(Core::AppCore *core)
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
|
|
|
|
return new StoryVolumeSourceEdit(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<Scale> StoryVolumeSourceEditFactory::configs() const
|
|
|
|
|
{
|
|
|
|
|
return QList<Scale>() << Scale::Project << Scale::Global;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-25 09:44:18 +00:00
|
|
|
|
namespace __impl_temp {
|
2022-11-22 03:42:48 +00:00
|
|
|
|
class VolumeConfigration : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
VolumeConfigration(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_voledit","default_font","font_family"}, "微软雅黑");
|
|
|
|
|
fontfamily->setCurrentText(family);
|
|
|
|
|
connect(fontfamily, &QComboBox::currentTextChanged, [port](const QString &text){
|
|
|
|
|
port->setConfig({"sourcecode_voledit","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_voledit","default_font","font_sizept"}, "20");
|
|
|
|
|
fontsize->setValue(size.toInt());
|
|
|
|
|
connect(fontsize, QOverload<int>::of(&QSpinBox::valueChanged), [port](int val){
|
|
|
|
|
port->setConfig({"sourcecode_voledit","default_font","font_sizept"}, QString("%1").arg(val));
|
|
|
|
|
});
|
|
|
|
|
layout->addWidget(fontsize);
|
|
|
|
|
|
|
|
|
|
layout->addWidget(new QWidget(this), 1);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
QWidget *StoryVolumeSourceEditFactory::getNewPanel(Config::Configration *config)
|
|
|
|
|
{
|
2023-02-25 09:44:18 +00:00
|
|
|
|
return new __impl_temp::VolumeConfigration(config);
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString StoryVolumeSourceEditFactory::extensionName() const
|
|
|
|
|
{
|
|
|
|
|
return "卷纲编辑";
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 01:32:42 +00:00
|
|
|
|
QList<QString> StoryVolumeSourceEditFactory::suffixPeers() const
|
2022-11-22 03:42:48 +00:00
|
|
|
|
{
|
2022-11-25 01:32:42 +00:00
|
|
|
|
return QList<QString>() << "storyvolume";
|
2022-11-22 03:42:48 +00:00
|
|
|
|
}
|