~ubuntu-branches/ubuntu/natty/qtpfsgui/natty

« back to all changes in this revision

Viewing changes to src/ToneMappingDialog/tonemappingdialog_impl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-01-06 04:39:36 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080106043936-a9u9g7yih3w16ru5
Tags: 1.9.0-1
* New upstream release.
* Replace “COPYING” with “LICENSE” in the NOT_NEEDED variable of
  debian/rules, following upstream's renaming.
* Update debian/links accordingly.
* Delete the matching TODO item since there's no longer needed to have a
  patched (with HTML tags) license file to get a correct display in the
  “License agreement” tab.
* Update the gcc4.3 patch (drop the hunk touching src/Libpfs/pfs.cpp):
   - 20_gcc4.3_includes.
* Add a link from /usr/share/qtpfsgui/html to the HTML documentation
  under /usr/share/doc/qtpfsgui/html since the former is used at runtime
  to display the manual.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * This file is a part of Qtpfsgui package.
3
 
 * ---------------------------------------------------------------------- 
4
 
 * Copyright (C) 2006,2007 Giuseppe Rota
5
 
 * 
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.
10
 
 *
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.
15
 
 *
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
 
 * ---------------------------------------------------------------------- 
20
 
 *
21
 
 * @author Giuseppe Rota <grota@users.sourceforge.net>
22
 
 */
23
 
 
24
 
#include <QDockWidget>
25
 
#include <QWorkspace>
26
 
#include <QLabel>
27
 
#include <QFileDialog>
28
 
#include <QMessageBox>
29
 
#include <QWhatsThis>
30
 
#include "tonemappingdialog_impl.h"
31
 
#include "ldrviewer.h"
32
 
#include "../Exif/exif_operations.h"
33
 
#include "../config.h"
34
 
 
35
 
TonemappingWindow::~TonemappingWindow() {}
36
 
 
37
 
TonemappingWindow::TonemappingWindow(QWidget *parent, pfs::Frame* &OriginalPfsFrame, QString cachepath, QString _file) : QMainWindow(parent), settings("Qtpfsgui", "Qtpfsgui") {
38
 
        setupUi(this);
39
 
        toolBar->setToolButtonStyle((Qt::ToolButtonStyle)settings.value(KEY_TOOLBAR_MODE,Qt::ToolButtonTextUnderIcon).toInt());
40
 
 
41
 
        prefixname=QFileInfo(_file).completeBaseName();
42
 
        setWindowTitle(tr("Tone mapping Window: ")+ prefixname);
43
 
        recentPathSaveLDR=settings.value(KEY_RECENT_PATH_SAVE_LDR,QDir::currentPath()).toString();
44
 
 
45
 
        workspace = new QWorkspace(this);
46
 
        workspace->setScrollBarsEnabled( TRUE );
47
 
        connect(workspace,SIGNAL(windowActivated(QWidget*)), this, SLOT(updateActions(QWidget *)) );
48
 
        setCentralWidget(workspace);
49
 
 
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)));
54
 
 
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*)));
59
 
 
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()));
68
 
 
69
 
        this->showMaximized();
70
 
}
71
 
 
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);
76
 
        n->show();
77
 
}
78
 
 
79
 
void TonemappingWindow::current_ldr_fit_to_win(bool checked) {
80
 
        ((LdrViewer*)(workspace->activeWindow()))->fitToWindow(checked);
81
 
}
82
 
 
83
 
void TonemappingWindow::LevelsRequested(bool checked) {
84
 
        if (checked) {
85
 
                LdrViewer* currentLDR=((LdrViewer*)(workspace->activeWindow()));
86
 
                if (currentLDR==NULL)
87
 
                        return;
88
 
                currentLDR->LevelsRequested(checked);
89
 
                actionFix_Histogram->setDisabled(true);
90
 
        }
91
 
}
92
 
 
93
 
void TonemappingWindow::levels_closed() {
94
 
//      qDebug("levels_closed");
95
 
        actionFix_Histogram->setDisabled(false);
96
 
        actionFix_Histogram->setChecked(false);
97
 
}
98
 
 
99
 
 
100
 
void TonemappingWindow::saveLDR() {
101
 
        LdrViewer* currentLDR=((LdrViewer*)(workspace->activeWindow()));
102
 
        if (currentLDR==NULL)
103
 
                return;
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);
118
 
        if (fd->exec()) {
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();
126
 
                                //save settings
127
 
                                settings.setValue(KEY_RECENT_PATH_SAVE_LDR, recentPathSaveLDR);
128
 
                        }
129
 
                        QString format=qfi.suffix();
130
 
                        if (qfi.suffix().isEmpty()) {
131
 
                                QString usedfilter=fd->selectedFilter();
132
 
                                if (usedfilter.startsWith("PNG")) {
133
 
                                        format="png";
134
 
                                        outfname+=".png";
135
 
                                } else if (usedfilter.startsWith("JPEG")) {
136
 
                                        format="jpeg";
137
 
                                        outfname+=".jpg";
138
 
                                } else if (usedfilter.startsWith("PPM")) {
139
 
                                        format="ppm";
140
 
                                        outfname+=".ppm";
141
 
                                } else if (usedfilter.startsWith("BMP")) {
142
 
                                        format="bmp";
143
 
                                        outfname+=".bmp";
144
 
                                }
145
 
                        }
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() );
154
 
                                }
155
 
                        }
156
 
                }
157
 
        }
158
 
        delete fd;
159
 
}
160
 
 
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);
168
 
        if (w!=NULL) {
169
 
                LdrViewer* current=(LdrViewer*)(workspace->activeWindow());
170
 
                actionFit_to_Window->setChecked(current->getFittingWin());
171
 
//              actionFix_Histogram->setChecked(current->hasLevelsOpen());
172
 
        }
173
 
}
174
 
 
175
 
void TonemappingWindow::closeEvent ( QCloseEvent * ) {
176
 
        emit closing();
177
 
}
178
 
 
179
 
void TonemappingWindow::viewAllAsThumbnails() {
180
 
        workspace->tile();
181
 
        QWidgetList allLDRresults=workspace->windowList();
182
 
        foreach (QWidget *p,allLDRresults) {
183
 
                ((LdrViewer*)p)->fitToWindow(true);
184
 
        }
185
 
}
186
 
 
187
 
void TonemappingWindow::close_all() {
188
 
        QWidgetList allLDRresults=workspace->windowList();
189
 
        foreach (QWidget *p,allLDRresults) {
190
 
                ((LdrViewer*)p)->close();
191
 
        }
192
 
}
193
 
 
194
 
void TonemappingWindow::enterWhatsThis() {
195
 
        QWhatsThis::enterWhatsThisMode();
196
 
}
197