Пример #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 );
    }
}
Пример #2
0
double PageItem_Table::maxBottomBorderWidth() const
{
	double maxWidth = 0.0;
	TableCell cell;
	for (int col = 0; col < columns(); col += cell.columnSpan())
	{
		cell = cellAt(rows() - 1, col);
		maxWidth = qMax(maxWidth, TableUtils::collapseBorders(bottomBorder(), cell.bottomBorder()).width());
	}
	return maxWidth;
}
Пример #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 ) );
}
Пример #4
0
void Decorator::drawBorder(Pictures& stack, const Rect& rectangle, const int offset)
{
  // pics are: 0TopLeft, 1Top, 2TopRight, 3Right, 4BottomRight, 5Bottom, 6BottomLeft, 7Left  
  Picture topborder( gui::rc.panel, offset+1);
  const int sw = topborder.width();
  const int sh = topborder.height();
  Picture bottomBorder( gui::rc.panel, offset+5);

  if( !sw || !sh )
  {
    Logger::warning( "!!! Cant draw border for sw={0}, sh={1}", sw, sh );
    return;
  }

  // draws horizontal borders
  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, offset+7);
  Picture rightborder( gui::rc.panel, offset+3);
  for (int i = 0; i<(rectangle.height()/sh+1); ++i)
  {
     stack.append( leftborder, rectangle.lefttop() + Point( 0, -rectangle.height()+sh*i ) );
     stack.append( rightborder, rectangle.lefttop() + Point( rectangle.width()-sw, -rectangle.height()+sh*i ) );
  }

  // topLeft corner
  stack.append( Picture( gui::rc.panel, offset+0), rectangle.lefttop());
  // topRight corner
  stack.append( Picture( gui::rc.panel, offset+2), Point( rectangle.right()-sw, rectangle.top() ) );
  // bottomLeft corner
  stack.append( Picture( gui::rc.panel, offset+6), Point( rectangle.left(), -rectangle.bottom()+sh ) );
  // bottomRight corner
  stack.append( Picture( gui::rc.panel, offset+4), Point( rectangle.right()-16, -rectangle.bottom()+sh ) );
}
Пример #5
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);
}
Пример #6
0
	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());
	}
Пример #7
0
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);
}