QtNovelUI/WordsIDE/srcedit_storyboard.cpp

123 lines
3.8 KiB
C++
Raw Normal View History

#include "srcedit_storyboard.h"
#include "keywordshighlighter.h"
#include <QComboBox>
#include <QMenu>
#include <QSpinBox>
#include <QTextStream>
#include <QVBoxLayout>
using namespace Enhancement;
using namespace Core;
2023-08-20 17:22:48 +00:00
using namespace Config;
using namespace Presents;
QString StorySourceEdit::file_suffix = "storyboard";
2023-08-27 14:09:46 +00:00
StorySourceEdit::StorySourceEdit(DocumentsManager *mgr, const Route &p, QObject *parent)
: FilePresent(parent), mgr_inst(mgr), path_store(p), edit_square(new QTextEdit) {
// words_highlighter->setDocument(this->edit_square->document());
connect(edit_square, &QTextEdit::textChanged, [this](){
emit this->dataChanged(filepath_store);
});
}
void StorySourceEdit::contexBinding(Core::AppCore *app) { this->core_temp = app; }
void StorySourceEdit::renderRepeat() const {
// this->words_highlighter->rehighlight();
}
QWidget *StorySourceEdit::widget() const
{
return edit_square;
}
QString StorySourceEdit::name() const
{
return this->name_store;
}
void StorySourceEdit::load(const QFileInfo &target_file)
{
if(!target_file.exists())
2023-08-20 17:22:48 +00:00
throw new SimpleException<QString>("参数错误", "传入的文件不存在:" + target_file.absoluteFilePath());
if(!target_file.isFile())
2023-08-20 17:22:48 +00:00
throw new SimpleException<QString>("参数错误", "传入参数非文件类型:" + target_file.absoluteFilePath());
2023-08-20 17:22:48 +00:00
filepath_store = target_file.canonicalFilePath();
QFile bin(filepath_store);
if(!bin.open(QIODevice::ReadOnly|QIODevice::Text))
2023-08-20 17:22:48 +00:00
throw new SimpleException<QString>("参数错误", "指定的文件无法打开:" + target_file.absoluteFilePath());
QTextStream tin(&bin);
tin.setCodec("UTF-8");
this->edit_square->setText(tin.readAll());
}
void StorySourceEdit::saveAs(const QString &path)
{
if(!path.isEmpty())
filepath_store = path;
QFile bout(filepath_store);
if(!bout.open(QIODevice::WriteOnly|QIODevice::Text))
2023-08-20 17:22:48 +00:00
throw new SimpleException<QString>("保存文件参数错误", "指定的文件无法打开:" + path);
QTextStream tout(&bout);
tout.setCodec("UTF-8");
tout << this->edit_square->toPlainText();
tout.flush();
}
QString StorySourceEdit::relativeTargetPath(const QDir &base) const
{
return base.relativeFilePath(filepath_store);
}
QString StorySourceEdit::absoluteTargetPath() const
{
return filepath_store;
}
bool StorySourceEdit::isModified() const
{
return true;
}
2023-08-15 14:40:40 +00:00
void StorySourceEdit::applySetting(const QString &name) { this->name_store = name; }
void StorySourceEdit::jumpTo(const QList<QString> &path) {
// auto fpath = this->absoluteTargetPath();
// auto core = core_temp->parseCore();
// if(path.size()){
// auto storynode = core->queryStoryBoard(path[0]).first();
// auto first_word = storynode->refered()[0];
// auto textblock = this->edit_square->document()->findBlockByNumber(first_word->row());
// auto cur = this->edit_square->textCursor();
// cur.setPosition(textblock.position());
// this->edit_square->setTextCursor(cur);
// }
}
2023-08-27 14:09:46 +00:00
#include "manager_docs.h"
void StorySourceEdit::beforeClose() { mgr_inst->save(); }
DocumentsManager *StorySourceEdit::docsManager() const { return mgr_inst; }
Route StorySourceEdit::accessPath() const { return path_store; }
void StorySourceEditFactory::create(const QFileInfo &target) {
QFile base_f(target.canonicalFilePath());
if (!base_f.exists()) {
2023-08-27 14:09:46 +00:00
throw new SimpleException<bool>("新建错误", "指定路径不合法,文件不存在:" + target.absoluteFilePath());
}
if (!base_f.open(QIODevice::WriteOnly | QIODevice::Text))
2023-08-27 14:09:46 +00:00
throw new SimpleException<bool>("新建错误", QString("指定文件无法建立:" + target.absoluteFilePath()));
base_f.write(" ");
base_f.flush();
base_f.close();
}