forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -568,6 +568,7 @@ void SettingsDialog::ensureCategoryWidget(Category *category)
|
|||||||
for (int j = 0; j < category->pages.size(); ++j) {
|
for (int j = 0; j < category->pages.size(); ++j) {
|
||||||
IOptionsPage *page = category->pages.at(j);
|
IOptionsPage *page = category->pages.at(j);
|
||||||
QWidget *widget = page->widget();
|
QWidget *widget = page->widget();
|
||||||
|
ICore::setupScreenShooter(page->displayName(), widget);
|
||||||
SmartScrollArea *ssa = new SmartScrollArea(this);
|
SmartScrollArea *ssa = new SmartScrollArea(this);
|
||||||
ssa->setWidget(widget);
|
ssa->setWidget(widget);
|
||||||
widget->setAutoFillBackground(false);
|
widget->setAutoFillBackground(false);
|
||||||
|
|||||||
@@ -290,6 +290,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
using namespace Core::Internal;
|
using namespace Core::Internal;
|
||||||
using namespace ExtensionSystem;
|
using namespace ExtensionSystem;
|
||||||
@@ -578,6 +579,56 @@ QString ICore::systemInformation()
|
|||||||
return result;
|
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()
|
void ICore::saveSettings()
|
||||||
{
|
{
|
||||||
emit m_instance->saveSettingsRequested();
|
emit m_instance->saveSettingsRequested();
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "id.h"
|
#include "id.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QRect>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -130,6 +131,7 @@ public:
|
|||||||
static void addPreCloseListener(const std::function<bool()> &listener);
|
static void addPreCloseListener(const std::function<bool()> &listener);
|
||||||
|
|
||||||
static QString systemInformation();
|
static QString systemInformation();
|
||||||
|
static void setupScreenShooter(const QString &name, QWidget *w, const QRect &rc = QRect());
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
static void saveSettings();
|
static void saveSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user