]> rtime.felk.cvut.cz Git - sojka/tekpic.git/blobdiff - src/mainwindow.cpp
Change default port to ttyUSB0
[sojka/tekpic.git] / src / mainwindow.cpp
index 6895675dfdf67618eba13d7db79b588fd866c33c..69c9f4adcca217f2f6ec872095abafa3c5c7caf4 100644 (file)
 #include <QClipboard>
 
 MainWindow::MainWindow(const string &tty)
- : QDialog(), m_commThread(tty), m_fileNum(0), m_image()
+ : QDialog(), m_commThread(tty), m_fileNum(0), m_lastSize(0), m_image()
 {
      ui.setupUi(this);
      
      imageLabel = new QLabel;
      ui.scrollArea->setWidget(imageLabel);
+     ui.scrollArea->setMinimumWidth(320);
      ui.progressBar->setValue(0);
-     ui.progressBar->setMaximum(15000);
+     ui.progressBar->hide();
      ui.saveButton->setDisabled(true);
+
+     ui.statusBar->setText("Press \"hardcopy\" button on the scope...");
      
      connect(ui.quitButton, SIGNAL(clicked()), this, SLOT(close()));
      connect(&m_commThread, SIGNAL(bytesReceived(int)), ui.progressBar, SLOT(setValue(int)));
+     connect(&m_commThread, SIGNAL(newImage()), this, SLOT(newImage()));
      connect(&m_commThread, SIGNAL(imageAvailable(OscImage*)), this, SLOT(processImage(OscImage*)));
      connect(ui.prefixLine, SIGNAL(textChanged(const QString&)), this, SLOT(generateFileName(const QString&)));
      connect(ui.saveButton, SIGNAL(clicked()), this, SLOT(saveImage()));
@@ -44,6 +48,7 @@ MainWindow::MainWindow(const string &tty)
 }
 
 
+
 MainWindow::~MainWindow()
 {
 }
@@ -52,22 +57,28 @@ void MainWindow::processImage( OscImage * img )
 {
         bool ret;
         ui.saveButton->setEnabled(true);
-        ui.progressBar->setMaximum(img->size());
-        ui.progressBar->setValue(img->size());
-        ui.progressBar->update();
-        
-        m_fileNum++;
-        generateFileName( ui.prefixLine->text());
+        m_lastSize = img->size();
+        ui.progressBar->setMaximum(m_lastSize);
+        ui.progressBar->setValue(m_lastSize);
+        ui.progressBar->hide();
         
         if (m_image) delete m_image;
         m_image = img;
         
         QPixmap pixmap;
         ret = pixmap.loadFromData(*m_image);
-        if (!ret) cerr << "Can't display image!"<<endl;
+        if (!ret)
+          ui.statusBar->setText("Cannot display the image! Unsupported format?");
+        else
+          ui.statusBar->setText("Ready");
+
         QApplication::clipboard()->setPixmap(pixmap);
         imageLabel->setPixmap(pixmap);
         imageLabel->adjustSize();
+
+        m_fileNum++;
+        generateFileName( ui.prefixLine->text());
+
 }
 
 
@@ -84,7 +95,8 @@ void MainWindow::generateFileName( const QString & prefix )
         
         ts.setFieldWidth(3); 
         ts.setPadChar('0') ;
-        ts << prefix << m_fileNum << ".tif";
+
+        ts << prefix << m_fileNum << ".bmp";
         ui.fileLine->setText(fname);
 }
 
@@ -97,3 +109,11 @@ void MainWindow::saveImage()
         ds.writeRawData(m_image->data(), m_image->size());
         file.close();
 }
+
+void MainWindow::newImage()
+{
+     ui.progressBar->show();
+     ui.statusBar->setText("Transferring...");
+        if (m_lastSize == 0)
+                ui.progressBar->setMaximum(0);
+}