src/qt3support/widgets/q3frame.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt3Support module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "q3frame.h"
       
    43 #include "qevent.h"
       
    44 #include "qpainter.h"
       
    45 
       
    46 QT_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 */
       
    57 Q3Frame::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 */
       
    68 Q3Frame::~Q3Frame()
       
    69 {
       
    70 }
       
    71 
       
    72 /*!
       
    73     Paints the frame (or part of the frame) that's necessary,
       
    74     depending on the \a event.
       
    75 */
       
    76 void 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 
       
   111 void 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 
       
   127 void 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 */
       
   138 void 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 
       
   152 void 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 
       
   172 void 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 */
       
   185 QRect 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 */
       
   195 int Q3Frame::frameWidth() const
       
   196 {
       
   197     return QFrame::frameWidth() + marg;
       
   198 }
       
   199 
       
   200 QT_END_NAMESPACE