Browse Source

Add ctkColorDialog a custom color dialog

Julien Finet 14 years ago
parent
commit
9f84335ab4

+ 2 - 2
Libs/Visualization/VTK/Widgets/ctkVTKScalarBarWidget.cpp

@@ -102,9 +102,9 @@ void ctkVTKScalarBarWidget::setScalarBarWidget(vtkScalarBarWidget* scalarBarWidg
   vtkScalarBarActor* newActor =
     scalarBarWidget ? scalarBarWidget->GetScalarBarActor() : 0;
   qvtkReconnect(d->ScalarBarWidget, scalarBarWidget, vtkCommand::EnableEvent, 
-              this, SLOT(updateFromScalarBarWidget()));
+                this, SLOT(updateFromScalarBarWidget()));
   qvtkReconnect(d->ScalarBarWidget, scalarBarWidget, vtkCommand::DisableEvent, 
-              this, SLOT(updateFromScalarBarWidget()));
+                this, SLOT(updateFromScalarBarWidget()));
   qvtkReconnect(oldActor, newActor, vtkCommand::ModifiedEvent,
                 this, SLOT(updateFromScalarBarWidget()));
   d->ScalarBarWidget = scalarBarWidget;

+ 3 - 0
Libs/Widgets/CMakeLists.txt

@@ -32,6 +32,8 @@ SET(KIT_SRCS
   ctkCollapsibleButton.h
   ctkCollapsibleGroupBox.cpp
   ctkCollapsibleGroupBox.h
+  ctkColorDialog.cpp
+  ctkColorDialog.h
   ctkColorPickerButton.cpp
   ctkColorPickerButton.h
   ctkConsoleWidget.cpp
@@ -116,6 +118,7 @@ SET(KIT_MOC_SRCS
   ctkComboBox.h
   ctkCollapsibleButton.h
   ctkCollapsibleGroupBox.h
+  ctkColorDialog.h
   ctkColorPickerButton.h
   ctkConsoleWidget.h
   ctkCoordinatesWidget.h

+ 2 - 0
Libs/Widgets/Testing/Cpp/CMakeLists.txt

@@ -10,6 +10,7 @@ CREATE_TEST_SOURCELIST(Tests ${KIT}CppTests.cxx
   ctkCheckablePushButtonTest1.cpp
   ctkCollapsibleButtonTest1.cpp
   ctkCollapsibleGroupBoxTest1.cpp
+  ctkColorDialogTest1.cpp
   ctkColorPickerButtonTest1.cpp
   ctkComboBoxTest1.cpp
   ctkConsoleWidgetTest1.cpp
@@ -79,6 +80,7 @@ SIMPLE_TEST( ctkCheckableHeaderViewTest1 )
 SIMPLE_TEST( ctkCheckablePushButtonTest1 )
 SIMPLE_TEST( ctkCollapsibleButtonTest1 )
 SIMPLE_TEST( ctkCollapsibleGroupBoxTest1 )
+SIMPLE_TEST( ctkColorDialogTest1 )
 SIMPLE_TEST( ctkColorPickerButtonTest1 )
 SIMPLE_TEST( ctkComboBoxTest1 )
 SIMPLE_TEST( ctkConsoleWidgetTest1 )

+ 55 - 0
Libs/Widgets/Testing/Cpp/ctkColorDialogTest1.cpp

@@ -0,0 +1,55 @@
+/*=========================================================================
+
+  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.commontk.org/LICENSE
+
+  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 <QApplication>
+#include <QCheckBox>
+
+// CTK includes
+#include "ctkColorDialog.h"
+
+// STD includes
+#include <cstdlib>
+#include <iostream>
+
+//-----------------------------------------------------------------------------
+int ctkColorDialogTest1(int argc, char * argv [] )
+{
+  QApplication app(argc, argv);
+
+  ctkColorDialog colorDialog;
+  QWidget* extraPanel = new QWidget;
+  colorDialog.addTab(extraPanel, "Extra");
+  if (extraPanel != colorDialog.widget(0))
+    {
+    return EXIT_FAILURE;
+    }
+  // the following is only in interactive mode
+  if (argc < 2 || QString(argv[1]) != "-I" )
+    {
+    return EXIT_SUCCESS;
+    }
+ if (!colorDialog.exec())
+    {
+    return EXIT_FAILURE;
+    }
+  return EXIT_SUCCESS;
+
+}

+ 103 - 0
Libs/Widgets/ctkColorDialog.cpp

@@ -0,0 +1,103 @@
+/*=========================================================================
+
+  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.commontk.org/LICENSE
+
+  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 <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QTabWidget>
+
+// CTK includes
+#include "ctkColorDialog.h"
+
+//------------------------------------------------------------------------------
+class ctkColorDialogPrivate
+{
+  Q_DECLARE_PUBLIC(ctkColorDialog);
+protected:
+  ctkColorDialog* const q_ptr;
+public:
+  ctkColorDialogPrivate(ctkColorDialog& object);
+  void init();
+  QTabWidget* LeftTabWidget;
+  QWidget*    BasicTab;
+};
+
+//------------------------------------------------------------------------------
+ctkColorDialogPrivate::ctkColorDialogPrivate(ctkColorDialog& object)
+  :q_ptr(&object)
+{
+  this->LeftTabWidget = 0;
+}
+
+//------------------------------------------------------------------------------
+void ctkColorDialogPrivate::init()
+{
+  Q_Q(ctkColorDialog);
+  QVBoxLayout* mainLay = qobject_cast<QVBoxLayout*>(q->layout());
+  QHBoxLayout* topLay = qobject_cast<QHBoxLayout*>(mainLay->itemAt(0)->layout());
+  QVBoxLayout* leftLay = qobject_cast<QVBoxLayout*>(topLay->takeAt(0)->layout());
+  
+  leftLay->setParent(0);
+  this->BasicTab = new QWidget(q);
+  this->BasicTab->setLayout(leftLay);
+
+  this->LeftTabWidget = new QTabWidget(q);
+  topLay->insertWidget(0, this->LeftTabWidget);
+  this->LeftTabWidget->addTab(this->BasicTab, QObject::tr("Basic"));
+}
+
+
+//------------------------------------------------------------------------------
+ctkColorDialog::ctkColorDialog(QWidget* parent)
+  : QColorDialog(parent)
+  , d_ptr(new ctkColorDialogPrivate(*this))
+{
+  Q_D(ctkColorDialog);
+  d->init();
+}
+
+//------------------------------------------------------------------------------
+ctkColorDialog::ctkColorDialog(const QColor& initial, QWidget* parent)
+  : QColorDialog(initial, parent)
+  , d_ptr(new ctkColorDialogPrivate(*this))
+{
+  Q_D(ctkColorDialog);
+  d->init();
+}
+
+//------------------------------------------------------------------------------
+ctkColorDialog::~ctkColorDialog()
+{
+}
+
+//------------------------------------------------------------------------------
+void ctkColorDialog::addTab(QWidget* widget, const QString& label)
+{
+  Q_D(ctkColorDialog);
+  d->LeftTabWidget->addTab(widget, label);
+}
+
+//------------------------------------------------------------------------------
+QWidget* ctkColorDialog::widget(int index)const
+{
+  Q_D(const ctkColorDialog);
+  return d->LeftTabWidget->widget(index+1);
+}

+ 65 - 0
Libs/Widgets/ctkColorDialog.h

@@ -0,0 +1,65 @@
+/*=========================================================================
+
+  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.commontk.org/LICENSE
+
+  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 __ctkColorDialog_h
+#define __ctkColorDialog_h
+
+// Qt includes
+#include <QColorDialog>
+
+// CTK includes
+#include "ctkWidgetsExport.h"
+
+class ctkColorDialogPrivate;
+
+/// Customizable QColorDialog.
+/// Extra widgets can be added to the left of the dialog into a QStackedWidget
+class CTK_WIDGETS_EXPORT ctkColorDialog : public QColorDialog
+{
+  Q_OBJECT
+
+public:
+  /// Constructor
+  /// By default, behaves like a QColorDialog
+  /// \sa QColorDialog()
+  explicit ctkColorDialog(QWidget* parent = 0);
+  explicit ctkColorDialog(const QColor& initial, QWidget* parent = 0);
+  virtual ~ctkColorDialog();
+  
+  /// Add an extra widget under the file format combobox. If a label is
+  /// given, it will appear in the first column.
+  /// The widget is reparented to ctkColorDialog
+  void addTab(QWidget* widget, const QString& label);
+
+  /// Return the extra widget if any
+  QWidget* widget(int index)const;
+
+  /// Internally used
+  //bool eventFilter(QObject *obj, QEvent *event);
+
+protected:
+  QScopedPointer<ctkColorDialogPrivate> d_ptr;
+
+private:
+  Q_DECLARE_PRIVATE(ctkColorDialog);
+  Q_DISABLE_COPY(ctkColorDialog);
+};
+
+#endif