annotate widgets/TransformFinder.cpp @ 419:b0c8e0def62e

* some work on transform finder
author Chris Cannam
date Thu, 25 Sep 2008 12:44:23 +0000
parents bd1e4ff5091d
children f8e04ad8e7b1
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@419 20 #include <QGridLayout>
Chris@416 21 #include <QGridLayout>
Chris@416 22 #include <QLineEdit>
Chris@416 23 #include <QLabel>
Chris@419 24 //#include <SelectableLabel>
Chris@416 25 #include <QDialogButtonBox>
Chris@416 26 #include <QScrollArea>
Chris@416 27
Chris@419 28 void
Chris@419 29 SelectableLabel::setUnselectedText(QString text)
Chris@419 30 {
Chris@419 31 setText(text);
Chris@419 32 }
Chris@419 33
Chris@419 34 void
Chris@419 35 SelectableLabel::setSelectedText(QString text)
Chris@419 36 {
Chris@419 37 setText(text);
Chris@419 38 }
Chris@419 39
Chris@419 40 void
Chris@419 41 SelectableLabel::mousePressEvent(QMouseEvent *e)
Chris@419 42 {
Chris@419 43
Chris@419 44 }
Chris@419 45
Chris@416 46 TransformFinder::TransformFinder(QWidget *parent) :
Chris@417 47 QDialog(parent),
Chris@417 48 m_resultsFrame(0),
Chris@417 49 m_resultsLayout(0)
Chris@416 50 {
Chris@416 51 setWindowTitle(tr("Find a Transform"));
Chris@416 52
Chris@416 53 QGridLayout *mainGrid = new QGridLayout;
Chris@416 54 setLayout(mainGrid);
Chris@416 55
Chris@416 56 mainGrid->addWidget(new QLabel(tr("Find:")), 0, 0);
Chris@416 57
Chris@416 58 QLineEdit *searchField = new QLineEdit;
Chris@416 59 mainGrid->addWidget(searchField, 0, 1);
Chris@416 60 connect(searchField, SIGNAL(textChanged(const QString &)),
Chris@416 61 this, SLOT(searchTextChanged(const QString &)));
Chris@416 62
Chris@416 63 m_resultsScroll = new QScrollArea;
Chris@416 64 mainGrid->addWidget(m_resultsScroll, 1, 0, 1, 2);
Chris@416 65 mainGrid->setRowStretch(1, 10);
Chris@416 66
Chris@416 67 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@416 68 QDialogButtonBox::Cancel);
Chris@416 69 mainGrid->addWidget(bb, 2, 0, 1, 2);
Chris@416 70 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
Chris@416 71 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
Chris@416 72
Chris@416 73 resize(500, 400); //!!!
Chris@416 74 }
Chris@416 75
Chris@416 76 TransformFinder::~TransformFinder()
Chris@416 77 {
Chris@416 78 }
Chris@416 79
Chris@416 80 void
Chris@416 81 TransformFinder::searchTextChanged(const QString &text)
Chris@416 82 {
Chris@416 83 std::cerr << "text is " << text.toStdString() << std::endl;
Chris@416 84
Chris@416 85 QStringList keywords = text.split(' ', QString::SkipEmptyParts);
Chris@416 86 TransformFactory::SearchResults results =
Chris@416 87 TransformFactory::getInstance()->search(keywords);
Chris@416 88
Chris@416 89 std::cerr << results.size() << " result(s)..." << std::endl;
Chris@416 90
Chris@416 91 std::set<TransformFactory::Match> sorted;
Chris@416 92 for (TransformFactory::SearchResults::const_iterator j = results.begin();
Chris@416 93 j != results.end(); ++j) {
Chris@416 94 sorted.insert(j->second);
Chris@416 95 }
Chris@416 96
Chris@416 97 int i = 0;
Chris@416 98 /*
Chris@416 99 for (std::set<TransformFactory::Match>::const_iterator j = sorted.begin();
Chris@416 100 j != sorted.end(); ++j) {
Chris@416 101 std::cerr << i++ << ": " << j->transform.toStdString() << ": ";
Chris@416 102 for (TransformFactory::Match::FragmentMap::const_iterator k =
Chris@416 103 j->fragments.begin();
Chris@416 104 k != j->fragments.end(); ++k) {
Chris@416 105 std::cerr << k->first.toStdString() << ": "
Chris@416 106 << k->second.toStdString() << " ";
Chris@416 107 }
Chris@416 108 std::cerr << "(" << j->score << ")" << std::endl;
Chris@416 109 }
Chris@416 110 */
Chris@417 111
Chris@417 112 if (!m_resultsLayout) {
Chris@417 113 std::cerr << "creating frame & layout" << std::endl;
Chris@417 114 m_resultsFrame = new QWidget;
Chris@417 115 // resultsFrame->setFrameStyle(QFrame::Sunken | QFrame::Box);
Chris@419 116 m_resultsLayout = new QGridLayout;
Chris@417 117 m_resultsFrame->setLayout(m_resultsLayout);
Chris@417 118 m_resultsScroll->setWidget(m_resultsFrame);
Chris@417 119 m_resultsFrame->show();
Chris@417 120 }
Chris@416 121
Chris@416 122 i = 0;
Chris@416 123 int maxResults = 40;
Chris@417 124 int height = 0;
Chris@417 125 int width = 0;
Chris@416 126
Chris@416 127 for (std::set<TransformFactory::Match>::const_iterator j = sorted.end();
Chris@416 128 j != sorted.begin(); ) {
Chris@416 129 --j;
Chris@417 130
Chris@416 131 TransformDescription desc =
Chris@416 132 TransformFactory::getInstance()->getTransformDescription(j->transform);
Chris@419 133
Chris@419 134 QString labelText;
Chris@416 135 labelText += tr("%2<br><small>").arg(desc.name);
Chris@416 136 labelText += "...";
Chris@416 137 for (TransformFactory::Match::FragmentMap::const_iterator k =
Chris@416 138 j->fragments.begin();
Chris@416 139 k != j->fragments.end(); ++k) {
Chris@416 140 labelText += k->second;
Chris@416 141 labelText += "... ";
Chris@416 142 }
Chris@416 143 labelText += tr("</small>");
Chris@417 144
Chris@419 145 QString selectedText;
Chris@419 146 selectedText += tr("<b>%1</b><br>").arg(desc.name);
Chris@419 147 selectedText += tr("<small><i>%1</i></small>").arg(desc.longDescription);
Chris@419 148 /*
Chris@419 149 for (TransformFactory::Match::FragmentMap::const_iterator k =
Chris@419 150 j->fragments.begin();
Chris@419 151 k != j->fragments.end(); ++k) {
Chris@419 152 selectedText += tr("<br><small>%1: %2</small>").arg(k->first).arg(k->second);
Chris@419 153 }
Chris@419 154 */
Chris@419 155
Chris@419 156 selectedText += tr("<br><small>Plugin type: %1</small>").arg(desc.type);
Chris@419 157 selectedText += tr("<br><small>Category: %1</small>").arg(desc.category);
Chris@419 158 selectedText += tr("<br><small>System identifier: %1</small>").arg(desc.identifier);
Chris@419 159
Chris@417 160 if (i >= m_labels.size()) {
Chris@419 161 SelectableLabel *label = new SelectableLabel(m_resultsFrame);
Chris@419 162 m_resultsLayout->addWidget(label, i, 0);
Chris@417 163 m_labels.push_back(label);
Chris@417 164 }
Chris@419 165 m_labels[i]->setUnselectedText(labelText);
Chris@419 166 m_labels[i]->setSelectedText(selectedText);
Chris@419 167
Chris@419 168 /*
Chris@417 169 QSize sh = m_labels[i]->sizeHint();
Chris@417 170 std::cerr << "size hint for text \"" << labelText.toStdString() << "\" has height " << sh.height() << std::endl;
Chris@417 171 height += sh.height();
Chris@417 172 if (sh.width() > width) width = sh.width();
Chris@419 173 */
Chris@419 174 // m_labels[i]->resize(m_labels[i]->sizeHint());
Chris@419 175 // m_labels[i]->updateGeometry();
Chris@417 176 m_labels[i]->show();
Chris@417 177
Chris@416 178 if (++i == maxResults) break;
Chris@416 179 }
Chris@416 180
Chris@417 181 std::cerr << "m_labels.size() = " << m_labels.size() << ", i = " << i << ", height = " << height << std::endl;
Chris@417 182
Chris@419 183 for (int j = m_labels.size(); j > i; ) m_labels[--j]->hide();
Chris@417 184
Chris@419 185 m_resultsFrame->resize(m_resultsFrame->sizeHint());
Chris@419 186 // m_resultsFrame->resize(height, width);
Chris@416 187 }
Chris@416 188
Chris@416 189 TransformId
Chris@416 190 TransformFinder::getTransform() const
Chris@416 191 {
Chris@416 192 return "";
Chris@416 193 }
Chris@416 194