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 ()
}
void getCurrentViewImage(QImage& _image) {
viewer( activeExaminer() )->snapshot( _image, true );
viewer( activeExaminer() )->snapshot( _image );
}
Viewer::ViewerProperties& viewerProperties(int _id) {
......
......@@ -304,14 +304,10 @@ void CoreWidget::applicationSnapshotDialog() {
suggest += format;
SnapshotDialog dialog(suggest, false, 0);
int w = width();
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)) );
......@@ -394,15 +390,10 @@ void CoreWidget::viewerSnapshotDialog() {
suggest += format;
SnapshotDialog dialog(suggest, true, 0);
int w = glView_->width();
int h = glView_->height();
dialog.snapWidth->setValue(w);
dialog.snapHeight->setValue(h);
connect(&dialog, SIGNAL(resizeViewers(int,int)), this, SIGNAL(resizeViewers(int,int)) );
SnapshotDialog dialog(suggest, true, w, h, 0);
bool ok = dialog.exec();
......@@ -426,7 +417,8 @@ void CoreWidget::viewerSnapshotDialog() {
{
QImage finalImage;
examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(finalImage);
examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(finalImage,
dialog.snapWidth->value(), dialog.snapHeight->value());
finalImage.save(newName);
......
......@@ -2031,11 +2031,24 @@ void glViewer::slotPropertiesUpdated() {
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;
// Test if size is given:
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);
}
if ( _offScreenRendering ){
QGLFramebufferObject fb( glstate_->context_width(), glstate_->context_height(), QGLFramebufferObject::CombinedDepthStencil);
QGLFramebufferObject fb( w, h, QGLFramebufferObject::CombinedDepthStencil);
if ( fb.isValid() ){
......@@ -2046,21 +2059,13 @@ void glViewer::snapshot(QImage& _image, bool _offScreenRendering)
paintGL();
glFinish();
_image = fb.toImage().copy(scenePos().x(), scenePos().y(), glWidth(), glHeight());
return;
}
_image = fb.toImage().copy(scenePos().x(), scenePos().y(), w, 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);
if(bak_w != 0 && bak_h != 0) {
// Reset viewport to former size
glstate_->viewport(0, 0, bak_w, bak_h);
}
}
void glViewer::snapshot()
......
......@@ -768,7 +768,7 @@ private:
virtual void snapshot();
/// 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,25 +48,49 @@
#include <iostream>
#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),
captureViewers_(_captureViewers)
captureViewers_(_captureViewers),
aspect_(_w / _h)
{
setupUi(this);
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(findButton, SIGNAL(clicked()), this, SLOT(findFile()) );
connect(resButton, SIGNAL(clicked()), this, SLOT(slotChangeResolution()) );
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()
{
if ( captureViewers_ )
emit resizeViewers(snapWidth->value(), snapHeight->value());
else
if ( !captureViewers_ )
emit resizeApplication(snapWidth->value(), snapHeight->value());
}
......@@ -80,9 +104,7 @@ void SnapshotDialog::slotOk()
return;
}
if ( captureViewers_ )
emit resizeViewers(snapWidth->value(), snapHeight->value());
else
if ( !captureViewers_ )
emit resizeApplication(snapWidth->value(), snapHeight->value());
accept();
......
......@@ -48,18 +48,21 @@ class SnapshotDialog : public QDialog, public Ui::SnapshotDialog
Q_OBJECT
public:
SnapshotDialog(QString _suggest, bool _captureViewers, QWidget *parent = 0);
SnapshotDialog(QString _suggest, bool _captureViewers, int _w, int _h, QWidget *parent = 0);
private:
bool captureViewers_;
double aspect_;
private slots:
void slotOk();
void findFile();
void slotChangeResolution();
void snapWidthChanged(int _w);
void snapHeightChanged(int _h);
signals:
void resizeViewers(int _width, int _height);
void resizeApplication(int _width, int _height);
};
......@@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>416</width>
<height>156</height>
<width>511</width>
<height>165</height>
</rect>
</property>
<property name="windowTitle">
......@@ -61,7 +61,7 @@
<number>100</number>
</property>
<property name="maximum">
<number>2000</number>
<number>8192</number>
</property>
<property name="value">
<number>800</number>
......@@ -81,7 +81,7 @@
<number>100</number>
</property>
<property name="maximum">
<number>2000</number>
<number>8192</number>
</property>
<property name="value">
<number>600</number>
......@@ -101,10 +101,17 @@
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="keepAspect">
<property name="text">
<string>Keep aspect</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="resButton">
<property name="text">
<string>Change now</string>
<string>Change Resolution</string>
</property>
</widget>
</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