12#include "Separator_p.h"
19#include <QGuiApplication>
21#ifdef KDDOCKWIDGETS_QTWIDGETS
31Separator *Separator::s_separatorBeingDragged =
nullptr;
35bool rubberBandIsTopLevel()
45struct Separator::Private
58 Widget *lazyResizeRubberBand =
nullptr;
59 ItemBoxContainer *parentContainer =
nullptr;
60 Layouting::Side lastMoveDirection = Side1;
62 Widget *
const m_hostWidget;
65Separator::Separator(
Widget *hostWidget)
66 : d(new Private(hostWidget))
71Separator::~Separator()
76 s_separatorBeingDragged =
nullptr;
79bool Separator::isVertical()
const
84void Separator::move(
int p)
99 return d->orientation;
102void Separator::onMousePress()
104 s_separatorBeingDragged =
this;
106 qCDebug(separators) <<
"Drag started";
108 if (d->lazyResizeRubberBand) {
109 setLazyPosition(position());
110 d->lazyResizeRubberBand->show();
111#ifdef KDDOCKWIDGETS_QTWIDGETS
112 if (rubberBandIsTopLevel())
113 d->lazyResizeRubberBand->asQWidget()->raise();
118void Separator::onMouseDoubleClick()
122 d->parentContainer->requestEqualSize(
this);
125void Separator::onMouseMove(
QPoint pos)
127 if (!isBeingDragged())
131 qCDebug(separators) << Q_FUNC_INFO <<
"Ignoring spurious mouse event. Someone ate our ReleaseEvent";
138 const bool mouseButtonIsReallyDown = (GetKeyState(VK_LBUTTON) & 0x8000) || (GetKeyState(VK_RBUTTON) & 0x8000);
139 if (!mouseButtonIsReallyDown) {
140 qCDebug(separators) << Q_FUNC_INFO <<
"Ignoring spurious mouse event. Someone ate our ReleaseEvent";
146 const int positionToGoTo = Layouting::pos(pos, d->orientation);
147 const int minPos = d->parentContainer->minPosForSeparator_global(
this);
148 const int maxPos = d->parentContainer->maxPosForSeparator_global(
this);
150 if ((positionToGoTo > maxPos && position() <= positionToGoTo) || (positionToGoTo < minPos && position() >= positionToGoTo)) {
161 d->lastMoveDirection = positionToGoTo < position() ? Side1
162 : (positionToGoTo > position() ? Side2
165 if (d->lazyResizeRubberBand)
166 setLazyPosition(positionToGoTo);
168 d->parentContainer->requestSeparatorMove(
this, positionToGoTo - position());
171void Separator::onMouseReleased()
173 if (d->lazyResizeRubberBand) {
174 d->lazyResizeRubberBand->hide();
175 d->parentContainer->requestSeparatorMove(
this, d->lazyPosition - position());
178 s_separatorBeingDragged =
nullptr;
181void Separator::setGeometry(
QRect r)
183 if (r != d->geometry) {
185 if (
auto w = asWidget()) {
192int Separator::position()
const
194 const QPoint topLeft = d->geometry.topLeft();
195 return isVertical() ? topLeft.
y() : topLeft.
x();
198QObject *Separator::host()
const
200 return d->m_hostWidget ? d->m_hostWidget->asQObject() :
nullptr;
203void Separator::init(ItemBoxContainer *parentContainer,
Qt::Orientation orientation)
205 if (!parentContainer) {
206 qWarning() << Q_FUNC_INFO <<
"null parentContainer";
210 d->parentContainer = parentContainer;
211 d->orientation = orientation;
212 d->lazyResizeRubberBand = d->usesLazyResize ? createRubberBand(rubberBandIsTopLevel() ?
nullptr : d->m_hostWidget)
214 asWidget()->setVisible(
true);
217ItemBoxContainer *Separator::parentContainer()
const
219 return d->parentContainer;
222void Separator::setGeometry(
int pos,
int pos2,
int length)
224 QRect newGeo = d->geometry;
227 newGeo.
setSize(
QSize(length, Item::separatorThickness));
231 newGeo.
setSize(
QSize(Item::separatorThickness, length));
238bool Separator::isResizing()
240 return s_separatorBeingDragged !=
nullptr;
243int Separator::numSeparators()
248void Separator::setLazyPosition(
int pos)
250 if (d->lazyPosition != pos) {
251 d->lazyPosition = pos;
253 QRect geo = asWidget()->geometry();
259#ifdef KDDOCKWIDGETS_QTWIDGETS
260 if (rubberBandIsTopLevel())
261 geo.
translate(d->m_hostWidget->asQWidget()->mapToGlobal(
QPoint(0, 0)));
263 d->lazyResizeRubberBand->setGeometry(geo);
267bool Separator::isBeingDragged()
const
269 return s_separatorBeingDragged ==
this;
Application-wide config to tune certain behaviours of the framework.
static int s_numSeparators
internal counter just for unit-tests
Config::Flags flags() const
returns the flags;
static Config & self()
returns the singleton Config instance
void moveTo(int x, int y)
void setSize(const QSize &size)
void translate(int dx, int dy)