ctkTreeComboBox.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 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 __ctkTreeComboBox_h
  15. #define __ctkTreeComboBox_h
  16. // Qt includes
  17. #include <QComboBox>
  18. // CTK includes
  19. #include <ctkPimpl.h>
  20. #include "CTKWidgetsExport.h"
  21. /// Description:
  22. /// ComboBox that displays the items as a tree view.
  23. /// See below for a use case:
  24. /// ctkTreeComboBox combo;
  25. /// QStandardItemModel model;
  26. /// model.appendRow(new QStandardItem("Test1"));
  27. /// model.item(0)->appendRow(new QStandardItem("Test1.1"));
  28. /// model.item(0)->appendRow(new QStandardItem("Test1.2"));
  29. /// model.item(0)->appendRow(new QStandardItem("Test1.3"));
  30. /// model.appendRow(new QStandardItem("Test2"));
  31. /// model.appendRow(new QStandardItem("Test3"));
  32. /// combo.setModel(&model);
  33. /// combo.show();
  34. //
  35. class ctkTreeComboBoxPrivate;
  36. class CTK_WIDGETS_EXPORT ctkTreeComboBox : public QComboBox
  37. {
  38. Q_OBJECT
  39. public:
  40. typedef QComboBox Superclass;
  41. explicit ctkTreeComboBox(QWidget* parent = 0);
  42. virtual ~ctkTreeComboBox(){}
  43. virtual bool eventFilter(QObject* object, QEvent* event);
  44. virtual void showPopup();
  45. virtual void hidePopup();
  46. protected:
  47. virtual void paintEvent(QPaintEvent*);
  48. protected slots:
  49. void onExpanded(const QModelIndex&);
  50. void onCollapsed(const QModelIndex&);
  51. private:
  52. CTK_DECLARE_PRIVATE(ctkTreeComboBox);
  53. };
  54. #endif