WindowAppBlockComment.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. #include "WindowAppBlockComment.h"
  2. #include "DialogEditComment.h"
  3. #include "Pou.h"
  4. #include "WindowAppPouScene.h"
  5. #include "VPCommand.h"
  6. WindowAppBlockComment::WindowAppBlockComment(
  7. TOOL* pNewTool,
  8. POU* Pou,
  9. bool bShowOnly,
  10. QGraphicsObject* parent
  11. )
  12. : WindowAppBlockBase(pNewTool, Pou, bShowOnly, parent)
  13. , isResizing(false)
  14. {
  15. // 设置默认的注释文字
  16. if (this->m_toolInfo->strComment.isEmpty())
  17. {
  18. this->m_toolInfo->strComment = COMM_DEFAULT_TEXT;
  19. }
  20. // 初始化UI风格
  21. this->initStyle();
  22. // 设置注释控件的默认宽度
  23. blockRect.setRect(
  24. 0,
  25. 0,
  26. COMM_BASIC_WIDTH,
  27. COMM_BASIC_HEIGHT
  28. );
  29. // 更新矩形区域的尺寸
  30. this->updateRect();
  31. reDirection = ResizeNone;
  32. // 2022-10-3,初始化右键菜单
  33. createContextMenu();
  34. }
  35. WindowAppBlockComment::~WindowAppBlockComment()
  36. {
  37. }
  38. /// <summary>
  39. /// 初始化UI风格
  40. /// </summary>
  41. void WindowAppBlockComment::initStyle()
  42. {
  43. // 允许移动
  44. setFlag(QGraphicsItem::ItemIsMovable);
  45. // 允许选中
  46. setFlag(QGraphicsItem::ItemIsSelectable);
  47. // 允许获得焦点
  48. setFlag(QGraphicsItem::ItemIsFocusable);
  49. // 允许发送尺寸变更通知
  50. setFlag(QGraphicsItem::ItemSendsGeometryChanges);
  51. // 响应鼠标悬停事件(重要,否则QGraphicsItem默认是不响应鼠标悬停事件的)
  52. this->setAcceptHoverEvents(true);
  53. }
  54. /// <summary>
  55. /// 绘制注释功能块
  56. /// </summary>
  57. /// <param name="painter"></param>
  58. /// <param name="option"></param>
  59. /// <param name="widget"></param>
  60. void WindowAppBlockComment::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
  61. {
  62. Q_UNUSED(option);
  63. Q_UNUSED(widget);
  64. painter->setRenderHints(QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing);
  65. painter->save();
  66. // 绘制边框
  67. this->drawFrame(painter);
  68. // 绘制文字
  69. this->drawContent(painter);
  70. painter->restore();
  71. }
  72. ////////////////////////////////////////////////////////////////
  73. // 初始化功能块的右键菜单
  74. void WindowAppBlockComment::createContextMenu()
  75. {
  76. WindowAppBlockBase::createContextMenu();
  77. connect(deleteAction, &QAction::triggered, this, &WindowAppBlockComment::onMenuDelete);
  78. contextMenu = new QMenu();
  79. contextMenu->addAction(deleteAction);
  80. }
  81. /// <summary>
  82. /// 绘制边框
  83. /// </summary>
  84. /// <param name="painter"></param>
  85. void WindowAppBlockComment::drawFrame(QPainter* painter)
  86. {
  87. // 设置画笔
  88. if (!this->isSelected())
  89. {
  90. painter->setPen(QPen(COLOR_FRAME_COMM, PEN_WIDTH_FRAME));
  91. }
  92. else
  93. {
  94. painter->setPen(QPen(COLOR_FRAME_COMM, PEN_WIDTH_FRAME_BOLD));
  95. }
  96. // 绘制边框
  97. painter->drawRoundedRect(blockRect, 0, 0);
  98. //// 设置画笔
  99. //painter->setPen(QPen(COLOR_COMM_FRAME, PEN_WIDTH_FRAME));
  100. // 设置透明
  101. //painter->setBrush(Qt::transparent);
  102. }
  103. /// <summary>
  104. /// 刷新全部(包括文字和尺寸)
  105. /// </summary>
  106. void WindowAppBlockComment::updateAll()
  107. {
  108. // 更新矩形区域的尺寸
  109. this->updateRect();
  110. // 刷新界面
  111. this->update();
  112. }
  113. /// <summary>
  114. /// 更新矩形区域的尺寸
  115. /// </summary>
  116. void WindowAppBlockComment::updateRect()
  117. {
  118. // 根据文字内容计算实际的文字矩形区域(包括换行)
  119. QRectF textRect = QFontMetrics(FONT_COMM).boundingRect(QRect(), Qt::TextWordWrap, m_toolInfo->strComment);
  120. // 根据文字矩形区域调整外边框
  121. double xFix = textRect.width() - blockRect.width();
  122. double yFix = textRect.height() - blockRect.height();
  123. blockRect.setRight(blockRect.right() + xFix + COMM_SIDE_X_SPACING * 2.0);
  124. blockRect.setBottom(blockRect.bottom() + yFix - COMM_SIDE_Y_SPACING * 2.0);
  125. // 如果调整完后的区域小于最小区域,则调成到最小区域
  126. if (blockRect.width() < COMM_BASIC_WIDTH)
  127. {
  128. blockRect.setRight(blockRect.left() + COMM_BASIC_WIDTH);
  129. }
  130. if (blockRect.height() < COMM_BASIC_HEIGHT)
  131. {
  132. blockRect.setBottom(blockRect.top() + COMM_BASIC_HEIGHT);
  133. }
  134. }
  135. /// <summary>
  136. /// 响应双击事件,弹出编辑内容对话框
  137. /// </summary>
  138. /// <param name="event"></param>
  139. void WindowAppBlockComment::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
  140. {
  141. // 只有鼠标左键才响应
  142. if (event->button() == Qt::LeftButton)
  143. {
  144. DialogEditComment dialogComm(m_toolInfo->strComment);
  145. // 接收用户输入的注释内容
  146. if (dialogComm.exec() == QDialog::Accepted)
  147. {
  148. this->m_toolInfo->strComment = dialogComm.m_strComment;
  149. // 如果用户输入了空的注释内容,直接删除本注释控件
  150. if (this->m_toolInfo->strComment.isEmpty())
  151. {
  152. qDebug() << "WindowAppBlockComment::mouseDoubleClickEvent - m_strComment is empty, delete myslef.";
  153. // 向scene发送通知
  154. emit this->emptyContent(this);
  155. }
  156. // 刷新整个界面
  157. this->updateAll();
  158. }
  159. }
  160. }
  161. /// <summary>
  162. /// 绘制文字(文字左上角对齐)
  163. /// </summary>
  164. /// <param name="painter"></param>
  165. void WindowAppBlockComment::drawContent(QPainter* painter)
  166. {
  167. // 设置画笔
  168. painter->setPen(QPen(COLOR_FRAME_COMM, PEN_WIDTH_FRAME));
  169. // 绘制文字
  170. painter->setFont(FONT_COMM);
  171. // 文字区域比当前四边略微缩小一点
  172. QRectF textRect = blockRect.adjusted(
  173. COMM_SIDE_X_SPACING,
  174. COMM_SIDE_Y_SPACING,
  175. - COMM_SIDE_Y_SPACING,
  176. - COMM_SIDE_Y_SPACING
  177. );
  178. //QTextOption toption(Qt::AlignLeft | Qt::AlignTop);
  179. //toption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
  180. painter->drawText(textRect, Qt::TextWordWrap, m_toolInfo->strComment);
  181. }
  182. /// <summary>
  183. /// 计算区域边界
  184. /// </summary>
  185. /// <returns></returns>
  186. QRectF WindowAppBlockComment::boundingRect() const
  187. {
  188. return blockRect;
  189. }
  190. /// <summary>
  191. /// 菜单 - Delete
  192. /// </summary>
  193. void WindowAppBlockComment::onMenuDelete()
  194. {
  195. //// 由Scene统一删除
  196. //m_pPou->parentScene()->delToolItem(this);
  197. // 生成删除指令,调用Undo体系进行删除
  198. PouToolDelCommand* toolDelCommand = new PouToolDelCommand(
  199. (WindowAppPouScene*)this->scene(),
  200. this->m_toolInfo,
  201. this->scenePos()
  202. );
  203. ((WindowAppPouScene*)scene())->m_CommandManager.executeCommand(toolDelCommand);
  204. }
  205. //======================================================================
  206. //
  207. // 注释控件缩放相关代码
  208. //
  209. //======================================================================
  210. /// <summary>
  211. /// 鼠标悬浮事件(用于显示拉伸用的鼠标)
  212. /// </summary>
  213. /// <param name="event"></param>
  214. void WindowAppBlockComment::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
  215. {
  216. // qDebug() << "WindowAppBlockComment::hoverMoveEvent";
  217. // 如果控件处于选中状态,则根据鼠标位置显示拉伸鼠标
  218. if (this->isSelected())
  219. {
  220. QPointF mousePoint = event->pos();
  221. QPointF mouseHandler = QPointF(10, 10);
  222. QPointF topLeft = blockRect.topLeft();
  223. QPointF topRight = blockRect.topRight();
  224. QPointF bottomLeft = blockRect.bottomLeft();
  225. QPointF bottomRight = blockRect.bottomRight();
  226. // resize top
  227. if (mousePoint.x() >= (topLeft.x() + mouseHandler.x()) &&
  228. mousePoint.x() <= (topRight.x() - mouseHandler.x()) &&
  229. mousePoint.y() >= (topLeft.y() - mouseHandler.y()) &&
  230. mousePoint.y() <= (topLeft.y() + mouseHandler.y()))
  231. {
  232. setCursor(Qt::SizeVerCursor);
  233. }
  234. // resize bottom
  235. else if (mousePoint.x() >= (bottomLeft.x() + mouseHandler.x()) &&
  236. mousePoint.x() <= (bottomRight.x() - mouseHandler.x()) &&
  237. mousePoint.y() >= (bottomLeft.y() - mouseHandler.y()) &&
  238. mousePoint.y() <= (bottomLeft.y() + mouseHandler.y()))
  239. {
  240. setCursor(Qt::SizeVerCursor);
  241. }
  242. // resize left
  243. else if (mousePoint.x() >= (topLeft.x() - mouseHandler.x()) &&
  244. mousePoint.x() <= (topLeft.x() + mouseHandler.x()) &&
  245. mousePoint.y() >= (topLeft.y() + mouseHandler.y()) &&
  246. mousePoint.y() <= (bottomLeft.y() - mouseHandler.y()))
  247. {
  248. setCursor(Qt::SizeHorCursor);
  249. }
  250. // resize right
  251. else if (mousePoint.x() >= (topRight.x() - mouseHandler.x()) &&
  252. mousePoint.x() <= (topRight.x() + mouseHandler.x()) &&
  253. mousePoint.y() >= (topRight.y() + mouseHandler.y()) &&
  254. mousePoint.y() <= (bottomRight.y() - mouseHandler.y()))
  255. {
  256. setCursor(Qt::SizeHorCursor);
  257. }
  258. // resize top left
  259. else if (mousePoint.x() <= (topLeft.x() + mouseHandler.x()) &&
  260. mousePoint.x() >= (topLeft.x() - mouseHandler.x()) &&
  261. mousePoint.y() <= (topLeft.y() + mouseHandler.y()) &&
  262. mousePoint.y() >= (topLeft.y() - mouseHandler.y()))
  263. {
  264. setCursor(Qt::SizeFDiagCursor);
  265. }
  266. // resize bottom right
  267. else if (mousePoint.x() <= (bottomRight.x() + mouseHandler.x()) &&
  268. mousePoint.x() >= (bottomRight.x() - mouseHandler.x()) &&
  269. mousePoint.y() <= (bottomRight.y() + mouseHandler.y()) &&
  270. mousePoint.y() >= (bottomRight.y() - mouseHandler.y()))
  271. {
  272. setCursor(Qt::SizeFDiagCursor);
  273. }
  274. // resize bottom left
  275. else if (mousePoint.x() <= (bottomLeft.x() + mouseHandler.x()) &&
  276. mousePoint.x() >= (bottomLeft.x() - mouseHandler.x()) &&
  277. mousePoint.y() >= (bottomLeft.y() - mouseHandler.y()) &&
  278. mousePoint.y() <= (bottomLeft.y() + mouseHandler.y()))
  279. {
  280. setCursor(Qt::SizeBDiagCursor);
  281. }
  282. // resize top right
  283. else if (mousePoint.x() <= (topRight.x() + mouseHandler.x()) &&
  284. mousePoint.x() >= (topRight.x() - mouseHandler.x()) &&
  285. mousePoint.y() >= (topRight.y() - mouseHandler.y()) &&
  286. mousePoint.y() <= (topRight.y() + mouseHandler.y()))
  287. {
  288. setCursor(Qt::SizeBDiagCursor);
  289. }
  290. else
  291. {
  292. setCursor(Qt::ArrowCursor);
  293. }
  294. }
  295. QGraphicsObject::hoverMoveEvent(event);
  296. }
  297. /// <summary>
  298. /// 鼠标移动事件(用于拉伸控件)
  299. /// </summary>
  300. /// <param name="event"></param>
  301. void WindowAppBlockComment::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
  302. {
  303. if (!isSelected())
  304. {
  305. return;
  306. }
  307. QPointF mousePoint = event->pos();
  308. // 如果处于拉伸状态,则调整控件的矩形区域
  309. if (this->isResizing)
  310. {
  311. if (reDirection & ResizeLeft)
  312. {
  313. blockRect.setLeft(mousePoint.x());
  314. }
  315. if (reDirection & ResizeRight)
  316. {
  317. blockRect.setRight(mousePoint.x());
  318. }
  319. if (reDirection & ResizeTop)
  320. {
  321. blockRect.setTop(mousePoint.y());
  322. }
  323. if (reDirection & ResizeBottom)
  324. {
  325. blockRect.setBottom(mousePoint.y());
  326. }
  327. scene()->update();
  328. return;
  329. }
  330. QGraphicsItem::mouseMoveEvent(event);
  331. }
  332. /// <summary>
  333. /// 鼠标按下事件(用于触发控件拉伸)
  334. /// </summary>
  335. /// <param name="event"></param>
  336. void WindowAppBlockComment::mousePressEvent(QGraphicsSceneMouseEvent* event)
  337. {
  338. QPointF mousePoint = event->pos();
  339. QPointF mouseHandler = QPointF(5, 5);
  340. QPointF topLeft = blockRect.topLeft();
  341. QPointF topRight = blockRect.topRight();
  342. QPointF bottomLeft = blockRect.bottomLeft();
  343. QPointF bottomRight = blockRect.bottomRight();
  344. reDirection = ResizeNone;
  345. this->isResizing = false;
  346. // resize top
  347. if (mousePoint.x() >= (topLeft.x() + 0) &&
  348. mousePoint.x() <= (topRight.x() - 0) &&
  349. mousePoint.y() >= (topLeft.y() - mouseHandler.y()) &&
  350. mousePoint.y() <= (topLeft.y() + mouseHandler.y()))
  351. {
  352. reDirection |= ResizeTop;
  353. this->isResizing = true;
  354. }
  355. // resize bottom
  356. if (mousePoint.x() >= (bottomLeft.x() + 0) &&
  357. mousePoint.x() <= (bottomRight.x() - 0) &&
  358. mousePoint.y() >= (bottomLeft.y() - mouseHandler.y()) &&
  359. mousePoint.y() <= (bottomLeft.y() + mouseHandler.y()))
  360. {
  361. reDirection |= ResizeBottom;
  362. this->isResizing = true;
  363. }
  364. // resize left
  365. if (mousePoint.x() >= (topLeft.x() - mouseHandler.x()) &&
  366. mousePoint.x() <= (topLeft.x() + mouseHandler.x()) &&
  367. mousePoint.y() >= (topLeft.y() + 0) &&
  368. mousePoint.y() <= (bottomLeft.y() - 0))
  369. {
  370. reDirection |= ResizeLeft;
  371. this->isResizing = true;
  372. }
  373. // resize right
  374. if (mousePoint.x() >= (topRight.x() - mouseHandler.x()) &&
  375. mousePoint.x() <= (topRight.x() + mouseHandler.x()) &&
  376. mousePoint.y() >= (topRight.y() + 0) &&
  377. mousePoint.y() <= (bottomRight.y() - 0))
  378. {
  379. reDirection |= ResizeRight;
  380. this->isResizing = true;
  381. }
  382. // 根据移动方向设置不同的鼠标指针
  383. switch (reDirection)
  384. {
  385. case ResizeRight:
  386. case ResizeLeft:
  387. setCursor(Qt::SizeHorCursor);
  388. break;
  389. case ResizeBottom:
  390. case ResizeTop:
  391. setCursor(Qt::SizeVerCursor);
  392. break;
  393. case ResizeRight | ResizeBottom:
  394. case ResizeLeft | ResizeTop:
  395. setCursor(Qt::SizeFDiagCursor);
  396. break;
  397. case ResizeLeft | ResizeBottom:
  398. case ResizeRight | ResizeTop:
  399. setCursor(Qt::SizeBDiagCursor);
  400. break;
  401. default:
  402. setCursor(Qt::ArrowCursor);
  403. break;
  404. }
  405. // 2022-10-4,调用一下基类的mousePressEvent,执行对应的功能(多选,位置保存等等)
  406. WindowAppBlockBase::mousePressEvent(event);
  407. QGraphicsObject::mousePressEvent(event);
  408. }
  409. /// <summary>
  410. /// 鼠标释放事件(用于鼠标还原以及接收拉伸状态)
  411. /// </summary>
  412. /// <param name="event"></param>
  413. void WindowAppBlockComment::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
  414. {
  415. // 还原鼠标
  416. setCursor(Qt::ArrowCursor);
  417. // 结束拉伸状态
  418. this->isResizing = false;
  419. reDirection = ResizeNone;
  420. // 2022-10-4,调用一下基类的mouseReleaseEvent,执行对应的功能
  421. WindowAppBlockBase::mouseReleaseEvent(event);
  422. QGraphicsObject::mouseReleaseEvent(event);
  423. }
  424. //======================================================================
  425. //
  426. // 注释控件缩放相关代码 - 结束
  427. //
  428. //======================================================================
  429. //====================================================
  430. //
  431. // Del
  432. //
  433. //====================================================
  434. ///// <summary>
  435. ///// 键盘按下时(回车键结束编辑)
  436. ///// </summary>
  437. ///// <param name="event"></param>
  438. //void WindowAppBlockComment::keyPressEvent(QKeyEvent* event)
  439. //{
  440. // // 点击回车失去焦点,编辑完成,后续给FocusOutEvent处理
  441. // if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
  442. // {
  443. // clearFocus();
  444. //
  445. // return;
  446. // }
  447. //
  448. // QGraphicsTextItem::keyPressEvent(event);
  449. //}
  450. //void WindowAppBlockComment::keyReleaseEvent(QKeyEvent* event)
  451. //{
  452. // // 编译完毕后,更新一下外边界
  453. // this->updateRect();
  454. // this->update();
  455. //
  456. // QGraphicsTextItem::keyReleaseEvent(event);
  457. //}
  458. //QVariant WindowAppBlockComment::itemChange(GraphicsItemChange change,
  459. // const QVariant& value)
  460. //{
  461. // if (change == QGraphicsItem::ItemSelectedHasChanged)
  462. // {
  463. // emit selectedChange(this);
  464. // }
  465. //
  466. // return value;
  467. //}
  468. ///// <summary>
  469. ///// 在文本内容变更时触发,自动更新边距
  470. ///// </summary>
  471. //void WindowAppBlockComment::onContentsChanged()
  472. //{
  473. // // 有内容变更时,更新一下外边界
  474. // this->updateRect();
  475. // this->update();
  476. //}
  477. //
  478. //
  479. ///// <summary>
  480. ///// 响应双击事件,激活文本编辑模式
  481. ///// </summary>
  482. ///// <param name="event"></param>
  483. //void WindowAppBlockComment::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
  484. //{
  485. // if (event->button() == Qt::LeftButton && textInteractionFlags() == Qt::NoTextInteraction)
  486. // {
  487. // setTextInteractionFlags(Qt::TextEditorInteraction);
  488. // }
  489. //
  490. // QGraphicsTextItem::mouseDoubleClickEvent(event);
  491. //}
  492. //
  493. //
  494. ///// <summary>
  495. ///// 重写Shape函数,使其没有文字的空白部分也可以响应消息
  496. ///// </summary>
  497. ///// <returns></returns>
  498. //QPainterPath WindowAppBlockComment::shape() const
  499. //{
  500. // QPainterPath path;
  501. // path.addRect(blockRect);
  502. // return path;
  503. //}
  504. //void WindowAppBlockComment::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
  505. //{
  506. // qDebug() << "WindowAppBlockComment::hoverEnterEvent";
  507. //
  508. // update();
  509. // QGraphicsObject::hoverEnterEvent(event);
  510. //}
  511. //
  512. //
  513. //void WindowAppBlockComment::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
  514. //{
  515. // qDebug() << "WindowAppBlockComment::hoverLeaveEvent";
  516. //
  517. // setCursor(QCursor(Qt::ArrowCursor));
  518. // scene()->update(sceneBoundingRect());
  519. // update();
  520. // QGraphicsObject::hoverLeaveEvent(event);
  521. //}
  522. //void WindowAppBlockComment::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
  523. //{
  524. // if (this->isSelected())
  525. // {
  526. // QPointF mousePoint = event->pos();
  527. // QPointF mouseHandler = QPointF(5, 5);
  528. // QPointF topLeft = blockRect.topLeft();
  529. // QPointF topRight = blockRect.topRight();
  530. // QPointF bottomLeft = blockRect.bottomLeft();
  531. // QPointF bottomRight = blockRect.bottomRight();
  532. //
  533. // // resize top
  534. // if (mousePoint.x() >= (topLeft.x() + mouseHandler.x()) &&
  535. // mousePoint.x() <= (topRight.x() - mouseHandler.x()) &&
  536. // mousePoint.y() >= (topLeft.y() - mouseHandler.y()) &&
  537. // mousePoint.y() <= (topLeft.y() + mouseHandler.y())) {
  538. // setCursor(Qt::SizeVerCursor);
  539. // }
  540. // // resize bottom
  541. // else if (mousePoint.x() >= (bottomLeft.x() + mouseHandler.x()) &&
  542. // mousePoint.x() <= (bottomRight.x() - mouseHandler.x()) &&
  543. // mousePoint.y() >= (bottomLeft.y() - mouseHandler.y()) &&
  544. // mousePoint.y() <= (bottomLeft.y() + mouseHandler.y())) {
  545. // setCursor(Qt::SizeVerCursor);
  546. // }
  547. // // resize left
  548. // else if (mousePoint.x() >= (topLeft.x() - mouseHandler.x()) &&
  549. // mousePoint.x() <= (topLeft.x() + mouseHandler.x()) &&
  550. // mousePoint.y() >= (topLeft.y() + mouseHandler.y()) &&
  551. // mousePoint.y() <= (bottomLeft.y() - mouseHandler.y())) {
  552. // setCursor(Qt::SizeHorCursor);
  553. // }
  554. // // resize right
  555. // else if (mousePoint.x() >= (topRight.x() - mouseHandler.x()) &&
  556. // mousePoint.x() <= (topRight.x() + mouseHandler.x()) &&
  557. // mousePoint.y() >= (topRight.y() + mouseHandler.y()) &&
  558. // mousePoint.y() <= (bottomRight.y() - mouseHandler.y())) {
  559. // setCursor(Qt::SizeHorCursor);
  560. // }
  561. // // resize top left
  562. // else if (mousePoint.x() <= (topLeft.x() + mouseHandler.x()) &&
  563. // mousePoint.x() >= (topLeft.x() - mouseHandler.x()) &&
  564. // mousePoint.y() <= (topLeft.y() + mouseHandler.y()) &&
  565. // mousePoint.y() >= (topLeft.y() - mouseHandler.y())) {
  566. // setCursor(Qt::SizeFDiagCursor);
  567. // }
  568. // // resize bottom right
  569. // else if (mousePoint.x() <= (bottomRight.x() + mouseHandler.x()) &&
  570. // mousePoint.x() >= (bottomRight.x() - mouseHandler.x()) &&
  571. // mousePoint.y() <= (bottomRight.y() + mouseHandler.y()) &&
  572. // mousePoint.y() >= (bottomRight.y() - mouseHandler.y())) {
  573. // setCursor(Qt::SizeFDiagCursor);
  574. // }
  575. // // resize bottom left
  576. // else if (mousePoint.x() <= (bottomLeft.x() + mouseHandler.x()) &&
  577. // mousePoint.x() >= (bottomLeft.x() - mouseHandler.x()) &&
  578. // mousePoint.y() >= (bottomLeft.y() - mouseHandler.y()) &&
  579. // mousePoint.y() <= (bottomLeft.y() + mouseHandler.y())) {
  580. // setCursor(Qt::SizeBDiagCursor);
  581. // }
  582. // // resize top right
  583. // else if (mousePoint.x() <= (topRight.x() + mouseHandler.x()) &&
  584. // mousePoint.x() >= (topRight.x() - mouseHandler.x()) &&
  585. // mousePoint.y() >= (topRight.y() - mouseHandler.y()) &&
  586. // mousePoint.y() <= (topRight.y() + mouseHandler.y())) {
  587. // setCursor(Qt::SizeBDiagCursor);
  588. // }
  589. // else {
  590. // setCursor(Qt::ArrowCursor);
  591. // }
  592. // }
  593. // QGraphicsObject::hoverMoveEvent(event);
  594. //}
  595. ///**
  596. // * @brief Element::paintSelected
  597. // * @details 绘制选中状态
  598. // * @param painter
  599. // * @param iLineWidth 线宽
  600. // */
  601. //void WindowAppBlockComment::paintSelected(QPainter* painter, int iLineWidth)
  602. //{
  603. // if (isSelected())
  604. // {
  605. // painter->save();
  606. //
  607. // painter->setBrush(Qt::NoBrush);
  608. //
  609. // //QPen pen(Qt::green, iLineWidth, Qt::DashLine);
  610. // //painter->setPen(pen);
  611. // QRectF rect = blockRect.adjusted(-1, -1, 1, 1);
  612. // // painter->drawRect(rect);
  613. //
  614. // QPen pen2(Qt::green, iLineWidth, Qt::SolidLine);
  615. // painter->setPen(pen2);
  616. // QPointF pt = QPointF(3, 3);
  617. //
  618. // painter->drawRect(QRectF(rect.topLeft() - pt, rect.topLeft() + pt));
  619. // QPointF ptMid = QPointF(rect.left() + rect.width() / 2, rect.top());
  620. // painter->drawRect(QRectF(ptMid - pt, ptMid + pt));
  621. // painter->drawRect(QRectF(rect.topRight() - pt, rect.topRight() + pt));
  622. //
  623. // ptMid = QPointF(rect.left(), rect.top() + rect.height() / 2);
  624. // painter->drawRect(QRectF(ptMid - pt, ptMid + pt));
  625. // ptMid = QPointF(rect.right(), rect.top() + rect.height() / 2);
  626. // painter->drawRect(QRectF(ptMid - pt, ptMid + pt));
  627. //
  628. // painter->drawRect(QRectF(rect.bottomLeft() - pt, rect.bottomLeft() + pt));
  629. // ptMid = QPointF(rect.left() + rect.width() / 2, rect.bottom());
  630. // painter->drawRect(QRectF(ptMid - pt, ptMid + pt));
  631. // painter->drawRect(QRectF(rect.bottomRight() - pt, rect.bottomRight() + pt));
  632. //
  633. // painter->restore();
  634. // }
  635. //}