rcglobal.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #pragma once
  2. #include <QString>
  3. #include <QVector>
  4. #include <QTreeWidgetItem>
  5. #define CMP_CODE_NOEQUAL
  6. enum RC_DIRECTION
  7. {
  8. RC_LEFT = 0,
  9. RC_RIGHT,
  10. };
  11. enum RC_CMP_RESULT
  12. {
  13. RC_RESULT_EQUAL=0,
  14. RC_RESULT_NOEQUAL,
  15. };
  16. enum RC_FILE_TYPE
  17. {
  18. RC_FILE = 1000,
  19. RC_DIR,
  20. RC_PAD_FILE
  21. };
  22. enum RC_ITEM_STATUS
  23. {
  24. RC_COLLAPSED = 0,
  25. RC_EXPANDED,
  26. };
  27. enum BLOCKSTATUS {
  28. UNKNOWN_BLOCK = 0,
  29. EQUAL_BLOCK = 1,
  30. UNEQUAL_BLOCK,
  31. PAD_BLOCK,
  32. //EMPTY_BLOCK,
  33. LAST_PAD_EMPTY_BLOCK, // 最后一个用于对齐的空行
  34. TEMP_INSERT_BLOCK
  35. };
  36. /* 是放置在block中的userState,-1是保留行,因为-1是默认没有时的值,标识新插入行 */
  37. enum RC_LINE_FORM
  38. {
  39. PAD_LINE = -2,//对齐行
  40. //-1没有使用QTextBlock::userState()的默认值
  41. UNKNOWN_LINE =0, //未知就是没有换行符号。当做没有
  42. UNIX_LINE,
  43. DOS_LINE,
  44. MAC_LINE,
  45. };
  46. typedef struct equalLineInfo_ {
  47. int index;//相等行序号,左右值
  48. int leftLineNums;
  49. int rightLineNums;
  50. }EqualLineInfo;
  51. typedef struct noequalblock_ {
  52. int startBlockNums; //开始的块号。左右两边都是一样的
  53. int blockLens;//左右长度。理论上二者是相等的,故只需要一个
  54. bool isDeleted; //是否已经被同步。即被删除过了,下次跳过这个
  55. int type; //
  56. noequalblock_()
  57. {
  58. type = UNKNOWN_BLOCK;
  59. }
  60. noequalblock_(int start, int lens)
  61. {
  62. startBlockNums = start;
  63. blockLens = lens;
  64. isDeleted = false;
  65. type = UNKNOWN_BLOCK;
  66. }
  67. bool operator==(const noequalblock_& other)
  68. {
  69. return (startBlockNums == other.startBlockNums);
  70. }
  71. }NoEqualBlock;
  72. enum CODE_ID {
  73. UNKOWN = -2,//其实应该是ANSI中的非GBK编码。暂时不考虑其它国家语言编码,则直接按照ASCII进行字节处理
  74. ANSI = -1,
  75. UTF8_NOBOM,//如果是这种,其实需要确定到底椒UTF8 还是ANSI
  76. UTF8_BOM, //UTF8_WITH BOM
  77. UNICODE_LE,
  78. UNICODE_BE,
  79. GBK,
  80. //增加国际化的几种语言
  81. EUC_JP,//日本鬼子
  82. Shift_JIS,//日文另外一种
  83. EUC_KR,//韩国
  84. KOI8_R,//俄罗斯
  85. TSCII,//泰国
  86. TIS_620,//泰文
  87. CODE_END //最后一个标志,在UI上是显示一个UNKNOWN,这是一个特殊
  88. };
  89. /*作用:这个类主要统计左右不同的块,给界面上的“上一部分”和“下一部分”来使用。
  90. */
  91. typedef struct BlocksInfo_ {
  92. public:
  93. BlocksInfo_()
  94. {
  95. startLine = 0;
  96. endLine = 0;
  97. }
  98. BlocksInfo_(bool equal_, int startLine_, int endLine_, int actualNums_)
  99. {
  100. equal = equal_;
  101. actualNums = actualNums_;
  102. startLine = startLine_;
  103. endLine = endLine_;
  104. }
  105. public:
  106. bool equal;//相同true,不同false
  107. int actualNums;//实际数据行数
  108. int startLine; //起点块的行号码
  109. int endLine;//终点块,不包含此块
  110. }BlocksInfo;
  111. //每一小段的字符,主要是将相等和不等的字符段分开
  112. typedef struct SectionNode_ {
  113. bool equal; //是否相等
  114. QString text;
  115. //QByteArray text;
  116. }SectionNode;
  117. //每一小段的二进制字节,主要是将相等和不等的二进制字符段分开
  118. typedef struct BinSectionNode_ {
  119. bool equal; //是否相等
  120. QVector<uchar> bytes;
  121. }BinSectionNode;
  122. typedef struct BinUnequalPos_ {
  123. int start;
  124. int end;
  125. }BinUnequalPos;
  126. //每一行的数据结构。每一行包含许多相等或不相等的小段
  127. typedef struct LineNode_ {
  128. int lineNums;//行的号码
  129. bool totalEqual;//是否完全相等
  130. QVector<SectionNode> lineText;
  131. LineNode_()
  132. {
  133. totalEqual = false;
  134. }
  135. void clear()
  136. {
  137. totalEqual = false;
  138. lineText.clear();
  139. }
  140. }LineNode;
  141. extern RC_LINE_FORM getLineEndType(QString line);
  142. extern RC_LINE_FORM getLineEndType(const LineNode& lines);
  143. #ifdef Q_OS_UNIX
  144. extern QString loadFontFromFile(QString path,int code=0);
  145. #endif
  146. typedef struct ModifyRecords_ {
  147. int position;//当前修改位置
  148. int modificationType;//1:增加 2 删除
  149. int length;//修改的长度
  150. int linesAdded;//增加多少行。正为增加,负数为减少
  151. bool isInPaste;//是否在拷贝中,在的话前面一个删除不能做处理,要等到后续添加消息
  152. ModifyRecords_(int position_, int type_, int length_, int linesAdded_) :position(position_), modificationType(type_), length(length_), linesAdded(linesAdded_)
  153. {
  154. isInPaste = false;
  155. }
  156. }ModifyRecords;
  157. typedef struct fileAttriNode_ {
  158. QString relativePath;//不带/而且不带最外层目录路径
  159. int type; //file or dirs,pad
  160. //int index; //用于表示先后顺序,用于向前向后的排序查找
  161. QTreeWidgetItem* parent; //父节点
  162. QTreeWidgetItem* selfItem; //如果是目录,则标记自己的节点
  163. fileAttriNode_()
  164. {
  165. parent = nullptr;
  166. }
  167. fileAttriNode_(QString relativePath_)
  168. {
  169. relativePath = relativePath_;
  170. }
  171. bool operator==(const fileAttriNode_& other) const
  172. {
  173. return (relativePath.compare(other.relativePath) == 0);
  174. }
  175. }fileAttriNode;
  176. struct WalkFileInfo {
  177. int direction;
  178. QTreeWidgetItem* root;
  179. QString path;
  180. WalkFileInfo(int dire_, QTreeWidgetItem* root_, QString path_) :direction(dire_), root(root_), path(path_)
  181. {
  182. }
  183. };
  184. const int MARGIN_NONE = 0;
  185. const int MARGIN_SYNC_BT = 1;
  186. const int MARGIN_SYNC_BT_BIT_MASK = 0x2;
  187. const int MARGIN_VER_LINE = 2;
  188. const int MARGIN_VER_LINE_BIT_MASK = 0x4;
  189. const int MARGIN_LINE_NUM = 3;
  190. enum WORK_STATUS
  191. {
  192. FREE_STATUS = 0,
  193. CMP_WORKING
  194. };
  195. #define OPEN_UNDO_REDO 1
  196. #ifdef OPEN_UNDO_REDO
  197. class BlockUserData;
  198. struct OperatorInfo {
  199. int startLineNums; //开始行号
  200. int lineLens;//左右长度。理论上二者是相等的,故只需要一个
  201. int type;
  202. QList<int> lineLength; //每一行的长度
  203. QList<char*> lineContents;// 每一行的内容
  204. QList<BlockUserData*> lineExternInfo; //每一行的额外信息
  205. NoEqualBlock noEqualBlockInfo;
  206. int noEqualindex;
  207. };
  208. enum OperRecordStatus {
  209. RC_OPER_SYNC = 1,//同步导致
  210. RC_OPER_EDIT,//编辑导致
  211. };
  212. const int Item_RelativePath = Qt::ToolTipRole;
  213. const int Item_Index = Qt::UserRole + 1;
  214. const int DIR_ITEM_MAXSIZE_FILE = Qt::UserRole + 2;
  215. #endif