view widgets/QueryResultsWidget.cpp @ 276:a9af42a93073

New property box for time stretching some labels updated
author benoitrigolleau
date Wed, 15 Oct 2008 16:18:18 +0000
parents fd4d0ccb7bc3
children 8bdfbd9ad418
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 "QueryResultsWidget.h"
#include "ConfidenceListWidget.h"

#include <QLabel>
#include <QApplication>

#include <iostream>

#include "sv/main/MainWindow.h"

#include <windows.h> 

int rank = 1;


QueryResultsWidget::QueryResultsWidget() : QWidget(),
	m_currentRow(0)
{
	m_resultsLayout = new QGridLayout;
	m_curResult = new std::vector<Info>;
	
	QWidget *resultsWidget = new QWidget;
	resultsWidget->setLayout(m_resultsLayout);

	m_scrollArea = new QScrollArea;
	m_scrollArea->setWidget(resultsWidget);
	m_scrollArea->setWidgetResizable(true);
	m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

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

	setLayout(mainLayout);

	connect(this,SIGNAL(pleaseAddResult(QString,QString,QString,int,QString)),this,SLOT(addResultWidget(QString,QString,QString,int,QString)));
}

QueryResultsWidget::~QueryResultsWidget()
{}

void QueryResultsWidget::addTop()
{
	QLabel *rankLabel = new QLabel("#");
	rankLabel->setAlignment(Qt::AlignHCenter);
	m_resultsLayout->addWidget(rankLabel,0,0,1,1);
	m_resultsLayout->setColumnMinimumWidth(0,15);
	m_resultsLayout->setColumnMinimumWidth(1,5);

	QLabel *typeLabel = new QLabel(tr("Type"));
	typeLabel->setAlignment(Qt::AlignHCenter);
	m_resultsLayout->addWidget(typeLabel,0,2,1,1);
	m_resultsLayout->setColumnMinimumWidth(3,5);
	m_resultsLayout->setColumnStretch(4,1);
	m_resultsLayout->setColumnMinimumWidth(5,5);

	QLabel *confidenceLabel = new QLabel(tr("Confidence"));
	confidenceLabel->setAlignment(Qt::AlignHCenter);
	m_resultsLayout->addWidget(confidenceLabel,0,6,1,1);
	m_resultsLayout->setColumnMinimumWidth(7,5);

	QLabel *metadataLabel = new QLabel(tr("Meta-Data"));
	confidenceLabel->setAlignment(Qt::AlignHCenter);
	m_resultsLayout->addWidget(metadataLabel,0,8,1,1);
	m_resultsLayout->setColumnMinimumWidth(9,5);
	m_resultsLayout->setColumnMinimumWidth(11,5);

	m_currentRow++; 
}
	
void QueryResultsWidget::addFoot()
{
	m_resultsLayout->setRowStretch(m_currentRow,1);
}

void QueryResultsWidget::reset()
{
	QLayoutItem *child;
	while ((child = m_resultsLayout->takeAt(0)) != 0) {
		delete child->widget();
	}
	m_allresults.clear();

}

void QueryResultsWidget::newResult()
{
	m_curResult->clear();
}

void QueryResultsWidget::addInfo(const QString& name, const QString& value)
{
	Info info;
	info.name = name;
	info.value = value;

	m_curResult->push_back(info);
}

void QueryResultsWidget::saveCurResult()
{
	//m_currentRow = 0;
	int type = 0;

	std::vector<Info>::iterator iterOnInfo;
	QString author = "";
	QString title = "";
	QString uri = "";
	QString confidence = "1";

	for (iterOnInfo = (*m_curResult).begin(); iterOnInfo != (*m_curResult).end(); iterOnInfo++)
	{
		if ((*iterOnInfo).name == "signal")
		{
			uri = (*iterOnInfo).value;
			//uri = uri.right(uri.length() - uri.lastIndexOf("#") - 1);
		}
	}
		
	for (iterOnInfo = (*m_curResult).begin(); iterOnInfo != (*m_curResult).end(); iterOnInfo++)
	{
		if ((*iterOnInfo).name != "signal")
		{
			//if((*iterOnInfo).name == "composer"){
			if((*iterOnInfo).name == "author"){
				author = (*iterOnInfo).value;
			}
			//if ((*iterOnInfo).name == "performance_title")
			if ((*iterOnInfo).name == "title")
			{
				title += (*iterOnInfo).value;
			}
			if ((*iterOnInfo).name == "confidence")
			{
				confidence = (*iterOnInfo).value;
			}
		}
	}
	
	//Sleep(5000);
	//emit pleaseAddResult(author,title,uri,type,confidence);
	addResultWidget(author,title,uri,type,confidence);
	
	m_currentRow=m_currentRow+3; 
	rank++;
	m_curResult = new std::vector<Info>; 
}

void QueryResultsWidget::displayResult()
{
	addFoot();
}

void QueryResultsWidget::addResultWidget(QString author,QString title, QString uri, int type, QString confidence)
{
	// add rank label
	QLabel *labelRank = new QLabel(QString().setNum(rank));
	labelRank->setMaximumWidth(20);
	labelRank->setMinimumWidth(20);
	m_resultsLayout->addWidget(labelRank,m_currentRow,0,1,1);
	
	//add the type
	QLabel *labelIcon = new QLabel();
	labelIcon->setMaximumWidth(25);
	labelIcon->setMinimumWidth(25);//
	QString pixmapName;
	switch(type){
		case 0:  
			pixmapName.append(":icons/musicIcon.png");
			break;
		case 1: 
			pixmapName.append(":icons/speechIcon.png");
			break;
		case 2: 
			pixmapName.append(":icons/videoIcon.png");
			break;
		default: 
			break;
	}
	labelIcon->setPixmap(QPixmap(pixmapName));
	m_resultsLayout->addWidget(labelIcon,m_currentRow,2,1,1);

	//add the author and title label
	QLabel *labelTitleArtist = new QLabel();
	QString auxAuthor = author;
	//auxAuthor.replace("Mac","<b>Mac</b>");
	QString label;
	label = auxAuthor+" - \"";
	label += "<a href=\"";
	label += uri;
	label += "\">";
	if (title != "")
		label += title;
	else
		label += "unknown";
	label += "</a>\"";
	labelTitleArtist->setText(label);
	labelTitleArtist->setWordWrap(true); 

	labelTitleArtist->setToolTip(title);
	connect(labelTitleArtist, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(importEasaierFile(QString)));
	connect(labelTitleArtist, SIGNAL(linkActivated(QString)), MainWindow::instance(), SLOT(lockWindow()));
	m_resultsLayout->addWidget(labelTitleArtist,m_currentRow,4,1,1);

	//add the confidence
	ConfidenceListWidget *confidenceListWidget= new ConfidenceListWidget();
	confidenceListWidget->setMaximumWidth(180);
	float fconfidence = confidence.toFloat();
	if (fconfidence < 0)
		fconfidence = 0;
	else if (fconfidence > 1)
		fconfidence = 100;
	else 
		fconfidence = fconfidence * 100;
	confidenceListWidget->addConfidence(fconfidence,"confidence");
	m_resultsLayout->addWidget(confidenceListWidget,m_currentRow,6,1,1);

	//TODO add metadatas

	//add preview button
	QPushButton *buttonPrev = new QPushButton();
	// TODO remove this line
	buttonPrev->setEnabled(false);
	buttonPrev->setMaximumSize(68,34);
	buttonPrev->setMinimumSize(68,34);
	QSize prevIconSize;
	prevIconSize.setHeight(34);
	prevIconSize.setWidth(68);
	buttonPrev->setIconSize(prevIconSize);
	buttonPrev->setIcon(QIcon(":icons/prev.png"));
	buttonPrev->setFlat(true);
	m_resultsLayout->addWidget(buttonPrev,m_currentRow,10,1,1);


	// search similar boutton
	QPushButton *buttonSimilar = new QPushButton();
	// TODO remove this line
	buttonSimilar->setEnabled(false);
	buttonSimilar->setMaximumSize(64,34);
	buttonSimilar->setMinimumSize(64,34);
	QSize similarIconSize;
	similarIconSize.setHeight(34);
	similarIconSize.setWidth(64);
	buttonSimilar->setIconSize(similarIconSize);
	buttonSimilar->setIcon(QIcon(":icons/similar.png"));
	buttonSimilar->setFlat(true);
	m_resultsLayout->addWidget(buttonSimilar,m_currentRow,12,1,1);

	//TODO add here the others informations
	//m_resultsLayout->addWidget(X,m_currentRow+1,4,1,9);

	// add the separator
	QFrame *hLine = new QFrame();
	hLine->setFrameStyle(QFrame::HLine | QFrame::Raised);
	hLine->setMaximumHeight(1);
	hLine->setMinimumHeight(1);
	m_resultsLayout->setRowMinimumHeight(m_currentRow+2,1);
	m_resultsLayout->addWidget(hLine,m_currentRow+2,1,1,12);
	
}