Parcourir la source

Improved GUI of hosted app example

Ivo Wolf il y a 13 ans
Parent
commit
466eb29dd1

+ 1 - 0
Plugins/org.commontk.dah.exampleapp/CMakeLists.txt

@@ -17,6 +17,7 @@ SET(PLUGIN_MOC_SRCS
 
 # Qt Designer files which should be processed by Qts uic
 SET(PLUGIN_UI_FORMS
+  ctkExampleDicomAppWidget.ui
 )
 
 # QRC Files which should be compiled into the plugin

+ 24 - 20
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic.cpp

@@ -37,7 +37,7 @@
 
 //----------------------------------------------------------------------------
 ctkExampleDicomAppLogic::ctkExampleDicomAppLogic():
-ctkDicomAbstractApp(ctkExampleDicomAppPlugin::getPluginContext()), Button(0)
+ctkDicomAbstractApp(ctkExampleDicomAppPlugin::getPluginContext()), AppWidget(0)
 {
 
 
@@ -62,34 +62,39 @@ ctkExampleDicomAppLogic::~ctkExampleDicomAppLogic()
   }
 }
 
-
-
 //----------------------------------------------------------------------------
 bool ctkExampleDicomAppLogic::bringToFront(const QRect& /*requestedScreenArea*/)
 {
-  return false;
+  if(this->AppWidget!=NULL)
+  {
+    this->AppWidget->activateWindow();
+    this->AppWidget->raise();
+  }
+  return true;
 }
 
 //----------------------------------------------------------------------------
 void ctkExampleDicomAppLogic::do_something()
 {
-  this->Button = new QPushButton("Button from App");
-  connect(this->Button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
+  AppWidget = new QWidget;
+  ui.setupUi(AppWidget);
+
+  connect(ui.GetDataButton, SIGNAL(clicked()), this, SLOT(buttonClicked()));
   try
     {
     QRect preferred(50,50,100,100);
     qDebug() << "  Asking:getAvailableScreen";
     QRect rect = getHostInterface()->getAvailableScreen(preferred);
     qDebug() << "  got sth:" << rect.top();
-    this->Button->move(rect.topLeft());
-    this->Button->resize(rect.size());
+    this->AppWidget->move(rect.topLeft());
+    this->AppWidget->resize(rect.size());
     }
   catch (const std::runtime_error& e)
     {
     qCritical() << e.what();
     return;
     }
-  this->Button->show();
+  this->AppWidget->show();
 }
 
 //----------------------------------------------------------------------------
@@ -115,14 +120,14 @@ void ctkExampleDicomAppLogic::onResumeProgress()
   getHostInterface()->notifyStateChanged(ctkDicomAppHosting::INPROGRESS);
   //we're rolling
   //do something else normally, but this is an example
-  this->Button->setEnabled(true);
+  ui.GetDataButton->setEnabled(true);
 }
 
 //----------------------------------------------------------------------------
 void ctkExampleDicomAppLogic::onSuspendProgress()
 {
   //release resources it can reclame later to resume work
-  this->Button->setEnabled(false);
+  ui.GetDataButton->setEnabled(false);
   //notify state changed
   setInternalState(ctkDicomAppHosting::SUSPENDED);
   getHostInterface()->notifyStateChanged(ctkDicomAppHosting::SUSPENDED);
@@ -153,9 +158,9 @@ void ctkExampleDicomAppLogic::onExitHostedApp()
 //----------------------------------------------------------------------------
 void ctkExampleDicomAppLogic::onReleaseResources()
 {
-  this->Button->hide();
-  delete (this->Button);
-  this->Button = 0 ;
+  this->AppWidget->hide();
+  delete (this->AppWidget);
+  this->AppWidget = 0 ;
 }
 
 
@@ -164,7 +169,7 @@ bool ctkExampleDicomAppLogic::notifyDataAvailable(const ctkDicomAppHosting::Avai
 {
   Q_UNUSED(lastData)
   QString s;
-  if(this->Button == 0)
+  if(this->AppWidget == 0)
     {
     qCritical() << "Button is null!";
     return false;
@@ -185,7 +190,8 @@ bool ctkExampleDicomAppLogic::notifyDataAvailable(const ctkDicomAppHosting::Avai
       }
     }
   }
-  this->Button->setText(s);
+  ui.ReceivedDataInformation->setText(s);
+  ui.GetDataButton->setEnabled(true);
   return false;
 }
 
@@ -233,7 +239,6 @@ void ctkExampleDicomAppLogic::buttonClicked()
     DicomImage dcmtkImage(filename.toLatin1().data());
     ctkDICOMImage ctkImage(&dcmtkImage);
 
-    QLabel* qtImage = new QLabel;
     QPixmap pixmap = QPixmap::fromImage(ctkImage.frame(0),Qt::AvoidDither);
     if (pixmap.isNull())
     {
@@ -241,9 +246,8 @@ void ctkExampleDicomAppLogic::buttonClicked()
     }
     else
     {
-      qtImage->setPixmap(pixmap);
-      qtImage->show();
+      ui.PlaceHolderForImage->setPixmap(pixmap);
     }
   }
-  this->Button->setText(s);
+  ui.ReceivedDataInformation->setText(s);
 }

+ 6 - 2
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppLogic_p.h

@@ -32,9 +32,12 @@
 
 #include <ctkServiceTracker.h>
 
+// ui of this application
+#include "ui_ctkExampleDicomAppWidget.h"
+
 struct ctkDicomHostInterface;
 
-class QPushButton;
+class QWidget;
 
 class ctkExampleDicomAppLogic : public ctkDicomAbstractApp
 {
@@ -74,7 +77,8 @@ protected slots:
 
   void buttonClicked();
 private:
-  QPushButton * Button;
+  QWidget * AppWidget;
+  Ui::ctkExampleDicomAppWidget ui;
 
   QUuid uuid;
 

+ 60 - 0
Plugins/org.commontk.dah.exampleapp/ctkExampleDicomAppWidget.ui

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkExampleDicomAppWidget</class>
+ <widget class="QWidget" name="ctkExampleDicomAppWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QPushButton" name="GetDataButton">
+     <property name="enabled">
+      <bool>false</bool>
+     </property>
+     <property name="text">
+      <string>Get Data</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="ReceivedDataInformation">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="text">
+      <string>No data received</string>
+     </property>
+     <property name="wordWrap">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="PlaceHolderForImage">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>1</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="text">
+      <string/>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>