From c311a2812eedc252375a8b641d798681af4a433f Mon Sep 17 00:00:00 2001 From: GiWoong Kim Date: Tue, 3 Mar 2015 15:56:46 +0900 Subject: [PATCH] screenshot: refactoring fix refresh bug when rotating align screen shot on Scene modified some variable names delete unused variables & etc Change-Id: If902928ec704bf0746e17a42d1c8360c87ed0d9b Signed-off-by: GiWoong Kim --- tizen/src/ui/mainwindow.h | 3 +- tizen/src/ui/menu/contextmenu.cpp | 2 +- tizen/src/ui/menu/screenshotdialog.cpp | 250 +++++++++++++------------ tizen/src/ui/menu/screenshotdialog.h | 51 +++-- tizen/src/ui/menu/screenshotview.cpp | 24 +-- tizen/src/ui/menu/screenshotview.h | 2 +- 6 files changed, 172 insertions(+), 160 deletions(-) diff --git a/tizen/src/ui/mainwindow.h b/tizen/src/ui/mainwindow.h index 346d2dfe6b..98da3f677a 100644 --- a/tizen/src/ui/mainwindow.h +++ b/tizen/src/ui/mainwindow.h @@ -100,13 +100,14 @@ protected: void closeEvent(QCloseEvent *); void setRegion(); + QLabel *screenWidget; private: /* windowing */ QHBoxLayout *winLayout; QGraphicsScene *skinScene; - SkinView* skinView; + SkinView *skinView; DisplayBase *display; ContextMenu *popupMenu; QThread *swapperThread; diff --git a/tizen/src/ui/menu/contextmenu.cpp b/tizen/src/ui/menu/contextmenu.cpp index 7426ebc51e..d5f75c27a2 100644 --- a/tizen/src/ui/menu/contextmenu.cpp +++ b/tizen/src/ui/menu/contextmenu.cpp @@ -733,7 +733,7 @@ void ContextMenu::slotShowScreenshot(const QPixmap &screenshot) qDebug("show screenshot"); if (screenshotDialog == NULL) { - screenshotDialog = new ScreenShotDialog(parent, screenshot); + screenshotDialog = new ScreenShotDialog(parent); } screenshotDialog->slotRefresh(screenshot); diff --git a/tizen/src/ui/menu/screenshotdialog.cpp b/tizen/src/ui/menu/screenshotdialog.cpp index 0fb1c811fa..2b92156ecd 100644 --- a/tizen/src/ui/menu/screenshotdialog.cpp +++ b/tizen/src/ui/menu/screenshotdialog.cpp @@ -34,131 +34,105 @@ #include "screenshotview.h" #include "mainwindow.h" -ScreenShotDialog::ScreenShotDialog(QWidget *parent, const QPixmap &pixmap) : - QDialog(parent), screenshotPixmap(pixmap) +ScreenShotDialog::ScreenShotDialog(QWidget *parent) : + QDialog(parent) { this->win = (MainWindow *)parent; + this->ratio = 1; + this->posX = "0"; + this->posY = "0"; setWindowTitle("Screen Shot - " + win->uiInfo->vmName + " : " + QString::number(get_device_serial_number())); setWindowIcon(QIcon(":/icons/screen_shot.png")); - createItems(); + dialogLayout = new QGridLayout(this); + dialogLayout->setContentsMargins(0, 0, 0, 0); - setImage(); - - 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); + scene = new QGraphicsScene(this); + view = new ScreenShotView(scene, this); + view->setCornerWidget(new QScrollArea(this)); - setLayout(gridlayout); + createItems(dialogLayout); + setLayout(dialogLayout); resize(win->uiInfo->getMainSize()); } -void ScreenShotDialog::createItems() +void ScreenShotDialog::createItems(QGridLayout *layout) { - statusBar = new QStatusBar(this); - toolbar = new QToolBar(this); + /* === tool bar === */ + toolBar = new QToolBar(this); + + /* Save */ + actionSave = new QAction("&Save", this); + actionSave->setShortcuts(QKeySequence::Save); + actionSave->setIcon(QIcon(":/icons/save_screenshot_dialog.png")); + actionSave->setToolTip("Save to file"); + connect(actionSave, SIGNAL(triggered()), this, SLOT(slotSave())); + toolBar->addAction(actionSave); + + /* Copy */ + actionCopy = new QAction("&Copy", this); + actionCopy->setShortcuts(QKeySequence::Copy); + actionCopy->setIcon(QIcon(":/icons/copy_screenshot_dialog.png")); + actionCopy->setToolTip("Copy to clipboard"); + connect(actionCopy, SIGNAL(triggered()), this, SLOT(slotCopy())); + toolBar->addAction(actionCopy); + + /* Refresh */ + actionRefresh = new QAction("&Refresh", this); + actionRefresh->setShortcuts(QKeySequence::Refresh); + actionRefresh->setIcon(QIcon(":/icons/refresh_screenshot_dialog.png")); + actionRefresh->setToolTip("Refresh Image"); + connect(actionRefresh, SIGNAL(triggered()), + win->getPopupMenu(), SLOT(slotRequestScreenshot())); + toolBar->addAction(actionRefresh); + toolBar->addSeparator(); + + /* zoom in/out */ slider = new QSlider(Qt::Horizontal, this); + slider->setFixedWidth(100); 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(slotScaleChanged(int))); - - 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(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(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()), - win->getPopupMenu(), SLOT(slotRequestScreenshot())); -} -void ScreenShotDialog::setImage() -{ - scene = new QGraphicsScene(this); + slider->setValue(3); /* default */ + updateRatio(getSliderLevel()); - qDebug() << screenshotPixmap; + connect(slider, SIGNAL(valueChanged(int)), this, SLOT(slotSliderChanged(int))); + toolBar->addWidget(slider); - QMatrix rm; - rm.rotate(getRotateAngle()); - screenshotPixmap = screenshotPixmap.transformed(rm); - scene->addPixmap(screenshotPixmap); + layout->addWidget(toolBar, 0, 0); + /* ====== */ - view = new ScreenShotView(scene, this); - ratioStr = "100%"; - view->setScene(scene); - view->setMouseTracking(true); - - QScrollArea *area = new QScrollArea(this); - area->setFixedSize(screenshotPixmap.width(), screenshotPixmap.height()); - view->setCornerWidget(area); - view->verticalScrollBar()->setValue(1); - view->horizontalScrollBar()->setValue(1); + /* view */ + layout->addWidget(view, 1, 0); + + /* status bar */ + statusBar = new QStatusBar(this); + layout->addWidget(statusBar, 2, 0); } -int ScreenShotDialog::getRotateAngle() +// TODO: UIState +int ScreenShotDialog::getDisplayAngle() { return win->uiInfo->getMainFormDisplayType()->getAngle(); } -QString ScreenShotDialog::getRatio() +QString ScreenShotDialog::getRatioInfo() { - return ratioStr; + return QString::number(ratio * 100).append("%"); } -void ScreenShotDialog::setRatio(int level) +QPixmap &ScreenShotDialog::getShotData() { - 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; - } - ratioStr = QString::number(ratio * 100).append("%"); + return shotData; } int ScreenShotDialog::getSliderLevel() { - return sliderLevel; + return slider->value(); } bool ScreenShotDialog::slotSave() @@ -178,7 +152,7 @@ bool ScreenShotDialog::slotSave() return false; } - QPixmap pixmap(screenshotPixmap); + QPixmap pixmap(shotData); qDebug() << filename; pixmap.save(filename); @@ -189,47 +163,85 @@ void ScreenShotDialog::slotCopy() { qDebug("copy to clipboard"); - QClipboard* clipboard = QApplication::clipboard(); - QPixmap pixmap(screenshotPixmap); - clipboard->clear(); - clipboard->setPixmap(pixmap); + QClipboard *clipboard = QApplication::clipboard(); + if (clipboard != NULL) { + clipboard->clear(); + clipboard->setPixmap(shotData); + } else { + qWarning("cannot copy to clipboard"); + } } void ScreenShotDialog::slotRefresh(const QPixmap &pixmap) { qDebug("refresh"); - frameBuf = pixmap; + shotData = pixmap; - ratioStr = "100%"; - sliderLevel = 3; - slider->setValue(3); scene->clear(); - // TODO: once - QMatrix rm; - rm.rotate(getRotateAngle()); - screenshotPixmap = screenshotPixmap.transformed(rm); - scene->addPixmap(screenshotPixmap); - slider->setToolTip(ratioStr); + /* draw a screenshot */ + updateScreenShot(shotData); } -void ScreenShotDialog::slotScaleChanged(int level) +void ScreenShotDialog::slotSliderChanged(int level) { - qDebug("scale changed: %d", level); + qDebug("slider changed : %d", level); + + updateRatio(getSliderLevel()); - sliderLevel = level; - QPixmap pixmap(screenshotPixmap); - setRatio(level); scene->clear(); - scene->addPixmap(pixmap.scaled(pixmap.size() * ratio, - Qt::KeepAspectRatio, Qt::FastTransformation)); - slider->setToolTip(ratioStr); + + /* draw a screenshot */ + updateScreenShot(shotData); updateStatusBar(); } -void ScreenShotDialog::setStatusBar(qreal xx, qreal yy) +void ScreenShotDialog::updateRatio(int level) +{ + // TODO: enum + 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; + } + + slider->setToolTip(getRatioInfo()); +} + +void ScreenShotDialog::updateScreenShot(QPixmap &shotData) +{ + /* scaling */ + QPixmap shotImage = shotData.scaled(shotData.size() * ratio, + Qt::KeepAspectRatio, Qt::FastTransformation); + + /* rotate */ + QMatrix matrix; + matrix.rotate(getDisplayAngle()); + shotImage = shotImage.transformed(matrix); + + /* update */ + scene->setSceneRect(0, 0, shotImage.width(), shotImage.height()); + scene->addPixmap(shotImage); +} + +void ScreenShotDialog::updateMousePosition(int xx, int yy) { posX = QString::number(xx); posY = QString::number(yy); @@ -239,16 +251,20 @@ void ScreenShotDialog::setStatusBar(qreal xx, qreal yy) void ScreenShotDialog::updateStatusBar() { - statusBar->showMessage("x: " + posX + ", y:" + posY + - " (" + QString::number(screenshotPixmap.width()) + - "x" + QString::number(screenshotPixmap.height()) + - ", " + qPrintable(getRatio()) + ")"); + if (statusBar != NULL) { + statusBar->showMessage("x: " + posX + ", y:" + posY + + " (" + QString::number(shotData.width()) + + "x" + QString::number(shotData.height()) + + ", " + getRatioInfo() + ")"); + } } void ScreenShotDialog::showEvent(QShowEvent *event) { Q_UNUSED(event) + updateStatusBar(); + // TODO: move(win->geometry().center().x(), win->geometry().center().y() - (geometry().size().height() / 2)); diff --git a/tizen/src/ui/menu/screenshotdialog.h b/tizen/src/ui/menu/screenshotdialog.h index 87bd1570d6..d030fdd172 100644 --- a/tizen/src/ui/menu/screenshotdialog.h +++ b/tizen/src/ui/menu/screenshotdialog.h @@ -40,15 +40,15 @@ class ScreenShotDialog : public QDialog Q_OBJECT public: - explicit ScreenShotDialog(QWidget *parent, const QPixmap &screenshot); + explicit ScreenShotDialog(QWidget *parent); ~ScreenShotDialog(); - int getRotateAngle(); - QString getRatio(); + int getDisplayAngle(); + QString getRatioInfo(); + QPixmap &getShotData(); int getSliderLevel(); - void setStatusBar(qreal xx, qreal yy); - - QPixmap frameBuf; + void updateMousePosition(int xx, int yy); + void updateStatusBar(); public slots: bool slotSave(); @@ -58,38 +58,31 @@ public slots: protected: void showEvent(QShowEvent *event); - QGraphicsScene *scene; - private: - void createItems(); - void setImage(); - void setRatio(int level); - void updateStatusBar(); + void createItems(QGridLayout *layout); + void updateRatio(int level); + void updateScreenShot(QPixmap &shotData); MainWindow *win; + QGridLayout *dialogLayout; + QGraphicsScene *scene; + QGraphicsView *view; + + /* state */ + QPixmap shotData; /* framebuffer */ + float ratio; QString posX; QString posY; - QGridLayout *gridlayout; - 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; + QAction *actionSave; + QAction *actionCopy; + QAction *actionRefresh; + QSlider *slider; + QStatusBar *statusBar; private slots: - void slotScaleChanged(int level); + void slotSliderChanged(int level); }; #endif // SCREENSHOT_H diff --git a/tizen/src/ui/menu/screenshotview.cpp b/tizen/src/ui/menu/screenshotview.cpp index 987744462e..10163f4c2a 100644 --- a/tizen/src/ui/menu/screenshotview.cpp +++ b/tizen/src/ui/menu/screenshotview.cpp @@ -36,33 +36,35 @@ ScreenShotView::ScreenShotView(QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent) { setBackgroundRole(QPalette::Dark); + + setMouseTracking(true); } void ScreenShotView::mouseMoveEvent(QMouseEvent *event) { + ScreenShotDialog *screenshot = (ScreenShotDialog *)parent(); + int max_x; int max_y; - ScreenShotDialog *screenshot = (ScreenShotDialog *)(this->parent()); - QPointF fixedPos = this->mapToScene(event->pos()); + + // TODO: radian + QPointF fixedPos = mapToScene(event->pos()); int sliderLevel = screenshot->getSliderLevel(); - switch (screenshot->getRotateAngle()) { + switch (screenshot->getDisplayAngle()) { case 90: case 270: - max_x = screenshot->frameBuf.size().height(); - max_y = screenshot->frameBuf.size().width(); + max_x = screenshot->getShotData().size().height(); + max_y = screenshot->getShotData().size().width(); break; case 0: case 180: default: - max_x = screenshot->frameBuf.size().width(); - max_y = screenshot->frameBuf.size().height(); + max_x = screenshot->getShotData().size().width(); + max_y = screenshot->getShotData().size().height(); break; } - // Too many logs are printed while mouse is moved. - // Thus comment out this line. - //qDebug("sliderLevel: %d", sliderLevel); int x; int y; float expo = 0; @@ -99,7 +101,7 @@ void ScreenShotView::mouseMoveEvent(QMouseEvent *event) } if (scene()->sceneRect().contains(fixedPos)) { - screenshot->setStatusBar(x, y); + screenshot->updateMousePosition(x, y); } } diff --git a/tizen/src/ui/menu/screenshotview.h b/tizen/src/ui/menu/screenshotview.h index a112e6662a..e5ee78c3ef 100644 --- a/tizen/src/ui/menu/screenshotview.h +++ b/tizen/src/ui/menu/screenshotview.h @@ -30,7 +30,7 @@ #ifndef SCREENSHOTVIEW_H #define SCREENSHOTVIEW_H -#include +#include class ScreenShotView: public QGraphicsView { -- 2.34.1