Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef DOCKLAYOUT_H
Toshihiro Shimizu 890ddd
#define DOCKLAYOUT_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qwidget></qwidget>
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <deque></deque>
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
#include <qlayout></qlayout>
Toshihiro Shimizu 890ddd
#include <qframe></qframe>
Toshihiro Shimizu 890ddd
#include "docklayout.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TOONZQT_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// Forward Declarations
Toshihiro Shimizu 890ddd
class DockLayout;
Toshihiro Shimizu 890ddd
class DockWidget;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DockPlaceholder;
Toshihiro Shimizu 890ddd
class DockSeparator;
Toshihiro Shimizu 890ddd
class DockDecoAllocator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Region;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------
Toshihiro Shimizu 890ddd
//    Docking Lock Check
Toshihiro Shimizu 890ddd
//--------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Singleton for docking system lock.
Shinya Kitaoka 120a6e
class DVAPI DockingCheck {
Shinya Kitaoka 120a6e
  bool m_enabled;
Shinya Kitaoka 120a6e
  QAction *m_toggle;
Shinya Kitaoka 120a6e
  DockingCheck() : m_enabled(false), m_toggle(0) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  static DockingCheck *instance();
Shinya Kitaoka 120a6e
  void setToggle(QAction *toggle);
Shinya Kitaoka 120a6e
  bool isEnabled() const { return m_enabled; }
Shinya Kitaoka 120a6e
  void setIsEnabled(bool on);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------
Toshihiro Shimizu 890ddd
//    Dock Layout
Toshihiro Shimizu 890ddd
//-------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! DockLayout inherits the abstract QLayout to provide a docking system for
Shinya Kitaoka 120a6e
//! widgets.
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
  \b IMPORTANT NOTE: Observe that the addWidget() method expects only widgets of
Shinya Kitaoka 120a6e
  type DockWidget, so any other
Toshihiro Shimizu 890ddd
  widget type added to this kind of Layout will cause a run-time error.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \sa DockWidget and DockSeparator classes.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka d1f6c4
class DVAPI DockLayout final : public QLayout {
Shinya Kitaoka 120a6e
  std::vector<qlayoutitem *=""> m_items;</qlayoutitem>
Shinya Kitaoka 120a6e
  std::deque<region *=""> m_regions;</region>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DockWidget
Shinya Kitaoka 120a6e
      *m_maximizedDock;  // Let the layout know if there is a maximized widget
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Decoration-related allocator (separators)
Shinya Kitaoka 120a6e
  DockDecoAllocator *m_decoAllocator;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DockLayout();
Shinya Kitaoka 120a6e
  virtual ~DockLayout();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // QLayout item handling (see Qt reference)
Shinya Kitaoka 473e70
  int count(void) const override;
Shinya Kitaoka 473e70
  void addItem(QLayoutItem *item) override;
Shinya Kitaoka 473e70
  QSize sizeHint() const override;
Shinya Kitaoka 473e70
  QSize minimumSize() const override;
Shinya Kitaoka 473e70
  QSize maximumSize() const override;
Shinya Kitaoka 473e70
  QLayoutItem *itemAt(int) const override;
Shinya Kitaoka 120a6e
  QWidget *widgetAt(int) const;
Shinya Kitaoka 473e70
  QLayoutItem *takeAt(int) override;
Shinya Kitaoka 473e70
  void setGeometry(const QRect &rect) override;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void update();        // Re-applies partition found
Shinya Kitaoka 120a6e
  void redistribute();  // Calculates partition
Shinya Kitaoka 120a6e
  void applyTransform(const QTransform &transform);  // Applies tranformation to
Shinya Kitaoka 120a6e
                                                     // known parition - Da
Shinya Kitaoka 120a6e
                                                     // rimuovere, non serve...
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  DockWidget *getMaximized() { return m_maximizedDock; }
Shinya Kitaoka 120a6e
  void setMaximized(
Shinya Kitaoka 120a6e
      DockWidget *item,
Shinya Kitaoka 120a6e
      bool state = true);  // Let DockLayout handle maximization requests
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Docking and undocking methods.
Shinya Kitaoka 120a6e
  Region *dockItem(DockWidget *item, Region *r = 0, int idx = 0);
Shinya Kitaoka 120a6e
  void dockItem(DockWidget *item, DockPlaceholder *place);
Shinya Kitaoka 120a6e
  void dockItem(DockWidget *item, DockWidget *target, int regionSide);
Shinya Kitaoka 120a6e
  bool undockItem(DockWidget *item);
Shinya Kitaoka 120a6e
  void calculateDockPlaceholders(DockWidget *item);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Query methods
Shinya Kitaoka 120a6e
  Region *rootRegion() const {
Shinya Kitaoka 120a6e
    return m_regions.size() ? m_regions.front() : 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  const std::deque<region *=""> ®ions() const { return m_regions; }</region>
Shinya Kitaoka 120a6e
  Region *region(int i) const { return m_regions[i]; }
Shinya Kitaoka 120a6e
  Region *find(DockWidget *item) const;
Shinya Kitaoka 120a6e
  QWidget *containerOf(QPoint point) const;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Save and load DockLayout states
Shinya Kitaoka 120a6e
  typedef std::pair<std::vector<qrect>, QString> State;</std::vector<qrect>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  State saveState();
Shinya Kitaoka 120a6e
  bool restoreState(const State &state);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Decorations allocator
Shinya Kitaoka 120a6e
  void setDecoAllocator(DockDecoAllocator *decoAllocator);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  void applyGeometry();
Shinya Kitaoka 120a6e
  inline void updateSeparatorCursors();
Shinya Kitaoka 120a6e
  Region *dockItemPrivate(DockWidget *item, Region *r, int idx);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Insertion and removal check - called internally by dock/undockItem
Shinya Kitaoka 120a6e
  bool isPossibleInsertion(DockWidget *item, Region *parentRegion,
Shinya Kitaoka 120a6e
                           int insertionIdx);
Shinya Kitaoka 120a6e
  bool isPossibleRemoval(DockWidget *item, Region *parentRegion,
Shinya Kitaoka 120a6e
                         int removalIdx);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Internal save function
Shinya Kitaoka 120a6e
  void writeRegion(Region *r, QString &hierarchy);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------
Toshihiro Shimizu 890ddd
//    Dock Widget
Toshihiro Shimizu 890ddd
//-----------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Dockable widgets are widget containers handled by DockLayout class.
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  DockLayouts accept only dock widgets of this class; so if you want to
Toshihiro Shimizu 890ddd
  place a given widget under this kind of layout, a DockWidget shell for
Toshihiro Shimizu 890ddd
  it must be allocated first. The following class implements base dock
Toshihiro Shimizu 890ddd
  widgets, with native floating decorations and no docked title bar.
Toshihiro Shimizu 890ddd
  It is encouraged to reimplement all the essential functions for custom aspect
Toshihiro Shimizu 890ddd
  and behaviour.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \sa DockLayout and DockPlaceholder classes.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
class DVAPI DockWidget : public QWidget {
Shinya Kitaoka 120a6e
  friend class DockLayout;  // DockLayout is granted access to placeholders'
Shinya Kitaoka 120a6e
                            // privates
Shinya Kitaoka 120a6e
  friend class DockPlaceholder;  // As above.
Shinya Kitaoka 120a6e
  // friend Region;          //Regions need access to m_saveIndex field.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  // Private attributes for dragging purposes
Shinya Kitaoka 120a6e
  bool m_floating;   // Whether this window is floating or docked
Shinya Kitaoka 120a6e
  bool m_dragging;   // Whether this window is being dragged
Shinya Kitaoka 120a6e
  bool m_undocking;  // Still docked, but after a mouse button press on a title
Shinya Kitaoka 120a6e
                     // bar.
Shinya Kitaoka 120a6e
  // NOTE: m_dragging ==> !m_undocking; m_dragging=>m_floating.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Private infos for resizing purposes
Shinya Kitaoka 120a6e
  bool m_resizing;   // Whether this window is being resized
Shinya Kitaoka 120a6e
  int m_marginType;  // Type of resize to consider
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Maximization
Shinya Kitaoka 120a6e
  bool m_maximized;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  QPoint m_dragInitialPos;
Shinya Kitaoka 120a6e
  QPoint m_dragMouseInitialPos;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Widget and Layout links
Shinya Kitaoka 120a6e
  DockLayout *m_parentLayout;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Decoration-related allocator (placeholders)
Shinya Kitaoka 120a6e
  DockDecoAllocator *m_decoAllocator;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_saveIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  // Protected infos for docking purposes
Shinya Kitaoka 120a6e
  std::vector<dockplaceholder *=""> m_placeholders;</dockplaceholder>
Shinya Kitaoka 120a6e
  DockPlaceholder *m_selectedPlace;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DockWidget(QWidget *parent = 0, Qt::WindowFlags flags = Qt::Tool);
Shinya Kitaoka 120a6e
  virtual ~DockWidget();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Returns the DockLayout owning \b this dock widget
Shinya Kitaoka 120a6e
  DockLayout *parentLayout() const { return m_parentLayout; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool isFloating() const { return m_floating; }
Shinya Kitaoka 120a6e
  bool isMaximized() const { return m_maximized; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Query functions
Shinya Kitaoka 120a6e
  QWidget *hoveredWidget(QMouseEvent *me);
Shinya Kitaoka 120a6e
  DockPlaceholder *placeAdjacentTo(DockWidget *dockWidget, int boundary);
Shinya Kitaoka 120a6e
  DockPlaceholder *placeOfSeparator(DockSeparator *);
Shinya Kitaoka 120a6e
  const std::vector<dockplaceholder *=""> &placeholders() const {</dockplaceholder>
Shinya Kitaoka 120a6e
    return m_placeholders;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Re-implementable functions for custom dock widgets.
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Returns the minimum size of the dock widget when docked. This function
Shinya Kitaoka 120a6e
  //! should be
Shinya Kitaoka 120a6e
  //! reimlemented whenever minimum size changes between floating and docked
Shinya Kitaoka 120a6e
  //! appearance.
Shinya Kitaoka 120a6e
  virtual QSize getDockedMinimumSize() { return minimumSize(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Returns the maximum size of the dock widget when docked. This function
Shinya Kitaoka 120a6e
  //! should be
Shinya Kitaoka 120a6e
  //! reimlemented whenever minimum size changes between floating and docked
Shinya Kitaoka 120a6e
  //! appearance.
Shinya Kitaoka 120a6e
  virtual QSize getDockedMaximumSize() { return maximumSize(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! This function is called in order to show the dock widget in its floating
Shinya Kitaoka 120a6e
  //! status. No show() or update()
Shinya Kitaoka 120a6e
  //! is needed in its body.
Shinya Kitaoka 120a6e
  //! It can be reimplemented to build custom-styled dock widgets.
Shinya Kitaoka 120a6e
  virtual void setFloatingAppearance() { setWindowFlags(Qt::Tool); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! This function is called in order to show the dock widget in its docked
Shinya Kitaoka 120a6e
  //! status. No show() or update()
Shinya Kitaoka 120a6e
  //! is needed in its body.
Shinya Kitaoka 120a6e
  //! It can be reimplemented to build custom-styled dock widgets.
Shinya Kitaoka 120a6e
  virtual void setDockedAppearance() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual bool isDragGrip(QPoint p);
Shinya Kitaoka 120a6e
  virtual int isResizeGrip(QPoint) {
Shinya Kitaoka 120a6e
    return 0;  // Native deco widgets handle margins and resizes on their own
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enum {
Shinya Kitaoka 120a6e
    leftMargin   = 0x1,
Shinya Kitaoka 120a6e
    rightMargin  = 0x2,
Shinya Kitaoka 120a6e
    topMargin    = 0x4,
Shinya Kitaoka 120a6e
    bottomMargin = 0x8
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Placeholders-related methods
Shinya Kitaoka 120a6e
  virtual void selectDockPlaceholder(QMouseEvent *me);
Shinya Kitaoka 120a6e
  void clearDockPlaceholders();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Decorations allocator
Shinya Kitaoka 120a6e
  void setDecoAllocator(DockDecoAllocator *decoAllocator);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // reimpremented in FlipbookPanel
Shinya Kitaoka 120a6e
  virtual void onDock(bool docked) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // Event handling
Shinya Kitaoka 120a6e
  // Basic events
Shinya Kitaoka 473e70
  bool event(QEvent *e) override;
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *me) override;
Shinya Kitaoka 473e70
  void mouseReleaseEvent(QMouseEvent *me) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *me) override;
Shinya Kitaoka 120a6e
  void hoverMoveEvent(QHoverEvent *he);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 120a6e
  // Customizable events
Shinya Kitaoka 473e70
  void wheelEvent(QWheelEvent *we) override;
Shinya Kitaoka 473e70
  void mouseDoubleClickEvent(QMouseEvent *me) override;
Shinya Kitaoka 120a6e
  virtual void windowTitleEvent(QEvent *) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------
Toshihiro Shimizu 890ddd
//    DockSeparator
Toshihiro Shimizu 890ddd
//---------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Separators are interposition widgets among docked DockWidgets of a
Shinya Kitaoka 120a6e
//! DockLayout.
Toshihiro Shimizu 890ddd
/*!
Shinya Kitaoka 120a6e
  A DockSeparator has the role of separating sister Regions; it is always owned
Shinya Kitaoka 120a6e
  by a parent
Shinya Kitaoka 120a6e
  Region and inherits its subdivision (here separation) direction. It also
Shinya Kitaoka 120a6e
  provides basical
Shinya Kitaoka 120a6e
  interaction with the user, allowing itself to be shifted along separation
Shinya Kitaoka 120a6e
  direction until
Toshihiro Shimizu 890ddd
  geometric constraints are met.
Shinya Kitaoka 120a6e
  DockSeparator class can be inherited to build custom separators - in that
Shinya Kitaoka 120a6e
  case, a
Shinya Kitaoka 120a6e
  heir of DockDecoAllocator class allocating the new separator class must be
Shinya Kitaoka 120a6e
  assigned to
Toshihiro Shimizu 890ddd
  the DockLayout.
Shinya Kitaoka 120a6e
  It is also possible to specify the Separators' thickness used in a DockLayout
Shinya Kitaoka 120a6e
  through the
Toshihiro Shimizu 890ddd
  QLayout::setSpacing(int) method.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  \b NOTE: Observe that Separators' geometry is owned by the DockLayout to which
Shinya Kitaoka 120a6e
  it belongs; it
Shinya Kitaoka 120a6e
  is discouraged (but not forbidden) to manually modify it. You may, for
Shinya Kitaoka 120a6e
  example, modify the
Toshihiro Shimizu 890ddd
  geometry of a DockSeparator when dragging a dock widget over it.
Shinya Kitaoka 120a6e
  In any case, the layout will automatically regenerate Separators' geometry at
Shinya Kitaoka 120a6e
  each update of
Toshihiro Shimizu 890ddd
  the layout.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \sa DockLayout and DockWidget classes.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DockSeparator : public QWidget {
Shinya Kitaoka 120a6e
  friend class DockLayout;  // Layout updates each DockSeparator during
Shinya Kitaoka 120a6e
                            // DockLayout::applyGeometry()
Shinya Kitaoka 38fd86
  friend class Region;      // Region may update a DockSeparator's parent during
Shinya Kitaoka 38fd86
                            // removeItem()
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DockLayout *m_owner;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Event-related infos
Shinya Kitaoka 120a6e
  bool m_pressed;
Shinya Kitaoka 120a6e
  QPoint m_oldOrigin;
Shinya Kitaoka 120a6e
  QPoint m_oldPos;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Structural infos
Shinya Kitaoka 120a6e
  Region *m_parentRegion;
Shinya Kitaoka 120a6e
  int m_index;
Shinya Kitaoka 120a6e
  bool m_orientation;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Constraint infos
Shinya Kitaoka 120a6e
  double m_leftBound;
Shinya Kitaoka 120a6e
  double m_rightBound;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DockSeparator(DockLayout *owner, bool orientation, Region *parentRegion);
Shinya Kitaoka 120a6e
  virtual ~DockSeparator() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Structural getters
Shinya Kitaoka 120a6e
  bool getOrientation() const { return m_orientation; }
Shinya Kitaoka 120a6e
  Region *getParentRegion() const { return m_parentRegion; }
Shinya Kitaoka 120a6e
  int getIndex() const { return m_index; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Public setters
Shinya Kitaoka 120a6e
  void shift(int dx);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  void calculateBounds();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void mousePressEvent(QMouseEvent *me) override;
Shinya Kitaoka 473e70
  void mouseReleaseEvent(QMouseEvent *me) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QMouseEvent *me) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------
Toshihiro Shimizu 890ddd
//    Dock Placeholder
Toshihiro Shimizu 890ddd
//---------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! A dock placeholder contains the necessary informations about a possible
Shinya Kitaoka 120a6e
//! docking solution.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  Dock placeholders are top-level widgets used by a DockLayout to draw docking
Toshihiro Shimizu 890ddd
  solutions for a dragged DockWidget. They are actually generated when
Toshihiro Shimizu 890ddd
  dragging of a DockWidget begins: if it belongs to a parent DockLayout, docking
Toshihiro Shimizu 890ddd
  possibilities are calculated and stored into the layout.
Shinya Kitaoka 120a6e
  Placeholders selection and activation depend on the dragged dock window and
Shinya Kitaoka 120a6e
  therefore
Toshihiro Shimizu 890ddd
  are of its own responsibility.
Shinya Kitaoka 120a6e
  You may, however, inherit this class to provide custom placeholders; in this
Shinya Kitaoka 120a6e
  case,
Shinya Kitaoka 120a6e
  a DockDecoAllocator class reimplementing allocation of placeholders must be
Shinya Kitaoka 120a6e
  assigned to
Toshihiro Shimizu 890ddd
  the owner dock widget.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \sa DockLayout and DockWidget classes
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
class DockPlaceholder : public QWidget {
Shinya Kitaoka 120a6e
  friend class DockLayout;  // DockLayout is granted access to placeholders'
Shinya Kitaoka 120a6e
                            // privates
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Docking informations - private
Shinya Kitaoka 120a6e
  Region *m_region;
Shinya Kitaoka 120a6e
  int m_idx;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Docking informations - public
Shinya Kitaoka 120a6e
  int m_attributes;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Owner
Shinya Kitaoka 120a6e
  DockSeparator *m_separator;
Shinya Kitaoka 120a6e
  DockWidget *m_owner;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DockPlaceholder(DockWidget *owner, Region *r, int idx, int attributes = 0);
Shinya Kitaoka 120a6e
  virtual ~DockPlaceholder() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Member access methods
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Returns DockSeparator on which docking takes place (if any)
Shinya Kitaoka 120a6e
  DockSeparator *getSeparator() const;
Shinya Kitaoka 120a6e
  //! Returns dockWidget owner
Shinya Kitaoka 120a6e
  DockWidget *getDockWidget() const { return m_owner; }
Shinya Kitaoka 120a6e
  //! Returns Region owner
Shinya Kitaoka 120a6e
  Region *getParentRegion() const { return m_region; }
Shinya Kitaoka 120a6e
  //! Returns insertion index into parent region
Shinya Kitaoka 120a6e
  int getInsertionIdx() const { return m_idx; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  enum {
Shinya Kitaoka 120a6e
    left    = 0,
Shinya Kitaoka 120a6e
    right   = 1,
Shinya Kitaoka 120a6e
    top     = 2,
Shinya Kitaoka 120a6e
    bottom  = 3,
Shinya Kitaoka 120a6e
    sepHor  = 4,
Shinya Kitaoka 120a6e
    sepVert = 5,
Shinya Kitaoka 120a6e
    root    = 6
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
  int getAttribute() const { return m_attributes; }
Shinya Kitaoka 120a6e
  void setAttribute(int attribute) { m_attributes = attribute; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Geometry functions
Shinya Kitaoka 120a6e
  QRect parentGeometry() const;
Shinya Kitaoka 120a6e
  virtual void buildGeometry();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Query functions
Shinya Kitaoka 120a6e
  //! A root placeholder is passed only if no item is currently docked (special
Shinya Kitaoka 120a6e
  //! case)
Shinya Kitaoka 120a6e
  bool isRoot() const { return m_attributes == root; }
Shinya Kitaoka 120a6e
  DockPlaceholder *parentPlaceholder();
Shinya Kitaoka 120a6e
  DockPlaceholder *greatestPlaceholder();
Shinya Kitaoka 120a6e
  DockPlaceholder *childPlaceholder(QPoint p);
Shinya Kitaoka 120a6e
  DockPlaceholder *smallestPlaceholder(QPoint p);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  //! Let wheel events also be propagated to owner dock widget
Shinya Kitaoka 473e70
  void wheelEvent(QWheelEvent *we) override { m_owner->wheelEvent(we); }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===========================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------
Toshihiro Shimizu 890ddd
//    Class Region
Toshihiro Shimizu 890ddd
//--------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Regions represent any rectangular space inside a DockLayout.
Shinya Kitaoka 120a6e
//! Normally there is no reason to deal with Regions, unless you want to
Shinya Kitaoka 120a6e
//! build complex docking systems or manually dock widgets into your code.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  Regions are rectangular areas of the DockLayout's contentsRect() which
Toshihiro Shimizu 890ddd
  can be either subdiveded into subRegions (all in a given \b subdivision
Toshihiro Shimizu 890ddd
  \b direction) or contain a DockWidget.
Toshihiro Shimizu 890ddd
  Every subRegion, if present, has opposite subdivision direction with
Toshihiro Shimizu 890ddd
  respect to parent one. In addition, regions possess lists of separators
Toshihiro Shimizu 890ddd
  and placeholders found along its subdivision direction.
Toshihiro Shimizu 890ddd
  Region informations are owned by the DockLayout who allocates it; however,
Toshihiro Shimizu 890ddd
  they are read-only accessible by the user.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \sa DockLayout, DockWidget, DockSeparator and DockPlaceholder classes.
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class Region {
Shinya Kitaoka 38fd86
  friend class DockLayout;     // Layout is the main operating class over
Shinya Kitaoka 38fd86
                               // rectangular regions - need full access
Shinya Kitaoka 120a6e
  friend class DockSeparator;  // Separators need access to extremal sizes
Shinya Kitaoka 120a6e
                               // methods when moving themselves
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  DockLayout *m_owner;
Shinya Kitaoka 120a6e
  DockWidget *m_item;
Shinya Kitaoka 120a6e
  Region *m_parent;
Shinya Kitaoka 120a6e
  std::deque<region *=""> m_childList;</region>
Shinya Kitaoka 120a6e
  std::deque<dockseparator *=""> m_separators;</dockseparator>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::vector<dockplaceholder *=""> m_placeholders;</dockplaceholder>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QRectF m_rect;
Shinya Kitaoka 120a6e
  bool m_orientation;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_minimumSize[2];
Shinya Kitaoka 120a6e
  int m_maximumSize[2];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int m_saveIndex;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  Region(DockLayout *owner, DockWidget *item = 0)
Shinya Kitaoka 120a6e
      : m_owner(owner), m_item(item), m_parent(0), m_orientation(0) {}
Shinya Kitaoka 120a6e
  ~Region();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  enum { inf = 1000000 };
Shinya Kitaoka 120a6e
  enum { horizontal = 0, vertical = 1 };
Shinya Kitaoka 120a6e
  enum { left = 0x1, right = 0x2, top = 0x4, bottom = 0x8 };
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Getters - public
Shinya Kitaoka 120a6e
  bool getOrientation() const { return m_orientation; }
Shinya Kitaoka 120a6e
  QRectF getGeometry() const { return m_rect; }
Shinya Kitaoka 120a6e
  QSizeF getSize() const { return QSizeF(m_rect.width(), m_rect.height()); }
Shinya Kitaoka 120a6e
  Region *getParent() const { return m_parent; }
Shinya Kitaoka 120a6e
  DockWidget *getItem() const { return m_item; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const std::deque<region *=""> &getChildList() const { return m_childList; }</region>
Shinya Kitaoka 120a6e
  Region *childRegion(int i) const { return m_childList[i]; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  const std::deque<dockseparator *=""> &separators() const { return m_separators; }</dockseparator>
Shinya Kitaoka 120a6e
  DockSeparator *separator(int i) const { return m_separators[i]; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::vector<dockplaceholder *=""> &placeholders() { return m_placeholders; }</dockplaceholder>
Shinya Kitaoka 120a6e
  DockPlaceholder *placeholder(int i) const { return m_placeholders[i]; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  unsigned int find(const Region *subRegion) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  // Setters - private
Shinya Kitaoka 120a6e
  void setOrientation(bool orientation) { m_orientation = orientation; }
Shinya Kitaoka 120a6e
  void setGeometry(const QRectF &rect) { m_rect = rect; }
Shinya Kitaoka 120a6e
  void setSize(const QSizeF &size) { m_rect.setSize(size); }
Shinya Kitaoka 120a6e
  void setParent(Region *parent) { m_parent = parent; }
Shinya Kitaoka 120a6e
  void setItem(DockWidget *item) { m_item = item; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Insertion and removal methods
Shinya Kitaoka 120a6e
  void insertSubRegion(Region *subregion, int idx);
Shinya Kitaoka 120a6e
  Region *insertItem(DockWidget *item, int idx);
Shinya Kitaoka 120a6e
  void removeItem(DockWidget *item);
Shinya Kitaoka 120a6e
  void insertSeparator(DockSeparator *sep);
Shinya Kitaoka 120a6e
  void removeSeparator();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Extremal region sizes
Shinya Kitaoka 120a6e
  //! Returns cached occupied space in \b this region along given \b direction.
Shinya Kitaoka 120a6e
  inline int getMaximumSize(bool direction) const {
Shinya Kitaoka 120a6e
    return m_maximumSize[direction];
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  //! Returns cached occupied space in \b this region along given \b direction.
Shinya Kitaoka 120a6e
  inline int getMinimumSize(bool direction) const {
Shinya Kitaoka 120a6e
    return m_minimumSize[direction];
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool addItemSize(DockWidget *item);
Shinya Kitaoka 120a6e
  bool subItemSize(DockWidget *item);
Shinya Kitaoka 120a6e
  void calculateExtremalSizes();
Shinya Kitaoka 120a6e
  int calculateMinimumSize(bool direction, bool recalcChildren);
Shinya Kitaoka 120a6e
  int calculateMaximumSize(bool direction, bool recalcChildren);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Redistribution function.
Shinya Kitaoka 120a6e
  // The main feature of a Region consists of the redistribute() method, which
Shinya Kitaoka 120a6e
  // extracts the optimal layout among the branching regions with \b this
Shinya Kitaoka 120a6e
  // root. However, only the full redistribute() method in DockLayout is made
Shinya Kitaoka 120a6e
  // public.
Shinya Kitaoka 120a6e
  void redistribute();
Shinya Kitaoka 120a6e
  void restoreGeometry();
Shinya Kitaoka 120a6e
  // void updateSeparators();
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------
Toshihiro Shimizu 890ddd
//    Dock Allocator
Toshihiro Shimizu 890ddd
//----------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! DockDecoAllocator class handles the allocation of decoration elements used
Shinya Kitaoka 120a6e
//! by our dock manager.
Toshihiro Shimizu 890ddd
/*!
Toshihiro Shimizu 890ddd
  In order to implement custom appearances for the docking system, it
Toshihiro Shimizu 890ddd
  is possible to customize both DockSeparator and DockPlaceholder classes. Since
Toshihiro Shimizu 890ddd
  allocation of such objects is handled internally by the docking system,
Toshihiro Shimizu 890ddd
  it is necessary to reimplement allocator functions whenever decoration
Toshihiro Shimizu 890ddd
  classes change.
Toshihiro Shimizu 890ddd
  In order to assign a DockDecoAllocator to a DockLayout or DockWidget, the
Toshihiro Shimizu 890ddd
  respective 'setDecoAllocator' methods are provided.
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
  \sa DockLayout, DockWidget, DockSeparator and DockPlaceholder classes.
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
class DockDecoAllocator {
Shinya Kitaoka 120a6e
  friend class DockLayout;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  DockDecoAllocator() {}
Shinya Kitaoka 120a6e
  virtual ~DockDecoAllocator() {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Customizabile allocators
Shinya Kitaoka 120a6e
  virtual DockSeparator *newSeparator(DockLayout *owner, bool orientation,
Shinya Kitaoka 120a6e
                                      Region *parentRegion);
Shinya Kitaoka 120a6e
  virtual DockPlaceholder *newPlaceholder(DockWidget *owner, Region *r, int idx,
Shinya Kitaoka 120a6e
                                          int attributes);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  DockPlaceholder *newPlaceBuilt(DockWidget *owner, Region *r, int idx,
Shinya Kitaoka 120a6e
                                 int attributes);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // SIMPLEQTTEST_H