aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools/screenshotcropper/screenshotcropperwindow.cpp
diff options
context:
space:
mode:
authorAlessandro Portale <alessandro.portale@nokia.com>2011-11-24 15:14:53 +0100
committerAlessandro Portale <alessandro.portale@nokia.com>2011-11-25 17:12:58 +0100
commit6c36a2a9ad5e495d31c2e20e7e76e57a0ede684f (patch)
tree99e1d8ce8543fa6982b37826f8dadb0ed1979cd9 /src/tools/screenshotcropper/screenshotcropperwindow.cpp
parent9e0cae5dac4d388caa948205a8e72cda199a213f (diff)
Cropping the examples screen shots to "Areas of interest".
The cropping coordinates are stored in a file images_areasofinterest.xml. A tool to create/maintain the cropping coordinates is included in this patch. Then changes to Delegate.qml prevent QML from scaling the image. If scaling is needed it is now the job of the Image provider. dropshadow.png had to be adjusted because the border had different widths and heights. Change-Id: Ib25db896d40eeec0e0a373c971931dc5cabf3cbe Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
Diffstat (limited to 'src/tools/screenshotcropper/screenshotcropperwindow.cpp')
-rw-r--r--src/tools/screenshotcropper/screenshotcropperwindow.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/tools/screenshotcropper/screenshotcropperwindow.cpp b/src/tools/screenshotcropper/screenshotcropperwindow.cpp
new file mode 100644
index 0000000000..524b5f00dc
--- /dev/null
+++ b/src/tools/screenshotcropper/screenshotcropperwindow.cpp
@@ -0,0 +1,53 @@
+#include "screenshotcropperwindow.h"
+#include "ui_screenshotcropperwindow.h"
+#include <QtGui/QListWidget>
+#include <QtCore/QDebug>
+
+using namespace QtSupport::Internal;
+
+ScreenShotCropperWindow::ScreenShotCropperWindow(QWidget *parent)
+ : QMainWindow(parent)
+ , ui(new Ui::ScreenShotCropperWindow)
+{
+ ui->setupUi(this);
+ connect(ui->m_filenamesList, SIGNAL(currentRowChanged(int)), SLOT(selectImage(int)));
+ connect(ui->m_cropImageView, SIGNAL(cropAreaChanged(QRect)), SLOT(setArea(QRect)));
+ connect(ui->m_buttonBox, SIGNAL(accepted()), SLOT(saveData()));
+ connect(ui->m_buttonBox, SIGNAL(rejected()), SLOT(close()));
+}
+
+ScreenShotCropperWindow::~ScreenShotCropperWindow()
+{
+ delete ui;
+}
+
+void ScreenShotCropperWindow::loadData(const QString &areasXmlFile, const QString &imagesFolder)
+{
+ m_areasOfInterestFile = areasXmlFile;
+ m_areasOfInterest = ScreenshotCropper::loadAreasOfInterest(m_areasOfInterestFile);
+ m_imagesFolder = imagesFolder;
+ foreach (const QString &pngFile, m_areasOfInterest.keys())
+ ui->m_filenamesList->addItem(pngFile);
+}
+
+void ScreenShotCropperWindow::selectImage(int index)
+{
+ const QString fileName = ui->m_filenamesList->item(index)->text();
+ ui->m_cropImageView->setImage(QImage(m_imagesFolder + QLatin1Char('/') + fileName));
+ ui->m_cropImageView->setArea(m_areasOfInterest.value(fileName));
+}
+
+void ScreenShotCropperWindow::setArea(const QRect &area)
+{
+ const QListWidgetItem *item = ui->m_filenamesList->currentItem();
+ if (!item)
+ return;
+ const QString currentFile = item->text();
+ m_areasOfInterest.insert(currentFile, area);
+}
+
+void ScreenShotCropperWindow::saveData()
+{
+ if (!ScreenshotCropper::saveAreasOfInterest(m_areasOfInterestFile, m_areasOfInterest))
+ qFatal("Cannot write %s", qPrintable(m_areasOfInterestFile));
+}