summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunkyu Im <munkyu.im@samsung.com>2014-10-21 13:53:23 +0900
committerMunkyu Im <munkyu.im@samsung.com>2014-11-06 14:42:15 +0900
commit5bc50876a6c5a8be21d70d73b1d9f869636792f4 (patch)
tree43736cf22ad6e634530aa4534f0c5d9608c1d7ee
parenta37c930db54216876ff14fd9c7047a6038742b9b (diff)
downloadqemu-5bc50876a6c5a8be21d70d73b1d9f869636792f4.tar.gz
qemu-5bc50876a6c5a8be21d70d73b1d9f869636792f4.tar.bz2
qemu-5bc50876a6c5a8be21d70d73b1d9f869636792f4.zip
screenshot: Implement screenshot dialog
Added features - capture/refresh - copy to clipboard - save to file Change-Id: I532a3d08fd0a1515e5276c32d92bb9ddbc88f443 Signed-off-by: Vasily Ulyanov <v.ulyanov@samsung.com> Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
-rw-r--r--tizen/src/ui/mainwindow.cpp14
-rw-r--r--tizen/src/ui/mainwindow.h1
-rw-r--r--tizen/src/ui/menu/Makefile.objs8
-rw-r--r--tizen/src/ui/menu/contextmenu.cpp19
-rw-r--r--tizen/src/ui/menu/contextmenu.h5
-rw-r--r--tizen/src/ui/menu/screenshot.cpp187
-rw-r--r--tizen/src/ui/menu/screenshot.h54
-rw-r--r--tizen/src/ui/menu/screenshotview.cpp28
-rw-r--r--tizen/src/ui/menu/screenshotview.h21
-rw-r--r--tizen/src/ui/resource/icons/copy_screenshot_dialog.pngbin0 -> 3267 bytes
-rw-r--r--tizen/src/ui/resource/icons/refresh_screenshot_dialog.pngbin0 -> 3917 bytes
-rw-r--r--tizen/src/ui/resource/icons/save_screenshot_dialog.pngbin0 -> 3272 bytes
-rw-r--r--tizen/src/ui/resource/resource.qrc3
13 files changed, 329 insertions, 11 deletions
diff --git a/tizen/src/ui/mainwindow.cpp b/tizen/src/ui/mainwindow.cpp
index d514824774..da749c77f6 100644
--- a/tizen/src/ui/mainwindow.cpp
+++ b/tizen/src/ui/mainwindow.cpp
@@ -349,19 +349,21 @@ void MainWindow::unsetCaptureRequestHandler(void *data)
}
void MainWindow::processCaptured(bool captured, void *pixels,
- int width, int height)
+ int width, int height)
{
qDebug("window process captured: %d %p[%dx%d]",
- captured, pixels, width, height);
+ captured, pixels, width, height);
if (captured) {
- /* TODO Perform what is needed here */
- QString path("/tmp/screenshot.png");
QImage image = QImage((uchar *)pixels, width, height,
QImage::Format_RGB32);
- bool saved = image.save(path, "PNG");
+ QPixmap pixmap = QPixmap::fromImage(image); /* deep copy the data */
- qDebug() << path << " " << saved;
+ QMetaObject::invokeMethod(popupMenu, "slotShowScreenshot",
+ Qt::QueuedConnection,
+ Q_ARG(QPixmap, pixmap));
+
+ qDebug("Image saved: %p", pixels);
}
}
diff --git a/tizen/src/ui/mainwindow.h b/tizen/src/ui/mainwindow.h
index 6b50dcec6b..c944edc3b3 100644
--- a/tizen/src/ui/mainwindow.h
+++ b/tizen/src/ui/mainwindow.h
@@ -108,7 +108,6 @@ private:
SkinView* skinView;
DisplayBase *display;
ContextMenu *popupMenu;
-
QThread *swapperThread;
DisplaySwapper *swapper;
diff --git a/tizen/src/ui/menu/Makefile.objs b/tizen/src/ui/menu/Makefile.objs
index f5b5313760..137a92f927 100644
--- a/tizen/src/ui/menu/Makefile.objs
+++ b/tizen/src/ui/menu/Makefile.objs
@@ -1,6 +1,8 @@
obj-$(CONFIG_QT) += aboutdialog.o moc_aboutdialog.o
+obj-$(CONFIG_QT) += screenshot.o moc_screenshot.o
obj-$(CONFIG_QT) += detailedinfodialog.o moc_detailedinfodialog.o
obj-$(CONFIG_QT) += contextmenu.o moc_contextmenu.o
+obj-$(CONFIG_QT) += screenshotview.o moc_screenshotview.o
$(obj)/moc_aboutdialog.o: $(obj)/moc_aboutdialog.cpp
$(obj)/moc_aboutdialog.cpp: $(obj)/aboutdialog.h
@@ -11,3 +13,9 @@ $(obj)/moc_detailedinfodialog.cpp: $(obj)/detailedinfodialog.h
$(obj)/moc_contextmenu.o: $(obj)/moc_contextmenu.cpp
$(obj)/moc_contextmenu.cpp: $(obj)/contextmenu.h
moc $< -o $@
+$(obj)/moc_screenshot.o: $(obj)/moc_screenshot.cpp
+$(obj)/moc_screenshot.cpp: $(obj)/screenshot.h
+ moc $< -o $@
+$(obj)/moc_screenshotview.o: $(obj)/moc_screenshotview.cpp
+$(obj)/moc_screenshotview.cpp: $(obj)/screenshotview.h
+ moc $< -o $@ \ No newline at end of file
diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp
index 82a19c3128..21c6b9c544 100644
--- a/tizen/src/ui/menu/contextmenu.cpp
+++ b/tizen/src/ui/menu/contextmenu.cpp
@@ -45,6 +45,7 @@ ContextMenu::ContextMenu(QWidget *parent) : QMenu(parent)
this->parent = (MainWindow *)parent;
this->infoDialog = NULL;
this->aboutDialog = NULL;
+ this->screenshotDialog = NULL;
this->vmName = ((MainWindow *)parent)->uiInfo->vmName + " : "
+ QString::number(get_device_serial_number());
@@ -182,7 +183,7 @@ void ContextMenu::createItems() {
/* Advanced > Screen Shot menu */
action = advancedMenu->addAction("Screen Shot");
action->setIcon(QIcon(QPixmap(":/icons/screen_shot.png")));
- connect(action, SIGNAL(triggered()), this, SLOT(slotScreenshot()));
+ connect(action, SIGNAL(triggered()), this, SLOT(slotRequestScreenshot()));
/* = Host Keyboard menu = */
QMenu *keyboardMenu = advancedMenu->addMenu(
@@ -468,13 +469,25 @@ void ContextMenu::slotControlPanel()
}
}
-void ContextMenu::slotScreenshot()
+void ContextMenu::slotRequestScreenshot()
{
- qDebug("screenshot");
+ qDebug("request screenshot");
parent->capture();
}
+void ContextMenu::slotShowScreenshot(const QPixmap &screenshot)
+{
+ qDebug("show screenshot");
+
+ if (screenshotDialog == NULL) {
+ screenshotDialog = new Screenshot(this, screenshot);
+ }
+
+ screenshotDialog->refresh(screenshot);
+ screenshotDialog->show();
+}
+
void ContextMenu::slotHostKeyboard(bool on)
{
qDebug("host keyboard : %s", on? "on" : "off");
diff --git a/tizen/src/ui/menu/contextmenu.h b/tizen/src/ui/menu/contextmenu.h
index a8e4212f88..6b799cb854 100644
--- a/tizen/src/ui/menu/contextmenu.h
+++ b/tizen/src/ui/menu/contextmenu.h
@@ -35,6 +35,7 @@
#include "detailedinfodialog.h"
#include "aboutdialog.h"
+#include "screenshot.h"
class MainWindow;
@@ -57,6 +58,7 @@ public:
QSignalMapper *getRotateMapper();
QSignalMapper *getScaleMapper();
QSignalMapper *getControllerMapper();
+ Screenshot *screenshotDialog;
signals:
@@ -69,7 +71,8 @@ public slots:
void slotCloseCon();
void slotShell();
void slotControlPanel();
- void slotScreenshot();
+ void slotRequestScreenshot();
+ void slotShowScreenshot(const QPixmap &);
void slotHostKeyboard(bool on);
void slotAbout();
void slotForceClose();
diff --git a/tizen/src/ui/menu/screenshot.cpp b/tizen/src/ui/menu/screenshot.cpp
new file mode 100644
index 0000000000..0283e9b3a9
--- /dev/null
+++ b/tizen/src/ui/menu/screenshot.cpp
@@ -0,0 +1,187 @@
+#include <QtWidgets>
+#include <qtoolbutton.h>
+#include "screenshot.h"
+#include "screenshotview.h"
+#include "mainwindow.h"
+
+void Screenshot::copy() {
+ qDebug("copy");
+ QClipboard* clipboard = QApplication::clipboard();
+ QPixmap pixmap(screenshotPixmap);
+ clipboard->clear();
+ clipboard->setPixmap(pixmap);
+}
+
+QString Screenshot::getRatio() {
+ return ratioStr;
+}
+
+void Screenshot::setRatio(int level) {
+ switch (level) {
+ case 0:
+ ratio = 0.125;
+ break;
+ case 1:
+ ratio = 0.25;
+ break;
+ case 2:
+ ratio = 0.50;
+ break;
+ case 3:
+ ratio = 1;
+ break;
+ case 4:
+ ratio = 2;
+ break;
+ case 5:
+ ratio = 4;
+ break;
+ case 6:
+ ratio = 8;
+ break;
+ }
+ ratioStr = QString::number(ratio * 100).append("%");
+}
+
+void Screenshot::scaleChanged(int level) {
+ qDebug("scale changed: %d", level);
+ sliderLevel = level;
+ QPixmap pixmap(screenshotPixmap);
+
+ setRatio(level);
+ scene->clear();
+ scene->addPixmap(pixmap.scaled(pixmap.size() * ratio, Qt::KeepAspectRatio, Qt::FastTransformation));
+ slider->setToolTip(ratioStr);
+}
+
+int Screenshot::getSliderLevel() {
+ return sliderLevel;
+}
+
+void Screenshot::refresh(const QPixmap &pixmap) {
+ qDebug("refresh");
+
+ screenshotPixmap = pixmap;
+
+ ((ScreenshotView*)view)->setWidthHeight(screenshotPixmap.width(),
+ screenshotPixmap.height());
+ ratioStr = "100%";
+ slider->setValue(3);
+ scene->clear();
+ scene->addPixmap(screenshotPixmap);
+ slider->setToolTip(ratioStr);
+
+}
+
+void Screenshot::setStatusBar(QString messsage) {
+ statusBar->showMessage(messsage);
+}
+
+bool Screenshot::save() {
+ qDebug("save");
+ QString vmname = ((MainWindow *) this->parent()->parent())->uiInfo->vmName;
+ QDateTime currentDateTime = QDateTime::currentDateTime();
+ QString date = currentDateTime.toString("yyyy-MM-dd-HHmmss");
+ QString defaultFile = QDir::homePath() + QDir::separator() + vmname + "-" + date + ".png";
+ QString filterName = "Image files (*.png *.jpg *.jpeg *.bmp)";
+ QString filename = QFileDialog::getSaveFileName(this, "Save Image", defaultFile, filterName);
+
+ if(filename.isEmpty()) {
+ qDebug("can not have file");
+ return false;
+ } else {
+ QPixmap pixmap(screenshotPixmap);
+ qDebug() << filename;
+ pixmap.save(filename);
+ return true;
+ }
+}
+
+void Screenshot::makeWidgets() {
+ toolbar = new QToolBar(this);
+
+ slider = new QSlider(Qt::Horizontal, this);
+ slider->setRange(0, 6);
+ slider->setValue(3);
+ slider->setFixedWidth(100);
+ slider->setToolTip("100%");
+ connect(slider, SIGNAL(valueChanged(int)), this, SLOT(scaleChanged(int)));
+
+ gridlayout = new QGridLayout;
+ gridlayout->setContentsMargins(0, 0, 0, 0);
+
+ saveAct = new QAction(tr("&Save"), this);
+ saveAct->setShortcuts(QKeySequence::Save);
+ saveAct->setIcon(QIcon(":/icons/save_screenshot_dialog.png"));
+ saveAct->setToolTip("Save to file");
+ connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
+
+ copyAct = new QAction(tr("&Copy"), this);
+ copyAct->setShortcuts(QKeySequence::Copy);
+ copyAct->setIcon(QIcon(":/icons/copy_screenshot_dialog.png"));
+ copyAct->setToolTip("Copy to clipboard");
+ connect(copyAct, SIGNAL(triggered()), this, SLOT(copy()));
+
+ refreshAct = new QAction(tr("&Refresh"), this);
+ refreshAct->setShortcuts(QKeySequence::Refresh);
+ refreshAct->setIcon(QIcon(":/icons/refresh_screenshot_dialog.png"));
+ refreshAct->setToolTip("Refresh Image");
+ connect(refreshAct, SIGNAL(triggered()), this->parent(),
+ SLOT(slotRequestScreenshot()));
+}
+
+void Screenshot::setImage() {
+ scene = new QGraphicsScene(this);
+
+ qDebug() << screenshotPixmap;
+ scene->addPixmap(screenshotPixmap);
+
+ view = new ScreenshotView(scene, this);
+ ratioStr = "100%";
+ ((ScreenshotView*) view)->setWidthHeight(screenshotPixmap.width(),
+ screenshotPixmap.height());
+ view->setScene(scene);
+ view->setMouseTracking(true);
+
+ QScrollArea* area = new QScrollArea(this);
+ area->setFixedSize(screenshotPixmap.width(), screenshotPixmap.height());
+ view->setCornerWidget(area);
+}
+
+Screenshot::Screenshot(QWidget *parent, const QPixmap &pixmap) :
+ QDialog(parent), screenshotPixmap(pixmap) {
+ QString vmname = ((MainWindow *) parent->parent())->uiInfo->vmName + " : "
+ + QString::number(get_device_serial_number());
+ MainWindow *mainWindow = (MainWindow *) parent->parent();
+ this->resize(mainWindow->uiInfo->getMainSize());
+ setWindowTitle("Screen Shot - " + vmname);
+
+ makeWidgets();
+
+ setImage();
+
+ statusBar = new QStatusBar;
+
+ toolbar->addAction(saveAct);
+ toolbar->addAction(copyAct);
+ toolbar->addAction(refreshAct);
+ toolbar->addWidget(slider);
+ gridlayout->addWidget(toolbar, 0, 0);
+ gridlayout->addWidget(view, 1, 0);
+ gridlayout->addWidget(statusBar, 2, 0);
+
+ this->setLayout(gridlayout);
+}
+
+void Screenshot::showEvent(QShowEvent *event) {
+ Q_UNUSED(event)
+
+ QWidget *win = ((QWidget *) this->parent());
+ move(win->geometry().center().x(),
+ win->geometry().center().y() - (geometry().size().height() / 2));
+}
+
+Screenshot::~Screenshot() {
+ qDebug("distructor");
+ ((ContextMenu*)this->parent())->screenshotDialog = NULL;
+}
diff --git a/tizen/src/ui/menu/screenshot.h b/tizen/src/ui/menu/screenshot.h
new file mode 100644
index 0000000000..50d540d8f0
--- /dev/null
+++ b/tizen/src/ui/menu/screenshot.h
@@ -0,0 +1,54 @@
+#ifndef SCREENSHOT_H
+#define SCREENSHOT_H
+
+#include <QtWidgets>
+
+class Screenshot: public QDialog {
+Q_OBJECT
+
+public:
+ explicit Screenshot(QWidget *me, const QPixmap &screenshot);
+ ~Screenshot();
+ void setStatusBar(QString message);
+ int getSliderLevel();
+ QString getRatio();
+
+public slots:
+ void refresh(const QPixmap &);
+
+protected:
+ void showEvent(QShowEvent *event);
+ QGraphicsScene* scene;
+
+private slots:
+ bool save();
+ void copy();
+ void scaleChanged(int level);
+
+private:
+ void makeWidgets();
+ void setImage();
+ void setRatio(int level);
+
+ QGridLayout *gridlayout;
+ QPixmap pixmap;
+ QGraphicsView* view;
+ int sliderLevel;
+ QLabel *label;
+ QSlider* slider;
+ QPixmap screenshotPixmap;
+ QToolBar *toolbar;
+
+ QStatusBar *statusBar;
+ QMenu *fileMenu;
+ QMenu *editMenu;
+ QMenu *helpMenu;
+ QToolBar *toolBar;
+ float ratio;
+ QString ratioStr;
+ QAction *saveAct;
+ QAction *copyAct;
+ QAction *refreshAct;
+};
+
+#endif
diff --git a/tizen/src/ui/menu/screenshotview.cpp b/tizen/src/ui/menu/screenshotview.cpp
new file mode 100644
index 0000000000..95400516bf
--- /dev/null
+++ b/tizen/src/ui/menu/screenshotview.cpp
@@ -0,0 +1,28 @@
+#include "screenshotview.h"
+#include "screenshot.h"
+
+ScreenshotView::ScreenshotView(QGraphicsScene *scene, QWidget* parent) :
+ QGraphicsView(scene, parent) {
+ width = 0;
+ height = 0;
+}
+
+void ScreenshotView::setWidthHeight(int width, int height) {
+ this->width = width;
+ this->height = height;
+}
+
+void ScreenshotView::mouseMoveEvent(QMouseEvent *event) {
+ QPointF fixedPos = this->mapToScene(event->pos());
+ if (scene()->sceneRect().contains(fixedPos)) {
+ QPixmap pixmap = QPixmap();
+ //QRgb rgbval = pixmap.toImage().pixel(fixedPos.x(), fixedPos.y());
+ Screenshot *screenshot = ((Screenshot *) this->parent());
+ screenshot->setStatusBar("x: " + QString::number(fixedPos.x()) + ", y:" + QString::number(fixedPos.y())
+ + " (Resolution: " + QString::number(width) + "x" + QString::number(height)
+ + ", " + qPrintable(screenshot->getRatio()) + ")");
+ }
+}
+
+ScreenshotView::~ScreenshotView() {
+}
diff --git a/tizen/src/ui/menu/screenshotview.h b/tizen/src/ui/menu/screenshotview.h
new file mode 100644
index 0000000000..ffb06fd684
--- /dev/null
+++ b/tizen/src/ui/menu/screenshotview.h
@@ -0,0 +1,21 @@
+#ifndef SCREENSHOTIMAGE_H
+#define SCREENSHOTIMAGE_H
+
+#include <QtWidgets>
+
+class ScreenshotView: public QGraphicsView {
+
+public:
+ ScreenshotView(QGraphicsScene *scene, QWidget* parent);
+ ~ScreenshotView();
+ void setWidthHeight(int width, int height);
+
+protected:
+ void mouseMoveEvent(QMouseEvent *event);
+
+private:
+ int width;
+ int height;
+
+};
+#endif
diff --git a/tizen/src/ui/resource/icons/copy_screenshot_dialog.png b/tizen/src/ui/resource/icons/copy_screenshot_dialog.png
new file mode 100644
index 0000000000..a07a5f720b
--- /dev/null
+++ b/tizen/src/ui/resource/icons/copy_screenshot_dialog.png
Binary files differ
diff --git a/tizen/src/ui/resource/icons/refresh_screenshot_dialog.png b/tizen/src/ui/resource/icons/refresh_screenshot_dialog.png
new file mode 100644
index 0000000000..e1616d9bc2
--- /dev/null
+++ b/tizen/src/ui/resource/icons/refresh_screenshot_dialog.png
Binary files differ
diff --git a/tizen/src/ui/resource/icons/save_screenshot_dialog.png b/tizen/src/ui/resource/icons/save_screenshot_dialog.png
new file mode 100644
index 0000000000..523fe9efd3
--- /dev/null
+++ b/tizen/src/ui/resource/icons/save_screenshot_dialog.png
Binary files differ
diff --git a/tizen/src/ui/resource/resource.qrc b/tizen/src/ui/resource/resource.qrc
index 10a3059c92..74222f3dcc 100644
--- a/tizen/src/ui/resource/resource.qrc
+++ b/tizen/src/ui/resource/resource.qrc
@@ -13,5 +13,8 @@
<file>icons/detailed_info.png</file>
<file>icons/screen_shot.png</file>
<file>icons/host_keyboard.png</file>
+ <file>icons/save_screenshot_dialog.png</file>
+ <file>icons/copy_screenshot_dialog.png</file>
+ <file>icons/refresh_screenshot_dialog.png</file>
</qresource>
</RCC>