1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
28
#include <boost/lexical_cast.hpp>
30
#include <QtGui/QFileDialog>
32
#include "core/common/WLogger.h"
33
#include "core/common/WPropertyVariable.h"
34
#include "core/common/constraints/WPropertyConstraintTypes.h"
35
#include "../WGuiConsts.h"
37
#include "WPropertyFilenameWidget.h"
38
#include "WPropertyFilenameWidget.moc"
40
WPropertyFilenameWidget::WPropertyFilenameWidget( WPropFilename property, QGridLayout* propertyGrid, QWidget* parent ):
41
WPropertyWidget( property, propertyGrid, parent ),
42
m_fnProperty( property ),
43
m_button( &m_parameterWidgets ),
44
m_layout( &m_parameterWidgets ),
45
m_asText( &m_informationWidgets ),
46
m_infoLayout( &m_informationWidgets )
49
m_parameterWidgets.setLayout( &m_layout );
51
// layout both against each other
52
m_layout.addWidget( &m_button );
53
m_layout.setMargin( WGLOBAL_MARGIN );
54
m_layout.setSpacing( WGLOBAL_SPACING );
56
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
57
m_infoLayout.addWidget( &m_asText );
58
m_infoLayout.setMargin( WGLOBAL_MARGIN );
59
m_infoLayout.setSpacing( WGLOBAL_SPACING );
60
m_informationWidgets.setLayout( &m_infoLayout );
62
// set the initial values
65
// connect the modification signal of the edit and slider with our callback
66
connect( &m_button, SIGNAL( released() ), this, SLOT( buttonReleased() ) );
69
WPropertyFilenameWidget::~WPropertyFilenameWidget()
74
void WPropertyFilenameWidget::update()
76
QString val = QString::fromStdString( m_fnProperty->get().filename() );
77
m_button.setText( val );
78
m_asText.setText( val );
81
void WPropertyFilenameWidget::buttonReleased()
85
// if there is a "IsDirectory" constraint -> set a special option in the dialog
86
if( m_fnProperty->countConstraint( PC_ISDIRECTORY ) != 0 )
88
// OK there should only be directories allowed
89
path = QFileDialog::getExistingDirectory( this,
90
QString::fromStdString( "Select directory for " + m_fnProperty->getName() ),
91
QString::fromStdString( m_fnProperty->get().file_string() ),
92
QFileDialog::DontConfirmOverwrite );
94
else if( m_fnProperty->countConstraint( PC_PATHEXISTS ) != 0 )
96
path = QFileDialog::getOpenFileName( this,
97
QString::fromStdString( "Select existing file for " + m_fnProperty->getName() ),
98
QString::fromStdString( m_fnProperty->get().file_string() ), QString(), 0,
99
QFileDialog::DontConfirmOverwrite );
103
path = QFileDialog::getSaveFileName( this,
104
QString::fromStdString( "Select file for " + m_fnProperty->getName() ),
105
QString::fromStdString( m_fnProperty->get().file_string() ), QString(), 0,
106
QFileDialog::DontConfirmOverwrite );
109
// convert it back to a WColor
110
invalidate( !m_fnProperty->set( boost::filesystem::path( path.toStdString() ) ) ); // NOTE: set automatically checks the validity of the value
113
m_button.setText( QString::fromStdString( m_fnProperty->get().filename() ) );