mainwindow.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include "framelessmainwindow/framelessmainwindowimpl.h"
  4. #include <QSharedPointer>
  5. #include <QBitArray>
  6. #include <QSet>
  7. #include "dockwidgethelper.h"
  8. class QDockWidget;
  9. class QSystemTrayIcon;
  10. class QTimer;
  11. class QLabel;
  12. class QTextEdit;
  13. namespace vnotex
  14. {
  15. class ToolBox;
  16. class NotebookExplorer;
  17. class TagExplorer;
  18. class ViewArea;
  19. class Event;
  20. class OutlineViewer;
  21. class LocationList;
  22. class SearchPanel;
  23. class SnippetPanel;
  24. class HistoryPanel;
  25. class ExportDialog;
  26. class ConsoleViewer;
  27. enum { RESTART_EXIT_CODE = 1000 };
  28. class MainWindow : public FramelessMainWindowImpl
  29. {
  30. Q_OBJECT
  31. public:
  32. friend class DockWidgetHelper;
  33. explicit MainWindow(QWidget *p_parent = nullptr);
  34. ~MainWindow();
  35. MainWindow(const MainWindow &) = delete;
  36. void operator=(const MainWindow &) = delete;
  37. void kickOffOnStart(const QStringList &p_paths);
  38. void resetStateAndGeometry();
  39. const QVector<QDockWidget *> &getDocks() const;
  40. ViewArea *getViewArea() const;
  41. NotebookExplorer *getNotebookExplorer() const;
  42. void setContentAreaExpanded(bool p_expanded);
  43. // Should be called after MainWindow is shown.
  44. bool isContentAreaExpanded() const;
  45. void focusViewArea();
  46. void setStayOnTop(bool p_enabled);
  47. void restart();
  48. void showMainWindow();
  49. void quitApp();
  50. void openFiles(const QStringList &p_files);
  51. LocationList *getLocationList() const;
  52. void setLocationListVisible(bool p_visible);
  53. void toggleLocationListVisible();
  54. void updateDockWidgetTabBar();
  55. signals:
  56. void mainWindowStarted();
  57. // @m_response of @p_event: true to continue the close, false to stop the close.
  58. void mainWindowClosed(const QSharedPointer<Event> &p_event);
  59. // No user interaction is available.
  60. void mainWindowClosedOnQuit();
  61. void layoutChanged();
  62. protected:
  63. void closeEvent(QCloseEvent *p_event) Q_DECL_OVERRIDE;
  64. void changeEvent(QEvent *p_event) Q_DECL_OVERRIDE;
  65. private slots:
  66. void closeOnQuit();
  67. void exportNotes();
  68. void showTips(const QString &p_message, int p_timeoutMilliseconds);
  69. private:
  70. void setupUI();
  71. void setupCentralWidget();
  72. void setupOutlineViewer();
  73. void setupConsoleViewer();
  74. void setupSearchPanel();
  75. void setupLocationList();
  76. void setupSnippetPanel();
  77. void setupHistoryPanel();
  78. void setupNotebookExplorer();
  79. void setupTagExplorer();
  80. void setupDocks();
  81. void setupStatusBar();
  82. void setupTipsArea();
  83. void createTipsArea();
  84. void saveStateAndGeometry();
  85. void loadStateAndGeometry(bool p_stateOnly = false);
  86. // Used to test widget in development.
  87. void demoWidget();
  88. QString getViewAreaTitle() const;
  89. void setupToolBar();
  90. void setupShortcuts();
  91. void setupSystemTray();
  92. void setTipsAreaVisible(bool p_visible);
  93. void setupSpellCheck();
  94. void checkForUpdates();
  95. void checkNotebooksFailedToLoad();
  96. void loadWidgetsData();
  97. DockWidgetHelper m_dockWidgetHelper;
  98. ToolBox *m_navigationToolBox = nullptr;
  99. NotebookExplorer *m_notebookExplorer = nullptr;
  100. TagExplorer *m_tagExplorer = nullptr;
  101. ViewArea *m_viewArea = nullptr;
  102. QWidget *m_viewAreaStatusWidget = nullptr;
  103. OutlineViewer *m_outlineViewer = nullptr;
  104. ConsoleViewer *m_consoleViewer = nullptr;
  105. LocationList *m_locationList = nullptr;
  106. SearchPanel *m_searchPanel = nullptr;
  107. SnippetPanel *m_snippetPanel = nullptr;
  108. HistoryPanel *m_historyPanel = nullptr;
  109. ExportDialog *m_exportDialog = nullptr;
  110. QSystemTrayIcon *m_trayIcon = nullptr;
  111. QLabel *m_tipsLabel = nullptr;
  112. QTimer *m_tipsTimer = nullptr;
  113. bool m_layoutReset = false;
  114. // -1: do not request to quit;
  115. // 0 and above: exit code.
  116. int m_requestQuit = -1;
  117. Qt::WindowStates m_windowOldState = Qt::WindowMinimized;
  118. QStringList m_visibleDocksBeforeExpand;
  119. };
  120. } // ns vnotex
  121. #endif // MAINWINDOW_H