ctkComboBox.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkComboBox_h
  15. #define __ctkComboBox_h
  16. // Qt includes
  17. #include <QComboBox>
  18. // CTK includes
  19. #include "ctkPimpl.h"
  20. #include "ctkWidgetsExport.h"
  21. class ctkComboBoxPrivate;
  22. /// \ingroup Widgets
  23. /// ctkComboBox is an advanced QComboBox. It allows the display of a default
  24. /// text/icon when the combobox current index is invalid (-1). A typical
  25. /// default text would be "Select a XXX..."
  26. /// forceDefault can force the display of the default text at all time (with
  27. /// a valid current index). The text displayed in the combo box can be
  28. /// elided when the size is too small.
  29. /// ctkComboBox works exactly the same as QComboBox by default.
  30. class CTK_WIDGETS_EXPORT ctkComboBox : public QComboBox
  31. {
  32. Q_OBJECT
  33. Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
  34. Q_PROPERTY(QIcon defaultIcon READ defaultIcon WRITE setDefaultIcon)
  35. Q_PROPERTY(bool forceDefault READ isDefaultForced WRITE forceDefault)
  36. Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
  37. public:
  38. /// Constructor, build a ctkComboBox that behave like QComboBox.
  39. explicit ctkComboBox(QWidget* parent = 0);
  40. virtual ~ctkComboBox();
  41. /// Empty by default (same behavior as QComboBox)
  42. void setDefaultText(const QString&);
  43. QString defaultText()const;
  44. /// Empty by default (same behavior as QComboBox)
  45. void setDefaultIcon(const QIcon&);
  46. QIcon defaultIcon()const;
  47. /// Force the display of the text/icon at all time (not only when the
  48. /// current index is invalid). False by default.
  49. void forceDefault(bool forceDefault);
  50. bool isDefaultForced()const;
  51. /// setElideMode can elide the text displayed on the combobox.
  52. /// Qt::ElideNone by default (same behavior as QComboBox)
  53. void setElideMode(const Qt::TextElideMode& newMode);
  54. Qt::TextElideMode elideMode()const;
  55. /// Reimplemented for internal reasons
  56. virtual QSize minimumSizeHint()const;
  57. /// Reimplemented for internal reasons
  58. virtual QSize sizeHint()const;
  59. protected:
  60. /// Reimplemented for internal reasons
  61. virtual void paintEvent(QPaintEvent*);
  62. virtual void changeEvent(QEvent *e);
  63. protected:
  64. QScopedPointer<ctkComboBoxPrivate> d_ptr;
  65. private:
  66. Q_DECLARE_PRIVATE(ctkComboBox);
  67. Q_DISABLE_COPY(ctkComboBox);
  68. };
  69. #endif