Commit 5cf3fd50 authored by Mike Kremer's avatar Mike Kremer

Corrected behaviour of viewer snapshot function. It is now possible to specify...

Corrected behaviour of viewer snapshot function. It is now possible to specify snapshot sizes up to 8192x8192 independently from the glwidget. Additionally a "keep aspect ratio" check box has been added.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9907 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3effe9bc
...@@ -591,7 +591,7 @@ QGLWidget *shareGLWidget () ...@@ -591,7 +591,7 @@ QGLWidget *shareGLWidget ()
} }
void getCurrentViewImage(QImage& _image) { void getCurrentViewImage(QImage& _image) {
viewer( activeExaminer() )->snapshot( _image, true ); viewer( activeExaminer() )->snapshot( _image );
} }
Viewer::ViewerProperties& viewerProperties(int _id) { Viewer::ViewerProperties& viewerProperties(int _id) {
......
...@@ -304,15 +304,11 @@ void CoreWidget::applicationSnapshotDialog() { ...@@ -304,15 +304,11 @@ void CoreWidget::applicationSnapshotDialog() {
suggest += format; suggest += format;
SnapshotDialog dialog(suggest, false, 0);
int w = width(); int w = width();
int h = height(); int h = height();
dialog.snapWidth->setValue(w);
dialog.snapHeight->setValue(h);
SnapshotDialog dialog(suggest, false, w, h, 0);
connect(&dialog, SIGNAL(resizeApplication(int,int)), this, SIGNAL(resizeApplication(int,int)) ); connect(&dialog, SIGNAL(resizeApplication(int,int)), this, SIGNAL(resizeApplication(int,int)) );
bool ok = dialog.exec(); bool ok = dialog.exec();
...@@ -394,16 +390,11 @@ void CoreWidget::viewerSnapshotDialog() { ...@@ -394,16 +390,11 @@ void CoreWidget::viewerSnapshotDialog() {
suggest += format; suggest += format;
SnapshotDialog dialog(suggest, true, 0);
int w = glView_->width(); int w = glView_->width();
int h = glView_->height(); int h = glView_->height();
dialog.snapWidth->setValue(w); SnapshotDialog dialog(suggest, true, w, h, 0);
dialog.snapHeight->setValue(h);
connect(&dialog, SIGNAL(resizeViewers(int,int)), this, SIGNAL(resizeViewers(int,int)) );
bool ok = dialog.exec(); bool ok = dialog.exec();
if (ok){ if (ok){
...@@ -426,7 +417,8 @@ void CoreWidget::viewerSnapshotDialog() { ...@@ -426,7 +417,8 @@ void CoreWidget::viewerSnapshotDialog() {
{ {
QImage finalImage; QImage finalImage;
examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(finalImage); examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(finalImage,
dialog.snapWidth->value(), dialog.snapHeight->value());
finalImage.save(newName); finalImage.save(newName);
...@@ -533,7 +525,7 @@ void CoreWidget::viewerSnapshot() { ...@@ -533,7 +525,7 @@ void CoreWidget::viewerSnapshot() {
case QtMultiViewLayout::Grid: case QtMultiViewLayout::Grid:
{ {
QImage img0,img1,img2,img3; QImage img0,img1,img2,img3;
examiner_widgets_[0]->snapshot(img0); examiner_widgets_[0]->snapshot(img0);
examiner_widgets_[1]->snapshot(img1); examiner_widgets_[1]->snapshot(img1);
examiner_widgets_[2]->snapshot(img2); examiner_widgets_[2]->snapshot(img2);
......
...@@ -2031,11 +2031,24 @@ void glViewer::slotPropertiesUpdated() { ...@@ -2031,11 +2031,24 @@ void glViewer::slotPropertiesUpdated() {
updateGL(); updateGL();
} }
void glViewer::snapshot(QImage& _image, bool _offScreenRendering) void glViewer::snapshot(QImage& _image, int _width, int _height) {
{
int w = 0, h = 0, bak_w = 0, bak_h = 0;
if ( _offScreenRendering ){ // Test if size is given:
QGLFramebufferObject fb( glstate_->context_width(), glstate_->context_height(), QGLFramebufferObject::CombinedDepthStencil); if(_width ==0 || _height == 0) {
// Get standard viewport size
w = glstate_->viewport_width();
h = glstate_->viewport_height();
} else {
w = _width;
h = _height;
bak_w = glstate_->viewport_width();
bak_h = glstate_->viewport_height();
// Set viewport to screenshot size
glstate_->viewport(0, 0, w, h);
}
QGLFramebufferObject fb( w, h, QGLFramebufferObject::CombinedDepthStencil);
if ( fb.isValid() ){ if ( fb.isValid() ){
...@@ -2045,22 +2058,14 @@ void glViewer::snapshot(QImage& _image, bool _offScreenRendering) ...@@ -2045,22 +2058,14 @@ void glViewer::snapshot(QImage& _image, bool _offScreenRendering)
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
paintGL(); paintGL();
glFinish(); glFinish();
_image = fb.toImage().copy(scenePos().x(), scenePos().y(), glWidth(), glHeight()); _image = fb.toImage().copy(scenePos().x(), scenePos().y(), w, h);
}
return;
if(bak_w != 0 && bak_h != 0) {
// Reset viewport to former size
glstate_->viewport(0, 0, bak_w, bak_h);
} }
}
makeCurrent();
qApp->processEvents();
makeCurrent();
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
paintGL();
glFinish();
copyToImage(_image, scenePos().x(), scenePos().y(), glWidth(), glHeight(), GL_BACK);
} }
void glViewer::snapshot() void glViewer::snapshot()
......
...@@ -768,7 +768,7 @@ private: ...@@ -768,7 +768,7 @@ private:
virtual void snapshot(); virtual void snapshot();
/// Take a snapshot and store it in the given image /// Take a snapshot and store it in the given image
virtual void snapshot(QImage& _image, bool _offScreenRendering = false); virtual void snapshot(QImage& _image, int _width = 0, int _height = 0);
/** @} */ /** @} */
......
...@@ -48,13 +48,25 @@ ...@@ -48,13 +48,25 @@
#include <iostream> #include <iostream>
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
SnapshotDialog::SnapshotDialog(QString _suggest, bool _captureViewers, QWidget *parent) SnapshotDialog::SnapshotDialog(QString _suggest, bool _captureViewers, int _w, int _h, QWidget *parent)
: QDialog(parent), : QDialog(parent),
captureViewers_(_captureViewers) captureViewers_(_captureViewers),
aspect_(_w / _h)
{ {
setupUi(this); setupUi(this);
filename->setText( _suggest ); filename->setText( _suggest );
// Disable 'change resolution' button if
// in viewer snapshot mode
resButton->setDisabled(captureViewers_);
keepAspect->setDisabled(!captureViewers_);
snapWidth->setValue(_w);
snapHeight->setValue(_h);
connect(snapWidth, SIGNAL(valueChanged(int)), this, SLOT(snapWidthChanged(int)) );
connect(snapHeight, SIGNAL(valueChanged(int)), this, SLOT(snapHeightChanged(int)) );
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()) ); connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()) );
connect(findButton, SIGNAL(clicked()), this, SLOT(findFile()) ); connect(findButton, SIGNAL(clicked()), this, SLOT(findFile()) );
...@@ -62,11 +74,23 @@ SnapshotDialog::SnapshotDialog(QString _suggest, bool _captureViewers, QWidget * ...@@ -62,11 +74,23 @@ SnapshotDialog::SnapshotDialog(QString _suggest, bool _captureViewers, QWidget *
connect(okButton, SIGNAL(clicked()), this, SLOT(slotOk()) ); connect(okButton, SIGNAL(clicked()), this, SLOT(slotOk()) );
} }
void SnapshotDialog::snapWidthChanged(int _w) {
if(keepAspect->isChecked()) {
snapHeight->setValue((int)(_w / aspect_));
}
}
void SnapshotDialog::snapHeightChanged(int _h) {
if(keepAspect->isChecked()) {
snapWidth->setValue((int)(_h * aspect_));
}
}
void SnapshotDialog::slotChangeResolution() void SnapshotDialog::slotChangeResolution()
{ {
if ( captureViewers_ ) if ( !captureViewers_ )
emit resizeViewers(snapWidth->value(), snapHeight->value());
else
emit resizeApplication(snapWidth->value(), snapHeight->value()); emit resizeApplication(snapWidth->value(), snapHeight->value());
} }
...@@ -80,9 +104,7 @@ void SnapshotDialog::slotOk() ...@@ -80,9 +104,7 @@ void SnapshotDialog::slotOk()
return; return;
} }
if ( captureViewers_ ) if ( !captureViewers_ )
emit resizeViewers(snapWidth->value(), snapHeight->value());
else
emit resizeApplication(snapWidth->value(), snapHeight->value()); emit resizeApplication(snapWidth->value(), snapHeight->value());
accept(); accept();
......
...@@ -48,18 +48,21 @@ class SnapshotDialog : public QDialog, public Ui::SnapshotDialog ...@@ -48,18 +48,21 @@ class SnapshotDialog : public QDialog, public Ui::SnapshotDialog
Q_OBJECT Q_OBJECT
public: public:
SnapshotDialog(QString _suggest, bool _captureViewers, QWidget *parent = 0); SnapshotDialog(QString _suggest, bool _captureViewers, int _w, int _h, QWidget *parent = 0);
private: private:
bool captureViewers_; bool captureViewers_;
double aspect_;
private slots: private slots:
void slotOk(); void slotOk();
void findFile(); void findFile();
void slotChangeResolution(); void slotChangeResolution();
void snapWidthChanged(int _w);
void snapHeightChanged(int _h);
signals: signals:
void resizeViewers(int _width, int _height);
void resizeApplication(int _width, int _height); void resizeApplication(int _width, int _height);
}; };
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>416</width> <width>511</width>
<height>156</height> <height>165</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
<number>100</number> <number>100</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>2000</number> <number>8192</number>
</property> </property>
<property name="value"> <property name="value">
<number>800</number> <number>800</number>
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<number>100</number> <number>100</number>
</property> </property>
<property name="maximum"> <property name="maximum">
<number>2000</number> <number>8192</number>
</property> </property>
<property name="value"> <property name="value">
<number>600</number> <number>600</number>
...@@ -101,10 +101,17 @@ ...@@ -101,10 +101,17 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QCheckBox" name="keepAspect">
<property name="text">
<string>Keep aspect</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="resButton"> <widget class="QPushButton" name="resButton">
<property name="text"> <property name="text">
<string>Change now</string> <string>Change Resolution</string>
</property> </property>
</widget> </widget>
</item> </item>
......
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