comparison widgets/TransformFinder.cpp @ 420:f8e04ad8e7b1

* More transform finder fiddling
author Chris Cannam
date Thu, 25 Sep 2008 13:47:40 +0000
parents b0c8e0def62e
children 7466402a32c5
comparison
equal deleted inserted replaced
419:b0c8e0def62e 420:f8e04ad8e7b1
23 #include <QLabel> 23 #include <QLabel>
24 //#include <SelectableLabel> 24 //#include <SelectableLabel>
25 #include <QDialogButtonBox> 25 #include <QDialogButtonBox>
26 #include <QScrollArea> 26 #include <QScrollArea>
27 27
28 SelectableLabel::SelectableLabel(QWidget *parent) :
29 QLabel(parent),
30 m_selected(false)
31 {
32 setTextFormat(Qt::RichText);
33 setLineWidth(2);
34 setFixedWidth(420);
35 setWordWrap(true);
36 }
37
28 void 38 void
29 SelectableLabel::setUnselectedText(QString text) 39 SelectableLabel::setUnselectedText(QString text)
30 { 40 {
31 setText(text); 41 m_unselectedText = text;
42 if (!m_selected) {
43 setText(m_unselectedText);
44 resize(sizeHint());
45 }
32 } 46 }
33 47
34 void 48 void
35 SelectableLabel::setSelectedText(QString text) 49 SelectableLabel::setSelectedText(QString text)
36 { 50 {
37 setText(text); 51 m_selectedText = text;
52 if (m_selected) {
53 setText(m_selectedText);
54 resize(sizeHint());
55 }
56 }
57
58 void
59 SelectableLabel::setSelected(bool s)
60 {
61 if (m_selected == s) return;
62 m_selected = s;
63 if (m_selected) {
64 setText(m_selectedText);
65 setFrameStyle(QFrame::Box | QFrame::Plain);
66 } else {
67 setText(m_unselectedText);
68 setFrameStyle(QFrame::NoFrame);
69 }
70 resize(sizeHint());
71 parentWidget()->resize(parentWidget()->sizeHint());
72 }
73
74 void
75 SelectableLabel::toggle()
76 {
77 setSelected(!m_selected);
38 } 78 }
39 79
40 void 80 void
41 SelectableLabel::mousePressEvent(QMouseEvent *e) 81 SelectableLabel::mousePressEvent(QMouseEvent *e)
42 { 82 {
43 83 toggle();
84 emit selectionChanged();
44 } 85 }
45 86
46 TransformFinder::TransformFinder(QWidget *parent) : 87 TransformFinder::TransformFinder(QWidget *parent) :
47 QDialog(parent), 88 QDialog(parent),
48 m_resultsFrame(0), 89 m_resultsFrame(0),
59 mainGrid->addWidget(searchField, 0, 1); 100 mainGrid->addWidget(searchField, 0, 1);
60 connect(searchField, SIGNAL(textChanged(const QString &)), 101 connect(searchField, SIGNAL(textChanged(const QString &)),
61 this, SLOT(searchTextChanged(const QString &))); 102 this, SLOT(searchTextChanged(const QString &)));
62 103
63 m_resultsScroll = new QScrollArea; 104 m_resultsScroll = new QScrollArea;
105 // m_resultsScroll->setWidgetResizable(true);
64 mainGrid->addWidget(m_resultsScroll, 1, 0, 1, 2); 106 mainGrid->addWidget(m_resultsScroll, 1, 0, 1, 2);
65 mainGrid->setRowStretch(1, 10); 107 mainGrid->setRowStretch(1, 10);
66 108
67 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | 109 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
68 QDialogButtonBox::Cancel); 110 QDialogButtonBox::Cancel);
122 i = 0; 164 i = 0;
123 int maxResults = 40; 165 int maxResults = 40;
124 int height = 0; 166 int height = 0;
125 int width = 0; 167 int width = 0;
126 168
169 if (sorted.empty()) m_selectedTransform = "";
170
127 for (std::set<TransformFactory::Match>::const_iterator j = sorted.end(); 171 for (std::set<TransformFactory::Match>::const_iterator j = sorted.end();
128 j != sorted.begin(); ) { 172 j != sorted.begin(); ) {
129 --j; 173 --j;
130 174
131 TransformDescription desc = 175 TransformDescription desc =
142 } 186 }
143 labelText += tr("</small>"); 187 labelText += tr("</small>");
144 188
145 QString selectedText; 189 QString selectedText;
146 selectedText += tr("<b>%1</b><br>").arg(desc.name); 190 selectedText += tr("<b>%1</b><br>").arg(desc.name);
147 selectedText += tr("<small><i>%1</i></small>").arg(desc.longDescription); 191 selectedText += tr("<small>%1</small>").arg(desc.longDescription);
148 /* 192 /*
149 for (TransformFactory::Match::FragmentMap::const_iterator k = 193 for (TransformFactory::Match::FragmentMap::const_iterator k =
150 j->fragments.begin(); 194 j->fragments.begin();
151 k != j->fragments.end(); ++k) { 195 k != j->fragments.end(); ++k) {
152 selectedText += tr("<br><small>%1: %2</small>").arg(k->first).arg(k->second); 196 selectedText += tr("<br><small>%1: %2</small>").arg(k->first).arg(k->second);
153 } 197 }
154 */ 198 */
155 199
156 selectedText += tr("<br><small>Plugin type: %1</small>").arg(desc.type); 200 selectedText += tr("<ul><small>");
157 selectedText += tr("<br><small>Category: %1</small>").arg(desc.category); 201 selectedText += tr("<li>Plugin type: %1</li>").arg(desc.type);
158 selectedText += tr("<br><small>System identifier: %1</small>").arg(desc.identifier); 202 selectedText += tr("<li>Category: %1</li>").arg(desc.category);
203 selectedText += tr("<li>System identifier: %1</li>").arg(desc.identifier);
204 selectedText += tr("</small></ul>");
159 205
160 if (i >= m_labels.size()) { 206 if (i >= m_labels.size()) {
161 SelectableLabel *label = new SelectableLabel(m_resultsFrame); 207 SelectableLabel *label = new SelectableLabel(m_resultsFrame);
162 m_resultsLayout->addWidget(label, i, 0); 208 m_resultsLayout->addWidget(label, i, 0);
209 connect(label, SIGNAL(selectionChanged()), this,
210 SLOT(selectedLabelChanged()));
163 m_labels.push_back(label); 211 m_labels.push_back(label);
164 } 212 }
213
214 m_labels[i]->setObjectName(desc.identifier);
215 m_selectedTransform = desc.identifier;
165 m_labels[i]->setUnselectedText(labelText); 216 m_labels[i]->setUnselectedText(labelText);
166 m_labels[i]->setSelectedText(selectedText); 217 m_labels[i]->setSelectedText(selectedText);
218 m_labels[i]->setSelected(i == 0);
167 219
168 /* 220 /*
169 QSize sh = m_labels[i]->sizeHint(); 221 QSize sh = m_labels[i]->sizeHint();
170 std::cerr << "size hint for text \"" << labelText.toStdString() << "\" has height " << sh.height() << std::endl; 222 std::cerr << "size hint for text \"" << labelText.toStdString() << "\" has height " << sh.height() << std::endl;
171 height += sh.height(); 223 height += sh.height();
184 236
185 m_resultsFrame->resize(m_resultsFrame->sizeHint()); 237 m_resultsFrame->resize(m_resultsFrame->sizeHint());
186 // m_resultsFrame->resize(height, width); 238 // m_resultsFrame->resize(height, width);
187 } 239 }
188 240
241 void
242 TransformFinder::selectedLabelChanged()
243 {
244 QObject *s = sender();
245 m_selectedTransform = "";
246 for (int i = 0; i < m_labels.size(); ++i) {
247 if (!m_labels[i]->isVisible()) continue;
248 if (m_labels[i] == s) {
249 if (m_labels[i]->isSelected()) {
250 m_selectedTransform = m_labels[i]->objectName();
251 }
252 } else {
253 if (m_labels[i]->isSelected()) {
254 m_labels[i]->setSelected(false);
255 }
256 }
257 }
258 std::cerr << "selectedLabelChanged: selected transform is now \""
259 << m_selectedTransform.toStdString() << "\"" << std::endl;
260 }
261
189 TransformId 262 TransformId
190 TransformFinder::getTransform() const 263 TransformFinder::getTransform() const
191 { 264 {
192 return ""; 265 return "";
193 } 266 }