File indexing completed on 2024-12-08 11:06:59

0001 /****************************************************************************
0002 **
0003 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
0004 ** Contact: http://www.qt-project.org/legal
0005 **
0006 ** This file is part of the Qt3Support module of the Qt Toolkit.
0007 **
0008 ** $QT_BEGIN_LICENSE:LGPL$
0009 ** Commercial License Usage
0010 ** Licensees holding valid commercial Qt licenses may use this file in
0011 ** accordance with the commercial license agreement provided with the
0012 ** Software or, alternatively, in accordance with the terms contained in
0013 ** a written agreement between you and Digia.  For licensing terms and
0014 ** conditions see http://qt.digia.com/licensing.  For further information
0015 ** use the contact form at http://qt.digia.com/contact-us.
0016 **
0017 ** GNU Lesser General Public License Usage
0018 ** Alternatively, this file may be used under the terms of the GNU Lesser
0019 ** General Public License version 2.1 as published by the Free Software
0020 ** Foundation and appearing in the file LICENSE.LGPL included in the
0021 ** packaging of this file.  Please review the following information to
0022 ** ensure the GNU Lesser General Public License version 2.1 requirements
0023 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
0024 **
0025 ** In addition, as a special exception, Digia gives you certain additional
0026 ** rights.  These rights are described in the Digia Qt LGPL Exception
0027 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
0028 **
0029 ** GNU General Public License Usage
0030 ** Alternatively, this file may be used under the terms of the GNU
0031 ** General Public License version 3.0 as published by the Free Software
0032 ** Foundation and appearing in the file LICENSE.GPL included in the
0033 ** packaging of this file.  Please review the following information to
0034 ** ensure the GNU General Public License version 3.0 requirements will be
0035 ** met: http://www.gnu.org/copyleft/gpl.html.
0036 **
0037 **
0038 ** $QT_END_LICENSE$
0039 **
0040 ****************************************************************************/
0041 
0042 #include "ktlq3frame.h"
0043 
0044 #include <QPaintEvent>
0045 #include <QPainter>
0046 
0047 QT_BEGIN_NAMESPACE
0048 
0049 /*! \class KtlQ3Frame
0050 
0051     \compat
0052 */
0053 
0054 /*!
0055     Creates a new frame with the given \a parent, object \a name, and
0056     with widget flags \a f.
0057 */
0058 KtlQ3Frame::KtlQ3Frame(QWidget *parent, const char *name, Qt::WindowFlags f)
0059     : QFrame(parent, f)
0060     , marg(0)
0061 {
0062     if (name)
0063         setObjectName(QLatin1String(name));
0064     setAttribute(Qt::WA_LayoutOnEntireRect);
0065 }
0066 
0067 /*!
0068     Destructs the frame.
0069 */
0070 KtlQ3Frame::~KtlQ3Frame()
0071 {
0072 }
0073 
0074 /*!
0075     Paints the frame (or part of the frame) that's necessary,
0076     depending on the \a event.
0077 */
0078 void KtlQ3Frame::paintEvent(QPaintEvent *event)
0079 {
0080     QPainter paint(this);
0081     if (!contentsRect().contains(event->rect())) {
0082         paint.save();
0083         paint.setClipRegion(event->region().intersected(frameRect()));
0084         drawFrame(&paint);
0085         paint.restore();
0086     }
0087     if (event->rect().intersects(contentsRect())) {
0088         paint.setClipRegion(event->region().intersected(contentsRect()));
0089         drawContents(&paint);
0090     }
0091 }
0092 
0093 /*!
0094     \fn void KtlQ3Frame::drawContents(QPainter *painter)
0095 
0096     Virtual function that draws the contents of the frame on the given
0097     \a painter.
0098 
0099     The QPainter is already open when you get it, and you must leave
0100     it open. Painter \link QPainter::setWorldMatrix()
0101     transformations\endlink are switched off on entry. If you
0102     transform the painter, remember to take the frame into account and
0103     \link QPainter::resetXForm() reset transformation\endlink before
0104     returning.
0105 
0106     This function is reimplemented by subclasses that draw something
0107     inside the frame. It should only draw inside contentsRect(). The
0108     default function does nothing.
0109 
0110     \sa contentsRect(), QPainter::setClipRect()
0111 */
0112 
0113 void KtlQ3Frame::drawContents(QPainter *)
0114 {
0115 }
0116 
0117 /*!
0118     Draws the frame using the painter \a p and the current frame
0119     attributes and color group. The rectangle inside the frame is not
0120     affected.
0121 
0122     This function is virtual, but in general you do not need to
0123     reimplement it. If you do, note that the QPainter is already open
0124     and must remain open.
0125 
0126     \sa frameRect(), contentsRect(), drawContents(), frameStyle(), setPalette()
0127 */
0128 
0129 void KtlQ3Frame::drawFrame(QPainter *p)
0130 {
0131     QFrame::drawFrame(p);
0132 }
0133 
0134 /*!
0135     \fn void KtlQ3Frame::resizeEvent(QResizeEvent *event)
0136 
0137     This just calls frameChanged(); it does not make use of the \a
0138     event itself.
0139 */
0140 void KtlQ3Frame::resizeEvent(QResizeEvent *e)
0141 {
0142     if (e->size() == e->oldSize())
0143         frameChanged();
0144 }
0145 
0146 /*!
0147     Virtual function that is called when the frame style, line width
0148     or mid-line width changes.
0149 
0150     This function can be reimplemented by subclasses that need to know
0151     when the frame attributes change.
0152 */
0153 
0154 void KtlQ3Frame::frameChanged()
0155 {
0156 }
0157 
0158 /*!
0159     \property KtlQ3Frame::margin
0160     \brief the width of the margin
0161 
0162     The margin is the distance between the innermost pixel of the
0163     frame and the outermost pixel of contentsRect(). It is included in
0164     frameWidth().
0165 
0166     The margin is filled according to backgroundMode().
0167 
0168     The default value is 0.
0169 
0170     \sa lineWidth(), frameWidth()
0171 */
0172 
0173 void KtlQ3Frame::setMargin(int w)
0174 {
0175     if (marg == w)
0176         return;
0177     marg = w;
0178     update();
0179     frameChanged();
0180 }
0181 
0182 /*!
0183     \property KtlQ3Frame::contentsRect
0184     \brief the frame's contents rectangle (including the margins)
0185 */
0186 QRect KtlQ3Frame::contentsRect() const
0187 {
0188     QRect cr(QFrame::contentsRect());
0189     cr.adjust(marg, marg, -marg, -marg);
0190     return cr;
0191 }
0192 
0193 /*!
0194     Returns the width of the frame (including the margin).
0195 */
0196 int KtlQ3Frame::frameWidth() const
0197 {
0198     return QFrame::frameWidth() + marg;
0199 }
0200 
0201 QT_END_NAMESPACE
0202 
0203 #include "moc_ktlq3frame.cpp"