comparison widgets/TransformFinder.cpp @ 417:fbf9f53cf979

* Annoyingly not-really-working twist on things
author Chris Cannam
date Tue, 23 Sep 2008 16:42:43 +0000
parents f4487328320d
children bd1e4ff5091d
comparison
equal deleted inserted replaced
416:f4487328320d 417:fbf9f53cf979
23 #include <QLabel> 23 #include <QLabel>
24 #include <QDialogButtonBox> 24 #include <QDialogButtonBox>
25 #include <QScrollArea> 25 #include <QScrollArea>
26 26
27 TransformFinder::TransformFinder(QWidget *parent) : 27 TransformFinder::TransformFinder(QWidget *parent) :
28 QDialog(parent) 28 QDialog(parent),
29 m_resultsFrame(0),
30 m_resultsLayout(0)
29 { 31 {
30 setWindowTitle(tr("Find a Transform")); 32 setWindowTitle(tr("Find a Transform"));
31 33
32 QGridLayout *mainGrid = new QGridLayout; 34 QGridLayout *mainGrid = new QGridLayout;
33 setLayout(mainGrid); 35 setLayout(mainGrid);
85 << k->second.toStdString() << " "; 87 << k->second.toStdString() << " ";
86 } 88 }
87 std::cerr << "(" << j->score << ")" << std::endl; 89 std::cerr << "(" << j->score << ")" << std::endl;
88 } 90 }
89 */ 91 */
90 QFrame *resultsFrame = new QFrame; 92
91 QVBoxLayout *resultsLayout = new QVBoxLayout; 93 if (!m_resultsLayout) {
92 resultsFrame->setLayout(resultsLayout); 94 std::cerr << "creating frame & layout" << std::endl;
95 m_resultsFrame = new QWidget;
96 // resultsFrame->setFrameStyle(QFrame::Sunken | QFrame::Box);
97 m_resultsLayout = new QVBoxLayout;
98 m_resultsFrame->setLayout(m_resultsLayout);
99 m_resultsScroll->setWidget(m_resultsFrame);
100 m_resultsFrame->show();
101 }
93 102
94 i = 0; 103 i = 0;
95 int maxResults = 40; 104 int maxResults = 40;
105 int height = 0;
106 int width = 0;
96 107
97 for (std::set<TransformFactory::Match>::const_iterator j = sorted.end(); 108 for (std::set<TransformFactory::Match>::const_iterator j = sorted.end();
98 j != sorted.begin(); ) { 109 j != sorted.begin(); ) {
99 --j; 110 --j;
111
100 QString labelText; 112 QString labelText;
101 TransformDescription desc = 113 TransformDescription desc =
102 TransformFactory::getInstance()->getTransformDescription(j->transform); 114 TransformFactory::getInstance()->getTransformDescription(j->transform);
103 labelText += tr("%2<br><small>").arg(desc.name); 115 labelText += tr("%2<br><small>").arg(desc.name);
104 labelText += "..."; 116 labelText += "...";
107 k != j->fragments.end(); ++k) { 119 k != j->fragments.end(); ++k) {
108 labelText += k->second; 120 labelText += k->second;
109 labelText += "... "; 121 labelText += "... ";
110 } 122 }
111 labelText += tr("</small>"); 123 labelText += tr("</small>");
112 resultsLayout->addWidget(new QLabel(labelText)); 124
125 if (i >= m_labels.size()) {
126 QLabel *label = new QLabel(m_resultsFrame);
127 m_resultsLayout->addWidget(label);
128 m_labels.push_back(label);
129 }
130 m_labels[i]->setText(labelText);
131 QSize sh = m_labels[i]->sizeHint();
132 std::cerr << "size hint for text \"" << labelText.toStdString() << "\" has height " << sh.height() << std::endl;
133 height += sh.height();
134 if (sh.width() > width) width = sh.width();
135 m_labels[i]->show();
136
113 if (++i == maxResults) break; 137 if (++i == maxResults) break;
114 } 138 }
115 139
116 QWidget *oldWidget = m_resultsScroll->takeWidget(); 140 std::cerr << "m_labels.size() = " << m_labels.size() << ", i = " << i << ", height = " << height << std::endl;
117 m_resultsScroll->setWidget(resultsFrame); 141
118 delete oldWidget; 142 while (i < m_labels.size()) m_labels[i++]->hide();
143
144 m_resultsFrame->resize(height, width);
119 } 145 }
120 146
121 TransformId 147 TransformId
122 TransformFinder::getTransform() const 148 TransformFinder::getTransform() const
123 { 149 {