summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmcsgedit.cpp
blob: f14e52c37416010ff1e55de78c1dabd9bd573cf8 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2000-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 "pmcsgedit.h"
#include "pmcsg.h"

#include <tqlayout.h>
#include <tqlabel.h>
#include <tqcombobox.h>
#include <tdelocale.h>

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

void PMCSGEdit::createTopWidgets( )
{
   Base::createTopWidgets( );
   
   TQHBoxLayout* layout;
   m_pTypeCombo = new TQComboBox( false, this );
   m_pTypeCombo->insertItem( i18n( "Union" ) );
   m_pTypeCombo->insertItem( i18n( "Intersection" ) );
   m_pTypeCombo->insertItem( i18n( "Difference" ) );
   m_pTypeCombo->insertItem( i18n( "Merge" ) );
   
   layout = new TQHBoxLayout( topLayout( ) );
   layout->addWidget( new TQLabel( i18n( "Type:" ), this ) );
   layout->addWidget( m_pTypeCombo );
   layout->addStretch( 1 );

   connect( m_pTypeCombo, TQ_SIGNAL( activated( int ) ), TQ_SLOT( slotTypeSelected( int ) ) );
}

void PMCSGEdit::displayObject( PMObject* o )
{
   if( o->isA( "CSG" ) )
   {
      bool readOnly = o->isReadOnly( );
      m_pDisplayedObject = ( PMCSG* ) o;

      switch( m_pDisplayedObject->csgType( ) )
      {
         case PMCSG::CSGUnion:
            m_pTypeCombo->setCurrentItem( 0 );
            break;
         case PMCSG::CSGIntersection:
            m_pTypeCombo->setCurrentItem( 1 );
            break;
         case PMCSG::CSGDifference:
            m_pTypeCombo->setCurrentItem( 2 );
            break;
         case PMCSG::CSGMerge:
            m_pTypeCombo->setCurrentItem( 3 );
            break;
      }
      
      m_pTypeCombo->setEnabled( !readOnly );
      
      Base::displayObject( o );
   }
   else
      kdError( PMArea ) << "PMCSGEdit: Can't display object\n";
}

void PMCSGEdit::saveContents( )
{
   if( m_pDisplayedObject )
   {
      Base::saveContents( );
      switch( m_pTypeCombo->currentItem( ) )
      {
         case 0:
            m_pDisplayedObject->setCSGType( PMCSG::CSGUnion );
            break;
         case 1:
            m_pDisplayedObject->setCSGType( PMCSG::CSGIntersection );
            break;
         case 2:
            m_pDisplayedObject->setCSGType( PMCSG::CSGDifference );
            break;
         case 3:
            m_pDisplayedObject->setCSGType( PMCSG::CSGMerge );
            break;
         default:
            m_pDisplayedObject->setCSGType( PMCSG::CSGUnion );
            break;
      }
   }
}

bool PMCSGEdit::isDataValid( )
{
   return Base::isDataValid( );
}

void PMCSGEdit::slotTypeSelected( int )
{
   emit dataChanged( );
}
#include "pmcsgedit.moc"