33#include <tqsimplerichtext.h>
34#include <tqpaintdevicemetrics.h>
37#include <KDXMLTools.h>
50 if( !source || this == source )
52 _rotation = source->_rotation;
53 _content.deepCopy( &source->_content);
54 _fontSize = source->_fontSize;
55 _fontScaleGlobal = source->_fontScaleGlobal;
56 _deltaX = source->_deltaX;
57 _deltaY = source->_deltaY;
58 _width = source->_width;
59 _height = source->_height;
60 _color = source->_color;
61 _paper = source->_paper;
62 _anchorArea = source->_anchorArea;
63 _anchorPos = source->_anchorPos;
64 _anchorAlign = source->_anchorAlign;
65 _dataRow = source->_dataRow;
66 _dataCol = source->_dataCol;
67 _data3rd = source->_data3rd;
68 _deltaAlign = source->_deltaAlign;
69 _deltaScaleGlobal = source->_deltaScaleGlobal;
70 _anchorBeingCalculated = source->_anchorBeingCalculated;
71 _parentAxisArea = source->_parentAxisArea;
82float KDChartCustomBox::trueFontSize( double areaWidthP1000,
83 double areaHeightP1000,
84 int rectHeight ) const
88 if( _fontScaleGlobal ) {
90 size = _fontSize * TQMIN(areaWidthP1000, areaHeightP1000) * -1.0;
95 float targetLineSpacing = (_fontSize * rectHeight)/ -1000;
96 size = targetLineSpacing;
98 TQFont font( content().font() );
99 font.setPointSizeFloat( size );
100 TQFontMetrics fm( font );
104 size *= targetLineSpacing / fm.lineSpacing();
107 font.setPointSizeFloat( size );
108 TQFontMetrics fm2( font );
109 size *= targetLineSpacing / fm2.lineSpacing();
120 size = content().font().pointSize();
122 size = content().font().pixelSize();
131int KDChartCustomBox::trueFontLineSpacing( double areaWidthP1000,
132 double areaHeightP1000,
133 int rectHeight ) const
135 TQFont font( content().font() );
136 font.setPointSizeFloat( trueFontSize( areaWidthP1000,areaHeightP1000, rectHeight ) );
137 TQFontMetrics fm( font );
138 return fm.lineSpacing();
142void KDChartCustomBox::getTrueShift( double areaWidthP1000,
143 double areaHeightP1000,
149 if( _deltaScaleGlobal ){
150 x = (0 > _deltaX) ? static_cast < int > ( -areaWidthP1000 * _deltaX ) : _deltaX;
151 y = (0 > _deltaY) ? static_cast < int > ( -areaHeightP1000 * _deltaY ) : _deltaY;
153 int fontHeight = trueFontLineSpacing( areaWidthP1000, areaHeightP1000, rectHeight );
155 x = (0 > _deltaX) ? static_cast < int > ( fontHeight * _deltaX / -100.0 ) : _deltaX;
156 y = (0 > _deltaY) ? static_cast < int > ( fontHeight * _deltaY / -100.0 ) : _deltaY;
159 uint deltaAlign = (KDCHART_AlignAuto == _deltaAlign) ? _anchorAlign : _deltaAlign;
160 if ( TQt::AlignLeft == (TQt::AlignLeft & deltaAlign) )
162 else if ( TQt::AlignRight == (TQt::AlignRight & deltaAlign) )
167 if ( TQt::AlignTop == (TQt::AlignTop & deltaAlign) )
169 else if ( TQt::AlignBottom == (TQt::AlignBottom & deltaAlign) )
178 tqDebug( "Sorry, not implemented yet: KDChartCustomBox::trueRect()" );
179 return TQRect( 1, 1, 2, 2 );
188 int w = (0 > _width ) ? static_cast < int > ( -areaWidthP1000 * _width ) : _width;
189 int h = (0 > _height) ? static_cast < int > ( -areaHeightP1000 * _height ) : _height;
193 if( _fontScaleGlobal && 0 == w && 0 == h ){
195 TQFont font( content().font() );
197 font.setPointSizeFloat(
199 ? (_fontSize * TQMIN(areaWidthP1000, areaHeightP1000) * -1.0)
203 TQString txt( content().text() );
204 TQString txtTest( txt.stripWhiteSpace().lower() );
205 if( !txtTest.startsWith( "<qt>" ) )
206 txt.prepend( "<qt>" );
207 if( !txtTest.endsWith( "</qt>") )
208 txt.append( "</qt>");
211 TQSimpleRichText tmpContent( txt, font );
219 w = tmpContent.widthUsed();
220 h = tmpContent.height();
227 if ( TQt::AlignLeft == (TQt::AlignLeft & _anchorAlign) )
229 else if ( TQt::AlignRight == (TQt::AlignRight & _anchorAlign) )
234 if ( TQt::AlignTop == (TQt::AlignTop & _anchorAlign) )
236 else if ( TQt::AlignBottom == (TQt::AlignBottom & _anchorAlign) )
241 getTrueShift( areaWidthP1000, areaHeightP1000, h,
245 return TQRect( anchor.x()+x+dX, anchor.y()+y+dY, w, h );
249int KDChartCustomBox::trueRectAlignX( const TQRect& rect) const
251 int ret = rect.center().x();
252 if ( TQt::AlignLeft == (TQt::AlignLeft & _anchorAlign) )
254 else if ( TQt::AlignRight == (TQt::AlignRight & _anchorAlign) )
258int KDChartCustomBox::trueRectAlignY( const TQRect& rect) const
260 int ret = rect.center().y();
261 if ( TQt::AlignTop == (TQt::AlignTop & _anchorAlign) )
262 ret -= rect.height();
263 else if ( TQt::AlignBottom == (TQt::AlignBottom & _anchorAlign) )
264 ret += rect.height();
270 double areaWidthP1000,
271 double areaHeightP1000,
273 const TQRect& frameRect,
274 const TQColor * color,
275 const TQBrush * paper ) const
289 TQRect myRect( trueRect( anchor, areaWidthP1000, areaHeightP1000 ) );
303 TQRect myFrameRect( frameRect );
304 if ( myRect.isValid() ) {
307 getTrueShift( areaWidthP1000, areaHeightP1000, myRect.height(),
309 myRect.moveBy( -rotDX, -rotDY );
311 myFrameRect.moveBy( -rotDX, -rotDY );
314 myRect.moveCenter( TQPoint( anchor.x() - trueRectAlignX(myRect),
315 anchor.y() - trueRectAlignY(myRect) ) );
317 myFrameRect.moveCenter( TQPoint( anchor.x() - trueRectAlignX(myFrameRect),
318 anchor.y() - trueRectAlignY(myFrameRect) ) );
320 painter->translate( anchor.x(), anchor.y() );
321 painter->rotate( _rotation );
322 painter->translate( rotDX, rotDY );
325 frame-> paint( painter, KDFrame::PaintAll, myFrameRect );
327 TQFont font( content().font() );
329 float trueSize = trueFontSize(areaWidthP1000,areaHeightP1000, myRect.height() );
330 font.setPointSizeFloat( trueSize );
332 myRect.setHeight( ( int)(trueSize )+ ( int)(trueSize*0.5));
333 const KDChartTextPiece tmpTextPiece( painter, content().text(), font );
335 tmpTextPiece.draw( painter, myRect.x(), myRect.y(), myRect,
340 content().draw( painter, myRect.x(), myRect.y(), myRect,
351 const TQString& elementName,
354 TQDomElement customBoxElement = document.createElement( elementName );
355 parent.appendChild( customBoxElement );
356 KDXML::createIntNode( document, customBoxElement, "Rotation", custombox->_rotation );
357 KDXML::createStringNode( document, customBoxElement, "ContentText",
358 custombox->_content.text() );
359 KDXML::createFontNode( document, customBoxElement, "ContentFont",
360 custombox->_content.font() );
361 KDXML::createIntNode( document, customBoxElement, "FontSize", custombox->_fontSize );
362 KDXML::createBoolNode( document, customBoxElement, "FontScaleGlobal",
363 custombox->_fontScaleGlobal );
364 KDXML::createIntNode( document, customBoxElement, "DeltaX", custombox->_deltaX );
365 KDXML::createIntNode( document, customBoxElement, "DeltaY", custombox->_deltaY );
366 KDXML::createIntNode( document, customBoxElement, "Width", custombox->_width );
367 KDXML::createIntNode( document, customBoxElement, "Height", custombox->_height );
368 KDXML::createColorNode( document, customBoxElement, "Color", custombox->_color );
369 KDXML::createBrushNode( document, customBoxElement, "Paper", custombox->_paper );
370 KDXML::createIntNode( document, customBoxElement, "AnchorArea",
371 custombox->_anchorArea );
372 KDXML::createStringNode( document, customBoxElement, "AnchorPos",
374 KDXML::createIntNode( document, customBoxElement, "AnchorAlign",
375 custombox->_anchorAlign );
376 KDXML::createIntNode( document, customBoxElement, "DataRow",
377 custombox->_dataRow );
378 KDXML::createIntNode( document, customBoxElement, "DataCol",
379 custombox->_dataCol );
380 KDXML::createIntNode( document, customBoxElement, "Data3rd",
381 custombox->_data3rd );
382 KDXML::createIntNode( document, customBoxElement, "DeltaAlign",
383 custombox->_deltaAlign );
384 KDXML::createBoolNode( document, customBoxElement, "DeltaScaleGlobal",
385 custombox->_deltaScaleGlobal );
386 KDXML::createIntNode( document, customBoxElement, "ParentAxisArea",
387 custombox->_parentAxisArea );
395 TQString tempContentText;
396 TQFont tempContentFont;
397 int tempRotation = 0;
398 int tempDeltaAlign = KDCHART_AlignAuto;
399 bool tempDeltaScaleGlobal = true;
400 int tempFontSize, tempDeltaX, tempDeltaY,
401 tempWidth, tempHeight, tempAnchorArea, tempParentAxisArea, tempAnchorAlign,
402 tempDataRow, tempDataCol, tempData3rd;
403 bool tempFontScaleGlobal;
407 TQDomNode node = element.firstChild();
408 while( !node.isNull() ) {
409 TQDomElement element = node.toElement();
410 if( !element.isNull() ) {
411 TQString tagName = element.tagName();
412 if( tagName == "Rotation" ) {
413 ok = ok & KDXML::readIntNode( element, tempRotation );
414 } else if( tagName == "ContentText" ) {
415 ok = ok & KDXML::readStringNode( element, tempContentText );
416 } else if( tagName == "ContentFont" ) {
417 ok = ok & KDXML::readFontNode( element, tempContentFont );
418 } else if( tagName == "FontSize" ) {
419 ok = ok & KDXML::readIntNode( element, tempFontSize );
420 } else if( tagName == "FontScaleGlobal" ) {
421 ok = ok & KDXML::readBoolNode( element, tempFontScaleGlobal );
422 } else if( tagName == "DeltaX" ) {
423 ok = ok & KDXML::readIntNode( element, tempDeltaX );
424 } else if( tagName == "DeltaY" ) {
425 ok = ok & KDXML::readIntNode( element, tempDeltaY );
426 } else if( tagName == "Width" ) {
427 ok = ok & KDXML::readIntNode( element, tempWidth );
428 } else if( tagName == "Height" ) {
429 ok = ok & KDXML::readIntNode( element, tempHeight );
430 } else if( tagName == "Color" ) {
431 ok = ok & KDXML::readColorNode( element, tempColor );
432 } else if( tagName == "Paper" ) {
433 ok = ok & KDXML::readBrushNode( element, tempPaper );
434 } else if( tagName == "AnchorArea" ) {
435 ok = ok & KDXML::readIntNode( element, tempAnchorArea );
436 } else if( tagName == "AnchorPos" ) {
438 ok = ok & KDXML::readStringNode( element, value );
440 } else if( tagName == "AnchorAlign" ) {
441 ok = ok & KDXML::readIntNode( element, tempAnchorAlign );
442 } else if( tagName == "DataRow" ) {
443 ok = ok & KDXML::readIntNode( element, tempDataRow );
444 } else if( tagName == "DataCol" ) {
445 ok = ok & KDXML::readIntNode( element, tempDataCol );
446 } else if( tagName == "Data3rd" ) {
447 ok = ok & KDXML::readIntNode( element, tempData3rd );
448 } else if( tagName == "DeltaAlign" ) {
449 ok = ok & KDXML::readIntNode( element, tempDeltaAlign );
450 } else if( tagName == "DeltaScaleGlobal" ) {
451 ok = ok & KDXML::readBoolNode( element, tempDeltaScaleGlobal );
452 } else if ( tagName == "ParentAxisArea" ) {
453 ok = ok & KDXML::readIntNode( element, tempParentAxisArea );
455 tqDebug( "Unknown tag in custom box" );
458 node = node.nextSibling();
462 const KDChartTextPiece piece( 0, tempContentText, tempContentFont );
463 custombox._content.deepCopy( &piece );
464 custombox._rotation = tempRotation;
465 custombox._fontSize = tempFontSize;
466 custombox._fontScaleGlobal = tempFontScaleGlobal;
467 custombox._deltaX = tempDeltaX;
468 custombox._deltaY = tempDeltaY;
469 custombox._width = tempWidth;
470 custombox._height = tempHeight;
471 custombox._color = tempColor;
472 custombox._paper = tempPaper;
473 custombox._anchorArea = tempAnchorArea;
474 custombox._anchorPos = tempAnchorPos;
475 custombox._anchorAlign = tempAnchorAlign;
476 custombox._dataRow = tempDataRow;
477 custombox._dataCol = tempDataCol;
478 custombox._data3rd = tempData3rd;
479 custombox._deltaAlign = tempDeltaAlign;
480 custombox._deltaScaleGlobal = tempDeltaScaleGlobal;
481 custombox._parentAxisArea = tempParentAxisArea;
487#include "KDChartCustomBox.moc"
Definition of a class for specifying and drawing custom boxes.
Header of the KDFrame class providing highly configurable rectangular frame drawing.
const TQBrush & paper() const Returns the background brush.
uint deltaAlign() const Returns the way how the values specified for deltaX and/or deltaY affect the position of the box.
const KDChartTextPiece & content() const Returns the text piece content that is to be drawn.
virtual void paint(TQPainter *painter, TQPoint anchor, double areaWidthP1000, double areaHeightP1000, const KDFrame *frame=0, const TQRect &frameRect=TQRect(), const TQColor *color=0, const TQBrush *paper=0) const Paints the box.
void deepCopy(const KDChartCustomBox *source) Copy the settings of box source into this box.
const KDChartCustomBox * clone() const Create a new box on the heap, copy the settings stored by this box into the newly created box and ret...
TQColor color() const Returns the text color.
TQRect trueRect(TQPainter *painter, TQPoint anchor, double areaWidthP1000, double areaHeightP1000) const Return the actual rectangle which to draw box into.
static bool readCustomBoxNode(const TQDomElement &element, KDChartCustomBox &custombox) Reads data from a DOM element node that represents a custom box object and fills a KDChartCustomBox o...
KDChartCustomBox() Constructor.
static void createCustomBoxNode(TQDomDocument &document, TQDomNode &parent, const TQString &elementName, const KDChartCustomBox *custombox) Creates a DOM element node that represents a custom box for use in a DOM document.
virtual ~KDChartCustomBox() Destructor.
static PositionFlag stringToPositionFlag(const TQString &string) Converts the specified string to a content position enum value.
PositionFlag The general position flag to specify a point of an area, for example this could be the anchor point w...
static TQString positionFlagToString(PositionFlag type) Converts the specified content position enum to a string representation.
The main class of KDFrame.
virtual void paint(TQPainter *painter, KDFramePaintSteps steps=PaintAll, TQRect innerRect=TQRect(0, 0, 0, 0)) const Paint methode actually drawing the frame.
|