Take screenshot.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2017-10-17 21:14:36 +01:00
parent 89618601b1
commit 269cb6cfd1
10 changed files with 114 additions and 12 deletions

View file

@ -20,6 +20,11 @@ void Emulator::repaintVideo()
video->repaint();
}
const QPixmap & Emulator::getScreen() const
{
return video->getScreen();
}
void Emulator::setVideoSize(QMdiSubWindow * window, const QSize & size)
{
window->showNormal();

View file

@ -15,6 +15,8 @@ public:
void updateVideo();
void repaintVideo();
const QPixmap & getScreen() const;
void setZoom(QMdiSubWindow * window, const int x);
void set43AspectRatio(QMdiSubWindow * window);

View file

@ -179,6 +179,7 @@ void Preferences::setData(const Data & data)
joystick->setCurrentText(data.joystick);
save_state->setText(data.saveState);
screenshot->setText(data.screenshotTemplate);
}
Preferences::Data Preferences::getData() const
@ -205,6 +206,7 @@ Preferences::Data Preferences::getData() const
}
data.saveState = save_state->text();
data.screenshotTemplate = screenshot->text();
return data;
}

View file

@ -26,6 +26,7 @@ public:
std::vector<QString> hds;
QString saveState;
QString screenshotTemplate;
};
explicit Preferences(QWidget *parent);

View file

@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>556</width>
<height>403</height>
<width>648</width>
<height>315</height>
</rect>
</property>
<property name="windowTitle">
<string>Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -280,8 +280,8 @@
<attribute name="title">
<string>Advanced</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Save State</string>
@ -307,6 +307,25 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Screenshot</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Template</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="screenshot"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="registry">

View file

@ -134,6 +134,17 @@ namespace
return 2;
}
}
QString getScreenshotTemplate()
{
const QString filenameTemplate = QSettings().value("QApple/Screenshot Template", "/tmp/qapple_%1.png").toString();
return filenameTemplate;
}
void setScreenshotTemplate(const QString & filenameTemplate)
{
QSettings().setValue("QApple/Screenshot Template", filenameTemplate);
}
}
void FrameDrawDiskLEDS(HDC)
@ -369,6 +380,7 @@ void QApple::on_actionOptions_triggered()
currentOptions.saveState = QString::fromUtf8(saveState);;
}
currentOptions.screenshotTemplate = getScreenshotTemplate();
QSettings settings; // the function will "modify" it
myPreferences.setup(currentOptions, settings);
@ -440,6 +452,10 @@ void QApple::on_actionOptions_triggered()
RegSaveString(TEXT(REG_CONFIG), REGVALUE_SAVESTATE_FILENAME, 1, name.c_str());
}
if (currentOptions.screenshotTemplate != newOptions.screenshotTemplate)
{
setScreenshotTemplate(newOptions.screenshotTemplate);
}
}
}
@ -466,3 +482,40 @@ void QApple::on_actionAbout_triggered()
{
QMessageBox::about(this, QApplication::applicationName(), "Apple ][ emulator\n\nBased on AppleWin\n");
}
QString getImageFilename()
{
QString filenameTemplate = getScreenshotTemplate();
static size_t counter = 0;
const size_t maximum = 10000;
while (counter < maximum)
{
const QString filename = filenameTemplate.arg(counter, 5, 10, QChar('0'));
if (!QFile(filename).exists())
{
return filename;
}
++counter;
}
return QString();
}
void QApple::on_actionScreenshot_triggered()
{
const QString filename = getImageFilename();
if (filename.isEmpty())
{
QMessageBox::warning(this, "Screenshot", "Cannot determine the screenshot filename.");
}
else
{
const bool ok = myEmulator->getScreen().save(filename);
if (!ok)
{
const QString message = QString::fromUtf8("Cannot save screenshot to %1").arg(filename);
QMessageBox::warning(this, "Screenshot", message);
}
}
}

View file

@ -53,6 +53,8 @@ private slots:
void on_actionAbout_triggered();
void on_actionScreenshot_triggered();
private:
void stopTimer();

View file

@ -48,6 +48,7 @@
<property name="title">
<string>&amp;Video</string>
</property>
<addaction name="actionScreenshot"/>
<addaction name="actionBenchmark"/>
</widget>
<widget class="QMenu" name="menuView">
@ -78,6 +79,9 @@
<addaction name="menuView"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<property name="windowTitle">
<string>size</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
@ -91,7 +95,7 @@
<widget class="QStatusBar" name="statusBar"/>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
<string>controls</string>
</property>
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
@ -163,12 +167,17 @@
</action>
<action name="actionAbout_Qt">
<property name="text">
<string>About Qt...</string>
<string>&amp;About Qt...</string>
</property>
</action>
<action name="actionAbout">
<property name="text">
<string>About...</string>
<string>A&amp;bout...</string>
</property>
</action>
<action name="actionScreenshot">
<property name="text">
<string>Screenshot</string>
</property>
</action>
</widget>

View file

@ -205,6 +205,9 @@ Video::Video(QWidget *parent) : VIDEO_BASECLASS(parent)
{
myGraphicsCache.reset(new GraphicsCache());
setMouseTracking(true);
const QSize standard(40 * 7 * 2, 24 * 8 * 2);
myOffscreen = QPixmap(standard);
}
void Video::paintEvent(QPaintEvent *)
@ -214,8 +217,6 @@ void Video::paintEvent(QPaintEvent *)
const double sx = double(actual.width()) / double(min.width());
const double sy = double(actual.height()) / double(min.height());
QPixmap offscreen(min);
/* How to make this faster
* 1) Do not call Video::paint() with a scale != 1:1
* 2) For this reason we need to draw elsewhere
@ -230,7 +231,7 @@ void Video::paintEvent(QPaintEvent *)
// first draw the image offscreen 1:1
{
QPainter painter(&offscreen);
QPainter painter(&myOffscreen);
paint(painter);
}
@ -238,10 +239,15 @@ void Video::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.scale(sx, sy);
painter.drawPixmap(0, 0, offscreen);
painter.drawPixmap(0, 0, myOffscreen);
}
}
const QPixmap & Video::getScreen() const
{
return myOffscreen;
}
void Video::paint(QPainter & painter)
{
const int displaypage2 = (SW_PAGE2) == 0 ? 0 : 1;

View file

@ -15,6 +15,8 @@ class Video : public VIDEO_BASECLASS
public:
explicit Video(QWidget *parent = 0);
const QPixmap & getScreen() const;
signals:
public slots:
@ -39,6 +41,7 @@ private:
void paint(QPainter & painter);
std::shared_ptr<const GraphicsCache> myGraphicsCache;
QPixmap myOffscreen;
};
#endif // VIDEO_H