/****************************************************************************
**
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
/*!
\class QPen
+ \inmodule QtGui
\ingroup painting
\ingroup shared
For example:
- \snippet doc/src/snippets/code/src_gui_painting_qpen.cpp 0
+ \snippet code/src_gui_painting_qpen.cpp 0
which is equivalent to
- \snippet doc/src/snippets/code/src_gui_painting_qpen.cpp 1
+ \snippet code/src_gui_painting_qpen.cpp 1
- The default pen is a solid black brush with 0 width, square
+ The default pen is a solid black brush with 1 width, square
cap style (Qt::SquareCap), and bevel join style (Qt::BevelJoin).
In addition QPen provides the color() and setColor()
spaces. For example, the custom pattern shown above is created
using the following code:
- \snippet doc/src/snippets/code/src_gui_painting_qpen.cpp 2
+ \snippet code/src_gui_painting_qpen.cpp 2
Note that the dash pattern is specified in units of the pens
width, e.g. a dash of length 5 in width 10 is 50 pixels long.
\internal
*/
inline QPenPrivate::QPenPrivate(const QBrush &_brush, qreal _width, Qt::PenStyle penStyle,
- Qt::PenCapStyle _capStyle, Qt::PenJoinStyle _joinStyle)
+ Qt::PenCapStyle _capStyle, Qt::PenJoinStyle _joinStyle, bool _defaultWidth)
: ref(1), dashOffset(0), miterLimit(2),
- cosmetic(false)
+ cosmetic(false), defaultWidth(_defaultWidth)
{
width = _width;
brush = _brush;
};
Q_GLOBAL_STATIC_WITH_ARGS(QPenDataHolder, defaultPenInstance,
- (Qt::black, 0, Qt::SolidLine, qpen_default_cap, qpen_default_join))
+ (Qt::black, 1, Qt::SolidLine, qpen_default_cap, qpen_default_join))
Q_GLOBAL_STATIC_WITH_ARGS(QPenDataHolder, nullPenInstance,
- (Qt::black, 0, Qt::NoPen, qpen_default_cap, qpen_default_join))
+ (Qt::black, 1, Qt::NoPen, qpen_default_cap, qpen_default_join))
/*!
- Constructs a default black solid line pen with 0 width.
+ Constructs a default black solid line pen with 1 width.
*/
QPen::QPen()
}
/*!
- Constructs a black pen with 0 width and the given \a style.
+ Constructs a black pen with 1 width and the given \a style.
\sa setStyle()
*/
d = nullPenInstance()->pen;
d->ref.ref();
} else {
- d = new QPenData(Qt::black, 0, style, qpen_default_cap, qpen_default_join);
+ d = new QPenData(Qt::black, 1, style, qpen_default_cap, qpen_default_join);
}
}
/*!
- Constructs a solid line pen with 0 width and the given \a color.
+ Constructs a solid line pen with 1 width and the given \a color.
\sa setBrush(), setColor()
*/
QPen::QPen(const QColor &color)
{
- d = new QPenData(color, 0, Qt::SolidLine, qpen_default_cap, qpen_default_join);
+ d = new QPenData(color, 1, Qt::SolidLine, qpen_default_cap, qpen_default_join);
}
Constructs a pen with the specified \a brush, \a width, pen \a style,
\a cap style and \a join style.
- \sa setBrush(), setWidth(), setStyle(), setCapStyle(), setJoinStyle()
+ \sa setBrush(), setWidth(), setStyle(), setCapStyle(), setJoinStyle()
*/
QPen::QPen(const QBrush &brush, qreal width, Qt::PenStyle s, Qt::PenCapStyle c, Qt::PenJoinStyle j)
{
- d = new QPenData(brush, width, s, c, j);
+ d = new QPenData(brush, width, s, c, j, false);
}
/*!
\row
\li \inlineimage qpen-custom.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpen.cpp 3
+ \snippet code/src_gui_painting_qpen.cpp 3
\endtable
The dash pattern is specified in units of the pens width; e.g. a
Returns the miter limit of the pen. The miter limit is only
relevant when the join style is set to Qt::MiterJoin.
- \sa setMiterLimit(), {QPen#Join Style}{Join Style}
+ \sa setMiterLimit(), {QPen#Join Style}{Join Style}
*/
qreal QPen::miterLimit() const
{
Returns the pen width with floating point precision.
- \sa setWidthF() width()
+ \sa setWidthF(), width()
*/
qreal QPen::widthF() const
{
Setting a pen width with a negative value is not supported.
- \sa setWidth() widthF()
+ \sa setWidth(), widthF()
*/
void QPen::setWidthF(qreal width)
{
- if (width < 0.f)
+ if (width < 0.f) {
qWarning("QPen::setWidthF: Setting a pen width with a negative value is not defined");
+ return;
+ }
if (qAbs(d->width - width) < 0.00000001f)
return;
detach();
d->width = width;
+ d->defaultWidth = false;
}
/*!
Returns the pen's join style.
- \sa setJoinStyle(), {QPen#Join Style}{Join Style}
+ \sa setJoinStyle(), {QPen#Join Style}{Join Style}
*/
Qt::PenJoinStyle QPen::joinStyle() const
{
used with. Drawing a shape with a cosmetic pen ensures that its
outline will have the same thickness at different scale factors.
- A zero width pen is cosmetic by default; pens with a non-zero width
- are non-cosmetic.
+ A zero width pen is cosmetic by default.
\sa setCosmetic(), widthF()
*/
|| (qFuzzyCompare(pdd->dashOffset, dd->dashOffset) &&
pdd->dashPattern == dd->dashPattern))
&& p.d->brush == d->brush
- && pdd->cosmetic == dd->cosmetic);
+ && pdd->cosmetic == dd->cosmetic
+ && pdd->defaultWidth == dd->defaultWidth);
}
}
if (s.version() >= 9)
s << double(p.dashOffset());
+ if (s.version() >= QDataStream::Qt_5_0)
+ s << bool(dd->defaultWidth);
}
return s;
}
QVector<qreal> dashPattern;
double dashOffset = 0;
bool cosmetic = false;
+ bool defaultWidth = false;
if (s.version() < QDataStream::Qt_4_3) {
quint8 style8;
s >> style8;
s >> dashOffset;
}
+ if (s.version() >= QDataStream::Qt_5_0) {
+ s >> defaultWidth;
+ } else {
+ // best we can do for legacy pens
+ defaultWidth = qFuzzyIsNull(width);
+ }
+
p.detach();
QPenData *dd = static_cast<QPenData *>(p.d);
dd->width = width;
dd->miterLimit = miterLimit;
dd->dashOffset = dashOffset;
dd->cosmetic = cosmetic;
+ dd->defaultWidth = defaultWidth;
return s;
}