2
* This file is a part of Qtpfsgui package.
3
* ----------------------------------------------------------------------
4
* Copyright (C) 2006,2007 Giuseppe Rota
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* ----------------------------------------------------------------------
21
* @author Giuseppe Rota <grota@users.sourceforge.net>
24
#include <QDockWidget>
27
#include <QFileDialog>
28
#include <QMessageBox>
30
#include "tonemappingdialog_impl.h"
31
#include "ldrviewer.h"
32
#include "../Exif/exif_operations.h"
33
#include "../config.h"
35
TonemappingWindow::~TonemappingWindow() {}
37
TonemappingWindow::TonemappingWindow(QWidget *parent, pfs::Frame* &OriginalPfsFrame, QString cachepath, QString _file) : QMainWindow(parent), settings("Qtpfsgui", "Qtpfsgui") {
39
toolBar->setToolButtonStyle((Qt::ToolButtonStyle)settings.value(KEY_TOOLBAR_MODE,Qt::ToolButtonTextUnderIcon).toInt());
41
prefixname=QFileInfo(_file).completeBaseName();
42
setWindowTitle(tr("Tone mapping Window: ")+ prefixname);
43
recentPathSaveLDR=settings.value(KEY_RECENT_PATH_SAVE_LDR,QDir::currentPath()).toString();
45
workspace = new QWorkspace(this);
46
workspace->setScrollBarsEnabled( TRUE );
47
connect(workspace,SIGNAL(windowActivated(QWidget*)), this, SLOT(updateActions(QWidget *)) );
48
setCentralWidget(workspace);
50
QDockWidget *dock = new QDockWidget(tr("Tone mapping Panel"), this);
51
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
52
dock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
53
connect(actionViewTMdock,SIGNAL(toggled(bool)),dock,SLOT(setShown(bool)));
55
TMWidget *tmwidget=new TMWidget(dock, OriginalPfsFrame, cachepath, statusBar());
56
dock->setWidget(tmwidget);
57
addDockWidget(Qt::LeftDockWidgetArea, dock);
58
connect(tmwidget,SIGNAL(newResult(const QImage&, tonemapping_options*)), this,SLOT(addMDIresult(const QImage&,tonemapping_options*)));
60
connect(actionAsThumbnails,SIGNAL(triggered()),this,SLOT(viewAllAsThumbnails()));
61
connect(actionCascade,SIGNAL(triggered()),workspace,SLOT(cascade()));
62
connect(actionFit_to_Window,SIGNAL(toggled(bool)),this,SLOT(current_ldr_fit_to_win(bool)));
63
connect(actionFix_Histogram,SIGNAL(toggled(bool)),this,SLOT(LevelsRequested(bool)));
64
connect(actionClose_All,SIGNAL(triggered()),this,SLOT(close_all()));
65
connect(actionSave, SIGNAL(triggered()),this, SLOT(saveLDR()));
66
connect(documentationAction,SIGNAL(triggered()),parent,SLOT(openDocumentation()));
67
connect(actionWhat_s_This,SIGNAL(triggered()),this,SLOT(enterWhatsThis()));
69
this->showMaximized();
72
void TonemappingWindow::addMDIresult(const QImage& i,tonemapping_options* opts) {
73
LdrViewer *n=new LdrViewer(this,i,opts);
74
connect(n,SIGNAL(levels_closed()),this,SLOT(levels_closed()));
75
workspace->addWindow(n);
79
void TonemappingWindow::current_ldr_fit_to_win(bool checked) {
80
((LdrViewer*)(workspace->activeWindow()))->fitToWindow(checked);
83
void TonemappingWindow::LevelsRequested(bool checked) {
85
LdrViewer* currentLDR=((LdrViewer*)(workspace->activeWindow()));
88
currentLDR->LevelsRequested(checked);
89
actionFix_Histogram->setDisabled(true);
93
void TonemappingWindow::levels_closed() {
94
// qDebug("levels_closed");
95
actionFix_Histogram->setDisabled(false);
96
actionFix_Histogram->setChecked(false);
100
void TonemappingWindow::saveLDR() {
101
LdrViewer* currentLDR=((LdrViewer*)(workspace->activeWindow()));
102
if (currentLDR==NULL)
104
QStringList filetypes;
105
filetypes += tr("All LDR formats (*.jpg *.jpeg *.png *.ppm *.pbm *.bmp)");
106
filetypes += "JPEG (*.jpg *.jpeg)";
107
filetypes += "PNG (*.png)";
108
filetypes += "PPM PBM (*.ppm *.pbm)";
109
filetypes += "BMP (*.bmp)";
110
QFileDialog *fd = new QFileDialog(this);
111
fd->setWindowTitle(tr("Save the LDR to..."));
112
fd->setDirectory( recentPathSaveLDR );
113
fd->selectFile(prefixname + "_" + currentLDR->getFilenamePostFix()+ ".jpg");
114
fd->setFileMode(QFileDialog::AnyFile);
115
fd->setFilters(filetypes);
116
fd->setAcceptMode(QFileDialog::AcceptSave);
117
fd->setConfirmOverwrite(true);
119
QString outfname=(fd->selectedFiles()).at(0);
120
if(!outfname.isEmpty()) {
121
QFileInfo qfi(outfname);
122
// if the new dir, the one just chosen by the user, is different from the one stored in the settings, update the settings.
123
if (recentPathSaveLDR != qfi.path()) {
124
// update internal field variable
125
recentPathSaveLDR=qfi.path();
127
settings.setValue(KEY_RECENT_PATH_SAVE_LDR, recentPathSaveLDR);
129
QString format=qfi.suffix();
130
if (qfi.suffix().isEmpty()) {
131
QString usedfilter=fd->selectedFilter();
132
if (usedfilter.startsWith("PNG")) {
135
} else if (usedfilter.startsWith("JPEG")) {
138
} else if (usedfilter.startsWith("PPM")) {
141
} else if (usedfilter.startsWith("BMP")) {
146
if(!((currentLDR->getQImage())->save(outfname,format.toAscii().constData(),100))) {
147
QMessageBox::warning(this,"",tr("Failed to save <b>") + outfname + "</b>",
148
QMessageBox::Ok, QMessageBox::NoButton);
149
} else { //save is succesful
150
if (format=="jpeg" || format=="jpg") {
151
//time to write the exif data...
152
LdrViewer* currentLDR = ((LdrViewer*)(workspace->activeWindow()));
153
ExifOperations::writeExifData( outfname.toStdString(), currentLDR->getExifComment().toStdString() );
161
void TonemappingWindow::updateActions(QWidget *w) {
162
actionFix_Histogram->setEnabled(w!=NULL);
163
actionSave->setEnabled(w!=NULL);
164
actionClose_All->setEnabled(w!=NULL);
165
actionAsThumbnails->setEnabled(w!=NULL);
166
actionFit_to_Window->setEnabled(w!=NULL);
167
actionCascade->setEnabled(w!=NULL);
169
LdrViewer* current=(LdrViewer*)(workspace->activeWindow());
170
actionFit_to_Window->setChecked(current->getFittingWin());
171
// actionFix_Histogram->setChecked(current->hasLevelsOpen());
175
void TonemappingWindow::closeEvent ( QCloseEvent * ) {
179
void TonemappingWindow::viewAllAsThumbnails() {
181
QWidgetList allLDRresults=workspace->windowList();
182
foreach (QWidget *p,allLDRresults) {
183
((LdrViewer*)p)->fitToWindow(true);
187
void TonemappingWindow::close_all() {
188
QWidgetList allLDRresults=workspace->windowList();
189
foreach (QWidget *p,allLDRresults) {
190
((LdrViewer*)p)->close();
194
void TonemappingWindow::enterWhatsThis() {
195
QWhatsThis::enterWhatsThisMode();