All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions
SciFigs::Brush Class Reference

#include <Brush.h>

Inheritance diagram for SciFigs::Brush:
QGpCoreTools::XMLClass

List of all members.

Public Member Functions

 Brush ()
 Brush (Qt::BrushStyle style)
 Brush (const QColor &color, Qt::BrushStyle style=Qt::SolidPattern)
 Brush (const QImage &image)
 Brush (const QBrush &b)
QBrush qbrush (double dotpercm) const
virtual const QString & xml_tagName () const
virtual ~Brush ()

Static Public Member Functions

static QString styleName (Qt::BrushStyle)
static Qt::BrushStyle styleValue (QString s)

Static Public Attributes

static const QString xmlBrushTag = "Brush"

Protected Member Functions

virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual bool xml_setProperty (XML_SETPROPERTY_ARGS)
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Constructor & Destructor Documentation

SciFigs::Brush::Brush ( ) [inline]
{}
SciFigs::Brush::Brush ( Qt::BrushStyle  style) [inline]
: QBrush(style) {}
SciFigs::Brush::Brush ( const QColor &  color,
Qt::BrushStyle  style = Qt::SolidPattern 
) [inline]
    : QBrush(color, style) {}
SciFigs::Brush::Brush ( const QImage &  image) [inline]
    : QBrush(image) {}
SciFigs::Brush::Brush ( const QBrush &  b) [inline]
: QBrush(b) {}
virtual SciFigs::Brush::~Brush ( ) [inline, virtual]
{}

Member Function Documentation

QBrush SciFigs::Brush::qbrush ( double  dotpercm) const

Return a QBrush. Default patterns are not used. Instead, they are redrawn to be device independent They are drawn on a 2.5x2.5 mm square, with 0.2 mm line weight.

TODO change and test again with Qt 4.4.0

The resolution indenpendent pattern does not work properly with Qt 4.3.4. A lot of X11 errors are encountered when using setImageTexture() and color is ignored even if image has a depth of 1 (to be fixed in Qt 4.4.0, bugs 169502 and 181805, respectively).

Currently, for screen painting (when dotpercm==screen resolution) the default patterns are used. For printing to other resolutions, the independent texture is used. Hence, for printing, the mask of the texture is not taken into account.

References SciFigs::SciFigsGlobal::screenResolution(), and TRACE.

Referenced by SciFigs::Symbol::paint(), and SciFigs::ParallelBands::paintData().

{
  TRACE;
  if(dotpercm==SciFigsGlobal::screenResolution()) return *this;
  if(dotpercm<40) return *this;
  switch (style()) {
  case Qt::HorPattern:
  case Qt::VerPattern:
  case Qt::CrossPattern:
  case Qt::FDiagPattern:
  case Qt::BDiagPattern:
  case Qt::DiagCrossPattern:
    break;
  default:
    return *this;
  }
  // For selected patterns, redraw them with a constant size (not depending on resolution)
  int s=(int)floor(dotpercm*0.25+0.5);
  int x;
  //QImage image(s,s, QImage::Format_Mono);
  QImage image(s,s, QImage::Format_ARGB32_Premultiplied);
  QPainter p;
  p.begin(&image);
  p.fillRect(0,0,s,s, Qt::white);
  p.setPen(QPen(color(),(int)round(dotpercm*0.02), Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
  //p.fillRect(0,0,s,s, Qt::color0);
  //p.setPen(QPen(Qt::color1,(int)round(dotpercm*0.02), Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
  switch (style()) {
  case Qt::HorPattern:
    x=s >> 2;
    p.drawLine(0,x,s,x);
    x=(s*3) >> 2;
    p.drawLine(0,x,s,x);
    break;
  case Qt::VerPattern:
    x=s >> 2;
    p.drawLine(x,0, x, s);
    x=(s*3) >> 2;
    p.drawLine(x,0, x, s);
    break;
  case Qt::CrossPattern:
    x=s >> 2;
    p.drawLine(0,x,s,x);
    p.drawLine(x,0, x, s);
    x=(s*3) >> 2;
    p.drawLine(0,x,s,x);
    p.drawLine(x,0, x, s);
    break;
  case Qt::FDiagPattern:
    x=s >> 1;
    p.drawLine(0,x,x,s);
    p.drawLine(x,0,s,x);
    break;
  case Qt::BDiagPattern:
    x=s >> 1;
    p.drawLine(0,x,x,0);
    p.drawLine(x,s,s,x);
    break;
  case Qt::DiagCrossPattern:
    x=s >> 1;
    p.drawLine(0,x,x,s);
    p.drawLine(x,0,s,x);
    p.drawLine(0,x,x,0);
    p.drawLine(x,s,s,x);
    break;
  default:
    break;
  }
  p.end();
  // TODO: maybe use a new constructor in Qt 4.4.0
  //return QBrush(color(), image);
  return QBrush(image);
}
QString SciFigs::Brush::styleName ( Qt::BrushStyle  s) [static]

References TRACE.

Referenced by xml_writeProperties().

{
  TRACE;
  switch (s) {
  case Qt::SolidPattern: return "SolidPattern";
  case Qt::Dense1Pattern: return "Dense1Pattern";
  case Qt::Dense2Pattern: return "Dense2Pattern";
  case Qt::Dense3Pattern: return "Dense3Pattern";
  case Qt::Dense4Pattern: return "Dense4Pattern";
  case Qt::Dense5Pattern: return "Dense5Pattern";
  case Qt::Dense6Pattern: return "Dense6Pattern";
  case Qt::Dense7Pattern: return "Dense7Pattern";
  case Qt::HorPattern: return "HorPattern";
  case Qt::VerPattern: return "VerPattern";
  case Qt::CrossPattern: return "CrossPattern";
  case Qt::BDiagPattern: return "BDiagPattern";
  case Qt::FDiagPattern: return "DDiagPattern";
  case Qt::DiagCrossPattern: return "DiagCrossPattern";
  default: return "NoBrush";
  }
}
Qt::BrushStyle SciFigs::Brush::styleValue ( QString  s) [static]

Referenced by SciFigs::LineLayer::setSymBrushStyle(), and xml_setProperty().

{
  if(s=="SolidPattern") return Qt::SolidPattern;
  else if(s=="Dense1Pattern") return Qt::Dense1Pattern;
  else if(s=="Dense2Pattern") return Qt::Dense2Pattern;
  else if(s=="Dense3Pattern") return Qt::Dense3Pattern;
  else if(s=="Dense4Pattern") return Qt::Dense4Pattern;
  else if(s=="Dense5Pattern") return Qt::Dense5Pattern;
  else if(s=="Dense6Pattern") return Qt::Dense6Pattern;
  else if(s=="Dense7Pattern") return Qt::Dense7Pattern;
  else if(s=="HorPattern") return Qt::HorPattern;
  else if(s=="VerPattern") return Qt::VerPattern;
  else if(s=="CrossPattern") return Qt::CrossPattern;
  else if(s=="BDiagPattern") return Qt::BDiagPattern;
  else if(s=="FDiagPattern") return Qt::FDiagPattern;
  else if(s=="DiagCrossPattern") return Qt::DiagCrossPattern;
  else return Qt::NoBrush;
}

Re-implement this function to offer XML restore (children and properties) support to your class.

From tag and map (with contains the attibute value) return a unique identifier under the format of a XMLMember. XMLMember is initialized with 3 types of contructors:

  • An integer: id number of a property
  • A XMLClass * : a child of this object identified by tag
  • Default constructor: error, unknow child or property

Map of attributes can be inspected in this way (can be achived also in xml_setProperty()):

    static const QString tmp("childrenName");
    XMLRestoreAttributeIterator it=map.find(tmp);
    if(it!=map.end()) {
      // found attribute "childrenName"
    }

If the map of attributes is not used:

    Q_UNUSED(attributes);
    if(tag=="x1") return XMLMember(0);
    else if(tag=="y1") return XMLMember(1);
    else if(tag=="x2") return XMLMember(2);
    else if(tag=="y2") return XMLMember(3);
    else return XMLMember(XMLMember::Unknown);

Arithmetic operations + and - apply to XMLMember to avoid confusion of property id numbers between inherited objects. Offset 3 corresponds to the number of properties defined in this object.

    if(tag=="anInteger") return XMLMember(0);
    else if(tag=="aString") return XMLMember(1);
    else if(tag=="aDouble") return XMLMember(2);
    return AbstractLine::xml_member(tag, attributes, context)+3;

For the arguments of this function use Macro XML_MEMBER_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References TRACE.

{
  TRACE;
  Q_UNUSED(attributes);
  Q_UNUSED(context);
  if(tag=="color") return XMLMember(0);
  else if(tag=="style") return XMLMember(1);
  return XMLMember(XMLMember::Unknown);
}
bool SciFigs::Brush::xml_setProperty ( XML_SETPROPERTY_ARGS  ) [protected, virtual]

Re-implement this function to offer XML restore properties support to your class.

From memberID set the corresponding property with value content. The map of attributes is given as a supplementary information (not useful in all cases).

For a general case:

  Q_UNUSED(attributes);
  double val=content.toDouble();
  switch (memberID) {
  case 0:
    _x1=val;
    return true;
  case 1:
    _y1=val;
    return true;
  case 2:
    _x2=val;
    return true;
  case 3:
    _y2=val;
    return true;
  default:
    return false;
  }

For classes inheriting other classes (see also xml_member())

  switch (memberID) {
  case 0:
    _anInteger=content.toString();
    return true;
  case 1:
    _aString=content.toInt();
    return true;
  case 2:
    _aDouble=content.toDouble();
    return true;
  default:
    return AbstractLine::xml_setProperty(memberID-3, map, content);

For the arguments of this function use Macro XML_SETPROPERTY_ARGS.

Reimplemented from QGpCoreTools::XMLClass.

References styleValue(), and TRACE.

{
  TRACE;
  Q_UNUSED(tag);
  Q_UNUSED(attributes);
  Q_UNUSED(context);
  switch (memberID) {
  case 0: {
      QColor col(content.toString());
      setColor(col);
      return true;
    }
  case 1:
    setStyle(styleValue(content.toString()));
    return true;
  default:
    return false;
  }
}
virtual const QString& SciFigs::Brush::xml_tagName ( ) const [inline, virtual]

Implements QGpCoreTools::XMLClass.

{return xmlBrushTag;}
void SciFigs::Brush::xml_writeProperties ( XML_WRITEPROPERTIES_ARGS  ) const [protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

References styleName(), TRACE, and QGpCoreTools::XMLClass::writeProperty().

{
  TRACE;
  Q_UNUSED(context);
  writeProperty(s, "color",color().name());
  writeProperty(s, "style",styleName(style()));
}

Member Data Documentation

const QString SciFigs::Brush::xmlBrushTag = "Brush" [static]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines