Commits

vedddd committed 43a072e

Добавил диалог ввода адреса камеры

  • Participants
  • Parent commits 3947d90

Comments (0)

Files changed (4)

File src/cpp/MainWindow.cpp

 #include <QtGui>
 #include <QtNetwork>
 #include <QtDebug>
- 
+#include <QFileDialog>
+#include <QDir>
+#include <QSettings>
+#include <QStackedLayout>
+#include "SettingsDialog.hpp"
+
+
 MainWindow::MainWindow(): isRunning(false), http(new QHttp), buffer(new QBuffer),
 			  imgReqId(-1), pixItem(0), view(0) {
 
-  host = "192.168.0.9";
+  QSettings settings;
+  host = settings.value("host", "192.168.0.9").toString();
+  
   ui.setupUi(this);
 
   readSettingTimer = new QTimer(this);
 
   netManager = new QNetworkAccessManager(this);
 
-  view = new QGraphicsView(new QGraphicsScene, ui.fImage);
+  QStackedLayout* layout = new QStackedLayout(ui.fImage);
+  view = new QGraphicsView(new QGraphicsScene);
+  layout->addWidget(view);
   //ui.fImage->addWidget(view);
+  
   http->setHost(host, 8081);
   connect(http, SIGNAL(requestFinished(int, bool)), this, SLOT(requestFinished(int, bool)));
 
   isRunning = true;
   readSettingTimer->start(500);
   //  qDebug() << "ff" << QImageReader::supportedImageFormats ();
+  QSettings app_settings;
+   
+  // add file path
+  ui.leFilePath->setText(
+      app_settings.value("lastPath", QDir::home().absolutePath()).toString()    
+      );
+  
+  // add extension
+  //ui.comboBoxExtension->addItem(".png");
+  //ui.comboBoxExtension->addItem(".jp2");
+  ui.comboBoxExtension->addItem(".jpg");
+  //ui.comboBoxExtension->addItem(".bmp");
+ 
 }
 
 MainWindow::~MainWindow() {
   isRunning = false;
   setDcm(1);
   for(int i=1;true; ++i) {
-    QString fn = QString::number(i) + ".jpg";
+    QString fn = ui.leFilePath->text() + QDir::separator() + ui.leFileName->text()
+		  + QString::number(i) + ui.comboBoxExtension->currentText();
     if(QFile::exists(fn)) continue;
     QFile file(fn);
     file.open(QIODevice::WriteOnly);
   qDebug() << "pbAcquire_clicked";
 }
 
-//test
-void MainWindow::on_actionSettings_triggered(bool checked)
+// file path
+void MainWindow::on_bSelectFilePath_clicked(bool checked)
 {
-  QCoreApplication::exit();
+  QString qdirectoryName = QFileDialog::getExistingDirectory(this, "Select files path", ".");
+  QString directoryName = qdirectoryName;
+  if(qdirectoryName=="") directoryName = ui.leFilePath->text();
+  ui.leFilePath->setText(directoryName);
+  
+  // save file path
+  QSettings settings;
+  settings.setValue("lastPath", directoryName);    
 }
 
+// settings
+void MainWindow::on_bSettings_clicked(bool checked)
+{
+  SettingsDialog dialog;
+  dialog.setIpAddress(host);
+  if (dialog.exec()) {
+    host = dialog.ipAddress();
+    QSettings settings;
+    host = dialog.ipAddress();
+    settings.setValue("host", host);
+    http->setHost(host, 8081);
+    qDebug() << dialog.ipAddress();
+  }
+}
+
+// auto exposition
 void MainWindow::on_cbAutoExp_stateChanged(int state) {
   setParam("autoexp_on", state == Qt::Unchecked ? 0 : 1);
 }
 
+// set exposition
 void MainWindow::on_dsbExpos_valueChanged(double d) {
-  //  setParam("autoexp", state == Qt::Unchecked ? 0 : 1);
+  //setParam("autoexp", state == Qt::Unchecked ? 0 : 1);
 }
 
+// slider exposition
 void MainWindow::on_hsExpos_valueChanged(int value) {
   if(ui.cbAutoExp->isChecked()) return;
   setParam("expos", value);
 }
 
-
+//
 void MainWindow::setParam(const QString& param, const QVariant& value) {
-  QString url = "http://" + host + "/var/elcap.php?" + param + "=" + value.toString();
+  QString url = "http://" + host + "/elcap.php?" + param + "=" + value.toString();
   QNetworkReply* reply = netManager->get(QNetworkRequest(QUrl(url)));
   while(!reply->isFinished() && reply->error() == QNetworkReply::NoError) QCoreApplication::processEvents();
   delete reply;
 }
 
+// image divider
 void MainWindow::setDcm(int dcm) {
-  QString url = "http://" + host + "/var/elcap.php?dcm_hor=" + QString::number(dcm) + "&dcm_vert=" + QString::number(dcm);
+  QString url = "http://" + host + "/elcap.php?dcm_hor=" + QString::number(dcm) + "&dcm_vert=" + QString::number(dcm);
   QNetworkReply* reply = netManager->get(QNetworkRequest(QUrl(url)));
   while(!reply->isFinished() && reply->error() == QNetworkReply::NoError) QCoreApplication::processEvents();
   delete reply;
 }
 
+//
 QByteArray MainWindow::getImageData() {
   QString url = "http://" + host + ":8081/last/wait";///torp/wait/next/save";
   QNetworkReply* reply = netManager->get(QNetworkRequest(QUrl(url)));
   reply = netManager->get(QNetworkRequest(QUrl(url)));
   while(!reply->isFinished()) QCoreApplication::processEvents();
   QByteArray result = reply->readAll();
-  delete reply;  
+  delete reply;
   return result;
 }
 

File src/cpp/MainWindow.hpp

 public:
   MainWindow();
   ~MainWindow();
+    void fileName(const char* arg1, MainWindow* arg2);
 protected:
   void closeEvent(QCloseEvent *event);
   void getImage();
   void on_cbAutoExp_stateChanged(int state);
   void on_dsbExpos_valueChanged(double d);
   void on_hsExpos_valueChanged(int value);
-  //my test
-  void on_actionSettings_triggered(bool checked);
+  // test
+  void on_bSelectFilePath_clicked(bool checked);
+  void on_bSettings_clicked(bool checked);
   
 private:
   QString host; // camera host

File src/cpp/main.cpp

   qDebug ("Application initialized");
 	
   QApplication app (argc, argv);
+  
+  // QSettings
+  QCoreApplication::setOrganizationName("PTRI UNN");
+  QCoreApplication::setOrganizationDomain("nifti.unn.ru");
+  QCoreApplication::setApplicationName("ElCap");
+  
   QStringList paths = QCoreApplication::libraryPaths();
   paths.push_back(QApplication::applicationDirPath());
   QCoreApplication::setLibraryPaths (paths);
   QCoreApplication::setApplicationName (QString::fromUtf8 ("ElCap"));   
 
   MainWindow mainwnd;
-  mainwnd.show();    
+  //mainwnd.showMaximized();
+  mainwnd.show();
   int ret = app.exec ();
   
   qDebug ("Application closed with code %d", ret);
   
   return ret;
-}
+}

File src/ui/MainWindow.ui

     <x>0</x>
     <y>0</y>
     <width>624</width>
-    <height>513</height>
+    <height>517</height>
    </rect>
   </property>
   <property name="windowTitle">
     <item row="0" column="0" colspan="2">
      <layout class="QHBoxLayout" name="horizontalLayout">
       <item>
-       <widget class="QLineEdit" name="lineEdit"/>
+       <widget class="QLineEdit" name="leFilePath">
+        <property name="readOnly">
+         <bool>true</bool>
+        </property>
+       </widget>
       </item>
       <item>
-       <widget class="QToolButton" name="toolButton">
+       <widget class="QToolButton" name="bSelectFilePath">
         <property name="text">
          <string>...</string>
         </property>
        </widget>
       </item>
       <item>
-       <widget class="QLineEdit" name="lineEdit_2"/>
+       <widget class="QLineEdit" name="leFileName"/>
       </item>
       <item>
-       <widget class="QComboBox" name="comboBox"/>
+       <widget class="QComboBox" name="comboBoxExtension"/>
       </item>
      </layout>
     </item>
          </property>
         </spacer>
        </item>
+       <item row="11" column="0" colspan="2">
+        <widget class="QPushButton" name="bSettings">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="text">
+          <string>Settings</string>
+         </property>
+         <property name="autoRepeat">
+          <bool>false</bool>
+         </property>
+         <property name="autoDefault">
+          <bool>false</bool>
+         </property>
+         <property name="default">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
       </layout>
      </widget>
     </item>
     </item>
    </layout>
   </widget>
-  <widget class="QMenuBar" name="menubar">
-   <property name="geometry">
-    <rect>
-     <x>0</x>
-     <y>0</y>
-     <width>624</width>
-     <height>21</height>
-    </rect>
-   </property>
-   <widget class="QMenu" name="menuFile">
-    <property name="title">
-     <string>File</string>
-    </property>
-    <addaction name="actionSave_as_3"/>
-    <addaction name="actionExit_2"/>
-   </widget>
-   <widget class="QMenu" name="menuEdit">
-    <property name="title">
-     <string>Edit</string>
-    </property>
-    <addaction name="actionSettings"/>
-    <addaction name="actionExpozition"/>
-   </widget>
-   <addaction name="menuFile"/>
-   <addaction name="menuEdit"/>
-  </widget>
   <widget class="QStatusBar" name="statusbar"/>
   <action name="actionSave_as">
    <property name="checkable">
     <string>Save as...</string>
    </property>
   </action>
-  <action name="actionExit_2">
-   <property name="text">
-    <string>Exit</string>
-   </property>
-  </action>
  </widget>
  <resources/>
  <connections>