summaryrefslogtreecommitdiffstats
path: root/kugar/kudesigner_lib/band.cpp
blob: 0b3225f6d7f297b69068673e2b81b5cb6f70a188 (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 <adymo@mksat.net>

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 <qcanvas.h>
#include <qrect.h>
#include <qpainter.h>

#include <kglobalsettings.h>

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

namespace Kudesigner
{

Band::~Band()
{
    for ( QCanvasItemList::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( QPainter &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 ( QCanvasItemList::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 ( QCanvasItemList::Iterator it = items.begin(); it != items.end(); ++it )
    {
        result = QMAX( result, static_cast<int>( static_cast<QCanvasRectangle*>( *it ) ->y() +
                       static_cast<QCanvasRectangle*>( *it ) ->height() ) );
    }
    return result - static_cast<int>( y() );
}

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

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

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

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

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

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

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

}