|
34 | 34 | #include <QtGlobal> |
35 | 35 | #include <QDebug> |
36 | 36 | #include <QMap> |
| 37 | +#include <QWindow> |
37 | 38 |
|
38 | 39 | #include "DockAreaWidget.h" |
39 | 40 |
|
| 41 | +#include <iostream> |
40 | 42 |
|
41 | 43 | namespace ads |
42 | 44 | { |
@@ -74,6 +76,7 @@ struct DockOverlayCrossPrivate |
74 | 76 | QGridLayout* GridLayout; |
75 | 77 | QColor IconColors[5]; |
76 | 78 | bool UpdateRequired = false; |
| 79 | + double LastDevicePixelRatio = 0.1; |
77 | 80 |
|
78 | 81 | /** |
79 | 82 | * Private data constructor |
@@ -140,21 +143,34 @@ struct DockOverlayCrossPrivate |
140 | 143 | const qreal metric = static_cast<qreal>(l->fontMetrics().height()) * 3.f; |
141 | 144 | const QSizeF size(metric, metric); |
142 | 145 |
|
143 | | - l->setPixmap(createDropIndicatorPixmap(size, DockWidgetArea, Mode)); |
| 146 | + l->setPixmap(createHighDpiDropIndicatorPixmap(size, DockWidgetArea, Mode)); |
144 | 147 | l->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); |
145 | 148 | l->setAttribute(Qt::WA_TranslucentBackground); |
| 149 | + l->setProperty("dockWidgetArea", DockWidgetArea); |
146 | 150 | return l; |
147 | 151 | } |
148 | 152 |
|
| 153 | + //============================================================================ |
| 154 | + void updateDropIndicatorIcon(QWidget* DropIndicatorWidget) |
| 155 | + { |
| 156 | + QLabel* l = qobject_cast<QLabel*>(DropIndicatorWidget); |
| 157 | + const qreal metric = static_cast<qreal>(l->fontMetrics().height()) * 3.f; |
| 158 | + const QSizeF size(metric, metric); |
| 159 | + |
| 160 | + int Area = l->property("dockWidgetArea").toInt(); |
| 161 | + l->setPixmap(createHighDpiDropIndicatorPixmap(size, (DockWidgetArea)Area, Mode)); |
| 162 | + } |
149 | 163 |
|
150 | 164 | //============================================================================ |
151 | | - QPixmap createDropIndicatorPixmap(const QSizeF& size, DockWidgetArea DockWidgetArea, |
| 165 | + QPixmap createHighDpiDropIndicatorPixmap(const QSizeF& size, DockWidgetArea DockWidgetArea, |
152 | 166 | CDockOverlay::eMode Mode) |
153 | 167 | { |
154 | 168 | QColor borderColor = iconColor(CDockOverlayCross::FrameColor); |
155 | 169 | QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor); |
156 | 170 |
|
157 | | - QPixmap pm(size.width(), size.height()); |
| 171 | + double DevicePixelRatio = _this->window()->devicePixelRatioF(); |
| 172 | + QSizeF PixmapSize = size * DevicePixelRatio; |
| 173 | + QPixmap pm(PixmapSize.toSize()); |
158 | 174 | pm.fill(QColor(0, 0, 0, 0)); |
159 | 175 |
|
160 | 176 | QPainter p(&pm); |
@@ -224,6 +240,7 @@ struct DockOverlayCrossPrivate |
224 | 240 | p.drawRect(areaRect); |
225 | 241 |
|
226 | 242 | pen = p.pen(); |
| 243 | + pen.setWidth(1); |
227 | 244 | pen.setColor(borderColor); |
228 | 245 | pen.setStyle(Qt::DashLine); |
229 | 246 | p.setPen(pen); |
@@ -283,6 +300,7 @@ struct DockOverlayCrossPrivate |
283 | 300 | p.drawPolygon(Arrow); |
284 | 301 | } |
285 | 302 |
|
| 303 | + pm.setDevicePixelRatio(DevicePixelRatio); |
286 | 304 | return pm; |
287 | 305 | } |
288 | 306 |
|
@@ -380,6 +398,7 @@ DockWidgetArea CDockOverlay::showOverlay(QWidget* target) |
380 | 398 | move(TopLeft); |
381 | 399 | show(); |
382 | 400 | d->Cross->updatePosition(); |
| 401 | + d->Cross->updateOverlayIcons(); |
383 | 402 | return dropAreaUnderCursor(); |
384 | 403 | } |
385 | 404 |
|
@@ -558,12 +577,29 @@ void CDockOverlayCross::setupOverlayCross(CDockOverlay::eMode Mode) |
558 | 577 | areaWidgets.insert(BottomDockWidgetArea, d->createDropIndicatorWidget(BottomDockWidgetArea, Mode)); |
559 | 578 | areaWidgets.insert(LeftDockWidgetArea, d->createDropIndicatorWidget(LeftDockWidgetArea, Mode)); |
560 | 579 | areaWidgets.insert(CenterDockWidgetArea, d->createDropIndicatorWidget(CenterDockWidgetArea, Mode)); |
| 580 | + d->LastDevicePixelRatio = devicePixelRatioF(); |
561 | 581 |
|
562 | 582 | setAreaWidgets(areaWidgets); |
563 | 583 | d->UpdateRequired = false; |
564 | 584 | } |
565 | 585 |
|
566 | 586 |
|
| 587 | +//============================================================================ |
| 588 | +void CDockOverlayCross::updateOverlayIcons() |
| 589 | +{ |
| 590 | + if (windowHandle()->devicePixelRatio() == d->LastDevicePixelRatio) |
| 591 | + { |
| 592 | + return; |
| 593 | + } |
| 594 | + |
| 595 | + for (auto Widget : d->DropIndicatorWidgets) |
| 596 | + { |
| 597 | + d->updateDropIndicatorIcon(Widget); |
| 598 | + } |
| 599 | + d->LastDevicePixelRatio = devicePixelRatioF(); |
| 600 | +} |
| 601 | + |
| 602 | + |
567 | 603 | //============================================================================ |
568 | 604 | void CDockOverlayCross::setIconColor(eIconColor ColorIndex, const QColor& Color) |
569 | 605 | { |
|
0 commit comments