svgui
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2009 QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #include "ActivityLog.h" 00017 00018 #include <QListView> 00019 #include <QGridLayout> 00020 #include <QStringListModel> 00021 #include <QLabel> 00022 #include <QDialogButtonBox> 00023 #include <QTime> 00024 #include <QApplication> 00025 00026 #include <iostream> 00027 00028 #include "base/Debug.h" 00029 00030 using std::cerr; 00031 using std::endl; 00032 00033 //#define PRINT_ACTIVITY 1 00034 00035 ActivityLog::ActivityLog() : QDialog() 00036 { 00037 setWindowTitle(tr("Activity Log")); 00038 00039 QGridLayout *layout = new QGridLayout; 00040 setLayout(layout); 00041 00042 layout->addWidget(new QLabel(tr("<p>Activity Log lists your interactions and other events within %1.</p>").arg(QApplication::applicationName())), 0, 0); 00043 00044 m_listView = new QListView; 00045 m_model = new QStringListModel; 00046 m_listView->setModel(m_model); 00047 layout->addWidget(m_listView, 1, 0); 00048 layout->setRowStretch(1, 10); 00049 00050 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); 00051 connect(bb, SIGNAL(rejected()), this, SLOT(hide())); 00052 layout->addWidget(bb, 2, 0); 00053 } 00054 00055 ActivityLog::~ActivityLog() 00056 { 00057 } 00058 00059 void 00060 ActivityLog::activityHappened(QString name) 00061 { 00062 name = name.replace("&", ""); 00063 00064 #ifdef PRINT_ACTIVITY 00065 cerr << "ActivityLog: " << name; 00066 if (name == m_prevName) { 00067 cerr << " (duplicate)"; 00068 } 00069 cerr << endl; 00070 #endif 00071 00072 if (name == m_prevName) { 00073 return; 00074 } 00075 m_prevName = name; 00076 int row = m_model->rowCount(); 00077 name = tr("%1: %2").arg(QTime::currentTime().toString()).arg(name); 00078 m_model->insertRows(row, 1); 00079 QModelIndex ix = m_model->index(row, 0); 00080 m_model->setData(ix, name); 00081 if (isVisible()) m_listView->scrollTo(ix); 00082 } 00083 00084 void 00085 ActivityLog::scrollToEnd() 00086 { 00087 if (m_model->rowCount() == 0 || !isVisible()) return; 00088 QModelIndex ix = m_model->index(m_model->rowCount()-1, 0); 00089 m_listView->scrollTo(ix); 00090 } 00091 00092