view widgets/InfoWidget.cpp @ 257:057856cf81a2

reformat the InfoWidget and integrate the related media query
author lbajardsilogic
date Wed, 18 Jun 2008 10:38:39 +0000
parents 2ea04b3f9141
children
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"
#include "RelatedMediaWidget.h"
#include "AdvancedToolBox.h"

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

	AdvancedToolBox *  toolBox= new AdvancedToolBox;
	toolBox->addItem("File Information", infoWidget);
	toolBox->addItem("Related Media", relMediaWidget);

	QScrollArea * scrollArea = new QScrollArea;
	scrollArea->setWidget(toolBox);
	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, QStringList*> info = model->getInfo();
	std::map<QString, QStringList*>::iterator iterInfo;
	QLabel* proper;
	QLabel* icon;
	QLabel* value;

	int row = 0;

	m_infoLayout->setColumnMinimumWidth(1,20);
	m_infoLayout->setColumnMinimumWidth(3,20);

	//display author and title at first
	iterInfo = info.find("title");
	if (iterInfo!= info.end())
	{
		proper = new QLabel(iterInfo->first.toUpper());
		value = new QLabel(iterInfo->second->join(" - "));
		m_infoLayout->addWidget(proper, row, 2,1,1);
		m_infoLayout->addWidget(value, row, 4,1,1);
		row++;
	}
	iterInfo = info.find("author");
	if (iterInfo!= info.end())
	{
		proper = new QLabel(iterInfo->first.toUpper());
		value = new QLabel(iterInfo->second->join(" - "));
		m_infoLayout->addWidget(proper, row, 2,1,1);
		m_infoLayout->addWidget(value, row, 4,1,1);
		row++;
	}
	iterInfo = info.find("performer_name");
	if (iterInfo!= info.end())
	{
		proper = new QLabel("PERFORMER");
		value = new QLabel(iterInfo->second->join(" - "));
		m_infoLayout->addWidget(proper, row, 2,1,1);
		m_infoLayout->addWidget(value, row, 4,1,1);
		row++;
	}
	row++;
	
	
	//display other info
	for (iterInfo = info.begin(); iterInfo != info.end(); iterInfo++)
	{
		if ( (iterInfo->first != "title") && (iterInfo->first != "author") && (iterInfo->first != "performer_name") && (iterInfo->first != "event_label") && (iterInfo->first != "signal"))
		{
			proper = new QLabel(iterInfo->first.toUpper());
			QStringList *values = iterInfo->second;
			QString label = "";
			for (int i = 0; i < values->size(); ++i)
			{
				QString curVal = values->at(i);
				if (curVal.contains("http:"))
				{
					curVal = curVal.right(curVal.length() - curVal.lastIndexOf('/') - 1);
					curVal = curVal.right(curVal.length() - curVal.lastIndexOf('#') - 1);
				}
				label += curVal;	
				if (i+1 < values->size())
					label += " - ";
			}
			value = new QLabel(label);	
			
			m_infoLayout->addWidget(proper, row, 2,1,1);
			m_infoLayout->addWidget(value, row, 4,1,1);
			row++;
		}
	}

	iterInfo = info.find("event_label");
	if (iterInfo!= info.end())
	{
		proper = new QLabel("TIMELINE INFORMATION");
		value = new QLabel("");
		QString label;
		QStringList::const_iterator constIterator;
		for (constIterator = iterInfo->second->constBegin(); constIterator != iterInfo->second->constEnd(); ++constIterator)
		{
			label += "<a href=\"";
			label += *constIterator;
			label += "\">";
			label += *constIterator;
			label += "</a> - ";
		}
		value->setText(label);
		//connect the main window to the linkActivated signal
		connect(value, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(importEasaierLayer(QString)));
		m_infoLayout->addWidget(proper, row, 2,1,1);
		m_infoLayout->addWidget(value, row, 4,1,1);
		row++;
	}

	m_infoLayout->setColumnStretch( 4, 1);
	m_infoLayout->setRowStretch( row, 1);
}