Beispiel #1
0
void KoView::slotAutoScroll(  )
{
    QPoint scrollDistance;
    bool actuallyDoScroll = false;
    QPoint pos( mapFromGlobal( QCursor::pos() ) );

    //Provide progressive scrolling depending on the mouse position
    if ( pos.y() < topBorder() )
    {
        scrollDistance.setY ((int) - autoScrollAcceleration( - pos.y() + topBorder() ));
        actuallyDoScroll = true;
    }
    else if ( pos.y() > height() - bottomBorder() )
    {
        scrollDistance.setY ((int) autoScrollAcceleration(pos.y() - height() + bottomBorder() ));
        actuallyDoScroll = true;
    }

    if ( pos.x() < leftBorder() )
    {
        scrollDistance.setX ((int) - autoScrollAcceleration( - pos.x() + leftBorder() ));
        actuallyDoScroll = true;
    }
    else if ( pos.x() > width() - rightBorder() )
    {
        scrollDistance.setX ((int) autoScrollAcceleration( pos.x() - width() + rightBorder() ));
        actuallyDoScroll = true;
    }

    if ( actuallyDoScroll )
    {
        int state=0;
#if KDE_IS_VERSION(3,4,0)
        state = kapp->keyboardMouseState();
#endif

        pos = canvas()->mapFrom(this, pos);
        QMouseEvent * event = new QMouseEvent(QEvent::MouseMove, pos, 0, state);

        QApplication::postEvent( canvas(), event );
        emit autoScroll( scrollDistance );
    }
}
Beispiel #2
0
double PageItem_Table::maxTopBorderWidth() const
{
	double maxWidth = 0.0;
	TableCell cell;
	for (int col = 0; col < columns(); col += cell.columnSpan())
	{
		cell = cellAt(0, col);
		maxWidth = qMax(maxWidth, TableUtils::collapseBorders(cell.topBorder(), topBorder()).width());
	}
	return maxWidth;
}
Beispiel #3
0
void Decorator::drawFrame(Pictures& stack, const Rect& rectangle, const int picId )
{
   // pics are: 0TopLeft, 1Top, 2TopRight, 3Left, 4Center, 5Right, 6BottomLeft, 7Bottom, 8BottomRight

   // draws the inside of the box
  Picture bg( gui::rc.panel, picId+4);
  const int sw = bg.width();
  const int sh = bg.height();
  for (int j = 0; j<(rectangle.height()/sh-1); ++j)
  {
     for (int i = 0; i<(rectangle.width()/sw-1); ++i)
     {
        stack.append( bg, rectangle.lefttop() + Point( sw+sw*i, sh+sh*j ) );
     }
  }

  // draws horizontal borders
  Picture topBorder( gui::rc.panel, picId+1);
  Picture bottomBorder( gui::rc.panel, picId+7);
  for (int i = 0; i<(rectangle.width()/sw-1); ++i)
  {
     stack.append( topBorder, rectangle.lefttop() + Point( sw+sw*i, 0 ));
     stack.append( bottomBorder, rectangle.lefttop() + Point( sw+sw*i, rectangle.height()-sh ) );
  }

  // draws vertical borders
  Picture leftBorder( gui::rc.panel, picId+3);
  Picture rightBorder( gui::rc.panel, picId+5);
  for (int i = 0; i<(rectangle.height()/sh-1); ++i)
  {
     stack.append( leftBorder, rectangle.lefttop() + Point( 0, sh+sh*i ) );
     stack.append( rightBorder, rectangle.lefttop() + Point( rectangle.width()-sw, sh+sh*i ) );
  }

  // topLeft corner
  stack.append( Picture( gui::rc.panel, picId+0), rectangle.lefttop() );
  // topRight corner
  stack.append( Picture( gui::rc.panel, picId+2), Point( rectangle.right()-sh, rectangle.top() ) );
  // bottomLeft corner
  stack.append( Picture( gui::rc.panel, picId+6), Point( rectangle.left(), rectangle.bottom() - sh ) );
  // bottomRight corner
  stack.append( Picture( gui::rc.panel, picId+8), rectangle.rightbottom() - Point( 16, 16 ) );
}
Beispiel #4
0
void UIWidget::drawImage(const Rect& screenCoords)
{
    if(!m_imageTexture || !screenCoords.isValid())
        return;

    // cache vertex buffers
    if(m_imageCachedScreenCoords != screenCoords || m_imageMustRecache) {
        m_imageCoordsBuffer.clear();
        m_imageCachedScreenCoords = screenCoords;
        m_imageMustRecache = false;

        Rect drawRect = screenCoords;
        drawRect.translate(m_imageRect.topLeft());
        if(m_imageRect.isValid())
            drawRect.resize(m_imageRect.size());

        Rect clipRect = m_imageClipRect.isValid() ? m_imageClipRect : Rect(0, 0, m_imageTexture->getSize());

        if(!m_imageBordered) {
            if(m_imageFixedRatio) {
                Size textureSize = m_imageTexture->getSize();

                Size textureClipSize = drawRect.size();
                textureClipSize.scale(textureSize, Fw::KeepAspectRatio);

                Point texCoordsOffset;
                if(textureSize.height() > textureClipSize.height())
                    texCoordsOffset.y = (textureSize.height() - textureClipSize.height())/2;
                else if(textureSize.width() > textureClipSize.width())
                    texCoordsOffset.x = (textureSize.width() - textureClipSize.width())/2;

                Rect textureClipRect(texCoordsOffset, textureClipSize);

                m_imageCoordsBuffer.addRect(drawRect, textureClipRect);
            } else {
                if(m_imageRepeated)
                    m_imageCoordsBuffer.addRepeatedRects(drawRect, clipRect);
                else
                    m_imageCoordsBuffer.addRect(drawRect, clipRect);
            }
        } else {
            int top = m_imageBorder.top;
            int bottom = m_imageBorder.bottom;
            int left =  m_imageBorder.left;
            int right  = m_imageBorder.right;

            // calculates border coords
            const Rect clip = clipRect;
            Rect leftBorder(clip.left(), clip.top() + top, left, clip.height() - top - bottom);
            Rect rightBorder(clip.right() - right + 1, clip.top() + top, right, clip.height() - top - bottom);
            Rect topBorder(clip.left() + left, clip.top(), clip.width() - right - left, top);
            Rect bottomBorder(clip.left() + left, clip.bottom() - bottom + 1, clip.width() - right - left, bottom);
            Rect topLeftCorner(clip.left(), clip.top(), left, top);
            Rect topRightCorner(clip.right() - right + 1, clip.top(), right, top);
            Rect bottomLeftCorner(clip.left(), clip.bottom() - bottom + 1, left, bottom);
            Rect bottomRightCorner(clip.right() - right + 1, clip.bottom() - bottom + 1, right, bottom);
            Rect center(clip.left() + left, clip.top() + top, clip.width() - right - left, clip.height() - top - bottom);
            Size bordersSize(leftBorder.width() + rightBorder.width(), topBorder.height() + bottomBorder.height());
            Size centerSize = drawRect.size() - bordersSize;
            Rect rectCoords;

            // first the center
            if(centerSize.area() > 0) {
                rectCoords = Rect(drawRect.left() + leftBorder.width(), drawRect.top() + topBorder.height(), centerSize);
                m_imageCoordsBuffer.addRepeatedRects(rectCoords, center);
            }
            // top left corner
            rectCoords = Rect(drawRect.topLeft(), topLeftCorner.size());
            m_imageCoordsBuffer.addRepeatedRects(rectCoords, topLeftCorner);
            // top
            rectCoords = Rect(drawRect.left() + topLeftCorner.width(), drawRect.topLeft().y, centerSize.width(), topBorder.height());
            m_imageCoordsBuffer.addRepeatedRects(rectCoords, topBorder);
            // top right corner
            rectCoords = Rect(drawRect.left() + topLeftCorner.width() + centerSize.width(), drawRect.top(), topRightCorner.size());
            m_imageCoordsBuffer.addRepeatedRects(rectCoords, topRightCorner);
            // left
            rectCoords = Rect(drawRect.left(), drawRect.top() + topLeftCorner.height(), leftBorder.width(), centerSize.height());
            m_imageCoordsBuffer.addRepeatedRects(rectCoords, leftBorder);
            // right
            rectCoords = Rect(drawRect.left() + leftBorder.width() + centerSize.width(), drawRect.top() + topRightCorner.height(), rightBorder.width(), centerSize.height());
            m_imageCoordsBuffer.addRepeatedRects(rectCoords, rightBorder);
            // bottom left corner
            rectCoords = Rect(drawRect.left(), drawRect.top() + topLeftCorner.height() + centerSize.height(), bottomLeftCorner.size());
            m_imageCoordsBuffer.addRepeatedRects(rectCoords, bottomLeftCorner);
            // bottom
            rectCoords = Rect(drawRect.left() + bottomLeftCorner.width(), drawRect.top() + topBorder.height() + centerSize.height(), centerSize.width(), bottomBorder.height());
            m_imageCoordsBuffer.addRepeatedRects(rectCoords, bottomBorder);
            // bottom right corner
            rectCoords = Rect(drawRect.left() + bottomLeftCorner.width() + centerSize.width(), drawRect.top() + topRightCorner.height() + centerSize.height(), bottomRightCorner.size());
            m_imageCoordsBuffer.addRepeatedRects(rectCoords, bottomRightCorner);
        }
    }

    // smooth is now enabled by default for all textures
    //m_imageTexture->setSmooth(m_imageSmooth);

    g_painter->setColor(m_imageColor);
    g_painter->drawTextureCoords(m_imageCoordsBuffer, m_imageTexture);
}
Beispiel #5
0
bool kpToolAutoCrop (kpMainWindow *mainWindow)
{
#if DEBUG_KP_TOOL_AUTO_CROP
    kdDebug () << "kpToolAutoCrop() CALLED!" << endl;
#endif

    if (!mainWindow)
    {
        kdError () << "kpToolAutoCrop() passed NULL mainWindow" << endl;
        return false;
    }

    kpDocument *doc = mainWindow->document ();
    if (!doc)
    {
        kdError () << "kpToolAutoCrop() passed NULL document" << endl;
        return false;
    }

    // OPT: if already pulled selection pixmap, no need to do it again here
    QPixmap pixmap = doc->selection () ? doc->getSelectedPixmap () : *doc->pixmap ();
    if (pixmap.isNull ())
    {
        kdError () << "kptoolAutoCrop() pased NULL pixmap" << endl;
        return false;
    }

    kpViewManager *vm = mainWindow->viewManager ();
    if (!vm)
    {
        kdError () << "kpToolAutoCrop() passed NULL vm" << endl;
        return false;
    }

    int processedColorSimilarity = mainWindow->colorToolBar ()->processedColorSimilarity ();
    kpToolAutoCropBorder leftBorder (&pixmap, processedColorSimilarity),
                         rightBorder (&pixmap, processedColorSimilarity),
                         topBorder (&pixmap, processedColorSimilarity),
                         botBorder (&pixmap, processedColorSimilarity);


    kpSetOverrideCursorSaver cursorSaver (Qt::waitCursor);

    // TODO: With Colour Similarity, a lot of weird (and wonderful) things can
    //       happen resulting in a huge number of code paths.  Needs refactoring
    //       and regression testing.
    //
    // TODO: e.g. When the top fills entire rect but bot doesn't we could
    //       invalidate top and continue autocrop.
    int numRegions = 0;
    if (!leftBorder.calculate (true/*x*/, +1/*going right*/) ||
            leftBorder.fillsEntirePixmap () ||
            !rightBorder.calculate (true/*x*/, -1/*going left*/) ||
            rightBorder.fillsEntirePixmap () ||
            !topBorder.calculate (false/*y*/, +1/*going down*/) ||
            topBorder.fillsEntirePixmap () ||
            !botBorder.calculate (false/*y*/, -1/*going up*/) ||
            botBorder.fillsEntirePixmap () ||
            ((numRegions = leftBorder.exists () +
                           rightBorder.exists () +
                           topBorder.exists () +
                           botBorder.exists ()) == 0))
    {
#if DEBUG_KP_TOOL_AUTO_CROP
        kdDebug () << "\tcan't find border; leftBorder.rect=" << leftBorder.rect ()
                   << " rightBorder.rect=" << rightBorder.rect ()
                   << " topBorder.rect=" << topBorder.rect ()
                   << " botBorder.rect=" << botBorder.rect ()
                   << endl;
#endif
        ::showNothingToAutocropMessage (mainWindow, (bool) doc->selection ());
        return false;
    }

#if DEBUG_KP_TOOL_AUTO_CROP
    kdDebug () << "\tnumRegions=" << numRegions << endl;
    kdDebug () << "\t\tleft=" << leftBorder.rect ()
               << " refCol=" << (leftBorder.exists () ? (int *) leftBorder.referenceColor ().toQRgb () : 0)
               << " avgCol=" << (leftBorder.exists () ? (int *) leftBorder.averageColor ().toQRgb () : 0)
               << endl;
    kdDebug () << "\t\tright=" << rightBorder.rect ()
               << " refCol=" << (rightBorder.exists () ? (int *) rightBorder.referenceColor ().toQRgb () : 0)
               << " avgCol=" << (rightBorder.exists () ? (int *) rightBorder.averageColor ().toQRgb () : 0)
               << endl;
    kdDebug () << "\t\ttop=" << topBorder.rect ()
               << " refCol=" << (topBorder.exists () ? (int *) topBorder.referenceColor ().toQRgb () : 0)
               << " avgCol=" << (topBorder.exists () ? (int *) topBorder.averageColor ().toQRgb () : 0)
               << endl;
    kdDebug () << "\t\tbot=" << botBorder.rect ()
               << " refCol=" << (botBorder.exists () ? (int *) botBorder.referenceColor ().toQRgb () : 0)
               << " avgCol=" << (botBorder.exists () ? (int *) botBorder.averageColor ().toQRgb () : 0)
               << endl;
#endif


    // In case e.g. the user pastes a solid, coloured-in rectangle,
    // we favour killing the bottom and right regions
    // (these regions probably contain the unwanted whitespace due
    //  to the doc being bigger than the pasted selection to start with).
    //
    // We also kill if they kiss or even overlap.

    if (leftBorder.exists () && rightBorder.exists ())
    {
        const kpColor leftCol = leftBorder.averageColor ();
        const kpColor rightCol = rightBorder.averageColor ();

        if ((numRegions == 2 && !leftCol.isSimilarTo (rightCol, processedColorSimilarity)) ||
                leftBorder.right () >= rightBorder.left () - 1)  // kissing or overlapping
        {
#if DEBUG_KP_TOOL_AUTO_CROP
            kdDebug () << "\tignoring left border" << endl;
#endif
            leftBorder.invalidate ();
        }
    }

    if (topBorder.exists () && botBorder.exists ())
    {
        const kpColor topCol = topBorder.averageColor ();
        const kpColor botCol = botBorder.averageColor ();

        if ((numRegions == 2 && !topCol.isSimilarTo (botCol, processedColorSimilarity)) ||
                topBorder.bottom () >= botBorder.top () - 1)  // kissing or overlapping
        {
#if DEBUG_KP_TOOL_AUTO_CROP
            kdDebug () << "\tignoring top border" << endl;
#endif
            topBorder.invalidate ();
        }
    }


    mainWindow->addImageOrSelectionCommand (
        new kpToolAutoCropCommand (
            (bool) doc->selection (),
            leftBorder, rightBorder,
            topBorder, botBorder,
            mainWindow));


    return true;
}
	void TableCellPropertiesMapping::Apply (IVisitable* visited)
	{
		TablePropertyExceptions* tapx	=	static_cast<TablePropertyExceptions*>(visited);
		int nComputedCellWidth			=	0;

		std::list<SinglePropertyModifier>::const_reverse_iterator rend = tapx->grpprl->rend();
		for (std::list<SinglePropertyModifier>::const_reverse_iterator iter = tapx->grpprl->rbegin(); iter != rend; ++iter)
		{
			switch (iter->OpCode)
			{				
				case sprmOldTDefTable:	
				case sprmTDefTable:	
				{
					SprmTDefTable tdef(iter->Arguments, iter->argumentsSize);
					int cc = tdef.numberOfColumns;

					_tGrid = tdef.rgdxaCenter;
                    _tcDef = tdef.rgTc80[(std::min)(_cellIndex,  (int)tdef.rgTc80.size() - 1)];	// NOTE: fix for crash

					appendValueElement( _tcPr, _T( "textDirection" ), FormatUtils::MapValueToWideString( _tcDef.textFlow, &Global::TextFlowMap[0][0], 6, 6 ).c_str(), false );

					if ( _tcDef.vertMerge == Global::fvmMerge )
					{
						appendValueElement( _tcPr, _T( "vMerge" ), _T( "continue" ), false );
					}
					else if ( _tcDef.vertMerge == Global::fvmRestart )
					{
						appendValueElement( _tcPr, _T( "vMerge" ), _T( "restart" ), false );
					}

					appendValueElement( _tcPr, _T( "vAlign" ), FormatUtils::MapValueToWideString( _tcDef.vertAlign, &Global::VerticalAlignMap[0][0], 3, 7 ).c_str(), false );

					if ( _tcDef.fFitText )
					{
						appendValueElement( _tcPr, _T( "tcFitText" ), _T( "" ), false );
					}

					if ( _tcDef.fNoWrap )
					{
						appendValueElement( _tcPr, _T( "noWrap" ), _T( "" ), true );
					}

                    nComputedCellWidth = (short)( tdef.rgdxaCenter[(size_t)(std::min)(_cellIndex,  (int)tdef.rgTc80.size() - 1) + 1] -
                        tdef.rgdxaCenter[(std::min)(_cellIndex, (int)tdef.rgTc80.size() - 1)] );	// NOTE: fix for crash

					if (!IsTableBordersDefined(tapx->grpprl))
					{											//borders

						RELEASEOBJECT(_brcTop);
						_brcTop = new BorderCode(*_tcDef.brcTop);

						RELEASEOBJECT(_brcLeft);
						_brcLeft = new BorderCode(*_tcDef.brcLeft);

						RELEASEOBJECT(_brcRight);
						_brcRight = new BorderCode(*_tcDef.brcRight);

						RELEASEOBJECT(_brcBottom);
						_brcBottom = new BorderCode(*_tcDef.brcBottom);
					}
				}
				break;

				case sprmTCellPadding:
				{							//margins

					unsigned char first		=	iter->Arguments[0];
					unsigned char lim		=	iter->Arguments[1];
					unsigned char ftsMargin	=	iter->Arguments[3];
					short wMargin	=	FormatUtils::BytesToInt16( iter->Arguments, 4, iter->argumentsSize );

					if ( ( _cellIndex >= first ) && ( _cellIndex < lim ) )
					{
						if ( FormatUtils::GetBitFromInt( iter->Arguments[2], 0 ) == true )
						{
							appendDxaElement( _tcMar, _T( "top" ), FormatUtils::IntToWideString( wMargin ).c_str(), true );
						}

						if ( FormatUtils::GetBitFromInt( iter->Arguments[2], 1 ) == true )
						{
							appendDxaElement( _tcMar, _T( "left" ), FormatUtils::IntToWideString( wMargin ).c_str(), true );
						}

						if (  FormatUtils::GetBitFromInt( iter->Arguments[2], 2 ) == true )
						{
							appendDxaElement( _tcMar, _T( "bottom" ), FormatUtils::IntToWideString( wMargin ).c_str(), true );
						}

						if ( FormatUtils::GetBitFromInt( iter->Arguments[2], 3 ) == true )
						{
							appendDxaElement( _tcMar, _T( "right" ), FormatUtils::IntToWideString( wMargin ).c_str(), true );
						}
					}
				}
				break;

				case sprmTDefTableShd80:
				{
					if (!tapx->IsSkipShading97())	// если такой операнд единственный то учитываем его, иначе скипаем его
					{
						apppendCellShading(iter->Arguments, iter->argumentsSize, _cellIndex);
					}
				}break;

				case sprmOldTDefTableShd:
				case sprmTDefTableShd:
				{						//	cell shading for cells 0-20
					apppendCellShading(iter->Arguments, iter->argumentsSize, _cellIndex);
				}break;

				case sprmTDefTableShd2nd:
				{						//	cell shading for cells 21-42
					apppendCellShading(iter->Arguments, iter->argumentsSize, (_cellIndex - 21));
				}break;

				case sprmTDefTableShd3rd:
				{						//	cell shading for cells 43-62
					apppendCellShading(iter->Arguments, iter->argumentsSize, (_cellIndex - 43));
				}break;

				case sprmTCellWidth:
				{				//width
					unsigned char first		=	iter->Arguments[0];
					unsigned char lim		=	iter->Arguments[1];

					if ((_cellIndex >= first) && (_cellIndex < lim))
					{
						_ftsWidth	=	(Global::CellWidthType)(iter->Arguments[2]);
						_width		=	FormatUtils::BytesToInt16(iter->Arguments, 3, iter->argumentsSize);
					}
				}
				break;
				
				case sprmTVertAlign:
				{							//vertical alignment
					unsigned char first		=	iter->Arguments[0];
					unsigned char lim		=	iter->Arguments[1];

					if ((_cellIndex >= first) && (_cellIndex < lim))
					{
						appendValueElement(_tcPr, _T( "vAlign" ), FormatUtils::MapValueToWideString( (VerticalCellAlignment)iter->Arguments[2], &VerticalCellAlignmentMap[0][0], 3, 7 ).c_str(), true );
					}
				}
				break;

				case sprmTFitText:
				{				//Autofit
					unsigned char first = iter->Arguments[0];
					unsigned char lim = iter->Arguments[1];

					if ( ( _cellIndex >= first ) && ( _cellIndex < lim ) )
					{
						appendValueElement( _tcPr, _T( "tcFitText" ), FormatUtils::IntToWideString( iter->Arguments[2] ).c_str(), true );
					}
				}
				break;

				case sprmOldTSetBrc:
				case sprmTSetBrc:
				{					//borders (cell definition)
					unsigned char min = iter->Arguments[0];
					unsigned char max = iter->Arguments[1];

					int bordersToApply = (int)( iter->Arguments[2] );

					if ( ( _cellIndex >= min ) && ( _cellIndex < max ) )
					{
						const int brcSize = 8;
						unsigned char brcBytes[brcSize];
						memcpy( brcBytes, ( iter->Arguments + 3 ), brcSize );

						if( FormatUtils::BitmaskToBool( bordersToApply, 0x01 ) )
						{
							RELEASEOBJECT( _brcTop );
							_brcTop = new BorderCode( brcBytes, brcSize );
						}

						if( FormatUtils::BitmaskToBool( bordersToApply, 0x02 ) )
						{
							RELEASEOBJECT( _brcLeft );
							_brcLeft = new BorderCode( brcBytes, brcSize );
						}

						if ( FormatUtils::BitmaskToBool( bordersToApply, 0x04 ) )
						{
							RELEASEOBJECT( _brcBottom );
							_brcBottom = new BorderCode( brcBytes, brcSize );
						}

						if ( FormatUtils::BitmaskToBool( bordersToApply, 0x08 ) )
						{
							RELEASEOBJECT( _brcRight );
							_brcRight = new BorderCode( brcBytes, brcSize );
						}
					}
				}
				break;
			}
		}

		//width
		XMLTools::XMLElement<wchar_t> tcW( _T( "w:tcW" ) );
		XMLTools::XMLAttribute<wchar_t> tcWType( _T( "w:type" ), FormatUtils::MapValueToWideString( _ftsWidth, &Global::CellWidthTypeMap[0][0], 4, 5 ).c_str() );
		XMLTools::XMLAttribute<wchar_t> tcWVal( _T( "w:w" ), FormatUtils::IntToWideString( _width ).c_str() );
		tcW.AppendAttribute( tcWType );
		tcW.AppendAttribute( tcWVal );
		_tcPr->AppendChild( tcW );

		//grid span
		_gridSpan = 1;

		if ( ( _gridIndex < (int)_grid->size() ) && ( nComputedCellWidth > _grid->at( _gridIndex ) ) )
		{
			//check the number of merged cells
			int w = _grid->at( _gridIndex );

			for ( unsigned int i = _gridIndex + 1; i < _grid->size(); i++ )
			{
				_gridSpan++;

				w += _grid->at( i );

				if ( w >= nComputedCellWidth )
				{
					break;
				}
			}

			appendValueElement( _tcPr, _T( "gridSpan" ), FormatUtils::IntToWideString( _gridSpan ).c_str(), true );
		}

		//append margins
		if (_tcMar->GetChildCount() > 0)
		{
			_tcPr->AppendChild( *(_tcMar) );
		}

		//append borders
		if (_brcTop)
		{
			XMLTools::XMLElement<wchar_t> topBorder(_T("w:top"));
			appendBorderAttributes(_brcTop, &topBorder);
			addOrSetBorder(_tcBorders, &topBorder );
		}

		if (_brcLeft )
		{
			XMLTools::XMLElement<wchar_t> leftBorder(_T("w:left"));
			appendBorderAttributes(_brcLeft, &leftBorder);
			addOrSetBorder(_tcBorders, &leftBorder);
		}

		if (_brcBottom)
		{
			XMLTools::XMLElement<wchar_t> bottomBorder(_T("w:bottom"));
			appendBorderAttributes(_brcBottom, &bottomBorder);
			addOrSetBorder(_tcBorders, &bottomBorder);
		}

		if (_brcRight)
		{
			XMLTools::XMLElement<wchar_t> rightBorder( _T( "w:right" ) );
			appendBorderAttributes( _brcRight, &rightBorder );
			addOrSetBorder( _tcBorders, &rightBorder );
		}

		if ( _tcBorders->GetChildCount() > 0 )
		{
			_tcPr->AppendChild( *(_tcBorders) );
		}

		//write Properties
		if ((_tcPr->GetChildCount() > 0) || (_tcPr->GetAttributeCount() > 0))
			m_pXmlWriter->WriteString(_tcPr->GetXMLString().c_str());
	}
void PageItem_Table::getNamedResources(ResourceCollection& lists) const
{
	TableBorder lborder = leftBorder();
	foreach (const TableBorderLine& line, lborder.borderLines())
	{
		if (line.color() == CommonStrings::None)
			continue;
		lists.collectColor(line.color());
	}

	TableBorder rborder = rightBorder();
	foreach (const TableBorderLine& line, rborder.borderLines())
	{
		if (line.color() == CommonStrings::None)
			continue;
		lists.collectColor(line.color());
	}

	TableBorder bborder = bottomBorder();
	foreach (const TableBorderLine& line, bborder.borderLines())
	{
		if (line.color() == CommonStrings::None)
			continue;
		lists.collectColor(line.color());
	}

	TableBorder tborder = topBorder();
	foreach (const TableBorderLine& line, tborder.borderLines())
	{
		if (line.color() == CommonStrings::None)
			continue;
		lists.collectColor(line.color());
	}

	QString tableStyleName = this->styleName();
	if (!tableStyleName.isEmpty())
		lists.collectTableStyle(tableStyleName);

	for (int row = 0; row < rows(); ++row)
	{
		int colSpan = 0;
		for (int col = 0; col < columns(); col += colSpan)
		{
			TableCell cell = cellAt(row, col);
			PageItem_TextFrame* textFrame = cell.textFrame();
			textFrame->getNamedResources(lists);

			QString cellStyle = cell.styleName();
			if (!cellStyle.isEmpty())
				lists.collectCellStyle(cellStyle);

			QString cellFill = cell.fillColor();
			if (cellFill != CommonStrings::None)
				lists.collectColor(cellFill);

			lborder = cell.leftBorder();
			foreach (const TableBorderLine& line, lborder.borderLines())
			{
				if (line.color() == CommonStrings::None)
					continue;
				lists.collectColor(line.color());
			}

			rborder = cell.rightBorder();
			foreach (const TableBorderLine& line, rborder.borderLines())
			{
				if (line.color() == CommonStrings::None)
					continue;
				lists.collectColor(line.color());
			}

			bborder = cell.bottomBorder();
			foreach (const TableBorderLine& line, bborder.borderLines())
			{
				if (line.color() == CommonStrings::None)
					continue;
				lists.collectColor(line.color());
			}

			tborder = cell.topBorder();
			foreach (const TableBorderLine& line, tborder.borderLines())
			{
				if (line.color() == CommonStrings::None)
					continue;
				lists.collectColor(line.color());
			}

			colSpan = cell.columnSpan();
		}
	}

	PageItem::getNamedResources(lists);
}
std::string MapEditor::blockType(Terrain* terrain){

	bool leftOccupied(false);
	bool rightOccupied(false);
	bool topOccupied(false);
	bool botOccupied(false);
	bool topLeftOccupied(true);
	bool topRightOccupied(true);
	bool botLeftOccupied(true);
	bool botRightOccupied(true);

	sf::Vector2f thisPos(terrain->getPos());
	std::string returnString;

	Terrains relevantTerrains;
	for (Terrains::size_type i = 0; i < mTerrains.size(); i++){
		if (mTerrains[i]->getPos().x < thisPos.x + 200 && mTerrains[i]->getPos().x > thisPos.x - 200)
			if(mTerrains[i]->getType() == Terrain::BLOCK0 || 
				mTerrains[i]->getType() == Terrain::BLOCK0ICY || 
				mTerrains[i]->getType() == Terrain::BLOCK0WALLJUMP)
			relevantTerrains.push_back(mTerrains[i]);
	}

	
	sf::Vector2f leftBorder(thisPos.x - 1, 
		thisPos.y + (terrain->getHeight()/ 2));
	sf::Vector2f rightBorder(thisPos.x + terrain->getWidth() + 1, 
		thisPos.y + (terrain->getHeight() / 2));
	sf::Vector2f topBorder(thisPos.x + (terrain->getWidth() / 2), 
		thisPos.y - 1);
	sf::Vector2f botBorder(thisPos.x + (terrain->getWidth() / 2), 
		thisPos.y + (terrain->getHeight() + 1));
	sf::Vector2f topLeftBorder(terrain->getPos());
	topLeftBorder.x -= 1;
	topLeftBorder.y -= 1;
	sf::Vector2f topRightBorder(terrain->getPos());
	topRightBorder.x += terrain->getWidth() + 1;
	topRightBorder.y -= 1;
	sf::Vector2f botLeftBorder(terrain->getPos());
	botLeftBorder.x -= 1;
	botLeftBorder.y += terrain->getHeight() + 1;
	sf::Vector2f botRightBorder(terrain->getPos());
	botRightBorder.x += terrain->getWidth() + 1;
	botRightBorder.y += terrain->getHeight() + 1;

	for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++){
		if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &leftBorder))
			leftOccupied = true;
		if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &rightBorder))
			rightOccupied = true;
		if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &topBorder))
			topOccupied = true;
		if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &botBorder))
			botOccupied = true;
	}

	if (leftOccupied && rightOccupied && topOccupied && botOccupied)
		returnString.push_back('a');
	if (leftOccupied && rightOccupied && topOccupied && !botOccupied)
		returnString.push_back('b');
	if (leftOccupied && rightOccupied && !topOccupied && botOccupied)
		returnString.push_back('c');
	if (leftOccupied && !rightOccupied && topOccupied && botOccupied)
		returnString.push_back('d');
	if (!leftOccupied && rightOccupied && topOccupied && botOccupied)
		returnString.push_back('e');
	if (leftOccupied && rightOccupied && !topOccupied && !botOccupied)
		returnString.push_back('f');
	if (leftOccupied && !rightOccupied && topOccupied && !botOccupied)
		returnString.push_back('g');
	if (!leftOccupied && rightOccupied && topOccupied && !botOccupied)
		returnString.push_back('h');
	if (leftOccupied && !rightOccupied && !topOccupied && botOccupied)
		returnString.push_back('i');
	if (!leftOccupied && rightOccupied && !topOccupied && botOccupied)
		returnString.push_back('j');
	if (!leftOccupied && !rightOccupied && topOccupied && botOccupied)
		returnString.push_back('k');
	if (leftOccupied && !rightOccupied && !topOccupied && !botOccupied)
		returnString.push_back('l');
	if (!leftOccupied && rightOccupied && !topOccupied && !botOccupied)
		returnString.push_back('m');
	if (!leftOccupied && !rightOccupied && topOccupied && !botOccupied)
		returnString.push_back('n');
	if (!leftOccupied && !rightOccupied && !topOccupied && botOccupied)
		returnString.push_back('o');
	if (!leftOccupied && !rightOccupied && !topOccupied && !botOccupied)
		returnString.push_back('p');

	bool tileDecNeeded(false);

	if (returnString[0] == 'a') {
		topLeftOccupied = false;
		topRightOccupied = false;
		botLeftOccupied = false;
		botRightOccupied = false;
		for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++) {
		
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &topLeftBorder))
				topLeftOccupied = true;
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &topRightBorder))
				topRightOccupied = true;
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &botLeftBorder))
				botLeftOccupied = true;
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &botRightBorder))
				botRightOccupied = true;

		}
		tileDecNeeded = true;
	}
	if (returnString[0] == 'b') {
		topLeftOccupied = false;
		topRightOccupied = false;
		for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++) {

			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &topLeftBorder))
				topLeftOccupied = true;
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &topRightBorder))
				topRightOccupied = true;
		}
		tileDecNeeded = true;
	}
	if (returnString[0] == 'c') {
		botLeftOccupied = false;
		botRightOccupied = false;
		for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++) {
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &botLeftBorder))
				botLeftOccupied = true;
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &botRightBorder))
				botRightOccupied = true;
		}
		tileDecNeeded = true;
	}
	if (returnString[0] == 'd') {
		topLeftOccupied = false;
		botLeftOccupied = false;
		for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++) {
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &topLeftBorder))
				topLeftOccupied = true;
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &botLeftBorder))
				botLeftOccupied = true;
		}
		tileDecNeeded = true;
	}
	if (returnString[0] == 'e') {
		topRightOccupied = false;
		botRightOccupied = false;
		for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++) {
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &topRightBorder))
				topRightOccupied = true;
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &botRightBorder))
				botRightOccupied = true;
		}
		tileDecNeeded = true;
	}
	if (returnString[0] == 'g') {
		topLeftOccupied = false;
		for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++) {
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &topLeftBorder))
				topLeftOccupied = true;
		}
		tileDecNeeded = true;
	}
	if (returnString[0] == 'h') {
		topRightOccupied = false;
		for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++) {
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &topRightBorder))
				topRightOccupied = true;
		}
		tileDecNeeded = true;
	}
	if (returnString[0] == 'i') {
		botLeftOccupied = false;
		for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++) {
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &botLeftBorder))
				botLeftOccupied = true;
		}
		tileDecNeeded = true;
	}
	if (returnString[0] == 'j') {
		botRightOccupied = false;
		for (Terrains::size_type i = 0; i < relevantTerrains.size(); i++) {
			if (MapEditor::isSpriteClicked(relevantTerrains[i]->getSprite(), &botRightBorder))
				botRightOccupied = true;
		}
		tileDecNeeded = true;
	}
	if (tileDecNeeded) {
		if (!topLeftOccupied && !topRightOccupied && !botRightOccupied && !botLeftOccupied)
			returnString.push_back('a');
		if (topLeftOccupied && topRightOccupied && !botRightOccupied && !botLeftOccupied)
			returnString.push_back('b');
		if (!topLeftOccupied && topRightOccupied && botRightOccupied && !botLeftOccupied)
			returnString.push_back('c');
		if (topLeftOccupied && !topRightOccupied && !botRightOccupied && botLeftOccupied)
			returnString.push_back('d');
		if (!topLeftOccupied && !topRightOccupied && botRightOccupied && botLeftOccupied)
			returnString.push_back('e');
		if (!topLeftOccupied && topRightOccupied && botRightOccupied && botLeftOccupied)
			returnString.push_back('f');
		if (topLeftOccupied && !topRightOccupied && botRightOccupied && botLeftOccupied)
			returnString.push_back('g');
		if (topLeftOccupied && topRightOccupied && !botRightOccupied && botLeftOccupied)
			returnString.push_back('h');
		if (topLeftOccupied && topRightOccupied && botRightOccupied && !botLeftOccupied)
			returnString.push_back('i');
		if (topLeftOccupied && !topRightOccupied && !botRightOccupied && !botLeftOccupied)
			returnString.push_back('j');
		if (!topLeftOccupied && topRightOccupied && !botRightOccupied && !botLeftOccupied)
			returnString.push_back('k');
		if (!topLeftOccupied && !topRightOccupied && botRightOccupied && !botLeftOccupied)
			returnString.push_back('l');
		if (!topLeftOccupied && !topRightOccupied && !botRightOccupied && botLeftOccupied)
			returnString.push_back('m');	
	}

	return returnString;
}