From 772ed4475a0a10367a782edecb2aa288c5dd0152 Mon Sep 17 00:00:00 2001 From: Niels Date: Wed, 21 Jul 2010 21:03:25 +0200 Subject: [PATCH] press Alt+s to take a screenshot of the map --- mapwidget.cpp | 24 +++++++++++++++++++++++- mapwidget.h | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mapwidget.cpp b/mapwidget.cpp index 17735dd..1ef1be7 100644 --- a/mapwidget.cpp +++ b/mapwidget.cpp @@ -43,6 +43,8 @@ MapWidget::MapWidget(QWidget *parent) m_usage(false), m_ui(true), m_zoomable(false), + m_takeScreenshot(false), + m_screenshotNumber(0), m_baseName(), m_xPadding(0), m_yPadding(0), @@ -276,6 +278,13 @@ void MapWidget::keyPressEvent(QKeyEvent *event) m_usage = !m_usage; break; } + case Qt::Key_S: + { + if (event->modifiers() == Qt::AltModifier) { + m_takeScreenshot = true; + } + break; + } case Qt::Key_Q: case Qt::Key_Escape: { @@ -299,7 +308,14 @@ void MapWidget::paintEvent(QPaintEvent *event) { event->accept(); - QPainter painter(this); + QImage screenshot(width(), height(), QImage::Format_ARGB32); + + QPainter painter; + if (m_takeScreenshot) { + painter.begin(&screenshot); + } else { + painter.begin(this); + } for (int x = 0; x < m_cols; ++x) { for (int y = 0; y < m_rows; ++y) { @@ -374,6 +390,12 @@ void MapWidget::paintEvent(QPaintEvent *event) } painter.end(); + if (m_takeScreenshot) { + screenshot.save(QString("NanoMap-%1.png").arg(m_screenshotNumber)); + m_takeScreenshot = false; + ++m_screenshotNumber; + update(); + } } void MapWidget::replyFinished(QNetworkReply *reply) diff --git a/mapwidget.h b/mapwidget.h index 68982ac..16a3c90 100644 --- a/mapwidget.h +++ b/mapwidget.h @@ -72,6 +72,8 @@ private: void changeZoomLevel(int diff); bool m_usage, m_ui, m_zoomable; + bool m_takeScreenshot; + int m_screenshotNumber; QString m_baseName; int m_xPadding, m_yPadding; QPoint m_pos, m_startPos;