From df33ee6770e8d19c79c7dacedbb9e4da4756bac5 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Mon, 15 Mar 2021 20:20:17 +0800 Subject: [PATCH] small fixes 1. Show Full Screen tips; 2. Show Rich Paste and Paste To Markdown tips; --- libs/vtextedit | 2 +- .../notebookconfigmgr/vxnotebookconfigmgr.cpp | 8 ++- src/core/vnotex.cpp | 9 ++- src/core/vnotex.h | 8 ++- src/data/extra/themes/moonlight/interface.qss | 5 ++ src/data/extra/themes/native/interface.qss | 5 ++ src/data/extra/themes/pure/interface.qss | 5 ++ src/widgets/dialogs/managenotebooksdialog.cpp | 13 +++-- src/widgets/editors/markdowneditor.cpp | 4 ++ src/widgets/fullscreentoggleaction.cpp | 1 + src/widgets/fullscreentoggleaction.h | 7 ++- src/widgets/mainwindow.cpp | 58 +++++++++++++++++++ src/widgets/mainwindow.h | 12 ++++ src/widgets/messageboxhelper.cpp | 3 +- src/widgets/toolbarhelper.cpp | 23 ++++++-- 15 files changed, 143 insertions(+), 20 deletions(-) diff --git a/libs/vtextedit b/libs/vtextedit index 279cfe3b..c86f8bfb 160000 --- a/libs/vtextedit +++ b/libs/vtextedit @@ -1 +1 @@ -Subproject commit 279cfe3bced0b614915a6531a4bf01278c89532c +Subproject commit c86f8bfbf6140b67290ca9229f1145dba5bfc092 diff --git a/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp b/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp index e3a0eb99..85f3c68c 100644 --- a/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp +++ b/src/core/notebookconfigmgr/vxnotebookconfigmgr.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include @@ -803,8 +805,12 @@ QString VXNotebookConfigMgr::fetchNodeAttachmentFolder(const QString &p_nodePath bool VXNotebookConfigMgr::isBuiltInFile(const Node *p_node, const QString &p_name) const { + static const QString backupFileExtension = ConfigMgr::getInst().getEditorConfig().getBackupFileExtension().toLower(); + const auto name = p_name.toLower(); - if (name == c_nodeConfigName || name == "_vnote.json") { + if (name == c_nodeConfigName + || name == QStringLiteral("_vnote.json") + || name.endsWith(backupFileExtension)) { return true; } return BundleNotebookConfigMgr::isBuiltInFile(p_node, p_name); diff --git a/src/core/vnotex.cpp b/src/core/vnotex.cpp index 6a83f9db..cfaecd9e 100644 --- a/src/core/vnotex.cpp +++ b/src/core/vnotex.cpp @@ -98,9 +98,9 @@ BufferMgr &VNoteX::getBufferMgr() const return *m_bufferMgr; } -void VNoteX::showStatusMessage(const QString &p_message, int timeoutMilliseconds) +void VNoteX::showStatusMessage(const QString &p_message, int p_timeoutMilliseconds) { - emit statusMessageRequested(p_message, timeoutMilliseconds); + emit statusMessageRequested(p_message, p_timeoutMilliseconds); } void VNoteX::showStatusMessageShort(const QString &p_message) @@ -108,6 +108,11 @@ void VNoteX::showStatusMessageShort(const QString &p_message) showStatusMessage(p_message, 3000); } +void VNoteX::showTips(const QString &p_message, int p_timeoutMilliseconds) +{ + emit tipsRequested(p_message, p_timeoutMilliseconds); +} + ID VNoteX::getInstanceId() const { return m_instanceId; diff --git a/src/core/vnotex.h b/src/core/vnotex.h index 8e512471..aa870834 100644 --- a/src/core/vnotex.h +++ b/src/core/vnotex.h @@ -46,10 +46,12 @@ namespace vnotex ID getInstanceId() const; public slots: - void showStatusMessage(const QString &p_message, int timeoutMilliseconds = 0); + void showStatusMessage(const QString &p_message, int p_timeoutMilliseconds = 0); void showStatusMessageShort(const QString &p_message); + void showTips(const QString &p_message, int p_timeoutMilliseconds = 3000); + signals: // Requested to new a notebook. void newNotebookRequested(); @@ -77,7 +79,9 @@ namespace vnotex void newFolderRequested(); // Requested to show status message. - void statusMessageRequested(const QString &p_message, int timeoutMilliseconds); + void statusMessageRequested(const QString &p_message, int p_timeoutMilliseconds); + + void tipsRequested(const QString &p_message, int p_timeoutMilliseconds); // Requested to open @p_node. void openNodeRequested(Node *p_node, const QSharedPointer &p_paras); diff --git a/src/data/extra/themes/moonlight/interface.qss b/src/data/extra/themes/moonlight/interface.qss index 46d56ccf..6a32e096 100644 --- a/src/data/extra/themes/moonlight/interface.qss +++ b/src/data/extra/themes/moonlight/interface.qss @@ -406,6 +406,11 @@ vnotex--DragDropAreaIndicator QLabel { font-weight: bold; } +vnotex--MainWindow QLabel#MainWindowTipsLabel { + font-size: 18pt; + font-weight: bold; +} + /* QLineEdit */ QLineEdit { border: 1px solid @widgets#qlineedit#border; diff --git a/src/data/extra/themes/native/interface.qss b/src/data/extra/themes/native/interface.qss index 314752a5..21943b34 100644 --- a/src/data/extra/themes/native/interface.qss +++ b/src/data/extra/themes/native/interface.qss @@ -118,3 +118,8 @@ vnotex--DragDropAreaIndicator QLabel { font-size: 12pt; font-weight: bold; } + +vnotex--MainWindow QLabel#MainWindowTipsLabel { + font-size: 18pt; + font-weight: bold; +} diff --git a/src/data/extra/themes/pure/interface.qss b/src/data/extra/themes/pure/interface.qss index 46d56ccf..6a32e096 100644 --- a/src/data/extra/themes/pure/interface.qss +++ b/src/data/extra/themes/pure/interface.qss @@ -406,6 +406,11 @@ vnotex--DragDropAreaIndicator QLabel { font-weight: bold; } +vnotex--MainWindow QLabel#MainWindowTipsLabel { + font-size: 18pt; + font-weight: bold; +} + /* QLineEdit */ QLineEdit { border: 1px solid @widgets#qlineedit#border; diff --git a/src/widgets/dialogs/managenotebooksdialog.cpp b/src/widgets/dialogs/managenotebooksdialog.cpp index ae9aa5b8..fbf8c71f 100644 --- a/src/widgets/dialogs/managenotebooksdialog.cpp +++ b/src/widgets/dialogs/managenotebooksdialog.cpp @@ -19,6 +19,7 @@ #include "exception.h" #include "../propertydefs.h" #include "../listwidget.h" +#include using namespace vnotex; @@ -69,7 +70,7 @@ void ManageNotebooksDialog::setupUI() closeNotebook(m_notebookInfoWidget->getNotebook()); }); - m_deleteNotebookBtn = new QPushButton(tr("Delete"), infoWidget); + m_deleteNotebookBtn = new QPushButton(tr("Delete (DANGER)"), infoWidget); WidgetUtils::setPropertyDynamically(m_deleteNotebookBtn, PropertyDefs::s_dangerButton, true); btnLayout->addWidget(m_deleteNotebookBtn); connect(m_deleteNotebookBtn, &QPushButton::clicked, @@ -218,7 +219,7 @@ void ManageNotebooksDialog::closeNotebook(const Notebook *p_notebook) { Q_ASSERT(p_notebook); int ret = MessageBoxHelper::questionOkCancel(MessageBoxHelper::Question, - tr("Close notebook %1?") + tr("Close notebook (%1)?") .arg(p_notebook->getName()), tr("The notebook could be imported again later."), tr("Notebook location: %1").arg(p_notebook->getRootFolderAbsolutePath()), @@ -245,10 +246,12 @@ void ManageNotebooksDialog::removeNotebook(const Notebook *p_notebook) { Q_ASSERT(p_notebook); int ret = MessageBoxHelper::questionOkCancel(MessageBoxHelper::Warning, - tr("Delete notebook %1 from disk?").arg(p_notebook->getName()), - tr("It will delete all files belonging to this notebook from disk. " + tr("Delete notebook (%1) from disk?").arg(p_notebook->getName()), + tr("CALM DOWN! CALM DOWN! CALM DOWN! It will delete all files belonging to this notebook from disk. " "It is dangerous since it will bypass system's recycle bin!"), - tr("Notebook location: %1").arg(p_notebook->getRootFolderAbsolutePath()), + tr("Notebook location: %1\nUse the \"Close\" button if you just want to remove it from %2.") + .arg(p_notebook->getRootFolderAbsolutePath()) + .arg(ConfigMgr::c_appName), this); if (ret != QMessageBox::Ok) { return; diff --git a/src/widgets/editors/markdowneditor.cpp b/src/widgets/editors/markdowneditor.cpp index a48a05c1..0c3045de 100644 --- a/src/widgets/editors/markdowneditor.cpp +++ b/src/widgets/editors/markdowneditor.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include "previewhelper.h" #include "../outlineprovider.h" @@ -443,6 +444,9 @@ void MarkdownEditor::handleInsertFromMimeData(const QMimeData *p_source, bool *p QClipboard *clipboard = QApplication::clipboard(); if (!clipboard->property(c_clipboardPropertyMark).toBool()) { // Default paste. + // Give tips about the Rich Paste and Parse As Markdown And Paste features. + VNoteX::getInst().showStatusMessageShort( + tr("For advanced paste, try the \"Rich Paste\" and \"Parse To Markdown And Paste\" on the editor's context menu")); return; } else { clipboard->setProperty(c_clipboardPropertyMark, false); diff --git a/src/widgets/fullscreentoggleaction.cpp b/src/widgets/fullscreentoggleaction.cpp index 69099788..7ab356fa 100644 --- a/src/widgets/fullscreentoggleaction.cpp +++ b/src/widgets/fullscreentoggleaction.cpp @@ -25,6 +25,7 @@ FullScreenToggleAction::FullScreenToggleAction(QWidget *p_window, if ((p_checked && !m_window->isFullScreen()) || (!p_checked && m_window->isFullScreen())) { setWindowFullScreen(m_window, p_checked); + emit fullScreenToggled(p_checked); } }); } diff --git a/src/widgets/fullscreentoggleaction.h b/src/widgets/fullscreentoggleaction.h index 579a5152..b93ee5eb 100644 --- a/src/widgets/fullscreentoggleaction.h +++ b/src/widgets/fullscreentoggleaction.h @@ -13,13 +13,16 @@ namespace vnotex const QIcon &p_icon, QObject *p_parent = nullptr); - static void setWindowFullScreen(QWidget *p_window, bool p_set); + signals: + bool fullScreenToggled(bool p_fullScreen); protected: bool eventFilter(QObject *p_object, QEvent *p_event) Q_DECL_OVERRIDE; private: - QWidget *m_window; + static void setWindowFullScreen(QWidget *p_window, bool p_set); + + QWidget *m_window = nullptr; }; } // ns vnotex diff --git a/src/widgets/mainwindow.cpp b/src/widgets/mainwindow.cpp index 1d9b4b4e..2834f102 100644 --- a/src/widgets/mainwindow.cpp +++ b/src/widgets/mainwindow.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "toolbox.h" #include "notebookexplorer.h" @@ -86,6 +87,7 @@ void MainWindow::setupUI() setupDocks(); setupToolBar(); setupStatusBar(); + setupTipsArea(); setupSystemTray(); activateDock(m_docks[DockIndex::NavigationDock]); @@ -98,6 +100,24 @@ void MainWindow::setupStatusBar() statusBar(), &QStatusBar::showMessage); } +void MainWindow::setupTipsArea() +{ + m_tipsLabel = new QLabel(this); + m_tipsLabel->setObjectName("MainWindowTipsLabel"); + m_tipsLabel->hide(); + + m_tipsTimer = new QTimer(this); + m_tipsTimer->setSingleShot(true); + m_tipsTimer->setInterval(3000); + connect(m_tipsTimer, &QTimer::timeout, + this, [this]() { + setTipsAreaVisible(false); + }); + + connect(&VNoteX::getInst(), &VNoteX::tipsRequested, + this, &MainWindow::showTips); +} + void MainWindow::setupCentralWidget() { m_viewArea = new ViewArea(this); @@ -600,3 +620,41 @@ void MainWindow::exportNotes() this); dialog.exec(); } + +void MainWindow::showTips(const QString &p_message, int p_timeoutMilliseconds) +{ + m_tipsTimer->stop(); + + setTipsAreaVisible(false); + + if (p_message.isEmpty()) { + return; + } + + m_tipsLabel->setText(p_message); + setTipsAreaVisible(true); + + m_tipsTimer->start(p_timeoutMilliseconds); +} + +void MainWindow::setTipsAreaVisible(bool p_visible) +{ + if (p_visible) { + m_tipsLabel->adjustSize(); + int labelW = m_tipsLabel->width(); + int labelH = m_tipsLabel->height(); + int x = (width() - labelW) / 2; + int y = (height() - labelH) / 2; + if (x < 0) { + x = 0; + } + if (y < 0) { + y = 0; + } + + m_tipsLabel->move(x, y); + m_tipsLabel->show(); + } else { + m_tipsLabel->hide(); + } +} diff --git a/src/widgets/mainwindow.h b/src/widgets/mainwindow.h index 32eda91c..7b6f472d 100644 --- a/src/widgets/mainwindow.h +++ b/src/widgets/mainwindow.h @@ -9,6 +9,8 @@ class QDockWidget; class QSystemTrayIcon; +class QTimer; +class QLabel; namespace vnotex { @@ -74,6 +76,8 @@ namespace vnotex void exportNotes(); + void showTips(const QString &p_message, int p_timeoutMilliseconds); + private: // Index in m_docks. enum DockIndex @@ -100,6 +104,8 @@ namespace vnotex void setupStatusBar(); + void setupTipsArea(); + void saveStateAndGeometry(); void loadStateAndGeometry(); @@ -117,6 +123,8 @@ namespace vnotex void setupSystemTray(); + void setTipsAreaVisible(bool p_visible); + ToolBarHelper m_toolBarHelper; StatusBarHelper m_statusBarHelper; @@ -142,6 +150,10 @@ namespace vnotex Qt::WindowStates m_windowOldState = Qt::WindowMinimized; QSystemTrayIcon *m_trayIcon = nullptr; + + QLabel *m_tipsLabel = nullptr; + + QTimer *m_tipsTimer = nullptr; }; } // ns vnotex diff --git a/src/widgets/messageboxhelper.cpp b/src/widgets/messageboxhelper.cpp index f478d06c..20ed6aff 100644 --- a/src/widgets/messageboxhelper.cpp +++ b/src/widgets/messageboxhelper.cpp @@ -122,12 +122,13 @@ int MessageBoxHelper::questionOkCancel(MessageBoxHelper::Type p_type, const QString &p_detailedText, QWidget *p_parent) { + bool dangerous = p_type == Type::Warning || p_type == Type::Critical; int ret = showMessageBox(p_type, p_text, p_informationText, p_detailedText, QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Ok, + dangerous ? QMessageBox::Cancel : QMessageBox::Ok, p_parent); return ret; } diff --git a/src/widgets/toolbarhelper.cpp b/src/widgets/toolbarhelper.cpp index 2ef85d10..5c979d48 100644 --- a/src/widgets/toolbarhelper.cpp +++ b/src/widgets/toolbarhelper.cpp @@ -224,12 +224,23 @@ QToolBar *ToolBarHelper::setupSettingsToolBar(MainWindow *p_win, QToolBar *p_too }); btn->setDefaultAction(expandAct); - auto fullScreenAct = new FullScreenToggleAction(p_win, - generateIcon("fullscreen.svg"), - menu); - WidgetUtils::addActionShortcut(fullScreenAct, - coreConfig.getShortcut(CoreConfig::Shortcut::FullScreen)); - menu->addAction(fullScreenAct); + { + auto fullScreenAct = new FullScreenToggleAction(p_win, + generateIcon("fullscreen.svg"), + menu); + const auto shortcut = coreConfig.getShortcut(CoreConfig::Shortcut::FullScreen); + WidgetUtils::addActionShortcut(fullScreenAct, shortcut); + MainWindow::connect(fullScreenAct, &FullScreenToggleAction::fullScreenToggled, + p_win, [shortcut](bool p_fullScreen) { + if (p_fullScreen) { + VNoteX::getInst().showTips( + MainWindow::tr("Press %1 To Exit Full Screen").arg(shortcut)); + } else { + VNoteX::getInst().showTips(""); + } + }); + menu->addAction(fullScreenAct); + } auto stayOnTopAct = menu->addAction(generateIcon("stay_on_top.svg"), MainWindow::tr("Stay On Top"), p_win, &MainWindow::setStayOnTop);