Prechádzať zdrojové kódy

Enlarge default collapsed height of ctkCollapsibleGroupBox for Mac Os style

If you plan to change the default height, please apply the same height
to the groupbox and button.
Note that 14px is the smallest height that look normal for Mac style.
Julien Finet 13 rokov pred
rodič
commit
a1c4c47a9c

+ 1 - 1
Libs/Widgets/ctkCollapsibleButton.cpp

@@ -96,7 +96,7 @@ void ctkCollapsibleButtonPrivate::init()
   this->ContentsLineWidth = 1;
   this->ContentsLineWidth = 1;
   this->ContentsMidLineWidth = 0;
   this->ContentsMidLineWidth = 0;
 
 
-  this->CollapsedHeight = 10;
+  this->CollapsedHeight = 14;
   this->ExclusiveMouseOver = false;  
   this->ExclusiveMouseOver = false;  
   this->LookOffWhenChecked = true; // set as a prop ?
   this->LookOffWhenChecked = true; // set as a prop ?
   
   

+ 7 - 4
Libs/Widgets/ctkCollapsibleButton.h

@@ -45,7 +45,10 @@ class QStyleOptionButton;
 class CTK_WIDGETS_EXPORT ctkCollapsibleButton : public QAbstractButton
 class CTK_WIDGETS_EXPORT ctkCollapsibleButton : public QAbstractButton
 {
 {
   Q_OBJECT
   Q_OBJECT
-  Q_PROPERTY(bool collapsed READ collapsed WRITE setCollapsed DESIGNABLE isCheckable NOTIFY contentsCollapsed)
+  Q_PROPERTY(bool collapsed READ collapsed WRITE setCollapsed NOTIFY contentsCollapsed)
+  /// This property holds the height in pixels of the contents (excludes the button)
+  /// when the button is collapsed.
+  /// 14 pixels by default (same as ctkCollapsibleGroupBox)
   Q_PROPERTY(int collapsedHeight READ collapsedHeight WRITE setCollapsedHeight)
   Q_PROPERTY(int collapsedHeight READ collapsedHeight WRITE setCollapsedHeight)
 
 
   Q_PROPERTY(QFrame::Shape contentsFrameShape READ contentsFrameShape WRITE setContentsFrameShape)
   Q_PROPERTY(QFrame::Shape contentsFrameShape READ contentsFrameShape WRITE setContentsFrameShape)
@@ -68,9 +71,9 @@ public:
   void setCollapsed(bool);
   void setCollapsed(bool);
   bool collapsed()const;
   bool collapsed()const;
 
 
-  /// 
-  /// Height used when the widget is collapsed
-  void setCollapsedHeight(int);
+  ///
+  /// \todo resize the widget when setting the new height
+  void setCollapsedHeight(int heightInPixels);
   int collapsedHeight()const;
   int collapsedHeight()const;
 
 
   /// 
   /// 

+ 23 - 4
Libs/Widgets/ctkCollapsibleGroupBox.cpp

@@ -52,9 +52,8 @@ class ctkCollapsibleGroupBoxStyle:public QProxyStyle
   }
   }
 };
 };
 #else
 #else
-  
-#endif
 
 
+#endif
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 class ctkCollapsibleGroupBoxPrivate
 class ctkCollapsibleGroupBoxPrivate
@@ -71,6 +70,7 @@ public:
   QSize OldSize;
   QSize OldSize;
   /// Maximum allowed height
   /// Maximum allowed height
   int   MaxHeight;
   int   MaxHeight;
+  int   CollapsedHeight;
 
 
   /// We change the visibility of the chidren in setChildrenVisibility
   /// We change the visibility of the chidren in setChildrenVisibility
   /// and we track when the visibility is changed to force it back to possibly
   /// and we track when the visibility is changed to force it back to possibly
@@ -91,6 +91,7 @@ ctkCollapsibleGroupBoxPrivate::ctkCollapsibleGroupBoxPrivate(
   this->ForcingVisibility = false;
   this->ForcingVisibility = false;
   this->IsStateCreated = false;
   this->IsStateCreated = false;
   this->MaxHeight = 0;
   this->MaxHeight = 0;
+  this->CollapsedHeight = 14;
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -173,6 +174,20 @@ ctkCollapsibleGroupBox::~ctkCollapsibleGroupBox()
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
+void ctkCollapsibleGroupBox::setCollapsedHeight(int heightInPixels)
+{
+  Q_D(ctkCollapsibleGroupBox);
+  d->CollapsedHeight = heightInPixels;
+}
+
+//-----------------------------------------------------------------------------
+int ctkCollapsibleGroupBox::collapsedHeight()const
+{
+  Q_D(const ctkCollapsibleGroupBox);
+  return d->CollapsedHeight;
+}
+
+//-----------------------------------------------------------------------------
 void ctkCollapsibleGroupBox::expand(bool _expand)
 void ctkCollapsibleGroupBox::expand(bool _expand)
 {
 {
   Q_D(ctkCollapsibleGroupBox);
   Q_D(ctkCollapsibleGroupBox);
@@ -199,7 +214,11 @@ void ctkCollapsibleGroupBox::expand(bool _expand)
   else
   else
     {
     {
     d->MaxHeight = this->maximumHeight();
     d->MaxHeight = this->maximumHeight();
-    this->setMaximumHeight(22);
+    QStyleOptionGroupBox option;
+    this->initStyleOption(&option);
+    QRect labelRect = this->style()->subControlRect(
+      QStyle::CC_GroupBox, &option, QStyle::SC_GroupBoxLabel, this);
+    this->setMaximumHeight(labelRect.height() + d->CollapsedHeight);
     }
     }
 }
 }
 
 
@@ -212,7 +231,7 @@ void ctkCollapsibleGroupBox::paintEvent(QPaintEvent* e)
   QStylePainter paint(this);
   QStylePainter paint(this);
   QStyleOptionGroupBox option;
   QStyleOptionGroupBox option;
   initStyleOption(&option);
   initStyleOption(&option);
-  option.activeSubControls &= !QStyle::SC_GroupBoxCheckBox;
+  option.activeSubControls &= ~QStyle::SC_GroupBoxCheckBox;
   paint.drawComplexControl(QStyle::CC_GroupBox, option);
   paint.drawComplexControl(QStyle::CC_GroupBox, option);
   
   
 }
 }

+ 10 - 0
Libs/Widgets/ctkCollapsibleGroupBox.h

@@ -38,6 +38,12 @@ class CTK_WIDGETS_EXPORT ctkCollapsibleGroupBox : public QGroupBox
 {
 {
   Q_OBJECT
   Q_OBJECT
   Q_PROPERTY(bool collapsed READ collapsed WRITE setCollapsed)
   Q_PROPERTY(bool collapsed READ collapsed WRITE setCollapsed)
+
+  /// This property holds the height in pixels of the contents (excludes the title)
+  /// when the box is collapsed.
+  /// 14px by default, it is the smallest height that fit Mac Style.
+  Q_PROPERTY(int collapsedHeight READ collapsedHeight WRITE setCollapsedHeight)
+
 public:
 public:
   ctkCollapsibleGroupBox(QWidget* parent = 0);
   ctkCollapsibleGroupBox(QWidget* parent = 0);
   ctkCollapsibleGroupBox(const QString& title, QWidget* parent = 0);
   ctkCollapsibleGroupBox(const QString& title, QWidget* parent = 0);
@@ -53,6 +59,10 @@ public:
   /// true if the groupbox is collapsed (closed), false if it is expanded(open)
   /// true if the groupbox is collapsed (closed), false if it is expanded(open)
   inline bool collapsed()const;
   inline bool collapsed()const;
 
 
+  /// Set the height of the collapsed box. Does not include the title height.
+  virtual void setCollapsedHeight(int heightInPixels);
+  int collapsedHeight()const;
+
   /// Reimplemented for internal reasons
   /// Reimplemented for internal reasons
   /// Catch when a child widget's visibility is externally changed
   /// Catch when a child widget's visibility is externally changed
   virtual bool eventFilter(QObject* child, QEvent* e);
   virtual bool eventFilter(QObject* child, QEvent* e);