| |
| |
| #ifndef DOCKLAYOUT_H |
| #define DOCKLAYOUT_H |
| |
| #include "tcommon.h" |
| |
| #include <QWidget> |
| #include <QAction> |
| |
| #include <deque> |
| #include <vector> |
| #include <QLayout> |
| #include <QFrame> |
| #include "docklayout.h" |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TOONZQT_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| |
| |
| |
| class DockLayout; |
| class DockWidget; |
| |
| class DockPlaceholder; |
| class DockSeparator; |
| class DockDecoAllocator; |
| |
| class Region; |
| |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI DockingCheck |
| { |
| bool m_enabled; |
| QAction *m_toggle; |
| DockingCheck() : m_enabled(false), m_toggle(0) {} |
| |
| public: |
| static DockingCheck *instance(); |
| void setToggle(QAction *toggle); |
| bool isEnabled() const { return m_enabled; } |
| void setIsEnabled(bool on); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI DockLayout : public QLayout |
| { |
| std::vector<QLayoutItem *> m_items; |
| std::deque<Region *> m_regions; |
| |
| DockWidget *m_maximizedDock; |
| |
| |
| DockDecoAllocator *m_decoAllocator; |
| |
| public: |
| DockLayout(); |
| virtual ~DockLayout(); |
| |
| |
| int count(void) const; |
| void addItem(QLayoutItem *item); |
| QSize sizeHint() const; |
| QSize minimumSize() const; |
| QSize maximumSize() const; |
| QLayoutItem *itemAt(int) const; |
| QWidget *widgetAt(int) const; |
| QLayoutItem *takeAt(int); |
| void setGeometry(const QRect &rect); |
| |
| void update(); |
| void redistribute(); |
| void applyTransform(const QTransform &transform); |
| |
| DockWidget *getMaximized() { return m_maximizedDock; } |
| void setMaximized(DockWidget *item, bool state = true); |
| |
| |
| Region *dockItem(DockWidget *item, Region *r = 0, int idx = 0); |
| void dockItem(DockWidget *item, DockPlaceholder *place); |
| void dockItem(DockWidget *item, DockWidget *target, int regionSide); |
| bool undockItem(DockWidget *item); |
| void calculateDockPlaceholders(DockWidget *item); |
| |
| |
| Region *rootRegion() const { return m_regions.size() ? m_regions.front() : 0; } |
| const std::deque<Region *> ®ions() const { return m_regions; } |
| Region *region(int i) const { return m_regions[i]; } |
| Region *find(DockWidget *item) const; |
| QWidget *containerOf(QPoint point) const; |
| |
| |
| typedef std::pair<std::vector<QRect>, QString> State; |
| |
| State saveState(); |
| bool restoreState(const State &state); |
| |
| |
| void setDecoAllocator(DockDecoAllocator *decoAllocator); |
| |
| private: |
| void applyGeometry(); |
| inline void updateSeparatorCursors(); |
| Region *dockItemPrivate(DockWidget *item, Region *r, int idx); |
| |
| |
| bool isPossibleInsertion(DockWidget *item, Region *parentRegion, int insertionIdx); |
| bool isPossibleRemoval(DockWidget *item, Region *parentRegion, int removalIdx); |
| |
| |
| void writeRegion(Region *r, QString &hierarchy); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI DockWidget : public QWidget |
| { |
| friend class DockLayout; |
| friend class DockPlaceholder; |
| |
| |
| protected: |
| |
| bool m_floating; |
| bool m_dragging; |
| bool m_undocking; |
| |
| |
| |
| bool m_resizing; |
| int m_marginType; |
| |
| |
| bool m_maximized; |
| |
| private: |
| QPoint m_dragInitialPos; |
| QPoint m_dragMouseInitialPos; |
| |
| |
| DockLayout *m_parentLayout; |
| |
| |
| DockDecoAllocator *m_decoAllocator; |
| |
| int m_saveIndex; |
| |
| protected: |
| |
| std::vector<DockPlaceholder *> m_placeholders; |
| DockPlaceholder *m_selectedPlace; |
| |
| public: |
| DockWidget(QWidget *parent = 0, Qt::WindowFlags flags = Qt::Tool); |
| virtual ~DockWidget(); |
| |
| |
| DockLayout *parentLayout() const { return m_parentLayout; } |
| |
| bool isFloating() const { return m_floating; } |
| bool isMaximized() const { return m_maximized; } |
| |
| |
| QWidget *hoveredWidget(QMouseEvent *me); |
| DockPlaceholder *placeAdjacentTo(DockWidget *dockWidget, int boundary); |
| DockPlaceholder *placeOfSeparator(DockSeparator *); |
| const std::vector<DockPlaceholder *> &placeholders() const { return m_placeholders; } |
| |
| |
| |
| |
| |
| virtual QSize getDockedMinimumSize() { return minimumSize(); } |
| |
| |
| |
| virtual QSize getDockedMaximumSize() { return maximumSize(); } |
| |
| |
| |
| |
| virtual void setFloatingAppearance() { setWindowFlags(Qt::Tool); } |
| |
| |
| |
| |
| virtual void setDockedAppearance() {} |
| |
| virtual bool isDragGrip(QPoint p); |
| virtual int isResizeGrip(QPoint) |
| { |
| return 0; |
| } |
| |
| enum { leftMargin = 0x1, |
| rightMargin = 0x2, |
| topMargin = 0x4, |
| bottomMargin = 0x8 }; |
| |
| |
| virtual void selectDockPlaceholder(QMouseEvent *me); |
| void clearDockPlaceholders(); |
| |
| |
| void setDecoAllocator(DockDecoAllocator *decoAllocator); |
| |
| |
| virtual void onDock(bool docked) {} |
| |
| private: |
| |
| |
| bool event(QEvent *e); |
| void mousePressEvent(QMouseEvent *me); |
| void mouseReleaseEvent(QMouseEvent *me); |
| void mouseMoveEvent(QMouseEvent *me); |
| void hoverMoveEvent(QHoverEvent *he); |
| |
| protected: |
| |
| virtual void wheelEvent(QWheelEvent *we); |
| virtual void mouseDoubleClickEvent(QMouseEvent *me); |
| virtual void windowTitleEvent(QEvent *) {} |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class DockSeparator : public QWidget |
| { |
| friend class DockLayout; |
| friend class Region; |
| |
| DockLayout *m_owner; |
| |
| |
| bool m_pressed; |
| QPoint m_oldOrigin; |
| QPoint m_oldPos; |
| |
| |
| Region *m_parentRegion; |
| int m_index; |
| bool m_orientation; |
| |
| |
| double m_leftBound; |
| double m_rightBound; |
| |
| public: |
| DockSeparator(DockLayout *owner, bool orientation, Region *parentRegion); |
| virtual ~DockSeparator() {} |
| |
| |
| bool getOrientation() const { return m_orientation; } |
| Region *getParentRegion() const { return m_parentRegion; } |
| int getIndex() const { return m_index; } |
| |
| |
| void shift(int dx); |
| |
| private: |
| void calculateBounds(); |
| |
| void mousePressEvent(QMouseEvent *me); |
| void mouseReleaseEvent(QMouseEvent *me); |
| void mouseMoveEvent(QMouseEvent *me); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class DockPlaceholder : public QWidget |
| { |
| friend class DockLayout; |
| |
| |
| Region *m_region; |
| int m_idx; |
| |
| |
| int m_attributes; |
| |
| |
| DockSeparator *m_separator; |
| DockWidget *m_owner; |
| |
| public: |
| DockPlaceholder(DockWidget *owner, Region *r, int idx, int attributes = 0); |
| virtual ~DockPlaceholder() {} |
| |
| |
| |
| |
| DockSeparator *getSeparator() const; |
| |
| DockWidget *getDockWidget() const { return m_owner; } |
| |
| Region *getParentRegion() const { return m_region; } |
| |
| int getInsertionIdx() const { return m_idx; } |
| |
| enum { left = 0, |
| right = 1, |
| top = 2, |
| bottom = 3, |
| sepHor = 4, |
| sepVert = 5, |
| root = 6 }; |
| int getAttribute() const { return m_attributes; } |
| void setAttribute(int attribute) { m_attributes = attribute; } |
| |
| |
| QRect parentGeometry() const; |
| virtual void buildGeometry(); |
| |
| |
| |
| bool isRoot() const { return m_attributes == root; } |
| DockPlaceholder *parentPlaceholder(); |
| DockPlaceholder *greatestPlaceholder(); |
| DockPlaceholder *childPlaceholder(QPoint p); |
| DockPlaceholder *smallestPlaceholder(QPoint p); |
| |
| private: |
| |
| void wheelEvent(QWheelEvent *we) { m_owner->wheelEvent(we); } |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class Region |
| { |
| friend class DockLayout; |
| friend class DockSeparator; |
| |
| DockLayout *m_owner; |
| DockWidget *m_item; |
| Region *m_parent; |
| std::deque<Region *> m_childList; |
| std::deque<DockSeparator *> m_separators; |
| |
| std::vector<DockPlaceholder *> m_placeholders; |
| |
| QRectF m_rect; |
| bool m_orientation; |
| |
| int m_minimumSize[2]; |
| int m_maximumSize[2]; |
| |
| int m_saveIndex; |
| |
| public: |
| Region(DockLayout *owner, DockWidget *item = 0) |
| : m_owner(owner), m_item(item), m_parent(0), m_orientation(0) {} |
| ~Region(); |
| |
| enum { inf = 1000000 }; |
| enum { horizontal = 0, |
| vertical = 1 }; |
| enum { left = 0x1, |
| right = 0x2, |
| top = 0x4, |
| bottom = 0x8 }; |
| |
| |
| bool getOrientation() const { return m_orientation; } |
| QRectF getGeometry() const { return m_rect; } |
| QSizeF getSize() const { return QSizeF(m_rect.width(), m_rect.height()); } |
| Region *getParent() const { return m_parent; } |
| DockWidget *getItem() const { return m_item; } |
| |
| const std::deque<Region *> &getChildList() const { return m_childList; } |
| Region *childRegion(int i) const { return m_childList[i]; } |
| |
| const std::deque<DockSeparator *> &separators() const { return m_separators; } |
| DockSeparator *separator(int i) const { return m_separators[i]; } |
| |
| std::vector<DockPlaceholder *> &placeholders() { return m_placeholders; } |
| DockPlaceholder *placeholder(int i) const { return m_placeholders[i]; } |
| |
| unsigned int find(const Region *subRegion) const; |
| |
| private: |
| |
| void setOrientation(bool orientation) { m_orientation = orientation; } |
| void setGeometry(const QRectF &rect) { m_rect = rect; } |
| void setSize(const QSizeF &size) { m_rect.setSize(size); } |
| void setParent(Region *parent) { m_parent = parent; } |
| void setItem(DockWidget *item) { m_item = item; } |
| |
| |
| void insertSubRegion(Region *subregion, int idx); |
| Region *insertItem(DockWidget *item, int idx); |
| void removeItem(DockWidget *item); |
| void insertSeparator(DockSeparator *sep); |
| void removeSeparator(); |
| |
| |
| |
| inline int getMaximumSize(bool direction) const |
| { |
| return m_maximumSize[direction]; |
| } |
| |
| inline int getMinimumSize(bool direction) const |
| { |
| return m_minimumSize[direction]; |
| } |
| |
| bool addItemSize(DockWidget *item); |
| bool subItemSize(DockWidget *item); |
| void calculateExtremalSizes(); |
| int calculateMinimumSize(bool direction, bool recalcChildren); |
| int calculateMaximumSize(bool direction, bool recalcChildren); |
| |
| |
| |
| |
| |
| void redistribute(); |
| void restoreGeometry(); |
| |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| class DockDecoAllocator |
| { |
| friend class DockLayout; |
| |
| public: |
| DockDecoAllocator() {} |
| virtual ~DockDecoAllocator() {} |
| |
| |
| virtual DockSeparator *newSeparator(DockLayout *owner, bool orientation, Region *parentRegion); |
| virtual DockPlaceholder *newPlaceholder(DockWidget *owner, Region *r, int idx, int attributes); |
| |
| private: |
| DockPlaceholder *newPlaceBuilt(DockWidget *owner, Region *r, int idx, int attributes); |
| }; |
| |
| #endif |
| |