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@751
|
28 #include "base/Debug.h"
|
Chris@751
|
29
|
Chris@751
|
30 using std::cerr;
|
Chris@751
|
31 using std::endl;
|
Chris@751
|
32
|
Chris@863
|
33 //#define PRINT_ACTIVITY 1
|
Chris@751
|
34
|
Chris@502
|
35 ActivityLog::ActivityLog() : QDialog()
|
Chris@502
|
36 {
|
Chris@505
|
37 setWindowTitle(tr("Activity Log"));
|
Chris@505
|
38
|
Chris@505
|
39 QGridLayout *layout = new QGridLayout;
|
Chris@505
|
40 setLayout(layout);
|
Chris@505
|
41
|
Chris@506
|
42 layout->addWidget(new QLabel(tr("<p>Activity Log lists your interactions and other events within %1.</p>").arg(QApplication::applicationName())), 0, 0);
|
Chris@505
|
43
|
Chris@505
|
44 m_listView = new QListView;
|
Chris@502
|
45 m_model = new QStringListModel;
|
Chris@502
|
46 m_listView->setModel(m_model);
|
Chris@505
|
47 layout->addWidget(m_listView, 1, 0);
|
Chris@505
|
48 layout->setRowStretch(1, 10);
|
Chris@505
|
49
|
Chris@505
|
50 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
|
Chris@505
|
51 connect(bb, SIGNAL(rejected()), this, SLOT(hide()));
|
Chris@505
|
52 layout->addWidget(bb, 2, 0);
|
Chris@502
|
53 }
|
Chris@502
|
54
|
Chris@502
|
55 ActivityLog::~ActivityLog()
|
Chris@502
|
56 {
|
Chris@502
|
57 }
|
Chris@502
|
58
|
Chris@502
|
59 void
|
Chris@502
|
60 ActivityLog::activityHappened(QString name)
|
Chris@502
|
61 {
|
Chris@502
|
62 name = name.replace("&", "");
|
Chris@751
|
63
|
Chris@751
|
64 #ifdef PRINT_ACTIVITY
|
Chris@751
|
65 cerr << "ActivityLog: " << name;
|
Chris@503
|
66 if (name == m_prevName) {
|
Chris@751
|
67 cerr << " (duplicate)";
|
Chris@751
|
68 }
|
Chris@751
|
69 cerr << endl;
|
Chris@751
|
70 #endif
|
Chris@751
|
71
|
Chris@751
|
72 if (name == m_prevName) {
|
Chris@503
|
73 return;
|
Chris@503
|
74 }
|
Chris@503
|
75 m_prevName = name;
|
Chris@503
|
76 int row = m_model->rowCount();
|
Chris@503
|
77 name = tr("%1: %2").arg(QTime::currentTime().toString()).arg(name);
|
Chris@502
|
78 m_model->insertRows(row, 1);
|
Chris@503
|
79 QModelIndex ix = m_model->index(row, 0);
|
Chris@503
|
80 m_model->setData(ix, name);
|
Chris@504
|
81 if (isVisible()) m_listView->scrollTo(ix);
|
Chris@502
|
82 }
|
Chris@502
|
83
|
Chris@505
|
84 void
|
Chris@505
|
85 ActivityLog::scrollToEnd()
|
Chris@505
|
86 {
|
Chris@505
|
87 if (m_model->rowCount() == 0 || !isVisible()) return;
|
Chris@505
|
88 QModelIndex ix = m_model->index(m_model->rowCount()-1, 0);
|
Chris@505
|
89 m_listView->scrollTo(ix);
|
Chris@505
|
90 }
|
Chris@505
|
91
|
Chris@505
|
92
|