50 #include "SnapshotDialog.hh"
53 SnapshotDialog::SnapshotDialog(QString _suggest,
bool _captureViewers,
int _w,
int _h, QWidget *parent)
55 captureViewers_(_captureViewers),
56 aspect_((double)_w / (double)_h),
61 filename->setText( _suggest );
65 multisampling->setChecked(captureViewers_);
66 changeRes_wdgt->setVisible(!captureViewers_);
67 changeRes_pb->setEnabled(!captureViewers_);
68 transparent->setDisabled(!captureViewers_);
69 hideCoordsys->setDisabled(!captureViewers_);
70 multisampling->setDisabled(!captureViewers_);
71 num_samples->setDisabled(!captureViewers_);
73 snapWidth->setValue(_w);
74 snapHeight->setValue(_h);
76 warning_lb->setText(
"");
81 if (keepAspect->isChecked()) {
82 snapHeight->setValue((
int)((
double)snapWidth->value() / aspect_));
85 connect(snapWidth, SIGNAL(valueChanged(
int)),
this, SLOT(snapWidthChanged(
int)) );
86 connect(snapHeight, SIGNAL(valueChanged(
int)),
this, SLOT(snapHeightChanged(
int)) );
87 connect(keepAspect, SIGNAL(stateChanged(
int)),
this, SLOT(keepAspectChanged()) );
88 connect(multisampling, SIGNAL(stateChanged(
int)),
this, SLOT(multisampleChanged()) );
90 connect(cancelButton, SIGNAL(clicked()),
this, SLOT(reject()) );
91 connect(findButton, SIGNAL(clicked()),
this, SLOT(findFile()) );
92 connect(changeRes_pb, SIGNAL(clicked()),
this, SLOT(slotChangeResolution()) );
93 connect(okButton, SIGNAL(clicked()),
this, SLOT(slotOk()) );
95 connect(filename, SIGNAL(textChanged(
const QString &)),
this, SLOT(filenameChanged(
const QString &)));
98 void SnapshotDialog::saveStates() {
109 void SnapshotDialog::loadStates() {
111 snapWidth->setValue(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/SnapWidth", snapWidth->value()).toInt());
112 snapHeight->setValue(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/SnapHeight", snapHeight->value()).toInt());
113 keepAspect->setChecked(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/KeepAspect",
false).toBool());
114 transparent->setChecked(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/Transparent",
false).toBool());
115 hideCoordsys->setChecked(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/HideCoordsys",
false).toBool());
116 multisampling->setChecked(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/Multisampling",
true).toBool());
117 num_samples->setValue(
OpenFlipperSettings().value(
"Viewer/SnapshotDialog/NumSamples", 16).toInt());
120 void SnapshotDialog::snapWidthChanged(
int _w) {
122 if(blockSpinBox_)
return;
124 if(keepAspect->isChecked()) {
125 blockSpinBox_ =
true;
126 snapHeight->setValue((
int)((
double)_w / aspect_));
127 blockSpinBox_ =
false;
131 void SnapshotDialog::snapHeightChanged(
int _h) {
133 if(blockSpinBox_)
return;
135 if(keepAspect->isChecked()) {
136 blockSpinBox_ =
true;
137 snapWidth->setValue((
int)((
double)_h * aspect_));
138 blockSpinBox_ =
false;
142 void SnapshotDialog::keepAspectChanged() {
144 if(keepAspect->isChecked()) {
145 blockSpinBox_ =
true;
146 snapHeight->setValue((
int)((
double)snapWidth->value() / aspect_));
147 blockSpinBox_ =
false;
151 void SnapshotDialog::multisampleChanged() {
152 num_samples->setDisabled (!multisampling->isChecked());
154 void SnapshotDialog::slotChangeResolution()
156 if ( !captureViewers_ )
157 emit resizeApplication(snapWidth->value(), snapHeight->value());
160 void SnapshotDialog::slotOk()
163 if (filename->text() ==
""){
165 msgBox.setText(tr(
"The Filename is empty!"));
170 if ( !captureViewers_ )
171 emit resizeApplication(snapWidth->value(), snapHeight->value());
179 void SnapshotDialog::findFile()
182 QFileInfo fi( filename->text() );
184 QFileDialog dialog(
this);
185 dialog.setFileMode(QFileDialog::AnyFile);
186 dialog.setDefaultSuffix(
"png");
187 dialog.setNameFilter(tr(
"Images (*.png *.ppm *.jpg)"));
188 dialog.setFileMode(QFileDialog::AnyFile);
189 dialog.setConfirmOverwrite(
true);
190 dialog.setDirectory( fi.path() );
191 dialog.selectFile( filename->text() );
192 dialog.setAcceptMode(QFileDialog::AcceptSave);
193 dialog.setWindowTitle(tr(
"Save Snapshot"));
195 bool ok = dialog.exec();
198 filename->setText( dialog.selectedFiles()[0] );
201 void SnapshotDialog::filenameChanged(
const QString &new_filename) {
202 QFileInfo fi(new_filename);
203 if (!QFileInfo(fi.path()).isWritable()) {
204 static const char *style =
"background: #ffffcc;";
205 filename->setStyleSheet(style);
206 warning_lb->setText(trUtf8(
"Warning: Folder not writable."));
207 }
else if (fi.exists()) {
208 static const char *style =
"background: #ffcccc;";
209 filename->setStyleSheet(style);
210 warning_lb->setText(trUtf8(
"Warning: File exists and will be "
211 "overwritten without further warning."));
213 static const char *style =
"";
214 filename->setStyleSheet(style);
215 warning_lb->setText(
"");
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...