ctkComboBox.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.commontk.org/LICENSE
  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. /// ctkComboBox is an advanced QComboBox. It allows the display of a default
  23. /// text/icon when the combobox current index is invalid (-1). A typical
  24. /// default text would be "Select a XXX..."
  25. /// forceDefault can force the display of the default text at all time (with
  26. /// a valid current index). The text displayed in the combo box can be
  27. /// elided when the size is too small.
  28. /// ctkComboBox works exactly the same as QComboBox by default.
  29. class CTK_WIDGETS_EXPORT ctkComboBox : public QComboBox
  30. {
  31. Q_OBJECT
  32. Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
  33. Q_PROPERTY(QIcon defaultIcon READ defaultIcon WRITE setDefaultIcon)
  34. Q_PROPERTY(bool forceDefault READ isDefaultForced WRITE forceDefault)
  35. Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
  36. public:
  37. /// Constructor, build a ctkComboBox that behave like QComboBox.
  38. explicit ctkComboBox(QWidget* parent = 0);
  39. virtual ~ctkComboBox();
  40. /// Empty by default (same behavior as QComboBox)
  41. void setDefaultText(const QString&);
  42. QString defaultText()const;
  43. /// Empty by default (same behavior as QComboBox)
  44. void setDefaultIcon(const QIcon&);
  45. QIcon defaultIcon()const;
  46. /// Force the display of the text/icon at all time (not only when the
  47. /// current index is invalid). False by default.
  48. void forceDefault(bool forceDefault);
  49. bool isDefaultForced()const;
  50. /// setElideMode can elide the text displayed on the combobox.
  51. /// Qt::ElideNone by default (same behavior as QComboBox)
  52. void setElideMode(const Qt::TextElideMode& newMode);
  53. Qt::TextElideMode elideMode()const;
  54. /// Reimplemented for internal reasons
  55. virtual QSize minimumSizeHint()const;
  56. /// Reimplemented for internal reasons
  57. virtual QSize sizeHint()const;
  58. protected:
  59. /// Reimplemented for internal reasons
  60. virtual void paintEvent(QPaintEvent*);
  61. protected:
  62. QScopedPointer<ctkComboBoxPrivate> d_ptr;
  63. private:
  64. Q_DECLARE_PRIVATE(ctkComboBox);
  65. Q_DISABLE_COPY(ctkComboBox);
  66. };
  67. #endif