瀏覽代碼

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 年之前
父節點
當前提交
a1c4c47a9c

+ 1 - 1
Libs/Widgets/ctkCollapsibleButton.cpp

@@ -96,7 +96,7 @@ void ctkCollapsibleButtonPrivate::init()
   this->ContentsLineWidth = 1;
   this->ContentsMidLineWidth = 0;
 
-  this->CollapsedHeight = 10;
+  this->CollapsedHeight = 14;
   this->ExclusiveMouseOver = false;  
   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
 {
   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(QFrame::Shape contentsFrameShape READ contentsFrameShape WRITE setContentsFrameShape)
@@ -68,9 +71,9 @@ public:
   void setCollapsed(bool);
   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;
 
   /// 

+ 23 - 4
Libs/Widgets/ctkCollapsibleGroupBox.cpp

@@ -52,9 +52,8 @@ class ctkCollapsibleGroupBoxStyle:public QProxyStyle
   }
 };
 #else
-  
-#endif
 
+#endif
 
 //-----------------------------------------------------------------------------
 class ctkCollapsibleGroupBoxPrivate
@@ -71,6 +70,7 @@ public:
   QSize OldSize;
   /// Maximum allowed height
   int   MaxHeight;
+  int   CollapsedHeight;
 
   /// We change the visibility of the chidren in setChildrenVisibility
   /// and we track when the visibility is changed to force it back to possibly
@@ -91,6 +91,7 @@ ctkCollapsibleGroupBoxPrivate::ctkCollapsibleGroupBoxPrivate(
   this->ForcingVisibility = false;
   this->IsStateCreated = false;
   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)
 {
   Q_D(ctkCollapsibleGroupBox);
@@ -199,7 +214,11 @@ void ctkCollapsibleGroupBox::expand(bool _expand)
   else
     {
     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);
   QStyleOptionGroupBox option;
   initStyleOption(&option);
-  option.activeSubControls &= !QStyle::SC_GroupBoxCheckBox;
+  option.activeSubControls &= ~QStyle::SC_GroupBoxCheckBox;
   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_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:
   ctkCollapsibleGroupBox(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)
   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
   /// Catch when a child widget's visibility is externally changed
   virtual bool eventFilter(QObject* child, QEvent* e);