mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +08:00
refine tags dialog
This commit is contained in:
parent
5848b5e737
commit
1802b00525
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
|
||||||
#include <notebook/node.h>
|
#include <notebook/node.h>
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ void ViewTagsDialog::setupUI()
|
|||||||
m_nodeNameLabel = new QLabel(mainWidget);
|
m_nodeNameLabel = new QLabel(mainWidget);
|
||||||
mainLayout->addRow(tr("Name:"), m_nodeNameLabel);
|
mainLayout->addRow(tr("Name:"), m_nodeNameLabel);
|
||||||
|
|
||||||
m_tagViewer = new TagViewer(mainWidget);
|
m_tagViewer = new TagViewer(false, mainWidget);
|
||||||
mainLayout->addRow(tr("Tags:"), m_tagViewer);
|
mainLayout->addRow(tr("Tags:"), m_tagViewer);
|
||||||
|
|
||||||
setDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
setDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||||
@ -56,3 +57,13 @@ void ViewTagsDialog::setNode(Node *p_node)
|
|||||||
m_nodeNameLabel->setText(m_node->getName());
|
m_nodeNameLabel->setText(m_node->getName());
|
||||||
m_tagViewer->setNode(m_node);
|
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);
|
||||||
|
}
|
||||||
|
@ -19,6 +19,8 @@ namespace vnotex
|
|||||||
protected:
|
protected:
|
||||||
void acceptedButtonClicked() Q_DECL_OVERRIDE;
|
void acceptedButtonClicked() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupUI();
|
void setupUI();
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ void TagPopup::setupUI()
|
|||||||
auto mainLayout = new QVBoxLayout(this);
|
auto mainLayout = new QVBoxLayout(this);
|
||||||
WidgetUtils::setContentsMargins(mainLayout);
|
WidgetUtils::setContentsMargins(mainLayout);
|
||||||
|
|
||||||
m_tagViewer = new TagViewer(this);
|
m_tagViewer = new TagViewer(true, this);
|
||||||
mainLayout->addWidget(m_tagViewer);
|
mainLayout->addWidget(m_tagViewer);
|
||||||
|
|
||||||
setMinimumSize(256, 320);
|
setMinimumSize(256, 320);
|
||||||
|
@ -30,8 +30,9 @@ QIcon TagViewer::s_tagIcon;
|
|||||||
|
|
||||||
QIcon TagViewer::s_selectedTagIcon;
|
QIcon TagViewer::s_selectedTagIcon;
|
||||||
|
|
||||||
TagViewer::TagViewer(QWidget *p_parent)
|
TagViewer::TagViewer(bool p_isPopup, QWidget *p_parent)
|
||||||
: QFrame(p_parent)
|
: QFrame(p_parent),
|
||||||
|
m_isPopup(p_isPopup)
|
||||||
{
|
{
|
||||||
initIcons();
|
initIcons();
|
||||||
|
|
||||||
@ -55,7 +56,9 @@ void TagViewer::setupUI()
|
|||||||
m_searchLineEdit->setValidator(tagNameValidator);
|
m_searchLineEdit->setValidator(tagNameValidator);
|
||||||
|
|
||||||
setFocusProxy(m_searchLineEdit);
|
setFocusProxy(m_searchLineEdit);
|
||||||
m_searchLineEdit->installEventFilter(this);
|
if (m_isPopup) {
|
||||||
|
m_searchLineEdit->installEventFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
m_tagList = new ListWidget(this);
|
m_tagList = new ListWidget(this);
|
||||||
m_tagList->setWrapping(true);
|
m_tagList->setWrapping(true);
|
||||||
@ -67,12 +70,15 @@ void TagViewer::setupUI()
|
|||||||
this, &TagViewer::toggleItemTag);
|
this, &TagViewer::toggleItemTag);
|
||||||
mainLayout->addWidget(m_tagList);
|
mainLayout->addWidget(m_tagList);
|
||||||
|
|
||||||
m_tagList->installEventFilter(this);
|
if (m_isPopup) {
|
||||||
|
m_tagList->installEventFilter(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TagViewer::eventFilter(QObject *p_obj, QEvent *p_event)
|
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) {
|
&& p_event->type() == QEvent::KeyPress) {
|
||||||
auto keyEve = static_cast<QKeyEvent *>(p_event);
|
auto keyEve = static_cast<QKeyEvent *>(p_event);
|
||||||
const auto key = keyEve->key();
|
const auto key = keyEve->key();
|
||||||
@ -86,6 +92,7 @@ bool TagViewer::eventFilter(QObject *p_obj, QEvent *p_event)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QFrame::eventFilter(p_obj, p_event);
|
return QFrame::eventFilter(p_obj, p_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ namespace vnotex
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit TagViewer(QWidget *p_parent = nullptr);
|
TagViewer(bool p_isPopup, QWidget *p_parent = nullptr);
|
||||||
|
|
||||||
void setNode(Node *p_node);
|
void setNode(Node *p_node);
|
||||||
|
|
||||||
@ -61,6 +61,8 @@ namespace vnotex
|
|||||||
|
|
||||||
static void initIcons();
|
static void initIcons();
|
||||||
|
|
||||||
|
bool m_isPopup = false;
|
||||||
|
|
||||||
// View the tags of @m_node.
|
// View the tags of @m_node.
|
||||||
Node *m_node = nullptr;
|
Node *m_node = nullptr;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user