diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-02-17 10:22:27 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-02-17 09:46:09 +0000 |
commit | 0285e3ad511882b3cfb87fc06ffbf5775c01437b (patch) | |
tree | c611db568230bed7d0974ce7615bfc65819011fc /src/pixeltool | |
parent | fa8e64b2b364f1a0139dd7dd50fb97ecfc70ceec (diff) |
Pixeltool: Add "About Pixeltool" displaying copyright and screen info
Change-Id: Iea12f257eba1083a31493fff4b88e058af8969f9
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/pixeltool')
-rw-r--r-- | src/pixeltool/qpixeltool.cpp | 44 | ||||
-rw-r--r-- | src/pixeltool/qpixeltool.h | 2 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/pixeltool/qpixeltool.cpp b/src/pixeltool/qpixeltool.cpp index 6fcaefb85..6e4c9f9ff 100644 --- a/src/pixeltool/qpixeltool.cpp +++ b/src/pixeltool/qpixeltool.cpp @@ -44,7 +44,10 @@ #include <qmenu.h> #include <qactiongroup.h> #include <qimagewriter.h> +#include <qscreen.h> #include <qstandardpaths.h> +#include <qtextstream.h> +#include <qwindow.h> #include <private/qhighdpiscaling_p.h> #include <qdebug.h> @@ -263,6 +266,9 @@ void QPixelTool::keyPressEvent(QKeyEvent *e) case Qt::Key_Control: grabKeyboard(); break; + case Qt::Key_F1: + aboutPixelTool(); + break; } } @@ -379,6 +385,7 @@ void QPixelTool::contextMenuEvent(QContextMenuEvent *e) menu.addSeparator(); menu.addAction(QLatin1String("About Qt"), qApp, &QApplication::aboutQt); + menu.addAction(QLatin1String("About Qt Pixeltool"), this, &QPixelTool::aboutPixelTool); menu.exec(mapToGlobal(e->pos())); @@ -563,4 +570,41 @@ void QPixelTool::saveToFile() m_freeze = oldFreeze; } +QTextStream &operator<<(QTextStream &str, const QScreen *screen) +{ + const QRect geometry = screen->geometry(); + str << '"' << screen->name() << "\" " << geometry.width() + << 'x' << geometry.height() << forcesign << geometry.x() << geometry.y() + << noforcesign << ", " << qRound(screen->logicalDotsPerInch()) << "DPI" + << ", Depth: " << screen->depth() << ", " << screen->refreshRate() << "Hz"; + const qreal dpr = screen->devicePixelRatio(); + if (!qFuzzyCompare(dpr, qreal(1))) + str << ", DPR: " << dpr; + return str; +} + +QString QPixelTool::aboutText() const +{ + const QList<QScreen *> screens = QGuiApplication::screens(); + const QScreen *windowScreen = windowHandle()->screen(); + + QString result; + QTextStream str(&result); + str << "<html></head><body><h2>Qt Pixeltool</h2><p>Qt " << QT_VERSION_STR + << "</p><p>Copyright (C) 2017 The Qt Company Ltd.</p><h3>Screens</h3><ul>"; + for (const QScreen *screen : screens) + str << "<li>" << (screen == windowScreen ? "* " : " ") << screen << "</li>"; + str << "<ul></body></html>"; + return result; +} + +void QPixelTool::aboutPixelTool() +{ + QMessageBox aboutBox(QMessageBox::Information, tr("About Qt Pixeltool"), aboutText(), + QMessageBox::Close, this); + aboutBox.setWindowFlags(aboutBox.windowFlags() & ~Qt::WindowContextHelpButtonHint); + aboutBox.setTextInteractionFlags(Qt::TextBrowserInteraction); + aboutBox.exec(); +} + QT_END_NAMESPACE diff --git a/src/pixeltool/qpixeltool.h b/src/pixeltool/qpixeltool.h index 01f2e475c..13fcd356c 100644 --- a/src/pixeltool/qpixeltool.h +++ b/src/pixeltool/qpixeltool.h @@ -59,6 +59,7 @@ public slots: void decreaseGridSize() { setGridSize(m_gridSize - 1); } void increaseZoom() { setZoom(m_zoom + 1); } void decreaseZoom() { setZoom(m_zoom - 1); } + void aboutPixelTool(); protected: void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; @@ -75,6 +76,7 @@ private: void grabScreen(); void startZoomVisibleTimer(); void startGridSizeVisibleTimer(); + QString aboutText() const; bool m_freeze; bool m_displayZoom; |