summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmtreeviewitem.cpp
blob: cac3b3c7daa094e41125297ebda8e00a6c130ef2 (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
/*
**************************************************************************
                                 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 "pmtreeviewitem.h"
#include "pmobject.h"
#include <kiconloader.h>

#include "pmtreeview.h"
#include "pmfactory.h"
#include "pmtexturemap.h"

PMTreeViewItem::PMTreeViewItem( PMObject* object, TQListView* parent )
      : TQListViewItem( parent )
{
   m_pObject = object;
   setDescriptions( );
   initSelection( );
}

PMTreeViewItem::PMTreeViewItem( PMObject* object, TQListViewItem* parent )
      : TQListViewItem( parent )
{
   m_pObject = object;
   setDescriptions( );
   initSelection( );
}

PMTreeViewItem::PMTreeViewItem( PMObject* object, TQListView* parent,
                                TQListViewItem* after )
      : TQListViewItem( parent, after )
{
   m_pObject = object;
   setDescriptions( );
   initSelection( );
}

PMTreeViewItem::PMTreeViewItem( PMObject* object, TQListViewItem* parent,
                   TQListViewItem* after )
      : TQListViewItem( parent, after )
{
   m_pObject = object;
   setDescriptions( );
   initSelection( );
}

void PMTreeViewItem::setDescriptions( )
{
   TQString text;
   setPixmap( 0, SmallIcon( m_pObject->pixmap( ), PMFactory::instance( ) ) );
   
   if( m_pObject->canHaveName( ) )
   {
      text = m_pObject->name( );
      if( text.isEmpty( ) )
         text = m_pObject->description( );      
   }
   else
      text = m_pObject->description( );
   
   if( m_pObject->parent( ) )
   {
      if( m_pObject->parent( )->isA( "TextureMapBase" ) )
      {
         PMTextureMapBase* tm = ( PMTextureMapBase* ) m_pObject->parent( );
         if( m_pObject->type( ) == tm->mapType( ) )
            text = TQString( "[%1] " ).arg( tm->mapValue( m_pObject ), 4, 'f', 2 ) + text;
      }
   }
   setText( 0, text );
}

TQString PMTreeViewItem::key( int, bool ) const
{
   TQString result;
   if( m_pObject->parent( ) )
      result.sprintf( "%06i", m_pObject->parent( )->findChild( m_pObject ) );
   else
      result = "000000";
   return result;
}

void PMTreeViewItem::setSelected( bool select )
{
   bool ws = isSelected( );
   PMTreeView* treeview = ( PMTreeView* ) listView( );

   // ignore selections during a move event
   if( treeview->acceptSelect( ) )
   {
      TQListViewItem::setSelected( select );

      if( ws != isSelected( ) )
         treeview->itemSelected( this, isSelected( ) );
   }
}

void PMTreeViewItem::initSelection( )
{
   TQListViewItem::setSelected( m_pObject->isSelected( ) );
//   if( m_pObject->isSelected( ) )
//      repaint( );
}