Просмотр исходного кода

ENH: return correct screen area for hosted applications

Marco Nolden лет назад: 14
Родитель
Сommit
b0ca47a45b

+ 6 - 3
Plugins/org.commontk.dicom.examplehost/ctkDicomExampleHost.cpp

@@ -3,8 +3,10 @@
 
 #include <QProcess>
 #include <QtDebug>
+#include <QRect>
 
-ctkDicomExampleHost::ctkDicomExampleHost(QWidget* placeholderWidget, int hostPort, int appPort) :
+
+ctkDicomExampleHost::ctkDicomExampleHost(ctkHostedAppPlaceholderWidget* placeholderWidget, int hostPort, int appPort) :
     ctkDicomAbstractHost(hostPort, appPort),
     placeholderWidget(placeholderWidget),
     applicationState(ctkDicomWG23::IDLE)
@@ -31,8 +33,9 @@ void ctkDicomExampleHost::StartApplication(QString AppPath){
 }
 
 QRect ctkDicomExampleHost::getAvailableScreen(const QRect& preferredScreen){
-    qDebug()<< "set screen from preferredScreen:"<< preferredScreen;
-    QRect rect (preferredScreen);
+    qDebug()<< "Application asked for this area:"<< preferredScreen;
+
+    QRect rect (this->placeholderWidget->getAbsolutePosition());
     emit giveAvailableScreen(rect);
     return rect;
 }

+ 4 - 2
Plugins/org.commontk.dicom.examplehost/ctkDicomExampleHost.h

@@ -2,6 +2,8 @@
 #define CTKDICOMEXAMPLEHOST_H
 
 #include <ctkDicomAbstractHost.h>
+#include <ctkHostedAppPlaceholderWidget.h>
+
 #include <org_commontk_dicom_examplehost_Export.h>
 
 #include <QUrl>
@@ -10,7 +12,7 @@
 class org_commontk_dicom_examplehost_EXPORT ctkDicomExampleHost : public ctkDicomAbstractHost{
     Q_OBJECT
 public:
-    ctkDicomExampleHost(QWidget* placeholderWidget, int hostPort = 8080, int appPort = 8081);
+    ctkDicomExampleHost(ctkHostedAppPlaceholderWidget* placeholderWidget, int hostPort = 8080, int appPort = 8081);
 
     virtual void StartApplication(QString AppPath);
     virtual QString generateUID() { return ""; }
@@ -28,7 +30,7 @@ signals:
 
 protected:
     QProcess appProcess;
-    QWidget* placeholderWidget;
+    ctkHostedAppPlaceholderWidget* placeholderWidget;
     ctkDicomWG23::State applicationState;
 };
 

+ 16 - 1
Plugins/org.commontk.dicom.examplehost/ctkHostedAppPlaceholderWidget.h

@@ -2,6 +2,7 @@
 #define CTKHOSTEDAPPPLACEHOLDERWIDGET_H
 
 #include <QFrame>
+#include <QDebug>
 #include <org_commontk_dicom_examplehost_Export.h>
 
 class org_commontk_dicom_examplehost_EXPORT ctkHostedAppPlaceholderWidget : public QFrame
@@ -9,10 +10,24 @@ class org_commontk_dicom_examplehost_EXPORT ctkHostedAppPlaceholderWidget : publ
   Q_OBJECT
 public:
     explicit ctkHostedAppPlaceholderWidget(QWidget *parent = 0);
+    QRect getAbsolutePosition()
+    {
+      QWidget* current = this;
+      int x = 0;
+      int y = 0;
+      do
+      {
+        x = x + current->x();
+        y = y + current->y();
+        current = dynamic_cast<QWidget*>(current->parent());
+      } while (current);
+      return QRect(x,y,width(),height());
+    }
+
 signals:
   void resized();
 protected:
-  void resizeEvent(QResizeEvent* event) { emit resized(); }
+  void resizeEvent(QResizeEvent* /* event */) { emit resized(); }
 };
 
 #endif // CTKHOSTEDAPPPLACEHOLDERWIDGET_H