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