mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00

Move config related stuff to VConfigManager. For a config value, VConfigManager will first try to look it up in the user-scoped vnote.ini config file, if it is empty, then try to look it up in the default vnote.ini. Signed-off-by: Le Tan <tamlokveer@gmail.com>
75 lines
1.5 KiB
C++
75 lines
1.5 KiB
C++
#include <QtWidgets>
|
|
#include "vedit.h"
|
|
#include "vnote.h"
|
|
#include "vconfigmanager.h"
|
|
|
|
extern VConfigManager vconfig;
|
|
|
|
VEdit::VEdit(VNoteFile *noteFile, QWidget *parent)
|
|
: QTextEdit(parent), noteFile(noteFile)
|
|
{
|
|
if (noteFile->docType == DocType::Markdown) {
|
|
setPalette(vconfig.getMdEditPalette());
|
|
setFont(vconfig.getMdEditFont());
|
|
} else {
|
|
setFont(vconfig.getBaseEditFont());
|
|
}
|
|
}
|
|
|
|
void VEdit::beginEdit()
|
|
{
|
|
setReadOnly(false);
|
|
switch (noteFile->docType) {
|
|
case DocType::Html:
|
|
setHtml(noteFile->content);
|
|
break;
|
|
case DocType::Markdown:
|
|
setPlainText(noteFile->content);
|
|
break;
|
|
default:
|
|
qWarning() << "error: unknown doc type" << int(noteFile->docType);
|
|
}
|
|
}
|
|
|
|
bool VEdit::tryEndEdit()
|
|
{
|
|
return !document()->isModified();
|
|
}
|
|
|
|
void VEdit::beginSave()
|
|
{
|
|
if (!document()->isModified()) {
|
|
return;
|
|
}
|
|
|
|
switch (noteFile->docType) {
|
|
case DocType::Html:
|
|
noteFile->content = toHtml();
|
|
break;
|
|
case DocType::Markdown:
|
|
noteFile->content = toPlainText();
|
|
break;
|
|
default:
|
|
qWarning() << "error: unknown doc type" << int(noteFile->docType);
|
|
}
|
|
}
|
|
|
|
void VEdit::endSave()
|
|
{
|
|
document()->setModified(false);
|
|
}
|
|
|
|
void VEdit::reloadFile()
|
|
{
|
|
switch (noteFile->docType) {
|
|
case DocType::Html:
|
|
setHtml(noteFile->content);
|
|
break;
|
|
case DocType::Markdown:
|
|
setPlainText(noteFile->content);
|
|
break;
|
|
default:
|
|
qWarning() << "error: unknown doc type" << int(noteFile->docType);
|
|
}
|
|
}
|