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