Browse Source

UniversalEntry: add ? to show help information

Le Tan 7 years ago
parent
commit
764c0acfe5
7 changed files with 129 additions and 7 deletions
  1. 0 3
      src/dialog/vupdater.cpp
  2. 13 2
      src/iuniversalentry.h
  3. 4 2
      src/src.pro
  4. 77 0
      src/vhelpue.cpp
  5. 31 0
      src/vhelpue.h
  6. 2 0
      src/vmainwindow.cpp
  7. 2 0
      src/vuniversalentry.cpp

+ 0 - 3
src/dialog/vupdater.cpp

@@ -64,10 +64,7 @@ void VUpdater::setupUI()
     m_proLabel->hide();
     m_proBar->hide();
 
-    m_descriptionWV->setMaximumSize(600, 400);
-
     setLayout(mainLayout);
-    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
     setWindowTitle(tr("VNote Update"));
 }
 

+ 13 - 2
src/iuniversalentry.h

@@ -27,6 +27,10 @@ public:
     {
     }
 
+    virtual ~IUniversalEntry()
+    {
+    }
+
     // Return a description string for the entry.
     virtual QString description(int p_id) const = 0;
 
@@ -52,7 +56,11 @@ public:
     }
 
     // Select next item.
-    virtual void selectNextItem(int p_id, bool p_forward) = 0;
+    virtual void selectNextItem(int p_id, bool p_forward)
+    {
+        Q_UNUSED(p_id);
+        Q_UNUSED(p_forward);
+    }
 
     // Select parent item.
     virtual void selectParentItem(int p_id)
@@ -61,7 +69,10 @@ public:
     }
 
     // Activate current item.
-    virtual void activate(int p_id) = 0;
+    virtual void activate(int p_id)
+    {
+        Q_UNUSED(p_id);
+    }
 
     // Ask the UE to stop asynchronously.
     virtual void askToStop(int p_id)

+ 4 - 2
src/src.pro

@@ -122,7 +122,8 @@ SOURCES += main.cpp\
     vlistwidgetdoublerows.cpp \
     vdoublerowitemwidget.cpp \
     vsearchue.cpp \
-    voutlineue.cpp
+    voutlineue.cpp \
+    vhelpue.cpp
 
 HEADERS  += vmainwindow.h \
     vdirectorytree.h \
@@ -235,7 +236,8 @@ HEADERS  += vmainwindow.h \
     vlistwidgetdoublerows.h \
     vdoublerowitemwidget.h \
     vsearchue.h \
-    voutlineue.h
+    voutlineue.h \
+    vhelpue.h
 
 RESOURCES += \
     vnote.qrc \

+ 77 - 0
src/vhelpue.cpp

@@ -0,0 +1,77 @@
+#include "vhelpue.h"
+
+#include "vlistwidget.h"
+
+
+VHelpUE::VHelpUE(QObject *p_parent)
+    : IUniversalEntry(p_parent),
+      m_listWidget(NULL)
+{
+}
+
+void VHelpUE::init()
+{
+    if (m_initialized) {
+        return;
+    }
+
+    m_initialized = true;
+
+    m_listWidget = new VListWidget(m_widgetParent);
+    m_listWidget->setFitContent(true);
+}
+
+QString VHelpUE::description(int p_id) const
+{
+    Q_UNUSED(p_id);
+    return tr("View help information about Universal Entry");
+}
+
+QWidget *VHelpUE::widget(int p_id)
+{
+    Q_UNUSED(p_id);
+
+    init();
+
+    return m_listWidget;
+}
+
+void VHelpUE::processCommand(int p_id, const QString &p_cmd)
+{
+    Q_UNUSED(p_id);
+    Q_UNUSED(p_cmd);
+
+    init();
+
+    if (initListWidget()) {
+        m_listWidget->updateGeometry();
+        emit widgetUpdated();
+    }
+
+    emit stateUpdated(State::Success);
+}
+
+void VHelpUE::clear(int p_id)
+{
+    Q_UNUSED(p_id);
+    m_listWidget->clearAll();
+}
+
+bool VHelpUE::initListWidget()
+{
+    if (m_listWidget->count() == 0) {
+        m_listWidget->addItem(tr("Esc/Ctrl+[: Hide Universal Entry"));
+        m_listWidget->addItem(tr("Ctrl+U: Clear the command input"));
+        m_listWidget->addItem(tr("Ctrl+E: Clear the command input except the entry key"));
+        m_listWidget->addItem(tr("Ctrl+J: Select next item"));
+        m_listWidget->addItem(tr("Ctrl+K: Select previous item"));
+        m_listWidget->addItem(tr("Enter: Activate current item"));
+        m_listWidget->addItem(tr("Ctrl+R: Select current item's parent item"));
+        m_listWidget->addItem(tr("Ctrl+T: Expand/Collapse current item"));
+        m_listWidget->addItem(tr("Ctrl+S: Sort the items"));
+
+        return true;
+    }
+
+    return false;
+}

+ 31 - 0
src/vhelpue.h

@@ -0,0 +1,31 @@
+#ifndef VHELPUE_H
+#define VHELPUE_H
+
+#include "iuniversalentry.h"
+
+class VListWidget;
+
+class VHelpUE : public IUniversalEntry
+{
+    Q_OBJECT
+public:
+    explicit VHelpUE(QObject *p_parent = nullptr);
+
+    QString description(int p_id) const Q_DECL_OVERRIDE;
+
+    QWidget *widget(int p_id) Q_DECL_OVERRIDE;
+
+    void processCommand(int p_id, const QString &p_cmd) Q_DECL_OVERRIDE;
+
+    void clear(int p_id) Q_DECL_OVERRIDE;
+
+protected:
+    void init() Q_DECL_OVERRIDE;
+
+private:
+    bool initListWidget();
+
+    VListWidget *m_listWidget;
+};
+
+#endif // VHELPUE_H

+ 2 - 0
src/vmainwindow.cpp

@@ -42,6 +42,7 @@
 #include "vuniversalentry.h"
 #include "vsearchue.h"
 #include "voutlineue.h"
+#include "vhelpue.h"
 
 extern VConfigManager *g_config;
 
@@ -3213,4 +3214,5 @@ void VMainWindow::initUniversalEntry()
     m_ue->registerEntry('y', new VOutlineUE(this), 0);
     m_ue->registerEntry('h', searchUE, VSearchUE::Path_FolderNote_AllNotebook);
     m_ue->registerEntry('n', searchUE, VSearchUE::Path_FolderNote_CurrentNotebook);
+    m_ue->registerEntry('?', new VHelpUE(this), 0);
 }

+ 2 - 0
src/vuniversalentry.cpp

@@ -353,6 +353,8 @@ void VUniversalEntry::keyPressEvent(QKeyEvent *p_event)
             return;
         }
 
+        break;
+
     case Qt::Key_S:
         if (VUtils::isControlModifierForVim(modifiers)) {
             // Ctrl+S to sort the items.