Skip to content

Commit

Permalink
[screenshottool] Rotate capture image to match UI orientation
Browse files Browse the repository at this point in the history
The image created by screenshottool should be rotated to match the
orientation of the UI at capture.
  • Loading branch information
matthewvogt committed Jun 29, 2015
1 parent 15a536f commit b91cc2c
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/screenshotservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
** of this file.
**
****************************************************************************/
#include <QStandardPaths>
#include <QDateTime>
#include "hwcrenderstage.h"
#include "lipstickcompositor.h"
#include "screenshotservice.h"

#include <QDateTime>
#include <QGuiApplication>
#include <QImage>
#include <QScreen>
#include <QStandardPaths>
#include <QTransform>
#include <private/qquickwindow_p.h>
#include "hwcrenderstage.h"

ScreenshotService::ScreenshotService(QObject *parent) :
QObject(parent)
Expand All @@ -27,12 +31,23 @@ ScreenshotService::ScreenshotService(QObject *parent) :

void ScreenshotService::saveScreenshot(const QString &path)
{
if (LipstickCompositor::instance() != 0) {
QQuickWindowPrivate *wd = QQuickWindowPrivate::get(LipstickCompositor::instance());
if (LipstickCompositor *compositor = LipstickCompositor::instance()) {
QQuickWindowPrivate *wd = QQuickWindowPrivate::get(compositor);
HwcRenderStage *renderStage = (HwcRenderStage *) wd->customRenderStage;
if (renderStage)
renderStage->setBypassHwc(true);
LipstickCompositor::instance()->grabWindow().save(path.isEmpty() ? (QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/" + QDateTime::currentDateTime().toString("yyyyMMddhhmmss") + ".png") : path);

QImage grab(compositor->grabWindow());

int rotation(QGuiApplication::primaryScreen()->angleBetween(Qt::PrimaryOrientation, compositor->topmostWindowOrientation()));
if (rotation != 0) {
QTransform xform;
xform.rotate(rotation);
grab = grab.transformed(xform, Qt::SmoothTransformation);
}

grab.save(path.isEmpty() ? (QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + "/" + QDateTime::currentDateTime().toString("yyyyMMddhhmmss") + ".png") : path);

if (renderStage)
renderStage->setBypassHwc(false);
}
Expand Down

0 comments on commit b91cc2c

Please sign in to comment.