~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/widgets/qdockwidgetseparator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the widgets module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qdockwidgetseparator_p.h"
 
30
 
 
31
#include "qdockwidget.h"
 
32
#include "qdockwidgetlayout_p.h"
 
33
 
 
34
#include <qapplication.h>
 
35
#include <qevent.h>
 
36
#include <qpainter.h>
 
37
#include <qstyle.h>
 
38
#include <qstyleoption.h>
 
39
 
 
40
 
 
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); }
 
44
 
 
45
/*!
 
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.
 
49
 */
 
50
QRect QDockWidgetSeparator::calcRect(const QPoint &point)
 
51
{
 
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));
 
58
}
 
59
 
 
60
bool QDockWidgetSeparator::event(QEvent *event)
 
61
{
 
62
    switch(event->type()) {
 
63
    case QEvent::HoverEnter:
 
64
        hover = true;
 
65
        update();
 
66
        break;
 
67
    case QEvent::HoverLeave:
 
68
        hover = false;
 
69
        update();
 
70
        break;
 
71
    default:
 
72
        break;
 
73
    }
 
74
    return QWidget::event(event);
 
75
}
 
76
 
 
77
void QDockWidgetSeparator::mousePressEvent(QMouseEvent *event)
 
78
{
 
79
    if (event->button() != Qt::LeftButton)
 
80
        return;
 
81
 
 
82
    Q_ASSERT(!state);
 
83
    state = new DragState;
 
84
 
 
85
    state->origin = state->last = parentWidget()->mapFromGlobal(event->globalPos());
 
86
 
 
87
    // clear focus... it will be restored when the mouse button is released
 
88
    state->prevFocus = qApp->focusWidget();
 
89
    if (state->prevFocus)
 
90
        state->prevFocus->clearFocus();
 
91
 
 
92
    layout->saveLayoutInfo();
 
93
}
 
94
 
 
95
void QDockWidgetSeparator::mouseReleaseEvent(QMouseEvent *event)
 
96
{
 
97
    if (event->button() != Qt::LeftButton)
 
98
        return;
 
99
 
 
100
    layout->relayout();
 
101
    layout->discardLayoutInfo();
 
102
 
 
103
    Q_ASSERT(state != 0);
 
104
 
 
105
    // restore focus
 
106
    if (state->prevFocus)
 
107
        state->prevFocus->setFocus();
 
108
    state->prevFocus = 0;
 
109
 
 
110
    delete state;
 
111
    state = 0;
 
112
}
 
113
 
 
114
void QDockWidgetSeparator::mouseMoveEvent(QMouseEvent *event)
 
115
{
 
116
    Q_ASSERT(state != 0);
 
117
 
 
118
    QPoint p = parentWidget()->mapFromGlobal(event->globalPos());
 
119
    int delta = pick(layout->orientation, p - state->origin);
 
120
 
 
121
    // constrain the mouse move event
 
122
    layout->resetLayoutInfo();
 
123
    p = state->origin + layout->constrain(this, delta);
 
124
    if (p == state->last)
 
125
        return;
 
126
    state->last = p;
 
127
 
 
128
    layout->relayout();
 
129
}
 
130
 
 
131
void QDockWidgetSeparator::paintEvent(QPaintEvent *)
 
132
{
 
133
    QPainter p(this);
 
134
    QStyleOption opt(0);
 
135
    opt.state = QStyle::State_None;
 
136
    if (isEnabled())
 
137
        opt.state |= QStyle::State_Enabled;
 
138
    if (layout->orientation != Qt::Horizontal)
 
139
        opt.state |= QStyle::State_Horizontal;
 
140
    if (hover)
 
141
        opt.state |= QStyle::State_MouseOver;
 
142
    opt.rect = rect();
 
143
    opt.palette = palette();
 
144
    style()->drawPrimitive(QStyle::PE_IndicatorDockWidgetResizeHandle, &opt, &p, this);
 
145
}