Commit b821a271 authored by Mike Kremer's avatar Mike Kremer

Corrected snapshot behavior when capturing screenshots of multiview / grid view mode.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9914 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 604cf2af
...@@ -426,12 +426,25 @@ void CoreWidget::viewerSnapshotDialog() { ...@@ -426,12 +426,25 @@ void CoreWidget::viewerSnapshotDialog() {
} }
case QtMultiViewLayout::Grid: case QtMultiViewLayout::Grid:
{ {
// Compute size of each viewer
int w = dialog.snapWidth->value();
int h = dialog.snapHeight->value();
// Relative size of first viewer (in relation to the other viewers
double relSizeW = (double)examiner_widgets_[0]->glWidth() / (double)glScene_->width();
double relSizeH = (double)examiner_widgets_[0]->glHeight() / (double)glScene_->height();
QImage img0,img1,img2,img3; QImage img0,img1,img2,img3;
examiner_widgets_[0]->snapshot(img0); examiner_widgets_[0]->snapshot(img0, (int)((double)w * relSizeW), (int)((double)h * relSizeH), dialog.transparent->isChecked());
examiner_widgets_[1]->snapshot(img1); examiner_widgets_[1]->snapshot(img1, (int)((double)w * (1.0 - relSizeW)), (int)((double)h * relSizeH), dialog.transparent->isChecked());
examiner_widgets_[2]->snapshot(img2); examiner_widgets_[2]->snapshot(img2, (int)((double)w * relSizeW), (int)((double)h * (1.0 - relSizeH)), dialog.transparent->isChecked());
examiner_widgets_[3]->snapshot(img3); examiner_widgets_[3]->snapshot(img3, (int)((double)w * (1.0 - relSizeW)), (int)((double)h * (1.0 - relSizeH)), dialog.transparent->isChecked());
img0.save("/home/kremer/multsnap0.png");
img1.save("/home/kremer/multsnap1.png");
img2.save("/home/kremer/multsnap2.png");
img3.save("/home/kremer/multsnap3.png");
QImage finalImage(img0.width() + img1.width()+2, img0.height() + img2.height()+2, QImage::Format_ARGB32_Premultiplied); QImage finalImage(img0.width() + img1.width()+2, img0.height() + img2.height()+2, QImage::Format_ARGB32_Premultiplied);
...@@ -454,12 +467,22 @@ void CoreWidget::viewerSnapshotDialog() { ...@@ -454,12 +467,22 @@ void CoreWidget::viewerSnapshotDialog() {
} }
case QtMultiViewLayout::HSplit: case QtMultiViewLayout::HSplit:
{ {
// Compute size of each viewer
int w = dialog.snapWidth->value();
int h = dialog.snapHeight->value();
// Relative size of first viewer (in relation to the other viewers
double relSizeW = (double)examiner_widgets_[0]->glWidth() / (double)glScene_->width();
double relSizeH1 = (double)examiner_widgets_[1]->glHeight() / (double)glScene_->height();
double relSizeH2 = (double)examiner_widgets_[2]->glHeight() / (double)glScene_->height();
double relSizeH3 = (double)examiner_widgets_[3]->glHeight() / (double)glScene_->height();
QImage img0,img1,img2,img3; QImage img0,img1,img2,img3;
examiner_widgets_[0]->snapshot(img0); examiner_widgets_[0]->snapshot(img0, (int)((double)w * relSizeW), h, dialog.transparent->isChecked());
examiner_widgets_[1]->snapshot(img1); examiner_widgets_[1]->snapshot(img1, (int)((double)w * (1.0 - relSizeW)), relSizeH1 * (double)h, dialog.transparent->isChecked());
examiner_widgets_[2]->snapshot(img2); examiner_widgets_[2]->snapshot(img2, (int)((double)w * (1.0 - relSizeW)), relSizeH2 * (double)h, dialog.transparent->isChecked());
examiner_widgets_[3]->snapshot(img3); examiner_widgets_[3]->snapshot(img3, (int)((double)w * (1.0 - relSizeW)), relSizeH3 * (double)h, dialog.transparent->isChecked());
QImage finalImage(img0.width() + img1.width() +2, img0.height(), QImage::Format_ARGB32_Premultiplied); QImage finalImage(img0.width() + img1.width() +2, img0.height(), QImage::Format_ARGB32_Premultiplied);
...@@ -484,7 +507,7 @@ void CoreWidget::viewerSnapshotDialog() { ...@@ -484,7 +507,7 @@ void CoreWidget::viewerSnapshotDialog() {
} }
} }
glView_->resize(w, h); //glView_->resize(w, h);
} }
///Take a snapshot of all viewers ///Take a snapshot of all viewers
......
...@@ -2033,28 +2033,30 @@ void glViewer::slotPropertiesUpdated() { ...@@ -2033,28 +2033,30 @@ void glViewer::slotPropertiesUpdated() {
} }
void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha) { void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha) {
int w = 0, h = 0, bak_w = 0, bak_h = 0; int w = 0, h = 0, bak_w = 0, bak_h = 0, left = 0, bottom = 0;
// Get viewport data
glstate_->get_viewport(left, bottom, w, h);
// Test if size is given: // Test if size is given:
if(_width ==0 && _height == 0) { if(_width != 0 || _height != 0) {
// Get standard viewport size
w = glstate_->viewport_width();
h = glstate_->viewport_height();
} else {
// Adapt dimensions if aspect ratio is demanded // Adapt dimensions if aspect ratio is demanded
if(_width == 0) { if(_width == 0) {
double aspect = glstate_->viewport_width()/glstate_->viewport_height(); double aspect = (double)w / (double)h;
_width = (int)(_height * aspect); _width = (int)((double)_height * aspect);
} }
if(_height == 0) { if(_height == 0) {
double aspect = glstate_->viewport_width()/glstate_->viewport_height(); double aspect = (double)w / (double)h;
_height = (int)(_width / aspect); _height = (int)((double)_width / aspect);
} }
bak_w = w;
bak_h = h;
w = _width; w = _width;
h = _height; h = _height;
bak_w = glstate_->viewport_width();
bak_h = glstate_->viewport_height(); // Set new viewport
// Set viewport to screenshot size
glstate_->viewport(0, 0, w, h); glstate_->viewport(0, 0, w, h);
} }
...@@ -2087,12 +2089,12 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha) { ...@@ -2087,12 +2089,12 @@ void glViewer::snapshot(QImage& _image, int _width, int _height, bool _alpha) {
if(_alpha) if(_alpha)
properties()->backgroundColor(backColorBak); properties()->backgroundColor(backColorBak);
_image = fb.toImage().copy(scenePos().x(), scenePos().y(), w, h); _image = fb.toImage().copy(0, 0, w, h);
} }
if(bak_w != 0 && bak_h != 0) { if(_width != 0 || _height != 0) {
// Reset viewport to former size // Reset viewport to former size
glstate_->viewport(0, 0, bak_w, bak_h); glstate_->viewport(left, bottom, bak_w, bak_h);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment