author | erik <erik> | 2007-01-19 01:12:38 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-19 01:12:38 (UTC) |
commit | 1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7 (patch) (unidiff) | |
tree | af4a12bc46e25853386dc53868b869e1bf05d863 /noncore/apps/opie-write/qrichtext.cpp | |
parent | 2b45dc71e79a3eb7d4e8553273c9bc4f4282d50a (diff) | |
download | opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.zip opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.tar.gz opie-1ab92f1d2b346de7da8ca5c3aaa6bc75b43981e7.tar.bz2 |
Every single file in this commit had a memory leak where a resource is
allocated in the constructor but not de-allocated in the destructor.
This commit fixes that.
Diffstat (limited to 'noncore/apps/opie-write/qrichtext.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-write/qrichtext.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/noncore/apps/opie-write/qrichtext.cpp b/noncore/apps/opie-write/qrichtext.cpp index c27eb1e..f040f1e 100644 --- a/noncore/apps/opie-write/qrichtext.cpp +++ b/noncore/apps/opie-write/qrichtext.cpp | |||
@@ -6015,197 +6015,196 @@ QTextFormat QTextFormat::makeTextFormat( const QStyleSheetItem *style, const QMa | |||
6015 | format.setPointSize( int( scaleFontsFactor * style.mid( 10, style.length() - 12 ).toInt() ) ); | 6015 | format.setPointSize( int( scaleFontsFactor * style.mid( 10, style.length() - 12 ).toInt() ) ); |
6016 | } if ( style.startsWith("font-style:" ) ) { | 6016 | } if ( style.startsWith("font-style:" ) ) { |
6017 | QString s = style.mid( 11 ).stripWhiteSpace(); | 6017 | QString s = style.mid( 11 ).stripWhiteSpace(); |
6018 | if ( s == "normal" ) | 6018 | if ( s == "normal" ) |
6019 | format.fn.setItalic( FALSE ); | 6019 | format.fn.setItalic( FALSE ); |
6020 | else if ( s == "italic" || s == "oblique" ) | 6020 | else if ( s == "italic" || s == "oblique" ) |
6021 | format.fn.setItalic( TRUE ); | 6021 | format.fn.setItalic( TRUE ); |
6022 | } else if ( style.startsWith("font-weight:" ) ) { | 6022 | } else if ( style.startsWith("font-weight:" ) ) { |
6023 | QString s = style.mid( 12 ); | 6023 | QString s = style.mid( 12 ); |
6024 | bool ok = TRUE; | 6024 | bool ok = TRUE; |
6025 | int n = s.toInt( &ok ); | 6025 | int n = s.toInt( &ok ); |
6026 | if ( ok ) | 6026 | if ( ok ) |
6027 | format.fn.setWeight( n/8 ); | 6027 | format.fn.setWeight( n/8 ); |
6028 | } else if ( style.startsWith("font-family:" ) ) { | 6028 | } else if ( style.startsWith("font-family:" ) ) { |
6029 | format.fn.setFamily( QTextDocument::section(style.mid(12),",",0,0).stripWhiteSpace() ); | 6029 | format.fn.setFamily( QTextDocument::section(style.mid(12),",",0,0).stripWhiteSpace() ); |
6030 | } else if ( style.startsWith("text-decoration:" ) ) { | 6030 | } else if ( style.startsWith("text-decoration:" ) ) { |
6031 | QString s = style.mid( 16 ).stripWhiteSpace(); | 6031 | QString s = style.mid( 16 ).stripWhiteSpace(); |
6032 | format.fn.setUnderline( s == "underline" ); | 6032 | format.fn.setUnderline( s == "underline" ); |
6033 | } else if ( style.startsWith("vertical-align:" ) ) { | 6033 | } else if ( style.startsWith("vertical-align:" ) ) { |
6034 | QString s = style.mid( 15 ).stripWhiteSpace(); | 6034 | QString s = style.mid( 15 ).stripWhiteSpace(); |
6035 | if ( s == "sub" ) | 6035 | if ( s == "sub" ) |
6036 | format.setVAlign( QTextFormat::AlignSubScript ); | 6036 | format.setVAlign( QTextFormat::AlignSubScript ); |
6037 | else if ( s == "super" ) | 6037 | else if ( s == "super" ) |
6038 | format.setVAlign( QTextFormat::AlignSuperScript ); | 6038 | format.setVAlign( QTextFormat::AlignSuperScript ); |
6039 | else | 6039 | else |
6040 | format.setVAlign( QTextFormat::AlignNormal ); | 6040 | format.setVAlign( QTextFormat::AlignNormal ); |
6041 | } else if ( style.startsWith("color:" ) ) { | 6041 | } else if ( style.startsWith("color:" ) ) { |
6042 | format.col.setNamedColor( style.mid(6) ); | 6042 | format.col.setNamedColor( style.mid(6) ); |
6043 | format.linkColor = FALSE; | 6043 | format.linkColor = FALSE; |
6044 | } | 6044 | } |
6045 | } | 6045 | } |
6046 | } | 6046 | } |
6047 | 6047 | ||
6048 | format.update(); | 6048 | format.update(); |
6049 | return format; | 6049 | return format; |
6050 | } | 6050 | } |
6051 | 6051 | ||
6052 | struct QPixmapInt | 6052 | struct QPixmapInt |
6053 | { | 6053 | { |
6054 | QPixmapInt() : ref( 0 ) {} | 6054 | QPixmapInt() : ref( 0 ) {} |
6055 | QPixmap pm; | 6055 | QPixmap pm; |
6056 | int ref; | 6056 | int ref; |
6057 | }; | 6057 | }; |
6058 | 6058 | ||
6059 | static QMap<QString, QPixmapInt> *pixmap_map = 0; | 6059 | static QMap<QString, QPixmapInt> *pixmap_map = 0; |
6060 | 6060 | ||
6061 | QTextImage::QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, | 6061 | QTextImage::QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, |
6062 | QMimeSourceFactory &factory ) | 6062 | QMimeSourceFactory &factory ) |
6063 | : QTextCustomItem( p ) | 6063 | : QTextCustomItem( p ), reg( 0 ) |
6064 | { | 6064 | { |
6065 | width = height = 0; | 6065 | width = height = 0; |
6066 | if ( attr.contains("width") ) | 6066 | if ( attr.contains("width") ) |
6067 | width = attr["width"].toInt(); | 6067 | width = attr["width"].toInt(); |
6068 | if ( attr.contains("height") ) | 6068 | if ( attr.contains("height") ) |
6069 | height = attr["height"].toInt(); | 6069 | height = attr["height"].toInt(); |
6070 | 6070 | ||
6071 | reg = 0; | ||
6072 | QString imageName = attr["src"]; | 6071 | QString imageName = attr["src"]; |
6073 | 6072 | ||
6074 | if (!imageName) | 6073 | if (!imageName) |
6075 | imageName = attr["source"]; | 6074 | imageName = attr["source"]; |
6076 | 6075 | ||
6077 | if ( !imageName.isEmpty() ) { | 6076 | if ( !imageName.isEmpty() ) { |
6078 | imgId = QString( "%1,%2,%3,%4" ).arg( imageName ).arg( width ).arg( height ).arg( (ulong)&factory ); | 6077 | imgId = QString( "%1,%2,%3,%4" ).arg( imageName ).arg( width ).arg( height ).arg( (ulong)&factory ); |
6079 | if ( !pixmap_map ) | 6078 | if ( !pixmap_map ) |
6080 | pixmap_map = new QMap<QString, QPixmapInt>; | 6079 | pixmap_map = new QMap<QString, QPixmapInt>; |
6081 | if ( pixmap_map->contains( imgId ) ) { | 6080 | if ( pixmap_map->contains( imgId ) ) { |
6082 | QPixmapInt& pmi = pixmap_map->operator[](imgId); | 6081 | QPixmapInt& pmi = pixmap_map->operator[](imgId); |
6083 | pm = pmi.pm; | 6082 | pm = pmi.pm; |
6084 | pmi.ref++; | 6083 | pmi.ref++; |
6085 | width = pm.width(); | 6084 | width = pm.width(); |
6086 | height = pm.height(); | 6085 | height = pm.height(); |
6087 | } else { | 6086 | } else { |
6088 | QImage img; | 6087 | QImage img; |
6089 | const QMimeSource* m = | 6088 | const QMimeSource* m = |
6090 | factory.data( imageName, context ); | 6089 | factory.data( imageName, context ); |
6091 | if ( !m ) { | 6090 | if ( !m ) { |
6092 | owarn << "QTextImage: no mimesource for " << imageName.latin1() << "" << oendl; | 6091 | owarn << "QTextImage: no mimesource for " << imageName.latin1() << "" << oendl; |
6093 | } | 6092 | } |
6094 | else { | 6093 | else { |
6095 | if ( !QImageDrag::decode( m, img ) ) { | 6094 | if ( !QImageDrag::decode( m, img ) ) { |
6096 | owarn << "QTextImage: cannot decode " << imageName.latin1() << "" << oendl; | 6095 | owarn << "QTextImage: cannot decode " << imageName.latin1() << "" << oendl; |
6097 | } | 6096 | } |
6098 | } | 6097 | } |
6099 | 6098 | ||
6100 | if ( !img.isNull() ) { | 6099 | if ( !img.isNull() ) { |
6101 | if ( width == 0 ) { | 6100 | if ( width == 0 ) { |
6102 | width = img.width(); | 6101 | width = img.width(); |
6103 | if ( height != 0 ) { | 6102 | if ( height != 0 ) { |
6104 | width = img.width() * height / img.height(); | 6103 | width = img.width() * height / img.height(); |
6105 | } | 6104 | } |
6106 | } | 6105 | } |
6107 | if ( height == 0 ) { | 6106 | if ( height == 0 ) { |
6108 | height = img.height(); | 6107 | height = img.height(); |
6109 | if ( width != img.width() ) { | 6108 | if ( width != img.width() ) { |
6110 | height = img.height() * width / img.width(); | 6109 | height = img.height() * width / img.width(); |
6111 | } | 6110 | } |
6112 | } | 6111 | } |
6113 | if ( img.width() != width || img.height() != height ){ | 6112 | if ( img.width() != width || img.height() != height ){ |
6114 | #ifndef QT_NO_IMAGE_SMOOTHSCALE | 6113 | #ifndef QT_NO_IMAGE_SMOOTHSCALE |
6115 | img = img.smoothScale(width, height); | 6114 | img = img.smoothScale(width, height); |
6116 | #endif | 6115 | #endif |
6117 | width = img.width(); | 6116 | width = img.width(); |
6118 | height = img.height(); | 6117 | height = img.height(); |
6119 | } | 6118 | } |
6120 | pm.convertFromImage( img ); | 6119 | pm.convertFromImage( img ); |
6121 | } | 6120 | } |
6122 | if ( !pm.isNull() ) { | 6121 | if ( !pm.isNull() ) { |
6123 | QPixmapInt& pmi = pixmap_map->operator[](imgId); | 6122 | QPixmapInt& pmi = pixmap_map->operator[](imgId); |
6124 | pmi.pm = pm; | 6123 | pmi.pm = pm; |
6125 | pmi.ref++; | 6124 | pmi.ref++; |
6126 | } | 6125 | } |
6127 | } | 6126 | } |
6128 | if ( pm.mask() ) { | 6127 | if ( pm.mask() ) { |
6129 | QRegion mask( *pm.mask() ); | 6128 | QRegion mask( *pm.mask() ); |
6130 | QRegion all( 0, 0, pm.width(), pm.height() ); | 6129 | QRegion all( 0, 0, pm.width(), pm.height() ); |
6131 | reg = new QRegion( all.subtract( mask ) ); | 6130 | reg = new QRegion( all.subtract( mask ) ); |
6132 | } | 6131 | } |
6133 | } | 6132 | } |
6134 | 6133 | ||
6135 | if ( pm.isNull() && (width*height)==0 ) | 6134 | if ( pm.isNull() && (width*height)==0 ) |
6136 | width = height = 50; | 6135 | width = height = 50; |
6137 | 6136 | ||
6138 | place = PlaceInline; | 6137 | place = PlaceInline; |
6139 | if ( attr["align"] == "left" ) | 6138 | if ( attr["align"] == "left" ) |
6140 | place = PlaceLeft; | 6139 | place = PlaceLeft; |
6141 | else if ( attr["align"] == "right" ) | 6140 | else if ( attr["align"] == "right" ) |
6142 | place = PlaceRight; | 6141 | place = PlaceRight; |
6143 | 6142 | ||
6144 | tmpwidth = width; | 6143 | tmpwidth = width; |
6145 | tmpheight = height; | 6144 | tmpheight = height; |
6146 | 6145 | ||
6147 | attributes = attr; | 6146 | attributes = attr; |
6148 | } | 6147 | } |
6149 | 6148 | ||
6150 | QTextImage::~QTextImage() | 6149 | QTextImage::~QTextImage() |
6151 | { | 6150 | { |
6151 | delete reg; | ||
6152 | if ( pixmap_map && pixmap_map->contains( imgId ) ) { | 6152 | if ( pixmap_map && pixmap_map->contains( imgId ) ) { |
6153 | QPixmapInt& pmi = pixmap_map->operator[](imgId); | 6153 | QPixmapInt& pmi = pixmap_map->operator[](imgId); |
6154 | pmi.ref--; | 6154 | pmi.ref--; |
6155 | if ( !pmi.ref ) { | 6155 | if ( !pmi.ref ) { |
6156 | pixmap_map->remove( imgId ); | 6156 | pixmap_map->remove( imgId ); |
6157 | if ( pixmap_map->isEmpty() ) { | 6157 | if ( pixmap_map->isEmpty() ) { |
6158 | delete pixmap_map; | 6158 | delete pixmap_map; |
6159 | pixmap_map = 0; | 6159 | pixmap_map = 0; |
6160 | } | 6160 | } |
6161 | } | 6161 | } |
6162 | } | 6162 | } |
6163 | delete reg; | ||
6164 | } | 6163 | } |
6165 | 6164 | ||
6166 | QString QTextImage::richText() const | 6165 | QString QTextImage::richText() const |
6167 | { | 6166 | { |
6168 | QString s; | 6167 | QString s; |
6169 | s += "<img "; | 6168 | s += "<img "; |
6170 | QMap<QString, QString>::ConstIterator it = attributes.begin(); | 6169 | QMap<QString, QString>::ConstIterator it = attributes.begin(); |
6171 | for ( ; it != attributes.end(); ++it ) | 6170 | for ( ; it != attributes.end(); ++it ) |
6172 | s += it.key() + "=" + *it + " "; | 6171 | s += it.key() + "=" + *it + " "; |
6173 | s += ">"; | 6172 | s += ">"; |
6174 | return s; | 6173 | return s; |
6175 | } | 6174 | } |
6176 | 6175 | ||
6177 | void QTextImage::adjustToPainter( QPainter* p ) | 6176 | void QTextImage::adjustToPainter( QPainter* p ) |
6178 | { | 6177 | { |
6179 | width = scale( tmpwidth, p ); | 6178 | width = scale( tmpwidth, p ); |
6180 | height = scale( tmpheight, p ); | 6179 | height = scale( tmpheight, p ); |
6181 | } | 6180 | } |
6182 | 6181 | ||
6183 | #if !defined(Q_WS_X11) | 6182 | #if !defined(Q_WS_X11) |
6184 | #include <qbitmap.h> | 6183 | #include <qbitmap.h> |
6185 | #include "qcleanuphandler.h" | 6184 | #include "qcleanuphandler.h" |
6186 | static QPixmap *qrt_selection = 0; | 6185 | static QPixmap *qrt_selection = 0; |
6187 | static QSingleCleanupHandler<QPixmap> qrt_cleanup_pixmap; | 6186 | static QSingleCleanupHandler<QPixmap> qrt_cleanup_pixmap; |
6188 | static void qrt_createSelectionPixmap( const QColorGroup &cg ) | 6187 | static void qrt_createSelectionPixmap( const QColorGroup &cg ) |
6189 | { | 6188 | { |
6190 | qrt_selection = new QPixmap( 2, 2 ); | 6189 | qrt_selection = new QPixmap( 2, 2 ); |
6191 | qrt_cleanup_pixmap.set( &qrt_selection ); | 6190 | qrt_cleanup_pixmap.set( &qrt_selection ); |
6192 | qrt_selection->fill( Qt::color0 ); | 6191 | qrt_selection->fill( Qt::color0 ); |
6193 | QBitmap m( 2, 2 ); | 6192 | QBitmap m( 2, 2 ); |
6194 | m.fill( Qt::color1 ); | 6193 | m.fill( Qt::color1 ); |
6195 | QPainter p( &m ); | 6194 | QPainter p( &m ); |
6196 | p.setPen( Qt::color0 ); | 6195 | p.setPen( Qt::color0 ); |
6197 | for ( int j = 0; j < 2; ++j ) { | 6196 | for ( int j = 0; j < 2; ++j ) { |
6198 | p.drawPoint( j % 2, j ); | 6197 | p.drawPoint( j % 2, j ); |
6199 | } | 6198 | } |
6200 | p.end(); | 6199 | p.end(); |
6201 | qrt_selection->setMask( m ); | 6200 | qrt_selection->setMask( m ); |
6202 | qrt_selection->fill( cg.highlight() ); | 6201 | qrt_selection->fill( cg.highlight() ); |
6203 | } | 6202 | } |
6204 | #endif | 6203 | #endif |
6205 | 6204 | ||
6206 | void QTextImage::draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) | 6205 | void QTextImage::draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) |
6207 | { | 6206 | { |
6208 | if ( placement() != PlaceInline ) { | 6207 | if ( placement() != PlaceInline ) { |
6209 | x = xpos; | 6208 | x = xpos; |
6210 | y = ypos; | 6209 | y = ypos; |
6211 | } | 6210 | } |