qsplitter.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QSPLITTER_H
  40. #define QSPLITTER_H
  41. #include <QtWidgets/qframe.h>
  42. #include <QtWidgets/qsizepolicy.h>
  43. QT_BEGIN_NAMESPACE
  44. #ifndef QT_NO_SPLITTER
  45. class QSplitterPrivate;
  46. class QTextStream;
  47. template <typename T> class QList;
  48. class QSplitterHandle;
  49. class Q_WIDGETS_EXPORT QSplitter : public QFrame
  50. {
  51. Q_OBJECT
  52. Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
  53. Q_PROPERTY(bool opaqueResize READ opaqueResize WRITE setOpaqueResize)
  54. Q_PROPERTY(int handleWidth READ handleWidth WRITE setHandleWidth)
  55. Q_PROPERTY(bool childrenCollapsible READ childrenCollapsible WRITE setChildrenCollapsible)
  56. public:
  57. explicit QSplitter(QWidget* parent = Q_NULLPTR);
  58. explicit QSplitter(Qt::Orientation, QWidget* parent = Q_NULLPTR);
  59. ~QSplitter();
  60. void addWidget(QWidget *widget);
  61. void insertWidget(int index, QWidget *widget);
  62. void setOrientation(Qt::Orientation);
  63. Qt::Orientation orientation() const;
  64. void setChildrenCollapsible(bool);
  65. bool childrenCollapsible() const;
  66. void setCollapsible(int index, bool);
  67. bool isCollapsible(int index) const;
  68. void setOpaqueResize(bool opaque = true);
  69. bool opaqueResize() const;
  70. void refresh();
  71. QSize sizeHint() const Q_DECL_OVERRIDE;
  72. QSize minimumSizeHint() const Q_DECL_OVERRIDE;
  73. QList<int> sizes() const;
  74. void setSizes(const QList<int> &list);
  75. QByteArray saveState() const;
  76. bool restoreState(const QByteArray &state);
  77. int handleWidth() const;
  78. void setHandleWidth(int);
  79. int indexOf(QWidget *w) const;
  80. QWidget *widget(int index) const;
  81. int count() const;
  82. void getRange(int index, int *, int *) const;
  83. QSplitterHandle *handle(int index) const;
  84. void setStretchFactor(int index, int stretch);
  85. Q_SIGNALS:
  86. void splitterMoved(int pos, int index);
  87. protected:
  88. virtual QSplitterHandle *createHandle();
  89. void childEvent(QChildEvent *) Q_DECL_OVERRIDE;
  90. bool event(QEvent *) Q_DECL_OVERRIDE;
  91. void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
  92. void changeEvent(QEvent *) Q_DECL_OVERRIDE;
  93. void moveSplitter(int pos, int index);
  94. void setRubberBand(int position);
  95. int closestLegalPosition(int, int);
  96. private:
  97. Q_DISABLE_COPY(QSplitter)
  98. Q_DECLARE_PRIVATE(QSplitter)
  99. private:
  100. friend class QSplitterHandle;
  101. };
  102. Q_WIDGETS_EXPORT QTextStream& operator<<(QTextStream&, const QSplitter&);
  103. Q_WIDGETS_EXPORT QTextStream& operator>>(QTextStream&, QSplitter&);
  104. class QSplitterHandlePrivate;
  105. class Q_WIDGETS_EXPORT QSplitterHandle : public QWidget
  106. {
  107. Q_OBJECT
  108. public:
  109. explicit QSplitterHandle(Qt::Orientation o, QSplitter *parent);
  110. ~QSplitterHandle();
  111. void setOrientation(Qt::Orientation o);
  112. Qt::Orientation orientation() const;
  113. bool opaqueResize() const;
  114. QSplitter *splitter() const;
  115. QSize sizeHint() const Q_DECL_OVERRIDE;
  116. protected:
  117. void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
  118. void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  119. void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  120. void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  121. void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
  122. bool event(QEvent *) Q_DECL_OVERRIDE;
  123. void moveSplitter(int p);
  124. int closestLegalPosition(int p);
  125. private:
  126. Q_DISABLE_COPY(QSplitterHandle)
  127. Q_DECLARE_PRIVATE(QSplitterHandle)
  128. };
  129. #endif // QT_NO_SPLITTER
  130. QT_END_NAMESPACE
  131. #endif // QSPLITTER_H