Commit cc616326 authored by Yunhe Guo's avatar Yunhe Guo
Browse files

HiDPI rendering improvement

Summary: Replace D23775. Without changes to fontMetrics

Reviewers: #kde_applications, aacid

Reviewed By: #kde_applications, aacid

Subscribers: #kde_applications, kde-utils-devel

Tags: #kde_applications

Differential Revision: https://phabricator.kde.org/D23993
parent cb65ab47
......@@ -67,6 +67,8 @@ int main(int argc, char *argv[])
app.setOrganizationName(QStringLiteral("KDE"));
app.setWindowIcon(QIcon::fromTheme(QStringLiteral(APP_NAME)));
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
QCommandLineParser options;
options.addHelpOption();
options.addVersionOption();
......
......@@ -108,15 +108,15 @@ void ProgressBox::paintEvent(QPaintEvent*)
tick+=16;
for (int i=0; i<PIECES_NUM; i++) {
const int size = qMin(width(), height()) * length[i];
const QRect rect(width() / 2 - size / 2, height() / 2 - size / 2, size, size);
const qreal size = qMin(width(), height()) * length[i];
const QRectF rect(width() / 2 - size / 2, height() / 2 - size / 2, size, size);
int angle = angleFactor[i] + tick*angleFactor[i];
QRadialGradient gradient(rect.center(), sin(angle/160.0f) * 100);
gradient.setColorAt(0, QColor::fromHsv(abs(angle/16) % 360 , 160, 255));
gradient.setColorAt(1, QColor::fromHsv(abs(angle/16) % 360 , 160, 128));
QBrush brush(gradient);
paint.setBrush(brush);
paint.drawPie(QRect(rect), angle, aLength[i]);
paint.drawPie(QRectF(rect), angle, aLength[i]);
}
paint.translate(0.5, 0.5);
......
......@@ -203,7 +203,7 @@ bool RadialMap::Map::build(const Folder * const dir, const uint depth, uint a_st
return false;
}
bool RadialMap::Map::resize(const QRect &newRect)
bool RadialMap::Map::resize(const QRectF &newRect)
{
//there's a MAP_2MARGIN border
......@@ -222,10 +222,11 @@ bool RadialMap::Map::resize(const QRect &newRect)
size = minSize;
}
//this QRect is used by paint()
//this QRectF is used by paint()
m_rect.setRect(0,0,size,size);
m_pixmap = QPixmap(m_rect.size());
m_pixmap = QPixmap(m_rect.width() * m_dpr, m_rect.height() * m_dpr);
m_pixmap.setDevicePixelRatio(m_dpr);
//resize the pixmap
size += MAP_2MARGIN;
......@@ -352,7 +353,7 @@ void RadialMap::Map::paint(bool antialias)
KColorScheme scheme(QPalette::Active, KColorScheme::View);
QPainter paint;
QRect rect = m_rect;
QRectF rect = m_rect;
rect.adjust(MAP_HIDDEN_TRIANGLE_SIZE, MAP_HIDDEN_TRIANGLE_SIZE, -MAP_HIDDEN_TRIANGLE_SIZE, -MAP_HIDDEN_TRIANGLE_SIZE);
m_pixmap.fill(Qt::transparent);
......@@ -381,7 +382,7 @@ void RadialMap::Map::paint(bool antialias)
//do intelligent distribution of excess to prevent nasty resizing
if (m_ringBreadth != MAX_RING_BREADTH && m_ringBreadth != MIN_RING_BREADTH) {
excess = rect.width() % m_ringBreadth;
excess = int(rect.width()) % m_ringBreadth;
++step;
}
......@@ -405,8 +406,8 @@ void RadialMap::Map::paint(bool antialias)
}
//draw arrow head to indicate undisplayed files/directories
QPolygon pts(3);
QPoint pos, cpos = rect.center();
QPolygonF pts;
QPointF pos, cpos = rect.center();
uint a[3] = { segment->start(), segment->length(), 0 };
a[2] = a[0] + (a[1] / 2); //assign to halfway between
......@@ -426,9 +427,9 @@ void RadialMap::Map::paint(bool antialias)
}
sincos(ra, &sinra, &cosra);
pos.rx() = cpos.x() + static_cast<int>(cosra * radius);
pos.ry() = cpos.y() - static_cast<int>(sinra * radius);
pts.setPoint(i, pos);
pos.rx() = cpos.x() + cosra * radius;
pos.ry() = cpos.y() - sinra * radius;
pts << pos;
}
paint.setBrush(segment->pen());
......@@ -440,7 +441,7 @@ void RadialMap::Map::paint(bool antialias)
int width = 2;
pen.setWidth(width);
paint.setPen(pen);
QRect rect2 = rect;
QRectF rect2 = rect;
width /= 2;
rect2.adjust(width, width, -width, -width);
paint.drawArc(rect2, segment->start(), segment->length());
......
......@@ -27,7 +27,7 @@
#include <KColorScheme>
#include <QPixmap>
#include <QRect>
#include <QRectF>
#include <QString>
namespace RadialMap {
......@@ -40,17 +40,17 @@ public:
~Map();
void make(const Folder *, bool = false);
bool resize(const QRect&);
bool resize(const QRectF&);
bool isNull() const {
return (m_signature == nullptr);
}
void invalidate();
int height() const {
qreal height() const {
return m_rect.height();
}
int width() const {
qreal width() const {
return m_rect.width();
}
QPixmap pixmap() const {
......@@ -72,13 +72,14 @@ private:
const Folder *m_root;
uint m_minSize;
QVector<FileSize> m_limits;
QRect m_rect;
QRectF m_rect;
uint m_visibleDepth; ///visible level depth of system
QPixmap m_pixmap;
int m_ringBreadth;
uint m_innerRadius; ///radius of inner circle
QString m_centerText;
bool m_summary;
qreal m_dpr;
uint MAP_2MARGIN;
};
......
......@@ -52,6 +52,7 @@ RadialMap::Widget::Widget(QWidget *parent, bool isSummary)
connect(&m_timer, &QTimer::timeout, this, &Widget::resizeTimeout);
m_tooltip.setFrameShape(QFrame::StyledPanel);
m_tooltip.setWindowFlags(Qt::ToolTip | Qt::WindowTransparentForInput);
m_map.m_dpr = devicePixelRatioF();
}
RadialMap::Widget::~Widget()
......
......@@ -98,7 +98,7 @@ protected:
void leaveEvent(QEvent*) override;
protected:
const Segment *segmentAt(QPoint position) const; //FIXME const reference for a library others can use
const Segment *segmentAt(QPointF position) const; //FIXME const reference for a library others can use
const Segment *rootSegment() const {
return m_rootSegment; ///never == 0
}
......@@ -111,7 +111,7 @@ private:
const Folder *m_tree;
const Segment *m_focus;
QPoint m_offset;
QPointF m_offset;
QTimer m_timer;
Map m_map;
Segment *m_rootSegment;
......
......@@ -88,9 +88,9 @@ void RadialMap::Widget::paintEvent(QPaintEvent*)
}
}
const RadialMap::Segment* RadialMap::Widget::segmentAt(QPoint e) const
const RadialMap::Segment* RadialMap::Widget::segmentAt(QPointF e) const
{
//determine which segment QPoint e is above
//determine which segment QPointF e is above
e -= m_offset;
......@@ -152,10 +152,10 @@ void RadialMap::Widget::mouseMoveEvent(QMouseEvent *e)
return;
}
const QRect screenRect = window()->windowHandle()->screen()->availableGeometry();
const QRectF screenRect = window()->windowHandle()->screen()->availableGeometry();
QPoint tooltipPosition = e->globalPos() + QPoint(20, 20);
QRect tooltipRect(tooltipPosition, m_tooltip.size());
QRectF tooltipRect(tooltipPosition, m_tooltip.size());
// Same content as before
if (m_focus == oldFocus) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment