diff --git a/.gitignore b/.gitignore index 50258e8d..bed905dd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.pro.user.* .ccls compile_commands.json +compile_commands.json.* compile_flags.txt .cache .tasks diff --git a/src/widgets/attachmentpopup.cpp b/src/widgets/attachmentpopup.cpp index edcc15a8..311a08b3 100644 --- a/src/widgets/attachmentpopup.cpp +++ b/src/widgets/attachmentpopup.cpp @@ -29,8 +29,7 @@ using namespace vnotex; AttachmentPopup::AttachmentPopup(QToolButton *p_btn, QWidget *p_parent) - : QMenu(p_parent), - m_button(p_btn) + : ButtonPopup(p_btn, p_parent) { setupUI(); @@ -68,7 +67,7 @@ void AttachmentPopup::setupUI() const auto destFolderPath = getDestFolderPath(); auto &sessionConfig = ConfigMgr::getInst().getSessionConfig(); - auto files = QFileDialog::getOpenFileNames(this, + auto files = QFileDialog::getOpenFileNames(nullptr, tr("Select Files As Attachments"), sessionConfig.getExternalMediaDefaultPath()); if (files.isEmpty()) { @@ -206,12 +205,7 @@ void AttachmentPopup::setupUI() widget->setMinimumSize(320, 384); - - auto act = new QWidgetAction(this); - // @act will own @p_widget. - act->setDefaultWidget(widget); - addAction(act); - + addWidget(widget); } QToolButton *AttachmentPopup::createButton() diff --git a/src/widgets/attachmentpopup.h b/src/widgets/attachmentpopup.h index 2a4d062f..e73205d2 100644 --- a/src/widgets/attachmentpopup.h +++ b/src/widgets/attachmentpopup.h @@ -1,16 +1,14 @@ #ifndef ATTACHMENTPOPUP_H #define ATTACHMENTPOPUP_H -#include - -class QToolButton; +#include "buttonpopup.h" namespace vnotex { class FileSystemViewer; class Buffer; - class AttachmentPopup : public QMenu + class AttachmentPopup : public ButtonPopup { Q_OBJECT public: @@ -43,9 +41,6 @@ namespace vnotex FileSystemViewer *m_viewer = nullptr; bool m_needUpdateAttachmentFolder = true; - - // Button for this menu. - QToolButton *m_button = nullptr; }; } diff --git a/src/widgets/buttonpopup.cpp b/src/widgets/buttonpopup.cpp index 44de5f3f..fba5304f 100644 --- a/src/widgets/buttonpopup.cpp +++ b/src/widgets/buttonpopup.cpp @@ -1,6 +1,6 @@ #include "buttonpopup.h" -#include +#include #include @@ -10,8 +10,6 @@ ButtonPopup::ButtonPopup(QToolButton *p_btn, QWidget *p_parent) : QMenu(p_parent), m_button(p_btn) { - setupUI(); - #if defined(Q_OS_MACOS) || defined(Q_OS_MAC) // Qt::Popup on macOS does not work well with input method. setWindowFlags(Qt::Tool | Qt::NoDropShadowWindowHint); @@ -19,16 +17,10 @@ ButtonPopup::ButtonPopup(QToolButton *p_btn, QWidget *p_parent) #endif } -void ButtonPopup::setupUI() +void ButtonPopup::addWidget(QWidget *p_widget) { - auto mainLayout = new QVBoxLayout(this); - WidgetUtils::setContentsMargins(mainLayout); -} - -void ButtonPopup::setCentralWidget(QWidget *p_widget) -{ - Q_ASSERT(p_widget); - auto mainLayout = layout(); - Q_ASSERT(mainLayout->count() == 0); - mainLayout->addWidget(p_widget); + auto act = new QWidgetAction(this); + // @act will own @p_widget. + act->setDefaultWidget(p_widget); + addAction(act); } diff --git a/src/widgets/buttonpopup.h b/src/widgets/buttonpopup.h index ce29ae96..a8d22120 100644 --- a/src/widgets/buttonpopup.h +++ b/src/widgets/buttonpopup.h @@ -15,10 +15,7 @@ namespace vnotex ButtonPopup(QToolButton *p_btn, QWidget *p_parent = nullptr); protected: - void setCentralWidget(QWidget *p_widget); - - private: - void setupUI(); + void addWidget(QWidget *p_widget); // Button for this menu. QToolButton *m_button = nullptr; diff --git a/src/widgets/outlinepopup.cpp b/src/widgets/outlinepopup.cpp index 31fedbf0..d4c1cdd7 100644 --- a/src/widgets/outlinepopup.cpp +++ b/src/widgets/outlinepopup.cpp @@ -1,8 +1,6 @@ #include "outlinepopup.h" -#include #include -#include #include #include @@ -11,8 +9,7 @@ using namespace vnotex; OutlinePopup::OutlinePopup(QToolButton *p_btn, QWidget *p_parent) - : QMenu(p_parent), - m_button(p_btn) + : ButtonPopup(p_btn, p_parent) { setupUI(); @@ -26,13 +23,7 @@ void OutlinePopup::setupUI() { m_viewer = new OutlineViewer(tr("Outline"), this); m_viewer->setMinimumSize(320, 384); - - auto act = new QWidgetAction(this); - // @act will own @p_widget. - act->setDefaultWidget(m_viewer); - addAction(act); - - + addWidget(m_viewer); } void OutlinePopup::setOutlineProvider(const QSharedPointer &p_provider) @@ -42,7 +33,7 @@ void OutlinePopup::setOutlineProvider(const QSharedPointer &p_p void OutlinePopup::showEvent(QShowEvent* p_event) { - QMenu::showEvent(p_event); + ButtonPopup::showEvent(p_event); // Move it to be right-aligned. if (m_button->isVisible()) { diff --git a/src/widgets/outlinepopup.h b/src/widgets/outlinepopup.h index 437e803d..1b519239 100644 --- a/src/widgets/outlinepopup.h +++ b/src/widgets/outlinepopup.h @@ -1,7 +1,8 @@ #ifndef OUTLINEPOPUP_H #define OUTLINEPOPUP_H -#include +#include "buttonpopup.h" + #include class QToolButton; @@ -11,7 +12,7 @@ namespace vnotex class OutlineProvider; class OutlineViewer; - class OutlinePopup : public QMenu + class OutlinePopup : public ButtonPopup { Q_OBJECT public: @@ -27,9 +28,6 @@ namespace vnotex // Managed by QObject. OutlineViewer *m_viewer = nullptr; - - // Button with this menu. - QToolButton *m_button = nullptr; }; } diff --git a/src/widgets/tagpopup.cpp b/src/widgets/tagpopup.cpp index 89d25817..9f9b03fb 100644 --- a/src/widgets/tagpopup.cpp +++ b/src/widgets/tagpopup.cpp @@ -1,9 +1,5 @@ #include "tagpopup.h" -#include -#include -#include - #include #include @@ -31,14 +27,8 @@ TagPopup::TagPopup(QToolButton *p_btn, QWidget *p_parent) void TagPopup::setupUI() { m_tagViewer = new TagViewer(true, this); - //setCentralWidget(m_tagViewer); - m_tagViewer->setMinimumSize(256, 320); - - auto act = new QWidgetAction(this); - // @act will own @p_widget. - act->setDefaultWidget(m_tagViewer); - addAction(act); + addWidget(m_tagViewer); } void TagPopup::setBuffer(Buffer *p_buffer) diff --git a/src/widgets/wordcountpopup.cpp b/src/widgets/wordcountpopup.cpp index e9d0b7b5..0d6e3a67 100644 --- a/src/widgets/wordcountpopup.cpp +++ b/src/widgets/wordcountpopup.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include @@ -72,10 +71,5 @@ void WordCountPopup::updateCount(const ViewWindow::WordCountInfo &p_info) void WordCountPopup::setupUI() { m_panel = new WordCountPanel(this); - - - auto act = new QWidgetAction(this); - // @act will own @p_widget. - act->setDefaultWidget(m_panel); - addAction(act); + addWidget(m_panel); }