From 604cf2af7ae0d6a73f37f8a12eba4390b226408c Mon Sep 17 00:00:00 2001 From: Mike Kremer Date: Wed, 25 Aug 2010 10:57:45 +0000 Subject: [PATCH] Corrected keep aspect ratio behavior when capturing screenshots. git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9913 383ad7c9-94d9-4d36-a494-682f7c89f535 --- widgets/glWidget/QtBaseViewer.cc | 11 +++++------ widgets/snapshotDialog/SnapshotDialog.cc | 16 +++++++++++++--- widgets/snapshotDialog/SnapshotDialog.hh | 2 ++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/widgets/glWidget/QtBaseViewer.cc b/widgets/glWidget/QtBaseViewer.cc index 4b31f01f..08bee2b8 100644 --- a/widgets/glWidget/QtBaseViewer.cc +++ b/widgets/glWidget/QtBaseViewer.cc @@ -2073,12 +2073,11 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha) { // Turn alpha on if demanded ACG::Vec4f backColorBak; ACG::Vec4f newBack; - if(_alpha) { - backColorBak = properties()->backgroundColor(); - newBack = ACG::Vec4f(backColorBak[0], backColorBak[1], backColorBak[2], 0.0f); - properties()->backgroundColor(newBack); - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - } + + backColorBak = properties()->backgroundColor(); + newBack = ACG::Vec4f(backColorBak[0], backColorBak[1], backColorBak[2], (_alpha ? 0.0f : 1.0f)); + properties()->backgroundColor(newBack); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); paintGL(); diff --git a/widgets/snapshotDialog/SnapshotDialog.cc b/widgets/snapshotDialog/SnapshotDialog.cc index 03786145..0bbd0cce 100644 --- a/widgets/snapshotDialog/SnapshotDialog.cc +++ b/widgets/snapshotDialog/SnapshotDialog.cc @@ -51,7 +51,8 @@ SnapshotDialog::SnapshotDialog(QString _suggest, bool _captureViewers, int _w, int _h, QWidget *parent) : QDialog(parent), captureViewers_(_captureViewers), - aspect_(_w / _h) + aspect_((double)_w / (double)_h), + blockSpinBox_(false) { setupUi(this); @@ -61,6 +62,7 @@ SnapshotDialog::SnapshotDialog(QString _suggest, bool _captureViewers, int _w, i // in viewer snapshot mode resButton->setDisabled(captureViewers_); keepAspect->setDisabled(!captureViewers_); + transparent->setDisabled(!captureViewers_); snapWidth->setValue(_w); snapHeight->setValue(_h); @@ -76,15 +78,23 @@ SnapshotDialog::SnapshotDialog(QString _suggest, bool _captureViewers, int _w, i void SnapshotDialog::snapWidthChanged(int _w) { + if(blockSpinBox_) return; + if(keepAspect->isChecked()) { - snapHeight->setValue((int)(_w / aspect_)); + blockSpinBox_ = true; + snapHeight->setValue((int)((double)_w / aspect_)); + blockSpinBox_ = false; } } void SnapshotDialog::snapHeightChanged(int _h) { + if(blockSpinBox_) return; + if(keepAspect->isChecked()) { - snapWidth->setValue((int)(_h * aspect_)); + blockSpinBox_ = true; + snapWidth->setValue((int)((double)_h * aspect_)); + blockSpinBox_ = false; } } diff --git a/widgets/snapshotDialog/SnapshotDialog.hh b/widgets/snapshotDialog/SnapshotDialog.hh index d42cc701..461ecb16 100644 --- a/widgets/snapshotDialog/SnapshotDialog.hh +++ b/widgets/snapshotDialog/SnapshotDialog.hh @@ -53,6 +53,8 @@ class SnapshotDialog : public QDialog, public Ui::SnapshotDialog private: bool captureViewers_; double aspect_; + + bool blockSpinBox_; private slots: void slotOk(); -- GitLab