menu: clean up codes in screenshot 48/36148/1
authorGiWoong Kim <giwoong.kim@samsung.com>
Mon, 2 Mar 2015 08:58:32 +0000 (17:58 +0900)
committerGiWoong Kim <giwoong.kim@samsung.com>
Tue, 3 Mar 2015 02:23:22 +0000 (11:23 +0900)
support PPM, XBM, XPM image formats
modified some function names
add separator, tick marks to slider
set MainWindow as parent & etc

Change-Id: Ia0af795bc75810f7f8cacf783983a0bdce8d79b5
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
tizen/src/ui/mainwindow.cpp
tizen/src/ui/mainwindow.h
tizen/src/ui/menu/contextmenu.cpp
tizen/src/ui/menu/detailedinfodialog.cpp
tizen/src/ui/menu/screenshot.cpp
tizen/src/ui/menu/screenshot.h
tizen/src/ui/menu/screenshotview.cpp
tizen/src/ui/menu/screenshotview.h

index fc85f469e011d701eec0b5b91fa66578f94a567d..d2486804c02411f5dfd823901ae7c71db2c6e763 100644 (file)
@@ -188,6 +188,11 @@ UIState *MainWindow::getUIState()
     return &(uiInfo->uiState);
 }
 
+ContextMenu *MainWindow::getPopupMenu()
+{
+    return popupMenu;
+}
+
 DockingController *MainWindow::getDockingCon()
 {
     return getUIState()->conState.dockingCon;
@@ -362,19 +367,20 @@ void MainWindow::processCaptured(bool captured, void *pixels,
             captured, pixels, width, height);
 
     if (captured) {
+        qDebug("save captured image : %p", pixels);
+
         QImage image = QImage((uchar *)pixels, width, height, QImage::Format_RGB32);
         QPixmap pixmap = QPixmap::fromImage(image); /* deep copy the data */
 
         QMetaObject::invokeMethod(popupMenu, "slotShowScreenshot",
-                                      Qt::QueuedConnection,
-                                      Q_ARG(QPixmap, pixmap));
-        qDebug("Image saved: %p", pixels);
+            Qt::QueuedConnection, Q_ARG(QPixmap, pixmap));
     } else {
-        QPixmap pixmap(uiInfo->resolution.width(),  uiInfo->resolution.height());
-        QMetaObject::invokeMethod(popupMenu, "slotShowScreenshot", Qt::QueuedConnection, Q_ARG(QPixmap, pixmap));
-        qDebug("Blank Image saved");
-    }
+        qDebug("save blank image");
 
+        QPixmap pixmap(uiInfo->resolution.width(), uiInfo->resolution.height());
+        QMetaObject::invokeMethod(popupMenu, "slotShowScreenshot",
+            Qt::QueuedConnection, Q_ARG(QPixmap, pixmap));
+    }
 }
 
 void MainWindow::setTopMost(bool on)
index 75cfd369403c0eacc94d4008b84e4e9634f1f429..346d2dfe6bcddf773535e4a6eaf33e5054248727 100644 (file)
@@ -74,6 +74,7 @@ public:
     ~MainWindow();
 
     UIState *getUIState(void);
+    ContextMenu *getPopupMenu();
     QLabel *getScreenWidget();
     void switchForm(int angle);
     void scaleForm(int scale);
index 4b7b560724b5a885006a28b004697192e7093f1c..ec22e1f11563419b36aa61865ff9c96363d8fe17 100644 (file)
@@ -733,10 +733,10 @@ void ContextMenu::slotShowScreenshot(const QPixmap &screenshot)
     qDebug("show screenshot");
 
     if (screenshotDialog == NULL) {
-        screenshotDialog = new Screenshot(this, screenshot);
+        screenshotDialog = new Screenshot(parent, screenshot);
     }
 
-    screenshotDialog->refresh(screenshot);
+    screenshotDialog->slotRefresh(screenshot);
     screenshotDialog->show();
 }
 
index 1650546a91223700457d875d9fa44925bd537bfa..5152857932c7f6d8159d7314c56269790d558479 100644 (file)
@@ -228,14 +228,11 @@ void DetailedInfoDialog::showEvent(QShowEvent *event)
 
 DetailedInfoDialog::~DetailedInfoDialog()
 {
-    QTableWidgetItem *item;
+    qDebug("destroy detailed info dialog");
 
     for (int i = 0; i < infoTable->rowCount(); i++) {
         for (int j = 0; j < infoTable->columnCount(); j++) {
-            item = infoTable->item(i, j);
-            delete item;
+            delete infoTable->item(i, j);
         }
     }
-
-    qDebug("destroy detailed info dialog");
 }
index 8456608cea709474e6e955b8439750c6eb6f5777..9ca468ebf8603bce438c0a5551c028dc9b3a687e 100644 (file)
 Screenshot::Screenshot(QWidget *parent, const QPixmap &pixmap) :
     QDialog(parent), screenshotPixmap(pixmap)
 {
-    this->win = (MainWindow *)parent->parent();
+    this->win = (MainWindow *)parent;
 
-    QString vmname = win->uiInfo->vmName + " : "
-        + QString::number(get_device_serial_number());
-    resize(win->uiInfo->getMainSize());
-    setWindowTitle("Screen Shot - " + vmname);
+    setWindowTitle("Screen Shot - " + win->uiInfo->vmName +
+        " : " + QString::number(get_device_serial_number()));
+    setWindowIcon(QIcon(":/icons/screen_shot.png"));
 
     createItems();
 
@@ -50,17 +49,20 @@ Screenshot::Screenshot(QWidget *parent, const QPixmap &pixmap) :
     toolbar->addAction(saveAct);
     toolbar->addAction(copyAct);
     toolbar->addAction(refreshAct);
+    toolbar->addSeparator();
     toolbar->addWidget(slider);
     gridlayout->addWidget(toolbar, 0, 0);
     gridlayout->addWidget(view, 1, 0);
     gridlayout->addWidget(statusBar, 2, 0);
 
-    this->setLayout(gridlayout);
+    setLayout(gridlayout);
+
+    resize(win->uiInfo->getMainSize());
 }
 
-void Screenshot::copy()
+void Screenshot::slotCopy()
 {
-    qDebug("copy");
+    qDebug("copy to clipboard");
 
     QClipboard* clipboard = QApplication::clipboard();
     QPixmap pixmap(screenshotPixmap);
@@ -98,7 +100,7 @@ void Screenshot::setRatio(int level)
     ratioStr = QString::number(ratio * 100).append("%");
 }
 
-void Screenshot::scaleChanged(int level)
+void Screenshot::slotScaleChanged(int level)
 {
     qDebug("scale changed: %d", level);
 
@@ -118,7 +120,7 @@ int Screenshot::getSliderLevel()
     return sliderLevel;
 }
 
-void Screenshot::refresh(const QPixmap &pixmap)
+void Screenshot::slotRefresh(const QPixmap &pixmap)
 {
     qDebug("refresh");
 
@@ -153,16 +155,17 @@ void Screenshot::updateStatusBar()
         ", " + qPrintable(getRatio()) + ")");
 }
 
-bool Screenshot::save()
+bool Screenshot::slotSave()
 {
     qDebug("save");
 
     QString vmname = win->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);
+    QString filePath = QDir::homePath() + QDir::separator() + vmname + "-" + date + ".png";
+    QString filterName = "Image files (*.png *.jpg *.jpeg *.bmp *.ppm *.xbm *.xpm);;"
+        "All files (*.*)";
+    QString filename = QFileDialog::getSaveFileName(this, "Save Image", filePath, filterName);
 
     if (filename.isEmpty()) {
         qDebug("can not have file");
@@ -171,8 +174,9 @@ bool Screenshot::save()
         QPixmap pixmap(screenshotPixmap);
         qDebug() << filename;
         pixmap.save(filename);
-        return true;
     }
+
+    return true;
 }
 
 int Screenshot::getRotateAngle()
@@ -182,38 +186,39 @@ int Screenshot::getRotateAngle()
 
 void Screenshot::createItems()
 {
-    statusBar = new QStatusBar();
+    statusBar = new QStatusBar(this);
     toolbar = new QToolBar(this);
 
     slider = new QSlider(Qt::Horizontal, this);
+    slider->setTickPosition(QSlider::TicksAbove);
     slider->setRange(0, 5);
     slider->setValue(3);
     sliderLevel = 3;
     slider->setFixedWidth(100);
     slider->setToolTip("100%");
-    connect(slider, SIGNAL(valueChanged(int)), this, SLOT(scaleChanged(int)));
+    connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slotScaleChanged(int)));
 
-    gridlayout = new QGridLayout;
+    gridlayout = new QGridLayout(this);
     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()));
+    connect(saveAct, SIGNAL(triggered()), this, SLOT(slotSave()));
 
     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()));
+    connect(copyAct, SIGNAL(triggered()), this, SLOT(slotCopy()));
 
     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()));
+    connect(refreshAct, SIGNAL(triggered()),
+        win->getPopupMenu(), SLOT(slotRequestScreenshot()));
 }
 
 void Screenshot::setImage()
@@ -244,14 +249,13 @@ void Screenshot::showEvent(QShowEvent *event)
     Q_UNUSED(event)
 
     // TODO:
-    QWidget *win = ((QWidget *) this->parent());
     move(win->geometry().center().x(),
-            win->geometry().center().y() - (geometry().size().height() / 2));
+        win->geometry().center().y() - (geometry().size().height() / 2));
 }
 
 Screenshot::~Screenshot()
 {
-    qDebug("distructor");
+    qDebug("destroy screenshot dialog");
 
-    ((ContextMenu *)this->parent())->screenshotDialog = NULL;
+    win->getPopupMenu()->screenshotDialog = NULL;
 }
index d132e09048a6542c9394e304e8d7bcb8e775db3d..bd1c0ff45b1ed7681c1910bcfbb585fca19666ad 100644 (file)
@@ -39,7 +39,7 @@ class Screenshot : public QDialog
     Q_OBJECT
 
 public:
-    explicit Screenshot(QWidget *me, const QPixmap &screenshot);
+    explicit Screenshot(QWidget *parent, const QPixmap &screenshot);
     ~Screenshot();
 
     void setStatusBar(qreal xx, qreal yy);
@@ -50,7 +50,7 @@ public:
     QPixmap frameBuf;
 
 public slots:
-    void refresh(const QPixmap &);
+    void slotRefresh(const QPixmap &);
 
 protected:
     void showEvent(QShowEvent *event);
@@ -85,9 +85,9 @@ private:
     QAction *refreshAct;
 
 private slots:
-    bool save();
-    void copy();
-    void scaleChanged(int level);
+    bool slotSave();
+    void slotCopy();
+    void slotScaleChanged(int level);
 };
 
 #endif // SCREENSHOT_H
index bc06e84f04e572cc842d8f8b1e45d2d53e8eeb66..8c70088f5a9a9f94c3de713b18c92ea78f9ae5d1 100644 (file)
  *
  */
 
+#include <QtCore/qmath.h>
+
 #include "screenshotview.h"
 #include "screenshot.h"
-#include <QtCore/qmath.h>
 
 ScreenshotView::ScreenshotView(QGraphicsScene *scene, QWidget *parent) :
-        QGraphicsView(scene, parent) {
+    QGraphicsView(scene, parent)
+{
+    setBackgroundRole(QPalette::Dark);
 }
 
-void ScreenshotView::mouseMoveEvent(QMouseEvent *event) {
+void ScreenshotView::mouseMoveEvent(QMouseEvent *event)
+{
     int max_x;
     int max_y;
     Screenshot *screenshot = (Screenshot *)(this->parent());
@@ -87,10 +91,10 @@ void ScreenshotView::mouseMoveEvent(QMouseEvent *event) {
 
     x = (int)(fixedPos.x() * pow(2, expo));
     y = (int)(fixedPos.y() * pow(2, expo));
-    if(x > max_x) {
+    if (x > max_x) {
         x = max_x;
     }
-    if(y > max_y) {
+    if (y > max_y) {
         y = max_y;
     }
 
@@ -99,5 +103,7 @@ void ScreenshotView::mouseMoveEvent(QMouseEvent *event) {
     }
 }
 
-ScreenshotView::~ScreenshotView() {
+ScreenshotView::~ScreenshotView()
+{
+    /* do nothing */
 }
index fda6a0b66213a3bee943a85cce3db4c204c27ad5..94e43bae93cc07c41ea48e250c8912f4e42b79bd 100644 (file)
 
 #include <QtWidgets>
 
-class ScreenshotView: public QGraphicsView {
-
+class ScreenshotView: public QGraphicsView
+{
 public:
     ScreenshotView(QGraphicsScene *scene, QWidget *parent);
     ~ScreenshotView();
 
 protected:
     void mouseMoveEvent(QMouseEvent *event);
-
 };
-#endif
+
+#endif // SCREENSHOTVIEW_H