storyunitsourceedit完善和TextView重构
This commit is contained in:
parent
d9973e8804
commit
4013acbeeb
|
@ -32,7 +32,7 @@ bool SensitiveCore::contains(const QFileInfo &target) const
|
|||
return false;
|
||||
}
|
||||
|
||||
VariedTextView *SensitiveCore::queryTextComponent(const QWidget *child_view) const
|
||||
TextView *SensitiveCore::queryTextComponent(const QWidget *child_view) const
|
||||
{
|
||||
for(auto ins : sourcecode_map)
|
||||
if(ins->textView() == child_view)
|
||||
|
@ -44,7 +44,7 @@ VariedTextView *SensitiveCore::queryTextComponent(const QWidget *child_view) con
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
VariedTextView *SensitiveCore::queryTextComponent(const QFileInfo &target) const
|
||||
TextView *SensitiveCore::queryTextComponent(const QFileInfo &target) const
|
||||
{
|
||||
for(auto &it : sourcecode_map.keys())
|
||||
if(it == target.absoluteFilePath())
|
||||
|
@ -74,10 +74,10 @@ void SensitiveCore::closeTextComponent(const QFileInfo &target)
|
|||
}
|
||||
}
|
||||
|
||||
void SensitiveCore::addPerceptionList(VariedTextView *ins, SensitiveType type)
|
||||
void SensitiveCore::addPerceptionList(TextView *ins, SensitiveType type)
|
||||
{
|
||||
if(type == SensitiveType::CompileAtChanged){
|
||||
connect(ins, &VariedTextView::dataChanged, [ins, this](const QString &path){
|
||||
connect(ins, &TextView::dataChanged, [ins, this](const QString &path){
|
||||
this->recompile(path, ins->docName());
|
||||
});
|
||||
this->sourcecode_map[ins->filePath()] = ins;
|
||||
|
@ -104,21 +104,21 @@ void SensitiveCore::recompile(const QString &file_path, const QString &doc_name)
|
|||
ex();
|
||||
}
|
||||
|
||||
VariedTextView::VariedTextView()
|
||||
TextView::TextView()
|
||||
: QObject(nullptr){}
|
||||
|
||||
void VariedTextView::initSource(Core::AppCore *core, const QFileInfo &src, const QString &name, QWidget *parent)
|
||||
void TextView::initSource(Core::AppCore *core, const QFileInfo &src, const QString &name, QWidget *parent)
|
||||
{
|
||||
this->doc_name = name;
|
||||
this->initSource(core, src, parent);
|
||||
}
|
||||
|
||||
QString VariedTextView::filePath() const
|
||||
QString TextView::filePath() const
|
||||
{
|
||||
return source_x;
|
||||
}
|
||||
|
||||
void VariedTextView::save() const
|
||||
void TextView::save() const
|
||||
{
|
||||
QFile bout(filePath());
|
||||
if(!bout.open(QIODevice::WriteOnly|QIODevice::Text)){
|
||||
|
@ -131,12 +131,12 @@ void VariedTextView::save() const
|
|||
tout.flush();
|
||||
}
|
||||
|
||||
QString VariedTextView::docName() const
|
||||
QString TextView::docName() const
|
||||
{
|
||||
return doc_name;
|
||||
}
|
||||
|
||||
void VariedTextView::initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent)
|
||||
void TextView::initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent)
|
||||
{
|
||||
this->source_x = src.absoluteFilePath();
|
||||
if(parent)
|
||||
|
|
|
@ -11,12 +11,12 @@ namespace MakeTools {
|
|||
/**
|
||||
* @brief 变化的文本视图
|
||||
*/
|
||||
class VariedTextView : public QObject
|
||||
class TextView : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VariedTextView();
|
||||
virtual ~VariedTextView() = default;
|
||||
explicit TextView();
|
||||
virtual ~TextView() = default;
|
||||
|
||||
void initSource(Core::AppCore *core, const QFileInfo &src, const QString &name, QWidget *parent=nullptr);
|
||||
|
||||
|
@ -59,17 +59,17 @@ namespace MakeTools {
|
|||
void saveAll() const;
|
||||
|
||||
bool contains(const QFileInfo &target) const;
|
||||
VariedTextView *queryTextComponent(const QWidget *child_view) const;
|
||||
VariedTextView * queryTextComponent(const QFileInfo &target) const;
|
||||
TextView *queryTextComponent(const QWidget *child_view) const;
|
||||
TextView * queryTextComponent(const QFileInfo &target) const;
|
||||
void closeTextComponent(const QFileInfo &target);
|
||||
|
||||
void addPerceptionList(VariedTextView *ins, SensitiveType type = SensitiveType::CompileAtChanged);
|
||||
void addPerceptionList(TextView *ins, SensitiveType type = SensitiveType::CompileAtChanged);
|
||||
void addProcTrigger(std::function<void()> exc);
|
||||
|
||||
private:
|
||||
StoryTool *const make_core;
|
||||
QHash<QString, VariedTextView*> sourcecode_map;
|
||||
QHash<QString, VariedTextView*> plaintext_map;
|
||||
QHash<QString, TextView*> sourcecode_map;
|
||||
QHash<QString, TextView*> plaintext_map;
|
||||
QList<std::function<void()>> trigger_list;
|
||||
|
||||
void recompile(const QString &file_path, const QString &doc_name);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
namespace Components {
|
||||
|
||||
class FormattedTextEdit : public MakeTools::VariedTextView,
|
||||
class FormattedTextEdit : public MakeTools::TextView,
|
||||
public ContentPresent::ModeView
|
||||
{
|
||||
public:
|
||||
|
@ -21,6 +21,7 @@ namespace Components {
|
|||
virtual void setContexMenuProcess(std::function<void(QMenu*)> exu);
|
||||
virtual QTextCursor getTextCursor();
|
||||
virtual void setTextCursor(QTextCursor s);
|
||||
QTextEdit *const edit_square;
|
||||
|
||||
// ModeView interface
|
||||
public:
|
||||
|
@ -33,7 +34,6 @@ namespace Components {
|
|||
virtual void textContentReset(const QString &value) override;
|
||||
|
||||
private:
|
||||
QTextEdit *const edit_square;
|
||||
std::function<void(QMenu*)> ex_unit;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -113,7 +113,7 @@ void AppCore::openTextDocument(const QString &src, const QString &name)
|
|||
|
||||
this->make_tool->compile(QFileInfo(src), name);
|
||||
|
||||
VariedTextView *tview = dynamic_cast<VariedTextView*>(xfactorys[0]->newInstance(this));
|
||||
TextView *tview = dynamic_cast<TextView*>(xfactorys[0]->newInstance(this));
|
||||
tview->initSource(this, QFileInfo(src), name, views_holder);
|
||||
framework->addPerceptionList(tview);
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
#include <QComboBox>
|
||||
#include <QMenu>
|
||||
#include <QSpinBox>
|
||||
#include <QSplitter>
|
||||
#include <QVBoxLayout>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Core;
|
||||
using namespace Parse::Result;
|
||||
|
@ -11,14 +13,19 @@ using namespace Components;
|
|||
using namespace Enhancement;
|
||||
|
||||
StoryUnitSourceEdit::StoryUnitSourceEdit(FileExtensionFactory *factory)
|
||||
: words_highlighter(new KeywordsHightlighter(this)), factory_ins(factory)
|
||||
: refers_descriptions(new QTableView()), refers_model(new QStandardItemModel()),
|
||||
split(new QSplitter()),
|
||||
words_highlighter(new KeywordsHightlighter(this)), factory_ins(factory)
|
||||
{
|
||||
words_highlighter->setDocument(this->textDocument());
|
||||
refers_descriptions->setModel(refers_model);
|
||||
|
||||
this->setContexMenuProcess([this](QMenu *menu){
|
||||
menu->addSeparator();
|
||||
menu->addAction("刷新", [this](){words_highlighter->rehighlight();});
|
||||
});
|
||||
|
||||
connect(edit_square, &QTextEdit::cursorPositionChanged, this, &StoryUnitSourceEdit::cursor_contex_query);
|
||||
}
|
||||
|
||||
FileExtensionFactory *StoryUnitSourceEdit::factory() const
|
||||
|
@ -30,9 +37,9 @@ void StoryUnitSourceEdit::reloadConfigrations(QList<Config::Configration *> conf
|
|||
{
|
||||
// TODO: 设置格式
|
||||
auto font_family = Config::ConfigHelper::getConfigAsDefaultSequence
|
||||
(configs, {"sourcecode_unitedit","default_font","font_family"}, "微软雅黑");
|
||||
(configs, {"sourcecode_unitedit","default_font","font_family"}, "微软雅黑");
|
||||
auto font_size = Config::ConfigHelper::getConfigAsDefaultSequence(
|
||||
configs, {"sourcecode_unitedit","default_font","font_sizept"}, "20");
|
||||
configs, {"sourcecode_unitedit","default_font","font_sizept"}, "20");
|
||||
QFont default_font;
|
||||
default_font.setFamily(font_family);
|
||||
default_font.setPointSize(font_size.toInt());
|
||||
|
@ -69,11 +76,100 @@ void StoryUnitSourceEdit::initSource(Core::AppCore *core, const QFileInfo &src,
|
|||
{
|
||||
this->source_target = src;
|
||||
this->core_ins = core;
|
||||
this->refers_descriptions->setParent(parent);
|
||||
this->refers_model->setParent(parent);
|
||||
this->split->setParent(parent);
|
||||
|
||||
FormattedTextEdit::initSource(core, src, parent);
|
||||
static_cast<KeywordsHightlighter*>(words_highlighter)
|
||||
->reset(core->parseCore()->queryDocument(src));
|
||||
}
|
||||
|
||||
void StoryUnitSourceEdit::cursor_contex_query()
|
||||
{
|
||||
refers_model->clear();
|
||||
refers_model->setHorizontalHeaderLabels(QStringList() << "故事" << "内容");
|
||||
|
||||
auto cursor = edit_square->textCursor();
|
||||
auto doc = this->core_ins->parseCore()->queryDocument(QFileInfo(filePath()));
|
||||
auto words = doc->getWords(cursor.block().blockNumber());
|
||||
|
||||
QList<DesNode*> frags;
|
||||
for (auto &w : words) {
|
||||
QHash<uint, Parse::Result::DesNode*> nodes;
|
||||
|
||||
auto xhost = w->host();
|
||||
while (xhost != nullptr){
|
||||
nodes[xhost->typeValue()] = xhost;
|
||||
xhost = xhost->parent();
|
||||
}
|
||||
|
||||
if(!nodes.contains(NODE_STORYFRAGMENT))
|
||||
continue;
|
||||
|
||||
xhost = nodes[NODE_STORYFRAGMENT];
|
||||
if(!frags.contains(xhost))
|
||||
frags << xhost;
|
||||
}
|
||||
|
||||
auto less_equal_than = [](std::pair<uint, uint> a, std::pair<uint, uint> b)->bool{
|
||||
if(a.first < b.first)
|
||||
return true;
|
||||
else if(a.first == b.first)
|
||||
return a.second <= b.second;
|
||||
return false;
|
||||
};
|
||||
for(auto x : frags){
|
||||
auto first = x->refered().first();
|
||||
auto last = x->refered().last();
|
||||
|
||||
auto tcursor = std::make_pair(cursor.block().blockNumber(), cursor.positionInBlock());
|
||||
auto fcursor = std::make_pair(first->row(), first->column());
|
||||
auto lcursor = std::make_pair(last->row(), last->column()+last->length());
|
||||
|
||||
if(less_equal_than(fcursor, tcursor) && less_equal_than(tcursor, lcursor))
|
||||
{
|
||||
auto name = static_cast<NamedNode*>(x)->name();
|
||||
present_refersed_tips(name[1], name[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StoryUnitSourceEdit::present_refersed_tips(const QString &unit, const QString &frag)
|
||||
{
|
||||
QHash<QString, DesNode*> nodes;
|
||||
|
||||
auto storys = core_ins->parseCore()->allStoryBoards();
|
||||
for (auto s : storys) {
|
||||
auto xins = static_cast<NamedNode*>(s);
|
||||
auto refs_x = s->children();
|
||||
for(auto &ref : refs_x)
|
||||
if(ref->typeValue() == NODE_FRAGMENTREFERENCE){
|
||||
auto nm_ref = static_cast<NamedNode*>(ref);
|
||||
|
||||
if(nm_ref->name()[0] == frag && nm_ref->name()[1] == unit){
|
||||
nodes[xins->name()[0]] = ref;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(auto &nm : nodes.keys())
|
||||
{
|
||||
QList<QStandardItem*> row;
|
||||
row << new QStandardItem(nm);
|
||||
row.last()->setEditable(false);
|
||||
row << new QStandardItem(nodes[nm]->toString());
|
||||
row.last()->setEditable(false);
|
||||
|
||||
refers_model->appendRow(row);
|
||||
}
|
||||
|
||||
refers_descriptions->resizeColumnsToContents();
|
||||
refers_descriptions->resizeRowsToContents();
|
||||
}
|
||||
|
||||
void StoryUnitSourceEdit::jumpTo(const QList<QString> &path)
|
||||
{
|
||||
auto fpath = this->filePath();
|
||||
|
@ -107,6 +203,14 @@ void StoryUnitSourceEdit::resetProcsType(const QString &suffix)
|
|||
|
||||
}
|
||||
|
||||
QWidget *StoryUnitSourceEdit::textView() const
|
||||
{
|
||||
auto vins = FormattedTextEdit::textView();
|
||||
split->addWidget(vins);
|
||||
split->addWidget(this->refers_descriptions);
|
||||
return split;
|
||||
}
|
||||
|
||||
Extension *StoryUnitSourceEditFactory::newInstance(Core::AppCore *core)
|
||||
{
|
||||
return new StoryUnitSourceEdit(this);
|
||||
|
@ -129,7 +233,7 @@ namespace __temp {
|
|||
auto families = QFontDatabase().families(QFontDatabase::WritingSystem::SimplifiedChinese);
|
||||
fontfamily->addItems(families);
|
||||
auto family = Config::ConfigHelper::getConfigAsDefault(
|
||||
port, {"sourcecode_unitedit","default_font","font_family"}, "微软雅黑");
|
||||
port, {"sourcecode_unitedit","default_font","font_family"}, "微软雅黑");
|
||||
fontfamily->setCurrentText(family);
|
||||
connect(fontfamily, &QComboBox::currentTextChanged, [port](const QString &text){
|
||||
port->setConfig({"sourcecode_unitedit","default_font","font_family"}, text);
|
||||
|
@ -140,10 +244,10 @@ namespace __temp {
|
|||
fontsize->setRange(10, 200);
|
||||
fontsize->setSingleStep(1);
|
||||
auto size = Config::ConfigHelper::getConfigAsDefault(
|
||||
port,{"sourcecode_unitedit","default_font","font_sizept"}, "20");
|
||||
port,{"sourcecode_unitedit","default_font","font_sizept"}, "20");
|
||||
fontsize->setValue(size.toInt());
|
||||
connect(fontsize, QOverload<int>::of(&QSpinBox::valueChanged), [port](int val){
|
||||
port->setConfig({"sourcecode_unitedit","default_font","font_sizept"}, QString("%1").arg(val));
|
||||
port->setConfig({"sourcecode_unitedit","default_font","font_sizept"}, QString("%1").arg(val));
|
||||
});
|
||||
layout->addWidget(fontsize);
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
#include "SourceEditView.h"
|
||||
|
||||
#include <QSplitter>
|
||||
#include <QTableView>
|
||||
|
||||
namespace Components {
|
||||
class StoryUnitSourceEditFactory : public Core::FileExtensionFactory
|
||||
{
|
||||
|
@ -43,11 +46,17 @@ namespace Components {
|
|||
virtual void initSource(Core::AppCore *core, const QFileInfo &src, QWidget *parent=nullptr) override;
|
||||
|
||||
private:
|
||||
QTableView *const refers_descriptions;
|
||||
QStandardItemModel *const refers_model;
|
||||
QSplitter *const split;
|
||||
QSyntaxHighlighter *const words_highlighter;
|
||||
Core::FileExtensionFactory *const factory_ins;
|
||||
QFileInfo source_target;
|
||||
Core::AppCore *core_ins;
|
||||
|
||||
void cursor_contex_query();
|
||||
void present_refersed_tips(const QString &unit, const QString &frag);
|
||||
|
||||
// VariedTextView interface
|
||||
public:
|
||||
virtual void jumpTo(const QList<QString> &path) override;
|
||||
|
@ -55,6 +64,10 @@ namespace Components {
|
|||
// Extension interface
|
||||
public:
|
||||
virtual void resetProcsType(const QString &suffix) override;
|
||||
|
||||
// VariedTextView interface
|
||||
public:
|
||||
virtual QWidget *textView() const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue