Mercurial > hg > svgui
comparison widgets/TransformFinder.cpp @ 448:2b5d04b21d87
* Add some informative labels to transform finder
author | Chris Cannam |
---|---|
date | Wed, 19 Nov 2008 14:55:17 +0000 |
parents | f8fcfbe13c8f |
children | f2ef0ff2e3b0 |
comparison
equal
deleted
inserted
replaced
447:84ada1c89510 | 448:2b5d04b21d87 |
---|---|
46 QLineEdit *searchField = new QLineEdit; | 46 QLineEdit *searchField = new QLineEdit; |
47 mainGrid->addWidget(searchField, 0, 1); | 47 mainGrid->addWidget(searchField, 0, 1); |
48 connect(searchField, SIGNAL(textChanged(const QString &)), | 48 connect(searchField, SIGNAL(textChanged(const QString &)), |
49 this, SLOT(searchTextChanged(const QString &))); | 49 this, SLOT(searchTextChanged(const QString &))); |
50 | 50 |
51 m_infoLabel = new QLabel(tr("Type in the box above to search descriptions of available and known transforms")); | |
52 mainGrid->addWidget(m_infoLabel, 1, 1); | |
53 | |
51 m_resultsScroll = new QScrollArea; | 54 m_resultsScroll = new QScrollArea; |
52 // m_resultsScroll->setWidgetResizable(true); | 55 mainGrid->addWidget(m_resultsScroll, 2, 0, 1, 2); |
53 mainGrid->addWidget(m_resultsScroll, 1, 0, 1, 2); | 56 mainGrid->setRowStretch(2, 10); |
54 mainGrid->setRowStretch(1, 10); | |
55 | 57 |
56 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | | 58 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | |
57 QDialogButtonBox::Cancel); | 59 QDialogButtonBox::Cancel); |
58 mainGrid->addWidget(bb, 2, 0, 1, 2); | 60 mainGrid->addWidget(bb, 3, 0, 1, 2); |
59 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); | 61 connect(bb, SIGNAL(accepted()), this, SLOT(accept())); |
60 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); | 62 connect(bb, SIGNAL(rejected()), this, SLOT(reject())); |
61 if (!m_resultsLayout) { | 63 |
62 std::cerr << "creating frame & layout" << std::endl; | 64 m_resultsFrame = new QWidget; |
63 m_resultsFrame = new QWidget; | 65 QPalette palette = m_resultsFrame->palette(); |
64 QPalette palette = m_resultsFrame->palette(); | 66 palette.setColor(QPalette::Window, palette.color(QPalette::Base)); |
65 palette.setColor(QPalette::Window, palette.color(QPalette::Base)); | 67 m_resultsFrame->setPalette(palette); |
66 m_resultsFrame->setPalette(palette); | 68 m_resultsScroll->setPalette(palette); |
67 m_resultsScroll->setPalette(palette); | 69 m_resultsLayout = new QVBoxLayout; |
68 m_resultsLayout = new QVBoxLayout; | 70 m_resultsLayout->setSpacing(0); |
69 m_resultsLayout->setSpacing(0); | 71 m_resultsLayout->setContentsMargins(0, 0, 0, 0); |
70 m_resultsLayout->setContentsMargins(0, 0, 0, 0); | 72 m_resultsFrame->setLayout(m_resultsLayout); |
71 m_resultsFrame->setLayout(m_resultsLayout); | 73 m_resultsScroll->setWidget(m_resultsFrame); |
72 m_resultsScroll->setWidget(m_resultsFrame); | 74 m_resultsFrame->show(); |
73 m_resultsFrame->show(); | 75 |
74 } | 76 m_noResultsLabel = new QLabel(tr("<br> No results found")); |
77 m_resultsLayout->addWidget(m_noResultsLabel); | |
78 m_noResultsLabel->hide(); | |
79 | |
80 m_beforeSearchLabel = new QLabel; | |
81 m_resultsLayout->addWidget(m_beforeSearchLabel); | |
82 m_beforeSearchLabel->hide(); | |
75 | 83 |
76 QAction *up = new QAction(tr("Up"), this); | 84 QAction *up = new QAction(tr("Up"), this); |
77 up->setShortcut(tr("Up")); | 85 up->setShortcut(tr("Up")); |
78 connect(up, SIGNAL(triggered()), this, SLOT(up())); | 86 connect(up, SIGNAL(triggered()), this, SLOT(up())); |
79 addAction(up); | 87 addAction(up); |
109 } | 117 } |
110 | 118 |
111 void | 119 void |
112 TransformFinder::searchTextChanged(const QString &text) | 120 TransformFinder::searchTextChanged(const QString &text) |
113 { | 121 { |
114 std::cerr << "text is " << text.toStdString() << std::endl; | 122 // std::cerr << "text is " << text.toStdString() << std::endl; |
115 m_newSearchText = text; | 123 m_newSearchText = text; |
116 } | 124 } |
117 | 125 |
118 void | 126 void |
119 TransformFinder::timeout() | 127 TransformFinder::timeout() |
120 { | 128 { |
121 int maxResults = 40; | 129 int maxResults = 60; |
122 | 130 |
123 if (m_newSearchText != "") { | 131 if (m_newSearchText != "") { |
124 | 132 |
125 QString text = m_newSearchText; | 133 QString text = m_newSearchText; |
126 m_newSearchText = ""; | 134 m_newSearchText = ""; |
127 | 135 |
128 QStringList keywords = text.split(' ', QString::SkipEmptyParts); | 136 QStringList keywords = text.split(' ', QString::SkipEmptyParts); |
129 TransformFactory::SearchResults results = | 137 TransformFactory::SearchResults results = |
130 TransformFactory::getInstance()->search(keywords); | 138 TransformFactory::getInstance()->search(keywords); |
131 | 139 |
132 std::cerr << results.size() << " result(s)..." << std::endl; | 140 // std::cerr << results.size() << " result(s)..." << std::endl; |
133 | 141 |
134 std::set<TextMatcher::Match> sorted; | 142 std::set<TextMatcher::Match> sorted; |
135 sorted.clear(); | 143 sorted.clear(); |
136 for (TransformFactory::SearchResults::const_iterator j = results.begin(); | 144 for (TransformFactory::SearchResults::const_iterator j = results.begin(); |
137 j != results.end(); ++j) { | 145 j != results.end(); ++j) { |
138 sorted.insert(j->second); | 146 sorted.insert(j->second); |
139 } | 147 } |
140 | 148 |
141 m_sortedResults.clear(); | 149 m_sortedResults.clear(); |
142 for (std::set<TextMatcher::Match>::const_iterator j = sorted.end(); | 150 for (std::set<TextMatcher::Match>::const_iterator j = sorted.end(); |
143 j != sorted.begin(); ) { | 151 j != sorted.begin(); ) { |
144 --j; | 152 --j; |
145 m_sortedResults.push_back(*j); | 153 m_sortedResults.push_back(*j); |
153 | 161 |
154 for (int j = m_labels.size(); j > m_sortedResults.size(); ) { | 162 for (int j = m_labels.size(); j > m_sortedResults.size(); ) { |
155 m_labels[--j]->hide(); | 163 m_labels[--j]->hide(); |
156 } | 164 } |
157 | 165 |
166 if (m_sortedResults.empty()) { | |
167 m_noResultsLabel->show(); | |
168 m_resultsFrame->resize(m_resultsFrame->sizeHint()); | |
169 } else { | |
170 m_noResultsLabel->hide(); | |
171 } | |
172 | |
173 if (m_sortedResults.size() < sorted.size()) { | |
174 m_infoLabel->setText | |
175 (tr("Found %n description(s) containing <b>%1</b>, showing the first %2 only", | |
176 0, sorted.size()).arg(text).arg(m_sortedResults.size())); | |
177 } else { | |
178 m_infoLabel->setText | |
179 (tr("Found %n description(s) containing <b>%1</b>", | |
180 0, sorted.size()).arg(text)); | |
181 } | |
182 | |
158 return; | 183 return; |
159 } | 184 } |
160 | 185 |
161 if (m_upToDateCount >= m_sortedResults.size()) return; | 186 if (m_upToDateCount >= m_sortedResults.size()) return; |
162 | 187 |
229 SelectableLabel *label = new SelectableLabel(m_resultsFrame); | 254 SelectableLabel *label = new SelectableLabel(m_resultsFrame); |
230 m_resultsLayout->addWidget(label); | 255 m_resultsLayout->addWidget(label); |
231 connect(label, SIGNAL(selectionChanged()), this, | 256 connect(label, SIGNAL(selectionChanged()), this, |
232 SLOT(selectedLabelChanged())); | 257 SLOT(selectedLabelChanged())); |
233 connect(label, SIGNAL(doubleClicked()), this, | 258 connect(label, SIGNAL(doubleClicked()), this, |
234 SLOT(accept())); | 259 SLOT(labelDoubleClicked())); |
235 QPalette palette = label->palette(); | 260 QPalette palette = label->palette(); |
236 label->setPalette(palette); | 261 label->setPalette(palette); |
237 m_labels.push_back(label); | 262 m_labels.push_back(label); |
238 } | 263 } |
239 | 264 |
275 } | 300 } |
276 std::cerr << "selectedLabelChanged: selected transform is now \"" | 301 std::cerr << "selectedLabelChanged: selected transform is now \"" |
277 << m_selectedTransform.toStdString() << "\"" << std::endl; | 302 << m_selectedTransform.toStdString() << "\"" << std::endl; |
278 } | 303 } |
279 | 304 |
305 void | |
306 TransformFinder::labelDoubleClicked() | |
307 { | |
308 // The first click should have selected the label already | |
309 if (TransformFactory::getInstance()->getTransformInstallStatus | |
310 (m_selectedTransform) == | |
311 TransformFactory::TransformInstalled) { | |
312 accept(); | |
313 } | |
314 } | |
315 | |
280 TransformId | 316 TransformId |
281 TransformFinder::getTransform() const | 317 TransformFinder::getTransform() const |
282 { | 318 { |
283 return m_selectedTransform; | 319 return m_selectedTransform; |
284 } | 320 } |