diff --git a/src/main.cpp b/src/main.cpp index be2e00ab..8d866316 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,10 @@ #include "vconfigmanager.h" VConfigManager vconfig; -static QFile g_logFile; + +#if defined(QT_NO_DEBUG) +QFile g_logFile; +#endif void VLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg) { diff --git a/src/vcaptain.cpp b/src/vcaptain.cpp index 192ad53e..620ef851 100644 --- a/src/vcaptain.cpp +++ b/src/vcaptain.cpp @@ -13,6 +13,10 @@ // 3s pending time after the leader keys. const int c_pendingTime = 3 * 1000; +#if defined(QT_NO_DEBUG) +extern QFile g_logFile; +#endif + VCaptain::VCaptain(VMainWindow *p_parent) : QWidget(p_parent), m_mainWindow(p_parent), m_mode(VCaptain::Normal), m_widgetBeforeCaptain(NULL), m_nextMajorKey('a'), m_ignoreFocusChange(false) @@ -303,6 +307,15 @@ bool VCaptain::handleKeyPress(int p_key, Qt::KeyboardModifiers p_modifiers) break; } +#if defined(QT_NO_DEBUG) + case Qt::Key_Comma: + { + // Flush g_logFile. + g_logFile.flush(); + break; + } +#endif + default: // Not implemented yet. Just exit Captain mode. break; diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 24d41c17..a02e70a1 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -25,6 +25,10 @@ extern VConfigManager vconfig; VNote *g_vnote; +#if defined(QT_NO_DEBUG) +extern QFile g_logFile; +#endif + VMainWindow::VMainWindow(QWidget *parent) : QMainWindow(parent), m_onePanel(false) { @@ -288,6 +292,16 @@ void VMainWindow::initHelpMenu() QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->setToolTipsVisible(true); +#if defined(QT_NO_DEBUG) + QAction *logAct = new QAction(tr("View &Log"), this); + logAct->setToolTip(tr("View VNote's debug log (%1)").arg(vconfig.getLogFilePath())); + connect(logAct, &QAction::triggered, + this, [](){ + QUrl url = QUrl::fromLocalFile(vconfig.getLogFilePath()); + QDesktopServices::openUrl(url); + }); +#endif + QAction *shortcutAct = new QAction(tr("&Shortcuts Help"), this); shortcutAct->setToolTip(tr("View information about shortcut keys")); connect(shortcutAct, &QAction::triggered, @@ -303,6 +317,10 @@ void VMainWindow::initHelpMenu() connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt); +#if defined(QT_NO_DEBUG) + helpMenu->addAction(logAct); +#endif + helpMenu->addAction(shortcutAct); helpMenu->addAction(aboutQtAct); helpMenu->addAction(aboutAct);