Przeglądaj źródła

refine tags dialog

Le Tan 4 lat temu
rodzic
commit
1802b00525

+ 12 - 1
src/widgets/dialogs/viewtagsdialog.cpp

@@ -2,6 +2,7 @@
 
 #include <QFormLayout>
 #include <QLabel>
+#include <QKeyEvent>
 
 #include <notebook/node.h>
 
@@ -30,7 +31,7 @@ void ViewTagsDialog::setupUI()
     m_nodeNameLabel = new QLabel(mainWidget);
     mainLayout->addRow(tr("Name:"), m_nodeNameLabel);
 
-    m_tagViewer = new TagViewer(mainWidget);
+    m_tagViewer = new TagViewer(false, mainWidget);
     mainLayout->addRow(tr("Tags:"), m_tagViewer);
 
     setDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
@@ -56,3 +57,13 @@ void ViewTagsDialog::setNode(Node *p_node)
     m_nodeNameLabel->setText(m_node->getName());
     m_tagViewer->setNode(m_node);
 }
+
+void ViewTagsDialog::keyPressEvent(QKeyEvent *p_event)
+{
+    if (p_event->key() == Qt::Key_Enter || p_event->key() == Qt::Key_Return) {
+        // Prevent it from closing the dialog.
+        return;
+    }
+
+    Dialog::keyPressEvent(p_event);
+}

+ 2 - 0
src/widgets/dialogs/viewtagsdialog.h

@@ -19,6 +19,8 @@ namespace vnotex
     protected:
         void acceptedButtonClicked() Q_DECL_OVERRIDE;
 
+        void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;
+
     private:
         void setupUI();
 

+ 1 - 1
src/widgets/tagpopup.cpp

@@ -33,7 +33,7 @@ void TagPopup::setupUI()
     auto mainLayout = new QVBoxLayout(this);
     WidgetUtils::setContentsMargins(mainLayout);
 
-    m_tagViewer = new TagViewer(this);
+    m_tagViewer = new TagViewer(true, this);
     mainLayout->addWidget(m_tagViewer);
 
     setMinimumSize(256, 320);

+ 12 - 5
src/widgets/tagviewer.cpp

@@ -30,8 +30,9 @@ QIcon TagViewer::s_tagIcon;
 
 QIcon TagViewer::s_selectedTagIcon;
 
-TagViewer::TagViewer(QWidget *p_parent)
-    : QFrame(p_parent)
+TagViewer::TagViewer(bool p_isPopup, QWidget *p_parent)
+    : QFrame(p_parent),
+      m_isPopup(p_isPopup)
 {
     initIcons();
 
@@ -55,7 +56,9 @@ void TagViewer::setupUI()
     m_searchLineEdit->setValidator(tagNameValidator);
 
     setFocusProxy(m_searchLineEdit);
-    m_searchLineEdit->installEventFilter(this);
+    if (m_isPopup) {
+        m_searchLineEdit->installEventFilter(this);
+    }
 
     m_tagList = new ListWidget(this);
     m_tagList->setWrapping(true);
@@ -67,12 +70,15 @@ void TagViewer::setupUI()
             this, &TagViewer::toggleItemTag);
     mainLayout->addWidget(m_tagList);
 
-    m_tagList->installEventFilter(this);
+    if (m_isPopup) {
+        m_tagList->installEventFilter(this);
+    }
 }
 
 bool TagViewer::eventFilter(QObject *p_obj, QEvent *p_event)
 {
-    if ((p_obj == m_searchLineEdit || p_obj == m_tagList)
+    if (m_isPopup
+        && (p_obj == m_searchLineEdit || p_obj == m_tagList)
         && p_event->type() == QEvent::KeyPress) {
         auto keyEve = static_cast<QKeyEvent *>(p_event);
         const auto key = keyEve->key();
@@ -86,6 +92,7 @@ bool TagViewer::eventFilter(QObject *p_obj, QEvent *p_event)
             return true;
         }
     }
+
     return QFrame::eventFilter(p_obj, p_event);
 }
 

+ 3 - 1
src/widgets/tagviewer.h

@@ -23,7 +23,7 @@ namespace vnotex
     {
         Q_OBJECT
     public:
-        explicit TagViewer(QWidget *p_parent = nullptr);
+        TagViewer(bool p_isPopup, QWidget *p_parent = nullptr);
 
         void setNode(Node *p_node);
 
@@ -61,6 +61,8 @@ namespace vnotex
 
         static void initIcons();
 
+        bool m_isPopup = false;
+
         // View the tags of @m_node.
         Node *m_node = nullptr;