mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-27 23:00:20 +08:00
Added High DPI support for the creation of drop indicator pixmaps
This commit is contained in:
parent
a4838a41ac
commit
115a9a5b3d
@ -34,9 +34,11 @@
|
|||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
#include "DockAreaWidget.h"
|
#include "DockAreaWidget.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace ads
|
namespace ads
|
||||||
{
|
{
|
||||||
@ -74,6 +76,7 @@ struct DockOverlayCrossPrivate
|
|||||||
QGridLayout* GridLayout;
|
QGridLayout* GridLayout;
|
||||||
QColor IconColors[5];
|
QColor IconColors[5];
|
||||||
bool UpdateRequired = false;
|
bool UpdateRequired = false;
|
||||||
|
double LastDevicePixelRatio = 0.1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data constructor
|
* Private data constructor
|
||||||
@ -140,21 +143,34 @@ struct DockOverlayCrossPrivate
|
|||||||
const qreal metric = static_cast<qreal>(l->fontMetrics().height()) * 3.f;
|
const qreal metric = static_cast<qreal>(l->fontMetrics().height()) * 3.f;
|
||||||
const QSizeF size(metric, metric);
|
const QSizeF size(metric, metric);
|
||||||
|
|
||||||
l->setPixmap(createDropIndicatorPixmap(size, DockWidgetArea, Mode));
|
l->setPixmap(createHighDpiDropIndicatorPixmap(size, DockWidgetArea, Mode));
|
||||||
l->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
|
l->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
|
||||||
l->setAttribute(Qt::WA_TranslucentBackground);
|
l->setAttribute(Qt::WA_TranslucentBackground);
|
||||||
|
l->setProperty("dockWidgetArea", DockWidgetArea);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void updateDropIndicatorIcon(QWidget* DropIndicatorWidget)
|
||||||
|
{
|
||||||
|
QLabel* l = qobject_cast<QLabel*>(DropIndicatorWidget);
|
||||||
|
const qreal metric = static_cast<qreal>(l->fontMetrics().height()) * 3.f;
|
||||||
|
const QSizeF size(metric, metric);
|
||||||
|
|
||||||
|
int Area = l->property("dockWidgetArea").toInt();
|
||||||
|
l->setPixmap(createHighDpiDropIndicatorPixmap(size, (DockWidgetArea)Area, Mode));
|
||||||
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
QPixmap createDropIndicatorPixmap(const QSizeF& size, DockWidgetArea DockWidgetArea,
|
QPixmap createHighDpiDropIndicatorPixmap(const QSizeF& size, DockWidgetArea DockWidgetArea,
|
||||||
CDockOverlay::eMode Mode)
|
CDockOverlay::eMode Mode)
|
||||||
{
|
{
|
||||||
QColor borderColor = iconColor(CDockOverlayCross::FrameColor);
|
QColor borderColor = iconColor(CDockOverlayCross::FrameColor);
|
||||||
QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor);
|
QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor);
|
||||||
|
|
||||||
QPixmap pm(size.width(), size.height());
|
double DevicePixelRatio = _this->window()->devicePixelRatioF();
|
||||||
|
QSizeF PixmapSize = size * DevicePixelRatio;
|
||||||
|
QPixmap pm(PixmapSize.toSize());
|
||||||
pm.fill(QColor(0, 0, 0, 0));
|
pm.fill(QColor(0, 0, 0, 0));
|
||||||
|
|
||||||
QPainter p(&pm);
|
QPainter p(&pm);
|
||||||
@ -224,6 +240,7 @@ struct DockOverlayCrossPrivate
|
|||||||
p.drawRect(areaRect);
|
p.drawRect(areaRect);
|
||||||
|
|
||||||
pen = p.pen();
|
pen = p.pen();
|
||||||
|
pen.setWidth(1);
|
||||||
pen.setColor(borderColor);
|
pen.setColor(borderColor);
|
||||||
pen.setStyle(Qt::DashLine);
|
pen.setStyle(Qt::DashLine);
|
||||||
p.setPen(pen);
|
p.setPen(pen);
|
||||||
@ -283,6 +300,7 @@ struct DockOverlayCrossPrivate
|
|||||||
p.drawPolygon(Arrow);
|
p.drawPolygon(Arrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pm.setDevicePixelRatio(DevicePixelRatio);
|
||||||
return pm;
|
return pm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,6 +398,7 @@ DockWidgetArea CDockOverlay::showOverlay(QWidget* target)
|
|||||||
move(TopLeft);
|
move(TopLeft);
|
||||||
show();
|
show();
|
||||||
d->Cross->updatePosition();
|
d->Cross->updatePosition();
|
||||||
|
d->Cross->updateOverlayIcons();
|
||||||
return dropAreaUnderCursor();
|
return dropAreaUnderCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,12 +577,29 @@ void CDockOverlayCross::setupOverlayCross(CDockOverlay::eMode Mode)
|
|||||||
areaWidgets.insert(BottomDockWidgetArea, d->createDropIndicatorWidget(BottomDockWidgetArea, Mode));
|
areaWidgets.insert(BottomDockWidgetArea, d->createDropIndicatorWidget(BottomDockWidgetArea, Mode));
|
||||||
areaWidgets.insert(LeftDockWidgetArea, d->createDropIndicatorWidget(LeftDockWidgetArea, Mode));
|
areaWidgets.insert(LeftDockWidgetArea, d->createDropIndicatorWidget(LeftDockWidgetArea, Mode));
|
||||||
areaWidgets.insert(CenterDockWidgetArea, d->createDropIndicatorWidget(CenterDockWidgetArea, Mode));
|
areaWidgets.insert(CenterDockWidgetArea, d->createDropIndicatorWidget(CenterDockWidgetArea, Mode));
|
||||||
|
d->LastDevicePixelRatio = devicePixelRatioF();
|
||||||
|
|
||||||
setAreaWidgets(areaWidgets);
|
setAreaWidgets(areaWidgets);
|
||||||
d->UpdateRequired = false;
|
d->UpdateRequired = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CDockOverlayCross::updateOverlayIcons()
|
||||||
|
{
|
||||||
|
if (windowHandle()->devicePixelRatio() == d->LastDevicePixelRatio)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto Widget : d->DropIndicatorWidgets)
|
||||||
|
{
|
||||||
|
d->updateDropIndicatorIcon(Widget);
|
||||||
|
}
|
||||||
|
d->LastDevicePixelRatio = devicePixelRatioF();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockOverlayCross::setIconColor(eIconColor ColorIndex, const QColor& Color)
|
void CDockOverlayCross::setIconColor(eIconColor ColorIndex, const QColor& Color)
|
||||||
{
|
{
|
||||||
|
@ -214,6 +214,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setupOverlayCross(CDockOverlay::eMode Mode);
|
void setupOverlayCross(CDockOverlay::eMode Mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recreates the overlay icons.
|
||||||
|
*/
|
||||||
|
void updateOverlayIcons();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets and updates the
|
* Resets and updates the
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user