~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kugar/kudesigner_lib/canvband.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2003 Alexander Dymo <cloudtemple@mksat.net>
3
 
 
4
 
   This library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Library General Public
6
 
   License as published by the Free Software Foundation; either
7
 
   version 2 of the License, or (at your option) any later version.
8
 
 
9
 
   This library is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
   Library General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU Library General Public License
15
 
   along with this library; see the file COPYING.LIB.  If not, write to
16
 
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
 
   Boston, MA 02111-1307, USA.
18
 
*/
19
 
 
20
 
#ifndef PURE_QT
21
 
#include <kglobalsettings.h>
22
 
#endif
23
 
 
24
 
#include <qcanvas.h>
25
 
#include <qrect.h>
26
 
#include <qpainter.h>
27
 
 
28
 
#include "canvband.h"
29
 
#include "canvbox.h"
30
 
#include "canvkutemplate.h"
31
 
#include "mycanvas.h"
32
 
#include "creportitem.h"
33
 
 
34
 
 
35
 
void CanvasBand::draw(QPainter &painter)
36
 
{
37
 
    setX(((MyCanvas*)canvas())->templ->props["LeftMargin"]->value().toInt());
38
 
    setSize(((MyCanvas*)canvas())->templ->width()
39
 
        - ((MyCanvas*)canvas())->templ->props["RightMargin"]->value().toInt()
40
 
        - ((MyCanvas*)canvas())->templ->props["LeftMargin"]->value().toInt(),
41
 
        props["Height"]->value().toInt());
42
 
    CanvasSection::draw(painter);
43
 
}
44
 
 
45
 
//arrange band and all sublings (items)
46
 
void CanvasBand::arrange(int base, bool destructive)
47
 
{
48
 
    int diff = base - (int)y();
49
 
    setY(base);
50
 
    if (!destructive)
51
 
        return;
52
 
    for (QCanvasItemList::Iterator it=items.begin(); it!=items.end(); ++it)
53
 
    {
54
 
        (*it)->moveBy(0, diff);
55
 
    //  ( (CanvasReportItem *)(*it) )->updateGeomProps();
56
 
        canvas()->update();
57
 
        (*it)->hide();
58
 
        (*it)->show();
59
 
    }
60
 
}
61
 
 
62
 
int CanvasBand::minHeight()
63
 
{
64
 
        int result=y()+10;
65
 
        for (QCanvasItemList::Iterator it=items.begin(); it!=items.end(); ++it)
66
 
        {
67
 
                result=QMAX(result,((QCanvasRectangle*)(*it))->y()+
68
 
                        ((QCanvasRectangle*)(*it))->height());
69
 
        }
70
 
        return result-y();
71
 
}
72
 
 
73
 
QString CanvasBand::getXml()
74
 
{
75
 
    QString result = "";
76
 
    std::map<QString, PropPtr >::const_iterator it;
77
 
    for (it = props.begin(); it != props.end(); ++it)
78
 
    {
79
 
        if (it->second->allowSaving())
80
 
        result += " " + it->first + "=" + "\"" + it->second->value() + "\"";
81
 
    }
82
 
    result += ">\n";
83
 
    for (QCanvasItemList::Iterator it=items.begin(); it!=items.end(); ++it)
84
 
    {
85
 
        result += ((CanvasReportItem *)(*it))->getXml();
86
 
    }
87
 
    return result;
88
 
}
89
 
 
90
 
int CanvasBand::isInHolder(const QPoint p)
91
 
{
92
 
    if (bottomMiddleResizableRect().contains(p)) return (ResizeBottom);
93
 
    return ResizeNothing;
94
 
}
95
 
 
96
 
void CanvasBand::drawHolders(QPainter &painter)
97
 
{
98
 
    painter.setPen(QColor(0, 0, 0));
99
 
    #ifndef PURE_QT
100
 
    painter.setBrush(KGlobalSettings::highlightColor());
101
 
    #else
102
 
    painter.setBrush(QColor(160, 160, 160));
103
 
    #endif
104
 
    painter.drawRect(bottomMiddleResizableRect());
105
 
}
106
 
 
107
 
QRect CanvasBand::bottomMiddleResizableRect()
108
 
{
109
 
    return QRect((int)(x()+width()/2-HolderSize/2.), (int)(y()+height()-HolderSize), HolderSize, HolderSize);
110
 
}
111
 
 
112
 
void CanvasBand::updateGeomProps()
113
 
{
114
 
    props["Height"]->setValue(QString("%1").arg(height()));
115
 
    ((MyCanvas *)canvas())->templ->arrangeSections();
116
 
}
117
 
 
118
 
CanvasBand::~CanvasBand()
119
 
{
120
 
    for (QCanvasItemList::Iterator it = items.begin(); it != items.end(); ++it)
121
 
    {
122
 
//  (*it)->hide();
123
 
        ((MyCanvas *)canvas())->selected.remove((CanvasBox*)(*it));
124
 
        (*it)->setSelected(false);
125
 
        delete (*it);
126
 
    }
127
 
    items.clear();
128
 
}