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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
/***************************************************************************
* Copyright (C) 2005 by Alexander Dymo *
* adymo@tdevelop.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "structurewidget.h"
#include <tqpainter.h>
#include <tqcanvas.h>
#include <koproperty/property.h>
#include "canvas.h"
#include "kugartemplate.h"
#include "reportheader.h"
#include "reportfooter.h"
#include "pageheader.h"
#include "pagefooter.h"
#include "detail.h"
#include "detailfooter.h"
#include "detailheader.h"
#include <kdebug.h>
namespace Kudesigner
{
using namespace KoProperty;
class StructureItem: public KListViewItem
{
public:
StructureItem( KListView *parent, const TQString &name )
: KListViewItem( parent, name ), m_bold( false )
{}
StructureItem( KListViewItem *parent, const TQString &name )
: KListViewItem( parent, name ), m_bold( false )
{}
void setBold( bool b )
{
m_bold = b;
}
bool isBold() const
{
return m_bold;
}
virtual void paintCell( TQPainter *p, const TQColorGroup &cg, int column, int width, int align )
{
if ( m_bold )
{
TQFont f = p->font();
f.setWeight( 75 );
p->setFont( f );
}
KListViewItem::paintCell( p, cg, column, width, align );
}
private:
bool m_bold;
};
StructureWidget::StructureWidget( TQWidget* parent, const char* name )
: KListView( parent, name )
{
setFullWidth( true );
addColumn( tr( "Report Structure" ) );
setSorting( -1 );
connect( this, TQT_SIGNAL( clicked( TQListViewItem* ) ), this, TQT_SLOT( selectItem( TQListViewItem* ) ) );
}
void StructureWidget::refresh()
{
if ( !m_doc )
return ;
clear();
m_selected.clear();
StructureItem *root = new StructureItem( this, tr( "Report Template" ) );
m_items[ m_doc->kugarTemplate() ] = root;
root->setOpen( true );
refreshSection( m_doc->kugarTemplate() ->reportFooter, root );
refreshSection( m_doc->kugarTemplate() ->pageFooter, root );
for ( std::map<int, DetailBand>::iterator it =
m_doc->kugarTemplate() ->details.begin();
it != m_doc->kugarTemplate() ->details.end(); ++it )
{
int level = ( *it ).first;
refreshSection( ( *it ).second.first.second, root, level );
refreshSection( ( *it ).second.second, root, level );
refreshSection( ( *it ).second.first.first, root, level );
}
refreshSection( m_doc->kugarTemplate() ->pageHeader, root );
refreshSection( m_doc->kugarTemplate() ->reportHeader, root );
}
void StructureWidget::refreshSection( Kudesigner::Band *section, StructureItem *root, int level )
{
if ( !section )
return ;
TQString name;
switch ( section->rtti() )
{
case Kudesigner::Rtti_ReportHeader:
name = tqtr( "Report Header" );
break;
case Kudesigner::Rtti_ReportFooter:
name = tqtr( "Report Footer" );
break;
case Kudesigner::Rtti_PageFooter:
name = tqtr( "Page Footer" );
break;
case Kudesigner::Rtti_PageHeader:
name = tqtr( "Page Header" );
break;
case Kudesigner::Rtti_Detail:
name = tqtr( "Detail" );
break;
case Kudesigner::Rtti_DetailHeader:
name = tqtr( "Detail Header" );
break;
case Kudesigner::Rtti_DetailFooter:
name = tqtr( "Detail Footer" );
break;
}
if ( level > 0 )
name += tqtr( " (level %1)" ).arg( level );
StructureItem *item = new StructureItem( root, name );
m_items[ section ] = item;
refreshSectionContents( section, item );
}
void StructureWidget::refreshSectionContents( Kudesigner::Band *section, StructureItem *root )
{
if ( !section )
return ;
for ( TQCanvasItemList::iterator it = section->items.begin(); it != section->items.end(); ++it )
{
Kudesigner::Box *box = static_cast<Kudesigner::Box*>( *it );
if ( !box )
continue;
TQString name = tr( "<unknown>" );
int idx;
switch ( box->rtti() )
{
case Kudesigner::Rtti_Label:
name = tqtr( "Label: %1" ).arg( box->props[ "Text" ].value().toString() );
break;
case Kudesigner::Rtti_Field:
name = tqtr( "Field: %1" ).arg( box->props[ "Field" ].value().toString() );
break;
case Kudesigner::Rtti_Calculated:
name = tqtr( "Calculated Field: %1" ).arg( box->props[ "Field" ].value().toString() );
break;
case Kudesigner::Rtti_Special:
idx = box->props[ "Type" ].listData()->keys.findIndex(
box->props[ "Type" ].value().toInt() );
name = tqtr( "Special Field: %1" ).arg( box->props[ "Type" ].listData()->keys[ idx ].toString() );
break;
case Kudesigner::Rtti_Line:
name = tqtr( "Line" );
break;
}
StructureItem *item = new StructureItem( root, name );
m_items[ box ] = item;
}
}
void StructureWidget::selectionMade()
{
m_selected.clear();
BoxList sel = m_doc->selected;
for ( BoxList::iterator it = sel.begin(); it != sel.end(); ++it )
{
if ( m_items.contains( *it ) )
{
StructureItem * item = static_cast<StructureItem*>( m_items[ *it ] );
item->setBold( true );
item->repaint();
m_selected.append( item );
}
}
}
void StructureWidget::selectionClear()
{
for ( TQValueList<StructureItem*>::iterator it = m_selected.begin(); it != m_selected.end(); ++it )
{
if ( ( *it ) == 0 )
continue;
( *it ) ->setBold( false );
( *it ) ->repaint();
}
m_selected.clear();
}
void StructureWidget::selectItem( TQListViewItem *item )
{
if ( !item )
return ;
int idx = m_items.values().findIndex( static_cast<StructureItem*>( item ) );
if ( idx == -1 )
return ;
Kudesigner::Box *box = m_items.keys() [ idx ];
if ( box )
m_doc->selectItem( box, false );
}
void StructureWidget::setDocument( Kudesigner::Canvas *doc )
{
m_doc = doc;
m_items.clear();
}
}
#include "structurewidget.moc"
|