~ubuntu-branches/ubuntu/precise/openwalnut/precise

« back to all changes in this revision

Viewing changes to src/qt4gui/qt4/controlPanel/WPropertyFilenameWidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Eichelbaum
  • Date: 2011-06-21 10:26:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110621102654-rq0zf436q949biih
Tags: upstream-1.2.5
ImportĀ upstreamĀ versionĀ 1.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
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.
 
14
//
 
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.
 
19
//
 
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/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#include <cmath>
 
26
#include <string>
 
27
 
 
28
#include <boost/lexical_cast.hpp>
 
29
 
 
30
#include <QtGui/QFileDialog>
 
31
 
 
32
#include "core/common/WLogger.h"
 
33
#include "core/common/WPropertyVariable.h"
 
34
#include "core/common/constraints/WPropertyConstraintTypes.h"
 
35
#include "../WGuiConsts.h"
 
36
 
 
37
#include "WPropertyFilenameWidget.h"
 
38
#include "WPropertyFilenameWidget.moc"
 
39
 
 
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 )
 
47
{
 
48
    // initialize members
 
49
    m_parameterWidgets.setLayout( &m_layout );
 
50
 
 
51
    // layout both against each other
 
52
    m_layout.addWidget( &m_button );
 
53
    m_layout.setMargin( WGLOBAL_MARGIN );
 
54
    m_layout.setSpacing( WGLOBAL_SPACING );
 
55
 
 
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 );
 
61
 
 
62
    // set the initial values
 
63
    update();
 
64
 
 
65
    // connect the modification signal of the edit and slider with our callback
 
66
    connect( &m_button, SIGNAL( released() ), this, SLOT( buttonReleased() ) );
 
67
}
 
68
 
 
69
WPropertyFilenameWidget::~WPropertyFilenameWidget()
 
70
{
 
71
    // cleanup
 
72
}
 
73
 
 
74
void WPropertyFilenameWidget::update()
 
75
{
 
76
    QString val = QString::fromStdString( m_fnProperty->get().filename() );
 
77
    m_button.setText( val );
 
78
    m_asText.setText( val );
 
79
}
 
80
 
 
81
void WPropertyFilenameWidget::buttonReleased()
 
82
{
 
83
    QString path;
 
84
 
 
85
    // if there is a "IsDirectory" constraint -> set a special option in the dialog
 
86
    if( m_fnProperty->countConstraint( PC_ISDIRECTORY ) != 0 )
 
87
    {
 
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 );
 
93
    }
 
94
    else if( m_fnProperty->countConstraint( PC_PATHEXISTS ) != 0 )
 
95
    {
 
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 );
 
100
    }
 
101
    else
 
102
    {
 
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 );
 
107
    }
 
108
 
 
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
 
111
 
 
112
    // set button
 
113
    m_button.setText( QString::fromStdString( m_fnProperty->get().filename() ) );
 
114
}
 
115