summaryrefslogtreecommitdiffstats
path: root/tests/manual/qcursor
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-04-22 09:31:58 +0200
committerLiang Qi <liang.qi@qt.io>2016-04-25 14:03:45 +0200
commitbb4b86618dc930e0035c5829e336f2606d140ada (patch)
tree6e36808ca46244373bc70aabbb926cc114538beb /tests/manual/qcursor
parent276adc5a09914fd89d976bb90cc0cd67de9d3d6e (diff)
parentbbd1228b17ee3f3a5483f88b0a581d6a60c41cad (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: config.tests/unix/compile.test configure src/android/jar/src/org/qtproject/qt5/android/QtMessageDialogHelper.java src/corelib/global/qglobal.cpp src/widgets/kernel/qapplication.cpp src/widgets/styles/qwindowsvistastyle.cpp tests/auto/corelib/kernel/qobject/tst_qobject.cpp Change-Id: I067083f34e5290aa5f7565e40c30a069cc37b83a
Diffstat (limited to 'tests/manual/qcursor')
-rw-r--r--tests/manual/qcursor/qcursorhighdpi/main.cpp69
1 files changed, 66 insertions, 3 deletions
diff --git a/tests/manual/qcursor/qcursorhighdpi/main.cpp b/tests/manual/qcursor/qcursorhighdpi/main.cpp
index 13c414fbbb..4a7646c39d 100644
--- a/tests/manual/qcursor/qcursorhighdpi/main.cpp
+++ b/tests/manual/qcursor/qcursorhighdpi/main.cpp
@@ -39,10 +39,12 @@
#include <QBitmap>
#include <QCursor>
+#include <QDrag>
#include <QPainter>
#include <QPixmap>
#include <QDebug>
+#include <QMimeData>
#include <QStringList>
#include <QTextStream>
@@ -63,6 +65,14 @@
#include <algorithm>
#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.
// It creates one widget per screen with a grid of standard cursors,
// pixmap / bitmap cursors and pixmap / bitmap cursors with device pixel ratio 2.
@@ -154,6 +164,49 @@ static QCursor bitmapCursorDevicePixelRatio(int size, int dpr)
}
#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
class VerticalRuler : public QWidget {
public:
@@ -205,8 +258,15 @@ static QLabel *createCursorLabel(const QCursor &cursor, const QString &additiona
#endif // Qt 5
if (!additionalText.isEmpty())
labelText += ' ' + additionalText;
- QLabel *result = new QLabel(labelText);
- result->setFrameShape(QFrame::Box);
+ const QPixmap cursorPixmap = cursor.pixmap();
+ 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);
return result;
}
@@ -299,7 +359,10 @@ int main(int argc, char *argv[])
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)));
const QPoint pos = desktopWidget->screenGeometry(s).center() - QPoint(200, 100);
window->move(pos);