annotate widgets/ModelDataTableDialog.cpp @ 392:1d85aa5a49be

* Start adding a spreadsheet-style editor window for model data
author Chris Cannam
date Fri, 06 Jun 2008 15:26:27 +0000
parents
children 6671eb37d6d6
rev   line source
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@392 19
Chris@392 20 #include <QTableView>
Chris@392 21 #include <QGridLayout>
Chris@392 22 #include <QGroupBox>
Chris@392 23 #include <QDialogButtonBox>
Chris@392 24 #include <QHeaderView>
Chris@392 25 #include <QApplication>
Chris@392 26 #include <QDesktopWidget>
Chris@392 27
Chris@392 28 ModelDataTableDialog::ModelDataTableDialog(Model *model, QWidget *parent) :
Chris@392 29 QDialog(parent)
Chris@392 30 {
Chris@392 31 setWindowTitle(tr("Data Editor"));
Chris@392 32
Chris@392 33 QGridLayout *grid = new QGridLayout;
Chris@392 34 setLayout(grid);
Chris@392 35
Chris@392 36 QGroupBox *box = new QGroupBox;
Chris@392 37 box->setTitle(tr("Layer Data"));
Chris@392 38 grid->addWidget(box, 0, 0);
Chris@392 39 grid->setRowStretch(0, 15);
Chris@392 40
Chris@392 41 QGridLayout *subgrid = new QGridLayout;
Chris@392 42 box->setLayout(subgrid);
Chris@392 43
Chris@392 44 subgrid->setSpacing(0);
Chris@392 45 subgrid->setMargin(5);
Chris@392 46
Chris@392 47 m_tableView = new QTableView;
Chris@392 48 subgrid->addWidget(m_tableView);
Chris@392 49
Chris@392 50 m_tableView->verticalHeader()->hide();
Chris@392 51 // m_tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
Chris@392 52 m_tableView->setShowGrid(false);
Chris@392 53
Chris@392 54 m_table = new ModelDataTableModel(model);
Chris@392 55 m_tableView->setModel(m_table);
Chris@392 56
Chris@392 57 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
Chris@392 58 connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
Chris@392 59 grid->addWidget(bb, 2, 0);
Chris@392 60 grid->setRowStretch(2, 0);
Chris@392 61
Chris@392 62 QDesktopWidget *desktop = QApplication::desktop();
Chris@392 63 QRect available = desktop->availableGeometry();
Chris@392 64
Chris@392 65 int width = available.width() / 3;
Chris@392 66 int height = available.height() / 2;
Chris@392 67 if (height < 370) {
Chris@392 68 if (available.height() > 500) height = 370;
Chris@392 69 }
Chris@392 70 if (width < 500) {
Chris@392 71 if (available.width() > 650) width = 500;
Chris@392 72 }
Chris@392 73
Chris@392 74 resize(width, height);
Chris@392 75 }
Chris@392 76
Chris@392 77 ModelDataTableDialog::~ModelDataTableDialog()
Chris@392 78 {
Chris@392 79 delete m_table;
Chris@392 80 }
Chris@392 81