Explorar o código

Added ctkDirectoryListWidget

MattClarkson %!s(int64=13) %!d(string=hai) anos
pai
achega
854fac6835

+ 6 - 0
Libs/Widgets/CMakeLists.txt

@@ -65,6 +65,9 @@ set(KIT_SRCS
   ctkDirectoryButton.h
   ctkDirectoryListView.cpp
   ctkDirectoryListView.h
+  ctkDirectoryListWidget.cpp
+  ctkDirectoryListWidget.h
+  ctkDirectoryListWidget_p.h
   ctkDoubleRangeSlider.cpp
   ctkDoubleRangeSlider.h
   ctkDoubleSlider.cpp
@@ -206,6 +209,8 @@ set(KIT_MOC_SRCS
   ctkDateRangeWidget.h
   ctkDirectoryButton.h
   ctkDirectoryListView.h
+  ctkDirectoryListWidget.h
+  ctkDirectoryListWidget_p.h
   ctkDoubleRangeSlider.h
   ctkDoubleSlider.h
   ctkDynamicSpacer.h
@@ -278,6 +283,7 @@ set(KIT_UI_FORMS
   Resources/UI/ctkThumbnailLabel.ui
   Resources/UI/ctkThumbnailListWidget.ui
   Resources/UI/ctkWorkflowGroupBox.ui
+  Resources/UI/ctkDirectoryListWidget.ui
   )
 
 # Resources

+ 97 - 0
Libs/Widgets/Resources/UI/ctkDirectoryListWidget.ui

@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ctkDirectoryListWidget</class>
+ <widget class="QWidget" name="ctkDirectoryListWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>776</width>
+    <height>347</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="ctkDirectoryListView" name="DirectoryList" native="true">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="GroupBox">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="title">
+      <string>Paths</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout">
+      <item>
+       <widget class="QPushButton" name="AddButton">
+        <property name="text">
+         <string>Add</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QPushButton" name="RemoveButton">
+        <property name="text">
+         <string>Remove</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <spacer name="ButtonSpacer">
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>224</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="ctkExpandButton" name="ExpandButton" native="true">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>ctkDirectoryListView</class>
+   <extends>QWidget</extends>
+   <header>ctkDirectoryListView.h</header>
+   <container>1</container>
+  </customwidget>
+  <customwidget>
+   <class>ctkExpandButton</class>
+   <extends>QWidget</extends>
+   <header>ctkExpandButton.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>

+ 142 - 0
Libs/Widgets/ctkDirectoryListWidget.cpp

@@ -0,0 +1,142 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QDebug>
+#include <QFileDialog>
+
+// CTK includes
+#include "ctkDirectoryListWidget.h"
+#include "ctkDirectoryListWidget_p.h"
+
+//-----------------------------------------------------------------------------
+// ctkDirectoryListWidgetPrivate methods
+
+//-----------------------------------------------------------------------------
+ctkDirectoryListWidgetPrivate::~ctkDirectoryListWidgetPrivate()
+{
+}
+
+//-----------------------------------------------------------------------------
+ctkDirectoryListWidgetPrivate::ctkDirectoryListWidgetPrivate(ctkDirectoryListWidget& object)
+  : QObject(&object), q_ptr(&object)
+{
+}
+
+//-----------------------------------------------------------------------------
+void ctkDirectoryListWidgetPrivate::init()
+{
+  Q_Q(ctkDirectoryListWidget);
+  this->setupUi(q);
+}
+
+//-----------------------------------------------------------------------------
+void ctkDirectoryListWidgetPrivate::setupUi(QWidget * widget)
+{
+  this->Ui_ctkDirectoryListWidget::setupUi(widget);
+
+  this->ExpandButton->setChecked(false);
+  this->ExpandButton->setMirrorOnExpand(true);
+  this->GroupBox->hide();
+
+  QObject::connect(this->AddButton, SIGNAL(clicked()),
+                   this, SLOT(onAddClicked()));
+  QObject::connect(this->RemoveButton, SIGNAL(clicked()),
+                   this, SLOT(onRemoveClicked()));
+  QObject::connect(this->ExpandButton, SIGNAL(clicked()),
+                   this, SLOT(onExpandClicked()));
+}
+
+//-----------------------------------------------------------------------------
+void ctkDirectoryListWidgetPrivate::setDirectoryList(const QStringList& list)
+{
+  this->DirectoryList->setDirectoryList(list);
+}
+
+//-----------------------------------------------------------------------------
+QStringList ctkDirectoryListWidgetPrivate::directoryList() const
+{
+  return this->DirectoryList->directoryList(true); // true for absolute path.
+}
+
+//-----------------------------------------------------------------------------
+void ctkDirectoryListWidgetPrivate::onAddClicked()
+{
+  QString path = QFileDialog::getExistingDirectory(
+        this->DirectoryList, tr("Select folder"),
+        QString(""));
+  // An empty directory means that the user cancelled the dialog.
+  if (path.isEmpty())
+    {
+    return;
+    }
+  this->DirectoryList->addDirectory(path);
+}
+
+//-----------------------------------------------------------------------------
+void ctkDirectoryListWidgetPrivate::onRemoveClicked()
+{
+  this->DirectoryList->removeSelectedDirectories();
+}
+
+//-----------------------------------------------------------------------------
+void ctkDirectoryListWidgetPrivate::onExpandClicked()
+{
+  if (this->GroupBox->isVisible())
+  {
+    this->GroupBox->hide();
+  }
+  else
+  {
+    this->GroupBox->show();
+  }
+}
+
+//-----------------------------------------------------------------------------
+// ctkDirectoryListWidget methods
+
+//-----------------------------------------------------------------------------
+ctkDirectoryListWidget::~ctkDirectoryListWidget()
+{
+}
+
+//-----------------------------------------------------------------------------
+ctkDirectoryListWidget::ctkDirectoryListWidget(QWidget* newParent)
+  : Superclass(newParent)
+  , d_ptr(new ctkDirectoryListWidgetPrivate(*this))
+{
+  Q_D(ctkDirectoryListWidget);
+  d->init();
+}
+
+//-----------------------------------------------------------------------------
+void ctkDirectoryListWidget::setDirectoryList(const QStringList& list)
+{
+  Q_D(ctkDirectoryListWidget);
+  d->setDirectoryList(list);
+}
+
+//-----------------------------------------------------------------------------
+QStringList ctkDirectoryListWidget::directoryList() const
+{
+  Q_D(const ctkDirectoryListWidget);
+  return d->directoryList();
+}
+

+ 69 - 0
Libs/Widgets/ctkDirectoryListWidget.h

@@ -0,0 +1,69 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkDirectoryListWidget_h
+#define __ctkDirectoryListWidget_h
+
+// Qt includes
+#include <QWidget>
+#include <QStringList>
+
+// QtGUI includes
+#include "ctkWidgetsExport.h"
+
+class ctkDirectoryListWidgetPrivate;
+
+/**
+ * \class ctkDirectoryListWidget
+ * \brief A widget to maintain a list of directories, with add and remove buttons,
+ * such as might be used in a settings panel to select a series of directories to search.
+ *
+ * \author m.clarkson@ucl.ac.uk
+ */
+class CTK_WIDGETS_EXPORT ctkDirectoryListWidget : public QWidget
+{
+  Q_OBJECT
+  Q_PROPERTY(QStringList directoryList READ directoryList WRITE setDirectoryList)
+
+public:
+  /// Superclass typedef
+  typedef QWidget Superclass;
+  ctkDirectoryListWidget(QWidget* parent = 0);
+  virtual ~ctkDirectoryListWidget();
+
+  /// Set the directory list, which will overwrite any existing list.
+  void setDirectoryList(const QStringList& list);
+  QStringList directoryList() const;
+
+public Q_SLOTS:
+
+Q_SIGNALS:
+  /// directoryListChanged emmitted whenever the list of directories is changed.
+  void directoryListChanged(const QStringList& directories);
+
+protected:
+  QScopedPointer<ctkDirectoryListWidgetPrivate> d_ptr;
+
+private:
+  Q_DECLARE_PRIVATE(ctkDirectoryListWidget);
+  Q_DISABLE_COPY(ctkDirectoryListWidget);
+};
+
+#endif

+ 59 - 0
Libs/Widgets/ctkDirectoryListWidget_p.h

@@ -0,0 +1,59 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+#ifndef __ctkDirectoryListWidget_p_h
+#define __ctkDirectoryListWidget_p_h
+
+// Qt includes
+#include <QObject>
+#include <QStringList>
+
+// CTK includes
+#include "ctkDirectoryListWidget.h"
+#include "ui_ctkDirectoryListWidget.h"
+
+//-----------------------------------------------------------------------------
+/// \ingroup Widgets
+
+class ctkDirectoryListWidgetPrivate : public QObject, public Ui_ctkDirectoryListWidget
+{
+  Q_OBJECT
+  Q_DECLARE_PUBLIC(ctkDirectoryListWidget);
+protected:
+  ctkDirectoryListWidget* const q_ptr;
+public:
+  explicit ctkDirectoryListWidgetPrivate(ctkDirectoryListWidget& object);
+  virtual ~ctkDirectoryListWidgetPrivate();
+
+  void init();
+  void setupUi(QWidget * parent);
+
+  void setDirectoryList(const QStringList& list);
+  QStringList directoryList() const;
+
+public Q_SLOTS:
+  void onAddClicked();
+  void onRemoveClicked();
+  void onExpandClicked();
+
+public:
+};
+
+#endif