# HG changeset patch # User Chris Cannam # Date 1222188163 0 # Node ID fbf9f53cf9797a82bbc97a4a7e5afa5b346b2d91 # Parent f4487328320da65a865a1de63ef62fa7e06a15f0 * Annoyingly not-really-working twist on things diff -r f4487328320d -r fbf9f53cf979 widgets/TransformFinder.cpp --- a/widgets/TransformFinder.cpp Tue Sep 23 13:39:25 2008 +0000 +++ b/widgets/TransformFinder.cpp Tue Sep 23 16:42:43 2008 +0000 @@ -25,7 +25,9 @@ #include TransformFinder::TransformFinder(QWidget *parent) : - QDialog(parent) + QDialog(parent), + m_resultsFrame(0), + m_resultsLayout(0) { setWindowTitle(tr("Find a Transform")); @@ -87,16 +89,26 @@ std::cerr << "(" << j->score << ")" << std::endl; } */ - QFrame *resultsFrame = new QFrame; - QVBoxLayout *resultsLayout = new QVBoxLayout; - resultsFrame->setLayout(resultsLayout); + + if (!m_resultsLayout) { + std::cerr << "creating frame & layout" << std::endl; + m_resultsFrame = new QWidget; +// resultsFrame->setFrameStyle(QFrame::Sunken | QFrame::Box); + m_resultsLayout = new QVBoxLayout; + m_resultsFrame->setLayout(m_resultsLayout); + m_resultsScroll->setWidget(m_resultsFrame); + m_resultsFrame->show(); + } i = 0; int maxResults = 40; + int height = 0; + int width = 0; for (std::set::const_iterator j = sorted.end(); j != sorted.begin(); ) { --j; + QString labelText; TransformDescription desc = TransformFactory::getInstance()->getTransformDescription(j->transform); @@ -109,13 +121,27 @@ labelText += "... "; } labelText += tr(""); - resultsLayout->addWidget(new QLabel(labelText)); + + if (i >= m_labels.size()) { + QLabel *label = new QLabel(m_resultsFrame); + m_resultsLayout->addWidget(label); + m_labels.push_back(label); + } + m_labels[i]->setText(labelText); + QSize sh = m_labels[i]->sizeHint(); + std::cerr << "size hint for text \"" << labelText.toStdString() << "\" has height " << sh.height() << std::endl; + height += sh.height(); + if (sh.width() > width) width = sh.width(); + m_labels[i]->show(); + if (++i == maxResults) break; } - QWidget *oldWidget = m_resultsScroll->takeWidget(); - m_resultsScroll->setWidget(resultsFrame); - delete oldWidget; + std::cerr << "m_labels.size() = " << m_labels.size() << ", i = " << i << ", height = " << height << std::endl; + + while (i < m_labels.size()) m_labels[i++]->hide(); + + m_resultsFrame->resize(height, width); } TransformId diff -r f4487328320d -r fbf9f53cf979 widgets/TransformFinder.h --- a/widgets/TransformFinder.h Tue Sep 23 13:39:25 2008 +0000 +++ b/widgets/TransformFinder.h Tue Sep 23 16:42:43 2008 +0000 @@ -18,10 +18,14 @@ #include +#include + #include "transform/Transform.h" class QVBoxLayout; class QScrollArea; +class QLabel; +class QWidget; class TransformFinder : public QDialog { @@ -38,7 +42,9 @@ protected: QScrollArea *m_resultsScroll; + QWidget *m_resultsFrame; QVBoxLayout *m_resultsLayout; + std::vector m_labels; }; #endif