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@396
|
34 QMainWindow(parent)
|
Chris@392
|
35 {
|
Chris@392
|
36 setWindowTitle(tr("Data Editor"));
|
Chris@392
|
37
|
Chris@396
|
38 QToolBar *toolbar = addToolBar(tr("Toolbar"));
|
Chris@396
|
39 CommandHistory::getInstance()->registerToolbar(toolbar);
|
Chris@396
|
40
|
Chris@396
|
41 QFrame *mainFrame = new QFrame;
|
Chris@396
|
42 setCentralWidget(mainFrame);
|
Chris@396
|
43
|
Chris@392
|
44 QGridLayout *grid = new QGridLayout;
|
Chris@396
|
45 mainFrame->setLayout(grid);
|
Chris@392
|
46
|
Chris@392
|
47 QGroupBox *box = new QGroupBox;
|
Chris@392
|
48 box->setTitle(tr("Layer Data"));
|
Chris@392
|
49 grid->addWidget(box, 0, 0);
|
Chris@392
|
50 grid->setRowStretch(0, 15);
|
Chris@392
|
51
|
Chris@392
|
52 QGridLayout *subgrid = new QGridLayout;
|
Chris@392
|
53 box->setLayout(subgrid);
|
Chris@392
|
54
|
Chris@392
|
55 subgrid->setSpacing(0);
|
Chris@392
|
56 subgrid->setMargin(5);
|
Chris@392
|
57
|
Chris@392
|
58 m_tableView = new QTableView;
|
Chris@392
|
59 subgrid->addWidget(m_tableView);
|
Chris@392
|
60
|
Chris@392
|
61 m_tableView->verticalHeader()->hide();
|
Chris@392
|
62 // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
Chris@395
|
63 m_tableView->setSortingEnabled(true);
|
Chris@396
|
64 m_tableView->sortByColumn(0, Qt::AscendingOrder);
|
Chris@392
|
65
|
Chris@392
|
66 m_table = new ModelDataTableModel(model);
|
Chris@392
|
67 m_tableView->setModel(m_table);
|
Chris@392
|
68
|
Chris@393
|
69 connect(m_tableView, SIGNAL(clicked(const QModelIndex &)),
|
Chris@393
|
70 this, SLOT(viewClicked(const QModelIndex &)));
|
Chris@393
|
71 connect(m_tableView, SIGNAL(pressed(const QModelIndex &)),
|
Chris@393
|
72 this, SLOT(viewPressed(const QModelIndex &)));
|
Chris@393
|
73
|
Chris@392
|
74 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
|
Chris@396
|
75 connect(bb, SIGNAL(rejected()), this, SLOT(close()));
|
Chris@392
|
76 grid->addWidget(bb, 2, 0);
|
Chris@392
|
77 grid->setRowStretch(2, 0);
|
Chris@392
|
78
|
Chris@392
|
79 QDesktopWidget *desktop = QApplication::desktop();
|
Chris@392
|
80 QRect available = desktop->availableGeometry();
|
Chris@392
|
81
|
Chris@392
|
82 int width = available.width() / 3;
|
Chris@392
|
83 int height = available.height() / 2;
|
Chris@392
|
84 if (height < 370) {
|
Chris@392
|
85 if (available.height() > 500) height = 370;
|
Chris@392
|
86 }
|
Chris@392
|
87 if (width < 500) {
|
Chris@392
|
88 if (available.width() > 650) width = 500;
|
Chris@392
|
89 }
|
Chris@392
|
90
|
Chris@392
|
91 resize(width, height);
|
Chris@392
|
92 }
|
Chris@392
|
93
|
Chris@392
|
94 ModelDataTableDialog::~ModelDataTableDialog()
|
Chris@392
|
95 {
|
Chris@392
|
96 delete m_table;
|
Chris@392
|
97 }
|
Chris@392
|
98
|
Chris@393
|
99 void
|
Chris@394
|
100 ModelDataTableDialog::scrollToFrameRequested(unsigned long frame)
|
Chris@393
|
101 {
|
Chris@393
|
102 m_tableView->scrollTo(m_table->getModelIndexForFrame(frame));
|
Chris@393
|
103 }
|
Chris@393
|
104
|
Chris@393
|
105 void
|
Chris@393
|
106 ModelDataTableDialog::viewClicked(const QModelIndex &index)
|
Chris@393
|
107 {
|
Chris@393
|
108 std::cerr << "ModelDataTableDialog::viewClicked: " << index.row() << ", " << index.column() << std::endl;
|
Chris@394
|
109 emit scrollToFrame(m_table->getFrameForModelIndex(index));
|
Chris@393
|
110 }
|
Chris@393
|
111
|
Chris@393
|
112 void
|
Chris@393
|
113 ModelDataTableDialog::viewPressed(const QModelIndex &index)
|
Chris@393
|
114 {
|
Chris@393
|
115 std::cerr << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << std::endl;
|
Chris@393
|
116 }
|
Chris@393
|
117
|
Chris@393
|
118 void
|
Chris@393
|
119 ModelDataTableDialog::executeCommand(Command *command)
|
Chris@393
|
120 {
|
Chris@393
|
121 CommandHistory::getInstance()->addCommand(command, true, true);
|
Chris@393
|
122 }
|
Chris@393
|
123
|