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

« back to all changes in this revision

Viewing changes to src/qt3support/widgets/q3frame.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 Qt 3 compatibility classes 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 "q3frame.h"
 
30
#include "qevent.h"
 
31
#include "qpainter.h"
 
32
 
 
33
 
 
34
/*! \class Q3Frame
 
35
 
 
36
    \compat
 
37
*/
 
38
 
 
39
/*!
 
40
    Creates a new frame with the given \a parent, object \a name, and
 
41
    with widget flags \a f.
 
42
*/
 
43
Q3Frame::Q3Frame(QWidget* parent, const char* name, Qt::WFlags f)
 
44
    :QFrame(parent, f), marg(0)
 
45
{
 
46
    if (name)
 
47
        setObjectName(name);
 
48
    setAttribute(Qt::WA_LayoutOnEntireRect);
 
49
    setAttribute(Qt::WA_PaintOnScreen);
 
50
}
 
51
 
 
52
/*!
 
53
    Destructs the frame.
 
54
*/
 
55
Q3Frame::~Q3Frame()
 
56
{
 
57
}
 
58
 
 
59
/*!
 
60
    Paints the frame (or part of the frame) that's necessary,
 
61
    depending on the \a event.
 
62
*/
 
63
void Q3Frame::paintEvent(QPaintEvent * event)
 
64
{
 
65
    QPainter paint(this);
 
66
    if (!contentsRect().contains(event->rect())) {
 
67
        paint.save();
 
68
        paint.setClipRegion(event->region().intersect(frameRect()));
 
69
        drawFrame(&paint);
 
70
        paint.restore();
 
71
    }
 
72
    if (event->rect().intersects(contentsRect())) {
 
73
        paint.setClipRegion(event->region().intersect(contentsRect()));
 
74
        drawContents(&paint);
 
75
    }
 
76
}
 
77
 
 
78
/*!
 
79
    \fn void Q3Frame::drawContents(QPainter *painter)
 
80
 
 
81
    Virtual function that draws the contents of the frame on the given
 
82
    \a painter.
 
83
 
 
84
    The QPainter is already open when you get it, and you must leave
 
85
    it open. Painter \link QPainter::setWorldMatrix()
 
86
    transformations\endlink are switched off on entry. If you
 
87
    transform the painter, remember to take the frame into account and
 
88
    \link QPainter::resetXForm() reset transformation\endlink before
 
89
    returning.
 
90
 
 
91
    This function is reimplemented by subclasses that draw something
 
92
    inside the frame. It should only draw inside contentsRect(). The
 
93
    default function does nothing.
 
94
 
 
95
    \sa contentsRect(), QPainter::setClipRect()
 
96
*/
 
97
 
 
98
void Q3Frame::drawContents(QPainter *)
 
99
{
 
100
}
 
101
 
 
102
/*!
 
103
    Draws the frame using the painter \a p and the current frame
 
104
    attributes and color group. The rectangle inside the frame is not
 
105
    affected.
 
106
 
 
107
    This function is virtual, but in general you do not need to
 
108
    reimplement it. If you do, note that the QPainter is already open
 
109
    and must remain open.
 
110
 
 
111
    \sa frameRect(), contentsRect(), drawContents(), frameStyle(), setPalette()
 
112
*/
 
113
 
 
114
void Q3Frame::drawFrame(QPainter *p)
 
115
{
 
116
    QFrame::drawFrame(p);
 
117
}
 
118
 
 
119
/*!
 
120
    \fn void Q3Frame::resizeEvent(QResizeEvent *event)
 
121
 
 
122
    This just calls frameChanged(); it does not make use of the \a
 
123
    event itself.
 
124
*/
 
125
void Q3Frame::resizeEvent(QResizeEvent *)
 
126
{
 
127
    frameChanged();
 
128
}
 
129
 
 
130
/*!
 
131
    Virtual function that is called when the frame style, line width
 
132
    or mid-line width changes.
 
133
 
 
134
    This function can be reimplemented by subclasses that need to know
 
135
    when the frame attributes change.
 
136
*/
 
137
 
 
138
void Q3Frame::frameChanged()
 
139
{
 
140
}
 
141
 
 
142
 
 
143
/*!
 
144
    \property Q3Frame::margin
 
145
    \brief the width of the margin
 
146
 
 
147
    The margin is the distance between the innermost pixel of the
 
148
    frame and the outermost pixel of contentsRect(). It is included in
 
149
    frameWidth().
 
150
 
 
151
    The margin is filled according to backgroundMode().
 
152
 
 
153
    The default value is 0.
 
154
 
 
155
    \sa lineWidth(), frameWidth()
 
156
*/
 
157
 
 
158
void Q3Frame::setMargin(int w)
 
159
{
 
160
    if (marg == w)
 
161
        return;
 
162
    marg = w;
 
163
    update();
 
164
    frameChanged();
 
165
}
 
166
 
 
167
/*!
 
168
    \property Q3Frame::contentsRect
 
169
    \brief the frame's contents rectangle (including the margins)
 
170
*/
 
171
QRect Q3Frame::contentsRect() const
 
172
{
 
173
    QRect cr(QFrame::contentsRect());
 
174
    cr.adjust(marg, marg, -marg, -marg);
 
175
    return cr;
 
176
}
 
177
 
 
178
/*!
 
179
    Returns the width of the frame (including the margin).
 
180
*/
 
181
int Q3Frame::frameWidth() const
 
182
{
 
183
    return QFrame::frameWidth() + marg;
 
184
}
 
185
 
 
186