mirror of
https://invent.kde.org/system/dolphin
synced 2024-07-15 18:01:11 +00:00
Merge branch 'davidedmundson/highdpi'
REVIEW: 123137
This commit is contained in:
commit
4ed0b82b02
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
|
||||
// #define KFILEITEMLISTVIEW_DEBUG
|
||||
|
||||
|
@ -154,8 +156,10 @@ QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const
|
|||
yCount = xCount;
|
||||
}
|
||||
|
||||
const qreal dpr = scene()->views()[0]->devicePixelRatio();
|
||||
// Draw the selected items into the grid cells.
|
||||
QPixmap dragPixmap(xCount * size + xCount, yCount * size + yCount);
|
||||
QPixmap dragPixmap(QSize(xCount * size + xCount, yCount * size + yCount) * dpr);
|
||||
dragPixmap.setDevicePixelRatio(dpr);
|
||||
dragPixmap.fill(Qt::transparent);
|
||||
|
||||
QPainter painter(&dragPixmap);
|
||||
|
@ -168,7 +172,7 @@ QPixmap KFileItemListView::createDragPixmap(const KItemSet& indexes) const
|
|||
QIcon icon = QIcon::fromTheme(model()->data(index).value("iconName").toString());
|
||||
pixmap = icon.pixmap(size, size);
|
||||
} else {
|
||||
KPixmapModifier::scale(pixmap, QSize(size, size));
|
||||
KPixmapModifier::scale(pixmap, QSize(size, size) * dpr);
|
||||
}
|
||||
|
||||
painter.drawPixmap(x, y, pixmap);
|
||||
|
|
|
@ -501,7 +501,7 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
|
|||
const bool enlargingRequired = scaledPixmap.width() < contentSize.width() &&
|
||||
scaledPixmap.height() < contentSize.height();
|
||||
if (enlargingRequired) {
|
||||
QSize frameSize = scaledPixmap.size();
|
||||
QSize frameSize = scaledPixmap.size() / scaledPixmap.devicePixelRatio();
|
||||
frameSize.scale(m_iconSize, Qt::KeepAspectRatio);
|
||||
|
||||
QPixmap largeFrame(frameSize);
|
||||
|
@ -510,8 +510,8 @@ void KFileItemModelRolesUpdater::slotGotPreview(const KFileItem& item, const QPi
|
|||
KPixmapModifier::applyFrame(largeFrame, frameSize);
|
||||
|
||||
QPainter painter(&largeFrame);
|
||||
painter.drawPixmap((largeFrame.width() - scaledPixmap.width()) / 2,
|
||||
(largeFrame.height() - scaledPixmap.height()) / 2,
|
||||
painter.drawPixmap((largeFrame.width() - scaledPixmap.width() / scaledPixmap.devicePixelRatio()) / 2,
|
||||
(largeFrame.height() - scaledPixmap.height() / scaledPixmap.devicePixelRatio()) / 2,
|
||||
scaledPixmap);
|
||||
scaledPixmap = largeFrame;
|
||||
} else {
|
||||
|
|
|
@ -1168,7 +1168,7 @@ void KItemListController::startDragging()
|
|||
const QPixmap pixmap = m_view->createDragPixmap(selectedItems);
|
||||
drag->setPixmap(pixmap);
|
||||
|
||||
const QPoint hotSpot(pixmap.width() / 2, 0);
|
||||
const QPoint hotSpot((pixmap.width() / pixmap.devicePixelRatio()) / 2, 0);
|
||||
drag->setHotSpot(hotSpot);
|
||||
|
||||
drag->exec(Qt::MoveAction | Qt::CopyAction | Qt::LinkAction, Qt::CopyAction);
|
||||
|
|
|
@ -368,7 +368,8 @@ QRectF KItemListWidget::expansionToggleRect() const
|
|||
QPixmap KItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option,
|
||||
QWidget* widget)
|
||||
{
|
||||
QPixmap pixmap(size().toSize());
|
||||
QPixmap pixmap(size().toSize() * widget->devicePixelRatio());
|
||||
pixmap.setDevicePixelRatio(widget->devicePixelRatio());
|
||||
pixmap.fill(Qt::transparent);
|
||||
|
||||
QPainter painter(&pixmap);
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <QTextLayout>
|
||||
#include <QTextLine>
|
||||
#include <QPixmapCache>
|
||||
#include <QGuiApplication>
|
||||
|
||||
// #define KSTANDARDITEMLISTWIDGET_DEBUG
|
||||
|
||||
|
@ -342,6 +343,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic
|
|||
*/
|
||||
// Paint pixmap1 so that pixmap1 = m_pixmap * (1.0 - hoverOpacity())
|
||||
QPixmap pixmap1(m_pixmap.size());
|
||||
pixmap1.setDevicePixelRatio(m_pixmap.devicePixelRatio());
|
||||
pixmap1.fill(Qt::transparent);
|
||||
{
|
||||
QPainter p(&pixmap1);
|
||||
|
@ -351,6 +353,7 @@ void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphic
|
|||
|
||||
// Paint pixmap2 so that pixmap2 = m_hoverPixmap * hoverOpacity()
|
||||
QPixmap pixmap2(pixmap1.size());
|
||||
pixmap2.setDevicePixelRatio(pixmap1.devicePixelRatio());
|
||||
pixmap2.fill(Qt::transparent);
|
||||
{
|
||||
QPainter p(&pixmap2);
|
||||
|
@ -952,10 +955,11 @@ void KStandardItemListWidget::updatePixmapCache()
|
|||
}
|
||||
const QStringList overlays = values["iconOverlays"].toStringList();
|
||||
m_pixmap = pixmapForIcon(iconName, overlays, maxIconHeight);
|
||||
} else if (m_pixmap.width() != maxIconWidth || m_pixmap.height() != maxIconHeight) {
|
||||
|
||||
} else if (m_pixmap.width() / m_pixmap.devicePixelRatio() != maxIconWidth || m_pixmap.height() / m_pixmap.devicePixelRatio() != maxIconHeight) {
|
||||
// A custom pixmap has been applied. Assure that the pixmap
|
||||
// is scaled to the maximum available size.
|
||||
KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight));
|
||||
KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight) * qApp->devicePixelRatio());
|
||||
}
|
||||
|
||||
if (m_isCut) {
|
||||
|
@ -1351,9 +1355,10 @@ void KStandardItemListWidget::updateAdditionalInfoTextColor()
|
|||
|
||||
void KStandardItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap)
|
||||
{
|
||||
if (m_scaledPixmapSize != pixmap.size()) {
|
||||
if (m_scaledPixmapSize != pixmap.size() / pixmap.devicePixelRatio()) {
|
||||
QPixmap scaledPixmap = pixmap;
|
||||
KPixmapModifier::scale(scaledPixmap, m_scaledPixmapSize);
|
||||
KPixmapModifier::scale(scaledPixmap, m_scaledPixmapSize * qApp->devicePixelRatio());
|
||||
scaledPixmap.setDevicePixelRatio(qApp->devicePixelRatio());
|
||||
painter->drawPixmap(m_pixmapPos, scaledPixmap);
|
||||
|
||||
#ifdef KSTANDARDITEMLISTWIDGET_DEBUG
|
||||
|
@ -1435,6 +1440,7 @@ void KStandardItemListWidget::closeRoleEditor()
|
|||
|
||||
QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStringList& overlays, int size)
|
||||
{
|
||||
size *= qApp->devicePixelRatio();
|
||||
const QString key = "KStandardItemListWidget:" % name % ":" % overlays.join(":") % ":" % QString::number(size);
|
||||
QPixmap pixmap;
|
||||
|
||||
|
@ -1460,7 +1466,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin
|
|||
requestedSize = size;
|
||||
}
|
||||
|
||||
pixmap = icon.pixmap(requestedSize, requestedSize);
|
||||
pixmap = icon.pixmap(requestedSize / qApp->devicePixelRatio(), requestedSize / qApp->devicePixelRatio());
|
||||
if (requestedSize != size) {
|
||||
KPixmapModifier::scale(pixmap, QSize(size, size));
|
||||
}
|
||||
|
@ -1481,6 +1487,7 @@ QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStrin
|
|||
|
||||
QPixmapCache::insert(key, pixmap);
|
||||
}
|
||||
pixmap.setDevicePixelRatio(qApp->devicePixelRatio());
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
|
|
@ -242,7 +242,7 @@ private:
|
|||
Layout m_layout;
|
||||
QPointF m_pixmapPos;
|
||||
QPixmap m_pixmap;
|
||||
QSize m_scaledPixmapSize;
|
||||
QSize m_scaledPixmapSize; //Size of the pixmap in device independent pixels
|
||||
|
||||
QRectF m_iconRect; // Cache for KItemListWidget::iconRect()
|
||||
QPixmap m_hoverPixmap; // Cache for modified m_pixmap when hovering the item
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QSize>
|
||||
#include <QGuiApplication>
|
||||
|
||||
|
||||
#include <config-X11.h> // for HAVE_XRENDER
|
||||
|
@ -347,6 +348,7 @@ void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize)
|
|||
}};
|
||||
|
||||
QPixmap scaledPixmap(scaledPixmapSize);
|
||||
scaledPixmap.setDevicePixelRatio(pixmap.devicePixelRatio());
|
||||
scaledPixmap.fill(Qt::transparent);
|
||||
|
||||
Display* dpy = QX11Info::display();
|
||||
|
@ -364,27 +366,32 @@ void KPixmapModifier::scale(QPixmap& pixmap, const QSize& scaledSize)
|
|||
pixmap = pixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
#else
|
||||
qreal dpr = pixmap.devicePixelRatio();
|
||||
pixmap = pixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
pixmap.setDevicePixelRatio(dpr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void KPixmapModifier::applyFrame(QPixmap& icon, const QSize& scaledSize)
|
||||
{
|
||||
static TileSet tileSet;
|
||||
qreal dpr = qApp->devicePixelRatio();
|
||||
|
||||
// Resize the icon to the maximum size minus the space required for the frame
|
||||
const QSize size(scaledSize.width() - TileSet::LeftMargin - TileSet::RightMargin,
|
||||
scaledSize.height() - TileSet::TopMargin - TileSet::BottomMargin);
|
||||
scale(icon, size);
|
||||
scale(icon, size * dpr);
|
||||
icon.setDevicePixelRatio(dpr);
|
||||
|
||||
QPixmap framedIcon(icon.size().width() + TileSet::LeftMargin + TileSet::RightMargin,
|
||||
icon.size().height() + TileSet::TopMargin + TileSet::BottomMargin);
|
||||
QPixmap framedIcon(icon.size().width() + (TileSet::LeftMargin + TileSet::RightMargin) * dpr,
|
||||
icon.size().height() + (TileSet::TopMargin + TileSet::BottomMargin) * dpr);
|
||||
framedIcon.setDevicePixelRatio(dpr);
|
||||
framedIcon.fill(Qt::transparent);
|
||||
|
||||
QPainter painter;
|
||||
painter.begin(&framedIcon);
|
||||
painter.setCompositionMode(QPainter::CompositionMode_Source);
|
||||
tileSet.paint(&painter, framedIcon.rect());
|
||||
tileSet.paint(&painter, QRect(QPoint(0,0), framedIcon.size() / dpr));
|
||||
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
|
||||
painter.drawPixmap(TileSet::LeftMargin, TileSet::TopMargin, icon);
|
||||
|
||||
|
|
|
@ -28,8 +28,26 @@ class QSize;
|
|||
class DOLPHIN_EXPORT KPixmapModifier
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Scale a pixmap to a given size.
|
||||
* @arg scaledSize is assumed to be the scaled to the same device pixel ratio as the source pixmap
|
||||
* @arg scaledSize is in device pixels
|
||||
*/
|
||||
static void scale(QPixmap& pixmap, const QSize& scaledSize);
|
||||
|
||||
/**
|
||||
* Resize and paint a frame round an icon
|
||||
* @arg scaledSize is in device-independent pixels
|
||||
* The returned image will be scaled by the application devicePixelRatio
|
||||
*/
|
||||
static void applyFrame(QPixmap& icon, const QSize& scaledSize);
|
||||
|
||||
/**
|
||||
* return and paint a frame round an icon
|
||||
* @arg framesize is in device-independent pixels
|
||||
* @return is in device-indepent pixels
|
||||
*/
|
||||
|
||||
static QSize sizeInsideFrame(const QSize& frameSize);
|
||||
};
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv)
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
Kdelibs4ConfigMigrator migrate(QStringLiteral("dolphin"));
|
||||
migrate.setConfigFiles(QStringList() << QStringLiteral("dolphinrc"));
|
||||
migrate.setUiFiles(QStringList() << QStringLiteral("dolphinpart.rc") << QStringLiteral("dolphinui.rc"));
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QStyle>
|
||||
|
||||
PixmapViewer::PixmapViewer(QWidget* parent, Transition transition) :
|
||||
QWidget(parent),
|
||||
|
@ -94,9 +95,6 @@ void PixmapViewer::paintEvent(QPaintEvent* event)
|
|||
const int scaledWidth = static_cast<int>((m_oldPixmap.width() * (1.0 - value)) + (m_pixmap.width() * value));
|
||||
const int scaledHeight = static_cast<int>((m_oldPixmap.height() * (1.0 - value)) + (m_pixmap.height() * value));
|
||||
|
||||
const int x = (width() - scaledWidth ) / 2;
|
||||
const int y = (height() - scaledHeight) / 2;
|
||||
|
||||
const bool useOldPixmap = (m_transition == SizeTransition) &&
|
||||
(m_oldPixmap.width() > m_pixmap.width());
|
||||
const QPixmap& largePixmap = useOldPixmap ? m_oldPixmap : m_pixmap;
|
||||
|
@ -105,12 +103,11 @@ void PixmapViewer::paintEvent(QPaintEvent* event)
|
|||
scaledHeight,
|
||||
Qt::IgnoreAspectRatio,
|
||||
Qt::FastTransformation);
|
||||
painter.drawPixmap(x, y, scaledPixmap);
|
||||
|
||||
style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, scaledPixmap);
|
||||
}
|
||||
} else {
|
||||
const int x = (width() - m_pixmap.width() ) / 2;
|
||||
const int y = (height() - m_pixmap.height()) / 2;
|
||||
painter.drawPixmap(x, y, m_pixmap);
|
||||
style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, m_pixmap);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue