#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()
return false;
}
- QPixmap pixmap(screenshotPixmap);
+ QPixmap pixmap(shotData);
qDebug() << filename;
pixmap.save(filename);
{
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);
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));