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 ui.statusBar->setText("Press \"hardcopy\" button on the scope...");
40 connect(ui.quitButton, SIGNAL(clicked()), this, SLOT(close()));
41 connect(&m_commThread, SIGNAL(bytesReceived(int)), ui.progressBar, SLOT(setValue(int)));
42 connect(&m_commThread, SIGNAL(newImage()), this, SLOT(newImage()));
43 connect(&m_commThread, SIGNAL(imageAvailable(OscImage*)), this, SLOT(processImage(OscImage*)));
44 connect(ui.prefixLine, SIGNAL(textChanged(const QString&)), this, SLOT(generateFileName(const QString&)));
45 connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(saveImage()));
52 MainWindow::~MainWindow()
56 void MainWindow::processImage( OscImage * img )
59 ui.saveButton->setEnabled(true);
60 m_lastSize = img->size();
61 ui.progressBar->setMaximum(m_lastSize);
62 ui.progressBar->setValue(m_lastSize);
63 ui.progressBar->hide();
65 if (m_image) delete m_image;
69 ret = pixmap.loadFromData(*m_image);
71 ui.statusBar->setText("Cannot display the image! Unsupported format?");
73 ui.statusBar->setText("Ready");
75 QApplication::clipboard()->setPixmap(pixmap);
76 imageLabel->setPixmap(pixmap);
77 imageLabel->adjustSize();
80 generateFileName( ui.prefixLine->text());
86 void MainWindow::resetFileCounter( )
91 void MainWindow::generateFileName( const QString & prefix )
94 QTextStream ts(&fname);
99 ts << prefix << m_fileNum << ".bmp";
100 ui.fileLine->setText(fname);
103 void MainWindow::saveImage()
105 QFile file(ui.fileLine->text());
106 QDataStream ds(&file);
108 file.open(QIODevice::WriteOnly);
109 ds.writeRawData(m_image->data(), m_image->size());
113 void MainWindow::newImage()
115 ui.progressBar->show();
116 ui.statusBar->setText("Transferring...");
118 ui.progressBar->setMaximum(0);