44 #include "SnapshotDialog.hh" 47 #include <QMessageBox> 48 #include <QFileDialog> 50 SnapshotDialog::SnapshotDialog(QString _suggest,
bool _captureViewers,
int _w,
int _h, QWidget *parent)
52 captureViewers_(_captureViewers),
53 aspect_((double)_w / (double)_h),
58 filename->setText( _suggest );
62 multisampling->setChecked(captureViewers_);
63 changeRes_wdgt->setVisible(!captureViewers_);
64 changeRes_pb->setEnabled(!captureViewers_);
65 transparent->setDisabled(!captureViewers_);
66 hideCoordsys->setDisabled(!captureViewers_);
67 multisampling->setDisabled(!captureViewers_);
68 num_samples->setDisabled(!captureViewers_);
70 snapWidth->setValue(_w);
71 snapHeight->setValue(_h);
73 warning_lb->setText(
"");
78 if (keepAspect->isChecked()) {
79 snapHeight->setValue((
int)((
double)snapWidth->value() / aspect_));
82 connect(snapWidth, SIGNAL(valueChanged(
int)),
this, SLOT(snapWidthChanged(
int)) );
83 connect(snapHeight, SIGNAL(valueChanged(
int)),
this, SLOT(snapHeightChanged(
int)) );
84 connect(keepAspect, SIGNAL(stateChanged(
int)),
this, SLOT(keepAspectChanged()) );
85 connect(multisampling, SIGNAL(stateChanged(
int)),
this, SLOT(multisampleChanged()) );
87 connect(cancelButton, SIGNAL(clicked()),
this, SLOT(reject()) );
88 connect(findButton, SIGNAL(clicked()),
this, SLOT(findFile()) );
89 connect(changeRes_pb, SIGNAL(clicked()),
this, SLOT(slotChangeResolution()) );
90 connect(okButton, SIGNAL(clicked()),
this, SLOT(slotOk()) );
92 connect(filename, SIGNAL(textChanged(
const QString &)),
this, SLOT(filenameChanged(
const QString &)));
95 void SnapshotDialog::saveStates() {
106 void SnapshotDialog::loadStates() {
108 snapWidth->setValue(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/SnapWidth", snapWidth->value()).toInt());
109 snapHeight->setValue(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/SnapHeight", snapHeight->value()).toInt());
110 keepAspect->setChecked(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/KeepAspect",
false).toBool());
111 transparent->setChecked(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/Transparent",
false).toBool());
112 hideCoordsys->setChecked(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/HideCoordsys",
false).toBool());
113 multisampling->setChecked(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/Multisampling",
true).toBool());
114 num_samples->setValue(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/NumSamples", 16).toInt());
117 void SnapshotDialog::snapWidthChanged(
int _w) {
119 if(blockSpinBox_)
return;
121 if(keepAspect->isChecked()) {
122 blockSpinBox_ =
true;
123 snapHeight->setValue((
int)((
double)_w / aspect_));
124 blockSpinBox_ =
false;
128 void SnapshotDialog::snapHeightChanged(
int _h) {
130 if(blockSpinBox_)
return;
132 if(keepAspect->isChecked()) {
133 blockSpinBox_ =
true;
134 snapWidth->setValue((
int)((
double)_h * aspect_));
135 blockSpinBox_ =
false;
139 void SnapshotDialog::keepAspectChanged() {
141 if(keepAspect->isChecked()) {
142 blockSpinBox_ =
true;
143 snapHeight->setValue((
int)((
double)snapWidth->value() / aspect_));
144 blockSpinBox_ =
false;
148 void SnapshotDialog::multisampleChanged() {
149 num_samples->setDisabled (!multisampling->isChecked());
151 void SnapshotDialog::slotChangeResolution()
153 if ( !captureViewers_ )
154 emit resizeApplication(snapWidth->value(), snapHeight->value());
157 void SnapshotDialog::slotOk()
160 if (filename->text() ==
""){
162 msgBox.setText(tr(
"The Filename is empty!"));
167 if ( !captureViewers_ )
168 emit resizeApplication(snapWidth->value(), snapHeight->value());
176 void SnapshotDialog::findFile()
179 QFileInfo fi( filename->text() );
181 QFileDialog dialog(
this);
182 dialog.setFileMode(QFileDialog::AnyFile);
183 dialog.setDefaultSuffix(
"png");
184 dialog.setNameFilter(tr(
"Images (*.png *.ppm *.jpg)"));
185 dialog.setFileMode(QFileDialog::AnyFile);
186 dialog.setConfirmOverwrite(
true);
187 dialog.setDirectory( fi.path() );
188 dialog.selectFile( filename->text() );
189 dialog.setAcceptMode(QFileDialog::AcceptSave);
190 dialog.setWindowTitle(tr(
"Save Snapshot"));
192 bool ok = dialog.exec();
195 filename->setText( dialog.selectedFiles()[0] );
198 void SnapshotDialog::filenameChanged(
const QString &new_filename) {
199 QFileInfo fi(new_filename);
200 if (!QFileInfo(fi.path()).isWritable()) {
201 static const char *style =
"background: #ffffcc;";
202 filename->setStyleSheet(style);
203 warning_lb->setText(trUtf8(
"Warning: Folder not writable."));
204 }
else if (fi.exists()) {
205 static const char *style =
"background: #ffcccc;";
206 filename->setStyleSheet(style);
207 warning_lb->setText(trUtf8(
"Warning: File exists and will be " 208 "overwritten without further warning."));
210 static const char *style =
"";
211 filename->setStyleSheet(style);
212 warning_lb->setText(
"");
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.