summaryrefslogtreecommitdiffstats
path: root/kugar/kudesigner_lib/band.cpp
blob: ffc56fe42d57d2113e79f1adc9b7e63cd6238d2b (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
/* This file is part of the KDE project
Copyright (C) 2003-2004 Alexander Dymo <[email protected]>

This library 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 library 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
Library General Public License for more details.

You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB.  If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/
#include "band.h"

#include <tqcanvas.h>
#include <tqrect.h>
#include <tqpainter.h>

#include <kglobalsettings.h>

#include "propertyserializer.h"
#include "kugartemplate.h"
#include "canvas.h"
#include "reportitem.h"

namespace Kudesigner
{

Band::~Band()
{
    for ( TQCanvasItemList::Iterator it = items.begin(); it != items.end(); ++it )
    {
        //  (*it)->hide();
        m_canvas->selected.remove( static_cast<Box*>( *it ) );
        ( *it ) ->setSelected( false );
        delete ( *it );
    }
    items.clear();
}

void Band::draw( TQPainter &painter )
{
    setX( m_canvas->kugarTemplate() ->props[ "LeftMargin" ].value().toInt() );
    setSize( m_canvas->kugarTemplate() ->width()
             - m_canvas->kugarTemplate() ->props[ "RightMargin" ].value().toInt()
             - m_canvas->kugarTemplate() ->props[ "LeftMargin" ].value().toInt(),
             props[ "Height" ].value().toInt() );
    Section::draw( painter );
}

//arrange band and all sublings (items)
void Band::arrange( int base, bool destructive )
{
    int diff = base - ( int ) y();
    setY( base );
    if ( !destructive )
        return ;
    for ( TQCanvasItemList::Iterator it = items.begin(); it != items.end(); ++it )
    {
        ( *it ) ->moveBy( 0, diff );
        //  ( (CanvasReportItem *)(*it) )->updateGeomProps();
        m_canvas->update();
        ( *it ) ->hide();
        ( *it ) ->show();
    }
}

int Band::minHeight()
{
    int result = static_cast<int>( y() + 10 );
    for ( TQCanvasItemList::Iterator it = items.begin(); it != items.end(); ++it )
    {
        result = TQMAX( result, static_cast<int>( static_cast<TQCanvasRectangle*>( *it ) ->y() +
                       static_cast<TQCanvasRectangle*>( *it ) ->height() ) );
    }
    return result - static_cast<int>( y() );
}

TQString Band::getXml()
{
    TQString result = "";

    for ( Set::Iterator it( props ); it.current(); ++it )
    {
        result += " " + TQString(it.currentKey()) + "=" + "\"" + PropertySerializer::toString( it.current() ) + "\"";
    }

    result += ">\n";
    for ( TQCanvasItemList::Iterator it = items.begin(); it != items.end(); ++it )
    {
        result += static_cast<ReportItem*>( *it ) ->getXml();
    }
    return result;
}

int Band::isInHolder( const TQPoint p )
{
    if ( bottomMiddleResizableRect().contains( p ) )
        return ( ResizeBottom );
    return ResizeNothing;
}

void Band::drawHolders( TQPainter &painter )
{
    painter.setPen( TQColor( 0, 0, 0 ) );
    painter.setBrush( KGlobalSettings::highlightColor() );
    painter.drawRect( bottomMiddleResizableRect() );
}

TQRect Band::bottomMiddleResizableRect()
{
    return TQRect( ( int ) ( x() + width() / 2 - HolderSize / 2. ), ( int ) ( y() + height() - HolderSize ), HolderSize, HolderSize );
}

void Band::updateGeomProps()
{
    props[ "Height" ].setValue( height() );
    m_canvas->kugarTemplate() ->arrangeSections();
}

}