mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 14:29:54 +08:00
VMdTab: use splitter instead of tab layout to hold editor and web view
Prepare for live preview.
This commit is contained in:
parent
2206102945
commit
051088be31
@ -1,4 +1,4 @@
|
|||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<head>
|
<head>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<head>
|
<head>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<head>
|
<head>
|
||||||
|
@ -164,13 +164,14 @@ table tr th :last-child, table tr td :last-child {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div.mermaid-diagram {
|
div.mermaid-diagram {
|
||||||
width: fit-content;
|
margin: 16px 0px 16px 0px;
|
||||||
overflow: hidden;
|
overflow-y: hidden;
|
||||||
background: #B0BEC5;
|
background: #B0BEC5;
|
||||||
color: #6C6C6C;
|
color: #6C6C6C;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.flowchart-diagram {
|
div.flowchart-diagram {
|
||||||
|
margin: 16px 0px 16px 0px;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: #B0BEC5;
|
background: #B0BEC5;
|
||||||
@ -178,6 +179,7 @@ div.flowchart-diagram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div.plantuml-diagram {
|
div.plantuml-diagram {
|
||||||
|
margin: 16px 0px 16px 0px;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: #B0BEC5;
|
background: #B0BEC5;
|
||||||
|
@ -169,16 +169,18 @@ table tr th :last-child, table tr td :last-child {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div.mermaid-diagram {
|
div.mermaid-diagram {
|
||||||
width: fit-content;
|
margin: 16px 0px 16px 0px;
|
||||||
overflow: hidden;
|
overflow-y: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.flowchart-diagram {
|
div.flowchart-diagram {
|
||||||
|
margin: 16px 0px 16px 0px;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.plantuml-diagram {
|
div.plantuml-diagram {
|
||||||
|
margin: 16px 0px 16px 0px;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
@ -170,16 +170,18 @@ table tr th :last-child, table tr td :last-child {
|
|||||||
}
|
}
|
||||||
|
|
||||||
div.mermaid-diagram {
|
div.mermaid-diagram {
|
||||||
width: fit-content;
|
margin: 16px 0px 16px 0px;
|
||||||
overflow: hidden;
|
overflow-y: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.flowchart-diagram {
|
div.flowchart-diagram {
|
||||||
|
margin: 16px 0px 16px 0px;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.plantuml-diagram {
|
div.plantuml-diagram {
|
||||||
|
margin: 16px 0px 16px 0px;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,7 @@ int VLineNumberArea::calculateWidth() const
|
|||||||
++digits;
|
++digits;
|
||||||
}
|
}
|
||||||
|
|
||||||
int width = m_digitWidth * (digits + 1);
|
const_cast<VLineNumberArea *>(this)->m_width = m_digitWidth * digits + 3;
|
||||||
const_cast<VLineNumberArea *>(this)->m_width = width;
|
|
||||||
|
|
||||||
return m_width;
|
return m_width;
|
||||||
}
|
}
|
||||||
|
@ -68,14 +68,18 @@ VMdTab::VMdTab(VFile *p_file, VEditArea *p_editArea,
|
|||||||
|
|
||||||
void VMdTab::setupUI()
|
void VMdTab::setupUI()
|
||||||
{
|
{
|
||||||
m_stacks = new QStackedLayout(this);
|
m_splitter = new QSplitter(this);
|
||||||
|
m_splitter->setOrientation(Qt::Horizontal);
|
||||||
|
|
||||||
setupMarkdownViewer();
|
setupMarkdownViewer();
|
||||||
|
|
||||||
// Setup editor when we really need it.
|
// Setup editor when we really need it.
|
||||||
m_editor = NULL;
|
m_editor = NULL;
|
||||||
|
|
||||||
setLayout(m_stacks);
|
QVBoxLayout *layout = new QVBoxLayout();
|
||||||
|
layout->addWidget(m_splitter);
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
setLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMdTab::showFileReadMode()
|
void VMdTab::showFileReadMode()
|
||||||
@ -87,7 +91,8 @@ void VMdTab::showFileReadMode()
|
|||||||
|
|
||||||
updateWebView();
|
updateWebView();
|
||||||
|
|
||||||
m_stacks->setCurrentWidget(m_webViewer);
|
setCurrentMode(Mode::Read);
|
||||||
|
|
||||||
clearSearchedWordHighlight();
|
clearSearchedWordHighlight();
|
||||||
|
|
||||||
updateStatus();
|
updateStatus();
|
||||||
@ -216,7 +221,8 @@ void VMdTab::showFileEditMode()
|
|||||||
|
|
||||||
VMdEditor *mdEdit = getEditor();
|
VMdEditor *mdEdit = getEditor();
|
||||||
|
|
||||||
m_stacks->setCurrentWidget(mdEdit);
|
setCurrentMode(Mode::Edit);
|
||||||
|
|
||||||
mdEdit->beginEdit();
|
mdEdit->beginEdit();
|
||||||
|
|
||||||
// If editor is not init, we need to wait for it to init headers.
|
// If editor is not init, we need to wait for it to init headers.
|
||||||
@ -444,7 +450,7 @@ void VMdTab::setupMarkdownViewer()
|
|||||||
m_webViewer->setHtml(VUtils::generateHtmlTemplate(m_mdConType),
|
m_webViewer->setHtml(VUtils::generateHtmlTemplate(m_mdConType),
|
||||||
m_file->getBaseUrl());
|
m_file->getBaseUrl());
|
||||||
|
|
||||||
m_stacks->addWidget(m_webViewer);
|
m_splitter->addWidget(m_webViewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMdTab::setupMarkdownEditor()
|
void VMdTab::setupMarkdownEditor()
|
||||||
@ -503,7 +509,7 @@ void VMdTab::setupMarkdownEditor()
|
|||||||
|
|
||||||
enableHeadingSequence(m_enableHeadingSequence);
|
enableHeadingSequence(m_enableHeadingSequence);
|
||||||
m_editor->reloadFile();
|
m_editor->reloadFile();
|
||||||
m_stacks->addWidget(m_editor);
|
m_splitter->insertWidget(0, m_editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMdTab::updateOutlineFromHtml(const QString &p_tocHtml)
|
void VMdTab::updateOutlineFromHtml(const QString &p_tocHtml)
|
||||||
@ -781,7 +787,11 @@ MarkdownConverterType VMdTab::getMarkdownConverterType() const
|
|||||||
|
|
||||||
void VMdTab::focusChild()
|
void VMdTab::focusChild()
|
||||||
{
|
{
|
||||||
m_stacks->currentWidget()->setFocus();
|
if (m_mode == Mode::Read) {
|
||||||
|
m_webViewer->setFocus();
|
||||||
|
} else {
|
||||||
|
m_editor->setFocus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMdTab::requestUpdateVimStatus()
|
void VMdTab::requestUpdateVimStatus()
|
||||||
@ -1303,3 +1313,30 @@ VWordCountInfo VMdTab::fetchWordCountInfo(bool p_editMode) const
|
|||||||
|
|
||||||
return VWordCountInfo();
|
return VWordCountInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMdTab::setCurrentMode(Mode p_mode)
|
||||||
|
{
|
||||||
|
switch (p_mode) {
|
||||||
|
case Mode::Read:
|
||||||
|
m_webViewer->show();
|
||||||
|
if (m_editor) {
|
||||||
|
m_editor->hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Mode::EditPreview:
|
||||||
|
case Mode::Edit:
|
||||||
|
Q_ASSERT(m_editor);
|
||||||
|
m_editor->show();
|
||||||
|
m_webViewer->hide();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_mode = p_mode;
|
||||||
|
|
||||||
|
focusChild();
|
||||||
|
}
|
||||||
|
10
src/vmdtab.h
10
src/vmdtab.h
@ -9,12 +9,12 @@
|
|||||||
#include "vconfigmanager.h"
|
#include "vconfigmanager.h"
|
||||||
|
|
||||||
class VWebView;
|
class VWebView;
|
||||||
class QStackedLayout;
|
|
||||||
class VDocument;
|
class VDocument;
|
||||||
class VMdEditor;
|
class VMdEditor;
|
||||||
class VInsertSelector;
|
class VInsertSelector;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class QWebEngineDownloadItem;
|
class QWebEngineDownloadItem;
|
||||||
|
class QSplitter;
|
||||||
|
|
||||||
class VMdTab : public VEditTab
|
class VMdTab : public VEditTab
|
||||||
{
|
{
|
||||||
@ -145,6 +145,8 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
enum TabReady { None = 0, ReadMode = 0x1, EditMode = 0x2 };
|
enum TabReady { None = 0, ReadMode = 0x1, EditMode = 0x2 };
|
||||||
|
|
||||||
|
enum Mode { Read = 0, Edit, EditPreview };
|
||||||
|
|
||||||
// Setup UI.
|
// Setup UI.
|
||||||
void setupUI();
|
void setupUI();
|
||||||
|
|
||||||
@ -213,6 +215,8 @@ private:
|
|||||||
// Update web view by current content.
|
// Update web view by current content.
|
||||||
void updateWebView();
|
void updateWebView();
|
||||||
|
|
||||||
|
void setCurrentMode(Mode p_mode);
|
||||||
|
|
||||||
VMdEditor *m_editor;
|
VMdEditor *m_editor;
|
||||||
VWebView *m_webViewer;
|
VWebView *m_webViewer;
|
||||||
VDocument *m_document;
|
VDocument *m_document;
|
||||||
@ -221,7 +225,7 @@ private:
|
|||||||
// Whether heading sequence is enabled.
|
// Whether heading sequence is enabled.
|
||||||
bool m_enableHeadingSequence;
|
bool m_enableHeadingSequence;
|
||||||
|
|
||||||
QStackedLayout *m_stacks;
|
QSplitter *m_splitter;
|
||||||
|
|
||||||
// Timer to write backup file when content has been changed.
|
// Timer to write backup file when content has been changed.
|
||||||
QTimer *m_backupTimer;
|
QTimer *m_backupTimer;
|
||||||
@ -232,6 +236,8 @@ private:
|
|||||||
VHeaderPointer m_headerFromEditMode;
|
VHeaderPointer m_headerFromEditMode;
|
||||||
|
|
||||||
VVim::SearchItem m_lastSearchItem;
|
VVim::SearchItem m_lastSearchItem;
|
||||||
|
|
||||||
|
Mode m_mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline VMdEditor *VMdTab::getEditor()
|
inline VMdEditor *VMdTab::getEditor()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user