Chris@502: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@502: Chris@502: /* Chris@502: Sonic Visualiser Chris@502: An audio file viewer and annotation editor. Chris@502: Centre for Digital Music, Queen Mary, University of London. Chris@502: This file copyright 2009 QMUL. Chris@502: Chris@502: This program is free software; you can redistribute it and/or Chris@502: modify it under the terms of the GNU General Public License as Chris@502: published by the Free Software Foundation; either version 2 of the Chris@502: License, or (at your option) any later version. See the file Chris@502: COPYING included with this distribution for more information. Chris@502: */ Chris@502: Chris@502: #include "ActivityLog.h" Chris@502: Chris@502: #include Chris@502: #include Chris@502: #include Chris@505: #include Chris@505: #include Chris@503: #include Chris@505: #include Chris@502: Chris@502: #include Chris@502: Chris@502: ActivityLog::ActivityLog() : QDialog() Chris@502: { Chris@505: setWindowTitle(tr("Activity Log")); Chris@505: Chris@505: QGridLayout *layout = new QGridLayout; Chris@505: setLayout(layout); Chris@505: Chris@506: layout->addWidget(new QLabel(tr("

Activity Log lists your interactions and other events within %1.

").arg(QApplication::applicationName())), 0, 0); Chris@505: Chris@505: m_listView = new QListView; Chris@502: m_model = new QStringListModel; Chris@502: m_listView->setModel(m_model); Chris@505: layout->addWidget(m_listView, 1, 0); Chris@505: layout->setRowStretch(1, 10); Chris@505: Chris@505: QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); Chris@505: connect(bb, SIGNAL(rejected()), this, SLOT(hide())); Chris@505: layout->addWidget(bb, 2, 0); Chris@502: } Chris@502: Chris@502: ActivityLog::~ActivityLog() Chris@502: { Chris@502: } Chris@502: Chris@502: void Chris@502: ActivityLog::activityHappened(QString name) Chris@502: { Chris@502: name = name.replace("&", ""); Chris@585: // DEBUG << "ActivityLog::activityHappened(" << name << ")" << endl; Chris@503: if (name == m_prevName) { Chris@524: // std::cerr << "(ignoring duplicate)" << std::endl; Chris@503: return; Chris@503: } Chris@503: m_prevName = name; Chris@503: int row = m_model->rowCount(); Chris@503: name = tr("%1: %2").arg(QTime::currentTime().toString()).arg(name); Chris@502: m_model->insertRows(row, 1); Chris@503: QModelIndex ix = m_model->index(row, 0); Chris@503: m_model->setData(ix, name); Chris@504: if (isVisible()) m_listView->scrollTo(ix); Chris@502: } Chris@502: Chris@505: void Chris@505: ActivityLog::scrollToEnd() Chris@505: { Chris@505: if (m_model->rowCount() == 0 || !isVisible()) return; Chris@505: QModelIndex ix = m_model->index(m_model->rowCount()-1, 0); Chris@505: m_listView->scrollTo(ix); Chris@505: } Chris@505: Chris@505: