qtpropertybrowserutils_p.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the Qt Solutions component.
  7. **
  8. ** $QT_BEGIN_LICENSE:BSD$
  9. ** You may use this file under the terms of the BSD license as follows:
  10. **
  11. ** "Redistribution and use in source and binary forms, with or without
  12. ** modification, are permitted provided that the following conditions are
  13. ** met:
  14. ** * Redistributions of source code must retain the above copyright
  15. ** notice, this list of conditions and the following disclaimer.
  16. ** * Redistributions in binary form must reproduce the above copyright
  17. ** notice, this list of conditions and the following disclaimer in
  18. ** the documentation and/or other materials provided with the
  19. ** distribution.
  20. ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
  21. ** of its contributors may be used to endorse or promote products derived
  22. ** from this software without specific prior written permission.
  23. **
  24. **
  25. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  36. **
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40. //
  41. // W A R N I N G
  42. // -------------
  43. //
  44. // This file is not part of the Qt API. It exists for the convenience
  45. // of Qt Designer. This header
  46. // file may change from version to version without notice, or even be removed.
  47. //
  48. // We mean it.
  49. //
  50. #ifndef QTPROPERTYBROWSERUTILS_H
  51. #define QTPROPERTYBROWSERUTILS_H
  52. #include <QMap>
  53. #include <QIcon>
  54. #include <QWidget>
  55. #include <QStringList>
  56. #if QT_VERSION >= 0x040400
  57. QT_BEGIN_NAMESPACE
  58. #endif
  59. class QMouseEvent;
  60. class QCheckBox;
  61. class QLineEdit;
  62. class QtCursorDatabase
  63. {
  64. public:
  65. QtCursorDatabase();
  66. void clear();
  67. QStringList cursorShapeNames() const;
  68. QMap<int, QIcon> cursorShapeIcons() const;
  69. QString cursorToShapeName(const QCursor &cursor) const;
  70. QIcon cursorToShapeIcon(const QCursor &cursor) const;
  71. int cursorToValue(const QCursor &cursor) const;
  72. #ifndef QT_NO_CURSOR
  73. QCursor valueToCursor(int value) const;
  74. #endif
  75. private:
  76. void appendCursor(Qt::CursorShape shape, const QString &name, const QIcon &icon);
  77. QStringList m_cursorNames;
  78. QMap<int, QIcon> m_cursorIcons;
  79. QMap<int, Qt::CursorShape> m_valueToCursorShape;
  80. QMap<Qt::CursorShape, int> m_cursorShapeToValue;
  81. };
  82. class QtPropertyBrowserUtils
  83. {
  84. public:
  85. static QPixmap brushValuePixmap(const QBrush &b);
  86. static QIcon brushValueIcon(const QBrush &b);
  87. static QString colorValueText(const QColor &c);
  88. static QPixmap fontValuePixmap(const QFont &f);
  89. static QIcon fontValueIcon(const QFont &f);
  90. static QString fontValueText(const QFont &f);
  91. };
  92. class QtBoolEdit : public QWidget {
  93. Q_OBJECT
  94. public:
  95. QtBoolEdit(QWidget *parent = 0);
  96. bool textVisible() const { return m_textVisible; }
  97. void setTextVisible(bool textVisible);
  98. Qt::CheckState checkState() const;
  99. void setCheckState(Qt::CheckState state);
  100. bool isChecked() const;
  101. void setChecked(bool c);
  102. bool blockCheckBoxSignals(bool block);
  103. Q_SIGNALS:
  104. void toggled(bool);
  105. protected:
  106. void mousePressEvent(QMouseEvent * event);
  107. void paintEvent(QPaintEvent *);
  108. private:
  109. QCheckBox *m_checkBox;
  110. bool m_textVisible;
  111. };
  112. class QtKeySequenceEdit : public QWidget
  113. {
  114. Q_OBJECT
  115. public:
  116. QtKeySequenceEdit(QWidget *parent = 0);
  117. QKeySequence keySequence() const;
  118. bool eventFilter(QObject *o, QEvent *e);
  119. public Q_SLOTS:
  120. void setKeySequence(const QKeySequence &sequence);
  121. Q_SIGNALS:
  122. void keySequenceChanged(const QKeySequence &sequence);
  123. protected:
  124. void focusInEvent(QFocusEvent *e);
  125. void focusOutEvent(QFocusEvent *e);
  126. void keyPressEvent(QKeyEvent *e);
  127. void keyReleaseEvent(QKeyEvent *e);
  128. void paintEvent(QPaintEvent *);
  129. bool event(QEvent *e);
  130. private slots:
  131. void slotClearShortcut();
  132. private:
  133. void handleKeyEvent(QKeyEvent *e);
  134. int translateModifiers(Qt::KeyboardModifiers state, const QString &text) const;
  135. int m_num;
  136. QKeySequence m_keySequence;
  137. QLineEdit *m_lineEdit;
  138. };
  139. #if QT_VERSION >= 0x040400
  140. QT_END_NAMESPACE
  141. #endif
  142. #endif