mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
add heading tool button
This commit is contained in:
parent
1f0ee88770
commit
cb6338ecf6
7
src/resources/icons/heading.svg
Normal file
7
src/resources/icons/heading.svg
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<g>
|
||||||
|
<title>Layer 1</title>
|
||||||
|
<text stroke="#000000" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " font-weight="bold" xml:space="preserve" text-anchor="middle" font-family="serif" font-size="24" id="svg_4" y="248.490375" x="-146.756839" stroke-width="0" fill="#000000">H</text>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 472 B |
@ -72,7 +72,8 @@ enum class TextDecoration
|
|||||||
Underline,
|
Underline,
|
||||||
Strikethrough,
|
Strikethrough,
|
||||||
InlineCode,
|
InlineCode,
|
||||||
CodeBlock
|
CodeBlock,
|
||||||
|
Heading
|
||||||
};
|
};
|
||||||
|
|
||||||
enum FindOption
|
enum FindOption
|
||||||
|
@ -100,8 +100,3 @@ void VEditOperations::setVimMode(VimMode p_mode)
|
|||||||
m_vim->setMode(p_mode);
|
m_vim->setMode(p_mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditOperations::decorateText(TextDecoration p_decoration)
|
|
||||||
{
|
|
||||||
Q_UNUSED(p_decoration);
|
|
||||||
}
|
|
||||||
|
@ -38,7 +38,11 @@ public:
|
|||||||
void requestUpdateVimStatus();
|
void requestUpdateVimStatus();
|
||||||
|
|
||||||
// Insert decoration markers or decorate selected text.
|
// Insert decoration markers or decorate selected text.
|
||||||
virtual void decorateText(TextDecoration p_decoration);
|
virtual void decorateText(TextDecoration p_decoration, int p_level = -1)
|
||||||
|
{
|
||||||
|
Q_UNUSED(p_decoration);
|
||||||
|
Q_UNUSED(p_level);
|
||||||
|
}
|
||||||
|
|
||||||
// Set Vim mode if not NULL.
|
// Set Vim mode if not NULL.
|
||||||
void setVimMode(VimMode p_mode);
|
void setVimMode(VimMode p_mode);
|
||||||
|
@ -893,10 +893,10 @@ void VEditor::setInputMethodEnabled(bool p_enabled)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VEditor::decorateText(TextDecoration p_decoration)
|
void VEditor::decorateText(TextDecoration p_decoration, int p_level)
|
||||||
{
|
{
|
||||||
if (m_editOps) {
|
if (m_editOps) {
|
||||||
m_editOps->decorateText(p_decoration);
|
m_editOps->decorateText(p_decoration, p_level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ public:
|
|||||||
void setInputMethodEnabled(bool p_enabled);
|
void setInputMethodEnabled(bool p_enabled);
|
||||||
|
|
||||||
// Insert decoration markers or decorate selected text.
|
// Insert decoration markers or decorate selected text.
|
||||||
void decorateText(TextDecoration p_decoration);
|
void decorateText(TextDecoration p_decoration, int p_level);
|
||||||
|
|
||||||
virtual bool isBlockVisible(const QTextBlock &p_block) = 0;
|
virtual bool isBlockVisible(const QTextBlock &p_block) = 0;
|
||||||
|
|
||||||
|
@ -73,7 +73,11 @@ public:
|
|||||||
virtual void requestUpdateVimStatus() = 0;
|
virtual void requestUpdateVimStatus() = 0;
|
||||||
|
|
||||||
// Insert decoration markers or decorate selected text.
|
// Insert decoration markers or decorate selected text.
|
||||||
virtual void decorateText(TextDecoration p_decoration) {Q_UNUSED(p_decoration);}
|
virtual void decorateText(TextDecoration p_decoration, int p_level = -1)
|
||||||
|
{
|
||||||
|
Q_UNUSED(p_decoration);
|
||||||
|
Q_UNUSED(p_level);
|
||||||
|
}
|
||||||
|
|
||||||
// Create a filled VEditTabInfo.
|
// Create a filled VEditTabInfo.
|
||||||
virtual VEditTabInfo fetchTabInfo() const;
|
virtual VEditTabInfo fetchTabInfo() const;
|
||||||
|
@ -424,6 +424,8 @@ void VMainWindow::initEditToolBar(QSize p_iconSize)
|
|||||||
|
|
||||||
m_editToolBar->addAction(m_headingSequenceAct);
|
m_editToolBar->addAction(m_headingSequenceAct);
|
||||||
|
|
||||||
|
initHeadingButton(m_editToolBar);
|
||||||
|
|
||||||
QAction *boldAct = new QAction(QIcon(":/resources/icons/bold.svg"),
|
QAction *boldAct = new QAction(QIcon(":/resources/icons/bold.svg"),
|
||||||
tr("Bold\t%1").arg(VUtils::getShortcutText("Ctrl+B")),
|
tr("Bold\t%1").arg(VUtils::getShortcutText("Ctrl+B")),
|
||||||
this);
|
this);
|
||||||
@ -1829,6 +1831,8 @@ void VMainWindow::updateActionsStateFromTab(const VEditTab *p_tab)
|
|||||||
|
|
||||||
m_attachmentBtn->setEnabled(file && file->getType() == FileType::Note);
|
m_attachmentBtn->setEnabled(file && file->getType() == FileType::Note);
|
||||||
|
|
||||||
|
m_headingBtn->setEnabled(file && editMode);
|
||||||
|
|
||||||
setActionsEnabled(m_editToolBar, file && editMode);
|
setActionsEnabled(m_editToolBar, file && editMode);
|
||||||
|
|
||||||
// Handle heading sequence act independently.
|
// Handle heading sequence act independently.
|
||||||
@ -2712,3 +2716,62 @@ void VMainWindow::openFlashPage()
|
|||||||
OpenFileMode::Edit,
|
OpenFileMode::Edit,
|
||||||
true);
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMainWindow::initHeadingButton(QToolBar *p_tb)
|
||||||
|
{
|
||||||
|
m_headingBtn = new QPushButton(QIcon(":/resources/icons/heading.svg"),
|
||||||
|
"",
|
||||||
|
this);
|
||||||
|
m_headingBtn->setToolTip(tr("Headings"));
|
||||||
|
m_headingBtn->setProperty("CornerBtn", true);
|
||||||
|
m_headingBtn->setFocusPolicy(Qt::NoFocus);
|
||||||
|
m_headingBtn->setEnabled(false);
|
||||||
|
|
||||||
|
QMenu *menu = new QMenu(this);
|
||||||
|
QAction *act = menu->addAction(tr("Heading 1\t%1").arg(VUtils::getShortcutText("Ctrl+1")));
|
||||||
|
QFont font = act->font();
|
||||||
|
int ps = font.pointSize();
|
||||||
|
font.setBold(true);
|
||||||
|
font.setPointSize(ps + 8);
|
||||||
|
act->setFont(font);
|
||||||
|
act->setData(1);
|
||||||
|
|
||||||
|
act = menu->addAction(tr("Heading 2\t%1").arg(VUtils::getShortcutText("Ctrl+2")));
|
||||||
|
font.setPointSize(ps + 6);
|
||||||
|
act->setFont(font);
|
||||||
|
act->setData(2);
|
||||||
|
|
||||||
|
act = menu->addAction(tr("Heading 3\t%1").arg(VUtils::getShortcutText("Ctrl+3")));
|
||||||
|
font.setPointSize(ps + 4);
|
||||||
|
act->setFont(font);
|
||||||
|
act->setData(3);
|
||||||
|
|
||||||
|
act = menu->addAction(tr("Heading 4\t%1").arg(VUtils::getShortcutText("Ctrl+4")));
|
||||||
|
font.setPointSize(ps + 2);
|
||||||
|
act->setFont(font);
|
||||||
|
act->setData(4);
|
||||||
|
|
||||||
|
act = menu->addAction(tr("Heading 5\t%1").arg(VUtils::getShortcutText("Ctrl+5")));
|
||||||
|
font.setPointSize(ps + 2);
|
||||||
|
act->setFont(font);
|
||||||
|
act->setData(5);
|
||||||
|
|
||||||
|
act = menu->addAction(tr("Heading 6\t%1").arg(VUtils::getShortcutText("Ctrl+6")));
|
||||||
|
font.setPointSize(ps + 2);
|
||||||
|
act->setFont(font);
|
||||||
|
act->setData(6);
|
||||||
|
|
||||||
|
act = menu->addAction(tr("Clear\t%1").arg(VUtils::getShortcutText("Ctrl+7")));
|
||||||
|
act->setData(0);
|
||||||
|
|
||||||
|
connect(menu, &QMenu::triggered,
|
||||||
|
this, [this](QAction *p_action) {
|
||||||
|
if (m_curTab) {
|
||||||
|
int level = p_action->data().toInt();
|
||||||
|
m_curTab->decorateText(TextDecoration::Heading, level);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
m_headingBtn->setMenu(menu);
|
||||||
|
p_tb->addWidget(m_headingBtn);
|
||||||
|
}
|
||||||
|
@ -261,6 +261,8 @@ private:
|
|||||||
|
|
||||||
void initShortcuts();
|
void initShortcuts();
|
||||||
|
|
||||||
|
void initHeadingButton(QToolBar *p_tb);
|
||||||
|
|
||||||
// Captain mode functions.
|
// Captain mode functions.
|
||||||
|
|
||||||
// Popup the attachment list if it is enabled.
|
// Popup the attachment list if it is enabled.
|
||||||
@ -372,6 +374,8 @@ private:
|
|||||||
// Attachment list.
|
// Attachment list.
|
||||||
VAttachmentList *m_attachmentList;
|
VAttachmentList *m_attachmentList;
|
||||||
|
|
||||||
|
QPushButton *m_headingBtn;
|
||||||
|
|
||||||
QVector<QPixmap> predefinedColorPixmaps;
|
QVector<QPixmap> predefinedColorPixmaps;
|
||||||
|
|
||||||
// Single instance guard.
|
// Single instance guard.
|
||||||
|
@ -223,7 +223,7 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event)
|
|||||||
{
|
{
|
||||||
if (modifiers == Qt::ControlModifier) {
|
if (modifiers == Qt::ControlModifier) {
|
||||||
// Ctrl + <N>: insert title at level <N>.
|
// Ctrl + <N>: insert title at level <N>.
|
||||||
if (insertTitle(key == Qt::Key_7 ? 0 : key - Qt::Key_0)) {
|
if (decorateHeading(key == Qt::Key_7 ? 0 : key - Qt::Key_0)) {
|
||||||
p_event->accept();
|
p_event->accept();
|
||||||
ret = true;
|
ret = true;
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -649,7 +649,7 @@ void VMdEditOperations::changeListBlockSeqNumber(QTextBlock &p_block, int p_seq)
|
|||||||
cursor.insertText(QString::number(p_seq));
|
cursor.insertText(QString::number(p_seq));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VMdEditOperations::insertTitle(int p_level)
|
bool VMdEditOperations::decorateHeading(int p_level)
|
||||||
{
|
{
|
||||||
QTextDocument *doc = m_editor->documentW();
|
QTextDocument *doc = m_editor->documentW();
|
||||||
QTextCursor cursor = m_editor->textCursorW();
|
QTextCursor cursor = m_editor->textCursorW();
|
||||||
@ -674,7 +674,7 @@ bool VMdEditOperations::insertTitle(int p_level)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMdEditOperations::decorateText(TextDecoration p_decoration)
|
void VMdEditOperations::decorateText(TextDecoration p_decoration, int p_level)
|
||||||
{
|
{
|
||||||
if (p_decoration == TextDecoration::None) {
|
if (p_decoration == TextDecoration::None) {
|
||||||
return;
|
return;
|
||||||
@ -702,6 +702,10 @@ void VMdEditOperations::decorateText(TextDecoration p_decoration)
|
|||||||
decorateCodeBlock();
|
decorateCodeBlock();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TextDecoration::Heading:
|
||||||
|
decorateHeading(p_level);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
validDecoration = false;
|
validDecoration = false;
|
||||||
qDebug() << "decoration" << (int)p_decoration << "is not implemented yet";
|
qDebug() << "decoration" << (int)p_decoration << "is not implemented yet";
|
||||||
|
@ -30,7 +30,7 @@ public:
|
|||||||
|
|
||||||
// Insert decoration markers or decorate selected text.
|
// Insert decoration markers or decorate selected text.
|
||||||
// If it is Vim Normal mode, change to Insert mode first.
|
// If it is Vim Normal mode, change to Insert mode first.
|
||||||
void decorateText(TextDecoration p_decoration) Q_DECL_OVERRIDE;
|
void decorateText(TextDecoration p_decoration, int p_level = -1) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Insert image from @oriImagePath as @path.
|
// Insert image from @oriImagePath as @path.
|
||||||
@ -55,12 +55,6 @@ private:
|
|||||||
bool handleKeyReturn(QKeyEvent *p_event);
|
bool handleKeyReturn(QKeyEvent *p_event);
|
||||||
bool handleKeyBracketLeft(QKeyEvent *p_event);
|
bool handleKeyBracketLeft(QKeyEvent *p_event);
|
||||||
|
|
||||||
// Insert title of level @p_level.
|
|
||||||
// Will detect if current block already has some leading #s. If yes,
|
|
||||||
// will delete it and insert the correct #s.
|
|
||||||
// @p_level: 0 to cancel title.
|
|
||||||
bool insertTitle(int p_level);
|
|
||||||
|
|
||||||
// Change the sequence number of a list block.
|
// Change the sequence number of a list block.
|
||||||
void changeListBlockSeqNumber(QTextBlock &p_block, int p_seq);
|
void changeListBlockSeqNumber(QTextBlock &p_block, int p_seq);
|
||||||
|
|
||||||
@ -79,6 +73,12 @@ private:
|
|||||||
// Insert strikethrough marker or set selected text strikethrough.
|
// Insert strikethrough marker or set selected text strikethrough.
|
||||||
void decorateStrikethrough();
|
void decorateStrikethrough();
|
||||||
|
|
||||||
|
// Insert title of level @p_level.
|
||||||
|
// Will detect if current block already has some leading #s. If yes,
|
||||||
|
// will delete it and insert the correct #s.
|
||||||
|
// @p_level: 0 to cancel title.
|
||||||
|
bool decorateHeading(int p_level);
|
||||||
|
|
||||||
// The cursor position after auto indent or auto list.
|
// The cursor position after auto indent or auto list.
|
||||||
// It will be -1 if last key press do not trigger the auto indent or auto list.
|
// It will be -1 if last key press do not trigger the auto indent or auto list.
|
||||||
int m_autoIndentPos;
|
int m_autoIndentPos;
|
||||||
|
@ -717,10 +717,10 @@ VEditTabInfo VMdTab::fetchTabInfo() const
|
|||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMdTab::decorateText(TextDecoration p_decoration)
|
void VMdTab::decorateText(TextDecoration p_decoration, int p_level)
|
||||||
{
|
{
|
||||||
if (m_editor) {
|
if (m_editor) {
|
||||||
m_editor->decorateText(p_decoration);
|
m_editor->decorateText(p_decoration, p_level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
void requestUpdateVimStatus() Q_DECL_OVERRIDE;
|
void requestUpdateVimStatus() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
// Insert decoration markers or decorate selected text.
|
// Insert decoration markers or decorate selected text.
|
||||||
void decorateText(TextDecoration p_decoration) Q_DECL_OVERRIDE;
|
void decorateText(TextDecoration p_decoration, int p_level = -1) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
// Create a filled VEditTabInfo.
|
// Create a filled VEditTabInfo.
|
||||||
VEditTabInfo fetchTabInfo() const Q_DECL_OVERRIDE;
|
VEditTabInfo fetchTabInfo() const Q_DECL_OVERRIDE;
|
||||||
|
@ -143,5 +143,6 @@
|
|||||||
<file>resources/icons/apply_snippet.svg</file>
|
<file>resources/icons/apply_snippet.svg</file>
|
||||||
<file>resources/icons/reading_modified.svg</file>
|
<file>resources/icons/reading_modified.svg</file>
|
||||||
<file>resources/icons/flash_page.svg</file>
|
<file>resources/icons/flash_page.svg</file>
|
||||||
|
<file>resources/icons/heading.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user