CmQtDockOverlayWidget.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "CmQtDockOverlayWidget.h"
  2. #include <QtGui/QPainter>
  3. #include <QtGui/QPen>
  4. #include <QtGui/QPolygon>
  5. #include <QtGui/QMouseEvent>
  6. #include <QtCore/QRect>
  7. namespace CamelotEditor
  8. {
  9. QtDockOverlayWidget::QtDockOverlayWidget(QWidget* parent)
  10. :QWidget(parent), mHighlightedDropLocation(CM_WINDROP_NONE), mDropOverlayEnabled(false)
  11. {
  12. setPalette(Qt::transparent);
  13. setAttribute(Qt::WA_TransparentForMouseEvents);
  14. hide();
  15. }
  16. void QtDockOverlayWidget::highlightDropLocation(WindowDragDropLocation dropLocation)
  17. {
  18. mHighlightedDropLocation = dropLocation;
  19. repaint();
  20. }
  21. void QtDockOverlayWidget::enableDropOverlay(std::vector<QPolygon> dragLocations, const QPoint& offset)
  22. {
  23. mDragLocations = dragLocations;
  24. mOverlayOffset = offset;
  25. if(!mDropOverlayEnabled)
  26. {
  27. show();
  28. mDropOverlayEnabled = true;
  29. repaint();
  30. }
  31. }
  32. void QtDockOverlayWidget::disableDropOverlay()
  33. {
  34. if(mDropOverlayEnabled)
  35. {
  36. hide();
  37. mDropOverlayEnabled = false;
  38. repaint();
  39. }
  40. }
  41. void QtDockOverlayWidget::paintEvent(QPaintEvent *event)
  42. {
  43. if(mDropOverlayEnabled)
  44. {
  45. drawDragLocations(mDragLocations, mHighlightedDropLocation);
  46. }
  47. }
  48. void QtDockOverlayWidget::drawDragLocations(const std::vector<QPolygon>& dragLocations, WindowDragDropLocation highlightedLocation)
  49. {
  50. QPainter painter(this);
  51. painter.translate(mOverlayOffset);
  52. painter.setRenderHint(QPainter::Antialiasing);
  53. painter.setPen(QColor(208, 208, 208));
  54. painter.setClipping(false);
  55. int idx = 0;
  56. for(auto iter = dragLocations.begin(); iter != dragLocations.end(); ++iter)
  57. {
  58. painter.drawPolygon(*iter);
  59. if(idx == (int)highlightedLocation)
  60. {
  61. QPainterPath highlightedPoly;
  62. highlightedPoly.addPolygon(*iter);
  63. painter.fillPath(highlightedPoly, QColor(190, 190, 190, 128));
  64. }
  65. else
  66. {
  67. QPainterPath highlightedPoly;
  68. highlightedPoly.addPolygon(*iter);
  69. painter.fillPath(highlightedPoly, QColor(210, 210, 210, 128));
  70. }
  71. ++idx;
  72. }
  73. }
  74. }