DockOverlay.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Qt Advanced Docking System
3 ** Copyright (C) 2017 Uwe Kindler
4 **
5 ** This library is free software; you can redistribute it and/or
6 ** modify it under the terms of the GNU Lesser General Public
7 ** License as published by the Free Software Foundation; either
8 ** version 2.1 of the License, or (at your option) any later version.
9 **
10 ** This library is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ** Lesser General Public License for more details.
14 **
15 ** You should have received a copy of the GNU Lesser General Public
16 ** License along with this library; If not, see <http://www.gnu.org/licenses/>.
17 ******************************************************************************/
18 
19 
20 //============================================================================
21 // INCLUDES
22 //============================================================================
23 #include "DockOverlay.h"
24 
25 #include <QPointer>
26 #include <QPaintEvent>
27 #include <QResizeEvent>
28 #include <QMoveEvent>
29 #include <QPainter>
30 #include <QGridLayout>
31 #include <QCursor>
32 #include <QIcon>
33 #include <QLabel>
34 #include <QtGlobal>
35 #include <QDebug>
36 #include <QMap>
37 #include <QWindow>
38 
39 #include "DockAreaWidget.h"
40 #include "DockAreaTitleBar.h"
41 
42 #include <iostream>
43 
44 namespace ads
45 {
46 
51 {
52  CDockOverlay* _this;
54  CDockOverlayCross* Cross;
55  QPointer<QWidget> TargetWidget;
57  bool DropPreviewEnabled = true;
58  CDockOverlay::eMode Mode = CDockOverlay::ModeDockAreaOverlay;
59  QRect DropAreaRect;
60 
64  DockOverlayPrivate(CDockOverlay* _public) : _this(_public) {}
65 };
66 
71 {
72  CDockOverlayCross* _this;
73  CDockOverlay::eMode Mode = CDockOverlay::ModeDockAreaOverlay;
74  CDockOverlay* DockOverlay;
75  QHash<DockWidgetArea, QWidget*> DropIndicatorWidgets;
76  QGridLayout* GridLayout;
77  QColor IconColors[5];
78  bool UpdateRequired = false;
79  double LastDevicePixelRatio = 0.1;
80 
84  DockOverlayCrossPrivate(CDockOverlayCross* _public) : _this(_public) {}
85 
91  QPoint areaGridPosition(const DockWidgetArea area);
92 
93 
97  QColor defaultIconColor(CDockOverlayCross::eIconColor ColorIndex)
98  {
99  QPalette pal = _this->palette();
100  switch (ColorIndex)
101  {
102  case CDockOverlayCross::FrameColor: return pal.color(QPalette::Active, QPalette::Highlight);
103  case CDockOverlayCross::WindowBackgroundColor: return pal.color(QPalette::Active, QPalette::Base);
104  case CDockOverlayCross::OverlayColor:
105  {
106  QColor Color = pal.color(QPalette::Active, QPalette::Highlight);
107  Color.setAlpha(64);
108  return Color;
109  }
110  break;
111 
112  case CDockOverlayCross::ArrowColor: return pal.color(QPalette::Active, QPalette::Base);
113  case CDockOverlayCross::ShadowColor: return QColor(0, 0, 0, 64);
114  default:
115  return QColor();
116  }
117 
118  return QColor();
119  }
120 
124  QColor iconColor(CDockOverlayCross::eIconColor ColorIndex)
125  {
126  QColor Color = IconColors[ColorIndex];
127  if (!Color.isValid())
128  {
129  Color = defaultIconColor(ColorIndex);
130  IconColors[ColorIndex] = Color;
131  }
132  return Color;
133  }
134 
135  //============================================================================
140  qreal dropIndicatiorWidth(QLabel* l) const
141  {
142  #ifdef Q_OS_LINUX
143  Q_UNUSED(l)
144  return 40;
145  #else
146  return static_cast<qreal>(l->fontMetrics().height()) * 3.f;
147  #endif
148  }
149 
150 
151  //============================================================================
153  CDockOverlay::eMode Mode)
154  {
155  QLabel* l = new QLabel();
156  l->setObjectName("DockWidgetAreaLabel");
157 
158  const qreal metric = dropIndicatiorWidth(l);
159  const QSizeF size(metric, metric);
160 
161  l->setPixmap(createHighDpiDropIndicatorPixmap(size, DockWidgetArea, Mode));
162  l->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
163  l->setAttribute(Qt::WA_TranslucentBackground);
164  l->setProperty("dockWidgetArea", DockWidgetArea);
165  return l;
166  }
167 
168  //============================================================================
169  void updateDropIndicatorIcon(QWidget* DropIndicatorWidget)
170  {
171  QLabel* l = qobject_cast<QLabel*>(DropIndicatorWidget);
172  const qreal metric = dropIndicatiorWidth(l);
173  const QSizeF size(metric, metric);
174 
175  int Area = l->property("dockWidgetArea").toInt();
176  l->setPixmap(createHighDpiDropIndicatorPixmap(size, (DockWidgetArea)Area, Mode));
177  }
178 
179  //============================================================================
181  CDockOverlay::eMode Mode)
182  {
183  QColor borderColor = iconColor(CDockOverlayCross::FrameColor);
184  QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor);
185 
186 #if QT_VERSION >= 0x050600
187  double DevicePixelRatio = _this->window()->devicePixelRatioF();
188 #else
189  double DevicePixelRatio = _this->window()->devicePixelRatio();
190 #endif
191  QSizeF PixmapSize = size * DevicePixelRatio;
192  QPixmap pm(PixmapSize.toSize());
193  pm.fill(QColor(0, 0, 0, 0));
194 
195  QPainter p(&pm);
196  QPen pen = p.pen();
197  QRectF ShadowRect(pm.rect());
198  QRectF baseRect;
199  baseRect.setSize(ShadowRect.size() * 0.7);
200  baseRect.moveCenter(ShadowRect.center());
201 
202  // Fill
203  QColor ShadowColor = iconColor(CDockOverlayCross::ShadowColor);
204  if (ShadowColor.alpha() == 255)
205  {
206  ShadowColor.setAlpha(64);
207  }
208  p.fillRect(ShadowRect, ShadowColor);
209 
210  // Drop area rect.
211  p.save();
212  QRectF areaRect;
213  QLineF areaLine;
214  QRectF nonAreaRect;
215  switch (DockWidgetArea)
216  {
217  case TopDockWidgetArea:
218  areaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width(), baseRect.height() * .5f);
219  nonAreaRect = QRectF(baseRect.x(), ShadowRect.height() * .5f, baseRect.width(), baseRect.height() * .5f);
220  areaLine = QLineF(areaRect.bottomLeft(), areaRect.bottomRight());
221  break;
222  case RightDockWidgetArea:
223  areaRect = QRectF(ShadowRect.width() * .5f, baseRect.y(), baseRect.width() * .5f, baseRect.height());
224  nonAreaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width() * .5f, baseRect.height());
225  areaLine = QLineF(areaRect.topLeft(), areaRect.bottomLeft());
226  break;
228  areaRect = QRectF(baseRect.x(), ShadowRect.height() * .5f, baseRect.width(), baseRect.height() * .5f);
229  nonAreaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width(), baseRect.height() * .5f);
230  areaLine = QLineF(areaRect.topLeft(), areaRect.topRight());
231  break;
232  case LeftDockWidgetArea:
233  areaRect = QRectF(baseRect.x(), baseRect.y(), baseRect.width() * .5f, baseRect.height());
234  nonAreaRect = QRectF(ShadowRect.width() * .5f, baseRect.y(), baseRect.width() * .5f, baseRect.height());
235  areaLine = QLineF(areaRect.topRight(), areaRect.bottomRight());
236  break;
237  default:
238  break;
239  }
240 
241  QSizeF baseSize = baseRect.size();
242  if (CDockOverlay::ModeContainerOverlay == Mode && DockWidgetArea != CenterDockWidgetArea)
243  {
244  baseRect = areaRect;
245  }
246 
247  p.fillRect(baseRect, backgroundColor);
248  if (areaRect.isValid())
249  {
250  pen = p.pen();
251  pen.setColor(borderColor);
252  QColor Color = iconColor(CDockOverlayCross::OverlayColor);
253  if (Color.alpha() == 255)
254  {
255  Color.setAlpha(64);
256  }
257  p.setBrush(Color);
258  p.setPen(Qt::NoPen);
259  p.drawRect(areaRect);
260 
261  pen = p.pen();
262  pen.setWidth(1);
263  pen.setColor(borderColor);
264  pen.setStyle(Qt::DashLine);
265  p.setPen(pen);
266  p.drawLine(areaLine);
267  }
268  p.restore();
269 
270  p.save();
271  // Draw outer border
272  pen = p.pen();
273  pen.setColor(borderColor);
274  pen.setWidth(1);
275  p.setBrush(Qt::NoBrush);
276  p.setPen(pen);
277  p.drawRect(baseRect);
278 
279  // draw window title bar
280  p.setBrush(borderColor);
281  QRectF FrameRect(baseRect.topLeft(), QSizeF(baseRect.width(), baseSize.height() / 10));
282  p.drawRect(FrameRect);
283  p.restore();
284 
285  // Draw arrow for outer container drop indicators
286  if (CDockOverlay::ModeContainerOverlay == Mode && DockWidgetArea != CenterDockWidgetArea)
287  {
288  QRectF ArrowRect;
289  ArrowRect.setSize(baseSize);
290  ArrowRect.setWidth(ArrowRect.width() / 4.6);
291  ArrowRect.setHeight(ArrowRect.height() / 2);
292  ArrowRect.moveCenter(QPointF(0, 0));
293  QPolygonF Arrow;
294  Arrow << ArrowRect.topLeft()
295  << QPointF( ArrowRect.right(), ArrowRect.center().y())
296  << ArrowRect.bottomLeft();
297  p.setPen(Qt::NoPen);
298  p.setBrush(iconColor(CDockOverlayCross::ArrowColor));
299  p.setRenderHint(QPainter::Antialiasing, true);
300  p.translate(nonAreaRect.center().x(), nonAreaRect.center().y());
301 
302  switch (DockWidgetArea)
303  {
304  case TopDockWidgetArea:
305  p.rotate(-90);
306  break;
307  case RightDockWidgetArea:
308  break;
310  p.rotate(90);
311  break;
312  case LeftDockWidgetArea:
313  p.rotate(180);
314  break;
315  default:
316  break;
317  }
318 
319  p.drawPolygon(Arrow);
320  }
321 
322  pm.setDevicePixelRatio(DevicePixelRatio);
323  return pm;
324  }
325 
326 };
327 
328 
329 //============================================================================
330 CDockOverlay::CDockOverlay(QWidget* parent, eMode Mode) :
331  QFrame(parent),
332  d(new DockOverlayPrivate(this))
333 {
334  d->Mode = Mode;
335  d->Cross = new CDockOverlayCross(this);
336 #ifdef Q_OS_LINUX
337  setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
338 #else
339  setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
340 #endif
341  setWindowOpacity(1);
342  setWindowTitle("DockOverlay");
343  setAttribute(Qt::WA_NoSystemBackground);
344  setAttribute(Qt::WA_TranslucentBackground);
345 
346  d->Cross->setVisible(false);
347  setVisible(false);
348 }
349 
350 
351 //============================================================================
352 CDockOverlay::~CDockOverlay()
353 {
354  delete d;
355 }
356 
357 
358 //============================================================================
359 void CDockOverlay::setAllowedAreas(DockWidgetAreas areas)
360 {
361  if (areas == d->AllowedAreas)
362  return;
363  d->AllowedAreas = areas;
364  d->Cross->reset();
365 }
366 
367 
368 //============================================================================
369 DockWidgetAreas CDockOverlay::allowedAreas() const
370 {
371  return d->AllowedAreas;
372 }
373 
374 
375 //============================================================================
376 DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
377 {
378  DockWidgetArea Result = d->Cross->cursorLocation();
379  if (Result != InvalidDockWidgetArea)
380  {
381  return Result;
382  }
383 
384  CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(d->TargetWidget.data());
385  if (!DockArea)
386  {
387  return Result;
388  }
389 
390  if (DockArea->allowedAreas().testFlag(CenterDockWidgetArea)
391  && !DockArea->titleBar()->isHidden()
392  && DockArea->titleBarGeometry().contains(DockArea->mapFromGlobal(QCursor::pos())))
393  {
394  return CenterDockWidgetArea;
395  }
396 
397  return Result;
398 }
399 
400 
401 //============================================================================
402 DockWidgetArea CDockOverlay::visibleDropAreaUnderCursor() const
403 {
404  if (isHidden() || !d->DropPreviewEnabled)
405  {
406  return InvalidDockWidgetArea;
407  }
408  else
409  {
410  return dropAreaUnderCursor();
411  }
412 }
413 
414 
415 //============================================================================
416 DockWidgetArea CDockOverlay::showOverlay(QWidget* target)
417 {
418  if (d->TargetWidget == target)
419  {
420  // Hint: We could update geometry of overlay here.
421  DockWidgetArea da = dropAreaUnderCursor();
422  if (da != d->LastLocation)
423  {
424  repaint();
425  d->LastLocation = da;
426  }
427  return da;
428  }
429 
430  d->TargetWidget = target;
431  d->LastLocation = InvalidDockWidgetArea;
432 
433  // Move it over the target.
434  resize(target->size());
435  QPoint TopLeft = target->mapToGlobal(target->rect().topLeft());
436  move(TopLeft);
437  show();
438  d->Cross->updatePosition();
439  d->Cross->updateOverlayIcons();
440  return dropAreaUnderCursor();
441 }
442 
443 
444 //============================================================================
445 void CDockOverlay::hideOverlay()
446 {
447  hide();
448  d->TargetWidget.clear();
449  d->LastLocation = InvalidDockWidgetArea;
450  d->DropAreaRect = QRect();
451 }
452 
453 
454 //============================================================================
455 void CDockOverlay::enableDropPreview(bool Enable)
456 {
457  d->DropPreviewEnabled = Enable;
458  update();
459 }
460 
461 
462 //============================================================================
463 bool CDockOverlay::dropPreviewEnabled() const
464 {
465  return d->DropPreviewEnabled;
466 }
467 
468 
469 //============================================================================
470 void CDockOverlay::paintEvent(QPaintEvent* event)
471 {
472  Q_UNUSED(event);
473  // Draw rect based on location
474  if (!d->DropPreviewEnabled)
475  {
476  d->DropAreaRect = QRect();
477  return;
478  }
479 
480  QRect r = rect();
481  const DockWidgetArea da = dropAreaUnderCursor();
482  double Factor = (CDockOverlay::ModeContainerOverlay == d->Mode) ?
483  3 : 2;
484 
485  switch (da)
486  {
487  case TopDockWidgetArea: r.setHeight(r.height() / Factor); break;
488  case RightDockWidgetArea: r.setX(r.width() * (1 - 1 / Factor)); break;
489  case BottomDockWidgetArea: r.setY(r.height() * (1 - 1 / Factor)); break;
490  case LeftDockWidgetArea: r.setWidth(r.width() / Factor); break;
491  case CenterDockWidgetArea: r = rect();break;
492  default: return;
493  }
494  QPainter painter(this);
495  QColor Color = palette().color(QPalette::Active, QPalette::Highlight);
496  QPen Pen = painter.pen();
497  Pen.setColor(Color.darker(120));
498  Pen.setStyle(Qt::SolidLine);
499  Pen.setWidth(1);
500  Pen.setCosmetic(true);
501  painter.setPen(Pen);
502  Color = Color.lighter(130);
503  Color.setAlpha(64);
504  painter.setBrush(Color);
505  painter.drawRect(r.adjusted(0, 0, -1, -1));
506  d->DropAreaRect = r;
507 }
508 
509 
510 //============================================================================
511 QRect CDockOverlay::dropOverlayRect() const
512 {
513  return d->DropAreaRect;
514 }
515 
516 
517 //============================================================================
518 void CDockOverlay::showEvent(QShowEvent* e)
519 {
520  d->Cross->show();
521  QFrame::showEvent(e);
522 }
523 
524 
525 //============================================================================
526 void CDockOverlay::hideEvent(QHideEvent* e)
527 {
528  d->Cross->hide();
529  QFrame::hideEvent(e);
530 }
531 
532 
533 //============================================================================
534 bool CDockOverlay::event(QEvent *e)
535 {
536  bool Result = Super::event(e);
537  if (e->type() == QEvent::Polish)
538  {
539  d->Cross->setupOverlayCross(d->Mode);
540  }
541  return Result;
542 }
543 
544 
545 //============================================================================
546 static int areaAlignment(const DockWidgetArea area)
547 {
548  switch (area)
549  {
550  case TopDockWidgetArea: return (int) Qt::AlignHCenter | Qt::AlignBottom;
551  case RightDockWidgetArea: return (int) Qt::AlignLeft | Qt::AlignVCenter;
552  case BottomDockWidgetArea: return (int) Qt::AlignHCenter | Qt::AlignTop;
553  case LeftDockWidgetArea: return (int) Qt::AlignRight | Qt::AlignVCenter;
554  case CenterDockWidgetArea: return (int) Qt::AlignCenter;
555  default: return Qt::AlignCenter;
556  }
557 }
558 
559 //============================================================================
560 // DockOverlayCrossPrivate
561 //============================================================================
563 {
564  if (CDockOverlay::ModeDockAreaOverlay == Mode)
565  {
566  switch (area)
567  {
568  case TopDockWidgetArea: return QPoint(1, 2);
569  case RightDockWidgetArea: return QPoint(2, 3);
570  case BottomDockWidgetArea: return QPoint(3, 2);
571  case LeftDockWidgetArea: return QPoint(2, 1);
572  case CenterDockWidgetArea: return QPoint(2, 2);
573  default: return QPoint();
574  }
575  }
576  else
577  {
578  switch (area)
579  {
580  case TopDockWidgetArea: return QPoint(0, 2);
581  case RightDockWidgetArea: return QPoint(2, 4);
582  case BottomDockWidgetArea: return QPoint(4, 2);
583  case LeftDockWidgetArea: return QPoint(2, 0);
584  case CenterDockWidgetArea: return QPoint(2, 2);
585  default: return QPoint();
586  }
587  }
588 }
589 
590 
591 //============================================================================
592 CDockOverlayCross::CDockOverlayCross(CDockOverlay* overlay) :
593  QWidget(overlay->parentWidget()),
594  d(new DockOverlayCrossPrivate(this))
595 {
596  d->DockOverlay = overlay;
597 #ifdef Q_OS_LINUX
598  setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
599 #else
600  setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
601 #endif
602  setWindowTitle("DockOverlayCross");
603  setAttribute(Qt::WA_TranslucentBackground);
604 
605  d->GridLayout = new QGridLayout();
606  d->GridLayout->setSpacing(0);
607  setLayout(d->GridLayout);
608 }
609 
610 
611 //============================================================================
612 CDockOverlayCross::~CDockOverlayCross()
613 {
614  delete d;
615 }
616 
617 
618 //============================================================================
619 void CDockOverlayCross::setupOverlayCross(CDockOverlay::eMode Mode)
620 {
621  d->Mode = Mode;
622 
623  QHash<DockWidgetArea, QWidget*> areaWidgets;
624  areaWidgets.insert(TopDockWidgetArea, d->createDropIndicatorWidget(TopDockWidgetArea, Mode));
625  areaWidgets.insert(RightDockWidgetArea, d->createDropIndicatorWidget(RightDockWidgetArea, Mode));
626  areaWidgets.insert(BottomDockWidgetArea, d->createDropIndicatorWidget(BottomDockWidgetArea, Mode));
627  areaWidgets.insert(LeftDockWidgetArea, d->createDropIndicatorWidget(LeftDockWidgetArea, Mode));
628  areaWidgets.insert(CenterDockWidgetArea, d->createDropIndicatorWidget(CenterDockWidgetArea, Mode));
629 #if QT_VERSION >= 0x050600
630  d->LastDevicePixelRatio = devicePixelRatioF();
631 #else
632  d->LastDevicePixelRatio = devicePixelRatio();
633 #endif
634  setAreaWidgets(areaWidgets);
635  d->UpdateRequired = false;
636 }
637 
638 
639 //============================================================================
640 void CDockOverlayCross::updateOverlayIcons()
641 {
642  if (windowHandle()->devicePixelRatio() == d->LastDevicePixelRatio)
643  {
644  return;
645  }
646 
647  for (auto Widget : d->DropIndicatorWidgets)
648  {
649  d->updateDropIndicatorIcon(Widget);
650  }
651 #if QT_VERSION >= 0x050600
652  d->LastDevicePixelRatio = devicePixelRatioF();
653 #else
654  d->LastDevicePixelRatio = devicePixelRatio();
655 #endif
656 }
657 
658 
659 //============================================================================
660 void CDockOverlayCross::setIconColor(eIconColor ColorIndex, const QColor& Color)
661 {
662  d->IconColors[ColorIndex] = Color;
663  d->UpdateRequired = true;
664 }
665 
666 
667 //============================================================================
668 QColor CDockOverlayCross::iconColor(eIconColor ColorIndex) const
669 {
670  return d->IconColors[ColorIndex];
671 }
672 
673 
674 //============================================================================
675 void CDockOverlayCross::setAreaWidgets(const QHash<DockWidgetArea, QWidget*>& widgets)
676 {
677  // Delete old widgets.
678  QMutableHashIterator<DockWidgetArea, QWidget*> i(d->DropIndicatorWidgets);
679  while (i.hasNext())
680  {
681  i.next();
682  QWidget* widget = i.value();
683  d->GridLayout->removeWidget(widget);
684  delete widget;
685  i.remove();
686  }
687 
688  // Insert new widgets into grid.
689  d->DropIndicatorWidgets = widgets;
690  QHashIterator<DockWidgetArea, QWidget*> i2(d->DropIndicatorWidgets);
691  while (i2.hasNext())
692  {
693  i2.next();
694  const DockWidgetArea area = i2.key();
695  QWidget* widget = i2.value();
696  QPoint p = d->areaGridPosition(area);
697  d->GridLayout->addWidget(widget, p.x(), p.y(), (Qt::Alignment) areaAlignment(area));
698  }
699 
700  if (CDockOverlay::ModeDockAreaOverlay == d->Mode)
701  {
702  d->GridLayout->setContentsMargins(0, 0, 0, 0);
703  d->GridLayout->setRowStretch(0, 1);
704  d->GridLayout->setRowStretch(1, 0);
705  d->GridLayout->setRowStretch(2, 0);
706  d->GridLayout->setRowStretch(3, 0);
707  d->GridLayout->setRowStretch(4, 1);
708 
709  d->GridLayout->setColumnStretch(0, 1);
710  d->GridLayout->setColumnStretch(1, 0);
711  d->GridLayout->setColumnStretch(2, 0);
712  d->GridLayout->setColumnStretch(3, 0);
713  d->GridLayout->setColumnStretch(4, 1);
714  }
715  else
716  {
717  d->GridLayout->setContentsMargins(4, 4, 4, 4);
718  d->GridLayout->setRowStretch(0, 0);
719  d->GridLayout->setRowStretch(1, 1);
720  d->GridLayout->setRowStretch(2, 1);
721  d->GridLayout->setRowStretch(3, 1);
722  d->GridLayout->setRowStretch(4, 0);
723 
724  d->GridLayout->setColumnStretch(0, 0);
725  d->GridLayout->setColumnStretch(1, 1);
726  d->GridLayout->setColumnStretch(2, 1);
727  d->GridLayout->setColumnStretch(3, 1);
728  d->GridLayout->setColumnStretch(4, 0);
729  }
730  reset();
731 }
732 
733 
734 //============================================================================
735 DockWidgetArea CDockOverlayCross::cursorLocation() const
736 {
737  const QPoint pos = mapFromGlobal(QCursor::pos());
738  QHashIterator<DockWidgetArea, QWidget*> i(d->DropIndicatorWidgets);
739  while (i.hasNext())
740  {
741  i.next();
742  if (d->DockOverlay->allowedAreas().testFlag(i.key())
743  && i.value()
744  && i.value()->isVisible()
745  && i.value()->geometry().contains(pos))
746  {
747  return i.key();
748  }
749  }
750  return InvalidDockWidgetArea;
751 }
752 
753 
754 //============================================================================
755 void CDockOverlayCross::showEvent(QShowEvent*)
756 {
757  if (d->UpdateRequired)
758  {
759  setupOverlayCross(d->Mode);
760  }
761  this->updatePosition();
762 }
763 
764 
765 //============================================================================
766 void CDockOverlayCross::updatePosition()
767 {
768  resize(d->DockOverlay->size());
769  QPoint TopLeft = d->DockOverlay->pos();
770  QPoint Offest((this->width() - d->DockOverlay->width()) / 2,
771  (this->height() - d->DockOverlay->height()) / 2);
772  QPoint CrossTopLeft = TopLeft - Offest;
773  move(CrossTopLeft);
774 }
775 
776 
777 //============================================================================
779 {
780  QList<DockWidgetArea> allAreas;
783  const DockWidgetAreas allowedAreas = d->DockOverlay->allowedAreas();
784 
785  // Update visibility of area widgets based on allowedAreas.
786  for (int i = 0; i < allAreas.count(); ++i)
787  {
788  QPoint p = d->areaGridPosition(allAreas.at(i));
789  QLayoutItem* item = d->GridLayout->itemAtPosition(p.x(), p.y());
790  QWidget* w = nullptr;
791  if (item && (w = item->widget()) != nullptr)
792  {
793  w->setVisible(allowedAreas.testFlag(allAreas.at(i)));
794  }
795  }
796 }
797 
798 
799 //============================================================================
800 void CDockOverlayCross::setIconColors(const QString& Colors)
801 {
802  static const QMap<QString, int> ColorCompenentStringMap{
803  {"Frame", CDockOverlayCross::FrameColor},
804  {"Background", CDockOverlayCross::WindowBackgroundColor},
805  {"Overlay", CDockOverlayCross::OverlayColor},
806  {"Arrow", CDockOverlayCross::ArrowColor},
807  {"Shadow", CDockOverlayCross::ShadowColor}};
808 
809  auto ColorList = Colors.split(' ', QString::SkipEmptyParts);
810  for (const auto& ColorListEntry : ColorList)
811  {
812  auto ComponentColor = ColorListEntry.split('=', QString::SkipEmptyParts);
813  int Component = ColorCompenentStringMap.value(ComponentColor[0], -1);
814  if (Component < 0)
815  {
816  continue;
817  }
818  d->IconColors[Component] = QColor(ComponentColor[1]);
819  }
820 
821  d->UpdateRequired = true;
822 }
823 
824 //============================================================================
825 QString CDockOverlayCross::iconColors() const
826 {
827  return QString();
828 }
829 
830 
831 
832 } // namespace ads
833 //----------------------------------------------------------------------------
834 
QColor iconColor(CDockOverlayCross::eIconColor ColorIndex)
CDockAreaTitleBar * titleBar() const
DockWidgetArea
Definition: ads_globals.h:73
MQTTClient d
Definition: test10.c:1656
DockOverlayCrossPrivate(CDockOverlayCross *_public)
Definition: DockOverlay.cpp:84
DockWidgetAreas allowedAreas() const
DockOverlayPrivate(CDockOverlay *_public)
Definition: DockOverlay.cpp:64
QPixmap createHighDpiDropIndicatorPixmap(const QSizeF &size, DockWidgetArea DockWidgetArea, CDockOverlay::eMode Mode)
CDockOverlay::eMode Mode
Definition: DockOverlay.cpp:58
qreal dropIndicatiorWidth(QLabel *l) const
static int areaAlignment(const DockWidgetArea area)
DockWidgetAreas AllowedAreas
Definition: DockOverlay.cpp:53
QHash< DockWidgetArea, QWidget * > DropIndicatorWidgets
Definition: DockOverlay.cpp:75
QPointer< QWidget > TargetWidget
Definition: DockOverlay.cpp:55
QWidget * createDropIndicatorWidget(DockWidgetArea DockWidgetArea, CDockOverlay::eMode Mode)
QRect titleBarGeometry() const
const T & move(const T &v)
Definition: backward.hpp:394
Declaration of CDockAreaWidget class.
CDockOverlayCross * Cross
Definition: DockOverlay.cpp:54
DockWidgetArea LastLocation
Definition: DockOverlay.cpp:56
CDockOverlay * _this
Definition: DockOverlay.cpp:52
QPoint areaGridPosition(const DockWidgetArea area)
CDockOverlayCross * _this
Definition: DockOverlay.cpp:72
void updateDropIndicatorIcon(QWidget *DropIndicatorWidget)
Declaration of CDockAreaTitleBar class.
QColor defaultIconColor(CDockOverlayCross::eIconColor ColorIndex)
Definition: DockOverlay.cpp:97


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:47:34