summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmlinkedit.cpp
blob: 2114c5faf97beb32a5e1cdb26e0bc606443a5237 (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2001-2002 by Andreas Zehender
    email                : [email protected]
**************************************************************************

**************************************************************************
*                                                                        *
*  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 "pmlinkedit.h"
#include <tqlineedit.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <klocale.h>
#include <kdialog.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>

#include "pmdeclare.h"
#include "pmobjectselect.h"

PMLinkEdit::PMLinkEdit( const TQString& declareType,
                        TQWidget* tqparent, const char* name )
      : TQWidget( tqparent, name )
{
   m_declareTypes.append( declareType );
   init( );
}

PMLinkEdit::PMLinkEdit( const TQStringList& declareTypes,
                        TQWidget* tqparent, const char* name )
      : TQWidget( tqparent, name )
{
   m_declareTypes = declareTypes;
   init( );
}

PMLinkEdit::PMLinkEdit( TQWidget* tqparent, const char* name )
      : TQWidget( tqparent, name )
{
   init( );
}

void PMLinkEdit::init( )
{
   m_pDeclare = 0;
   m_pDisplayedObject = 0;
   m_bReadOnly = false;

   TQGridLayout* grid = new TQGridLayout( this, 2, 2, 0, KDialog::spacingHint( ) );

   grid->addWidget( new TQLabel( i18n( "Prototype:" ), this ), 0, 0 );
   grid->setColStretch( 0, 0 );
   grid->setColStretch( 1, 1 );
   m_pIDEdit = new TQLineEdit( this );
   m_pIDEdit->setReadOnly( true );
   grid->addWidget( m_pIDEdit, 0, 1 );

   TQHBoxLayout* tqlayout = new TQHBoxLayout( );
   grid->addLayout( tqlayout, 1, 1 );
   m_pSelectButton = new TQPushButton( i18n( "Select..." ), this );
   tqlayout->addWidget( m_pSelectButton );
   m_pClearButton = new KPushButton( KStdGuiItem::clear(), this );
   tqlayout->addWidget( m_pClearButton );

   connect( m_pSelectButton, TQT_SIGNAL( clicked( ) ), TQT_SLOT( slotSelectClicked( ) ) );
   connect( m_pClearButton, TQT_SIGNAL( clicked( ) ), TQT_SLOT( slotClearClicked( ) ) );
}

void PMLinkEdit::setDisplayedObject( PMObject* obj )
{
   m_pDisplayedObject = obj;
   m_pDeclare = obj->linkedObject( );
   if( m_pDeclare )
   {
      m_pIDEdit->setText( m_pDeclare->id( ) );
      if( !m_bReadOnly )
         m_pClearButton->setEnabled( true );
   }
   else
   {
      m_pIDEdit->clear( );
      if( !m_bReadOnly )
         m_pClearButton->setEnabled( false );
   }
}

void PMLinkEdit::setLinkPossibility( const TQString& t )
{
   m_declareTypes.clear( );
   m_declareTypes.append( t );
}


void PMLinkEdit::setLinkPossibilities( const TQStringList& t )
{
   m_declareTypes = t;
}

void PMLinkEdit::setReadOnly( bool yes )
{
   m_bReadOnly = yes;
   m_pClearButton->setEnabled( !m_bReadOnly && m_pDeclare );
   m_pSelectButton->setEnabled( !m_bReadOnly );
}

void PMLinkEdit::slotSelectClicked( )
{
   if( m_pDisplayedObject )
   {
      PMObject* obj = 0;
      int result;

      if( m_declareTypes.count( ) == 1 )
         result = PMObjectSelect::selectDeclare(
            m_pDisplayedObject, m_declareTypes.first( ), obj, this );
      else
         result = PMObjectSelect::selectDeclare(
            m_pDisplayedObject, m_declareTypes, obj, this );

      if( ( result == TQDialog::Accepted ) && obj )
      {
         m_pDeclare = ( PMDeclare* ) obj;
         m_pIDEdit->setText( m_pDeclare->id( ) );
         m_pClearButton->setEnabled( true );
         emit dataChanged( );
      }
   }
}

void PMLinkEdit::slotClearClicked( )
{
   m_pDeclare = 0;
   m_pIDEdit->clear( );
   emit dataChanged( );
}

#include "pmlinkedit.moc"