source: trunk/src/qt3support/widgets/q3frame.cpp@ 494

Last change on this file since 494 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the Qt3Support module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "q3frame.h"
43#include "qevent.h"
44#include "qpainter.h"
45
46QT_BEGIN_NAMESPACE
47
48/*! \class Q3Frame
49
50 \compat
51*/
52
53/*!
54 Creates a new frame with the given \a parent, object \a name, and
55 with widget flags \a f.
56*/
57Q3Frame::Q3Frame(QWidget* parent, const char* name, Qt::WindowFlags f)
58 :QFrame(parent, f), marg(0)
59{
60 if (name)
61 setObjectName(QLatin1String(name));
62 setAttribute(Qt::WA_LayoutOnEntireRect);
63}
64
65/*!
66 Destructs the frame.
67*/
68Q3Frame::~Q3Frame()
69{
70}
71
72/*!
73 Paints the frame (or part of the frame) that's necessary,
74 depending on the \a event.
75*/
76void Q3Frame::paintEvent(QPaintEvent * event)
77{
78 QPainter paint(this);
79 if (!contentsRect().contains(event->rect())) {
80 paint.save();
81 paint.setClipRegion(event->region().intersected(frameRect()));
82 drawFrame(&paint);
83 paint.restore();
84 }
85 if (event->rect().intersects(contentsRect())) {
86 paint.setClipRegion(event->region().intersected(contentsRect()));
87 drawContents(&paint);
88 }
89}
90
91/*!
92 \fn void Q3Frame::drawContents(QPainter *painter)
93
94 Virtual function that draws the contents of the frame on the given
95 \a painter.
96
97 The QPainter is already open when you get it, and you must leave
98 it open. Painter \link QPainter::setWorldMatrix()
99 transformations\endlink are switched off on entry. If you
100 transform the painter, remember to take the frame into account and
101 \link QPainter::resetXForm() reset transformation\endlink before
102 returning.
103
104 This function is reimplemented by subclasses that draw something
105 inside the frame. It should only draw inside contentsRect(). The
106 default function does nothing.
107
108 \sa contentsRect(), QPainter::setClipRect()
109*/
110
111void Q3Frame::drawContents(QPainter *)
112{
113}
114
115/*!
116 Draws the frame using the painter \a p and the current frame
117 attributes and color group. The rectangle inside the frame is not
118 affected.
119
120 This function is virtual, but in general you do not need to
121 reimplement it. If you do, note that the QPainter is already open
122 and must remain open.
123
124 \sa frameRect(), contentsRect(), drawContents(), frameStyle(), setPalette()
125*/
126
127void Q3Frame::drawFrame(QPainter *p)
128{
129 QFrame::drawFrame(p);
130}
131
132/*!
133 \fn void Q3Frame::resizeEvent(QResizeEvent *event)
134
135 This just calls frameChanged(); it does not make use of the \a
136 event itself.
137*/
138void Q3Frame::resizeEvent(QResizeEvent *e)
139{
140 if (e->size() == e->oldSize())
141 frameChanged();
142}
143
144/*!
145 Virtual function that is called when the frame style, line width
146 or mid-line width changes.
147
148 This function can be reimplemented by subclasses that need to know
149 when the frame attributes change.
150*/
151
152void Q3Frame::frameChanged()
153{
154}
155
156
157/*!
158 \property Q3Frame::margin
159 \brief the width of the margin
160
161 The margin is the distance between the innermost pixel of the
162 frame and the outermost pixel of contentsRect(). It is included in
163 frameWidth().
164
165 The margin is filled according to backgroundMode().
166
167 The default value is 0.
168
169 \sa lineWidth(), frameWidth()
170*/
171
172void Q3Frame::setMargin(int w)
173{
174 if (marg == w)
175 return;
176 marg = w;
177 update();
178 frameChanged();
179}
180
181/*!
182 \property Q3Frame::contentsRect
183 \brief the frame's contents rectangle (including the margins)
184*/
185QRect Q3Frame::contentsRect() const
186{
187 QRect cr(QFrame::contentsRect());
188 cr.adjust(marg, marg, -marg, -marg);
189 return cr;
190}
191
192/*!
193 Returns the width of the frame (including the margin).
194*/
195int Q3Frame::frameWidth() const
196{
197 return QFrame::frameWidth() + marg;
198}
199
200QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.