Skip to content

Commit 115a9a5

Browse files
author
Uwe Kindler
committed
Added High DPI support for the creation of drop indicator pixmaps
1 parent a4838a4 commit 115a9a5

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/DockOverlay.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
#include <QtGlobal>
3535
#include <QDebug>
3636
#include <QMap>
37+
#include <QWindow>
3738

3839
#include "DockAreaWidget.h"
3940

41+
#include <iostream>
4042

4143
namespace ads
4244
{
@@ -74,6 +76,7 @@ struct DockOverlayCrossPrivate
7476
QGridLayout* GridLayout;
7577
QColor IconColors[5];
7678
bool UpdateRequired = false;
79+
double LastDevicePixelRatio = 0.1;
7780

7881
/**
7982
* Private data constructor
@@ -140,21 +143,34 @@ struct DockOverlayCrossPrivate
140143
const qreal metric = static_cast<qreal>(l->fontMetrics().height()) * 3.f;
141144
const QSizeF size(metric, metric);
142145

143-
l->setPixmap(createDropIndicatorPixmap(size, DockWidgetArea, Mode));
146+
l->setPixmap(createHighDpiDropIndicatorPixmap(size, DockWidgetArea, Mode));
144147
l->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
145148
l->setAttribute(Qt::WA_TranslucentBackground);
149+
l->setProperty("dockWidgetArea", DockWidgetArea);
146150
return l;
147151
}
148152

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+
}
149163

150164
//============================================================================
151-
QPixmap createDropIndicatorPixmap(const QSizeF& size, DockWidgetArea DockWidgetArea,
165+
QPixmap createHighDpiDropIndicatorPixmap(const QSizeF& size, DockWidgetArea DockWidgetArea,
152166
CDockOverlay::eMode Mode)
153167
{
154168
QColor borderColor = iconColor(CDockOverlayCross::FrameColor);
155169
QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor);
156170

157-
QPixmap pm(size.width(), size.height());
171+
double DevicePixelRatio = _this->window()->devicePixelRatioF();
172+
QSizeF PixmapSize = size * DevicePixelRatio;
173+
QPixmap pm(PixmapSize.toSize());
158174
pm.fill(QColor(0, 0, 0, 0));
159175

160176
QPainter p(&pm);
@@ -224,6 +240,7 @@ struct DockOverlayCrossPrivate
224240
p.drawRect(areaRect);
225241

226242
pen = p.pen();
243+
pen.setWidth(1);
227244
pen.setColor(borderColor);
228245
pen.setStyle(Qt::DashLine);
229246
p.setPen(pen);
@@ -283,6 +300,7 @@ struct DockOverlayCrossPrivate
283300
p.drawPolygon(Arrow);
284301
}
285302

303+
pm.setDevicePixelRatio(DevicePixelRatio);
286304
return pm;
287305
}
288306

@@ -380,6 +398,7 @@ DockWidgetArea CDockOverlay::showOverlay(QWidget* target)
380398
move(TopLeft);
381399
show();
382400
d->Cross->updatePosition();
401+
d->Cross->updateOverlayIcons();
383402
return dropAreaUnderCursor();
384403
}
385404

@@ -558,12 +577,29 @@ void CDockOverlayCross::setupOverlayCross(CDockOverlay::eMode Mode)
558577
areaWidgets.insert(BottomDockWidgetArea, d->createDropIndicatorWidget(BottomDockWidgetArea, Mode));
559578
areaWidgets.insert(LeftDockWidgetArea, d->createDropIndicatorWidget(LeftDockWidgetArea, Mode));
560579
areaWidgets.insert(CenterDockWidgetArea, d->createDropIndicatorWidget(CenterDockWidgetArea, Mode));
580+
d->LastDevicePixelRatio = devicePixelRatioF();
561581

562582
setAreaWidgets(areaWidgets);
563583
d->UpdateRequired = false;
564584
}
565585

566586

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+
567603
//============================================================================
568604
void CDockOverlayCross::setIconColor(eIconColor ColorIndex, const QColor& Color)
569605
{

src/DockOverlay.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ class CDockOverlayCross : public QWidget
214214
*/
215215
void setupOverlayCross(CDockOverlay::eMode Mode);
216216

217+
/**
218+
* Recreates the overlay icons.
219+
*/
220+
void updateOverlayIcons();
221+
217222
/**
218223
* Resets and updates the
219224
*/

0 commit comments

Comments
 (0)