Chris@336: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@336: 
Chris@336: /*
Chris@336:     Sonic Visualiser
Chris@336:     An audio file viewer and annotation editor.
Chris@336:     Centre for Digital Music, Queen Mary, University of London.
Chris@336:     This file copyright 2007 QMUL.
Chris@336:     
Chris@336:     This program is free software; you can redistribute it and/or
Chris@336:     modify it under the terms of the GNU General Public License as
Chris@336:     published by the Free Software Foundation; either version 2 of the
Chris@336:     License, or (at your option) any later version.  See the file
Chris@336:     COPYING included with this distribution for more information.
Chris@336: */
Chris@336: 
Chris@336: #include "LayerTreeDialog.h"
Chris@336: 
Chris@336: #include "LayerTree.h"
Chris@336: #include "view/PaneStack.h"
Chris@336: 
Chris@336: #include <QTreeView>
Chris@336: #include <QTableView>
Chris@336: #include <QGridLayout>
Chris@336: #include <QGroupBox>
Chris@336: #include <QDialogButtonBox>
Chris@336: #include <QHeaderView>
Chris@336: #include <QApplication>
Chris@336: #include <QDesktopWidget>
Chris@336: 
Chris@336: LayerTreeDialog::LayerTreeDialog(PaneStack *stack, QWidget *parent) :
Chris@336:     QDialog(parent),
Chris@336:     m_paneStack(stack)
Chris@336: {
Chris@336:     setWindowTitle(tr("Layer Summary"));
Chris@336: 
Chris@336:     QGridLayout *grid = new QGridLayout;
Chris@336:     setLayout(grid);
Chris@336:     
Chris@336:     QGroupBox *modelBox = new QGroupBox;
Chris@336:     modelBox->setTitle(tr("Audio Data Sources"));
Chris@336:     grid->addWidget(modelBox, 0, 0);
Chris@336:     grid->setRowStretch(0, 15);
Chris@336: 
Chris@336:     QGridLayout *subgrid = new QGridLayout;
Chris@336:     modelBox->setLayout(subgrid);
Chris@336: 
Chris@336:     subgrid->setSpacing(0);
Chris@336:     subgrid->setMargin(5);
Chris@336: 
Chris@336:     m_modelView = new QTableView;
Chris@336:     subgrid->addWidget(m_modelView);
Chris@336: 
Chris@336:     m_modelView->verticalHeader()->hide();
Chris@639: #if (QT_VERSION >= 0x050000)
Chris@616:     m_modelView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
Chris@639: #else
Chris@639:     m_modelView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
Chris@639: #endif
Chris@336:     m_modelView->setShowGrid(false);
Chris@336: 
Chris@392:     m_modelModel = new ModelMetadataModel(m_paneStack, true);
Chris@336:     m_modelView->setModel(m_modelModel);
Chris@336: 
Chris@336:     QGroupBox *layerBox = new QGroupBox;
Chris@336:     layerBox->setTitle(tr("Panes and Layers"));
Chris@336:     grid->addWidget(layerBox, 1, 0);
Chris@336:     grid->setRowStretch(1, 20);
Chris@336: 
Chris@336:     subgrid = new QGridLayout;
Chris@336:     layerBox->setLayout(subgrid);
Chris@336: 
Chris@336:     subgrid->setSpacing(0);
Chris@336:     subgrid->setMargin(5);
Chris@336: 
Chris@336:     m_layerView = new QTreeView;
Chris@639: #if (QT_VERSION >= 0x050000)
Chris@616:     m_layerView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
Chris@639: #else
Chris@639:     m_layerView->header()->setResizeMode(QHeaderView::ResizeToContents);
Chris@639: #endif
Chris@336:     subgrid->addWidget(m_layerView);
Chris@336: 
Chris@336:     m_layerModel = new LayerTreeModel(m_paneStack);
Chris@336:     m_layerView->setModel(m_layerModel);
Chris@336:     m_layerView->expandAll();
Chris@336: 
Chris@336:     QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
Chris@336:     connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
Chris@336:     grid->addWidget(bb, 2, 0);
Chris@336:     grid->setRowStretch(2, 0);
Chris@336:     
Chris@336:     QDesktopWidget *desktop = QApplication::desktop();
Chris@336:     QRect available = desktop->availableGeometry();
Chris@336: 
Chris@336:     int width = available.width() / 2;
Chris@336:     int height = available.height() / 3;
Chris@336:     if (height < 370) {
Chris@336:         if (available.height() > 500) height = 370;
Chris@336:     }
Chris@336:     if (width < 500) {
Chris@336:         if (available.width() > 650) width = 500;
Chris@336:     }
Chris@336: 
Chris@336:     resize(width, height);
Chris@336: }
Chris@336: 
Chris@336: LayerTreeDialog::~LayerTreeDialog()
Chris@336: {
Chris@336:     delete m_layerModel;
Chris@336: }
Chris@336: