QCMakeWidgets.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <QComboBox>
  6. #include <QCompleter>
  7. #include <QLineEdit>
  8. class QToolButton;
  9. // common widgets for Qt based CMake
  10. /// Editor widget for editing paths or file paths
  11. class QCMakeFileEditor : public QLineEdit
  12. {
  13. Q_OBJECT
  14. public:
  15. QCMakeFileEditor(QWidget* p, QString var);
  16. protected slots:
  17. virtual void chooseFile() = 0;
  18. signals:
  19. void fileDialogExists(bool);
  20. protected:
  21. void resizeEvent(QResizeEvent* e);
  22. QToolButton* ToolButton;
  23. QString Variable;
  24. };
  25. /// editor widget for editing files
  26. class QCMakePathEditor : public QCMakeFileEditor
  27. {
  28. Q_OBJECT
  29. public:
  30. QCMakePathEditor(QWidget* p = nullptr, const QString& var = QString());
  31. void chooseFile();
  32. };
  33. /// editor widget for editing paths
  34. class QCMakeFilePathEditor : public QCMakeFileEditor
  35. {
  36. Q_OBJECT
  37. public:
  38. QCMakeFilePathEditor(QWidget* p = nullptr, const QString& var = QString());
  39. void chooseFile();
  40. };
  41. /// completer class that returns native cmake paths
  42. class QCMakeFileCompleter : public QCompleter
  43. {
  44. Q_OBJECT
  45. public:
  46. QCMakeFileCompleter(QObject* o, bool dirs);
  47. virtual QString pathFromIndex(const QModelIndex& idx) const;
  48. };
  49. // editor for strings
  50. class QCMakeComboBox : public QComboBox
  51. {
  52. Q_OBJECT
  53. Q_PROPERTY(QString value READ currentText WRITE setValue USER true);
  54. public:
  55. QCMakeComboBox(QWidget* p, QStringList strings)
  56. : QComboBox(p)
  57. {
  58. this->addItems(strings);
  59. }
  60. void setValue(const QString& v)
  61. {
  62. int i = this->findText(v);
  63. if (i != -1) {
  64. this->setCurrentIndex(i);
  65. }
  66. }
  67. };