mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
toolbar: implement strikethrough and add shortcut tips
This commit is contained in:
parent
71bcfe3019
commit
6fd92f915b
@ -42,11 +42,13 @@ Save current changes and exit edit mode.
|
|||||||
|
|
||||||
#### Text Editing
|
#### Text Editing
|
||||||
- `Ctrl+B`
|
- `Ctrl+B`
|
||||||
Insert bold. Press `Ctrl+B` again to exit. Currently selected text will be changed to bold if exist.
|
Insert bold. Press `Ctrl+B` again to exit. Current selected text will be changed to bold if exist.
|
||||||
- `Ctrl+I`
|
- `Ctrl+I`
|
||||||
Insert italic. Press `Ctrl+I` again to exit. Currently selected text will be changed to italic if exist.
|
Insert italic. Press `Ctrl+I` again to exit. Current selected text will be changed to italic if exist.
|
||||||
|
- `Ctrl+D`
|
||||||
|
Insert strikethrought. Press `Ctrl+D` again to exit. Current selected text will be changed to strikethrough if exist.
|
||||||
- `Ctrl+O`
|
- `Ctrl+O`
|
||||||
Insert inline code. Press `Ctrl+O` again to exit. Currently selected text will be changed to inline code if exist.
|
Insert inline code. Press `Ctrl+O` again to exit. Current selected text will be changed to inline code if exist.
|
||||||
- `Ctrl+H`
|
- `Ctrl+H`
|
||||||
Backspace. Delete a character backward.
|
Backspace. Delete a character backward.
|
||||||
- `Ctrl+W`
|
- `Ctrl+W`
|
||||||
@ -54,7 +56,7 @@ Delete all the characters from current cursor to the first space backward.
|
|||||||
- `Ctrl+U`
|
- `Ctrl+U`
|
||||||
Delete all the characters from current cursor to the beginning of current line.
|
Delete all the characters from current cursor to the beginning of current line.
|
||||||
- `Ctrl+<Num>`
|
- `Ctrl+<Num>`
|
||||||
Insert title at level `<Num>`. `<Num>` should be 1 to 6. Currently selected text will be changed to title if exist.
|
Insert title at level `<Num>`. `<Num>` should be 1 to 6. Current selected text will be changed to title if exist.
|
||||||
- `Tab`/`Shift+Tab`
|
- `Tab`/`Shift+Tab`
|
||||||
Increase or decrease the indentation. If any text is selected, the indentation will operate on all these selected lines.
|
Increase or decrease the indentation. If any text is selected, the indentation will operate on all these selected lines.
|
||||||
- `Shift+Enter`
|
- `Shift+Enter`
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
插入粗体;再次按`Ctrl+B`退出。如果已经选择文本,则将当前选择文本加粗。
|
插入粗体;再次按`Ctrl+B`退出。如果已经选择文本,则将当前选择文本加粗。
|
||||||
- `Ctrl+I`
|
- `Ctrl+I`
|
||||||
插入斜体;再次按`Ctrl+I`退出。如果已经选择文本,则将当前选择文本改为斜体。
|
插入斜体;再次按`Ctrl+I`退出。如果已经选择文本,则将当前选择文本改为斜体。
|
||||||
|
- `Ctrl+D`
|
||||||
|
插入删除线;再次按`Ctrl+D`退出。如果已经选择文本,则将当前选择文本改为删除线。
|
||||||
- `Ctrl+O`
|
- `Ctrl+O`
|
||||||
插入行内代码;再次按`Ctrl+O`退出。如果已经选择文本,则将当前选择文本改为行内代码。
|
插入行内代码;再次按`Ctrl+O`退出。如果已经选择文本,则将当前选择文本改为行内代码。
|
||||||
- `Ctrl+H`
|
- `Ctrl+H`
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
|
<svg width="512" height="512" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
<g>
|
<g>
|
||||||
<title>Layer 1</title>
|
<title>Layer 1</title>
|
||||||
<text fill="#000000" stroke-width="0" x="-146.756839" y="248.490375" id="svg_4" font-size="24" font-family="serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000" font-style="normal">S</text>
|
<text fill="#000000" stroke-width="0" x="-146.756839" y="248.490375" id="svg_4" font-size="24" font-family="serif" text-anchor="middle" xml:space="preserve" font-weight="normal" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " stroke="#000000" font-style="normal">D</text>
|
||||||
<rect stroke="#000000" fill="#000000" stroke-width="5" x="94.999999" y="282" width="318.999997" height="21" id="svg_2" stroke-opacity="0"/>
|
<rect stroke="#000000" fill="#000000" stroke-width="5" x="91" y="262" width="325" height="21" id="svg_2" stroke-opacity="0"/>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
Before Width: | Height: | Size: 635 B After Width: | Height: | Size: 622 B |
@ -1,8 +0,0 @@
|
|||||||
<?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 style="cursor: move;" font-style="normal" stroke="#000000" transform="matrix(16.72881317138672,0,0,16.72881317138672,2707.567729830742,-3759.186347961426) " font-weight="normal" 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">U</text>
|
|
||||||
<rect stroke="#000000" stroke-opacity="0" id="svg_2" height="21" width="322.000016" y="422" x="91.999999" stroke-width="5" fill="#000000"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 657 B |
@ -187,21 +187,24 @@ void VMainWindow::initViewToolBar()
|
|||||||
QAction *onePanelViewAct = new QAction(QIcon(":/resources/icons/one_panel.svg"),
|
QAction *onePanelViewAct = new QAction(QIcon(":/resources/icons/one_panel.svg"),
|
||||||
tr("&Single Panel"), this);
|
tr("&Single Panel"), this);
|
||||||
onePanelViewAct->setStatusTip(tr("Display only the notes list panel"));
|
onePanelViewAct->setStatusTip(tr("Display only the notes list panel"));
|
||||||
|
onePanelViewAct->setToolTip(tr("Single Panel (Ctrl+E P)"));
|
||||||
connect(onePanelViewAct, &QAction::triggered,
|
connect(onePanelViewAct, &QAction::triggered,
|
||||||
this, &VMainWindow::onePanelView);
|
this, &VMainWindow::onePanelView);
|
||||||
|
|
||||||
QAction *twoPanelViewAct = new QAction(QIcon(":/resources/icons/two_panels.svg"),
|
QAction *twoPanelViewAct = new QAction(QIcon(":/resources/icons/two_panels.svg"),
|
||||||
tr("&Two Panels"), this);
|
tr("&Two Panels"), this);
|
||||||
twoPanelViewAct->setStatusTip(tr("Display both the folders and notes list panel"));
|
twoPanelViewAct->setStatusTip(tr("Display both the folders and notes list panel"));
|
||||||
|
twoPanelViewAct->setToolTip(tr("Two Panels (Ctrl+E P)"));
|
||||||
connect(twoPanelViewAct, &QAction::triggered,
|
connect(twoPanelViewAct, &QAction::triggered,
|
||||||
this, &VMainWindow::twoPanelView);
|
this, &VMainWindow::twoPanelView);
|
||||||
|
|
||||||
QMenu *panelMenu = new QMenu(this);
|
QMenu *panelMenu = new QMenu(this);
|
||||||
|
panelMenu->setToolTipsVisible(true);
|
||||||
panelMenu->addAction(onePanelViewAct);
|
panelMenu->addAction(onePanelViewAct);
|
||||||
panelMenu->addAction(twoPanelViewAct);
|
panelMenu->addAction(twoPanelViewAct);
|
||||||
|
|
||||||
expandViewAct = new QAction(QIcon(":/resources/icons/expand.svg"),
|
expandViewAct = new QAction(QIcon(":/resources/icons/expand.svg"),
|
||||||
tr("Expand"), this);
|
tr("Expand (Ctrl+E E)"), this);
|
||||||
expandViewAct->setStatusTip(tr("Expand the edit area"));
|
expandViewAct->setStatusTip(tr("Expand the edit area"));
|
||||||
expandViewAct->setCheckable(true);
|
expandViewAct->setCheckable(true);
|
||||||
expandViewAct->setMenu(panelMenu);
|
expandViewAct->setMenu(panelMenu);
|
||||||
@ -229,7 +232,7 @@ void VMainWindow::initEditToolBar()
|
|||||||
m_editToolBar->addSeparator();
|
m_editToolBar->addSeparator();
|
||||||
|
|
||||||
QAction *boldAct = new QAction(QIcon(":/resources/icons/bold.svg"),
|
QAction *boldAct = new QAction(QIcon(":/resources/icons/bold.svg"),
|
||||||
tr("Bold"), this);
|
tr("Bold (Ctrl+B)"), this);
|
||||||
boldAct->setStatusTip(tr("Insert bold text or change selected text to bold"));
|
boldAct->setStatusTip(tr("Insert bold text or change selected text to bold"));
|
||||||
connect(boldAct, &QAction::triggered,
|
connect(boldAct, &QAction::triggered,
|
||||||
this, [this](){
|
this, [this](){
|
||||||
@ -241,7 +244,7 @@ void VMainWindow::initEditToolBar()
|
|||||||
m_editToolBar->addAction(boldAct);
|
m_editToolBar->addAction(boldAct);
|
||||||
|
|
||||||
QAction *italicAct = new QAction(QIcon(":/resources/icons/italic.svg"),
|
QAction *italicAct = new QAction(QIcon(":/resources/icons/italic.svg"),
|
||||||
tr("Italic"), this);
|
tr("Italic (Ctrl+I)"), this);
|
||||||
italicAct->setStatusTip(tr("Insert italic text or change selected text to italic"));
|
italicAct->setStatusTip(tr("Insert italic text or change selected text to italic"));
|
||||||
connect(italicAct, &QAction::triggered,
|
connect(italicAct, &QAction::triggered,
|
||||||
this, [this](){
|
this, [this](){
|
||||||
@ -252,20 +255,8 @@ void VMainWindow::initEditToolBar()
|
|||||||
|
|
||||||
m_editToolBar->addAction(italicAct);
|
m_editToolBar->addAction(italicAct);
|
||||||
|
|
||||||
QAction *underlineAct = new QAction(QIcon(":/resources/icons/underline.svg"),
|
|
||||||
tr("Underline"), this);
|
|
||||||
underlineAct->setStatusTip(tr("Insert underlined text or change selected text to underlined"));
|
|
||||||
connect(underlineAct, &QAction::triggered,
|
|
||||||
this, [this](){
|
|
||||||
if (m_curTab) {
|
|
||||||
m_curTab->decorateText(TextDecoration::Underline);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
m_editToolBar->addAction(underlineAct);
|
|
||||||
|
|
||||||
QAction *strikethroughAct = new QAction(QIcon(":/resources/icons/strikethrough.svg"),
|
QAction *strikethroughAct = new QAction(QIcon(":/resources/icons/strikethrough.svg"),
|
||||||
tr("Strikethrough"), this);
|
tr("Strikethrough (Ctrl+D)"), this);
|
||||||
strikethroughAct->setStatusTip(tr("Insert strikethrough text or change selected text to strikethroughed"));
|
strikethroughAct->setStatusTip(tr("Insert strikethrough text or change selected text to strikethroughed"));
|
||||||
connect(strikethroughAct, &QAction::triggered,
|
connect(strikethroughAct, &QAction::triggered,
|
||||||
this, [this](){
|
this, [this](){
|
||||||
@ -277,7 +268,7 @@ void VMainWindow::initEditToolBar()
|
|||||||
m_editToolBar->addAction(strikethroughAct);
|
m_editToolBar->addAction(strikethroughAct);
|
||||||
|
|
||||||
QAction *inlineCodeAct = new QAction(QIcon(":/resources/icons/inline_code.svg"),
|
QAction *inlineCodeAct = new QAction(QIcon(":/resources/icons/inline_code.svg"),
|
||||||
tr("Inline Code"), this);
|
tr("Inline Code (Ctrl+O)"), this);
|
||||||
inlineCodeAct->setStatusTip(tr("Insert inline-code text or change selected text to inline-coded"));
|
inlineCodeAct->setStatusTip(tr("Insert inline-code text or change selected text to inline-coded"));
|
||||||
connect(inlineCodeAct, &QAction::triggered,
|
connect(inlineCodeAct, &QAction::triggered,
|
||||||
this, [this](){
|
this, [this](){
|
||||||
@ -336,14 +327,16 @@ void VMainWindow::initFileToolBar()
|
|||||||
discardExitAct = new QAction(QIcon(":/resources/icons/discard_exit.svg"),
|
discardExitAct = new QAction(QIcon(":/resources/icons/discard_exit.svg"),
|
||||||
tr("Discard Changes And Read"), this);
|
tr("Discard Changes And Read"), this);
|
||||||
discardExitAct->setStatusTip(tr("Discard changes and exit edit mode"));
|
discardExitAct->setStatusTip(tr("Discard changes and exit edit mode"));
|
||||||
|
discardExitAct->setToolTip(tr("Discard Changes And Read (Ctrl+E Q)"));
|
||||||
connect(discardExitAct, &QAction::triggered,
|
connect(discardExitAct, &QAction::triggered,
|
||||||
editArea, &VEditArea::readFile);
|
editArea, &VEditArea::readFile);
|
||||||
|
|
||||||
QMenu *exitEditMenu = new QMenu(this);
|
QMenu *exitEditMenu = new QMenu(this);
|
||||||
|
exitEditMenu->setToolTipsVisible(true);
|
||||||
exitEditMenu->addAction(discardExitAct);
|
exitEditMenu->addAction(discardExitAct);
|
||||||
|
|
||||||
saveExitAct = new QAction(QIcon(":/resources/icons/save_exit.svg"),
|
saveExitAct = new QAction(QIcon(":/resources/icons/save_exit.svg"),
|
||||||
tr("Save Changes And Read"), this);
|
tr("Save Changes And Read (Ctrl+T)"), this);
|
||||||
saveExitAct->setStatusTip(tr("Save changes and exit edit mode"));
|
saveExitAct->setStatusTip(tr("Save changes and exit edit mode"));
|
||||||
saveExitAct->setMenu(exitEditMenu);
|
saveExitAct->setMenu(exitEditMenu);
|
||||||
saveExitAct->setShortcut(QKeySequence("Ctrl+T"));
|
saveExitAct->setShortcut(QKeySequence("Ctrl+T"));
|
||||||
|
@ -328,6 +328,17 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Qt::Key_D:
|
||||||
|
{
|
||||||
|
if (modifiers == Qt::ControlModifier) {
|
||||||
|
decorateStrikethrough();
|
||||||
|
p_event->accept();
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -653,18 +664,24 @@ void VMdEditOperations::decorateText(TextDecoration p_decoration)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_vim->setMode(VimMode::Insert, false);
|
|
||||||
|
|
||||||
switch (p_decoration) {
|
switch (p_decoration) {
|
||||||
case TextDecoration::Bold:
|
case TextDecoration::Bold:
|
||||||
|
m_vim->setMode(VimMode::Insert, false);
|
||||||
decorateBold();
|
decorateBold();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TextDecoration::Italic:
|
case TextDecoration::Italic:
|
||||||
|
m_vim->setMode(VimMode::Insert, false);
|
||||||
decorateItalic();
|
decorateItalic();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TextDecoration::Strikethrough:
|
||||||
|
m_vim->setMode(VimMode::Insert, false);
|
||||||
|
decorateStrikethrough();
|
||||||
|
break;
|
||||||
|
|
||||||
case TextDecoration::InlineCode:
|
case TextDecoration::InlineCode:
|
||||||
|
m_vim->setMode(VimMode::Insert, false);
|
||||||
decorateInlineCode();
|
decorateInlineCode();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -784,3 +801,40 @@ void VMdEditOperations::decorateInlineCode()
|
|||||||
cursor.endEditBlock();
|
cursor.endEditBlock();
|
||||||
m_editor->setTextCursor(cursor);
|
m_editor->setTextCursor(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMdEditOperations::decorateStrikethrough()
|
||||||
|
{
|
||||||
|
QTextCursor cursor = m_editor->textCursor();
|
||||||
|
cursor.beginEditBlock();
|
||||||
|
if (cursor.hasSelection()) {
|
||||||
|
// Insert ~~ around the selected text.
|
||||||
|
int start = cursor.selectionStart();
|
||||||
|
int end = cursor.selectionEnd();
|
||||||
|
cursor.clearSelection();
|
||||||
|
cursor.setPosition(start, QTextCursor::MoveAnchor);
|
||||||
|
cursor.insertText("~~");
|
||||||
|
cursor.setPosition(end + 2, QTextCursor::MoveAnchor);
|
||||||
|
cursor.insertText("~~");
|
||||||
|
} else {
|
||||||
|
// Insert ~~~~ and place cursor in the middle.
|
||||||
|
// Or if there are one ~~ after current cursor, just skip it.
|
||||||
|
int pos = cursor.positionInBlock();
|
||||||
|
bool hasStrikethrough = false;
|
||||||
|
QString text = cursor.block().text();
|
||||||
|
if (pos <= text.size() - 2) {
|
||||||
|
if (text[pos] == '~' && text[pos + 1] == '~') {
|
||||||
|
hasStrikethrough = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasStrikethrough) {
|
||||||
|
cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 2);
|
||||||
|
} else {
|
||||||
|
cursor.insertText("~~~~");
|
||||||
|
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.endEditBlock();
|
||||||
|
m_editor->setTextCursor(cursor);
|
||||||
|
}
|
||||||
|
@ -56,6 +56,9 @@ private:
|
|||||||
// Insert inline-code marker or set selected text inline-coded.
|
// Insert inline-code marker or set selected text inline-coded.
|
||||||
void decorateInlineCode();
|
void decorateInlineCode();
|
||||||
|
|
||||||
|
// Insert strikethrough marker or set selected text strikethrough.
|
||||||
|
void decorateStrikethrough();
|
||||||
|
|
||||||
// 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;
|
||||||
|
@ -113,7 +113,6 @@
|
|||||||
<file>utils/flowchart.js/raphael.min.js</file>
|
<file>utils/flowchart.js/raphael.min.js</file>
|
||||||
<file>resources/icons/bold.svg</file>
|
<file>resources/icons/bold.svg</file>
|
||||||
<file>resources/icons/italic.svg</file>
|
<file>resources/icons/italic.svg</file>
|
||||||
<file>resources/icons/underline.svg</file>
|
|
||||||
<file>resources/icons/strikethrough.svg</file>
|
<file>resources/icons/strikethrough.svg</file>
|
||||||
<file>resources/icons/inline_code.svg</file>
|
<file>resources/icons/inline_code.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user