comparison 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
comparison
equal deleted inserted replaced
418:bd1e4ff5091d 419:b0c8e0def62e
15 15
16 #include "TransformFinder.h" 16 #include "TransformFinder.h"
17 17
18 #include "transform/TransformFactory.h" 18 #include "transform/TransformFactory.h"
19 19
20 #include <QVBoxLayout> 20 #include <QGridLayout>
21 #include <QGridLayout> 21 #include <QGridLayout>
22 #include <QLineEdit> 22 #include <QLineEdit>
23 #include <QLabel> 23 #include <QLabel>
24 //#include <SelectableLabel>
24 #include <QDialogButtonBox> 25 #include <QDialogButtonBox>
25 #include <QScrollArea> 26 #include <QScrollArea>
27
28 void
29 SelectableLabel::setUnselectedText(QString text)
30 {
31 setText(text);
32 }
33
34 void
35 SelectableLabel::setSelectedText(QString text)
36 {
37 setText(text);
38 }
39
40 void
41 SelectableLabel::mousePressEvent(QMouseEvent *e)
42 {
43
44 }
26 45
27 TransformFinder::TransformFinder(QWidget *parent) : 46 TransformFinder::TransformFinder(QWidget *parent) :
28 QDialog(parent), 47 QDialog(parent),
29 m_resultsFrame(0), 48 m_resultsFrame(0),
30 m_resultsLayout(0) 49 m_resultsLayout(0)
92 111
93 if (!m_resultsLayout) { 112 if (!m_resultsLayout) {
94 std::cerr << "creating frame & layout" << std::endl; 113 std::cerr << "creating frame & layout" << std::endl;
95 m_resultsFrame = new QWidget; 114 m_resultsFrame = new QWidget;
96 // resultsFrame->setFrameStyle(QFrame::Sunken | QFrame::Box); 115 // resultsFrame->setFrameStyle(QFrame::Sunken | QFrame::Box);
97 m_resultsLayout = new QVBoxLayout; 116 m_resultsLayout = new QGridLayout;
98 m_resultsFrame->setLayout(m_resultsLayout); 117 m_resultsFrame->setLayout(m_resultsLayout);
99 m_resultsScroll->setWidget(m_resultsFrame); 118 m_resultsScroll->setWidget(m_resultsFrame);
100 m_resultsFrame->show(); 119 m_resultsFrame->show();
101 } 120 }
102 121
107 126
108 for (std::set<TransformFactory::Match>::const_iterator j = sorted.end(); 127 for (std::set<TransformFactory::Match>::const_iterator j = sorted.end();
109 j != sorted.begin(); ) { 128 j != sorted.begin(); ) {
110 --j; 129 --j;
111 130
112 QString labelText;
113 TransformDescription desc = 131 TransformDescription desc =
114 TransformFactory::getInstance()->getTransformDescription(j->transform); 132 TransformFactory::getInstance()->getTransformDescription(j->transform);
133
134 QString labelText;
115 labelText += tr("%2<br><small>").arg(desc.name); 135 labelText += tr("%2<br><small>").arg(desc.name);
116 labelText += "..."; 136 labelText += "...";
117 for (TransformFactory::Match::FragmentMap::const_iterator k = 137 for (TransformFactory::Match::FragmentMap::const_iterator k =
118 j->fragments.begin(); 138 j->fragments.begin();
119 k != j->fragments.end(); ++k) { 139 k != j->fragments.end(); ++k) {
120 labelText += k->second; 140 labelText += k->second;
121 labelText += "... "; 141 labelText += "... ";
122 } 142 }
123 labelText += tr("</small>"); 143 labelText += tr("</small>");
124 144
145 QString selectedText;
146 selectedText += tr("<b>%1</b><br>").arg(desc.name);
147 selectedText += tr("<small><i>%1</i></small>").arg(desc.longDescription);
148 /*
149 for (TransformFactory::Match::FragmentMap::const_iterator k =
150 j->fragments.begin();
151 k != j->fragments.end(); ++k) {
152 selectedText += tr("<br><small>%1: %2</small>").arg(k->first).arg(k->second);
153 }
154 */
155
156 selectedText += tr("<br><small>Plugin type: %1</small>").arg(desc.type);
157 selectedText += tr("<br><small>Category: %1</small>").arg(desc.category);
158 selectedText += tr("<br><small>System identifier: %1</small>").arg(desc.identifier);
159
125 if (i >= m_labels.size()) { 160 if (i >= m_labels.size()) {
126 QLabel *label = new QLabel(m_resultsFrame); 161 SelectableLabel *label = new SelectableLabel(m_resultsFrame);
127 label->setTextFormat(Qt::RichText); 162 m_resultsLayout->addWidget(label, i, 0);
128 m_resultsLayout->addWidget(label);
129 m_labels.push_back(label); 163 m_labels.push_back(label);
130 } 164 }
131 m_labels[i]->setText(labelText); 165 m_labels[i]->setUnselectedText(labelText);
166 m_labels[i]->setSelectedText(selectedText);
167
168 /*
132 QSize sh = m_labels[i]->sizeHint(); 169 QSize sh = m_labels[i]->sizeHint();
133 std::cerr << "size hint for text \"" << labelText.toStdString() << "\" has height " << sh.height() << std::endl; 170 std::cerr << "size hint for text \"" << labelText.toStdString() << "\" has height " << sh.height() << std::endl;
134 height += sh.height(); 171 height += sh.height();
135 if (sh.width() > width) width = sh.width(); 172 if (sh.width() > width) width = sh.width();
173 */
174 // m_labels[i]->resize(m_labels[i]->sizeHint());
175 // m_labels[i]->updateGeometry();
136 m_labels[i]->show(); 176 m_labels[i]->show();
137 177
138 if (++i == maxResults) break; 178 if (++i == maxResults) break;
139 } 179 }
140 180
141 std::cerr << "m_labels.size() = " << m_labels.size() << ", i = " << i << ", height = " << height << std::endl; 181 std::cerr << "m_labels.size() = " << m_labels.size() << ", i = " << i << ", height = " << height << std::endl;
142 182
143 while (i < m_labels.size()) m_labels[i++]->hide(); 183 for (int j = m_labels.size(); j > i; ) m_labels[--j]->hide();
144 184
145 m_resultsFrame->resize(height, width); 185 m_resultsFrame->resize(m_resultsFrame->sizeHint());
186 // m_resultsFrame->resize(height, width);
146 } 187 }
147 188
148 TransformId 189 TransformId
149 TransformFinder::getTransform() const 190 TransformFinder::getTransform() const
150 { 191 {