From cb142954c54b7a6e391950d9209b5cea9252092b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 14 Dec 2017 14:15:34 +0100 Subject: XCB: Implement native window dump for diaglib Extract a helper function to determine the window title from QXcbConnection and add an invokable function to the native interface that dumps the window tree similar to existing functionality on Windows. Change-Id: I5544d69ea2b801eb16d3b5b8d64021b3e567b0d8 Reviewed-by: Shawn Rutledge --- tests/manual/diaglib/nativewindowdump.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tests/manual') diff --git a/tests/manual/diaglib/nativewindowdump.cpp b/tests/manual/diaglib/nativewindowdump.cpp index 83edf878b3..a854e8a790 100644 --- a/tests/manual/diaglib/nativewindowdump.cpp +++ b/tests/manual/diaglib/nativewindowdump.cpp @@ -28,10 +28,25 @@ #include "nativewindowdump.h" +#if QT_VERSION >= 0x050000 +# include +# include +#endif + +#include + namespace QtDiag { -void dumpNativeWindows(WId) +void dumpNativeWindows(WId wid) { +#if QT_VERSION >= 0x050000 + QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface(); + QString result; + QMetaObject::invokeMethod(ni, "dumpNativeWindows", Qt::DirectConnection, + Q_RETURN_ARG(QString, result), + Q_ARG(WId, wid)); + qDebug().noquote() << result; +#endif // Qt 5 } void dumpNativeQtTopLevels() -- cgit v1.2.3 From cb612491b371675c6b028deabacf5c1492370330 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 23 Jan 2018 09:24:28 +0100 Subject: tests/manual/widgets/styles: Extend the style icon display Refactor the page displaying the standard pixmaps of a style: - Use a QGroupBox - Sort items by enumeration name Add a page displaying the standard icons along with the list of sizes. This allows for conveniently checking which resolutions are available. Change-Id: I2d7f655456fc3e7013c2582ad520b6ac582951e6 Reviewed-by: Richard Moe Gustavsen --- tests/manual/widgets/styles/main.cpp | 123 ++++++++++++++++++++++++++++------- 1 file changed, 101 insertions(+), 22 deletions(-) (limited to 'tests/manual') diff --git a/tests/manual/widgets/styles/main.cpp b/tests/manual/widgets/styles/main.cpp index 7df54baef5..43580ce781 100644 --- a/tests/manual/widgets/styles/main.cpp +++ b/tests/manual/widgets/styles/main.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,7 @@ #include #include #include +#include #include #include @@ -61,22 +63,67 @@ static inline QString formatEnumValue(Enum value) return result; } -static QString pixmapDescription(QStyle::StandardPixmap sp, const QPixmap &pixmap) +static QTextStream &operator<<(QTextStream &str, const QSize &s) { - QString description = formatEnumValue(sp); - QTextStream str(&description); - str << '(' << int(sp) << ") "; - if (pixmap.isNull()) { - str << "(null)"; - } else { - const qreal dpr = pixmap.devicePixelRatioF(); - str << ' ' << pixmap.width() << 'x' << pixmap.height(); - if (!qFuzzyCompare(dpr, qreal(1))) - str << " DPR=" << dpr; + str << s.width(); + if (s.width() != s.height()) + str << 'x' << s.height(); + return str; +} + +struct StyleIconEntry +{ + QString name; + QStyle::StandardPixmap pixmap; +}; + +static bool operator<(const StyleIconEntry &e1, const StyleIconEntry &e2) +{ + return e1.name < e2.name; +} + +static QVector styleIconEntries() +{ + QVector result; + const int count = int(QStyle::SP_LineEditClearButton) + 1; + result.reserve(count); + for (int i = 0; i < count; ++i) { + QStyle::StandardPixmap px = static_cast(i); + result.append({formatEnumValue(px), px}); } - return description; + std::sort(result.begin(), result.end()); + return result; } +class IconDisplayWidget : public QGroupBox +{ +public: + explicit IconDisplayWidget(const QString &title, const QString &text, + const QPixmap &pixmap, QWidget *p = nullptr); +}; + +IconDisplayWidget::IconDisplayWidget(const QString &title, const QString &text, + const QPixmap &pixmap, QWidget *p) + : QGroupBox(title, p) +{ + QHBoxLayout *hLayout = new QHBoxLayout(this); + hLayout->addWidget(new QLabel(text, this)); + QLabel *iconLabel = new QLabel(this); + iconLabel->setPixmap(pixmap); + hLayout->addWidget(iconLabel); +} + +static IconDisplayWidget *createStandardPixmapDisplay(const StyleIconEntry &e, QWidget *parent) +{ + QPixmap pixmap = parent->style()->standardPixmap(e.pixmap, nullptr, parent); + QString description; + QTextStream str(&description); + str << pixmap.size(); + return new IconDisplayWidget(e.name, description, pixmap, parent); +} + +enum : int { maxColumns = 6 }; + // Display pixmaps returned by QStyle::standardPixmap() in a grid. static QWidget *createStandardPixmapPage(QWidget *parent) { @@ -84,16 +131,47 @@ static QWidget *createStandardPixmapPage(QWidget *parent) QGridLayout *grid = new QGridLayout(result); int row = 0; int column = 0; - const int maxColumns = 6; - for (int i = 0; i <= int(QStyle::SP_LineEditClearButton); ++i) { - const QStyle::StandardPixmap sp = static_cast(i); - QPixmap pixmap = result->style()->standardPixmap(sp, nullptr, result); - QLabel *descriptionLabel = new QLabel(pixmapDescription(sp, pixmap)); - grid->addWidget(descriptionLabel, row, column++); - QLabel *displayLabel = new QLabel; - displayLabel->setPixmap(pixmap); - displayLabel->setFrameShape(QFrame::Box); - grid->addWidget(displayLabel, row, column++); + QVector entries = styleIconEntries(); + for (int i = 0, size = entries.size(); i < size; ++i) { + grid->addWidget(createStandardPixmapDisplay(entries.at(i), parent), row, column++); + if (column >= maxColumns) { + ++row; + column = 0; + } + } + return result; +} + +// Display icons returned by QStyle::standardIcon() in a grid. +static IconDisplayWidget *createStandardIconDisplay(const StyleIconEntry &e, + const QSize &displaySize, + QWidget *parent) +{ + QIcon icon = parent->style()->standardIcon(e.pixmap, nullptr, parent); + QString description; + QTextStream str(&description); + auto availableSizes = icon.availableSizes(); + std::sort(availableSizes.begin(), availableSizes.end(), + [](QSize s1, QSize s2) { return s1.width() < s2.width(); }); + for (int i =0; i < availableSizes.size(); ++i) { + if (i) + str << ','; + str << availableSizes.at(i); + } + return new IconDisplayWidget(e.name, description, icon.pixmap(displaySize), parent); +} + +static QWidget *createStandardIconPage(QWidget *parent) +{ + QWidget *result = new QWidget(parent); + QGridLayout *grid = new QGridLayout(result); + int row = 0; + int column = 0; + const int largeIconSize = parent->style()->pixelMetric(QStyle::PM_LargeIconSize); + const QSize displaySize(largeIconSize, largeIconSize); + QVector entries = styleIconEntries(); + for (int i = 0, size = entries.size(); i < size; ++i) { + grid->addWidget(createStandardIconDisplay(entries.at(i), displaySize, parent), row, column++); if (column >= maxColumns) { ++row; column = 0; @@ -190,6 +268,7 @@ MainWindow::MainWindow() QVBoxLayout *mainLayout = new QVBoxLayout(central); mainLayout->addWidget(m_descriptionLabel); mainLayout->addWidget(m_tabWidget); + m_tabWidget->addTab(createStandardIconPage(m_tabWidget), "Standard Icon"); m_tabWidget->addTab(createStandardPixmapPage(m_tabWidget), "Standard Pixmaps"); m_tabWidget->addTab(createHintsPage(m_tabWidget), "Hints"); m_tabWidget->addTab(createMetricsPage(m_tabWidget), "Pixel Metrics"); -- cgit v1.2.3