Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tdockwindows.h"
Toshihiro Shimizu 890ddd
#include <qboxlayout></qboxlayout>
Toshihiro Shimizu 890ddd
#include <qvboxlayout></qvboxlayout>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qregion></qregion>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
#include <qstyleoption></qstyleoption>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qmouseevent></qmouseevent>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------
Toshihiro Shimizu 890ddd
//    Decorations
Toshihiro Shimizu 890ddd
//-------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TDockDecoAllocator final : public DockDecoAllocator {
Shinya Kitaoka 120a6e
  DockSeparator *newSeparator(DockLayout *owner, bool orientation,
Shinya Kitaoka 473e70
                              Region *parentRegion) override;
Shinya Kitaoka 120a6e
  DockPlaceholder *newPlaceholder(DockWidget *owner, Region *r, int idx,
Shinya Kitaoka 473e70
                                  int attributes) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------
Toshihiro Shimizu 890ddd
//    TMainWindow
Toshihiro Shimizu 890ddd
//-----------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TMainWindow::TMainWindow(QWidget *parent, Qt::WindowFlags flags)
Shinya Kitaoka 120a6e
    : QWidget(parent, flags) {
Shinya Kitaoka 120a6e
  // Delete on close
Shinya Kitaoka 120a6e
  setAttribute(Qt::WidgetAttribute(Qt::WA_DeleteOnClose));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Set a vertical layout to include menu bars
Shinya Kitaoka 120a6e
  QVBoxLayout *vlayout = new QVBoxLayout;
Shinya Kitaoka 120a6e
  vlayout->setMargin(0);
Shinya Kitaoka 120a6e
  vlayout->setSpacing(4);
Shinya Kitaoka 120a6e
  setLayout(vlayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Allocate the dock layout
Shinya Kitaoka 120a6e
  m_layout = new DockLayout;
Shinya Kitaoka 120a6e
  m_layout->setContentsMargins(0, 0, 0, 0);
Jeremy Bullock d9eff0
  m_layout->setSpacing(4);
Shinya Kitaoka 120a6e
  m_layout->setDecoAllocator(new TDockDecoAllocator);
Shinya Kitaoka 120a6e
  vlayout->addLayout(m_layout);
Shinya Kitaoka 120a6e
  vlayout->setAlignment(m_layout, Qt::AlignTop);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  show();  // NOTA: E' NECESSARIO MOSTRARE LA FINESTRA, prima di dockare
Shinya Kitaoka 120a6e
           // qualcosa (altrimenti non viene fatto
Shinya Kitaoka 120a6e
  // l'update della geometria della main window, e il contentsRect del layout
Shinya Kitaoka 120a6e
  // viene sballato!!).
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TMainWindow::~TMainWindow() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Adds input \b item to this TMainWindow. If item was already
Shinya Kitaoka 120a6e
//! assigned to \b this TMainWindow, nothing happens.
Shinya Kitaoka 120a6e
void TMainWindow::addDockWidget(TDockWidget *item) {
Shinya Kitaoka 120a6e
  if (!m_layout->find(item)) m_layout->addWidget(item);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMainWindow::removeDockWidget(TDockWidget *item) {
Shinya Kitaoka 120a6e
  m_layout->removeWidget(item);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// NOTE: Unlike QMainWindow::addToolBar, we only allow one
Shinya Kitaoka 120a6e
// fixed-size undockable menu bar at top of the dock layout.
Shinya Kitaoka 120a6e
void TMainWindow::setMenuWidget(QWidget *menubar) {
Shinya Kitaoka 120a6e
  if (menubar) {
Shinya Kitaoka 120a6e
    QVBoxLayout *vlayout = static_cast<qvboxlayout *="">(layout());</qvboxlayout>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    // If necessary, remove current menu bar
Shinya Kitaoka 120a6e
    if (m_menu && m_menu != menubar) vlayout->removeWidget(m_menu);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    vlayout->insertWidget(0, menubar);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMainWindow::setDecoAllocator(DockDecoAllocator *allocator) {
Shinya Kitaoka 120a6e
  m_layout->setDecoAllocator(allocator);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Sets global thickness of separators between dock widget.
Shinya Kitaoka 120a6e
void TMainWindow::setSeparatorsThickness(int thick) {
Shinya Kitaoka 120a6e
  if (thick > 0) {
Shinya Kitaoka 120a6e
    m_layout->setSpacing(thick);
Shinya Kitaoka 120a6e
    m_layout->redistribute();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TMainWindow::resizeEvent(QResizeEvent *event) { m_layout->redistribute(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------
Toshihiro Shimizu 890ddd
//    TDockWidget
Toshihiro Shimizu 890ddd
//-------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Constructs a TDockWidget with given parent and window flags. If parent is
Shinya Kitaoka 120a6e
//! a TMainWindow, then the constructed dock widget is assigned to it
Shinya Kitaoka 120a6e
//! (addDockWidget'd).
Shinya Kitaoka 120a6e
//! TDockWidgets are always floating at construction.
Toshihiro Shimizu 890ddd
TDockWidget::TDockWidget(QWidget *parent, Qt::WindowFlags flags)
Shinya Kitaoka 120a6e
    : DockWidget(parent, flags), m_widget(0), m_titlebar(0), m_margin(5) {
Shinya Kitaoka 120a6e
  setAutoFillBackground(false);
Shinya Kitaoka 120a6e
  // setFrameStyle(QFrame::StyledPanel);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom);
Shinya Kitaoka 120a6e
  layout->setSpacing(0);
Shinya Kitaoka 120a6e
  setLayout(layout);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // Check if parent is a TMainWindow class
Shinya Kitaoka 120a6e
  TMainWindow *parentMain = qobject_cast<tmainwindow *="">(parent);</tmainwindow>
Shinya Kitaoka 120a6e
  if (parentMain) parentMain->addDockWidget(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setDecoAllocator(new TDockDecoAllocator);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDockWidget::TDockWidget(const QString &title, QWidget *parent,
Shinya Kitaoka 120a6e
                         Qt::WindowFlags flags)
Shinya Kitaoka 120a6e
    : DockWidget(parent, flags), m_widget(0), m_titlebar(0), m_margin(5) {
Shinya Kitaoka 120a6e
  setWindowTitle(title);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom);
Shinya Kitaoka 120a6e
  layout->setSpacing(0);
Shinya Kitaoka 120a6e
  setLayout(layout);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDockWidget::setTitleBarWidget(QWidget *titlebar) {
Shinya Kitaoka 120a6e
  if (titlebar) {
Shinya Kitaoka 120a6e
    QBoxLayout *boxLayout = static_cast<qboxlayout *="">(layout());</qboxlayout>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (m_titlebar && m_titlebar != titlebar)
Shinya Kitaoka 120a6e
      boxLayout->removeWidget(m_titlebar);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    boxLayout->insertWidget(0, titlebar);
Shinya Kitaoka 120a6e
    // Set top/left-aligned
Shinya Kitaoka 120a6e
    boxLayout->setAlignment(
Shinya Kitaoka 120a6e
        titlebar, getOrientation() == vertical ? Qt::AlignTop : Qt::AlignLeft);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_titlebar = titlebar;
Shinya Kitaoka 120a6e
    if (m_floating) setFloatingAppearance();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDockWidget::windowTitleEvent(QEvent *e) {
Shinya Kitaoka 120a6e
  if (m_titlebar) m_titlebar->update();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDockWidget::setWidget(QWidget *widget) {
Shinya Kitaoka 120a6e
  if (widget) {
Shinya Kitaoka 120a6e
    QBoxLayout *boxLayout = static_cast<qboxlayout *="">(layout());</qboxlayout>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    if (m_widget && m_widget != widget) boxLayout->removeWidget(m_widget);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    boxLayout->insertWidget(1, widget);
Shinya Kitaoka 120a6e
    widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_widget = widget;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDockWidget::setFloatingAppearance() {
Shinya Kitaoka 120a6e
  if (m_titlebar) {
Shinya Kitaoka 120a6e
    // If has a custom title bar, impose a margin to the layout
Shinya Kitaoka 120a6e
    // to provide a frame.
Shinya Kitaoka 120a6e
    layout()->setMargin(m_margin);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (!m_floating)  // was docked
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      // Adding margin to extremal sizes
Shinya Kitaoka 120a6e
      int addition = 2 * m_margin;
Shinya Kitaoka 120a6e
      setMinimumSize(
Shinya Kitaoka 120a6e
          QSize(minimumWidth() + addition, minimumHeight() + addition));
Shinya Kitaoka 120a6e
      setMaximumSize(
Shinya Kitaoka 120a6e
          QSize(maximumWidth() + addition, maximumHeight() + addition));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // else
Shinya Kitaoka 120a6e
  //  setWindowFlags(Qt::Tool);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDockWidget::setDockedAppearance() {
Shinya Kitaoka 120a6e
  // No layout margin is visible when docked
Shinya Kitaoka 120a6e
  layout()->setMargin(0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_floating)  // was floating
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    // Removing margin from extremal sizes
Shinya Kitaoka 120a6e
    int addition = 2 * m_margin;
Shinya Kitaoka 120a6e
    setMinimumSize(
Shinya Kitaoka 120a6e
        QSize(minimumWidth() - addition, minimumHeight() - addition));
Shinya Kitaoka 120a6e
    setMaximumSize(
Shinya Kitaoka 120a6e
        QSize(maximumWidth() - addition, maximumHeight() - addition));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TDockWidget::isDragGrip(QPoint p) {
Shinya Kitaoka 120a6e
  if (!m_titlebar) return DockWidget::isDragGrip(p);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return m_titlebar->geometry().contains(p);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TDockWidget::isResizeGrip(QPoint p) {
Shinya Kitaoka 120a6e
  if (m_dragging || (!m_titlebar && m_floating)) return 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int marginType = 0;
Shinya Kitaoka 120a6e
  QRect geom(QPoint(0, 0), QPoint(width(), height()));
Shinya Kitaoka 120a6e
  int margin = layout()->margin();
Shinya Kitaoka 120a6e
  QRect contGeom(geom.adjusted(margin, margin, -margin, -margin));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (geom.contains(p) && !contGeom.contains(p)) {
Shinya Kitaoka 120a6e
    if (p.x() < 15) marginType |= leftMargin;
Shinya Kitaoka 120a6e
    if (p.y() < 15) marginType |= topMargin;
Shinya Kitaoka 120a6e
    if (p.x() > width() - 15) marginType |= rightMargin;
Shinya Kitaoka 120a6e
    if (p.y() > height() - 15) marginType |= bottomMargin;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return marginType;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Currently working only for \b status = true. If you need to
Shinya Kitaoka 120a6e
//! dock a TDockWidget, you \b must specify a dock location by either
Shinya Kitaoka 120a6e
//! choosing a placeholder or identifying the Region and insertion index,
Shinya Kitaoka 120a6e
//! and then running 'parentLayout()->dockItem(..)'.
Shinya Kitaoka 120a6e
void TDockWidget::setFloating(bool status) {
Shinya Kitaoka 120a6e
  if (status) {
Shinya Kitaoka 120a6e
    setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
Shinya Kitaoka 120a6e
    if (!m_floating) parentLayout()->undockItem(this);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Specifies the orientation of the dock widget. It can
Shinya Kitaoka 120a6e
//! be either \b vertical (default) or \b horizontal, meaning that
Shinya Kitaoka 120a6e
//! the titlebar is laid respectively at the top or left side of
Shinya Kitaoka 120a6e
//! content widget. Directly speaking, it is equivalent to setting the
Shinya Kitaoka 120a6e
//! Qt's QDockWidget::DockWidgetVerticalTitleBar feature.
Shinya Kitaoka 120a6e
void TDockWidget::setOrientation(bool direction) {
Shinya Kitaoka 120a6e
  QBoxLayout *boxLayout = static_cast<qboxlayout *="">(layout());</qboxlayout>
Shinya Kitaoka 120a6e
  QBoxLayout::Direction boxDirection;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (direction == vertical) {
Shinya Kitaoka 120a6e
    boxLayout->setAlignment(m_titlebar, Qt::AlignTop);
Shinya Kitaoka 120a6e
    boxDirection = QBoxLayout::TopToBottom;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    boxLayout->setAlignment(m_titlebar, Qt::AlignLeft);
Shinya Kitaoka 120a6e
    boxDirection = QBoxLayout::LeftToRight;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  boxLayout->setDirection(boxDirection);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TDockWidget::getOrientation() const {
Shinya Kitaoka 120a6e
  QBoxLayout *boxLayout = static_cast<qboxlayout *="">(layout());</qboxlayout>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return (boxLayout->direction() == QBoxLayout::TopToBottom) ? vertical
Shinya Kitaoka 120a6e
                                                             : horizontal;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
//! Maximizes \b this TDockWidget, if docked.
Shinya Kitaoka 120a6e
void TDockWidget::setMaximized(bool status) {
Shinya Kitaoka 120a6e
  parentLayout()->setMaximized(this, status);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QSize TDockWidget::getDockedMinimumSize() {
Shinya Kitaoka 120a6e
  int addedSize = 2 * m_margin;
Shinya Kitaoka 120a6e
  return m_floating ? minimumSize() -= QSize(addedSize, addedSize)
Shinya Kitaoka 120a6e
                    : minimumSize();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QSize TDockWidget::getDockedMaximumSize() {
Shinya Kitaoka 120a6e
  int addedSize = 2 * m_margin;
Shinya Kitaoka 120a6e
  return m_floating ? maximumSize() -= QSize(addedSize, addedSize)
Shinya Kitaoka 120a6e
                    : maximumSize();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------
Toshihiro Shimizu 890ddd
//    Custom Decorations
Toshihiro Shimizu 890ddd
//--------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TDockSeparator final : public DockSeparator {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TDockSeparator(DockLayout *owner, bool orientation, Region *parentRegion)
Shinya Kitaoka 120a6e
      : DockSeparator(owner, orientation, parentRegion) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void paintEvent(QPaintEvent *pe) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class TDockPlaceholder final : public DockPlaceholder {
Shinya Kitaoka 120a6e
  QWidget *m_associated[3];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TDockPlaceholder(DockWidget *owner, Region *r, int idx, int attributes);
Shinya Kitaoka 120a6e
  ~TDockPlaceholder();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void buildGeometry() override;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void showEvent(QShowEvent *se) override;
Shinya Kitaoka 473e70
  void hideEvent(QHideEvent *he) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDockPlaceholder::TDockPlaceholder(DockWidget *owner, Region *r, int idx,
Shinya Kitaoka 120a6e
                                   int attributes)
Shinya Kitaoka 120a6e
    : DockPlaceholder(owner, r, idx, attributes) {
Shinya Kitaoka 120a6e
  setAutoFillBackground(true);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setObjectName("TDockPlaceholder");
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  setWindowOpacity(0.8);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TDockPlaceholder::~TDockPlaceholder() {
Shinya Kitaoka 120a6e
  if (isRoot()) {
Shinya Kitaoka 120a6e
    delete m_associated[0];
Shinya Kitaoka 120a6e
    delete m_associated[1];
Shinya Kitaoka 120a6e
    delete m_associated[2];
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
inline void TDockPlaceholder::buildGeometry() {
Shinya Kitaoka 120a6e
  DockPlaceholder::buildGeometry();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (isRoot()) {
Shinya Kitaoka 120a6e
    // Solution 2: Set associated widgets
Shinya Kitaoka 120a6e
    QRect geom(geometry());
Shinya Kitaoka 120a6e
    QSize horSize(geom.width(), 6);
Shinya Kitaoka 120a6e
    QSize vertSize(6, geom.height() + 12);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    setGeometry(QRect(geom.topLeft() - QPoint(6, 6), vertSize));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_associated[0] = new TDockPlaceholder(0, 0, 0, 0);
Shinya Kitaoka 120a6e
    m_associated[0]->setGeometry(QRect(geom.topLeft() - QPoint(0, 6), horSize));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_associated[1] = new TDockPlaceholder(0, 0, 0, 0);
Shinya Kitaoka 120a6e
    m_associated[1]->setGeometry(
Shinya Kitaoka 120a6e
        QRect(geom.topRight() + QPoint(1, -6), vertSize));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_associated[2] = new TDockPlaceholder(0, 0, 0, 0);
Shinya Kitaoka 120a6e
    m_associated[2]->setGeometry(
Shinya Kitaoka 120a6e
        QRect(geom.bottomLeft() + QPoint(0, 1), horSize));
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDockPlaceholder::showEvent(QShowEvent *se) {
Shinya Kitaoka 120a6e
  if (isRoot()) {
Shinya Kitaoka 120a6e
    // Show associated widgets
Shinya Kitaoka 120a6e
    m_associated[0]->show();
Shinya Kitaoka 120a6e
    m_associated[1]->show();
Shinya Kitaoka 120a6e
    m_associated[2]->show();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDockPlaceholder::hideEvent(QHideEvent *he) {
Shinya Kitaoka 120a6e
  if (isRoot()) {
Shinya Kitaoka 120a6e
    // Show associated widgets
Shinya Kitaoka 120a6e
    m_associated[0]->hide();
Shinya Kitaoka 120a6e
    m_associated[1]->hide();
Shinya Kitaoka 120a6e
    m_associated[2]->hide();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDockSeparator::paintEvent(QPaintEvent *pe) {
Shinya Kitaoka 120a6e
  QPainter p(this);
Shinya Kitaoka 120a6e
  QStyleOption opt(0);
Shinya Kitaoka 120a6e
  opt.state = (getOrientation() == Region::horizontal)
Shinya Kitaoka 120a6e
                  ? QStyle::State_None
Shinya Kitaoka 120a6e
                  : QStyle::State_Horizontal;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  /*if (w->isEnabled())
Shinya Kitaoka 120a6e
opt.state |= QStyle::State_Enabled;
Shinya Kitaoka 120a6e
if (o != Qt::Horizontal)
Shinya Kitaoka 120a6e
opt.state |= QStyle::State_Horizontal;
Shinya Kitaoka 120a6e
if (mouse_over)
Shinya Kitaoka 120a6e
opt.state |= QStyle::State_MouseOver;*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  opt.rect    = QRect(QPoint(0, 0), QSize(geometry().size()));
Shinya Kitaoka 120a6e
  opt.palette = palette();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  style()->drawPrimitive(QStyle::PE_IndicatorDockWidgetResizeHandle, &opt, &p,
Shinya Kitaoka 120a6e
                         this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  p.end();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DockSeparator *TDockDecoAllocator::newSeparator(DockLayout *owner,
Shinya Kitaoka 120a6e
                                                bool orientation,
Shinya Kitaoka 120a6e
                                                Region *parentRegion) {
Shinya Kitaoka 120a6e
  return new TDockSeparator(owner, orientation, parentRegion);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
DockPlaceholder *TDockDecoAllocator::newPlaceholder(DockWidget *owner,
Shinya Kitaoka 120a6e
                                                    Region *r, int idx,
Shinya Kitaoka 120a6e
                                                    int attributes) {
Shinya Kitaoka 120a6e
  return new TDockPlaceholder(owner, r, idx, attributes);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TDockWidget::selectDockPlaceholder(QMouseEvent *me) {
Shinya Kitaoka 120a6e
  if (m_placeholders.size() && m_placeholders[0]->isRoot()) {
Shinya Kitaoka 120a6e
    DockPlaceholder *selected = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QPoint pos = parentWidget()->mapFromGlobal(me->globalPos());
Shinya Kitaoka 120a6e
    if (parentLayout()->contentsRect().contains(pos))
Shinya Kitaoka 120a6e
      selected = m_placeholders[0];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (m_selectedPlace != selected) {
Shinya Kitaoka 120a6e
      if (m_selectedPlace) m_selectedPlace->hide();
Shinya Kitaoka 120a6e
      if (selected) selected->show();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    m_selectedPlace = selected;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    DockWidget::selectDockPlaceholder(me);
Toshihiro Shimizu 890ddd
}