ctkComboBox.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /// \brief ctkComboBox is an advanced QComboBox.
  24. /// It adds multiple features:
  25. /// * Display a default text and/or icon when the combobox current index is
  26. /// invalid (-1). A typical default text would be "Select a XXX...".
  27. /// forceDefault can force the display of the default text at all time (with
  28. /// a valid current index). The text displayed in the combo box can be
  29. /// elided when the size is too small.
  30. /// * Optionally prevent the mouse scroll events from changing the current
  31. /// index.
  32. /// ctkComboBox works exactly the same as QComboBox by default.
  33. /// \sa QComboBox
  34. class CTK_WIDGETS_EXPORT ctkComboBox : public QComboBox
  35. {
  36. Q_OBJECT
  37. Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
  38. Q_PROPERTY(QIcon defaultIcon READ defaultIcon WRITE setDefaultIcon)
  39. Q_PROPERTY(bool forceDefault READ isDefaultForced WRITE forceDefault)
  40. Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
  41. /// This property controls the behavior of the mouse scroll wheel.
  42. /// ScrollOn by default.
  43. /// /sa scrollWheelEffect, setScrollWheelEffect
  44. Q_PROPERTY(ScrollEffect scrollWheelEffect READ scrollWheelEffect WRITE setScrollWheelEffect)
  45. Q_ENUMS(ScrollEffect);
  46. public:
  47. /// Constructor, build a ctkComboBox that behave like QComboBox.
  48. explicit ctkComboBox(QWidget* parent = 0);
  49. virtual ~ctkComboBox();
  50. /// Empty by default (same behavior as QComboBox)
  51. void setDefaultText(const QString&);
  52. QString defaultText()const;
  53. /// Empty by default (same behavior as QComboBox)
  54. void setDefaultIcon(const QIcon&);
  55. QIcon defaultIcon()const;
  56. /// Force the display of the text/icon at all time (not only when the
  57. /// current index is invalid). False by default.
  58. void forceDefault(bool forceDefault);
  59. bool isDefaultForced()const;
  60. /// setElideMode can elide the text displayed on the combobox.
  61. /// Qt::ElideNone by default (same behavior as QComboBox)
  62. void setElideMode(const Qt::TextElideMode& newMode);
  63. Qt::TextElideMode elideMode()const;
  64. /// \tbd turn into flags ?
  65. enum ScrollEffect
  66. {
  67. /// Scrolling is not possible with the mouse wheel.
  68. NeverScroll,
  69. /// Scrolling is always possible with the mouse wheel.
  70. AlwaysScroll,
  71. /// Scrolling is only possible if the combobox has the focus.
  72. /// The focus policy is automatically set to Qt::StrongFocus
  73. ScrollWithFocus,
  74. /// Scrolling is not possible when the combobox is inside a scrollarea with
  75. /// a visible vertical scrollbar.
  76. ScrollWithNoVScrollBar
  77. };
  78. /// Return the scrollWheelEffect property value.
  79. /// \sa scrollEffect
  80. ScrollEffect scrollWheelEffect()const;
  81. /// Set the scrollWheelEffect property value.
  82. /// \sa scrollEffect
  83. void setScrollWheelEffect(ScrollEffect scroll);
  84. /// Reimplemented for internal reasons
  85. virtual QSize minimumSizeHint()const;
  86. /// Reimplemented for internal reasons
  87. virtual QSize sizeHint()const;
  88. protected:
  89. /// Reimplemented for internal reasons
  90. virtual void paintEvent(QPaintEvent* event);
  91. virtual void changeEvent(QEvent* event);
  92. virtual void wheelEvent(QWheelEvent* event);
  93. protected:
  94. QScopedPointer<ctkComboBoxPrivate> d_ptr;
  95. private:
  96. Q_DECLARE_PRIVATE(ctkComboBox);
  97. Q_DISABLE_COPY(ctkComboBox);
  98. };
  99. #endif