Browse Source

Merge branch 'ctkColorDialog'

* ctkColorDialog:
  Add ctkColorDialog::removeTab/indexOf()
Julien Finet 14 years ago
parent
commit
1ef7367584
2 changed files with 42 additions and 0 deletions
  1. 30 0
      Libs/Widgets/ctkColorDialog.cpp
  2. 12 0
      Libs/Widgets/ctkColorDialog.h

+ 30 - 0
Libs/Widgets/ctkColorDialog.cpp

@@ -97,9 +97,32 @@ void ctkColorDialog::addTab(QWidget* widget, const QString& label)
 }
 
 //------------------------------------------------------------------------------
+void ctkColorDialog::removeTab(int index)
+{
+  Q_D(ctkColorDialog);
+  if (index < 0)
+    {
+    return;
+    }
+  d->LeftTabWidget->removeTab(index + 1);
+}
+
+//------------------------------------------------------------------------------
+int ctkColorDialog::indexOf(QWidget* widget)const
+{
+  Q_D(const ctkColorDialog);
+  int index = d->LeftTabWidget->indexOf(widget);
+  return index >= 0 ? index - 1 : -1;
+}
+
+//------------------------------------------------------------------------------
 QWidget* ctkColorDialog::widget(int index)const
 {
   Q_D(const ctkColorDialog);
+  if (index < 0)
+    {
+    return 0;
+    }
   return d->LeftTabWidget->widget(index+1);
 }
 
@@ -119,6 +142,12 @@ QColor ctkColorDialog::getColor(const QColor &initial, QWidget *parent, const QS
     dlg.addTab(tab, tab->accessibleDescription());
     }
   dlg.exec();
+  foreach(QWidget* tab, ctkColorDialog::DefaultTabs)
+    {
+    dlg.removeTab(dlg.indexOf(tab));
+    tab->setParent(0);
+    }
+  
   return dlg.selectedColor();
 }
 
@@ -127,4 +156,5 @@ void ctkColorDialog::addDefaultTab(QWidget* widget, const QString& label)
 {
   widget->setAccessibleDescription(label);
   ctkColorDialog::DefaultTabs << widget;
+  widget->setParent(0);
 }

+ 12 - 0
Libs/Widgets/ctkColorDialog.h

@@ -46,10 +46,22 @@ public:
   /// 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
+  /// The ownership of the widget is taken
   void addTab(QWidget* widget, const QString& label);
 
+  /// The ownership of widget remains the same. The widget is not deleted, 
+  /// but simply removed from the widget's stacked layout, causing it to be
+  /// hidden.
+  /// It is not possible to remove the "Basic Colors" tab
+  void removeTab(int index);
+
   /// Return the extra widget if any
+  /// It is not possible to retrieave the "Basic colors" tab
   QWidget* widget(int index)const;
+  
+  /// Returns the index position of the page occupied by the widget w,
+  /// or -1 if the widget cannot be found
+  int indexOf(QWidget* widget)const;
 
   /// Pops up a modal color dialog with the given window \a title (or "Select Color" if none is
   /// specified), lets the user choose a color, and returns that color. The color is initially set