Skip to content
Permalink
Browse files

Implemented new resize modes for multiframe item (currently only html)

  • Loading branch information
mhugent committed Aug 17, 2012
1 parent a37611e commit 8e02e1f90f06b3a5269f35f542f343920071f200
@@ -9,7 +9,9 @@ public:
enum ResizeMode
{
UseExistingFrames = 0,
ExtendToNextPage //duplicates last frame to next page to fit the total size
ExtendToNextPage, //uses the next page(s) until the content has been printed
RepeatOnEveryPage, //repeats the same frame on every page
RepeatUntilFinished //duplicates last frame to next page to fit the total size
};

QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands );
@@ -41,4 +43,4 @@ public:
void deleteFrames();

int nFrames() const;
};
};
@@ -19,6 +19,7 @@
QgsComposerMultiFrame::QgsComposerMultiFrame( QgsComposition* c, bool createUndoCommands ): mComposition( c ), mResizeMode( UseExistingFrames ), mCreateUndoCommands( createUndoCommands )
{
mComposition->addMultiFrame( this );
connect( mComposition, SIGNAL( nPagesChanged() ), this, SLOT( handlePageChange() ) );
}

QgsComposerMultiFrame::QgsComposerMultiFrame(): mComposition( 0 ), mResizeMode( UseExistingFrames )
@@ -61,7 +62,7 @@ void QgsComposerMultiFrame::recalculateFrameSizes()

for ( int i = 0; i < mFrameItems.size(); ++i )
{
if ( currentY >= totalHeight )
if ( mResizeMode != RepeatOnEveryPage && currentY >= totalHeight )
{
if ( mResizeMode == RepeatUntilFinished || mResizeMode == ExtendToNextPage ) //remove unneeded frames in extent mode
{
@@ -75,7 +76,14 @@ void QgsComposerMultiFrame::recalculateFrameSizes()

currentItem = mFrameItems.value( i );
currentHeight = currentItem->rect().height();
currentItem->setContentSection( QRectF( 0, currentY, currentItem->rect().width(), currentHeight ) );
if ( mResizeMode == RepeatOnEveryPage )
{
currentItem->setContentSection( QRectF( 0, 0, currentItem->rect().width(), currentHeight ) );
}
else
{
currentItem->setContentSection( QRectF( 0, currentY, currentItem->rect().width(), currentHeight ) );
}
currentItem->update();
currentY += currentHeight;
}
@@ -133,13 +141,55 @@ void QgsComposerMultiFrame::handleFrameRemoval( QgsComposerItem* item )
}
}

void QgsComposerMultiFrame::handlePageChange()
{
if ( mComposition->numPages() < 1 )
{
return;
}

if ( mResizeMode != RepeatOnEveryPage )
{
return;
}

//remove items beginning on non-existing pages
for ( int i = 0; i < mFrameItems.size(); ++i )
{
QgsComposerFrame* frame = mFrameItems[i];
int page = frame->transform().dy() / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() );
if ( page > ( mComposition->numPages() - 1 ) )
{
removeFrame( i );
}
}

//page number of the last item
QgsComposerFrame* lastFrame = mFrameItems.last();
int lastItemPage = lastFrame->transform().dy() / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() );

for ( int i = lastItemPage + 1; i < mComposition->numPages(); ++i )
{
//copy last frame to current page
QgsComposerFrame* newFrame = new QgsComposerFrame( mComposition, this, lastFrame->transform().dx(),
lastFrame->transform().dy() + mComposition->paperHeight() + mComposition->spaceBetweenPages(),
lastFrame->rect().width(), lastFrame->rect().height() );
addFrame( newFrame, false );
lastFrame = newFrame;
}

recalculateFrameSizes();
update();
}

void QgsComposerMultiFrame::removeFrame( int i )
{
QgsComposerFrame* frameItem = mFrameItems[i];
if ( mComposition )
{
mComposition->removeComposerItem( frameItem );
}
mFrameItems.removeAt( i );
}

void QgsComposerMultiFrame::update()
@@ -82,6 +82,8 @@ class CORE_EXPORT QgsComposerMultiFrame: public QObject
void recalculateFrameSizes();
/**Called before a frame is going to be removed (update frame list)*/
void handleFrameRemoval( QgsComposerItem* item );
/**Adapts to changed number of pages if resize type is RepeatOnEveryPage*/
void handlePageChange();

private:
QgsComposerMultiFrame(); //forbidden
@@ -118,6 +118,7 @@ void QgsComposition::setNumPages( int pages )
mPages.removeLast();
}
}
emit nPagesChanged();
}

int QgsComposition::numPages() const
@@ -311,6 +311,7 @@ class CORE_EXPORT QgsComposition: public QGraphicsScene

signals:
void paperSizeChanged();
void nPagesChanged();

/**Is emitted when selected item changed. If 0, no item is selected*/
void selectedItemChanged( QgsComposerItem* selected );

0 comments on commit 8e02e1f

Please sign in to comment.
You can’t perform that action at this time.