1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the widgets module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qdockwidgetseparator_p.h"
31
#include "qdockwidget.h"
32
#include "qdockwidgetlayout_p.h"
34
#include <qapplication.h>
38
#include <qstyleoption.h>
41
QDockWidgetSeparator::QDockWidgetSeparator(QDockWidgetLayout *l, QWidget *parent)
42
: QWidget(parent), layout(l), state(0), hover(false)
43
{ setCursor(layout->orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor); }
46
Returns a rectangle centered around \a point. The parent dock
47
orientation is used to calculate a rectangle that is appropriate
48
for use while the user is moving the separator.
50
QRect QDockWidgetSeparator::calcRect(const QPoint &point)
52
int pos = pick(layout->orientation, point);
53
int ext = pick(layout->orientation, size());
54
int sz = pick_perp(layout->orientation, size());
55
return (layout->orientation == Qt::Horizontal ?
56
QRect(pos - (ext/2), 0, ext, sz) :
57
QRect(0, pos - (ext/2), sz, ext));
60
bool QDockWidgetSeparator::event(QEvent *event)
62
switch(event->type()) {
63
case QEvent::HoverEnter:
67
case QEvent::HoverLeave:
74
return QWidget::event(event);
77
void QDockWidgetSeparator::mousePressEvent(QMouseEvent *event)
79
if (event->button() != Qt::LeftButton)
83
state = new DragState;
85
state->origin = state->last = parentWidget()->mapFromGlobal(event->globalPos());
87
// clear focus... it will be restored when the mouse button is released
88
state->prevFocus = qApp->focusWidget();
90
state->prevFocus->clearFocus();
92
layout->saveLayoutInfo();
95
void QDockWidgetSeparator::mouseReleaseEvent(QMouseEvent *event)
97
if (event->button() != Qt::LeftButton)
101
layout->discardLayoutInfo();
103
Q_ASSERT(state != 0);
106
if (state->prevFocus)
107
state->prevFocus->setFocus();
108
state->prevFocus = 0;
114
void QDockWidgetSeparator::mouseMoveEvent(QMouseEvent *event)
116
Q_ASSERT(state != 0);
118
QPoint p = parentWidget()->mapFromGlobal(event->globalPos());
119
int delta = pick(layout->orientation, p - state->origin);
121
// constrain the mouse move event
122
layout->resetLayoutInfo();
123
p = state->origin + layout->constrain(this, delta);
124
if (p == state->last)
131
void QDockWidgetSeparator::paintEvent(QPaintEvent *)
135
opt.state = QStyle::State_None;
137
opt.state |= QStyle::State_Enabled;
138
if (layout->orientation != Qt::Horizontal)
139
opt.state |= QStyle::State_Horizontal;
141
opt.state |= QStyle::State_MouseOver;
143
opt.palette = palette();
144
style()->drawPrimitive(QStyle::PE_IndicatorDockWidgetResizeHandle, &opt, &p, this);