changeset 416:f4487328320d

* Start work on TransformFinder dialog
author Chris Cannam
date Tue, 23 Sep 2008 13:39:25 +0000
parents 31f222929319
children fbf9f53cf979
files widgets/TransformFinder.cpp widgets/TransformFinder.h widgets/widgets.pro
diffstat 3 files changed, 173 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/TransformFinder.cpp	Tue Sep 23 13:39:25 2008 +0000
@@ -0,0 +1,126 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2008 QMUL.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#include "TransformFinder.h"
+
+#include "transform/TransformFactory.h"
+
+#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QLineEdit>
+#include <QLabel>
+#include <QDialogButtonBox>
+#include <QScrollArea>
+
+TransformFinder::TransformFinder(QWidget *parent) :
+    QDialog(parent)
+{
+    setWindowTitle(tr("Find a Transform"));
+    
+    QGridLayout *mainGrid = new QGridLayout;
+    setLayout(mainGrid);
+
+    mainGrid->addWidget(new QLabel(tr("Find:")), 0, 0);
+    
+    QLineEdit *searchField = new QLineEdit;
+    mainGrid->addWidget(searchField, 0, 1);
+    connect(searchField, SIGNAL(textChanged(const QString &)),
+            this, SLOT(searchTextChanged(const QString &)));
+
+    m_resultsScroll = new QScrollArea;
+    mainGrid->addWidget(m_resultsScroll, 1, 0, 1, 2);
+    mainGrid->setRowStretch(1, 10);
+
+    QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
+                                                QDialogButtonBox::Cancel);
+    mainGrid->addWidget(bb, 2, 0, 1, 2);
+    connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
+    connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
+
+    resize(500, 400); //!!!
+}
+
+TransformFinder::~TransformFinder()
+{
+}
+
+void
+TransformFinder::searchTextChanged(const QString &text)
+{
+    std::cerr << "text is " << text.toStdString() << std::endl;
+
+    QStringList keywords = text.split(' ', QString::SkipEmptyParts);
+    TransformFactory::SearchResults results =
+        TransformFactory::getInstance()->search(keywords);
+    
+    std::cerr << results.size() << " result(s)..." << std::endl;
+
+    std::set<TransformFactory::Match> sorted;
+    for (TransformFactory::SearchResults::const_iterator j = results.begin();
+         j != results.end(); ++j) {
+        sorted.insert(j->second);
+    }
+
+    int i = 0;
+/*
+    for (std::set<TransformFactory::Match>::const_iterator j = sorted.begin();
+         j != sorted.end(); ++j) {
+        std::cerr << i++ << ": " << j->transform.toStdString() << ": ";
+        for (TransformFactory::Match::FragmentMap::const_iterator k =
+                 j->fragments.begin();
+             k != j->fragments.end(); ++k) {
+            std::cerr << k->first.toStdString() << ": "
+                      << k->second.toStdString() << " ";
+        }
+        std::cerr << "(" << j->score << ")" << std::endl;
+    }
+*/
+    QFrame *resultsFrame = new QFrame;
+    QVBoxLayout *resultsLayout = new QVBoxLayout;
+    resultsFrame->setLayout(resultsLayout);
+
+    i = 0;
+    int maxResults = 40;
+
+    for (std::set<TransformFactory::Match>::const_iterator j = sorted.end();
+         j != sorted.begin(); ) {
+        --j;
+        QString labelText;
+        TransformDescription desc =
+            TransformFactory::getInstance()->getTransformDescription(j->transform);
+        labelText += tr("%2<br><small>").arg(desc.name);
+        labelText += "...";
+        for (TransformFactory::Match::FragmentMap::const_iterator k =
+                 j->fragments.begin();
+             k != j->fragments.end(); ++k) {
+            labelText += k->second;
+            labelText += "... ";
+        }
+        labelText += tr("</small>");
+        resultsLayout->addWidget(new QLabel(labelText));
+        if (++i == maxResults) break;
+    }
+
+    QWidget *oldWidget = m_resultsScroll->takeWidget();
+    m_resultsScroll->setWidget(resultsFrame);
+    delete oldWidget;
+}
+
+TransformId
+TransformFinder::getTransform() const
+{
+    return "";
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/widgets/TransformFinder.h	Tue Sep 23 13:39:25 2008 +0000
@@ -0,0 +1,45 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2008 QMUL.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef _TRANSFORM_FINDER_H_
+#define _TRANSFORM_FINDER_H_
+
+#include <QDialog>
+
+#include "transform/Transform.h"
+
+class QVBoxLayout;
+class QScrollArea;
+
+class TransformFinder : public QDialog
+{
+    Q_OBJECT
+
+public:
+    TransformFinder(QWidget *parent = 0);
+    ~TransformFinder();
+
+    TransformId getTransform() const;
+
+protected slots:
+    void searchTextChanged(const QString &);
+    
+protected:
+    QScrollArea *m_resultsScroll;
+    QVBoxLayout *m_resultsLayout;
+};
+
+#endif
+
--- a/widgets/widgets.pro	Mon Sep 22 15:44:03 2008 +0000
+++ b/widgets/widgets.pro	Tue Sep 23 13:39:25 2008 +0000
@@ -46,6 +46,7 @@
            TextAbbrev.h \
            Thumbwheel.h \
            TipDialog.h \
+           TransformFinder.h \
            WindowShapePreview.h \
            WindowTypeSelector.h
 SOURCES += AudioDial.cpp \
@@ -80,5 +81,6 @@
            TextAbbrev.cpp \
            Thumbwheel.cpp \
            TipDialog.cpp \
+           TransformFinder.cpp \
            WindowShapePreview.cpp \
            WindowTypeSelector.cpp