comparison widgets/RelatedMediaWidget.cpp @ 153:98df77b4f041

add pdf icon for related media and restrain image size
author lbajardsilogic
date Thu, 15 Nov 2007 09:44:32 +0000
parents 97fd6148fb8e
children 1b8f08375391
comparison
equal deleted inserted replaced
152:46688275b5d4 153:98df77b4f041
53 } 53 }
54 } 54 }
55 55
56 void RelatedMediaWidget::addRelatedMedia(const QString &filename) 56 void RelatedMediaWidget::addRelatedMedia(const QString &filename)
57 { 57 {
58 QString imageSource;
59 QString extension = filename.right(filename.length() - (filename.lastIndexOf('.') + 1));
60
61 int width;
62 int height;
63 int maxHeight = 150;
64
65 if (extension == "pdf")
66 {
67 imageSource = ":icons/icon_pdf.png";
68 } else
69 {
70 imageSource = filename;
71 }
72
73 QPixmap image(imageSource);
74 if (image.height() > maxHeight)
75 {
76 height = maxHeight;
77 width = image.width() * maxHeight / image.height();
78 } else
79 {
80 height = image.height();
81 width = image.width();
82 }
83
58 QLabel *mediaLabel = new QLabel(); 84 QLabel *mediaLabel = new QLabel();
59 mediaLabel->setText("<html><header><style type=\"text/css\">a {text-decoration: none;}</style></header><body><a href=\"" + filename + "\"><img src=\"" + filename + "\">&nbsp;</a></body></html>"); 85 mediaLabel->setText("<html><header><style type=\"text/css\">a {text-decoration: none;}</style></header><body><a href=\"" + filename +
86 "\"><img src=\"" + imageSource + "\" width=\"" + QString::number(width) + "\" height=\"" + QString::number(height) + "\">&nbsp;</a></body></html>");
60 87
61 connect(mediaLabel, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(runExternProcess(QString))); 88 connect(mediaLabel, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(runExternProcess(QString)));
62 89
63 m_relMediaLayout->addWidget(mediaLabel, 0, m_nbRelMedia); 90 m_relMediaLayout->addWidget(mediaLabel, 0, m_nbRelMedia);
64 m_nbRelMedia++; 91 m_nbRelMedia++;