summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2016-12-20 11:19:22 +0100
committerhjk <hjk@qt.io>2017-11-16 10:28:49 +0000
commitcdaa4aee1a5caa411b4f790ce1d6834da281eb54 (patch)
treedcc5aec6543511fbed236e66329aee7e9517c86d
parentf58a617ea9a593656cbf1ab82825c5c5026d9d77 (diff)
downloadqt-creator-cdaa4aee1a5caa411b4f790ce1d6834da281eb54.tar.gz
Add some mechanism to help screenshot creation
If QTC_SCREENSHOTS_PATH points to a writable directory, each widget that has been registered with ICore's setupScreenShooter(const QString &name, QWidget *w) will dump a screen shot to this directory as soon as the widget is shown. Change-Id: I2dec12064f1bb3c510d2fd9d27c1b79f7b7d5f30 Reviewed-by: Jake Petroules <jake.petroules@qt.io>
-rw-r--r--src/plugins/coreplugin/dialogs/settingsdialog.cpp1
-rw-r--r--src/plugins/coreplugin/icore.cpp51
-rw-r--r--src/plugins/coreplugin/icore.h2
3 files changed, 54 insertions, 0 deletions
diff --git a/src/plugins/coreplugin/dialogs/settingsdialog.cpp b/src/plugins/coreplugin/dialogs/settingsdialog.cpp
index 1d1ac06ac3..dca59526dd 100644
--- a/src/plugins/coreplugin/dialogs/settingsdialog.cpp
+++ b/src/plugins/coreplugin/dialogs/settingsdialog.cpp
@@ -568,6 +568,7 @@ void SettingsDialog::ensureCategoryWidget(Category *category)
for (int j = 0; j < category->pages.size(); ++j) {
IOptionsPage *page = category->pages.at(j);
QWidget *widget = page->widget();
+ ICore::setupScreenShooter(page->displayName(), widget);
SmartScrollArea *ssa = new SmartScrollArea(this);
ssa->setWidget(widget);
widget->setAutoFillBackground(false);
diff --git a/src/plugins/coreplugin/icore.cpp b/src/plugins/coreplugin/icore.cpp
index ab2a7f9770..550321396e 100644
--- a/src/plugins/coreplugin/icore.cpp
+++ b/src/plugins/coreplugin/icore.cpp
@@ -290,6 +290,7 @@
#include <QDebug>
#include <QDir>
#include <QStatusBar>
+#include <QTimer>
using namespace Core::Internal;
using namespace ExtensionSystem;
@@ -578,6 +579,56 @@ QString ICore::systemInformation()
return result;
}
+static const QByteArray &screenShotsPath()
+{
+ static const QByteArray path = qgetenv("QTC_SCREENSHOTS_PATH");
+ return path;
+}
+
+class ScreenShooter : public QObject
+{
+public:
+ ScreenShooter(QWidget *widget, const QString &name, const QRect &rc)
+ : m_widget(widget), m_name(name), m_rc(rc)
+ {
+ m_widget->installEventFilter(this);
+ }
+
+ bool eventFilter(QObject *watched, QEvent *event) override
+ {
+ QTC_ASSERT(watched == m_widget, return false);
+ if (event->type() == QEvent::Show)
+ QTimer::singleShot(0, this, &ScreenShooter::helper);
+ return false;
+ }
+
+ void helper()
+ {
+ if (m_widget) {
+ QRect rc = m_rc.isValid() ? m_rc : m_widget->rect();
+ QPixmap pm = m_widget->grab(rc);
+ for (int i = 0; ; ++i) {
+ QString fileName = screenShotsPath() + '/' + m_name + QString("-%1.png").arg(i);
+ if (!QFileInfo::exists(fileName)) {
+ pm.save(fileName);
+ break;
+ }
+ }
+ }
+ deleteLater();
+ }
+
+ QPointer<QWidget> m_widget;
+ QString m_name;
+ QRect m_rc;
+};
+
+void ICore::setupScreenShooter(const QString &name, QWidget *w, const QRect &rc)
+{
+ if (!screenShotsPath().isEmpty())
+ new ScreenShooter(w, name, rc);
+}
+
void ICore::saveSettings()
{
emit m_instance->saveSettingsRequested();
diff --git a/src/plugins/coreplugin/icore.h b/src/plugins/coreplugin/icore.h
index 89c6ada180..c05db031eb 100644
--- a/src/plugins/coreplugin/icore.h
+++ b/src/plugins/coreplugin/icore.h
@@ -29,6 +29,7 @@
#include "id.h"
#include <QObject>
+#include <QRect>
#include <QSettings>
#include <functional>
@@ -130,6 +131,7 @@ public:
static void addPreCloseListener(const std::function<bool()> &listener);
static QString systemInformation();
+ static void setupScreenShooter(const QString &name, QWidget *w, const QRect &rc = QRect());
public slots:
static void saveSettings();