outlinepopup.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "outlinepopup.h"
  2. #include <QVBoxLayout>
  3. #include <QToolButton>
  4. #include <core/global.h>
  5. #include <utils/widgetutils.h>
  6. #include "outlineviewer.h"
  7. using namespace vnotex;
  8. OutlinePopup::OutlinePopup(QToolButton *p_btn, QWidget *p_parent)
  9. : QMenu(p_parent),
  10. m_button(p_btn)
  11. {
  12. setupUI();
  13. connect(this, &QMenu::aboutToShow,
  14. this, [this]() {
  15. m_viewer->setFocus();
  16. });
  17. }
  18. void OutlinePopup::setupUI()
  19. {
  20. auto mainLayout = new QVBoxLayout(this);
  21. WidgetUtils::setContentsMargins(mainLayout);
  22. m_viewer = new OutlineViewer(tr("Outline"), this);
  23. mainLayout->addWidget(m_viewer);
  24. setMinimumSize(320, 384);
  25. }
  26. void OutlinePopup::setOutlineProvider(const QSharedPointer<OutlineProvider> &p_provider)
  27. {
  28. m_viewer->setOutlineProvider(p_provider);
  29. }
  30. void OutlinePopup::showEvent(QShowEvent* p_event)
  31. {
  32. QMenu::showEvent(p_event);
  33. const auto p = pos();
  34. const auto btnRect = m_button->geometry();
  35. // Move it to right-aligned.
  36. move(p.x() + btnRect.width() - geometry().width(), p.y());
  37. }