summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmpovraymatrixedit.cpp
blob: 0d78c226a07e178b5086d26a55b66aaaea6f87eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2001 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/


#include "pmpovraymatrixedit.h"
#include "pmpovraymatrix.h"
#include "pmlineedits.h"

#include <qlayout.h>
#include <qlabel.h>
#include <klocale.h>


PMPovrayMatrixEdit::PMPovrayMatrixEdit( QWidget* parent, const char* name )
      : Base( parent, name )
{
   m_pDisplayedObject = 0;
}

void PMPovrayMatrixEdit::createTopWidgets( )
{
   Base::createTopWidgets( );

   int i, r, c;
   QGridLayout* gl = new QGridLayout( topLayout( ), 4, 4 );

   for( i = 0; i < 12; i++ )
   {
      m_pValue[i] = new PMFloatEdit( this );
      connect( m_pValue[i], SIGNAL( dataChanged( ) ), SIGNAL( dataChanged( ) ) );
   }

   for( r = 0; r < 4; r++ )
      for( c = 0; c < 3; c++ )
         gl->addWidget( m_pValue[r*3+c], r, c );
   gl->addWidget( new QLabel( "0.0", this ), 0, 3 );
   gl->addWidget( new QLabel( "0.0", this ), 1, 3 );
   gl->addWidget( new QLabel( "0.0", this ), 2, 3 );
   gl->addWidget( new QLabel( "1.0", this ), 3, 3 );
}

void PMPovrayMatrixEdit::displayObject( PMObject* o )
{
   if( o->isA( "PovrayMatrix" ) )
   {
      bool readOnly = o->isReadOnly( );
      int i;
      m_pDisplayedObject = ( PMPovrayMatrix* ) o;
      PMVector v = m_pDisplayedObject->values( );

      for( i = 0; i < 12; i++ )
      {
         m_pValue[i]->setValue( v[i] );
         m_pValue[i]->setReadOnly( readOnly );
      }

      Base::displayObject( o );
   }
   else
      kdError( PMArea ) << "PMPovrayMatrixEdit: Can't display object\n";
}

void PMPovrayMatrixEdit::saveContents( )
{
   if( m_pDisplayedObject )
   {
      Base::saveContents( );
      PMVector v( 12 );
      int i;

      for( i = 0; i < 12; i++ )
         v[i] = m_pValue[i]->value( );
      m_pDisplayedObject->setValues( v );
   }
}

bool PMPovrayMatrixEdit::isDataValid( )
{
   int i;

   for( i = 0; i < 12; i++ )
      if( !m_pValue[i]->isDataValid( ) )
         return false;

   return Base::isDataValid( );
}

#include "pmpovraymatrixedit.moc"