svgui  1.9
LayerTreeDialog.cpp
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2007 QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #include "LayerTreeDialog.h"
00017 
00018 #include "LayerTree.h"
00019 #include "view/PaneStack.h"
00020 
00021 #include <QTreeView>
00022 #include <QTableView>
00023 #include <QGridLayout>
00024 #include <QGroupBox>
00025 #include <QDialogButtonBox>
00026 #include <QHeaderView>
00027 #include <QApplication>
00028 #include <QDesktopWidget>
00029 
00030 LayerTreeDialog::LayerTreeDialog(PaneStack *stack, QWidget *parent) :
00031     QDialog(parent),
00032     m_paneStack(stack)
00033 {
00034     setWindowTitle(tr("Layer Summary"));
00035 
00036     QGridLayout *grid = new QGridLayout;
00037     setLayout(grid);
00038     
00039     QGroupBox *modelBox = new QGroupBox;
00040     modelBox->setTitle(tr("Audio Data Sources"));
00041     grid->addWidget(modelBox, 0, 0);
00042     grid->setRowStretch(0, 15);
00043 
00044     QGridLayout *subgrid = new QGridLayout;
00045     modelBox->setLayout(subgrid);
00046 
00047     subgrid->setSpacing(0);
00048     subgrid->setMargin(5);
00049 
00050     m_modelView = new QTableView;
00051     subgrid->addWidget(m_modelView);
00052 
00053     m_modelView->verticalHeader()->hide();
00054 #if (QT_VERSION >= 0x050000)
00055     m_modelView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
00056 #else
00057     m_modelView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
00058 #endif
00059     m_modelView->setShowGrid(false);
00060 
00061     m_modelModel = new ModelMetadataModel(m_paneStack, true);
00062     m_modelView->setModel(m_modelModel);
00063 
00064     QGroupBox *layerBox = new QGroupBox;
00065     layerBox->setTitle(tr("Panes and Layers"));
00066     grid->addWidget(layerBox, 1, 0);
00067     grid->setRowStretch(1, 20);
00068 
00069     subgrid = new QGridLayout;
00070     layerBox->setLayout(subgrid);
00071 
00072     subgrid->setSpacing(0);
00073     subgrid->setMargin(5);
00074 
00075     m_layerView = new QTreeView;
00076 #if (QT_VERSION >= 0x050000)
00077     m_layerView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
00078 #else
00079     m_layerView->header()->setResizeMode(QHeaderView::ResizeToContents);
00080 #endif
00081     subgrid->addWidget(m_layerView);
00082 
00083     m_layerModel = new LayerTreeModel(m_paneStack);
00084     m_layerView->setModel(m_layerModel);
00085     m_layerView->expandAll();
00086 
00087     QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close);
00088     connect(bb, SIGNAL(rejected()), this, SLOT(reject()));
00089     grid->addWidget(bb, 2, 0);
00090     grid->setRowStretch(2, 0);
00091     
00092     QDesktopWidget *desktop = QApplication::desktop();
00093     QRect available = desktop->availableGeometry();
00094 
00095     int width = available.width() / 2;
00096     int height = available.height() / 3;
00097     if (height < 370) {
00098         if (available.height() > 500) height = 370;
00099     }
00100     if (width < 500) {
00101         if (available.width() > 650) width = 500;
00102     }
00103 
00104     resize(width, height);
00105 }
00106 
00107 LayerTreeDialog::~LayerTreeDialog()
00108 {
00109     delete m_layerModel;
00110 }
00111