Forráskód Böngészése

Merge branch '502-flat-ctkCollapsibleButton'

* 502-flat-ctkCollapsibleButton:
  Add ctkCollapsibleButton::flat property
Julien Finet 10 éve
szülő
commit
6a92c85d3f

+ 22 - 1
Libs/Widgets/ctkCollapsibleButton.cpp

@@ -45,7 +45,7 @@ public:
   ctkCollapsibleButtonPrivate(ctkCollapsibleButton& object);
   void init();
   void setChildVisibility(QWidget* childWidget);
-  
+
   bool     Collapsed;
 
   // Contents frame
@@ -55,6 +55,7 @@ public:
   int            ContentsMidLineWidth;
 
   int      CollapsedHeight;
+  bool     Flat;
   bool     ExclusiveMouseOver;
   bool     LookOffWhenChecked;
 
@@ -79,6 +80,7 @@ public:
 ctkCollapsibleButtonPrivate::ctkCollapsibleButtonPrivate(ctkCollapsibleButton& object)
   :q_ptr(&object)
 {
+  this->Flat = false;
   this->ForcingVisibility = false;
   this->IsStateCreated = false;
 }
@@ -184,6 +186,10 @@ void ctkCollapsibleButton::initStyleOption(QStyleOptionButton* option)const
     {
     option->state |= QStyle::State_Raised;
     }
+  if (d->Flat)
+    {
+    option->features |= QStyleOptionButton::Flat;
+    }
 
   option->text = this->text();
   option->icon = this->icon();
@@ -252,6 +258,21 @@ int ctkCollapsibleButton::collapsedHeight()const
 }
 
 //-----------------------------------------------------------------------------
+void ctkCollapsibleButton::setFlat(bool flat)
+{
+  Q_D(ctkCollapsibleButton);
+  d->Flat = flat;
+  this->update();
+}
+
+//-----------------------------------------------------------------------------
+bool ctkCollapsibleButton::isFlat()const
+{
+  Q_D(const ctkCollapsibleButton);
+  return d->Flat;
+}
+
+//-----------------------------------------------------------------------------
 void ctkCollapsibleButton::onToggled(bool checked)
 {
   if (this->isCheckable())

+ 14 - 0
Libs/Widgets/ctkCollapsibleButton.h

@@ -51,6 +51,12 @@ class CTK_WIDGETS_EXPORT ctkCollapsibleButton : public QAbstractButton
   /// 14 pixels by default (same as ctkCollapsibleGroupBox)
   Q_PROPERTY(int collapsedHeight READ collapsedHeight WRITE setCollapsedHeight)
 
+  /// This property holds whether the button border is raised.
+  /// This property's default is false. If this property is set, most styles will not pain the button
+  /// background unless the button is being pressed.
+  /// \sa isFlat(), setFlat(), QPushButton::flat
+  Q_PROPERTY(bool flat READ isFlat WRITE setFlat)
+
   Q_PROPERTY(QFrame::Shape contentsFrameShape READ contentsFrameShape WRITE setContentsFrameShape)
   Q_PROPERTY(QFrame::Shadow contentsFrameShadow READ contentsFrameShadow WRITE setContentsFrameShadow)
   Q_PROPERTY(int contentsLineWidth READ contentsLineWidth WRITE setContentsLineWidth)
@@ -76,6 +82,14 @@ public:
   void setCollapsedHeight(int heightInPixels);
   int collapsedHeight()const;
 
+  /// Set the flat property value.
+  /// \sa flat, isFlat()
+  void setFlat(bool flat);
+
+  /// Return the flat property value.
+  /// \sa flat, setFlat()
+  bool isFlat()const;
+
   /// 
   /// Set the frame shape of the contents
   /// Hint: StyledPanel is probably the shape you are looking for