Qt 4.8
Classes | Functions
qpen.h File Reference
#include <QtGui/qcolor.h>
#include <QtGui/qbrush.h>

Go to the source code of this file.

Classes

class  QPen
 The QPen class defines how a QPainter should draw lines and outlines of shapes. More...
 

Functions

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &, const QPen &)
 
Q_GUI_EXPORT QDebug operator<< (QDebug, const QPen &)
 
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &, QPen &)
 
 Q_DECLARE_TYPEINFO (QPen, Q_MOVABLE_TYPE)
 

Function Documentation

◆ operator<<() [1/2]

Q_GUI_EXPORT QDataStream& operator<< ( QDataStream ,
const QPen  
)

Definition at line 936 of file qpen.cpp.

Referenced by QPen::data_ptr(), and QPen::operator!=().

937 {
938  QPenData *dd = static_cast<QPenData *>(p.d);
939  if (s.version() < 3) {
940  s << (quint8)p.style();
941  } else if (s.version() < QDataStream::Qt_4_3) {
942  s << (quint8)(p.style() | p.capStyle() | p.joinStyle());
943  } else {
944  s << (quint16)(p.style() | p.capStyle() | p.joinStyle());
945  s << (bool)(dd->cosmetic);
946  }
947 
948  if (s.version() < 7) {
949  s << (quint8)p.width();
950  s << p.color();
951  } else {
952  s << double(p.widthF());
953  s << p.brush();
954  s << double(p.miterLimit());
955  if (sizeof(qreal) == sizeof(double)) {
956  s << p.dashPattern();
957  } else {
958  // ensure that we write doubles here instead of streaming the pattern
959  // directly; otherwise, platforms that redefine qreal might generate
960  // data that cannot be read on other platforms.
961  QVector<qreal> pattern = p.dashPattern();
962  s << quint32(pattern.size());
963  for (int i = 0; i < pattern.size(); ++i)
964  s << double(pattern.at(i));
965  }
966  if (s.version() >= 9)
967  s << double(p.dashOffset());
968  }
969  return s;
970 }
double qreal
Definition: qglobal.h:1193
unsigned char quint8
Definition: qglobal.h:934
uint cosmetic
Definition: qpen_p.h:73
unsigned short quint16
Definition: qglobal.h:936
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
unsigned int quint32
Definition: qglobal.h:938
Qt::PenStyle style
Definition: qpen_p.h:67
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ operator<<() [2/2]

Q_GUI_EXPORT QDebug operator<< ( QDebug  ,
const QPen  
)

Definition at line 1045 of file qpen.cpp.

1046 {
1047 #ifndef Q_BROKEN_DEBUG_STREAM
1048  const char *PEN_STYLES[] = {
1049  "NoPen",
1050  "SolidLine",
1051  "DashLine",
1052  "DotLine",
1053  "DashDotLine",
1054  "DashDotDotLine",
1055  "CustomDashLine"
1056  };
1057 
1058  dbg.nospace() << "QPen(" << p.width() << ',' << p.brush()
1059  << ',' << PEN_STYLES[p.style()] << ',' << int(p.capStyle())
1060  << ',' << int(p.joinStyle()) << ',' << p.dashPattern()
1061  << ',' << p.dashOffset()
1062  << ',' << p.miterLimit() << ')';
1063  return dbg.space();
1064 #else
1065  qWarning("This compiler doesn't support streaming QPen to QDebug");
1066  return dbg;
1067  Q_UNUSED(p);
1068 #endif
1069 }
Q_CORE_EXPORT void qWarning(const char *,...)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ operator>>()

Q_GUI_EXPORT QDataStream& operator>> ( QDataStream ,
QPen  
)

Definition at line 985 of file qpen.cpp.

Referenced by QPen::operator!=().

986 {
987  quint16 style;
988  quint8 width8 = 0;
989  double width = 0;
990  QColor color;
991  QBrush brush;
992  double miterLimit = 2;
993  QVector<qreal> dashPattern;
994  double dashOffset = 0;
995  bool cosmetic = false;
996  if (s.version() < QDataStream::Qt_4_3) {
997  quint8 style8;
998  s >> style8;
999  style = style8;
1000  } else {
1001  s >> style;
1002  s >> cosmetic;
1003  }
1004  if (s.version() < 7) {
1005  s >> width8;
1006  s >> color;
1007  brush = color;
1008  width = width8;
1009  } else {
1010  s >> width;
1011  s >> brush;
1012  s >> miterLimit;
1013  if (sizeof(qreal) == sizeof(double)) {
1014  s >> dashPattern;
1015  } else {
1016  quint32 numDashes;
1017  s >> numDashes;
1018  double dash;
1019  for (quint32 i = 0; i < numDashes; ++i) {
1020  s >> dash;
1021  dashPattern << dash;
1022  }
1023  }
1024  if (s.version() >= 9)
1025  s >> dashOffset;
1026  }
1027 
1028  p.detach();
1029  QPenData *dd = static_cast<QPenData *>(p.d);
1030  dd->width = width;
1031  dd->brush = brush;
1032  dd->style = Qt::PenStyle(style & Qt::MPenStyle);
1033  dd->capStyle = Qt::PenCapStyle(style & Qt::MPenCapStyle);
1035  dd->dashPattern = dashPattern;
1036  dd->miterLimit = miterLimit;
1037  dd->dashOffset = dashOffset;
1038  dd->cosmetic = cosmetic;
1039 
1040  return s;
1041 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
void detach()
Definition: qvector.h:147
qreal dashOffset
Definition: qpen_p.h:71
qreal miterLimit
Definition: qpen_p.h:72
Qt::PenCapStyle capStyle
Definition: qpen_p.h:68
unsigned char quint8
Definition: qglobal.h:934
PenStyle
Definition: qnamespace.h:1134
uint cosmetic
Definition: qpen_p.h:73
PenCapStyle
Definition: qnamespace.h:1147
Qt::PenJoinStyle joinStyle
Definition: qpen_p.h:69
unsigned short quint16
Definition: qglobal.h:936
PenJoinStyle
Definition: qnamespace.h:1154
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QVector< qreal > dashPattern
Definition: qpen_p.h:70
unsigned int quint32
Definition: qglobal.h:938
qreal width
Definition: qpen_p.h:65
Qt::PenStyle style
Definition: qpen_p.h:67
QBrush brush
Definition: qpen_p.h:66

◆ Q_DECLARE_TYPEINFO()

Q_DECLARE_TYPEINFO ( QPen  ,
Q_MOVABLE_TYPE   
)

Referenced by QPen::data_ptr().