/****************************************************************************
**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
+** 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()
\table
\row
- \o \inlineimage qpen-solid.png
- \o \inlineimage qpen-dash.png
- \o \inlineimage qpen-dot.png
+ \li \inlineimage qpen-solid.png
+ \li \inlineimage qpen-dash.png
+ \li \inlineimage qpen-dot.png
\row
- \o Qt::SolidLine
- \o Qt::DashLine
- \o Qt::DotLine
+ \li Qt::SolidLine
+ \li Qt::DashLine
+ \li Qt::DotLine
\row
- \o \inlineimage qpen-dashdot.png
- \o \inlineimage qpen-dashdotdot.png
- \o \inlineimage qpen-custom.png
+ \li \inlineimage qpen-dashdot.png
+ \li \inlineimage qpen-dashdotdot.png
+ \li \inlineimage qpen-custom.png
\row
- \o Qt::DashDotLine
- \o Qt::DashDotDotLine
- \o Qt::CustomDashLine
+ \li Qt::DashDotLine
+ \li Qt::DashDotDotLine
+ \li Qt::CustomDashLine
\endtable
Simply use the setStyle() function to convert the pen style to
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.
\table
\row
- \o \inlineimage qpen-square.png
- \o \inlineimage qpen-flat.png
- \o \inlineimage qpen-roundcap.png
+ \li \inlineimage qpen-square.png
+ \li \inlineimage qpen-flat.png
+ \li \inlineimage qpen-roundcap.png
\row
- \o Qt::SquareCap
- \o Qt::FlatCap
- \o Qt::RoundCap
+ \li Qt::SquareCap
+ \li Qt::FlatCap
+ \li Qt::RoundCap
\endtable
The Qt::SquareCap style is a square line end that covers the end
\table
\row
- \o \inlineimage qpen-bevel.png
- \o \inlineimage qpen-miter.png
- \o \inlineimage qpen-roundjoin.png
+ \li \inlineimage qpen-bevel.png
+ \li \inlineimage qpen-miter.png
+ \li \inlineimage qpen-roundjoin.png
\row
- \o Qt::BevelJoin
- \o Qt::MiterJoin
- \o Qt::RoundJoin
+ \li Qt::BevelJoin
+ \li Qt::MiterJoin
+ \li Qt::RoundJoin
\endtable
The Qt::BevelJoin style fills the triangular notch between the two
\table 100%
\row
- \o \inlineimage qpen-demo.png
- \o \bold {\l {painting/pathstroke}{The Path Stroking Example}}
+ \li \inlineimage qpen-demo.png
+ \li \b {\l {painting/pathstroke}{The Path Stroking Example}}
The Path Stroking example shows Qt's built-in dash patterns and shows
how custom patterns can be used to extend the range of available
\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);
}
/*!
\table 100%
\row
- \o \inlineimage qpen-custom.png
- \o
- \snippet doc/src/snippets/code/src_gui_painting_qpen.cpp 3
+ \li \inlineimage qpen-custom.png
+ \li
+ \snippet code/src_gui_painting_qpen.cpp 3
\endtable
The dash pattern is specified in units of the pens width; e.g. a
to specify the dash pattern.
\table
- \row \o \inlineimage qpen-dashpattern.png
- \o For example, a pattern where each stroke is four units long, followed by a gap
+ \row \li \inlineimage qpen-dashpattern.png
+ \li For example, a pattern where each stroke is four units long, followed by a gap
of two units, will begin with the stroke when drawn as a line.
However, if the dash offset is set to 4.0, any line drawn will begin with the gap.
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;
}
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QPen &p)
{
-#ifndef Q_BROKEN_DEBUG_STREAM
const char *PEN_STYLES[] = {
"NoPen",
"SolidLine",
<< ',' << p.dashOffset()
<< ',' << p.miterLimit() << ')';
return dbg.space();
-#else
- qWarning("This compiler doesn't support streaming QPen to QDebug");
- return dbg;
- Q_UNUSED(p);
-#endif
}
#endif