annotate widgets/ActivityLog.cpp @ 731:f831ca41d4a5 tonioni

Add selectionChangedByUser for selection changes prompted by interactivity rather than by undo/redo
author Chris Cannam
date Wed, 05 Mar 2014 09:35:32 +0000
parents 1a0dfcbffaf1
children 34c1203d21b5
rev   line source
Chris@502 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@502 2
Chris@502 3 /*
Chris@502 4 Sonic Visualiser
Chris@502 5 An audio file viewer and annotation editor.
Chris@502 6 Centre for Digital Music, Queen Mary, University of London.
Chris@502 7 This file copyright 2009 QMUL.
Chris@502 8
Chris@502 9 This program is free software; you can redistribute it and/or
Chris@502 10 modify it under the terms of the GNU General Public License as
Chris@502 11 published by the Free Software Foundation; either version 2 of the
Chris@502 12 License, or (at your option) any later version. See the file
Chris@502 13 COPYING included with this distribution for more information.
Chris@502 14 */
Chris@502 15
Chris@502 16 #include "ActivityLog.h"
Chris@502 17
Chris@502 18 #include <QListView>
Chris@502 19 #include <QGridLayout>
Chris@502 20 #include <QStringListModel>
Chris@505 21 #include <QLabel>
Chris@505 22 #include <QDialogButtonBox>
Chris@503 23 #include <QTime>
Chris@505 24 #include <QApplication>
Chris@502 25
Chris@502 26 #include <iostream>
Chris@502 27
Chris@502 28 ActivityLog::ActivityLog() : QDialog()
Chris@502 29 {
Chris@505 30 setWindowTitle(tr("Activity Log"));
Chris@505 31
Chris@505 32 QGridLayout *layout = new QGridLayout;
Chris@505 33 setLayout(layout);
Chris@505 34
Chris@506 35 layout->addWidget(new QLabel(tr("<p>Activity Log lists your interactions and other events within %1.</p>").arg(QApplication::applicationName())), 0, 0);
Chris@505 36
Chris@505 37 m_listView = new QListView;
Chris@502 38 m_model = new QStringListModel;
Chris@502 39 m_listView->setModel(m_model);
Chris@505 40 layout->addWidget(m_listView, 1, 0);
Chris@505 41 layout->setRowStretch(1, 10);
Chris@505 42
Chris@505 43 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
Chris@505 44 connect(bb, SIGNAL(rejected()), this, SLOT(hide()));
Chris@505 45 layout->addWidget(bb, 2, 0);
Chris@502 46 }
Chris@502 47
Chris@502 48 ActivityLog::~ActivityLog()
Chris@502 49 {
Chris@502 50 }
Chris@502 51
Chris@502 52 void
Chris@502 53 ActivityLog::activityHappened(QString name)
Chris@502 54 {
Chris@502 55 name = name.replace("&", "");
Chris@587 56 // SVDEBUG << "ActivityLog::activityHappened(" << name << ")" << endl;
Chris@503 57 if (name == m_prevName) {
Chris@682 58 // cerr << "(ignoring duplicate)" << endl;
Chris@503 59 return;
Chris@503 60 }
Chris@503 61 m_prevName = name;
Chris@503 62 int row = m_model->rowCount();
Chris@503 63 name = tr("%1: %2").arg(QTime::currentTime().toString()).arg(name);
Chris@502 64 m_model->insertRows(row, 1);
Chris@503 65 QModelIndex ix = m_model->index(row, 0);
Chris@503 66 m_model->setData(ix, name);
Chris@504 67 if (isVisible()) m_listView->scrollTo(ix);
Chris@502 68 }
Chris@502 69
Chris@505 70 void
Chris@505 71 ActivityLog::scrollToEnd()
Chris@505 72 {
Chris@505 73 if (m_model->rowCount() == 0 || !isVisible()) return;
Chris@505 74 QModelIndex ix = m_model->index(m_model->rowCount()-1, 0);
Chris@505 75 m_listView->scrollTo(ix);
Chris@505 76 }
Chris@505 77
Chris@505 78