datacontainerfileloaderwidget.cpp 4.37 KB
Newer Older
1 2 3 4
// ================================================================================================
// 
// This file is part of the CAMPVis Software Framework.
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2015, all rights reserved,
6 7
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
//      Chair for Computer Aided Medical Procedures
8 9
//      Technische Universitaet Muenchen
//      Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// 
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
// 
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 
// except in compliance with the License. You may obtain a copy of the License at
// 
// http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software distributed under the 
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
// either express or implied. See the License for the specific language governing permissions 
// and limitations under the License.
// 
// ================================================================================================

#include "datacontainerfileloaderwidget.h"

27 28
#include <QScrollBar>

29 30 31 32 33 34 35 36 37 38
namespace campvis {

    const std::string DataContainerFileLoaderWidget::loggerCat_ = "CAMPVis.application.DataContainerFileLoaderWidget";

    DataContainerFileLoaderWidget::DataContainerFileLoaderWidget(DataContainerInspectorWidget* parentDataInspector, QWidget* parent) 
        : QWidget(parent)
        , _dataContainer(0)
        , _layout(0)
        , _pipelinePropertiesScrollArea(0)
        , _fileName("fileName", "Image URL", "")
Sebastian Pölsterl's avatar
Sebastian Pölsterl committed
39
        , _propCollectionWidget(0)
40
    {
41 42 43
        _parent = parentDataInspector;
        _dataContainer = _parent->getDataContainer();
        _imgReader = new GenericImageReader();
44 45 46 47
        setupGUI();
    }

    DataContainerFileLoaderWidget::~DataContainerFileLoaderWidget() {
48 49 50
        delete _imgReader;
        _imgReader = nullptr;

51 52
        if (_dataContainer != 0) {
            _dataContainer->s_dataAdded.disconnect(this);
53 54 55 56
        }
    }

    void DataContainerFileLoaderWidget::setDataContainer(DataContainer* dataContainer) {
57
        _dataContainer = dataContainer;
58 59 60 61 62 63 64 65 66 67
    }

    QSize DataContainerFileLoaderWidget::sizeHint() const {
        return QSize(300, 350);
    }


    void DataContainerFileLoaderWidget::setupGUI() {
        setWindowTitle(tr("Browse File"));

68 69
        _layout = new QGridLayout();
        _layout->setSpacing(2);
70 71
        setLayout(_layout);

72 73 74 75
        _pipelinePropertiesScrollArea = new QScrollArea(this);
        _pipelinePropertiesScrollArea->setWidgetResizable(true);
        _pipelinePropertiesScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        _pipelinePropertiesScrollArea->setFrameStyle(QScrollArea::NoFrame);
76
        
77 78 79 80 81
        _propCollectionWidget = new PropertyCollectionWidget(_pipelinePropertiesScrollArea);
        _propCollectionWidget->installEventFilter(this);
        _pipelinePropertiesScrollArea->setWidget(_propCollectionWidget);
        _propCollectionWidget->updatePropCollection(_imgReader, _dataContainer);
        _layout->addWidget(_pipelinePropertiesScrollArea, 0, 0, 1, 2);
82

83 84 85 86
        _btnLoadFile = new QPushButton(tr("Load"), this);
        _layout->addWidget(_btnLoadFile, 1, 0, 1, 1);
        _btnCancel = new QPushButton(tr("Cancel"), this);
        _layout->addWidget(_btnCancel, 1, 1, 1, 1);
87 88

        qRegisterMetaType<QtDataHandle>("QtDataHandle");
89 90 91 92 93 94 95 96 97 98 99 100
        connect(_btnCancel, SIGNAL(clicked()), this, SLOT(onBtnCancelClicked()));
        connect( _btnLoadFile, SIGNAL(clicked()), this, SLOT(onBtnLoadFileClicked()));
    }


    bool DataContainerFileLoaderWidget::eventFilter(QObject* watched, QEvent* event) {
        if (watched == _propCollectionWidget && event->type() == QEvent::Resize) {
            _pipelinePropertiesScrollArea->setMinimumWidth(_propCollectionWidget->minimumSizeHint().width() +
                _pipelinePropertiesScrollArea->verticalScrollBar()->width());
        }

        return false;
101 102 103 104
    }

    void DataContainerFileLoaderWidget::onBtnCancelClicked() {
        delete _imgReader;
105 106
        _imgReader = nullptr;
        close();
107 108 109
    }

    void DataContainerFileLoaderWidget::onBtnLoadFileClicked() {
110 111 112
        _imgReader->process(*_dataContainer);
        _parent->setDataContainer(_dataContainer);
        close();
113 114
    }

Sebastian Pölsterl's avatar
Sebastian Pölsterl committed
115
}