12 #include "Separator_p.h"
14 #include "Logging_p.h"
18 #include <QGuiApplication>
26 Separator *Separator::s_separatorBeingDragged =
nullptr;
31 struct Separator::Private
44 Widget *lazyResizeRubberBand =
nullptr;
46 Layouting::Side lastMoveDirection = Side1;
48 Widget *
const m_hostWidget;
51 Separator::Separator(
Widget *hostWidget)
52 : d(new Private(hostWidget))
57 Separator::~Separator()
62 s_separatorBeingDragged =
nullptr;
65 bool Separator::isVertical()
const
70 void Separator::move(
int p)
85 return d->orientation;
88 void Separator::onMousePress()
90 s_separatorBeingDragged =
this;
92 qCDebug(separators) <<
"Drag started";
94 if (d->lazyResizeRubberBand) {
95 setLazyPosition(position());
96 d->lazyResizeRubberBand->show();
100 void Separator::onMouseDoubleClick()
104 d->parentContainer->requestEqualSize(
this);
107 void Separator::onMouseMove(
QPoint pos)
109 if (!isBeingDragged())
113 qCDebug(separators) << Q_FUNC_INFO <<
"Ignoring spurious mouse event. Someone ate our ReleaseEvent";
120 const bool mouseButtonIsReallyDown = (GetKeyState(VK_LBUTTON) & 0x8000) || (GetKeyState(VK_RBUTTON) & 0x8000);
121 if (!mouseButtonIsReallyDown) {
122 qCDebug(separators) << Q_FUNC_INFO <<
"Ignoring spurious mouse event. Someone ate our ReleaseEvent";
128 const int positionToGoTo = Layouting::pos(pos, d->orientation);
129 const int minPos = d->parentContainer->minPosForSeparator_global(
this);
130 const int maxPos = d->parentContainer->maxPosForSeparator_global(
this);
132 if ((positionToGoTo > maxPos && position() <= positionToGoTo) || (positionToGoTo < minPos && position() >= positionToGoTo)) {
143 d->lastMoveDirection = positionToGoTo < position() ? Side1
144 : (positionToGoTo > position() ? Side2
147 if (d->lazyResizeRubberBand)
148 setLazyPosition(positionToGoTo);
150 d->parentContainer->requestSeparatorMove(
this, positionToGoTo - position());
153 void Separator::onMouseReleased()
155 if (d->lazyResizeRubberBand) {
156 d->lazyResizeRubberBand->hide();
157 d->parentContainer->requestSeparatorMove(
this, d->lazyPosition - position());
160 s_separatorBeingDragged =
nullptr;
163 void Separator::setGeometry(
QRect r)
165 if (r != d->geometry) {
167 if (
auto w = asWidget()) {
174 int Separator::position()
const
176 const QPoint topLeft = d->geometry.topLeft();
177 return isVertical() ? topLeft.
y() : topLeft.
x();
180 QObject *Separator::host()
const
182 return d->m_hostWidget ? d->m_hostWidget->asQObject() :
nullptr;
187 if (!parentContainer) {
188 qWarning() << Q_FUNC_INFO <<
"null parentContainer";
192 d->parentContainer = parentContainer;
193 d->orientation = orientation;
194 d->lazyResizeRubberBand = d->usesLazyResize ? createRubberBand(d->m_hostWidget)
196 asWidget()->setVisible(
true);
201 return d->parentContainer;
204 void Separator::setGeometry(
int pos,
int pos2,
int length)
206 QRect newGeo = d->geometry;
209 newGeo.
setSize(
QSize(length, Item::separatorThickness));
213 newGeo.
setSize(
QSize(Item::separatorThickness, length));
220 bool Separator::isResizing()
222 return s_separatorBeingDragged !=
nullptr;
225 int Separator::numSeparators()
230 void Separator::setLazyPosition(
int pos)
232 if (d->lazyPosition != pos) {
233 d->lazyPosition = pos;
235 QRect geo = asWidget()->geometry();
242 d->lazyResizeRubberBand->setGeometry(geo);
246 bool Separator::isBeingDragged()
const
248 return s_separatorBeingDragged ==
this;