view widgets/InfoWidget.cpp @ 115:1ae07a8c28a0

(none)
author benoitrigolleau
date Thu, 20 Sep 2007 09:16:41 +0000
parents 87495ac7710a
children c1ea7af931e7
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 "InfoWidget.h"

#include <QScrollArea>
#include <QLayoutItem>

#include <iostream>

#include "sv/main/MainWindow.h"

InfoWidget::InfoWidget() : QWidget()
{
	m_infoLayout = new QGridLayout;
	
	QWidget *infoWidget = new QWidget;
	infoWidget->setLayout(m_infoLayout);

	QScrollArea * scrollArea = new QScrollArea;
	scrollArea->setWidget(infoWidget);
	scrollArea->setWidgetResizable(true);

	QVBoxLayout *mainLayout = new QVBoxLayout;
	mainLayout->addWidget(scrollArea);

	setLayout(mainLayout);
}

InfoWidget::~InfoWidget()
{}

void InfoWidget::reset()
{
	QLayoutItem *child;
	while ((child = m_infoLayout->takeAt(0)) != 0) {
		delete child->widget();
	}
}
void InfoWidget::displayAudioSourceInfo(AudioSourceInfoModel* model)
{
	reset();

	std::map<QString, QString> info = model->getInfo();
	std::map<QString, QString>::iterator iterInfo;
	QLabel* proper;
	QLabel* value;

	int row = 0;

	//display author and title at first
	iterInfo = info.find("title");
	if (iterInfo!= info.end())
	{
		proper = new QLabel(iterInfo->first);
		value = new QLabel(iterInfo->second);
		m_infoLayout->addWidget(proper, row, 0);
		m_infoLayout->addWidget(value, row, 1);
		row++;
	}
	iterInfo = info.find("author");
	if (iterInfo!= info.end())
	{
		proper = new QLabel(iterInfo->first);
		value = new QLabel(iterInfo->second);
		m_infoLayout->addWidget(proper, row, 0);
		m_infoLayout->addWidget(value, row, 1);
		row++;
	}

	//display other info
	for (iterInfo = info.begin(); iterInfo != info.end(); iterInfo++)
	{
		if ((iterInfo->first != "title") && (iterInfo->first != "author"))
		{
			proper = new QLabel(iterInfo->first);

			QString valueText(iterInfo->second);

			if (valueText.right(4) == ".xml")
			{
				value = new QLabel();
				value->setText("<a href=\"" + iterInfo->second + "\">" + iterInfo->second + "</a>");
				//connect the main window to the linkActivated signal
				connect(value, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(importEasaierLayer(QString)));

			} else {
				value = new QLabel(iterInfo->second);
			}
			
			m_infoLayout->addWidget(proper, row, 0);
			m_infoLayout->addWidget(value, row, 1);
			row++;
		}
	}

	m_infoLayout->setColumnStretch( 1, 1);
}