From: GiWoong Kim Date: Mon, 2 Mar 2015 08:58:32 +0000 (+0900) Subject: menu: clean up codes in screenshot X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.2~561 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6024aeae02c12c961762ac09c88b8d01e774895a;p=sdk%2Femulator%2Fqemu.git menu: clean up codes in screenshot 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 --- diff --git a/tizen/src/ui/mainwindow.cpp b/tizen/src/ui/mainwindow.cpp index fc85f469e0..d2486804c0 100644 --- a/tizen/src/ui/mainwindow.cpp +++ b/tizen/src/ui/mainwindow.cpp @@ -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) diff --git a/tizen/src/ui/mainwindow.h b/tizen/src/ui/mainwindow.h index 75cfd36940..346d2dfe6b 100644 --- a/tizen/src/ui/mainwindow.h +++ b/tizen/src/ui/mainwindow.h @@ -74,6 +74,7 @@ public: ~MainWindow(); UIState *getUIState(void); + ContextMenu *getPopupMenu(); QLabel *getScreenWidget(); void switchForm(int angle); void scaleForm(int scale); diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index 4b7b560724..ec22e1f115 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -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(); } diff --git a/tizen/src/ui/menu/detailedinfodialog.cpp b/tizen/src/ui/menu/detailedinfodialog.cpp index 1650546a91..5152857932 100644 --- a/tizen/src/ui/menu/detailedinfodialog.cpp +++ b/tizen/src/ui/menu/detailedinfodialog.cpp @@ -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"); } diff --git a/tizen/src/ui/menu/screenshot.cpp b/tizen/src/ui/menu/screenshot.cpp index 8456608cea..9ca468ebf8 100644 --- a/tizen/src/ui/menu/screenshot.cpp +++ b/tizen/src/ui/menu/screenshot.cpp @@ -36,12 +36,11 @@ 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; } diff --git a/tizen/src/ui/menu/screenshot.h b/tizen/src/ui/menu/screenshot.h index d132e09048..bd1c0ff45b 100644 --- a/tizen/src/ui/menu/screenshot.h +++ b/tizen/src/ui/menu/screenshot.h @@ -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 diff --git a/tizen/src/ui/menu/screenshotview.cpp b/tizen/src/ui/menu/screenshotview.cpp index bc06e84f04..8c70088f5a 100644 --- a/tizen/src/ui/menu/screenshotview.cpp +++ b/tizen/src/ui/menu/screenshotview.cpp @@ -27,15 +27,19 @@ * */ +#include + #include "screenshotview.h" #include "screenshot.h" -#include 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 */ } diff --git a/tizen/src/ui/menu/screenshotview.h b/tizen/src/ui/menu/screenshotview.h index fda6a0b662..94e43bae93 100644 --- a/tizen/src/ui/menu/screenshotview.h +++ b/tizen/src/ui/menu/screenshotview.h @@ -32,14 +32,14 @@ #include -class ScreenshotView: public QGraphicsView { - +class ScreenshotView: public QGraphicsView +{ public: ScreenshotView(QGraphicsScene *scene, QWidget *parent); ~ScreenshotView(); protected: void mouseMoveEvent(QMouseEvent *event); - }; -#endif + +#endif // SCREENSHOTVIEW_H