Commit daebbcf5 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

Manual test qcursorhighdpi: Add drag and drop.


Add dragging functionality to the labels showing a pixmap
cursor, allowing for testing DnD with pixmaps with device pixel ratio.

Task-number: QTBUG-46068
Task-number: QTBUG-50938
Change-Id: If6781f380864e614efd4328e8b880b57cd900511
Reviewed-by: default avatarMorten Johan Sørvig <morten.sorvig@theqtcompany.com>
parent 8d169943
No related merge requests found
Showing with 66 additions and 3 deletions
...@@ -44,10 +44,12 @@ ...@@ -44,10 +44,12 @@
#include <QBitmap> #include <QBitmap>
#include <QCursor> #include <QCursor>
#include <QDrag>
#include <QPainter> #include <QPainter>
#include <QPixmap> #include <QPixmap>
#include <QDebug> #include <QDebug>
#include <QMimeData>
#include <QStringList> #include <QStringList>
#include <QTextStream> #include <QTextStream>
...@@ -68,6 +70,14 @@ ...@@ -68,6 +70,14 @@
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#if QT_VERSION < 0x050000
QDebug operator<<(QDebug d, const QPixmap &p)
{
d.nospace() << "QPixmap(" << p.size() << ')';
return d;
}
#endif // Qt 4
// High DPI cursor test for testing cursor sizes in multi-screen setups. // High DPI cursor test for testing cursor sizes in multi-screen setups.
// It creates one widget per screen with a grid of standard cursors, // It creates one widget per screen with a grid of standard cursors,
// pixmap / bitmap cursors and pixmap / bitmap cursors with device pixel ratio 2. // pixmap / bitmap cursors and pixmap / bitmap cursors with device pixel ratio 2.
...@@ -159,6 +169,49 @@ static QCursor bitmapCursorDevicePixelRatio(int size, int dpr) ...@@ -159,6 +169,49 @@ static QCursor bitmapCursorDevicePixelRatio(int size, int dpr)
} }
#endif // Qt 5 #endif // Qt 5
// A label from which a pixmap can be dragged for testing drag with pixmaps/DPR.
class DraggableLabel : public QLabel {
public:
explicit DraggableLabel(const QPixmap &p, const QString &text, QWidget *parent = Q_NULLPTR)
: QLabel(text, parent), m_pixmap(p)
{
setToolTip(QLatin1String("Click to drag away the pixmap. Press Shift to set a circular mask."));
}
protected:
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
private:
const QPixmap m_pixmap;
};
void DraggableLabel::mousePressEvent(QMouseEvent *)
{
QMimeData *mimeData = new QMimeData;
mimeData->setImageData(qVariantFromValue(m_pixmap));
QDrag *drag = new QDrag(this);
QPixmap pixmap = m_pixmap;
if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
QBitmap mask(pixmap.width(), pixmap.height());
mask.clear();
QPainter painter(&mask);
painter.setBrush(Qt::color1);
const int hx = pixmap.width() / 2;
const int hy = pixmap.width() / 2;
painter.drawEllipse(QPoint(hx, hy), hx, hy);
pixmap.setMask(mask);
}
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
QPoint sizeP = QPoint(m_pixmap.width(), m_pixmap.height());
#if QT_VERSION > 0x050000
sizeP /= int(m_pixmap.devicePixelRatio());
#endif // Qt 5
drag->setHotSpot(sizeP / 2);
qDebug() << "Dragging:" << m_pixmap;
drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
}
// Vertical ruler widget with 10 px marks // Vertical ruler widget with 10 px marks
class VerticalRuler : public QWidget { class VerticalRuler : public QWidget {
public: public:
...@@ -210,8 +263,15 @@ static QLabel *createCursorLabel(const QCursor &cursor, const QString &additiona ...@@ -210,8 +263,15 @@ static QLabel *createCursorLabel(const QCursor &cursor, const QString &additiona
#endif // Qt 5 #endif // Qt 5
if (!additionalText.isEmpty()) if (!additionalText.isEmpty())
labelText += ' ' + additionalText; labelText += ' ' + additionalText;
QLabel *result = new QLabel(labelText); const QPixmap cursorPixmap = cursor.pixmap();
result->setFrameShape(QFrame::Box); QLabel *result = Q_NULLPTR;
if (cursorPixmap.size().isEmpty()) {
result = new QLabel(labelText);
result->setFrameShape(QFrame::Box);
} else {
result = new DraggableLabel(cursor.pixmap(), labelText);
result->setFrameShape(QFrame::StyledPanel);
}
result->setCursor(cursor); result->setCursor(cursor);
return result; return result;
} }
...@@ -304,7 +364,10 @@ int main(int argc, char *argv[]) ...@@ -304,7 +364,10 @@ int main(int argc, char *argv[])
QDesktopWidget *desktopWidget = app.desktop(); QDesktopWidget *desktopWidget = app.desktop();
for (int s = desktopWidget->screenCount() - 1; s >= 0; --s) { const int lastScreen = arguments.contains("-p")
? 0 // Primary screen only
: desktopWidget->screenCount() - 1; // All screens
for (int s = lastScreen; s >= 0; --s) {
MainWindowPtr window(new MainWindow(desktopWidget->screen(s))); MainWindowPtr window(new MainWindow(desktopWidget->screen(s)));
const QPoint pos = desktopWidget->screenGeometry(s).center() - QPoint(200, 100); const QPoint pos = desktopWidget->screenGeometry(s).center() - QPoint(200, 100);
window->move(pos); window->move(pos);
......
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