/
qgscomposerframe.cpp
133 lines (115 loc) · 3.78 KB
/
qgscomposerframe.cpp
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
/***************************************************************************
qgscomposerframe.cpp
------------------------------------------------------------
begin : July 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************
* *
* 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 "qgscomposerframe.h"
#include "qgscomposermultiframe.h"
#include "qgscomposition.h"
QgsComposerFrame::QgsComposerFrame( QgsComposition* c, QgsComposerMultiFrame* mf, qreal x, qreal y, qreal width, qreal height )
: QgsComposerItem( x, y, width, height, c )
, mMultiFrame( mf )
{
//repaint frame when multiframe content changes
connect( mf, SIGNAL( contentsChanged() ), this, SLOT( repaint() ) );
}
QgsComposerFrame::QgsComposerFrame()
: QgsComposerItem( 0, 0, 0, 0, 0 )
, mMultiFrame( 0 )
{
}
QgsComposerFrame::~QgsComposerFrame()
{
}
bool QgsComposerFrame::writeXML( QDomElement& elem, QDomDocument & doc ) const
{
QDomElement frameElem = doc.createElement( "ComposerFrame" );
frameElem.setAttribute( "sectionX", QString::number( mSection.x() ) );
frameElem.setAttribute( "sectionY", QString::number( mSection.y() ) );
frameElem.setAttribute( "sectionWidth", QString::number( mSection.width() ) );
frameElem.setAttribute( "sectionHeight", QString::number( mSection.height() ) );
elem.appendChild( frameElem );
return _writeXML( frameElem, doc );
}
bool QgsComposerFrame::readXML( const QDomElement& itemElem, const QDomDocument& doc )
{
double x = itemElem.attribute( "sectionX" ).toDouble();
double y = itemElem.attribute( "sectionY" ).toDouble();
double width = itemElem.attribute( "sectionWidth" ).toDouble();
double height = itemElem.attribute( "sectionHeight" ).toDouble();
mSection = QRectF( x, y, width, height );
QDomElement composerItem = itemElem.firstChildElement( "ComposerItem" );
if ( composerItem.isNull() )
{
return false;
}
return _readXML( composerItem, doc );
}
QString QgsComposerFrame::displayName() const
{
if ( !id().isEmpty() )
{
return id();
}
if ( mMultiFrame )
{
return mMultiFrame->displayName();
}
return tr( "<frame>" );
}
void QgsComposerFrame::setSceneRect( const QRectF &rectangle )
{
QRectF fixedRect = rectangle;
QSizeF fixedSize = mMultiFrame->fixedFrameSize();
if ( fixedSize.width() > 0 )
{
fixedRect.setWidth( fixedSize.width() );
}
if ( fixedSize.height() > 0 )
{
fixedRect.setHeight( fixedSize.height() );
}
QgsComposerItem::setSceneRect( fixedRect );
}
void QgsComposerFrame::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
Q_UNUSED( itemStyle );
Q_UNUSED( pWidget );
if ( !painter )
{
return;
}
drawBackground( painter );
if ( mMultiFrame )
{
mMultiFrame->render( painter, mSection );
}
drawFrame( painter );
if ( isSelected() )
{
drawSelectionBoxes( painter );
}
}
void QgsComposerFrame::beginItemCommand( const QString& text )
{
if ( mComposition )
{
mComposition->beginMultiFrameCommand( multiFrame(), text );
}
}
void QgsComposerFrame::endItemCommand()
{
if ( mComposition )
{
mComposition->endMultiFrameCommand();
}
}