Build an icon for any attachments
| 638 | |
| 639 | // Build an icon for any attachments |
| 640 | QString NoteFormatter::findIcon(qint32 lid, Resource r, QString appl) { |
| 641 | QLOG_TRACE_IN(); |
| 642 | |
| 643 | FilterCriteria *criteria = global.filterCriteria[global.filterPosition]; |
| 644 | // First get the icon for this type of file |
| 645 | resourceHighlight = false; |
| 646 | if (criteria->isSearchStringSet() && criteria->getSearchString() != "") { |
| 647 | FilterEngine engine; |
| 648 | resourceHighlight = engine.resourceContains(lid, criteria->getSearchString(), NULL); |
| 649 | } |
| 650 | |
| 651 | QString fileName = global.fileManager.getDbaDirPath(QString::number(lid) +appl); |
| 652 | QIcon icon; |
| 653 | QFileInfo info(fileName); |
| 654 | QFileIconProvider provider; |
| 655 | icon = provider.icon(info); |
| 656 | |
| 657 | // Build a string name for the display |
| 658 | QString displayName; |
| 659 | ResourceAttributes attributes; |
| 660 | if (r.attributes.isSet()) |
| 661 | attributes = r.attributes; |
| 662 | if (attributes.fileName.isSet()) |
| 663 | displayName = attributes.fileName; |
| 664 | else |
| 665 | displayName = appl.toUpper() +" " +QString(tr("File")); |
| 666 | |
| 667 | // Setup the painter |
| 668 | QPainter p; |
| 669 | |
| 670 | // Setup the font |
| 671 | QFont font; // =p.font() ; |
| 672 | global.getGuiFont(font); |
| 673 | QPen fontPen; |
| 674 | fontPen.setColor(QColor(global.getEditorFontColor())); |
| 675 | // font.setFamily("Arial"); |
| 676 | QFontMetrics fm(font); |
| 677 | int width = fm.width(displayName); |
| 678 | if (width < 40) // steup a minimum width |
| 679 | width = 40; |
| 680 | width=width+50; // Add 10 px for padding & 40 for the icon |
| 681 | |
| 682 | // Start drawing a new pixmap for the image in the note |
| 683 | QPoint textPoint(40,15); |
| 684 | QPoint sizePoint(40,29); |
| 685 | QPixmap pixmap(width,37); |
| 686 | if (resourceHighlight) { |
| 687 | pixmap.fill(Qt::yellow); |
| 688 | } else |
| 689 | pixmap.fill(QColor(global.getEditorBackgroundColor())); |
| 690 | |
| 691 | p.begin(&pixmap); |
| 692 | p.setPen(fontPen); |
| 693 | p.setFont(font); |
| 694 | p.drawPixmap(QPoint(3,3), icon.pixmap(QSize(30,40))); |
| 695 | |
| 696 | // Write out the attributes of the file |
| 697 | p.drawText(textPoint, displayName); |
nothing calls this directly
no test coverage detected