qpaperedithandler.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef QPAPEREDITHANDLER_H
  2. #define QPAPEREDITHANDLER_H
  3. #include <QWidget>
  4. #include "ui_qpaperedithandler.h"
  5. #include<QPalette>
  6. #include <QPainter>
  7. #include <QMouseEvent>
  8. #include <QStyledItemDelegate>
  9. #include <vector>
  10. using namespace std;
  11. struct ItemInfo
  12. {
  13. int id;
  14. QString origion_imgpath;
  15. string img_oldpath;
  16. QImage* pPreviewImg;
  17. QListWidgetItem* pItem;
  18. };
  19. Q_DECLARE_METATYPE(ItemInfo)
  20. class MyItemPainter : public QStyledItemDelegate
  21. {
  22. Q_OBJECT
  23. public:
  24. MyItemPainter(QWidget *parent);
  25. ~MyItemPainter();
  26. private:
  27. QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const;
  28. void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
  29. };
  30. class QPaperEditHandler : public QWidget
  31. {
  32. Q_OBJECT
  33. enum MouseStatus
  34. {
  35. Mouse_Normal,
  36. Mouse_Drag,
  37. Mouse_Pen,
  38. Mouse_Line,
  39. Mouse_Eraser,
  40. Mouse_Cut,
  41. Mouse_Cuting,
  42. Mouse_Locate,
  43. };
  44. public:
  45. QPaperEditHandler(QWidget *parent = 0);
  46. ~QPaperEditHandler();
  47. void SetOrigionImg(QString path, string oldpath);
  48. void SetImgList(vector<QString> imglist,vector<string> oldpathlist);
  49. void SetShowSchema(bool bshow);//是否显示模板按钮
  50. vector<string> GetEditedImgs();
  51. void ShowMovie(bool bshow=true);
  52. void SetViewMode(bool view = true);//查看模式,不处理异常
  53. bool m_bIsEdited;//图片是否修改过
  54. void SetPaper(int paper_id);
  55. void SetTitleInfo(string info);
  56. void SetHandlerKaohaoyichang(bool bViewMode = true);
  57. int paper_id;
  58. Q_SIGNALS:
  59. void switchToShibieYichang();
  60. void PaperChange(QString);
  61. void sig_SetViewMode(bool);
  62. private:
  63. void ClickDrag();
  64. void ClickRoomin();
  65. void ClickRoomout();
  66. void ClickRotate90();
  67. void ClickRotateN90();
  68. void ClickUndo();
  69. void ClickRedo();
  70. void ClickPen(QObject* sender);
  71. void ClickEraser(QObject* sender);
  72. void ClickLine(QObject* sender);
  73. void ClickCut();
  74. void ClickLocate(QObject* sender);
  75. void ClickMore();
  76. void ClickPre();
  77. void ClickPreView();
  78. void ClickNext();
  79. void ClickRestore();
  80. void ClickSwitchDrag();//切换到拖移模式
  81. void ClickCur();//考号冲突 点击当前页
  82. void ClickConflict(int index);//考号冲突 点击重复1 2 3 4 5
  83. void ClickSwitchPage();
  84. void paintEvent(QPaintEvent *);
  85. void mouseMoveEvent(QMouseEvent *event);
  86. void mousePressEvent(QMouseEvent *event);
  87. void mouseReleaseEvent(QMouseEvent *event);
  88. void wheelEvent(QWheelEvent *event);
  89. virtual void resizeEvent(QResizeEvent *event);
  90. bool eventFilter(QObject *watched, QEvent *event);
  91. QPoint PointSwitchToImg(QPoint sPoint);
  92. QRect RectSwitchImg(QRect sRect);
  93. QPoint PointSwitchToClient(QPoint sPoint);
  94. QRect RectSwitchToClient(QRect sRect);
  95. void Reset();
  96. void LoadPreview();
  97. private slots:
  98. void ClickButton();
  99. public slots :
  100. void ClickPreViewLable(int id);
  101. void ListItemChange(QListWidgetItem*);
  102. void mergeImg();
  103. void ClickCutOK();
  104. void ClickCutDel();
  105. void ClickCutSave();
  106. void ClickCutCopy();
  107. private:
  108. Ui::QPaperEditHandler ui;
  109. QPoint startPoint;
  110. QPoint endPoint;
  111. bool ispressed;
  112. MouseStatus mousestatus;
  113. QPixmap bgmap;
  114. QImage bgimage;
  115. float room;
  116. QString origionImgpath;
  117. string oldimgpath;
  118. QPoint offset;
  119. int eraserW;
  120. int eraserH;
  121. int locateW;
  122. int locateH;
  123. QPen pen;
  124. int penW;
  125. QColor penColor;
  126. int lineW;
  127. QColor lineColor;
  128. vector<ItemInfo> iteminfos;
  129. vector<QString> origionImglist;
  130. vector<string> oldImgpathlist;
  131. MyItemPainter itemPainter;
  132. bool bLoadedPreview;//延迟加载预览图
  133. bool m_bShowMovie;
  134. int NextItem();
  135. int preItem();
  136. void HideButtons();
  137. bool bFirstResize;//第一次显示图片时完整显示,作个标记
  138. vector<int> m_conflict_paper;
  139. int m_curpage;//当前操作的是哪一页 对于考号冲突的情况 当切换到其它试卷时,保存当前页号
  140. string m_titleInfo;
  141. };
  142. #endif // QPAPEREDITHANDLER_H