annotate widgets/TransformFinder.cpp @ 416:f4487328320d

* Start work on TransformFinder dialog
author Chris Cannam
date Tue, 23 Sep 2008 13:39:25 +0000
parents
children fbf9f53cf979
rev   line source
Chris@416 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@416 2
Chris@416 3 /*
Chris@416 4 Sonic Visualiser
Chris@416 5 An audio file viewer and annotation editor.
Chris@416 6 Centre for Digital Music, Queen Mary, University of London.
Chris@416 7 This file copyright 2008 QMUL.
Chris@416 8
Chris@416 9 This program is free software; you can redistribute it and/or
Chris@416 10 modify it under the terms of the GNU General Public License as
Chris@416 11 published by the Free Software Foundation; either version 2 of the
Chris@416 12 License, or (at your option) any later version. See the file
Chris@416 13 COPYING included with this distribution for more information.
Chris@416 14 */
Chris@416 15
Chris@416 16 #include "TransformFinder.h"
Chris@416 17
Chris@416 18 #include "transform/TransformFactory.h"
Chris@416 19
Chris@416 20 #include <QVBoxLayout>
Chris@416 21 #include <QGridLayout>
Chris@416 22 #include <QLineEdit>
Chris@416 23 #include <QLabel>
Chris@416 24 #include <QDialogButtonBox>
Chris@416 25 #include <QScrollArea>
Chris@416 26
Chris@416 27 TransformFinder::TransformFinder(QWidget *parent) :
Chris@416 28 QDialog(parent)
Chris@416 29 {
Chris@416 30 setWindowTitle(tr("Find a Transform"));
Chris@416 31
Chris@416 32 QGridLayout *mainGrid = new QGridLayout;
Chris@416 33 setLayout(mainGrid);
Chris@416 34
Chris@416 35 mainGrid->addWidget(new QLabel(tr("Find:")), 0, 0);
Chris@416 36
Chris@416 37 QLineEdit *searchField = new QLineEdit;
Chris@416 38 mainGrid->addWidget(searchField, 0, 1);
Chris@416 39 connect(searchField, SIGNAL(textChanged(const QString &)),
Chris@416 40 this, SLOT(searchTextChanged(const QString &)));
Chris@416 41
Chris@416 42 m_resultsScroll = new QScrollArea;
Chris@416 43 mainGrid->addWidget(m_resultsScroll, 1, 0, 1, 2);
Chris@416 44 mainGrid->setRowStretch(1, 10);
Chris@416 45
Chris@416 46 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@416 47 QDialogButtonBox::Cancel);
Chris@416 48 mainGrid->addWidget(bb, 2, 0, 1, 2);
Chris@416 49 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
Chris@416 50 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
Chris@416 51
Chris@416 52 resize(500, 400); //!!!
Chris@416 53 }
Chris@416 54
Chris@416 55 TransformFinder::~TransformFinder()
Chris@416 56 {
Chris@416 57 }
Chris@416 58
Chris@416 59 void
Chris@416 60 TransformFinder::searchTextChanged(const QString &text)
Chris@416 61 {
Chris@416 62 std::cerr << "text is " << text.toStdString() << std::endl;
Chris@416 63
Chris@416 64 QStringList keywords = text.split(' ', QString::SkipEmptyParts);
Chris@416 65 TransformFactory::SearchResults results =
Chris@416 66 TransformFactory::getInstance()->search(keywords);
Chris@416 67
Chris@416 68 std::cerr << results.size() << " result(s)..." << std::endl;
Chris@416 69
Chris@416 70 std::set<TransformFactory::Match> sorted;
Chris@416 71 for (TransformFactory::SearchResults::const_iterator j = results.begin();
Chris@416 72 j != results.end(); ++j) {
Chris@416 73 sorted.insert(j->second);
Chris@416 74 }
Chris@416 75
Chris@416 76 int i = 0;
Chris@416 77 /*
Chris@416 78 for (std::set<TransformFactory::Match>::const_iterator j = sorted.begin();
Chris@416 79 j != sorted.end(); ++j) {
Chris@416 80 std::cerr << i++ << ": " << j->transform.toStdString() << ": ";
Chris@416 81 for (TransformFactory::Match::FragmentMap::const_iterator k =
Chris@416 82 j->fragments.begin();
Chris@416 83 k != j->fragments.end(); ++k) {
Chris@416 84 std::cerr << k->first.toStdString() << ": "
Chris@416 85 << k->second.toStdString() << " ";
Chris@416 86 }
Chris@416 87 std::cerr << "(" << j->score << ")" << std::endl;
Chris@416 88 }
Chris@416 89 */
Chris@416 90 QFrame *resultsFrame = new QFrame;
Chris@416 91 QVBoxLayout *resultsLayout = new QVBoxLayout;
Chris@416 92 resultsFrame->setLayout(resultsLayout);
Chris@416 93
Chris@416 94 i = 0;
Chris@416 95 int maxResults = 40;
Chris@416 96
Chris@416 97 for (std::set<TransformFactory::Match>::const_iterator j = sorted.end();
Chris@416 98 j != sorted.begin(); ) {
Chris@416 99 --j;
Chris@416 100 QString labelText;
Chris@416 101 TransformDescription desc =
Chris@416 102 TransformFactory::getInstance()->getTransformDescription(j->transform);
Chris@416 103 labelText += tr("%2<br><small>").arg(desc.name);
Chris@416 104 labelText += "...";
Chris@416 105 for (TransformFactory::Match::FragmentMap::const_iterator k =
Chris@416 106 j->fragments.begin();
Chris@416 107 k != j->fragments.end(); ++k) {
Chris@416 108 labelText += k->second;
Chris@416 109 labelText += "... ";
Chris@416 110 }
Chris@416 111 labelText += tr("</small>");
Chris@416 112 resultsLayout->addWidget(new QLabel(labelText));
Chris@416 113 if (++i == maxResults) break;
Chris@416 114 }
Chris@416 115
Chris@416 116 QWidget *oldWidget = m_resultsScroll->takeWidget();
Chris@416 117 m_resultsScroll->setWidget(resultsFrame);
Chris@416 118 delete oldWidget;
Chris@416 119 }
Chris@416 120
Chris@416 121 TransformId
Chris@416 122 TransformFinder::getTransform() const
Chris@416 123 {
Chris@416 124 return "";
Chris@416 125 }
Chris@416 126