1 /***************************************************************************
2 * Copyright (C) 2006 by Michal Sojka *
3 * sojkam1@fel.cvut.cz *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include "mainwindow.h"
21 #include <QTextStream>
22 #include <QDataStream>
26 MainWindow::MainWindow(const string &tty)
27 : QDialog(), m_commThread(tty), m_fileNum(0), m_lastSize(0), m_image()
31 imageLabel = new QLabel;
32 ui.scrollArea->setWidget(imageLabel);
33 ui.scrollArea->setMinimumWidth(320);
34 ui.progressBar->setValue(0);
35 ui.progressBar->hide();
36 ui.saveButton->setDisabled(true);
38 connect(ui.quitButton, SIGNAL(clicked()), this, SLOT(close()));
39 connect(&m_commThread, SIGNAL(bytesReceived(int)), ui.progressBar, SLOT(setValue(int)));
40 connect(&m_commThread, SIGNAL(newImage()), this, SLOT(newImage()));
41 connect(&m_commThread, SIGNAL(imageAvailable(OscImage*)), this, SLOT(processImage(OscImage*)));
42 connect(ui.prefixLine, SIGNAL(textChanged(const QString&)), this, SLOT(generateFileName(const QString&)));
43 connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(saveImage()));
49 MainWindow::~MainWindow()
53 void MainWindow::processImage( OscImage * img )
56 ui.saveButton->setEnabled(true);
57 m_lastSize = img->size();
58 ui.progressBar->setMaximum(m_lastSize);
59 ui.progressBar->setValue(m_lastSize);
60 ui.progressBar->hide();
63 generateFileName( ui.prefixLine->text());
65 if (m_image) delete m_image;
69 ret = pixmap.loadFromData(*m_image);
70 if (!ret) cerr << "Can't display image!"<<endl;
71 QApplication::clipboard()->setPixmap(pixmap);
72 imageLabel->setPixmap(pixmap);
73 imageLabel->adjustSize();
78 void MainWindow::resetFileCounter( )
83 void MainWindow::generateFileName( const QString & prefix )
86 QTextStream ts(&fname);
90 ts << prefix << m_fileNum << ".tif";
91 ui.fileLine->setText(fname);
94 void MainWindow::saveImage()
96 QFile file(ui.fileLine->text());
97 QDataStream ds(&file);
99 file.open(QIODevice::WriteOnly);
100 ds.writeRawData(m_image->data(), m_image->size());
104 void MainWindow::newImage()
106 ui.progressBar->show();
108 ui.progressBar->setMaximum(0);