Chris@392: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@392: Chris@392: /* Chris@392: Sonic Visualiser Chris@392: An audio file viewer and annotation editor. Chris@392: Centre for Digital Music, Queen Mary, University of London. Chris@392: This file copyright 2008 QMUL. Chris@392: Chris@392: This program is free software; you can redistribute it and/or Chris@392: modify it under the terms of the GNU General Public License as Chris@392: published by the Free Software Foundation; either version 2 of the Chris@392: License, or (at your option) any later version. See the file Chris@392: COPYING included with this distribution for more information. Chris@392: */ Chris@392: Chris@392: #include "ModelDataTableDialog.h" Chris@392: Chris@392: #include "data/model/ModelDataTableModel.h" Chris@395: #include "data/model/TabularModel.h" Chris@392: Chris@393: #include "CommandHistory.h" Chris@393: Chris@392: #include Chris@392: #include Chris@392: #include Chris@392: #include Chris@392: #include Chris@392: #include Chris@392: #include Chris@392: Chris@393: #include Chris@393: Chris@395: ModelDataTableDialog::ModelDataTableDialog(TabularModel *model, QWidget *parent) : Chris@392: QDialog(parent) Chris@392: { Chris@392: setWindowTitle(tr("Data Editor")); Chris@392: Chris@392: QGridLayout *grid = new QGridLayout; Chris@392: setLayout(grid); Chris@392: Chris@392: QGroupBox *box = new QGroupBox; Chris@392: box->setTitle(tr("Layer Data")); Chris@392: grid->addWidget(box, 0, 0); Chris@392: grid->setRowStretch(0, 15); Chris@392: Chris@392: QGridLayout *subgrid = new QGridLayout; Chris@392: box->setLayout(subgrid); Chris@392: Chris@392: subgrid->setSpacing(0); Chris@392: subgrid->setMargin(5); Chris@392: Chris@392: m_tableView = new QTableView; Chris@392: subgrid->addWidget(m_tableView); Chris@392: Chris@392: m_tableView->verticalHeader()->hide(); Chris@392: // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); Chris@393: // m_tableView->setShowGrid(false); Chris@395: m_tableView->setSortingEnabled(true); Chris@392: Chris@392: m_table = new ModelDataTableModel(model); Chris@392: m_tableView->setModel(m_table); Chris@392: Chris@393: connect(m_tableView, SIGNAL(clicked(const QModelIndex &)), Chris@393: this, SLOT(viewClicked(const QModelIndex &))); Chris@393: connect(m_tableView, SIGNAL(pressed(const QModelIndex &)), Chris@393: this, SLOT(viewPressed(const QModelIndex &))); Chris@393: Chris@392: QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); Chris@392: connect(bb, SIGNAL(rejected()), this, SLOT(reject())); Chris@392: grid->addWidget(bb, 2, 0); Chris@392: grid->setRowStretch(2, 0); Chris@392: Chris@392: QDesktopWidget *desktop = QApplication::desktop(); Chris@392: QRect available = desktop->availableGeometry(); Chris@392: Chris@392: int width = available.width() / 3; Chris@392: int height = available.height() / 2; Chris@392: if (height < 370) { Chris@392: if (available.height() > 500) height = 370; Chris@392: } Chris@392: if (width < 500) { Chris@392: if (available.width() > 650) width = 500; Chris@392: } Chris@392: Chris@392: resize(width, height); Chris@392: } Chris@392: Chris@392: ModelDataTableDialog::~ModelDataTableDialog() Chris@392: { Chris@392: delete m_table; Chris@392: } Chris@392: Chris@393: void Chris@394: ModelDataTableDialog::scrollToFrameRequested(unsigned long frame) Chris@393: { Chris@393: m_tableView->scrollTo(m_table->getModelIndexForFrame(frame)); Chris@393: } Chris@393: Chris@393: void Chris@393: ModelDataTableDialog::viewClicked(const QModelIndex &index) Chris@393: { Chris@393: std::cerr << "ModelDataTableDialog::viewClicked: " << index.row() << ", " << index.column() << std::endl; Chris@394: emit scrollToFrame(m_table->getFrameForModelIndex(index)); Chris@393: } Chris@393: Chris@393: void Chris@393: ModelDataTableDialog::viewPressed(const QModelIndex &index) Chris@393: { Chris@393: std::cerr << "ModelDataTableDialog::viewPressed: " << index.row() << ", " << index.column() << std::endl; Chris@393: } Chris@393: Chris@393: void Chris@393: ModelDataTableDialog::executeCommand(Command *command) Chris@393: { Chris@393: CommandHistory::getInstance()->addCommand(command, true, true); Chris@393: } Chris@393: