mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59: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
|
||||
- `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`
|
||||
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`
|
||||
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`
|
||||
Backspace. Delete a character backward.
|
||||
- `Ctrl+W`
|
||||
@ -54,7 +56,7 @@ Delete all the characters from current cursor to the first space backward.
|
||||
- `Ctrl+U`
|
||||
Delete all the characters from current cursor to the beginning of current line.
|
||||
- `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`
|
||||
Increase or decrease the indentation. If any text is selected, the indentation will operate on all these selected lines.
|
||||
- `Shift+Enter`
|
||||
|
@ -45,6 +45,8 @@
|
||||
插入粗体;再次按`Ctrl+B`退出。如果已经选择文本,则将当前选择文本加粗。
|
||||
- `Ctrl+I`
|
||||
插入斜体;再次按`Ctrl+I`退出。如果已经选择文本,则将当前选择文本改为斜体。
|
||||
- `Ctrl+D`
|
||||
插入删除线;再次按`Ctrl+D`退出。如果已经选择文本,则将当前选择文本改为删除线。
|
||||
- `Ctrl+O`
|
||||
插入行内代码;再次按`Ctrl+O`退出。如果已经选择文本,则将当前选择文本改为行内代码。
|
||||
- `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">
|
||||
<g>
|
||||
<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>
|
||||
<rect stroke="#000000" fill="#000000" stroke-width="5" x="94.999999" y="282" width="318.999997" height="21" id="svg_2" stroke-opacity="0"/>
|
||||
<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="91" y="262" width="325" height="21" id="svg_2" stroke-opacity="0"/>
|
||||
</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"),
|
||||
tr("&Single Panel"), this);
|
||||
onePanelViewAct->setStatusTip(tr("Display only the notes list panel"));
|
||||
onePanelViewAct->setToolTip(tr("Single Panel (Ctrl+E P)"));
|
||||
connect(onePanelViewAct, &QAction::triggered,
|
||||
this, &VMainWindow::onePanelView);
|
||||
|
||||
QAction *twoPanelViewAct = new QAction(QIcon(":/resources/icons/two_panels.svg"),
|
||||
tr("&Two Panels"), this);
|
||||
twoPanelViewAct->setStatusTip(tr("Display both the folders and notes list panel"));
|
||||
twoPanelViewAct->setToolTip(tr("Two Panels (Ctrl+E P)"));
|
||||
connect(twoPanelViewAct, &QAction::triggered,
|
||||
this, &VMainWindow::twoPanelView);
|
||||
|
||||
QMenu *panelMenu = new QMenu(this);
|
||||
panelMenu->setToolTipsVisible(true);
|
||||
panelMenu->addAction(onePanelViewAct);
|
||||
panelMenu->addAction(twoPanelViewAct);
|
||||
|
||||
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->setCheckable(true);
|
||||
expandViewAct->setMenu(panelMenu);
|
||||
@ -229,7 +232,7 @@ void VMainWindow::initEditToolBar()
|
||||
m_editToolBar->addSeparator();
|
||||
|
||||
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"));
|
||||
connect(boldAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
@ -241,7 +244,7 @@ void VMainWindow::initEditToolBar()
|
||||
m_editToolBar->addAction(boldAct);
|
||||
|
||||
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"));
|
||||
connect(italicAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
@ -252,20 +255,8 @@ void VMainWindow::initEditToolBar()
|
||||
|
||||
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"),
|
||||
tr("Strikethrough"), this);
|
||||
tr("Strikethrough (Ctrl+D)"), this);
|
||||
strikethroughAct->setStatusTip(tr("Insert strikethrough text or change selected text to strikethroughed"));
|
||||
connect(strikethroughAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
@ -277,7 +268,7 @@ void VMainWindow::initEditToolBar()
|
||||
m_editToolBar->addAction(strikethroughAct);
|
||||
|
||||
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"));
|
||||
connect(inlineCodeAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
@ -336,14 +327,16 @@ void VMainWindow::initFileToolBar()
|
||||
discardExitAct = new QAction(QIcon(":/resources/icons/discard_exit.svg"),
|
||||
tr("Discard Changes And Read"), this);
|
||||
discardExitAct->setStatusTip(tr("Discard changes and exit edit mode"));
|
||||
discardExitAct->setToolTip(tr("Discard Changes And Read (Ctrl+E Q)"));
|
||||
connect(discardExitAct, &QAction::triggered,
|
||||
editArea, &VEditArea::readFile);
|
||||
|
||||
QMenu *exitEditMenu = new QMenu(this);
|
||||
exitEditMenu->setToolTipsVisible(true);
|
||||
exitEditMenu->addAction(discardExitAct);
|
||||
|
||||
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->setMenu(exitEditMenu);
|
||||
saveExitAct->setShortcut(QKeySequence("Ctrl+T"));
|
||||
|
@ -328,6 +328,17 @@ bool VMdEditOperations::handleKeyPressEvent(QKeyEvent *p_event)
|
||||
break;
|
||||
}
|
||||
|
||||
case Qt::Key_D:
|
||||
{
|
||||
if (modifiers == Qt::ControlModifier) {
|
||||
decorateStrikethrough();
|
||||
p_event->accept();
|
||||
ret = true;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -653,18 +664,24 @@ void VMdEditOperations::decorateText(TextDecoration p_decoration)
|
||||
return;
|
||||
}
|
||||
|
||||
m_vim->setMode(VimMode::Insert, false);
|
||||
|
||||
switch (p_decoration) {
|
||||
case TextDecoration::Bold:
|
||||
m_vim->setMode(VimMode::Insert, false);
|
||||
decorateBold();
|
||||
break;
|
||||
|
||||
case TextDecoration::Italic:
|
||||
m_vim->setMode(VimMode::Insert, false);
|
||||
decorateItalic();
|
||||
break;
|
||||
|
||||
case TextDecoration::Strikethrough:
|
||||
m_vim->setMode(VimMode::Insert, false);
|
||||
decorateStrikethrough();
|
||||
break;
|
||||
|
||||
case TextDecoration::InlineCode:
|
||||
m_vim->setMode(VimMode::Insert, false);
|
||||
decorateInlineCode();
|
||||
break;
|
||||
|
||||
@ -784,3 +801,40 @@ void VMdEditOperations::decorateInlineCode()
|
||||
cursor.endEditBlock();
|
||||
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.
|
||||
void decorateInlineCode();
|
||||
|
||||
// Insert strikethrough marker or set selected text strikethrough.
|
||||
void decorateStrikethrough();
|
||||
|
||||
// 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.
|
||||
int m_autoIndentPos;
|
||||
|
@ -113,7 +113,6 @@
|
||||
<file>utils/flowchart.js/raphael.min.js</file>
|
||||
<file>resources/icons/bold.svg</file>
|
||||
<file>resources/icons/italic.svg</file>
|
||||
<file>resources/icons/underline.svg</file>
|
||||
<file>resources/icons/strikethrough.svg</file>
|
||||
<file>resources/icons/inline_code.svg</file>
|
||||
</qresource>
|
||||
|
Loading…
x
Reference in New Issue
Block a user