Chris@392
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@392
|
2
|
Chris@392
|
3 /*
|
Chris@392
|
4 Sonic Visualiser
|
Chris@392
|
5 An audio file viewer and annotation editor.
|
Chris@392
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@392
|
7 This file copyright 2008 QMUL.
|
Chris@392
|
8
|
Chris@392
|
9 This program is free software; you can redistribute it and/or
|
Chris@392
|
10 modify it under the terms of the GNU General Public License as
|
Chris@392
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@392
|
12 License, or (at your option) any later version. See the file
|
Chris@392
|
13 COPYING included with this distribution for more information.
|
Chris@392
|
14 */
|
Chris@392
|
15
|
Chris@392
|
16 #include "ModelDataTableDialog.h"
|
Chris@392
|
17
|
Chris@392
|
18 #include "data/model/ModelDataTableModel.h"
|
Chris@395
|
19 #include "data/model/TabularModel.h"
|
Chris@392
|
20
|
Chris@393
|
21 #include "CommandHistory.h"
|
Chris@393
|
22
|
Chris@392
|
23 #include <QTableView>
|
Chris@392
|
24 #include <QGridLayout>
|
Chris@392
|
25 #include <QGroupBox>
|
Chris@392
|
26 #include <QDialogButtonBox>
|
Chris@392
|
27 #include <QHeaderView>
|
Chris@392
|
28 #include <QApplication>
|
Chris@392
|
29 #include <QDesktopWidget>
|
Chris@392
|
30
|
Chris@393
|
31 #include <iostream>
|
Chris@393
|
32
|
Chris@395
|
33 ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QWidget *parent) :
|
Chris@392
|
34 QDialog(parent)
|
Chris@392
|
35 {
|
Chris@392
|
36 setWindowTitle(tr("Data Editor"));
|
Chris@392
|
37
|
Chris@392
|
38 QGridLayout *grid = new QGridLayout;
|
Chris@392
|
39 setLayout(grid);
|
Chris@392
|
40
|
Chris@392
|
41 QGroupBox *box = new QGroupBox;
|
Chris@392
|
42 box->setTitle(tr("Layer Data"));
|
Chris@392
|
43 grid->addWidget(box, 0, 0);
|
Chris@392
|
44 grid->setRowStretch(0, 15);
|
Chris@392
|
45
|
Chris@392
|
46 QGridLayout *subgrid = new QGridLayout;
|
Chris@392
|
47 box->setLayout(subgrid);
|
Chris@392
|
48
|
Chris@392
|
49 subgrid->setSpacing(0);
|
Chris@392
|
50 subgrid->setMargin(5);
|
Chris@392
|
51
|
Chris@392
|
52 m_tableView = new QTableView;
|
Chris@392
|
53 subgrid->addWidget(m_tableView);
|
Chris@392
|
54
|
Chris@392
|
55 m_tableView->verticalHeader()->hide();
|
Chris@392
|
56 // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
Chris@393
|
57 // m_tableView->setShowGrid(false);
|
Chris@395
|
58 m_tableView->setSortingEnabled(true);
|
Chris@392
|
59
|
Chris@392
|
60 m_table = new ModelDataTableModel(model);
|
Chris@392
|
61 m_tableView->setModel(m_table);
|
Chris@392
|
62
|
Chris@393
|
63 connect(m_tableView, SIGNAL(clicked(const QModelIndex &)),
|
Chris@393
|
64 this, SLOT(viewClicked(const QModelIndex &)));
|
Chris@393
|
65 connect(m_tableView, SIGNAL(pressed(const QModelIndex &)),
|
Chris@393
|
66 this, SLOT(viewPressed(const QModelIndex &)));
|
Chris@393
|
67
|
Chris@392
|
68 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
|
Chris@392
|
69 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
|
Chris@392
|
70 grid->addWidget(bb, 2, 0);
|
Chris@392
|
71 grid->setRowStretch(2, 0);
|
Chris@392
|
72
|
Chris@392
|
73 QDesktopWidget *desktop = QApplication::desktop();
|
Chris@392
|
74 QRect available = desktop->availableGeometry();
|
Chris@392
|
75
|
Chris@392
|
76 int width = available.width() / 3;
|
Chris@392
|
77 int height = available.height() / 2;
|
Chris@392
|
78 if (height < 370) {
|
Chris@392
|
79 if (available.height() > 500) height = 370;
|
Chris@392
|
80 }
|
Chris@392
|
81 if (width < 500) {
|
Chris@392
|
82 if (available.width() > 650) width = 500;
|
Chris@392
|
83 }
|
Chris@392
|
84
|
Chris@392
|
85 resize(width, height);
|
Chris@392
|
86 }
|
Chris@392
|
87
|
Chris@392
|
88 ModelDataTableDialog::~ModelDataTableDialog()
|
Chris@392
|
89 {
|
Chris@392
|
90 delete m_table;
|
Chris@392
|
91 }
|
Chris@392
|
92
|
Chris@393
|
93 void
|
Chris@394
|
94 ModelDataTableDialog::scrollToFrameRequested(unsigned long frame)
|
Chris@393
|
95 {
|
Chris@393
|
96 m_tableView->scrollTo(m_table->getModelIndexForFrame(frame));
|
Chris@393
|
97 }
|
Chris@393
|
98
|
Chris@393
|
99 void
|
Chris@393
|
100 ModelDataTableDialog::viewClicked(const QModelIndex &index)
|
Chris@393
|
101 {
|
Chris@393
|
102 std::cerr << "ModelDataTableDialog::viewClicked: " << index.row() << ", " << index.column() << std::endl;
|
Chris@394
|
103 emit scrollToFrame(m_table->getFrameForModelIndex(index));
|
Chris@393
|
104 }
|
Chris@393
|
105
|
Chris@393
|
106 void
|
Chris@393
|
107 ModelDataTableDialog::viewPressed(const QModelIndex &index)
|
Chris@393
|
108 {
|
Chris@393
|
109 std::cerr << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << std::endl;
|
Chris@393
|
110 }
|
Chris@393
|
111
|
Chris@393
|
112 void
|
Chris@393
|
113 ModelDataTableDialog::executeCommand(Command *command)
|
Chris@393
|
114 {
|
Chris@393
|
115 CommandHistory::getInstance()->addCommand(command, true, true);
|
Chris@393
|
116 }
|
Chris@393
|
117
|