CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkComboBox.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkComboBox_h
22 #define __ctkComboBox_h
23 
24 // Qt includes
25 #include <QComboBox>
26 
27 // CTK includes
28 #include "ctkPimpl.h"
29 #include "ctkWidgetsExport.h"
30 class ctkComboBoxPrivate;
31 
44 class CTK_WIDGETS_EXPORT ctkComboBox : public QComboBox
45 {
46  Q_OBJECT
47  Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
48  Q_PROPERTY(QIcon defaultIcon READ defaultIcon WRITE setDefaultIcon)
49  Q_PROPERTY(bool forceDefault READ isDefaultForced WRITE forceDefault)
50  Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
54  Q_PROPERTY(ScrollEffect scrollWheelEffect READ scrollWheelEffect WRITE setScrollWheelEffect)
56  Q_PROPERTY(QString currentUserDataAsString READ currentUserDataAsString WRITE setCurrentUserDataAsString)
57 
58  Q_ENUMS(ScrollEffect);
59 public:
61  explicit ctkComboBox(QWidget* parent = 0);
62  virtual ~ctkComboBox();
63 
65  void setDefaultText(const QString&);
66  QString defaultText()const;
67 
69  void setDefaultIcon(const QIcon&);
70  QIcon defaultIcon()const;
71 
74  void forceDefault(bool forceDefault);
75  bool isDefaultForced()const;
76 
79  void setElideMode(const Qt::TextElideMode& newMode);
80  Qt::TextElideMode elideMode()const;
81 
84  {
94  ScrollWithNoVScrollBar
95  };
102 
104  virtual QSize minimumSizeHint()const;
106  virtual QSize sizeHint()const;
107 
109  QString currentUserDataAsString()const;
110 
111 public slots:
113  void setCurrentUserDataAsString(QString userData);
114 
115 protected:
117  virtual void paintEvent(QPaintEvent* event);
118  virtual void changeEvent(QEvent* event);
119  virtual void wheelEvent(QWheelEvent* event);
120 
121 protected:
122  QScopedPointer<ctkComboBoxPrivate> d_ptr;
123 
124 private:
125  Q_DECLARE_PRIVATE(ctkComboBox);
126  Q_DISABLE_COPY(ctkComboBox);
127 };
128 
129 #endif
ctkComboBox is an advanced QComboBox. It adds multiple features:
Definition: ctkComboBox.h:45
QIcon defaultIcon() const
bool isDefaultForced() const
QScopedPointer< ctkComboBoxPrivate > d_ptr
Definition: ctkComboBox.h:122
void forceDefault(bool forceDefault)
void setScrollWheelEffect(ScrollEffect scroll)
Qt::TextElideMode elideMode() const
virtual void wheelEvent(QWheelEvent *event)
QString currentUserDataAsString() const
Get current item's user data as string.
void setCurrentUserDataAsString(QString userData)
Set current item based on user data.
void setDefaultText(const QString &)
Empty by default (same behavior as QComboBox)
ScrollEffect scrollWheelEffect() const
ScrollEffect
\tbd turn into flags ?
Definition: ctkComboBox.h:84
@ AlwaysScroll
Scrolling is always possible with the mouse wheel.
Definition: ctkComboBox.h:88
@ NeverScroll
Scrolling is not possible with the mouse wheel.
Definition: ctkComboBox.h:86
virtual QSize minimumSizeHint() const
Reimplemented for internal reasons.
QString defaultText() const
virtual void paintEvent(QPaintEvent *event)
Reimplemented for internal reasons.
virtual ~ctkComboBox()
void setElideMode(const Qt::TextElideMode &newMode)
virtual void changeEvent(QEvent *event)
void setDefaultIcon(const QIcon &)
Empty by default (same behavior as QComboBox)
ctkComboBox(QWidget *parent=0)
Constructor, build a ctkComboBox that behaves like QComboBox.
virtual QSize sizeHint() const
Reimplemented for internal reasons.