1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Timo Sachsenberg $
25
// $Authors: Marc Sturm $
26
// --------------------------------------------------------------------------
32
#include <OpenMS/VISUAL/DIALOGS/SaveImageDialog.h>
33
#include <OpenMS/MATH/MISC/MathFunctions.h>
36
#include <QtGui/QLayout>
37
#include <QtGui/QPushButton>
38
#include <QtGui/QComboBox>
39
#include <QtGui/QLabel>
40
#include <QtGui/QValidator>
41
#include <QtGui/QGridLayout>
42
#include <QtGui/QHBoxLayout>
43
#include <QtGui/QImageWriter>
44
#include <QtGui/QApplication>
50
SaveImageDialog::SaveImageDialog( QWidget * parent ):
54
//create dialog and layout (grid)
55
QGridLayout* grid=new QGridLayout(this);
57
//add accept/cancel buttons (and their layout)
58
QBoxLayout* box_layout = new QHBoxLayout();
59
grid->addLayout(box_layout,5,1);
61
QPushButton* button = new QPushButton(this);
62
button->setText("Cancel");
63
connect(button,SIGNAL(clicked()),this,SLOT(reject()));
64
box_layout->addWidget(button);
66
button = new QPushButton(this);
67
button->setText("Accept");
68
button->setDefault(true);
69
connect(button,SIGNAL(clicked()),this,SLOT(checkSize()));
70
box_layout->addWidget(button);
72
//add picture format selector
73
QLabel* label = new QLabel("Picture format:",this);
74
grid->addWidget(label,0,0);
75
format_ = new QComboBox(this);
76
QList<QByteArray> list = QImageWriter::supportedImageFormats();
77
for (int i = 0; i < list.size(); ++i)
79
format_->insertItem(i,list.at(i));
81
grid->addWidget(format_,0,1,Qt::AlignLeft);
82
//set format to PNG/JPEG if available
85
for (int i=0;i<format_->count();i++)
87
if (format_->itemText(i)=="PNG")
91
if (format_->itemText(i)=="JPEG")
98
format_->setCurrentIndex(png);
102
format_->setCurrentIndex(jpeg);
105
//add size boxes and label (and their layout)
106
label = new QLabel("Size (WxH):",this);
107
grid->addWidget(label,1,0);
109
QValidator* v = new QIntValidator(1,10000,this);
110
box_layout = new QHBoxLayout();
111
grid->addLayout(box_layout,1,1);
112
size_x_ = new QLineEdit(this);
113
size_x_->setValidator(v);
114
connect(size_x_,SIGNAL(textChanged(const QString&)),this,SLOT(xSizeChanged(const QString&)));
115
box_layout->addWidget(size_x_);
116
label = new QLabel("x",this);
117
box_layout->addWidget(label);
118
size_y_ = new QLineEdit(this);
119
size_y_->setValidator(v);
120
connect(size_y_,SIGNAL(textChanged(const QString&)),this,SLOT(ySizeChanged(const QString&)));
121
box_layout->addWidget(size_y_);
122
label = new QLabel("pixel",this);
123
box_layout->addWidget(label);
125
size_proportions_ = new QCheckBox("keep proportions",this);
126
size_proportions_->setChecked(true);
127
connect(size_proportions_,SIGNAL(toggled(bool)),this,SLOT(proportionsActivated(bool)));
128
grid->addWidget(size_proportions_,2,1);
131
void SaveImageDialog::setSize(int x, int y)
133
QString* temp =new QString();
135
size_x_->setText(*temp);
137
size_y_->setText(*temp);
138
setSizeRatio_(float(x)/float(y));
141
void SaveImageDialog::setSizeRatio_(float r)
153
void SaveImageDialog::xSizeChanged(const QString& s)
155
if(size_proportions_->isChecked() && size_x_==qApp->focusWidget())
157
QString* temp = new QString();
158
temp->setNum((int)Math::round(s.toInt()/size_ratio_));
159
size_y_->setText(*temp);
163
void SaveImageDialog::ySizeChanged(const QString& s)
165
if(size_proportions_->isChecked() && size_y_==qApp->focusWidget())
167
QString* temp = new QString();
168
temp->setNum((int)Math::round(s.toInt()*size_ratio_));
169
size_x_->setText(*temp);
173
void SaveImageDialog::proportionsActivated(bool state)
176
setSizeRatio_(QString(size_x_->text()).toFloat()/QString(size_y_->text()).toFloat());
180
void SaveImageDialog::checkSize()
182
int x =size_x_->text().toInt();
183
int y =size_y_->text().toInt();
189
int SaveImageDialog::getXSize()
191
return size_x_->text().toInt();
194
int SaveImageDialog::getYSize()
196
return size_y_->text().toInt();
199
QString SaveImageDialog::getFormat()
201
return format_->currentText();