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