Sfoglia il codice sorgente

Merge branch 'ctkColorDialog'

* ctkColorDialog:
  Add slots to change the current color in ctkColorDialog
Julien Finet 14 anni fa
parent
commit
b6a6a41be0
2 ha cambiato i file con 37 aggiunte e 5 eliminazioni
  1. 25 3
      Libs/Widgets/ctkColorDialog.cpp
  2. 12 2
      Libs/Widgets/ctkColorDialog.h

+ 25 - 3
Libs/Widgets/ctkColorDialog.cpp

@@ -139,22 +139,44 @@ QColor ctkColorDialog::getColor(const QColor &initial, QWidget *parent, const QS
   dlg.setCurrentColor(initial);
   foreach(QWidget* tab, ctkColorDialog::DefaultTabs)
     {
-    dlg.addTab(tab, tab->accessibleDescription());
+    dlg.addTab(tab, tab->windowTitle());
+    if (tab->accessibleDescription().isEmpty())
+      {
+      QObject::connect(tab, tab->accessibleDescription().toLatin1(),
+                       &dlg, SLOT(setColor(QColor)));
+      }
     }
   dlg.exec();
   foreach(QWidget* tab, ctkColorDialog::DefaultTabs)
     {
     dlg.removeTab(dlg.indexOf(tab));
+    if (tab->accessibleDescription().isEmpty())
+      {
+      QObject::disconnect(tab, tab->accessibleDescription().toLatin1(),
+                          &dlg, SLOT(setColor(QColor)));
+      }
     tab->setParent(0);
+    tab->hide();
     }
   
   return dlg.selectedColor();
 }
 
 //------------------------------------------------------------------------------
-void ctkColorDialog::addDefaultTab(QWidget* widget, const QString& label)
+void ctkColorDialog::addDefaultTab(QWidget* widget, const QString& label, const char* signal)
 {
-  widget->setAccessibleDescription(label);
+  // I'm a bit lazy here and the label+ signal should probably be stored in a
+  // separate structure
+  widget->setWindowTitle(label);
+  widget->setAccessibleDescription(signal);
+
   ctkColorDialog::DefaultTabs << widget;
   widget->setParent(0);
 }
+
+//------------------------------------------------------------------------------
+void ctkColorDialog::setColor(const QColor& color)
+{
+  this->QColorDialog::setCurrentColor(color);
+}
+  

+ 12 - 2
Libs/Widgets/ctkColorDialog.h

@@ -46,7 +46,9 @@ 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
+  /// The ownership of the widget is taken.
+  /// You must manually connect the color changed signal of the widget 
+  /// to ctkColorDialog::setColor(QColor)
   void addTab(QWidget* widget, const QString& label);
 
   /// The ownership of widget remains the same. The widget is not deleted, 
@@ -72,7 +74,15 @@ public:
   /// QColorDialog::DontUseNativeDialog is forced
   static QColor getColor(const QColor &initial, QWidget *parent,
                          const QString &title, ColorDialogOptions options);
-  static void addDefaultTab(QWidget* widget, const QString& label);
+  /// Add a custom widget as an additional tab of the color dialog created by 
+  /// ctkColorDialog::getColor. \a label is title of the tab and \a signal is the signal fired by 
+  /// the widget whenever a QColor is changed, typically: SIGNAL(currentColorChanged(QColor)). It
+  /// is internally connected to set the current color of the dialog
+  static void addDefaultTab(QWidget* widget, const QString& label, const char* signal = 0);
+
+public slots:
+  /// Slotify QColorDialog::setCurrentColor(QColor)
+  void setColor(const QColor& color);
 
 protected:
   QScopedPointer<ctkColorDialogPrivate> d_ptr;