ActivityLog.cpp
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2009 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #include "ActivityLog.h"
17 
18 #include <QListView>
19 #include <QGridLayout>
20 #include <QStringListModel>
21 #include <QLabel>
22 #include <QDialogButtonBox>
23 #include <QTime>
24 #include <QApplication>
25 
26 #include <iostream>
27 
28 #include "base/Debug.h"
29 
30 using std::cerr;
31 using std::endl;
32 
33 #ifndef NO_PRINT_ACTIVITY
34 #define PRINT_ACTIVITY 1
35 #endif
36 
38 {
39  setWindowTitle(tr("Activity Log"));
40 
41  QGridLayout *layout = new QGridLayout;
42  setLayout(layout);
43 
44  layout->addWidget(new QLabel(tr("<p>Activity Log lists your interactions and other events within %1.</p>").arg(QApplication::applicationName())), 0, 0);
45 
46  m_listView = new QListView;
47  m_model = new QStringListModel;
48  m_listView->setModel(m_model);
49  layout->addWidget(m_listView, 1, 0);
50  layout->setRowStretch(1, 10);
51 
52  QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
53  connect(bb, SIGNAL(rejected()), this, SLOT(hide()));
54  layout->addWidget(bb, 2, 0);
55 }
56 
58 {
59 }
60 
61 void
63 {
64  name = name.replace("&", "");
65 
66 #ifdef PRINT_ACTIVITY
67  SVDEBUG << "ActivityLog: " << name;
68  if (name == m_prevName) {
69  SVDEBUG << " (duplicate)";
70  }
71  SVDEBUG << endl;
72 #endif
73 
74  if (name == m_prevName) {
75  return;
76  }
77  m_prevName = name;
78  int row = m_model->rowCount();
79  name = tr("%1: %2").arg(QTime::currentTime().toString()).arg(name);
80  m_model->insertRows(row, 1);
81  QModelIndex ix = m_model->index(row, 0);
82  m_model->setData(ix, name);
83  if (isVisible()) m_listView->scrollTo(ix);
84 }
85 
86 void
88 {
89  if (m_model->rowCount() == 0 || !isVisible()) return;
90  QModelIndex ix = m_model->index(m_model->rowCount()-1, 0);
91  m_listView->scrollTo(ix);
92 }
93 
94 
QString m_prevName
Definition: ActivityLog.h:40
QStringListModel * m_model
Definition: ActivityLog.h:39
QListView * m_listView
Definition: ActivityLog.h:38
void scrollToEnd()
Definition: ActivityLog.cpp:87
void activityHappened(QString)
Definition: ActivityLog.cpp:62