MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / buildIcon

Method buildIcon

html/attachmenticonbuilder.cpp:37–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35
36
37QString AttachmentIconBuilder::buildIcon(qint32 lid, QString fileName) {
38 // First get the icon for this type of file
39 QIcon icon;
40 QFileInfo info(fileName);
41 QFileIconProvider provider;
42 icon = provider.icon(info);
43
44 // Build a string name for the display
45 QString displayName = info.fileName();
46
47 // Setup the painter
48 QPainter p;
49
50 // Setup the font
51 QFont font;
52 if (global.defaultGuiFontSize > 0)
53 font.setPointSize (global.defaultGuiFontSize);
54 font.setFamily("Arial");
55 QFontMetrics fm(font);
56 int width = fm.width(displayName);
57 if (width < 40) // steup a minimum width
58 width = 40;
59 width=width+50; // Add 10 px for padding & 40 for the icon
60
61 // Start drawing a new pixmap for the image in the note
62 QPoint textPoint(40,15);
63 QPoint sizePoint(40,29);
64 QPixmap pixmap(width,37);
65 pixmap.fill(QColor(global.getEditorBackgroundColor()));
66
67 p.begin(&pixmap);
68 p.setFont(font);
69 p.drawPixmap(QPoint(3,3), icon.pixmap(QSize(30,40)));
70
71 // Write out the attributes of the file
72 p.drawText(textPoint, displayName);
73
74 QString unit = QString(tr("Bytes"));
75 qint64 size = QFileInfo(fileName).size();
76 if (size > 1024) {
77 size = size/1024;
78 unit = QString(tr("KB"));
79 }
80 if (size > 1024) {
81 size = size/1024;
82 unit= QString("MB");
83 }
84 QPen pen;
85 pen.setColor(global.getEditorFontColor());
86 p.drawText(sizePoint, QString::number(size).trimmed() +" " +unit);
87 p.drawRect(0,0,width-1,37-1); // Draw a rectangle around the image.
88 p.end();
89
90 // Now that it is drawn, we write it out to a temporary file
91 QString tmpFile = global.fileManager.getTmpDirPath(QString::number(lid) + QString("_icon.png"));
92 tmpFile = tmpFile.replace("\\", "/");
93 pixmap.save(tmpFile, "png");
94 return tmpFile;

Callers 2

attachFileSelectedMethod · 0.80

Calls 6

setColorMethod · 0.80
getEditorFontColorMethod · 0.80
getTmpDirPathMethod · 0.80
saveMethod · 0.80
QStringClass · 0.50

Tested by

no test coverage detected