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

« back to all changes in this revision

Viewing changes to src/qt4gui/qt4/controlPanel/WPropertyStringWidget.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 "core/common/WLogger.h"
 
31
#include "core/common/WPropertyVariable.h"
 
32
#include "../WGuiConsts.h"
 
33
 
 
34
#include "WPropertyStringWidget.h"
 
35
#include "WPropertyStringWidget.moc"
 
36
 
 
37
WPropertyStringWidget::WPropertyStringWidget( WPropString property, QGridLayout* propertyGrid, QWidget* parent ):
 
38
    WPropertyWidget( property, propertyGrid, parent ),
 
39
    m_stringProperty( property ),
 
40
    m_edit( &m_parameterWidgets ),
 
41
    m_layout( &m_parameterWidgets ),
 
42
    m_asText( &m_informationWidgets ),
 
43
    m_infoLayout( &m_informationWidgets )
 
44
{
 
45
    // initialize members
 
46
    m_parameterWidgets.setLayout( &m_layout );
 
47
 
 
48
    // layout
 
49
    m_layout.addWidget( &m_edit );
 
50
    m_layout.setMargin( WGLOBAL_MARGIN );
 
51
    m_layout.setSpacing( WGLOBAL_SPACING );
 
52
 
 
53
    // Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
 
54
    m_infoLayout.addWidget( &m_asText );
 
55
    m_infoLayout.setMargin( WGLOBAL_MARGIN );
 
56
    m_infoLayout.setSpacing( WGLOBAL_SPACING );
 
57
    m_informationWidgets.setLayout( &m_infoLayout );
 
58
    m_asText.setWordWrap( true );
 
59
    // To have word warp work correctly -> set size policy
 
60
    m_asText.setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ) );
 
61
 
 
62
    m_asText.setTextInteractionFlags( Qt::TextSelectableByMouse );
 
63
 
 
64
    // set the initial values
 
65
    update();
 
66
 
 
67
    // connect the modification signal of the edit and slider with our callback
 
68
    connect( &m_edit, SIGNAL( returnPressed() ), this, SLOT( editChanged() ) );
 
69
    connect( &m_edit, SIGNAL( textEdited( const QString& ) ), this, SLOT( textEdited( const QString& ) ) );
 
70
}
 
71
 
 
72
WPropertyStringWidget::~WPropertyStringWidget()
 
73
{
 
74
    // cleanup
 
75
}
 
76
 
 
77
void WPropertyStringWidget::update()
 
78
{
 
79
    QString val = QString::fromStdString( m_stringProperty->get() );
 
80
    m_edit.setText( val );
 
81
    m_asText.setText( val );
 
82
}
 
83
 
 
84
void WPropertyStringWidget::editChanged()
 
85
{
 
86
    std::string value = m_edit.text().toStdString();
 
87
    // now: is the value acceptable by the property?
 
88
    invalidate( !m_stringProperty->set( value ) );     // NOTE: set automatically checks the validity of the value
 
89
}
 
90
 
 
91
void WPropertyStringWidget::textEdited( const QString& text )
 
92
{
 
93
    // this method does NOT set the property actually, but tries to validate it
 
94
    std::string value = text.toStdString();
 
95
    invalidate( !m_stringProperty->accept( value ) );
 
96
}
 
97
 
 
98