stringpropertywidget.cpp 4.38 KB
Newer Older
1
2
// ================================================================================================
// 
schultezub's avatar
schultezub committed
3
// This file is part of the CAMPVis Software Framework.
4
// 
5
// If not explicitly stated otherwise: Copyright (C) 2012-2013, all rights reserved,
schultezub's avatar
schultezub committed
6
//      Christian Schulte zu Berge <christian.szb@in.tum.de>
7
//      Chair for Computer Aided Medical Procedures
8
9
//      Technische Universität München
//      Boltzmannstr. 3, 85748 Garching b. München, Germany
10
// 
schultezub's avatar
schultezub committed
11
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
12
// 
13
14
15
16
// 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
17
// 
18
19
20
21
// 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.
22
23
24
// 
// ================================================================================================

schultezub's avatar
schultezub committed
25
#include "stringpropertywidget.h"
26
27
28
29
30
31
#include "core/properties/datanameproperty.h"

#include <QLineEdit>
#include <QPushButton>
#include <QDir>
#include <QFileDialog>
schultezub's avatar
schultezub committed
32

schultezub's avatar
schultezub committed
33
namespace campvis {
schultezub's avatar
schultezub committed
34
    StringPropertyWidget::StringPropertyWidget(StringProperty* property, QWidget* parent /*= 0*/)
35
        : AbstractPropertyWidget(property, false, parent)
schultezub's avatar
schultezub committed
36
        , _lineEdit(0)
37
        , _btnLoadFile(0)
schultezub's avatar
schultezub committed
38
    {
schultezub's avatar
schultezub committed
39
40
        _lineEdit = new QLineEdit(this);
        _lineEdit->setText(QString::fromStdString(property->getValue()));
schultezub's avatar
schultezub committed
41
42
        addWidget(_lineEdit);

43
        if (! dynamic_cast<DataNameProperty*>(property)) {
44
            _btnLoadFile = new QPushButton(tr("Browse"), this);
45
46
47
48
            addWidget(_btnLoadFile);
            connect(_btnLoadFile, SIGNAL(clicked(bool)), this, SLOT(onBtnLoadFileClicked(bool)));
        }

schultezub's avatar
schultezub committed
49
        connect(_lineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onTextChanged(const QString&)));
schultezub's avatar
schultezub committed
50
51
52
53
54
    }

    StringPropertyWidget::~StringPropertyWidget() {

    }
55
56
57
    void StringPropertyWidget::setButtonLabel(const std::string& btnLabel) {
        this->_btnLoadFile->setText(QString(btnLabel.c_str()));
    }
schultezub's avatar
schultezub committed
58
59
60
61
62
63
64
65
66
67
68
69
70

    void StringPropertyWidget::updateWidgetFromProperty() {
        StringProperty* prop = static_cast<StringProperty*>(_property);
        QString qs = QString::fromStdString(prop->getValue());
        if (_lineEdit->text() != qs) {
            _lineEdit->blockSignals(true);
            _lineEdit->setText(qs);
            _lineEdit->blockSignals(false);
        }
    }

    void StringPropertyWidget::onTextChanged(const QString& text) {
        StringProperty* prop = static_cast<StringProperty*>(_property);
schultezub's avatar
schultezub committed
71
        ++_ignorePropertyUpdates;
schultezub's avatar
schultezub committed
72
        prop->setValue(text.toStdString());
schultezub's avatar
schultezub committed
73
        --_ignorePropertyUpdates;
schultezub's avatar
schultezub committed
74
    }
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

    void StringPropertyWidget::onBtnLoadFileClicked(bool flag) {
        StringProperty* prop = static_cast<StringProperty*>(_property);

        QString dialogCaption = QString::fromStdString(prop->getTitle());
        QString directory;
        // use directory of current property value if any, default directory otherwise
        if (! prop->getValue().empty())
            directory = QString::fromStdString(prop->getValue());
        else
            directory = tr("");

        const QString fileFilter = /*QString::fromStdString(property_->getFileFilter()) + ";;" + */tr("All files (*)");

        QString filename;
//        if (property_->getFileMode() == FileDialogProperty::OPEN_FILE) {
            filename = QFileDialog::getOpenFileName(QWidget::parentWidget(), dialogCaption, directory, fileFilter);
/*        }
        else if (property_->getFileMode() == FileDialogProperty::SAVE_FILE) {
            filename = QFileDialog::getSaveFileName(QWidget::parentWidget(), dialogCaption, directory, fileFilter);
        }
        else if (property_->getFileMode() == FileDialogProperty::DIRECTORY) {
            filename = QFileDialog::getExistingDirectory(QWidget::parentWidget(), dialogCaption, QString::fromStdString(property_->get()));
        }*/

        if (! filename.isEmpty()) {
            prop->setValue(filename.toStdString());
            //emit modified();
        }
    }

schultezub's avatar
schultezub committed
106
}