vnotebookselector.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef VNOTEBOOKSELECTOR_H
  2. #define VNOTEBOOKSELECTOR_H
  3. #include <QComboBox>
  4. #include <QVector>
  5. #include <QString>
  6. #include "vnavigationmode.h"
  7. class VNotebook;
  8. class QListWidget;
  9. class QAction;
  10. class QListWidgetItem;
  11. class QLabel;
  12. class VNotebookSelector : public QComboBox, public VNavigationMode
  13. {
  14. Q_OBJECT
  15. public:
  16. explicit VNotebookSelector(QWidget *p_parent = 0);
  17. // Update Combox from m_notebooks.
  18. void update();
  19. // Select notebook @p_notebook.
  20. bool locateNotebook(const VNotebook *p_notebook);
  21. // Add notebook on popup if no notebooks currently.
  22. void showPopup() Q_DECL_OVERRIDE;
  23. VNotebook *currentNotebook() const;
  24. // Implementations for VNavigationMode.
  25. void registerNavigation(QChar p_majorKey) Q_DECL_OVERRIDE;
  26. void showNavigation() Q_DECL_OVERRIDE;
  27. void hideNavigation() Q_DECL_OVERRIDE;
  28. bool handleKeyNavigation(int p_key, bool &p_succeed) Q_DECL_OVERRIDE;
  29. signals:
  30. void curNotebookChanged(VNotebook *p_notebook);
  31. // Info of current notebook was changed.
  32. void notebookUpdated(const VNotebook *p_notebook);
  33. // Emit after creating a new notebook.
  34. void notebookCreated(const QString &p_name, bool p_import);
  35. public slots:
  36. // Popup a dialog to prompt user to create a notebook.
  37. bool newNotebook();
  38. protected:
  39. bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
  40. private slots:
  41. // Act to currentIndexChanged() signal if m_muted is false.
  42. void handleCurIndexChanged(int p_index);
  43. void popupListContextMenuRequested(QPoint p_pos);
  44. // Delete currently selected notebook.
  45. void deleteNotebook();
  46. // View and edit notebook information of selected notebook.
  47. void editNotebookInfo();
  48. private:
  49. void initActions();
  50. // Update Combox from m_notebooks.
  51. void updateComboBox();
  52. // Return the item index of @p_notebook.
  53. int itemIndexOfNotebook(const VNotebook *p_notebook) const;
  54. // If @p_import is true, we will use the existing config file.
  55. // If @p_imageFolder is empty, we will use the global one.
  56. // If @p_attachmentFolder is empty, we will use the global one.
  57. void createNotebook(const QString &p_name, const QString &p_path,
  58. bool p_import, const QString &p_imageFolder,
  59. const QString &p_attachmentFolder);
  60. void deleteNotebook(VNotebook *p_notebook, bool p_deleteFiles);
  61. // Add an item corresponding to @p_notebook to combo box.
  62. void addNotebookItem(const VNotebook *p_notebook);
  63. void fillItem(QListWidgetItem *p_item, const VNotebook *p_notebook) const;
  64. // Insert "Add Notebook" item to combo box.
  65. void insertAddNotebookItem();
  66. // Set current item corresponding to @p_notebook.
  67. void setCurrentItemToNotebook(const VNotebook *p_notebook);
  68. // Get VNotebook from @p_itemIdx, the index of m_listWidget.
  69. VNotebook *getNotebook(int p_itemIdx) const;
  70. VNotebook *getNotebook(const QListWidgetItem *p_item) const;
  71. void resizeListWidgetToContent();
  72. bool handlePopupKeyPress(QKeyEvent *p_event);
  73. QVector<VNotebook *> &m_notebooks;
  74. QListWidget *m_listWidget;
  75. // Used to restore after clicking Add Notebook item.
  76. int m_lastValidIndex;
  77. // Whether it is muted from currentIndexChanged().
  78. bool m_muted;
  79. // Actions
  80. QAction *m_deleteNotebookAct;
  81. QAction *m_notebookInfoAct;
  82. QAction *m_openLocationAct;
  83. QAction *m_recycleBinAct;
  84. QAction *m_emptyRecycleBinAct;
  85. QLabel *m_naviLabel;
  86. };
  87. #endif // VNOTEBOOKSELECTOR_H