Browse Source

Merge branch '445-fix-ctkPushButton-text-alignment'

* 445-fix-ctkPushButton-text-alignment:
  Fix ctkPushButton text alignment with no icon
Julien Finet 11 years ago
parent
commit
a95f0c4716

+ 3 - 0
Libs/Widgets/Testing/Cpp/CMakeLists.txt

@@ -63,6 +63,7 @@ set(TEST_SOURCES
   ctkPathListWidgetTest.cpp
   ctkPathListWidgetWithButtonsTest.cpp
   ctkPopupWidgetTest1.cpp
+  ctkPushButtonTest.cpp
   ctkProxyStyleTest1.cpp
   ctkRangeSliderTest.cpp
   ctkRangeSliderTest1.cpp
@@ -202,6 +203,7 @@ QT4_GENERATE_MOCS(
   ctkMessageBoxDontShowAgainTest.cpp
   ctkPathListWidgetTest.cpp
   ctkPathListWidgetWithButtonsTest.cpp
+  ctkPushButtonTest.cpp
   ctkRangeSliderTest.cpp
   ctkRangeWidgetTest.cpp
   ctkRangeWidgetValueProxyTest.cpp
@@ -290,6 +292,7 @@ SIMPLE_TEST( ctkPathListWidgetTest )
 SIMPLE_TEST( ctkPathListWidgetWithButtonsTest )
 SIMPLE_TEST( ctkPopupWidgetTest1 )
 SIMPLE_TEST( ctkProxyStyleTest1 )
+SIMPLE_TEST( ctkPushButtonTest )
 SIMPLE_TEST( ctkRangeSliderTest )
 SIMPLE_TEST( ctkRangeSliderTest1 )
 SIMPLE_TEST( ctkRangeWidgetTest )

+ 61 - 0
Libs/Widgets/Testing/Cpp/ctkPushButtonTest.cpp

@@ -0,0 +1,61 @@
+/*=========================================================================
+
+  Library:   CTK
+
+  Copyright (c) Kitware Inc.
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0.txt
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+=========================================================================*/
+
+// Qt includes
+#include <QApplication>
+#include <QCleanlooksStyle>
+#include <QHBoxLayout>
+#include <QPlastiqueStyle>
+#include <QSignalSpy>
+#include <QTimer>
+#include <QWindowsStyle>
+
+// CTK includes
+#include "ctkPushButton.h"
+#include "ctkTest.h"
+
+//-----------------------------------------------------------------------------
+class ctkPushButtonTester : public QObject
+{
+  Q_OBJECT
+
+private slots:
+
+  void testDefaults();
+};
+
+// ----------------------------------------------------------------------------
+void ctkPushButtonTester::testDefaults()
+{
+  QApplication::setStyle( new QCleanlooksStyle );
+
+  ctkPushButton button("text");
+
+  QCOMPARE(button.buttonTextAlignment(), Qt::AlignHCenter|Qt::AlignVCenter);
+  QCOMPARE(button.iconAlignment(), Qt::AlignLeft|Qt::AlignVCenter);
+
+  button.show();
+  QTest::qWaitForWindowShown(&button);
+  //qApp->exec();
+}
+
+// ----------------------------------------------------------------------------
+CTK_TEST_MAIN(ctkPushButtonTest)
+#include "moc_ctkPushButtonTest.cpp"

+ 5 - 0
Libs/Widgets/ctkPushButton.cpp

@@ -145,6 +145,11 @@ QStyleOptionButton ctkPushButtonPrivate::drawIcon(QPainter* p)
   QStyleOptionButton iconOpt;
   iconOpt.init(q);
   iconOpt.rect = this->iconRect();
+  if (q->icon().isNull())
+    {
+    iconOpt.rect.setWidth(0);
+    return iconOpt;
+    }
   QIcon::Mode mode = iconOpt.state & QStyle::State_Enabled ? QIcon::Normal : QIcon::Disabled;
   if (mode == QIcon::Normal && iconOpt.state & QStyle::State_HasFocus)
     {