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