mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 21:25:44 +08:00
Fixed display of drop overlay
This commit is contained in:
parent
1b1c636107
commit
c5ea5c80b1
@ -105,8 +105,8 @@ void MainWindow::createContent()
|
|||||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, DockWidget);
|
||||||
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
|
m_DockManager->addDockWidget(ads::LeftDockWidgetArea, createLongTextLabelDockWidget(ViewMenu));
|
||||||
/*m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
m_DockManager->addDockWidget(ads::BottomDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
||||||
auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
/*auto TopDockArea = m_DockManager->addDockWidget(ads::TopDockWidgetArea, createFileSystemTreeDockWidget(ViewMenu));
|
||||||
DockWidget = createCalendarDockWidget(ViewMenu);
|
DockWidget = createCalendarDockWidget(ViewMenu);
|
||||||
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
DockWidget->setFeatures(DockWidget->features().setFlag(ads::CDockWidget::DockWidgetClosable, false));
|
||||||
m_DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
|
m_DockManager->addDockWidget(ads::CenterDockWidgetArea, DockWidget, TopDockArea);
|
||||||
|
@ -124,7 +124,8 @@ struct DockContainerWidgetPrivate
|
|||||||
/**
|
/**
|
||||||
* Restore state of child nodes.
|
* Restore state of child nodes.
|
||||||
* \param[in] Stream The data stream that contains the serialized state
|
* \param[in] Stream The data stream that contains the serialized state
|
||||||
* \param[out] CreatedWidget The widget created from parsed data
|
* \param[out] CreatedWidget The widget created from parsed data or 0 if
|
||||||
|
* the parsed widget was an empty splitter
|
||||||
* \param[in] Testing If Testing is true, only the stream data is
|
* \param[in] Testing If Testing is true, only the stream data is
|
||||||
* parsed without modifiying anything.
|
* parsed without modifiying anything.
|
||||||
*/
|
*/
|
||||||
@ -828,10 +829,18 @@ bool CDockContainerWidget::restoreState(QDataStream& stream, bool Testing)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the root splitter is empty, rostoreChildNodes returns a 0 pointer
|
||||||
|
// and we need to create a new empty root splitter
|
||||||
|
if (!NewRootSplitter)
|
||||||
|
{
|
||||||
|
NewRootSplitter = internal::newSplitter(Qt::Horizontal);
|
||||||
|
}
|
||||||
|
|
||||||
d->Layout->replaceWidget(d->RootSplitter, NewRootSplitter);
|
d->Layout->replaceWidget(d->RootSplitter, NewRootSplitter);
|
||||||
QSplitter* OldRoot = d->RootSplitter;
|
QSplitter* OldRoot = d->RootSplitter;
|
||||||
d->RootSplitter = dynamic_cast<QSplitter*>(NewRootSplitter);
|
d->RootSplitter = dynamic_cast<QSplitter*>(NewRootSplitter);
|
||||||
OldRoot->deleteLater();
|
OldRoot->deleteLater();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +148,7 @@ struct DockOverlayPrivate
|
|||||||
QPointer<QWidget> TargetWidget;
|
QPointer<QWidget> TargetWidget;
|
||||||
QRect TargetRect;
|
QRect TargetRect;
|
||||||
DockWidgetArea LastLocation = InvalidDockWidgetArea;
|
DockWidgetArea LastLocation = InvalidDockWidgetArea;
|
||||||
|
bool DropPreviewEnabled = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private data constructor
|
* Private data constructor
|
||||||
@ -187,7 +188,7 @@ CDockOverlay::CDockOverlay(QWidget* parent, eMode Mode) :
|
|||||||
{
|
{
|
||||||
d->Cross = new CDockOverlayCross(this);
|
d->Cross = new CDockOverlayCross(this);
|
||||||
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
|
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
|
||||||
setWindowOpacity(0.2);
|
setWindowOpacity(1);
|
||||||
setWindowTitle("DockOverlay");
|
setWindowTitle("DockOverlay");
|
||||||
setAttribute(Qt::WA_NoSystemBackground);
|
setAttribute(Qt::WA_NoSystemBackground);
|
||||||
setAttribute(Qt::WA_TranslucentBackground);
|
setAttribute(Qt::WA_TranslucentBackground);
|
||||||
@ -195,6 +196,8 @@ CDockOverlay::CDockOverlay(QWidget* parent, eMode Mode) :
|
|||||||
QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
|
QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||||
l->setSpacing(0);
|
l->setSpacing(0);
|
||||||
setLayout(l);
|
setLayout(l);
|
||||||
|
l->setContentsMargins(QMargins(0, 0, 0, 0));
|
||||||
|
l->addWidget(d->Cross);
|
||||||
|
|
||||||
d->Cross->setupOverlayCross(Mode);
|
d->Cross->setupOverlayCross(Mode);
|
||||||
d->Cross->setVisible(false);
|
d->Cross->setVisible(false);
|
||||||
@ -253,7 +256,6 @@ DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
DockWidgetArea CDockOverlay::showOverlay(QWidget* target)
|
DockWidgetArea CDockOverlay::showOverlay(QWidget* target)
|
||||||
{
|
{
|
||||||
//std::cout << "CDockOverlay::showDockOverlay(QWidget* target)" << std::endl;
|
|
||||||
if (d->TargetWidget == target)
|
if (d->TargetWidget == target)
|
||||||
{
|
{
|
||||||
qInfo() << "_target == target";
|
qInfo() << "_target == target";
|
||||||
@ -274,33 +276,15 @@ DockWidgetArea CDockOverlay::showOverlay(QWidget* target)
|
|||||||
|
|
||||||
// Move it over the target.
|
// Move it over the target.
|
||||||
resize(target->size());
|
resize(target->size());
|
||||||
move(target->mapToGlobal(target->rect().topLeft()));
|
QPoint TopLeft = target->mapToGlobal(target->rect().topLeft());
|
||||||
|
move(TopLeft);
|
||||||
|
std::cout << "Overlay top: " << TopLeft.x() << " left: " << TopLeft.y()
|
||||||
|
<< std::endl;
|
||||||
show();
|
show();
|
||||||
return dropAreaUnderCursor();
|
return dropAreaUnderCursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CDockOverlay::showOverlay(QWidget* target, const QRect& targetAreaRect)
|
|
||||||
{
|
|
||||||
qInfo() << "CDockOverlay::showDockOverlay(QWidget* target, const QRect& targetAreaRect)";
|
|
||||||
if (d->TargetWidget == target && d->TargetRect == targetAreaRect)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//hideDockOverlay();
|
|
||||||
d->TargetWidget = target;
|
|
||||||
d->TargetRect = targetAreaRect;
|
|
||||||
d->LastLocation = InvalidDockWidgetArea;
|
|
||||||
|
|
||||||
// Move it over the target's area.
|
|
||||||
resize(targetAreaRect.size());
|
|
||||||
move(target->mapToGlobal(QPoint(targetAreaRect.x(), targetAreaRect.y())));
|
|
||||||
show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockOverlay::hideOverlay()
|
void CDockOverlay::hideOverlay()
|
||||||
{
|
{
|
||||||
@ -313,12 +297,25 @@ void CDockOverlay::hideOverlay()
|
|||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockOverlay::paintEvent(QPaintEvent*)
|
void CDockOverlay::enableDropPreview(bool Enable)
|
||||||
|
{
|
||||||
|
d->DropPreviewEnabled = Enable;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CDockOverlay::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
// Draw rect based on location
|
// Draw rect based on location
|
||||||
|
if (!d->DropPreviewEnabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QRect r = rect();
|
QRect r = rect();
|
||||||
const DockWidgetArea da = dropAreaUnderCursor();
|
const DockWidgetArea da = dropAreaUnderCursor();
|
||||||
std::cout << "CursorLocation: " << dropAreaUnderCursor() << std::endl;
|
//std::cout << "CursorLocation: " << dropAreaUnderCursor() << std::endl;
|
||||||
switch (da)
|
switch (da)
|
||||||
{
|
{
|
||||||
case TopDockWidgetArea: r.setHeight(r.height() / 2); break;
|
case TopDockWidgetArea: r.setHeight(r.height() / 2); break;
|
||||||
@ -330,9 +327,9 @@ void CDockOverlay::paintEvent(QPaintEvent*)
|
|||||||
}
|
}
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
QColor Color = palette().color(QPalette::Active, QPalette::Highlight);
|
QColor Color = palette().color(QPalette::Active, QPalette::Highlight);
|
||||||
painter.fillRect(r, QBrush(Color, Qt::Dense4Pattern));
|
Color.setAlpha(64);
|
||||||
painter.setBrush(QBrush(Color));
|
painter.setPen(Qt::NoPen);
|
||||||
painter.drawRect(r);
|
painter.fillRect(r, Color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -353,23 +350,6 @@ void CDockOverlay::hideEvent(QHideEvent*)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CDockOverlay::resizeEvent(QResizeEvent* e)
|
|
||||||
{
|
|
||||||
qInfo() << "CDockOverlay::resizeEvent" << e->size();
|
|
||||||
d->Cross->resize(e->size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void CDockOverlay::moveEvent(QMoveEvent* e)
|
|
||||||
{
|
|
||||||
qInfo() << "CDockOverlay::moveEvent" << e->pos();
|
|
||||||
d->Cross->move(e->pos());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
static int areaAlignment(const DockWidgetArea area)
|
static int areaAlignment(const DockWidgetArea area)
|
||||||
{
|
{
|
||||||
@ -568,6 +548,8 @@ void CDockOverlayCross::reset()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -84,22 +84,21 @@ public:
|
|||||||
*/
|
*/
|
||||||
DockWidgetArea showOverlay(QWidget* target);
|
DockWidgetArea showOverlay(QWidget* target);
|
||||||
|
|
||||||
/**
|
|
||||||
* Show drop overlay for the given target widget and the given rectangle
|
|
||||||
*/
|
|
||||||
void showOverlay(QWidget* target, const QRect& targetAreaRect);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hides the overlay
|
* Hides the overlay
|
||||||
*/
|
*/
|
||||||
void hideOverlay();
|
void hideOverlay();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables / disables the semi transparent overlay rectangle that represents
|
||||||
|
* the future area of the dropped widget
|
||||||
|
*/
|
||||||
|
void enableDropPreview(bool Enable);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void paintEvent(QPaintEvent *e) override;
|
virtual void paintEvent(QPaintEvent *e) override;
|
||||||
virtual void showEvent(QShowEvent* e) override;
|
virtual void showEvent(QShowEvent* e) override;
|
||||||
virtual void hideEvent(QHideEvent* e) override;
|
virtual void hideEvent(QHideEvent* e) override;
|
||||||
virtual void resizeEvent(QResizeEvent* e) override;
|
|
||||||
virtual void moveEvent(QMoveEvent* e) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,6 +133,7 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint& GlobalPos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
DropContainer = TopContainer;
|
DropContainer = TopContainer;
|
||||||
|
//std::cout << "TopContainer " << TopContainer << std::endl;
|
||||||
auto ContainerOverlay = DockManager->containerOverlay();
|
auto ContainerOverlay = DockManager->containerOverlay();
|
||||||
auto DockAreaOverlay = DockManager->dockAreaOverlay();
|
auto DockAreaOverlay = DockManager->dockAreaOverlay();
|
||||||
|
|
||||||
@ -146,13 +147,15 @@ void FloatingDockContainerPrivate::updateDropOverlays(const QPoint& GlobalPos)
|
|||||||
ContainerOverlay->setAllowedAreas(TopContainer->dockAreaCount() > 1 ?
|
ContainerOverlay->setAllowedAreas(TopContainer->dockAreaCount() > 1 ?
|
||||||
OuterDockAreas : AllDockAreas);
|
OuterDockAreas : AllDockAreas);
|
||||||
ContainerOverlay->showOverlay(TopContainer);
|
ContainerOverlay->showOverlay(TopContainer);
|
||||||
ContainerOverlay->raise();
|
//ContainerOverlay->raise();
|
||||||
|
|
||||||
auto DockArea = TopContainer->dockAreaAt(GlobalPos);
|
auto DockArea = TopContainer->dockAreaAt(GlobalPos);
|
||||||
if (DockArea && TopContainer->dockAreaCount() > 1)
|
if (DockArea && TopContainer->dockAreaCount() > 0)
|
||||||
{
|
{
|
||||||
DockAreaOverlay->setAllowedAreas(AllDockAreas);
|
DockAreaOverlay->setAllowedAreas((TopContainer->dockAreaCount() == 1) ?
|
||||||
DockAreaOverlay->showOverlay(DockArea);
|
NoDockWidgetArea : AllDockAreas);
|
||||||
|
DockWidgetArea Area = DockAreaOverlay->showOverlay(DockArea);
|
||||||
|
ContainerOverlay->enableDropPreview(InvalidDockWidgetArea == Area);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user