Mercurial > hg > easaier-soundaccess
view 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 |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ /* Sound Access EASAIER client application. Silogic 2007. Laure Bajard. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information . */ #include "RelatedMediaWidget.h" #include <QScrollArea> #include <QLayoutItem> #include <QLinearGradient> #include <iostream> #include "sv/main/MainWindow.h" RelatedMediaWidget::RelatedMediaWidget() : QWidget() , m_nbRelMedia(0), m_painter(0) { m_relMediaLayout = new QGridLayout; QWidget *mediaWidget = new QWidget; mediaWidget->setLayout(m_relMediaLayout); QScrollArea * scrollArea = new QScrollArea; scrollArea->setWidget(mediaWidget); scrollArea->setWidgetResizable(true); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(scrollArea); setLayout(mainLayout); } RelatedMediaWidget::~RelatedMediaWidget() {} void RelatedMediaWidget::reset() { m_nbRelMedia = 0; QLayoutItem *child; while ((child = m_relMediaLayout->takeAt(0)) != 0) { delete child->widget(); } } void RelatedMediaWidget::addRelatedMedia(const QString &filename) { QString imageSource; QString extension = filename.right(filename.length() - (filename.lastIndexOf('.') + 1)); int width; int height; int maxHeight = 150; if (extension == "pdf") { imageSource = ":icons/icon_pdf.png"; } else { imageSource = filename; } QPixmap image(imageSource); if (image.height() > maxHeight) { height = maxHeight; width = image.width() * maxHeight / image.height(); } else { height = image.height(); width = image.width(); } QLabel *mediaLabel = new QLabel(); mediaLabel->setText("<html><header><style type=\"text/css\">a {text-decoration: none;}</style></header><body><a href=\"" + filename + "\"><img src=\"" + imageSource + "\" width=\"" + QString::number(width) + "\" height=\"" + QString::number(height) + "\"> </a></body></html>"); connect(mediaLabel, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(runExternProcess(QString))); m_relMediaLayout->addWidget(mediaLabel, 0, m_nbRelMedia); m_nbRelMedia++; }