From 044b3d3c298c33087c4cc32fcba71402e7768854 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 4 Jan 2018 19:54:44 +0800 Subject: [PATCH] add VLineEdit which supports Ctrl+H/W/U shortcuts --- src/dialog/vdeletenotebookdialog.h | 1 - src/dialog/vdirinfodialog.cpp | 2 +- src/dialog/veditsnippetdialog.cpp | 11 +++-- src/dialog/veditsnippetdialog.h | 6 +-- src/dialog/vfileinfodialog.cpp | 4 +- src/dialog/vfindreplacedialog.cpp | 7 +-- src/dialog/vfindreplacedialog.h | 6 +-- src/dialog/vinsertimagedialog.cpp | 7 +-- src/dialog/vinsertimagedialog.h | 4 +- src/dialog/vinsertlinkdialog.cpp | 6 +-- src/dialog/vinsertlinkdialog.h | 4 +- src/dialog/vnewdirdialog.cpp | 2 +- src/dialog/vnewnotebookdialog.cpp | 10 ++-- src/dialog/vnewnotebookdialog.h | 8 +-- src/dialog/vnotebookinfodialog.cpp | 10 ++-- src/dialog/vnotebookinfodialog.h | 8 +-- src/dialog/vorphanfileinfodialog.cpp | 5 +- src/dialog/vorphanfileinfodialog.h | 4 +- src/dialog/vsettingsdialog.cpp | 9 ++-- src/dialog/vsettingsdialog.h | 10 ++-- src/lineeditdelegate.cpp | 8 +-- src/src.pro | 6 ++- src/vattachmentlist.cpp | 3 +- src/vexporter.cpp | 3 +- src/vexporter.h | 4 +- src/vlineedit.cpp | 74 ++++++++++++++++++++++++++++ src/vlineedit.h | 19 +++++++ src/vmetawordlineedit.cpp | 6 +-- src/vmetawordlineedit.h | 6 +-- src/vvimindicator.cpp | 6 +-- src/vvimindicator.h | 4 +- 31 files changed, 182 insertions(+), 81 deletions(-) create mode 100644 src/vlineedit.cpp create mode 100644 src/vlineedit.h diff --git a/src/dialog/vdeletenotebookdialog.h b/src/dialog/vdeletenotebookdialog.h index d88baac8..0f6f949e 100644 --- a/src/dialog/vdeletenotebookdialog.h +++ b/src/dialog/vdeletenotebookdialog.h @@ -5,7 +5,6 @@ #include class QLabel; -class QLineEdit; class QString; class QCheckBox; class QDialogButtonBox; diff --git a/src/dialog/vdirinfodialog.cpp b/src/dialog/vdirinfodialog.cpp index 479aa9c9..c423bc01 100644 --- a/src/dialog/vdirinfodialog.cpp +++ b/src/dialog/vdirinfodialog.cpp @@ -17,7 +17,7 @@ VDirInfoDialog::VDirInfoDialog(const QString &title, { setupUI(); - connect(m_nameEdit, &QLineEdit::textChanged, this, &VDirInfoDialog::handleInputChanged); + connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VDirInfoDialog::handleInputChanged); handleInputChanged(); } diff --git a/src/dialog/veditsnippetdialog.cpp b/src/dialog/veditsnippetdialog.cpp index 9ca9aa87..fcdc5563 100644 --- a/src/dialog/veditsnippetdialog.cpp +++ b/src/dialog/veditsnippetdialog.cpp @@ -5,6 +5,7 @@ #include "vmetawordlineedit.h" #include "vconfigmanager.h" #include "utils/vmetawordmanager.h" +#include "vlineedit.h" extern VMetaWordManager *g_mwMgr; @@ -65,11 +66,11 @@ void VEditSnippetDialog::setupUI(const QString &p_title, const QString &p_info) } // Cursor mark. - m_cursorMarkEdit = new QLineEdit(m_snippet.getCursorMark()); + m_cursorMarkEdit = new VLineEdit(m_snippet.getCursorMark()); m_cursorMarkEdit->setToolTip(tr("String in the content to mark the cursor position")); // Selection mark. - m_selectionMarkEdit = new QLineEdit(m_snippet.getSelectionMark()); + m_selectionMarkEdit = new VLineEdit(m_snippet.getSelectionMark()); m_selectionMarkEdit->setToolTip(tr("String in the content to be replaced with selected text")); // Auto Indent. @@ -117,16 +118,16 @@ void VEditSnippetDialog::setupUI(const QString &p_title, const QString &p_info) setWindowTitle(p_title); - connect(m_nameEdit, &QLineEdit::textChanged, + connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VEditSnippetDialog::handleInputChanged); connect(m_typeCB, static_cast(&QComboBox::currentIndexChanged), this, &VEditSnippetDialog::handleInputChanged); - connect(m_cursorMarkEdit, &QLineEdit::textChanged, + connect(m_cursorMarkEdit, &VLineEdit::textChanged, this, &VEditSnippetDialog::handleInputChanged); - connect(m_selectionMarkEdit, &QLineEdit::textChanged, + connect(m_selectionMarkEdit, &VLineEdit::textChanged, this, &VEditSnippetDialog::handleInputChanged); connect(m_contentEdit, &QTextEdit::textChanged, diff --git a/src/dialog/veditsnippetdialog.h b/src/dialog/veditsnippetdialog.h index f6907c35..8f3c0cd4 100644 --- a/src/dialog/veditsnippetdialog.h +++ b/src/dialog/veditsnippetdialog.h @@ -7,7 +7,7 @@ #include "vsnippet.h" class VMetaWordLineEdit; -class QLineEdit; +class VLineEdit; class QLabel; class QDialogButtonBox; class QComboBox; @@ -54,8 +54,8 @@ private: VMetaWordLineEdit *m_nameEdit; QComboBox *m_typeCB; QComboBox *m_shortcutCB; - QLineEdit *m_cursorMarkEdit; - QLineEdit *m_selectionMarkEdit; + VLineEdit *m_cursorMarkEdit; + VLineEdit *m_selectionMarkEdit; QCheckBox *m_autoIndentCB; QTextEdit *m_contentEdit; diff --git a/src/dialog/vfileinfodialog.cpp b/src/dialog/vfileinfodialog.cpp index dd17e63f..f6d2e723 100644 --- a/src/dialog/vfileinfodialog.cpp +++ b/src/dialog/vfileinfodialog.cpp @@ -17,7 +17,7 @@ VFileInfoDialog::VFileInfoDialog(const QString &title, { setupUI(title, info); - connect(m_nameEdit, &QLineEdit::textChanged, this, &VFileInfoDialog::handleInputChanged); + connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VFileInfoDialog::handleInputChanged); handleInputChanged(); } @@ -45,7 +45,7 @@ void VFileInfoDialog::setupUI(const QString &p_title, const QString &p_info) m_nameEdit->setSelection(baseStart, baseLength); // Attachment folder. - QLineEdit *attachmentFolderEdit = new QLineEdit(m_file->getAttachmentFolder()); + VLineEdit *attachmentFolderEdit = new VLineEdit(m_file->getAttachmentFolder()); attachmentFolderEdit->setPlaceholderText(tr("Will be assigned when adding attachments")); attachmentFolderEdit->setToolTip(tr("The folder to hold attachments of this note")); attachmentFolderEdit->setReadOnly(true); diff --git a/src/dialog/vfindreplacedialog.cpp b/src/dialog/vfindreplacedialog.cpp index 9dc196f1..7954b298 100644 --- a/src/dialog/vfindreplacedialog.cpp +++ b/src/dialog/vfindreplacedialog.cpp @@ -2,6 +2,7 @@ #include #include "utils/viconutils.h" +#include "vlineedit.h" VFindReplaceDialog::VFindReplaceDialog(QWidget *p_parent) : QWidget(p_parent), m_options(0), m_replaceAvailable(true) @@ -28,7 +29,7 @@ void VFindReplaceDialog::setupUI() // Find QLabel *findLabel = new QLabel(tr("Find:")); - m_findEdit = new QLineEdit(); + m_findEdit = new VLineEdit(); m_findEdit->setPlaceholderText(tr("Enter text to search")); findLabel->setBuddy(m_findEdit); m_findNextBtn = new QPushButton(tr("Find &Next")); @@ -39,7 +40,7 @@ void VFindReplaceDialog::setupUI() // Replace QLabel *replaceLabel = new QLabel(tr("&Replace with:")); - m_replaceEdit = new QLineEdit(); + m_replaceEdit = new VLineEdit(); m_replaceEdit->setPlaceholderText(tr("Enter text to replace with")); replaceLabel->setBuddy(m_replaceEdit); m_replaceBtn = new QPushButton(tr("Replace")); @@ -121,7 +122,7 @@ void VFindReplaceDialog::setupUI() // Signals connect(m_closeBtn, &QPushButton::clicked, this, &VFindReplaceDialog::closeDialog); - connect(m_findEdit, &QLineEdit::textChanged, + connect(m_findEdit, &VLineEdit::textChanged, this, &VFindReplaceDialog::handleFindTextChanged); connect(m_advancedBtn, &QPushButton::toggled, this, &VFindReplaceDialog::advancedBtnToggled); diff --git a/src/dialog/vfindreplacedialog.h b/src/dialog/vfindreplacedialog.h index 59cd0397..3d2edb4c 100644 --- a/src/dialog/vfindreplacedialog.h +++ b/src/dialog/vfindreplacedialog.h @@ -5,7 +5,7 @@ #include #include "vconstants.h" -class QLineEdit; +class VLineEdit; class QPushButton; class QCheckBox; @@ -52,8 +52,8 @@ private: uint m_options; bool m_replaceAvailable; - QLineEdit *m_findEdit; - QLineEdit *m_replaceEdit; + VLineEdit *m_findEdit; + VLineEdit *m_replaceEdit; QPushButton *m_findNextBtn; QPushButton *m_findPrevBtn; QPushButton *m_replaceBtn; diff --git a/src/dialog/vinsertimagedialog.cpp b/src/dialog/vinsertimagedialog.cpp index d6aff6fe..86d6a424 100644 --- a/src/dialog/vinsertimagedialog.cpp +++ b/src/dialog/vinsertimagedialog.cpp @@ -7,6 +7,7 @@ #include "utils/vutils.h" #include "vmetawordlineedit.h" #include "vdownloader.h" +#include "vlineedit.h" VInsertImageDialog::VInsertImageDialog(const QString &p_title, const QString &p_imageTitle, @@ -20,7 +21,7 @@ VInsertImageDialog::VInsertImageDialog(const QString &p_title, { setupUI(p_title, p_imageTitle, p_imagePath); - connect(m_imageTitleEdit, &QLineEdit::textChanged, + connect(m_imageTitleEdit, &VMetaWordLineEdit::textChanged, this, &VInsertImageDialog::handleInputChanged); if (m_browsable) { @@ -30,7 +31,7 @@ VInsertImageDialog::VInsertImageDialog(const QString &p_title, connect(m_timer, &QTimer::timeout, this, &VInsertImageDialog::handlePathEditChanged); - connect(m_pathEdit, &QLineEdit::textChanged, + connect(m_pathEdit, &VLineEdit::textChanged, this, [this]() { m_timer->stop(); @@ -64,7 +65,7 @@ void VInsertImageDialog::setupUI(const QString &p_title, const QString &p_imagePath) { QLabel *pathLabel = new QLabel(tr("&From:")); - m_pathEdit = new QLineEdit(p_imagePath); + m_pathEdit = new VLineEdit(p_imagePath); pathLabel->setBuddy(m_pathEdit); browseBtn = new QPushButton(tr("&Browse")); m_pathEdit->setReadOnly(!m_browsable); diff --git a/src/dialog/vinsertimagedialog.h b/src/dialog/vinsertimagedialog.h index 6ea5857a..95294632 100644 --- a/src/dialog/vinsertimagedialog.h +++ b/src/dialog/vinsertimagedialog.h @@ -7,7 +7,7 @@ #include class QLabel; -class QLineEdit; +class VLineEdit; class VMetaWordLineEdit; class QPushButton; class QDialogButtonBox; @@ -59,7 +59,7 @@ private: void fetchImageFromClipboard(); VMetaWordLineEdit *m_imageTitleEdit; - QLineEdit *m_pathEdit; + VLineEdit *m_pathEdit; QPushButton *browseBtn; QDialogButtonBox *m_btnBox; QLabel *imagePreviewLabel; diff --git a/src/dialog/vinsertlinkdialog.cpp b/src/dialog/vinsertlinkdialog.cpp index 91c68ac5..47950481 100644 --- a/src/dialog/vinsertlinkdialog.cpp +++ b/src/dialog/vinsertlinkdialog.cpp @@ -40,7 +40,7 @@ void VInsertLinkDialog::setupUI(const QString &p_title, m_linkTextEdit = new VMetaWordLineEdit(p_linkText); m_linkTextEdit->selectAll(); - m_linkUrlEdit = new QLineEdit(p_linkUrl); + m_linkUrlEdit = new VLineEdit(p_linkUrl); m_linkUrlEdit->setToolTip(tr("Absolute or relative path of the link")); QFormLayout *inputLayout = new QFormLayout(); @@ -71,9 +71,9 @@ void VInsertLinkDialog::setupUI(const QString &p_title, setLayout(mainLayout); setWindowTitle(p_title); - connect(m_linkTextEdit, &QLineEdit::textChanged, + connect(m_linkTextEdit, &VMetaWordLineEdit::textChanged, this, &VInsertLinkDialog::handleInputChanged); - connect(m_linkUrlEdit, &QLineEdit::textChanged, + connect(m_linkUrlEdit, &VLineEdit::textChanged, this, &VInsertLinkDialog::handleInputChanged); } diff --git a/src/dialog/vinsertlinkdialog.h b/src/dialog/vinsertlinkdialog.h index 52f20013..c9c8c7d1 100644 --- a/src/dialog/vinsertlinkdialog.h +++ b/src/dialog/vinsertlinkdialog.h @@ -5,7 +5,7 @@ #include class VMetaWordLineEdit; -class QLineEdit; +class VLineEdit; class QDialogButtonBox; class QShowEvent; @@ -42,7 +42,7 @@ private: VMetaWordLineEdit *m_linkTextEdit; - QLineEdit *m_linkUrlEdit; + VLineEdit *m_linkUrlEdit; QDialogButtonBox *m_btnBox; }; diff --git a/src/dialog/vnewdirdialog.cpp b/src/dialog/vnewdirdialog.cpp index af707842..f0c778bc 100644 --- a/src/dialog/vnewdirdialog.cpp +++ b/src/dialog/vnewdirdialog.cpp @@ -17,7 +17,7 @@ VNewDirDialog::VNewDirDialog(const QString &title, { setupUI(); - connect(m_nameEdit, &QLineEdit::textChanged, this, &VNewDirDialog::handleInputChanged); + connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VNewDirDialog::handleInputChanged); handleInputChanged(); } diff --git a/src/dialog/vnewnotebookdialog.cpp b/src/dialog/vnewnotebookdialog.cpp index df73c394..d70a7b45 100644 --- a/src/dialog/vnewnotebookdialog.cpp +++ b/src/dialog/vnewnotebookdialog.cpp @@ -19,8 +19,8 @@ VNewNotebookDialog::VNewNotebookDialog(const QString &title, const QString &info { setupUI(title, info); - connect(m_nameEdit, &QLineEdit::textChanged, this, &VNewNotebookDialog::handleInputChanged); - connect(pathEdit, &QLineEdit::textChanged, this, &VNewNotebookDialog::handleInputChanged); + connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VNewNotebookDialog::handleInputChanged); + connect(pathEdit, &VLineEdit::textChanged, this, &VNewNotebookDialog::handleInputChanged); connect(browseBtn, &QPushButton::clicked, this, &VNewNotebookDialog::handleBrowseBtnClicked); handleInputChanged(); @@ -42,12 +42,12 @@ void VNewNotebookDialog::setupUI(const QString &p_title, const QString &p_info) nameLabel->setBuddy(m_nameEdit); QLabel *pathLabel = new QLabel(tr("Notebook &root folder:")); - pathEdit = new QLineEdit(defaultPath); + pathEdit = new VLineEdit(defaultPath); pathLabel->setBuddy(pathEdit); browseBtn = new QPushButton(tr("&Browse")); QLabel *imageFolderLabel = new QLabel(tr("&Image folder:")); - m_imageFolderEdit = new QLineEdit(); + m_imageFolderEdit = new VLineEdit(); imageFolderLabel->setBuddy(m_imageFolderEdit); m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)") .arg(g_config->getImageFolder())); @@ -58,7 +58,7 @@ void VNewNotebookDialog::setupUI(const QString &p_title, const QString &p_info) m_imageFolderEdit->setValidator(validator); QLabel *attachmentFolderLabel = new QLabel(tr("&Attachment folder:")); - m_attachmentFolderEdit = new QLineEdit(); + m_attachmentFolderEdit = new VLineEdit(); attachmentFolderLabel->setBuddy(m_attachmentFolderEdit); m_attachmentFolderEdit->setPlaceholderText(tr("Use global configuration (%1)") .arg(g_config->getAttachmentFolder())); diff --git a/src/dialog/vnewnotebookdialog.h b/src/dialog/vnewnotebookdialog.h index b300b2b6..79143f89 100644 --- a/src/dialog/vnewnotebookdialog.h +++ b/src/dialog/vnewnotebookdialog.h @@ -5,7 +5,7 @@ #include class QLabel; -class QLineEdit; +class VLineEdit; class VMetaWordLineEdit; class QPushButton; class QDialogButtonBox; @@ -54,11 +54,11 @@ private: bool autoComplete(); VMetaWordLineEdit *m_nameEdit; - QLineEdit *pathEdit; + VLineEdit *pathEdit; QPushButton *browseBtn; QLabel *m_warnLabel; - QLineEdit *m_imageFolderEdit; - QLineEdit *m_attachmentFolderEdit; + VLineEdit *m_imageFolderEdit; + VLineEdit *m_attachmentFolderEdit; QDialogButtonBox *m_btnBox; QString defaultName; diff --git a/src/dialog/vnotebookinfodialog.cpp b/src/dialog/vnotebookinfodialog.cpp index d84eeea0..bb087c9e 100644 --- a/src/dialog/vnotebookinfodialog.cpp +++ b/src/dialog/vnotebookinfodialog.cpp @@ -17,7 +17,7 @@ VNotebookInfoDialog::VNotebookInfoDialog(const QString &p_title, { setupUI(p_title, p_info); - connect(m_nameEdit, &QLineEdit::textChanged, + connect(m_nameEdit, &VMetaWordLineEdit::textChanged, this, &VNotebookInfoDialog::handleInputChanged); handleInputChanged(); @@ -36,11 +36,11 @@ void VNotebookInfoDialog::setupUI(const QString &p_title, const QString &p_info) m_nameEdit->setValidator(validator); m_nameEdit->selectAll(); - m_pathEdit = new QLineEdit(m_notebook->getPath()); + m_pathEdit = new VLineEdit(m_notebook->getPath()); m_pathEdit->setReadOnly(true); // Image folder. - m_imageFolderEdit = new QLineEdit(m_notebook->getImageFolderConfig()); + m_imageFolderEdit = new VLineEdit(m_notebook->getImageFolderConfig()); m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)") .arg(g_config->getImageFolder())); m_imageFolderEdit->setToolTip(tr("Set the name of the folder to hold images of all the notes in this notebook " @@ -50,14 +50,14 @@ void VNotebookInfoDialog::setupUI(const QString &p_title, const QString &p_info) // Attachment folder. Q_ASSERT(!m_notebook->getAttachmentFolder().isEmpty()); - m_attachmentFolderEdit = new QLineEdit(m_notebook->getAttachmentFolder()); + m_attachmentFolderEdit = new VLineEdit(m_notebook->getAttachmentFolder()); m_attachmentFolderEdit->setPlaceholderText(tr("Use global configuration (%1)") .arg(g_config->getAttachmentFolder())); m_attachmentFolderEdit->setToolTip(tr("The folder to hold attachments of all the notes in this notebook")); m_attachmentFolderEdit->setReadOnly(true); // Recycle bin folder. - QLineEdit *recycleBinFolderEdit = new QLineEdit(m_notebook->getRecycleBinFolder()); + VLineEdit *recycleBinFolderEdit = new VLineEdit(m_notebook->getRecycleBinFolder()); recycleBinFolderEdit->setReadOnly(true); recycleBinFolderEdit->setToolTip(tr("The folder to hold deleted files from within VNote of all the notes in this notebook")); diff --git a/src/dialog/vnotebookinfodialog.h b/src/dialog/vnotebookinfodialog.h index fc90800b..e7e98a85 100644 --- a/src/dialog/vnotebookinfodialog.h +++ b/src/dialog/vnotebookinfodialog.h @@ -5,7 +5,7 @@ #include class QLabel; -class QLineEdit; +class VLineEdit; class VMetaWordLineEdit; class QDialogButtonBox; class QString; @@ -40,10 +40,10 @@ private: const VNotebook *m_notebook; VMetaWordLineEdit *m_nameEdit; - QLineEdit *m_pathEdit; - QLineEdit *m_imageFolderEdit; + VLineEdit *m_pathEdit; + VLineEdit *m_imageFolderEdit; // Read-only. - QLineEdit *m_attachmentFolderEdit; + VLineEdit *m_attachmentFolderEdit; QLabel *m_warnLabel; QDialogButtonBox *m_btnBox; const QVector &m_notebooks; diff --git a/src/dialog/vorphanfileinfodialog.cpp b/src/dialog/vorphanfileinfodialog.cpp index 5b7b561e..88a41492 100644 --- a/src/dialog/vorphanfileinfodialog.cpp +++ b/src/dialog/vorphanfileinfodialog.cpp @@ -4,6 +4,7 @@ #include "vorphanfile.h" #include "vconfigmanager.h" #include "utils/vutils.h" +#include "vlineedit.h" extern VConfigManager *g_config; @@ -12,7 +13,7 @@ VOrphanFileInfoDialog::VOrphanFileInfoDialog(const VOrphanFile *p_file, QWidget { setupUI(); - connect(m_imageFolderEdit, &QLineEdit::textChanged, + connect(m_imageFolderEdit, &VLineEdit::textChanged, this, &VOrphanFileInfoDialog::handleInputChanged); handleInputChanged(); @@ -25,7 +26,7 @@ void VOrphanFileInfoDialog::setupUI() QLabel *fileLabel = new QLabel(m_file->fetchPath()); topLayout->addRow(tr("File:"), fileLabel); - m_imageFolderEdit = new QLineEdit(m_file->getImageFolder()); + m_imageFolderEdit = new VLineEdit(m_file->getImageFolder()); m_imageFolderEdit->setPlaceholderText(tr("Use global configuration (%1)") .arg(g_config->getImageFolderExt())); QString imgFolderTip = tr("Set the path of the image folder to store images " diff --git a/src/dialog/vorphanfileinfodialog.h b/src/dialog/vorphanfileinfodialog.h index f0d2a862..9093a77e 100644 --- a/src/dialog/vorphanfileinfodialog.h +++ b/src/dialog/vorphanfileinfodialog.h @@ -5,7 +5,7 @@ class VOrphanFile; class QDialogButtonBox; -class QLineEdit; +class VLineEdit; class VOrphanFileInfoDialog : public QDialog { @@ -28,7 +28,7 @@ private: const VOrphanFile *m_file; QDialogButtonBox *m_btnBox; - QLineEdit *m_imageFolderEdit; + VLineEdit *m_imageFolderEdit; }; #endif // VORPHANFILEINFODIALOG_H diff --git a/src/dialog/vsettingsdialog.cpp b/src/dialog/vsettingsdialog.cpp index d1eb5abb..b5406cd9 100644 --- a/src/dialog/vsettingsdialog.cpp +++ b/src/dialog/vsettingsdialog.cpp @@ -4,6 +4,7 @@ #include "vconfigmanager.h" #include "utils/vutils.h" #include "vconstants.h" +#include "vlineedit.h" extern VConfigManager *g_config; @@ -440,7 +441,7 @@ VNoteManagementTab::VNoteManagementTab(QWidget *p_parent) connect(m_customImageFolder, &QCheckBox::stateChanged, this, &VNoteManagementTab::customImageFolderChanged); - m_imageFolderEdit = new QLineEdit(this); + m_imageFolderEdit = new VLineEdit(this); m_imageFolderEdit->setPlaceholderText(tr("Name of the image folder")); m_imageFolderEdit->setToolTip(m_customImageFolder->toolTip()); QValidator *validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp), this); @@ -457,7 +458,7 @@ VNoteManagementTab::VNoteManagementTab(QWidget *p_parent) connect(m_customAttachmentFolder, &QCheckBox::stateChanged, this, &VNoteManagementTab::customAttachmentFolderChanged); - m_attachmentFolderEdit = new QLineEdit(this); + m_attachmentFolderEdit = new VLineEdit(this); m_attachmentFolderEdit->setPlaceholderText(tr("Name of the attachment folder")); m_attachmentFolderEdit->setToolTip(m_customAttachmentFolder->toolTip()); validator = new QRegExpValidator(QRegExp(VUtils::c_fileNameRegExp), this); @@ -483,7 +484,7 @@ VNoteManagementTab::VNoteManagementTab(QWidget *p_parent) connect(m_customImageFolderExt, &QCheckBox::stateChanged, this, &VNoteManagementTab::customImageFolderExtChanged); - m_imageFolderEditExt = new QLineEdit(this); + m_imageFolderEditExt = new VLineEdit(this); m_imageFolderEditExt->setToolTip(m_customImageFolderExt->toolTip()); m_imageFolderEditExt->setPlaceholderText(tr("Name of the image folder")); @@ -689,7 +690,7 @@ VMarkdownTab::VMarkdownTab(QWidget *p_parent) zoomFactorLayout->addWidget(m_webZoomFactorSpin); // Color column. - m_colorColumnEdit = new QLineEdit(); + m_colorColumnEdit = new VLineEdit(); m_colorColumnEdit->setToolTip(tr("Specify the screen column in fenced code block " "which will be highlighted")); QValidator *validator = new QRegExpValidator(QRegExp("\\d+"), this); diff --git a/src/dialog/vsettingsdialog.h b/src/dialog/vsettingsdialog.h index c4afa557..d04aeeb2 100644 --- a/src/dialog/vsettingsdialog.h +++ b/src/dialog/vsettingsdialog.h @@ -10,7 +10,7 @@ class QComboBox; class QGroupBox; class QDoubleSpinBox; class QCheckBox; -class QLineEdit; +class VLineEdit; class QStackedLayout; class QListWidget; class QPlainTextEdit; @@ -79,15 +79,15 @@ public: // Image folder. QCheckBox *m_customImageFolder; - QLineEdit *m_imageFolderEdit; + VLineEdit *m_imageFolderEdit; // Image folder of External File. QCheckBox *m_customImageFolderExt; - QLineEdit *m_imageFolderEditExt; + VLineEdit *m_imageFolderEditExt; // Attachment folder. QCheckBox *m_customAttachmentFolder; - QLineEdit *m_attachmentFolderEdit; + VLineEdit *m_attachmentFolderEdit; private slots: void customImageFolderChanged(int p_state); @@ -125,7 +125,7 @@ public: QDoubleSpinBox *m_webZoomFactorSpin; // Color column in code block. - QLineEdit *m_colorColumnEdit; + VLineEdit *m_colorColumnEdit; private: bool loadOpenMode(); diff --git a/src/lineeditdelegate.cpp b/src/lineeditdelegate.cpp index d424d255..0c5a0faa 100644 --- a/src/lineeditdelegate.cpp +++ b/src/lineeditdelegate.cpp @@ -1,6 +1,6 @@ #include "lineeditdelegate.h" -#include +#include "vlineedit.h" LineEditDelegate::LineEditDelegate(QObject *p_parent) @@ -15,7 +15,7 @@ QWidget *LineEditDelegate::createEditor(QWidget *p_parent, Q_UNUSED(p_option); Q_UNUSED(p_index); - QLineEdit *edit = new QLineEdit(p_parent); + VLineEdit *edit = new VLineEdit(p_parent); return edit; } @@ -23,7 +23,7 @@ void LineEditDelegate::setEditorData(QWidget *p_editor, const QModelIndex &p_ind { QString text = p_index.model()->data(p_index, Qt::EditRole).toString(); - QLineEdit *edit = static_cast(p_editor); + VLineEdit *edit = static_cast(p_editor); edit->setText(text); } @@ -31,7 +31,7 @@ void LineEditDelegate::setModelData(QWidget *p_editor, QAbstractItemModel *p_model, const QModelIndex &p_index) const { - QLineEdit *edit = static_cast(p_editor); + VLineEdit *edit = static_cast(p_editor); p_model->setData(p_index, edit->text(), Qt::EditRole); } diff --git a/src/src.pro b/src/src.pro index 88ae39a1..a78f687d 100644 --- a/src/src.pro +++ b/src/src.pro @@ -105,7 +105,8 @@ SOURCES += main.cpp\ dialog/vtipsdialog.cpp \ dialog/vcopytextashtmldialog.cpp \ vwaitingwidget.cpp \ - utils/vwebutils.cpp + utils/vwebutils.cpp \ + vlineedit.cpp HEADERS += vmainwindow.h \ vdirectorytree.h \ @@ -197,7 +198,8 @@ HEADERS += vmainwindow.h \ dialog/vtipsdialog.h \ dialog/vcopytextashtmldialog.h \ vwaitingwidget.h \ - utils/vwebutils.h + utils/vwebutils.h \ + vlineedit.h RESOURCES += \ vnote.qrc \ diff --git a/src/vattachmentlist.cpp b/src/vattachmentlist.cpp index cdc1d69c..2cd70ff0 100644 --- a/src/vattachmentlist.cpp +++ b/src/vattachmentlist.cpp @@ -10,6 +10,7 @@ #include "dialog/vsortdialog.h" #include "utils/vimnavigationforwidget.h" #include "utils/viconutils.h" +#include "vlineedit.h" extern VConfigManager *g_config; extern VMainWindow *g_mainWin; @@ -413,7 +414,7 @@ void VAttachmentList::sortItems() void VAttachmentList::handleListItemCommitData(QWidget *p_itemEdit) { - QString text = reinterpret_cast(p_itemEdit)->text(); + QString text = reinterpret_cast(p_itemEdit)->text(); QListWidgetItem *item = m_attachmentList->currentItem(); Q_ASSERT(item && item->text() == text); diff --git a/src/vexporter.cpp b/src/vexporter.cpp index 4a76d8a3..5523bc63 100644 --- a/src/vexporter.cpp +++ b/src/vexporter.cpp @@ -22,6 +22,7 @@ #include "vnote.h" #include "vmarkdownconverter.h" #include "vdocument.h" +#include "vlineedit.h" extern VConfigManager *g_config; @@ -51,7 +52,7 @@ void VExporter::setupUI() // Target file path. QLabel *pathLabel = new QLabel(tr("Target &path:")); - m_pathEdit = new QLineEdit(); + m_pathEdit = new VLineEdit(); pathLabel->setBuddy(m_pathEdit); m_browseBtn = new QPushButton(tr("&Browse")); connect(m_browseBtn, &QPushButton::clicked, diff --git a/src/vexporter.h b/src/vexporter.h index a51d79a6..88534820 100644 --- a/src/vexporter.h +++ b/src/vexporter.h @@ -8,7 +8,7 @@ class VWebView; class VFile; -class QLineEdit; +class VLineEdit; class QLabel; class QDialogButtonBox; class QPushButton; @@ -99,7 +99,7 @@ private: ExportState m_state; QLabel *m_infoLabel; - QLineEdit *m_pathEdit; + VLineEdit *m_pathEdit; QPushButton *m_browseBtn; QLabel *m_layoutLabel; QPushButton *m_layoutBtn; diff --git a/src/vlineedit.cpp b/src/vlineedit.cpp new file mode 100644 index 00000000..f1616ced --- /dev/null +++ b/src/vlineedit.cpp @@ -0,0 +1,74 @@ +#include "vlineedit.h" + +#include + +#include "utils/vutils.h" + +VLineEdit::VLineEdit(QWidget *p_parent) + : QLineEdit(p_parent) +{ +} + +VLineEdit::VLineEdit(const QString &p_contents, QWidget *p_parent) + : QLineEdit(p_contents, p_parent) +{ +} + +void VLineEdit::keyPressEvent(QKeyEvent *p_event) +{ + // Note that QKeyEvent starts with isAccepted() == true, so you do not + // need to call QKeyEvent::accept() - just do not call the base class + // implementation if you act upon the key. + + bool accept = false; + int modifiers = p_event->modifiers(); + switch (p_event->key()) { + case Qt::Key_H: + // Backspace. + if (VUtils::isControlModifierForVim(modifiers)) { + backspace(); + accept = true; + } + + break; + + case Qt::Key_W: + // Delete one word backward. + if (VUtils::isControlModifierForVim(modifiers)) { + if (!hasSelectedText()) { + cursorWordBackward(true); + } + + backspace(); + accept = true; + } + + break; + + case Qt::Key_U: + { + if (VUtils::isControlModifierForVim(modifiers)) { + if (hasSelectedText()) { + backspace(); + } else { + int pos = cursorPosition(); + if (pos > 0) { + cursorBackward(true, pos); + backspace(); + } + } + + accept = true; + } + + break; + } + + default: + break; + } + + if (!accept) { + QLineEdit::keyPressEvent(p_event); + } +} diff --git a/src/vlineedit.h b/src/vlineedit.h new file mode 100644 index 00000000..2cc1b367 --- /dev/null +++ b/src/vlineedit.h @@ -0,0 +1,19 @@ +#ifndef VLINEEDIT_H +#define VLINEEDIT_H + +#include + + +class VLineEdit : public QLineEdit +{ + Q_OBJECT +public: + explicit VLineEdit(QWidget *p_parent = nullptr); + + VLineEdit(const QString &p_contents, QWidget *p_parent = nullptr); + +protected: + void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE; +}; + +#endif // VLINEEDIT_H diff --git a/src/vmetawordlineedit.cpp b/src/vmetawordlineedit.cpp index 964b4b34..39d2353a 100644 --- a/src/vmetawordlineedit.cpp +++ b/src/vmetawordlineedit.cpp @@ -9,13 +9,13 @@ extern VMetaWordManager *g_mwMgr; VMetaWordLineEdit::VMetaWordLineEdit(QWidget *p_parent) - : QLineEdit(p_parent) + : VLineEdit(p_parent) { init(); } VMetaWordLineEdit::VMetaWordLineEdit(const QString &p_contents, QWidget *p_parent) - : QLineEdit(p_contents, p_parent) + : VLineEdit(p_contents, p_parent) { init(); } @@ -37,7 +37,7 @@ void VMetaWordLineEdit::init() { m_evaluatedText = g_mwMgr->evaluate(text()); - connect(this, &QLineEdit::textChanged, + connect(this, &VLineEdit::textChanged, this, &VMetaWordLineEdit::handleTextChanged); } diff --git a/src/vmetawordlineedit.h b/src/vmetawordlineedit.h index 13f05720..17352970 100644 --- a/src/vmetawordlineedit.h +++ b/src/vmetawordlineedit.h @@ -1,11 +1,11 @@ #ifndef VMETAWORDLINEEDIT_H #define VMETAWORDLINEEDIT_H -#include +#include "vlineedit.h" -// QLineEdit with meta word support. -class VMetaWordLineEdit : public QLineEdit +// VLineEdit with meta word support. +class VMetaWordLineEdit : public VLineEdit { Q_OBJECT public: diff --git a/src/vvimindicator.cpp b/src/vvimindicator.cpp index eed512c6..7cd41a9f 100644 --- a/src/vvimindicator.cpp +++ b/src/vvimindicator.cpp @@ -341,7 +341,7 @@ void VVimIndicator::triggerCommandLine(VVim::CommandLineType p_type) } VVimCmdLineEdit::VVimCmdLineEdit(QWidget *p_parent) - : QLineEdit(p_parent), m_type(VVim::CommandLineType::Invalid), + : VLineEdit(p_parent), m_type(VVim::CommandLineType::Invalid), m_registerPending(false), m_enableInputMethod(true) { // When user delete all the text, cancel command input. @@ -432,7 +432,7 @@ QVariant VVimCmdLineEdit::inputMethodQuery(Qt::InputMethodQuery p_query) const return m_enableInputMethod; } - return QLineEdit::inputMethodQuery(p_query); + return VLineEdit::inputMethodQuery(p_query); } // See if @p_modifiers is Control which is different on macOs and Windows. @@ -531,7 +531,7 @@ void VVimCmdLineEdit::keyPressEvent(QKeyEvent *p_event) } exit: - QLineEdit::keyPressEvent(p_event); + VLineEdit::keyPressEvent(p_event); } void VVimCmdLineEdit::focusOutEvent(QFocusEvent *p_event) diff --git a/src/vvimindicator.h b/src/vvimindicator.h index 74b1ea55..4c83ecbb 100644 --- a/src/vvimindicator.h +++ b/src/vvimindicator.h @@ -2,9 +2,9 @@ #define VVIMINDICATOR_H #include -#include #include #include "utils/vvim.h" +#include "vlineedit.h" class QLabel; class VButtonWithWidget; @@ -12,7 +12,7 @@ class QKeyEvent; class QFocusEvent; class VEditTab; -class VVimCmdLineEdit : public QLineEdit +class VVimCmdLineEdit : public VLineEdit { Q_OBJECT