vattachmentlist.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef VATTACHMENTLIST_H
  2. #define VATTACHMENTLIST_H
  3. #include <QWidget>
  4. #include <QVector>
  5. #include <QStringList>
  6. #include "vnotefile.h"
  7. #include "vbuttonwithwidget.h"
  8. #include "lineeditdelegate.h"
  9. class QPushButton;
  10. class QListWidget;
  11. class QListWidgetItem;
  12. class QLabel;
  13. class VNoteFile;
  14. class QAction;
  15. class VAttachmentList : public QWidget, public VButtonPopupWidget
  16. {
  17. Q_OBJECT
  18. public:
  19. explicit VAttachmentList(QWidget *p_parent = 0);
  20. // Need to call updateContent() to update the list.
  21. void setFile(VNoteFile *p_file);
  22. // Update attachment info of m_file.
  23. void updateContent();
  24. bool isAcceptDrops() const Q_DECL_OVERRIDE;
  25. bool handleDragEnterEvent(QDragEnterEvent *p_event) Q_DECL_OVERRIDE;
  26. bool handleDropEvent(QDropEvent *p_event) Q_DECL_OVERRIDE;
  27. void handleAboutToShow() Q_DECL_OVERRIDE;
  28. protected:
  29. void keyPressEvent(QKeyEvent *p_event) Q_DECL_OVERRIDE;
  30. void showEvent(QShowEvent *p_event) Q_DECL_OVERRIDE;
  31. private slots:
  32. void addAttachment();
  33. void handleContextMenuRequested(QPoint p_pos);
  34. void handleItemActivated(QListWidgetItem *p_item);
  35. void deleteSelectedItems();
  36. void sortItems();
  37. void handleListItemCommitData(QWidget *p_itemEdit);
  38. private:
  39. void setupUI();
  40. void initActions();
  41. void fillAttachmentList(const QVector<VAttachment> &p_attachments);
  42. void addAttachments(const QStringList &p_files);
  43. // Update the state of VButtonWithWidget.
  44. void updateButtonState() const;
  45. // Check if there are attachments that do not exist in disk.
  46. void checkAttachments();
  47. QPushButton *m_addBtn;
  48. QPushButton *m_clearBtn;
  49. QPushButton *m_locateBtn;
  50. QLabel *m_numLabel;
  51. LineEditDelegate m_listDelegate;
  52. QListWidget *m_attachmentList;
  53. QAction *m_openAct;
  54. QAction *m_deleteAct;
  55. QAction *m_sortAct;
  56. VNoteFile *m_file;
  57. };
  58. #endif // VATTACHMENTLIST_H