Mercurial > hg > easaier-soundaccess
view widgets/QueryResultsWidget.cpp @ 250:c12986afc03c
patch for the EasaierTB rdf storage format
author | lbajardsilogic |
---|---|
date | Tue, 10 Jun 2008 16:06:57 +0000 |
parents | ec2ca3fbd957 |
children | ee047fc1a552 |
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" 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); } 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_allresults.push_back(m_curResult); m_curResult = new std::vector<Info>; } void QueryResultsWidget::displayResult() { m_currentRow = 0; rank = 1; addTop(); int type = 0; std::vector<std::vector<Info>*>::iterator iterOnResults; int size = m_allresults.size(); for (iterOnResults = m_allresults.begin(); iterOnResults != m_allresults.end();iterOnResults++) { std::vector<Info>* onInfo = *iterOnResults; std::vector<Info>::iterator iterOnInfo; QString author = ""; QString title = ""; QString uri = ""; for (iterOnInfo = (*onInfo).begin(); iterOnInfo != (*onInfo).end(); iterOnInfo++) { if ((*iterOnInfo).name == "signal") { uri = (*iterOnInfo).value; //uri = uri.right(uri.length() - uri.lastIndexOf("#") - 1); } } for (iterOnInfo = (*onInfo).begin(); iterOnInfo != (*onInfo).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 (author == "Django") type = 2; addResultWidget(author,title,uri,type); m_currentRow=m_currentRow+3; rank++; } addFoot(); } void QueryResultsWidget::addResultWidget(QString author,QString title, QString uri, int type) { // 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 += "\">"; label += title; 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); confidenceListWidget->addConfidence(100,"confidence"); //confidenceListWidget->addConfidence(10,"confidence"); //confidenceListWidget->addConfidence(65,"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); }