This commit is contained in:
Sergio Martins
2020-04-27 23:56:47 +01:00
parent 3326429c05
commit 16d337a648
6 changed files with 52 additions and 45 deletions

View File

@@ -33,8 +33,8 @@
using namespace KDDockWidgets;
using namespace Layouting;
bool Anchor::s_isResizing = false;
Anchor* Anchor::s_separatorBeingDragged = nullptr;
static SeparatorFactoryFunc s_separatorFactoryFunc = nullptr;
@@ -62,6 +62,8 @@ Anchor::Anchor(ItemContainer *parentContainer, Qt::Orientation orientation,
Anchor::~Anchor()
{
delete m_separatorWidget;
if (s_separatorBeingDragged == this)
s_separatorBeingDragged = nullptr;
}
QWidget *Anchor::hostWidget() const
@@ -83,6 +85,11 @@ void Anchor::setGeometry(QRect r)
}
}
bool Anchor::isVertical() const
{
return m_orientation == Qt::Vertical;
}
Qt::Orientation Anchor::orientation() const
{
return m_orientation;
@@ -112,8 +119,7 @@ int Anchor::position() const
bool Anchor::isBeingDragged() const
{
return false; // TODO
//return m_layout->anchorBeingDragged() == this;
return s_separatorBeingDragged == this;
}
bool Anchor::lazyResizeEnabled() const
@@ -147,10 +153,21 @@ int Anchor::position(QPoint p) const
return isVertical() ? p.y() : p.x();
}
void Anchor::setPosition(int p)
{
QPoint pt = m_geometry.topLeft();
if (isVertical())
pt.setY(p);
else
pt.setX(p);
m_geometry.moveTopLeft(pt);
}
void Anchor::onMousePress()
{
s_isResizing = true;
//m_layout->setAnchorBeingDragged(this); TODO
s_separatorBeingDragged = this;
qCDebug(separators) << "Drag started";
if (lazyResizeEnabled()) {
@@ -163,11 +180,10 @@ void Anchor::onMouseReleased()
{
if (m_lazyResizeRubberBand) {
m_lazyResizeRubberBand->hide();
//setPosition(m_lazyPosition); TODO
setPosition(m_lazyPosition);
}
s_isResizing = false;
// m_layout->setAnchorBeingDragged(nullptr); TODO
s_separatorBeingDragged = nullptr;
}
void Anchor::onMouseMoved(QPoint pt)
@@ -205,17 +221,21 @@ void Anchor::onMouseMoved(QPoint pt)
if (/*m_lazyResize*/ false) // TODO
setLazyPosition(positionToGoTo);
//else
//setPosition(positionToGoTo);
else
setPosition(positionToGoTo);
}
void Anchor::onWidgetMoved(int )
void Anchor::onWidgetMoved(int p)
{
/* if (m_layout->anchorBeingDragged() != this) // We only care if it's being dragged by mouse
return;*/ // TODO
if (!isResizing()) // We only care if it's being dragged by mouse
return;
setPosition(p);
}
// setPosition(p); TODO
QRect Anchor::geometry() const
{
return m_geometry;
}
bool Anchor::isResizing()

View File

@@ -61,13 +61,9 @@ public:
QWidget *hostWidget() const;
Qt::Orientation orientation() const;
bool isVertical() const { return m_orientation == Qt::Vertical; }
void setGeometry(int pos, int pos2, int length);
void updatePositionPercentage();
int position() const;
void setVisible(bool);
///@brief returns the separator widget
Separator* separatorWidget() const;
@@ -81,20 +77,21 @@ public:
void onMouseMoved(QPoint pt);
void onWidgetMoved(int p);
QRect geometry() const;
bool isVertical() const;
///@brief Returns whether we're dragging a separator. Can be useful for the app to stop other work while we're not in the final size
static bool isResizing();
static void setSeparatorFactoryFunc(SeparatorFactoryFunc);
private:
void setLazyPosition(int);
void setGeometry(QRect);
Q_SIGNALS:
void geometryChanged(QRect);
public:
private:
void setLazyPosition(int);
void setGeometry(QRect);
int position(QPoint) const;
void updateSize();
QRect geometry() const { return m_geometry; }
void setPosition(int p);
const Qt::Orientation m_orientation;
@@ -102,10 +99,8 @@ public:
Layouting::Side m_lastMoveDirection = Side1;
QWidget *const m_hostWidget;
bool m_showingSide1Rubberband = false;
bool m_showingSide2Rubberband = false;
bool m_initialized = false;
static bool s_isResizing;
static Anchor* s_separatorBeingDragged;
Separator *const m_separatorWidget;
QRect m_geometry;

View File

@@ -776,8 +776,8 @@ bool ItemContainer::checkSanity()
return false;
}
const int separatorPos2 = Layouting::pos(separator->m_geometry.topLeft(), oppositeOrientation(m_orientation));
if (Layouting::pos(separator->m_geometry.topLeft(), oppositeOrientation(m_orientation)) != pos2) {
const int separatorPos2 = Layouting::pos(separator->geometry().topLeft(), oppositeOrientation(m_orientation));
if (Layouting::pos(separator->geometry().topLeft(), oppositeOrientation(m_orientation)) != pos2) {
root()->dumpLayout();
qWarning() << Q_FUNC_INFO << "Unexpected position pos2=" << separatorPos2
<< "; expected=" << pos2

View File

@@ -36,9 +36,9 @@ Separator::Separator(Layouting::Anchor *anchor, QWidget *hostWidget)
const int thickness = Item::separatorThickness();
if (isVertical())
setFixedHeight(thickness);
else
setFixedWidth(thickness);
else
setFixedHeight(thickness);
}
bool Separator::isVertical() const
@@ -46,17 +46,12 @@ bool Separator::isVertical() const
return m_anchor->isVertical();
}
int Separator::position() const
{
return isVertical() ? y() : x();
}
void Separator::move(int p)
{
if (isVertical()) {
QWidget::move(p, y());
} else {
QWidget::move(x(), p);
} else {
QWidget::move(p, y());
}
}
@@ -67,7 +62,7 @@ void Separator::mousePressEvent(QMouseEvent *)
void Separator::mouseMoveEvent(QMouseEvent *ev)
{
m_anchor->onMouseMoved(parentWidget()->mapFromGlobal(ev->globalPos() ));
m_anchor->onMouseMoved(parentWidget()->mapFromGlobal(ev->globalPos()));
}
void Separator::mouseReleaseEvent(QMouseEvent *)

View File

@@ -33,15 +33,13 @@ class /*DOCKS_EXPORT*/ Separator : public QWidget
{
Q_OBJECT
Q_PROPERTY(bool isVertical READ isVertical CONSTANT)
//Q_PROPERTY(int position READ position NOTIFY positionChanged)
public:
explicit Separator(Layouting::Anchor *anchor, QWidget *hostWidget);
bool isVertical() const;
int position() const;
void move(int p);
const QPointer<Layouting::Anchor> anchor() const { return m_anchor; }
protected:
const QPointer<Layouting::Anchor> anchor() const { return m_anchor; }
void mousePressEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;

View File

@@ -19,7 +19,6 @@
*/
#include "SeparatorWidget_p.h"
#include "multisplitter/MultiSplitterLayout_p.h"
#include "multisplitter/Anchor_p.h"
#include "Logging_p.h"
@@ -46,7 +45,7 @@ void SeparatorWidget::paintEvent(QPaintEvent *)
opt.palette = palette();
opt.rect = rect();
opt.state = QStyle::State_None;
if (isVertical())
if (!isVertical())
opt.state |= QStyle::State_Horizontal;
if (isEnabled())
@@ -57,7 +56,7 @@ void SeparatorWidget::paintEvent(QPaintEvent *)
void SeparatorWidget::enterEvent(QEvent *)
{
qCDebug(anchors) << Q_FUNC_INFO << anchor() << isEnabled() << this;
qCDebug(anchors) << Q_FUNC_INFO << anchor() << this;
if (!anchor())
return;