소스 검색

Adding possibility to dynamically change the layout of the dicomTableManager

Andreas Fetzer 11 년 전
부모
커밋
d801d029bc

+ 6 - 0
Libs/DICOM/Widgets/Resources/UI/ctkDICOMTableManager.ui

@@ -16,6 +16,12 @@
     <verstretch>0</verstretch>
    </sizepolicy>
   </property>
+  <property name="minimumSize">
+   <size>
+    <width>800</width>
+    <height>400</height>
+   </size>
+  </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>

+ 20 - 0
Libs/DICOM/Widgets/ctkDICOMTableManager.cpp

@@ -26,6 +26,7 @@
 // Qt includes
 #include <QHBoxLayout>
 #include <QVBoxLayout>
+#include <QResizeEvent>
 #include <QSplitter>
 
 class ctkDICOMTableManagerPrivate : public Ui_ctkDICOMTableManager
@@ -114,6 +115,7 @@ void ctkDICOMTableManagerPrivate::setCTKDICOMDatabase(ctkDICOMDatabase* db)
 ctkDICOMTableManager::ctkDICOMTableManager(QWidget *parent)
   :Superclass(parent)
   , d_ptr(new ctkDICOMTableManagerPrivate(*this))
+  , m_DynamicLayout(false)
 {
   Q_D(ctkDICOMTableManager);
   d->init();
@@ -124,6 +126,7 @@ ctkDICOMTableManager::ctkDICOMTableManager(QWidget *parent)
 ctkDICOMTableManager::ctkDICOMTableManager(ctkDICOMDatabase *db, QWidget *parent)
   : Superclass(parent)
   , d_ptr(new ctkDICOMTableManagerPrivate(*this))
+  , m_DynamicLayout(false)
 {
   Q_D(ctkDICOMTableManager);
   d->init();
@@ -228,3 +231,20 @@ void ctkDICOMTableManager::onStudiesSelectionChanged(const QStringList &uids)
     }
   d->seriesTable->addSqlWhereCondition(studiesCondition);
 }
+
+void ctkDICOMTableManager::setDynamicTableLayout(bool dynamic)
+{
+  this->m_DynamicLayout = dynamic;
+}
+
+void ctkDICOMTableManager::resizeEvent(QResizeEvent *e)
+{
+  Q_D(ctkDICOMTableManager);
+  if (!m_DynamicLayout)
+    return;
+
+  if (e->size().width() == this->minimumWidth())
+    this->setTableOrientation(Qt::Vertical);
+  else
+    this->setTableOrientation(Qt::Horizontal);
+}

+ 8 - 0
Libs/DICOM/Widgets/ctkDICOMTableManager.h

@@ -44,6 +44,7 @@ class CTK_DICOM_WIDGETS_EXPORT ctkDICOMTableManager : public QWidget
     * Property for setting the table layout either to vertical or horizontal alignment
     */
   Q_PROPERTY(Qt::Orientation tableOrientation READ tableOrientation WRITE setTableOrientation)
+  Q_PROPERTY(bool m_DynamicLayout WRITE setDynamicTableLayout)
 
 public:
   typedef QWidget Superclass;
@@ -69,6 +70,8 @@ public:
   QStringList currentStudiesSelection();
   QStringList currentSeriesSelection();
 
+  void setDynamicTableLayout(bool);
+
 public Q_SLOTS:
 
   void onPatientsQueryChanged(const QStringList&);
@@ -92,6 +95,11 @@ protected:
   QScopedPointer<ctkDICOMTableManagerPrivate> d_ptr;
 
 private:
+
+  void resizeEvent(QResizeEvent *);
+
+  bool m_DynamicLayout;
+
   Q_DECLARE_PRIVATE(ctkDICOMTableManager)
   Q_DISABLE_COPY(ctkDICOMTableManager)
 };