screenshot: Implement screenshot dialog 53/29953/1
authorMunkyu Im <munkyu.im@samsung.com>
Tue, 21 Oct 2014 04:53:23 +0000 (13:53 +0900)
committerMunkyu Im <munkyu.im@samsung.com>
Thu, 6 Nov 2014 05:42:15 +0000 (14:42 +0900)
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>
13 files changed:
tizen/src/ui/mainwindow.cpp
tizen/src/ui/mainwindow.h
tizen/src/ui/menu/Makefile.objs
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/contextmenu.h
tizen/src/ui/menu/screenshot.cpp [new file with mode: 0644]
tizen/src/ui/menu/screenshot.h [new file with mode: 0644]
tizen/src/ui/menu/screenshotview.cpp [new file with mode: 0644]
tizen/src/ui/menu/screenshotview.h [new file with mode: 0644]
tizen/src/ui/resource/icons/copy_screenshot_dialog.png [new file with mode: 0644]
tizen/src/ui/resource/icons/refresh_screenshot_dialog.png [new file with mode: 0644]
tizen/src/ui/resource/icons/save_screenshot_dialog.png [new file with mode: 0644]
tizen/src/ui/resource/resource.qrc

index d51482477435b103cc1df6b183fd5aacb9f7d331..da749c77f6274bb56ce0d88db116d9b18c1f857c 100644 (file)
@@ -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);
     }
 }
 
index 6b50dcec6b2b35a8c54b61bf9acf7207cc809cc3..c944edc3b36c3c75d483278917c18c4b38a0f493 100644 (file)
@@ -108,7 +108,6 @@ private:
     SkinView* skinView;
     DisplayBase *display;
     ContextMenu *popupMenu;
-
     QThread *swapperThread;
     DisplaySwapper *swapper;
 
index f5b531376029f4e0048b7ec94e9899f77bed5cea..137a92f927956be00699ea104685cb1ab100c078 100644 (file)
@@ -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
index 82a19c3128bf0433bf58b072116728a449219116..21c6b9c544aafc7efae49ebd4f2a30cab849a7d0 100644 (file)
@@ -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");
index a8e4212f883901ec2ed3e8eec4bcf30bc9693ab2..6b799cb85471525b859e0660b2d35f27afe9b02c 100644 (file)
@@ -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 (file)
index 0000000..0283e9b
--- /dev/null
@@ -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 (file)
index 0000000..50d540d
--- /dev/null
@@ -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 (file)
index 0000000..9540051
--- /dev/null
@@ -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 (file)
index 0000000..ffb06fd
--- /dev/null
@@ -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 (file)
index 0000000..a07a5f7
Binary files /dev/null and b/tizen/src/ui/resource/icons/copy_screenshot_dialog.png 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 (file)
index 0000000..e1616d9
Binary files /dev/null and b/tizen/src/ui/resource/icons/refresh_screenshot_dialog.png 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 (file)
index 0000000..523fe9e
Binary files /dev/null and b/tizen/src/ui/resource/icons/save_screenshot_dialog.png differ
index 10a3059c92ee412bea98d11ba6363edc1b6c5e28..74222f3dcc7a1c280ccf3b81c0607d69533e4750 100644 (file)
@@ -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>