Skip to content

Commit b6ee23c

Browse files
author
timlinux
committedMay 14, 2008
Bug fix and gui enhancement:
- remove rendering artifacts in legend item icons (dont use argb premultified!) - show polygon icons as a squiggly polygon so the edges arent clipped (and hopefull people find it more attractive) - show line icons as a curve git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8430 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

3 files changed

+59
-16
lines changed

3 files changed

+59
-16
lines changed
 

‎src/app/legend/qgslegenditem.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "qgslegenditem.h"
2121
#include <iostream>
2222
#include <QCoreApplication>
23-
#include <QIcon>
2423
#include "qgslegend.h"
2524

2625

‎src/app/legend/qgslegendsymbologyitem.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@
2121
#include "qgslegendsymbologyitem.h"
2222

2323
QgsLegendSymbologyItem::QgsLegendSymbologyItem(QTreeWidgetItem * theItem,QString theString, int pixmapWidth, int pixmapHeight)
24-
: QgsLegendItem(theItem, theString), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight), mLegend(0)
24+
: QgsLegendItem(theItem, theString),
25+
mPixmapWidth(pixmapWidth),
26+
mPixmapHeight(pixmapHeight),
27+
mLegend(0)
2528
{
2629
mType = LEGEND_SYMBOL_ITEM;
2730
}
2831

29-
QgsLegendSymbologyItem::QgsLegendSymbologyItem(int pixmapWidth, int pixmapHeight): QgsLegendItem(), mPixmapWidth(pixmapWidth), mPixmapHeight(pixmapHeight), mLegend(0)
32+
QgsLegendSymbologyItem::QgsLegendSymbologyItem(int pixmapWidth, int pixmapHeight)
33+
: QgsLegendItem(),
34+
mPixmapWidth(pixmapWidth),
35+
mPixmapHeight(pixmapHeight),
36+
mLegend(0)
3037
{
3138
mType = LEGEND_SYMBOL_ITEM;
3239
}

‎src/core/symbology/qgssymbol.cpp

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -245,23 +245,60 @@ int QgsSymbol::pointSize() const
245245

246246
QImage QgsSymbol::getLineSymbolAsImage()
247247
{
248-
QImage img(15, 15, QImage::Format_ARGB32_Premultiplied);
249-
img.fill(QColor(255,255,255,0).rgba());
250-
QPainter p(&img);
251-
p.setPen(mPen);
252-
p.drawLine(0, 0, 15, 15);
253-
return img; //this is ok because of qts sharing mechanism
248+
//Note by Tim: dont use premultiplied - it causes
249+
//artifacts on the output icon!
250+
QImage img(15, 15,QImage::Format_ARGB32 );//QImage::Format_ARGB32_Premultiplied);
251+
img.fill(QColor(255,255,255,255).rgba());
252+
QPainter p(&img);
253+
p.setRenderHints(QPainter::Antialiasing);
254+
p.setPen(mPen);
255+
256+
257+
QPainterPath myPath;
258+
myPath.moveTo(0, 0);
259+
myPath.cubicTo(15, 0, 5, 7, 15, 15);
260+
p.drawPath(myPath);
261+
//p.drawLine(0, 0, 15, 15);
262+
return img; //this is ok because of qts sharing mechanism
254263
}
255264

256265
QImage QgsSymbol::getPolygonSymbolAsImage()
257266
{
258-
QImage img(15, 15, QImage::Format_ARGB32_Premultiplied);
259-
img.fill(QColor(255,255,255,0).rgba());
260-
QPainter p(&img);
261-
p.setPen(mPen);
262-
p.setBrush(mBrush);
263-
p.drawRect(0, 0, 15, 15);
264-
return img; //this is ok because of qts sharing mechanism
267+
//Note by Tim: dont use premultiplied - it causes
268+
//artifacts on the output icon!
269+
QImage img(15, 15,QImage::Format_ARGB32); //, QImage::Format_ARGB32_Premultiplied);
270+
img.fill(QColor(255,255,255,255).rgba());
271+
QPainter p(&img);
272+
p.setRenderHints(QPainter::Antialiasing);
273+
p.setPen(mPen);
274+
p.setBrush(mBrush);
275+
QPolygon myPolygon;
276+
//leave a little white space around so
277+
//dont draw at 0,0,15,15
278+
myPolygon << QPoint(2, 2)
279+
<< QPoint(1, 5)
280+
<< QPoint(1, 10)
281+
<< QPoint(2, 12)
282+
<< QPoint(5, 13)
283+
<< QPoint(6, 13)
284+
<< QPoint(8, 12)
285+
<< QPoint(8, 12)
286+
<< QPoint(10, 12)
287+
<< QPoint(12, 13)
288+
<< QPoint(13, 11)
289+
<< QPoint(12, 8)
290+
<< QPoint(11, 6)
291+
<< QPoint(12, 5)
292+
<< QPoint(13, 2)
293+
<< QPoint(11, 1)
294+
<< QPoint(10, 1)
295+
<< QPoint(8, 2)
296+
<< QPoint(6, 4)
297+
<< QPoint(4, 2)
298+
;
299+
p.drawPolygon(myPolygon);
300+
//p.drawRect(1, 1, 14, 14);
301+
return img; //this is ok because of qts sharing mechanism
265302
}
266303

267304
QImage QgsSymbol::getCachedPointSymbolAsImage( double widthScale,

0 commit comments

Comments
 (0)
Please sign in to comment.