QCMakeWidgets.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef QCMakeWidgets_h
  11. #define QCMakeWidgets_h
  12. #include <QLineEdit>
  13. #include <QComboBox>
  14. #include <QCompleter>
  15. class QToolButton;
  16. // common widgets for Qt based CMake
  17. /// Editor widget for editing paths or file paths
  18. class QCMakeFileEditor : public QLineEdit
  19. {
  20. Q_OBJECT
  21. public:
  22. QCMakeFileEditor(QWidget* p, const QString& var);
  23. protected slots:
  24. virtual void chooseFile() = 0;
  25. signals:
  26. void fileDialogExists(bool);
  27. protected:
  28. void resizeEvent(QResizeEvent* e);
  29. QToolButton* ToolButton;
  30. QString Variable;
  31. };
  32. /// editor widget for editing files
  33. class QCMakePathEditor : public QCMakeFileEditor
  34. {
  35. Q_OBJECT
  36. public:
  37. QCMakePathEditor(QWidget* p = NULL, const QString& var = QString());
  38. void chooseFile();
  39. };
  40. /// editor widget for editing paths
  41. class QCMakeFilePathEditor : public QCMakeFileEditor
  42. {
  43. Q_OBJECT
  44. public:
  45. QCMakeFilePathEditor(QWidget* p = NULL, const QString& var = QString());
  46. void chooseFile();
  47. };
  48. /// completer class that returns native cmake paths
  49. class QCMakeFileCompleter : public QCompleter
  50. {
  51. Q_OBJECT
  52. public:
  53. QCMakeFileCompleter(QObject* o, bool dirs);
  54. virtual QString pathFromIndex(const QModelIndex& idx) const;
  55. };
  56. // editor for strings
  57. class QCMakeComboBox : public QComboBox
  58. {
  59. Q_OBJECT
  60. Q_PROPERTY(QString value READ currentText WRITE setValue USER true);
  61. public:
  62. QCMakeComboBox(QWidget* p, QStringList strings) : QComboBox(p)
  63. {
  64. this->addItems(strings);
  65. }
  66. void setValue(const QString& v)
  67. {
  68. int i = this->findText(v);
  69. if(i != -1)
  70. {
  71. this->setCurrentIndex(i);
  72. }
  73. }
  74. };
  75. #endif