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

The GraphicObject is the base class for all children of a GraphicSheet. More...

#include <GraphicObject.h>

Inheritance diagram for SciFigs::GraphicObject:
QGpGuiTools::PropertyContext QGpGuiTools::PropertyItem QGpCoreTools::XMLClass SciFigs::AxisWindow SciFigs::ColorPaletteWidget SciFigs::ImageWidget SciFigs::LegendItemWidget SciFigs::LegendWidget SciFigs::TextEdit GeopsyGui::ArrayMap SciFigs::ActivityMonitor SignalViewer

List of all members.

Public Types

enum  PositionAnchor {
  XMask = 1, YMask = 2, TopLeft = 3, TopRight = 2,
  BottomLeft = 1, BottomRight = 0
}

Public Slots

void copy ()
void copyImage (int dpi=0)
void copyMakeUp ()
virtual void deepUpdate ()
void deleteObject ()
void exportImage (QString fileName=QString::null, QString imageFormat=QString::null, int dpi=0)
QPixmap image (int dpi=0)
void keyPopupMenu ()
void pasteMakeUp ()
void print (int dpi=0)
void print (bool outputToFile, QString name, int dpi)
void restoreMakeUp (QString fileName=QString::null)
void saveMakeUp (QString fileName=QString::null)
void savePage (QString fileName=QString::null)
void showProperties ()
virtual void update ()
virtual void updateGeometry ()

Signals

void dragged (Point2D delta)
void positionChanged ()
void sizeChanged ()
void wantToBeSelected (GraphicObject *, Qt::KeyboardModifiers)
void wantToStartDragging ()

Public Member Functions

GraphicObjectactiveObject (const char *className=0) const
virtual void addProperties (PropertyProxy *pp)
PositionAnchor anchor () const
QString anchorString () const
bool constantWidthHeightRatio () const
void drag (Point2D delta)
 GraphicObject (QWidget *parent=0, Qt::WFlags f=0)
bool isActive () const
bool isRemovable ()
bool isSelected () const
GraphicObjectoperator= (const GraphicObject &o)
virtual void polish ()
void print (QPrinter &printer)
double printBottom (double refHeight=0.0) const
double printBottomMargin () const
double printHeight () const
double printLeft (double refWidth=0.0) const
double printLeftMargin () const
int printResolution () const
double printRight (double refWidth=0.0) const
double printRightMargin () const
double printTop (double refHeight=0.0) const
double printTopMargin () const
double printWidth () const
double printXAnchor () const
double printYAnchor () const
virtual void properties (PropertyWidget *w) const
PropertyProxyproxy () const
virtual void removeProperties (PropertyProxy *pp)
SelectionWidgetselectionWidget () const
void setActive (Qt::KeyboardModifiers m)
void setAnchor (PositionAnchor pa)
void setAnchor (QString pa)
void setConstantWidthHeightRatio (bool c)
virtual void setObjectName (QString name)
bool setOrderIndex (int index)
void setPrintAnchor (Point2D pos)
void setPrintBottom (double val)
void setPrintBottomMargin (double val)
void setPrintHeight (double val)
void setPrintLeft (double val)
void setPrintLeftMargin (double val)
void setPrintResolution (int val)
void setPrintRight (double val)
void setPrintRightMargin (double val)
void setPrintTop (double val)
void setPrintTopMargin (double val)
void setPrintWidth (double val)
void setPrintXAnchor (double val)
void setPrintYAnchor (double val)
virtual void setProperty (uint wid, int pid, QVariant val)
void setRemovable (bool r)
void setSelected (SelectionWidget *s)
void setToolTip (const QString &t)
void setTransparency (int val)
void setTransparentMask (bool val)
GraphicSheetsheet ()
virtual QSize sizeHint () const
void startDragging ()
int transparency () const
bool transparentMask () const
void updateGeometryProperties (PropertyProxy *pp)
virtual const QString & xml_tagName () const
 ~GraphicObject ()

Static Public Member Functions

static QBitmap colorMask (const QPixmap &pixmap, uint blankColor)
static int scaleFont (QFont &f, double scale, bool *changed=0)

Static Public Attributes

static const QString allImageFilter = ";;" + GraphicObject::pixelImageFilter
static const QString pixelImageFilter = "PNG (*.png);;PPM (*.ppm);;XBM (*.xbm);;XPM (*.xpm)"
static const QString vectorialImageFilter = "PS (*.ps);;PDF (*.pdf);;SVG (*.svg)"
static const QString xmlGraphicObjectTag = "GraphicObject"

Protected Member Functions

virtual void addActions ()
virtual void enterEvent (QEvent *e)
virtual void leaveEvent (QEvent *e)
virtual void mouseDoubleClickEvent (QMouseEvent *e)
virtual void mouseMoveEvent (QMouseEvent *e)
virtual void mousePressEvent (QMouseEvent *e)
virtual void mouseReleaseEvent (QMouseEvent *e)
virtual void paint (QPainter &p, double dotpercm, int w, int h, bool mask)
virtual void paintEvent (QPaintEvent *e)
virtual void print (QPainter &p, double dotpercm, int x0Sheet, int y0Sheet, bool mask)
void printSvg (const QString &fileName, int dpi)
virtual void restoreScaleFonts (int *fontSizeStorage)
virtual int * scaleFonts (double scale)
int scaleWidgetFonts (QWidget *w, double scale)
virtual void setPrintSize (double dotpercm)
virtual void showEvent (QShowEvent *e)
void updateMask ()
virtual XMLMember xml_member (XML_MEMBER_ARGS)
virtual void xml_polish (XML_POLISH_ARGS)
virtual bool xml_setProperty (XML_SETPROPERTY_ARGS)
virtual void xml_writeProperties (XML_WRITEPROPERTIES_ARGS) const

Protected Attributes

PositionAnchor _anchor
Point2D _printAnchor
double _printBottomMargin
double _printHeight
double _printLeftMargin
double _printRightMargin
double _printTopMargin
double _printWidth

Properties

QString anchor
bool constantWidthHeightRatio
 DUMMY_PROPERTIES
QString name
QString objectName
double printBottomMargin
double printHeight
double printLeftMargin
int printResolution
double printRightMargin
double printTopMargin
double printWidth
double printX
double printY
int transparency
bool transparentMask

Friends

class GraphicSheet
class SelectionWidget

Detailed Description

The GraphicObject is the base class for all children of a GraphicSheet.

GraphicObject handles main geometric properties of objects (position, size, margins, printing resolution and user name). It works with two modes:

In the first mode, it responds only to mouse click events to display its general context menu containing (also available through CTRL+M):

In the second mode, the same actions are supported, but the following menu items are added:

Moreover, the mouse clicks are handled to move and to select the object in the sheet. Multiple selections are supported with the SHIFT key.

The selected object is marked by a SelectionWidget that is slightly larger than this object, showing a black (active selection) or grey (passive selection) border. The mouse events on the border are redirected to this object. Usually, it is not necessary to use it explicitely. See setSelected(), selected(), active(), activeObject().

The margins are useful when exporting to bitmaps or when the object is located close to the edge of a GraphicSheet. It extends the printing or image size by a few millimeters. Units for margins are always cm. See printLeftMargin(), printRightMargin(), printTopMargin(), printBottomMargin(), and setPrintLeftMargin(), setPrintRightMargin(), setPrintTopMargin(), setPrintBottomMargin().


Member Enumeration Documentation

Enumerator:
XMask 
YMask 
TopLeft 
TopRight 
BottomLeft 
BottomRight 

Constructor & Destructor Documentation

SciFigs::GraphicObject::GraphicObject ( QWidget *  parent = 0,
Qt::WFlags  f = 0 
)

Construct a generic graphical object. This function is generally not called directly. Use one of the derived objects (AxisWindow, TextEdit, ImageWidget, ColorPaletteWidget).

References _anchor, _printAnchor, _printBottomMargin, _printHeight, _printLeftMargin, _printRightMargin, _printTopMargin, _printWidth, keyPopupMenu(), QGpGuiTools::setWidgetColor(), TopLeft, QGpCoreTools::tr(), and TRACE.

                                                         :
    QWidget(parent, f)
{
  TRACE;
  _selected=0;
  _sheet=0;
  _orderTip=0;
  _isRemovable=false;
  new QShortcut(tr( "Ctrl+M" ), this, SLOT(keyPopupMenu()) );

  setWidgetColor(this, Qt::white);
  setAttribute(Qt::WA_DeleteOnClose);
  // Just a test to check if mask still necessary or directly implemented in Qt
  // setAttribute(Qt::WA_OpaquePaintEvent);
  _printAnchor=Point2D(1.0, 1.0);
  _anchor=TopLeft;
  _printWidth=5.0;
  _printHeight=5.0;
  _constantWidthHeightRatio=false;
  _printResolution=300;
  _printLeftMargin=0.5;
  _printRightMargin=0.5;
  _printTopMargin=0.5;
  _printBottomMargin=0.5;
  _transparency=255;
  _mask=false;
}

Destructor

References TRACE.

{
  TRACE;
  delete _orderTip;
}

Member Function Documentation

GraphicObject * SciFigs::GraphicObject::activeObject ( const char *  className = 0) const

Return the active object of the parent GraphicSheet.

References SciFigs::GraphicSheet::activeObject(), and TRACE.

Referenced by keyPopupMenu().

{
  TRACE;
  return _sheet->activeObject(className);
}
void SciFigs::GraphicObject::addActions ( ) [protected, virtual]

Initialize context menu

References copy(), copyImage(), copyMakeUp(), deleteObject(), exportImage(), isRemovable(), pasteMakeUp(), print(), restoreMakeUp(), saveMakeUp(), savePage(), sheet(), showProperties(), QGpCoreTools::tr(), and TRACE.

Referenced by polish().

{
  TRACE;
  QAction * a;

  a=new QAction(tr( "&Properties" ), this);
  a->setObjectName( "Properties" );
  a->setStatusTip(tr("Set properties of object"));
  a->setShortcut(tr("Ctrl+Alt+P"));
  a->setShortcutContext(Qt::WidgetShortcut);
  connect(a, SIGNAL(triggered( bool) ) , this, SLOT(showProperties()) );
  QWidget::addAction(a);

  if(sheet()) {
    a=new QAction(this);
    a->setSeparator(true);
    QWidget::addAction(a);

    QMenu * m=new QMenu(this);
    m->addAction(tr( "Bring to &front" ), sheet(), SLOT(raiseSelection()) );
    m->addAction(tr( "Send to &back" ), sheet(), SLOT(lowerSelection()) );

    a=new QAction(tr( "&Order" ), this);
    a->setObjectName( "Order" );
    a->setMenu(m);
    QWidget::addAction(a);

    m=new QMenu(this);
    m->addAction(tr( "&Left" ), sheet(), SLOT(alignLeft()) );
    m->addAction(tr( "&Centered" ), sheet(), SLOT(alignHCenter()) );
    m->addAction(tr( "&Right" ), sheet(), SLOT(alignRight()) );
    m->addSeparator();
    m->addAction(tr( "&Top" ), sheet(), SLOT(alignTop()) );
    m->addAction(tr( "C&entered" ), sheet(), SLOT(alignVCenter()) );
    m->addAction(tr( "&Bottom" ), sheet(), SLOT(alignBottom()) );

    a=new QAction(tr( "&Alignment" ), this);
    a->setObjectName( "Alignment" );
    a->setMenu(m);
    QWidget::addAction(a);

    if(isRemovable()) {
      a=new QAction(tr( "&Delete" ), this);
      a->setObjectName( "Delete" );
      connect(a, SIGNAL(triggered( bool) ) , this, SLOT(deleteObject()) );
      QWidget::addAction(a);
    }
  }

  a=new QAction(this);
  a->setSeparator(true);
  QWidget::addAction(a);

  a=new QAction(tr("&Copy"), this);
  a->setStatusTip(tr("Copy this object to the clipboard (compatible with figue)"));
  connect(a, SIGNAL(triggered(bool)) , this, SLOT(copy()));
  QWidget::addAction(a);

  a=new QAction(tr("Copy &image"), this);
  a->setStatusTip(tr("Copy this object as an image to the clipboard (compatible with office suites)"));
  connect(a, SIGNAL(triggered(bool)) , this, SLOT(copyImage()));
  QWidget::addAction(a);

  a=new QAction(tr( "Save as a page" ), this);
  a->setObjectName( "Save as a page" );
  a->setStatusTip(tr("Save this object as a page file. Open and edit it with figue."));
  connect(a, SIGNAL(triggered(bool)), this, SLOT(savePage()));
  QWidget::addAction(a);

  a=new QAction(tr( "&Export image as ..." ), this);
  a->setObjectName( "Export image" );
  a->setStatusTip(tr("Export this object as an image (PNG, JPG, PS, PDF,...). Adjust resolution in object properties."));
  connect( a, SIGNAL(triggered(bool)) , this, SLOT(exportImage()));
  QWidget::addAction(a);

  a=new QAction(tr( "&Print" ), this);
  a->setObjectName( "Print" );
  connect(a, SIGNAL(triggered( bool) ) , this, SLOT(print()) );
  QWidget::addAction(a);

  a=new QAction(this);
  a->setSeparator(true);
  QWidget::addAction(a);

  a=new QAction(tr("&Copy make-up"), this);
  a->setObjectName("Copy make-up");
  a->setStatusTip(tr("Copy object format to the clipboard"));
  connect(a, SIGNAL(triggered(bool)) , this, SLOT(copyMakeUp()));
  QWidget::addAction(a);

  a=new QAction(tr("&Paste make-up"), this);
  a->setObjectName("Paste make-up");
  a->setStatusTip(tr("Restore object format from the clipboard"));
  connect(a, SIGNAL(triggered(bool)) , this, SLOT(pasteMakeUp()));
  QWidget::addAction(a);

  a=new QAction(tr( "&Save make-up" ), this);
  a->setObjectName( "Save make-up" );
  a->setStatusTip(tr("Save object format to a file"));
  connect(a, SIGNAL(triggered( bool)) , this, SLOT(saveMakeUp()));
  QWidget::addAction(a);

  a=new QAction(tr( "&Restore make-up" ), this);
  a->setObjectName( "Restore make-up" );
  a->setStatusTip(tr("Restore object format from a file"));
  connect(a, SIGNAL(triggered(bool)), this, SLOT(restoreMakeUp()));
  QWidget::addAction(a);
}

Reimplemented in SciFigs::LegendWidget, SciFigs::ColorPaletteWidget, SciFigs::AxisWindow, SciFigs::TextEdit, and SciFigs::ImageWidget.

References QGpGuiTools::PropertyProxy::addCategory(), QGpGuiTools::PropertyProxy::addReference(), QGpGuiTools::PropertyProxy::addTab(), QGpGuiTools::PropertyProxy::setCurrentCategory(), QGpGuiTools::PropertyProxy::setCurrentTab(), QGpCoreTools::tr(), TRACE, and w.

Referenced by SciFigs::GraphicSheet::selectObjects(), showProperties(), and SciFigs::GraphicSheet::showProperties().

{
  TRACE;
  if( !pp->setCurrentCategory(_category) ) {
    pp->addCategory(_category, tr("Object"), QIcon( ":/images/graphicobject.png"));
  }
  if(pp->setCurrentTab(_tabId)) {
    pp->addReference(this);
  } else {
    GraphicObjectIdProperties * w=new GraphicObjectIdProperties;
    pp->addTab(_tabId, tr("Identification"), w, this);
  }
  if(pp->setCurrentTab(_tabGeomery)) {
    pp->addReference(this);
  } else {
    GraphicObjectGeometryProperties * w=new GraphicObjectGeometryProperties;
    pp->addTab(_tabGeomery, tr("Geometry"), w, this);
  }
  if(pp->setCurrentTab(_tabPrint)) {
    pp->addReference(this);
  } else {
    GraphicObjectPrintProperties * w=new GraphicObjectPrintProperties;
    pp->addTab(_tabPrint, tr("Print"), w, this);
  }
}

Referenced by anchorString(), and properties().

{return _anchor;}

References anchor(), BottomLeft, BottomRight, TopRight, and TRACE.

{
  TRACE;
  switch (anchor()) {
  case TopRight:
    return "TopRight";
  case BottomLeft:
    return "BottomLeft";
  case BottomRight:
    return "BottomRight";
  default:
    return "TopLeft";
  }
}
QBitmap SciFigs::GraphicObject::colorMask ( const QPixmap &  pixmap,
uint  blankColor 
) [static]

References TRACE, TRACE_BUG, TRACE_BUG_INT, TRACE_BUG_N, and TRACE_BUG_POINTER.

Referenced by image(), SciFigs::GraphicSheet::image(), and updateMask().

{
  TRACE;
  int nHeight=pixmap.height();
  int nWidth=pixmap.width();
  TRACE_BUG;
  TRACE_BUG_INT(nWidth);
  TRACE_BUG_INT(nHeight);
  QBitmap pmask(nWidth, nHeight);
  TRACE_BUG_N(1);
  if(nWidth==0 || nHeight==0) {
    return pmask;
  }
  QImage mask(nWidth, nHeight, QImage::Format_Mono);
  QImage imPixmap=pixmap.toImage();
  int nWidth8=nWidth-8;
  TRACE_BUG_N(2);
  for(int ih=0; ih<nHeight; ih++) {
    TRACE_BUG_N(5);
    TRACE_BUG_INT(ih);
    uint * bPixmap=(uint* ) imPixmap.scanLine(ih);
    TRACE_BUG_POINTER(bPixmap);
    uchar * bmask=mask.scanLine(ih);
    TRACE_BUG_POINTER(bmask);
    int im=0, iw=0;
    uchar maskByte;
    TRACE_BUG_N(6);
    while(iw < nWidth8) {
      maskByte=0;
      if(bPixmap[ iw ]==blankColor) maskByte += 0x80;
      if(bPixmap[ iw + 1 ]==blankColor) maskByte += 0x40;
      if(bPixmap[ iw + 2 ]==blankColor) maskByte += 0x20;
      if(bPixmap[ iw + 3 ]==blankColor) maskByte += 0x10;
      if(bPixmap[ iw + 4 ]==blankColor) maskByte += 0x08;
      if(bPixmap[ iw + 5 ]==blankColor) maskByte += 0x04;
      if(bPixmap[ iw + 6 ]==blankColor) maskByte += 0x02;
      if(bPixmap[ iw + 7 ]==blankColor) maskByte += 0x01;
      bmask[ im ]=maskByte;
      iw += 8;
      im++;
    }
    uchar maskBit=0x80;
    maskByte=0;
    TRACE_BUG_N(7);
    while(iw < nWidth) {
      ASSERT(maskBit);
      if(bPixmap[ iw++ ]==blankColor) maskByte += maskBit;
      maskBit=maskBit >> 1;
    }
    bmask[ im ]=maskByte;
    TRACE_BUG_N(8);
  }
  TRACE_BUG_N(3);
  pmask=QBitmap::fromImage(mask);
  TRACE_BUG_N(4);
  return pmask;
}

Referenced by properties(), and setProperty().

{return _constantWidthHeightRatio;}

Copy this object to the clipboard

References SciFigs::XMLSciFigs::Page, SciFigs::XMLSciFigs::saveByteArray(), and TRACE.

Referenced by addActions().

{
  TRACE;
  QClipboard * cb=QApplication::clipboard();
  XMLSciFigs s;
  QByteArray object=s.saveByteArray(this, XMLSciFigs::Page);
  QMimeData * mime=new QMimeData;
  mime->setData("XMLSciFigs::Page", object);
  cb->setMimeData(mime, QClipboard::Clipboard);
}
void SciFigs::GraphicObject::copyImage ( int  dpi = 0) [slot]

Transform object into a pixmap and copy it to the clipboard

References image(), and TRACE.

Referenced by addActions().

{
  TRACE;
  QPixmap pixmap=image(dpi);
  if(!pixmap.isNull()) {
    QClipboard * cb=QApplication::clipboard();
    cb->setPixmap(pixmap, QClipboard::Clipboard);
  }
}

Copy make-up to the clipboard

References SciFigs::XMLSciFigs::MakeUp, SciFigs::MakeUpFilter::saveByteArray(), SciFigs::XMLSciFigs::saveString(), SciFigs::MakeUpFilter::setXml(), and TRACE.

Referenced by addActions().

{
  TRACE;
  XMLSciFigs s;
  MakeUpFilter * d=new MakeUpFilter(this);
  d->setXml(s.saveString(this, XMLSciFigs::MakeUp));
  if(d->exec()==QDialog::Accepted) {
    QClipboard * cb=QApplication::clipboard();
    QMimeData * mime=new QMimeData;
    mime->setData("XMLSciFigs::ObjectMakeUp", d->saveByteArray());
    cb->setMimeData(mime, QClipboard::Clipboard);
  }
}
virtual void SciFigs::GraphicObject::deepUpdate ( ) [inline, virtual, slot]

Delete all selected object after confirmation from the user . It is not working if not docked in a sheet.

References isRemovable(), MSG_ID, SciFigs::GraphicSheet::removeObject(), SciFigs::GraphicSheet::selectedObjects(), QGpCoreTools::tr(), and TRACE.

Referenced by addActions(), and SciFigs::GraphicSheet::cut().

{
  TRACE;
  if( !_sheet) return ;
  QList<GraphicObject *> tmpList=_sheet->selectedObjects<GraphicObject *>();
  if(tmpList.isEmpty()) {
    Message::warning(MSG_ID, tr( "Deleting objects" ), tr( "Empty selection." ), Message::ok());
    return;
  }
  // Count removable objects
  int nToRemove=0;
  GraphicObject * obj;
  foreach(obj, tmpList) {
    if(obj->isRemovable()) nToRemove++;
  }
  if (tmpList.count()>nToRemove) {
    static QString title=tr("Deleting objects");
    switch(nToRemove) {
    case 0:
      if(tmpList.count()==1) {
        Message::warning(MSG_ID, title,
                         tr("This object is not removable.")
                                .arg(tmpList.count()), Message::ok(), true);
      } else {
        Message::warning(MSG_ID, title,
                         tr("These %1 objects are not removable.")
                                .arg(tmpList.count()), Message::ok(), true);
      }
      break;
    case 1:
      Message::warning(MSG_ID, title,
                       tr("Only 1 object out of %2 selected is removable.")
                              .arg(tmpList.count()), Message::ok(), true);
      break;
    default:
      Message::warning(MSG_ID, title,
                       tr("Only %1 objects out of %2 selected are removable.")
                              .arg(nToRemove).arg( tmpList.count()), Message::ok(), true);
      break;
    }

    if (nToRemove==1) {
      Message::warning(MSG_ID, tr("Deleting objects"),
                           tr("Only 1 object out of %2 selected are removable.")
                              .arg(tmpList.count()), Message::ok(), true);
    } else {
      Message::warning(MSG_ID, tr( "Deleting objects"),
                         tr( "Only %1 objects out of %2 selected are removable.")
                              .arg(nToRemove).arg( tmpList.count()), Message::ok(), true);
    }
  }
  switch(nToRemove) {
  case 0:
    break;
  case 1:
    if(Message::warning(MSG_ID, "Deleting objects",
                              tr( "Do you really want to delete 1 object?" ),
                              Message::no() , Message::yes())==Message::Answer0) {
      return;
    }
    break;
  default:
    if(Message::warning(MSG_ID, "Deleting objects",
                              tr( "Do you really want to delete %1 objects?" ).arg(nToRemove),
                              Message::no() , Message::yes())==Message::Answer0) {
      return;
    }
    break;
  }
  foreach(obj, tmpList) _sheet->removeObject(obj);
}

References setPrintAnchor(), and TRACE.

{
  TRACE;
  setPrintAnchor(_oldPrintPos + delta);
}
void SciFigs::GraphicObject::dragged ( Point2D  delta) [signal]

Referenced by mouseMoveEvent().

void SciFigs::GraphicObject::enterEvent ( QEvent *  e) [protected, virtual]

References SciFigs::GraphicSheet::addSelection(), SciFigs::SelectionWidget::Hoover, selectionWidget(), SciFigs::SelectionWidget::setState(), sheet(), TRACE, TRACE_BUG, TRACE_BUG_N, and TRACE_BUG_POINTER.

{
  TRACE;
  TRACE_BUG;
  // 2012-12-05: reccursion still observed under Mac
  if(antiReccurFlag) {
    antiReccurFlag=false;
    if (sheet() && !selectionWidget()) {
      sheet()->addSelection(this);
      // Here and not in addSelection(), bug observed with Qt 4.6 under Mac, show() calls GraphicObject::enterEvent()
      ASSERT(_selected);
      TRACE_BUG_N(1);
      TRACE_BUG_POINTER(this);
      _selected->setState(SelectionWidget::Hoover);
      TRACE_BUG_N(2);
      _selected->show();
      TRACE_BUG_N(3);
    }
    antiReccurFlag=true;
  }
}
void SciFigs::GraphicObject::exportImage ( QString  fileName = QString::null,
QString  imageFormat = QString::null,
int  dpi = 0 
) [slot]

Export the object to an image file, imageFormat may be any of the format accetped by QImage. Additionally, the 'PS' and 'PDF' are accepted.

If dpi is different from 0, it override the resolution specified in object properties.

References allImageFilter, image(), MSG_ID, print(), printSvg(), DinverCore::qHash(), QGpCoreTools::tr(), TRACE, transparentMask(), and updateMask().

Referenced by addActions().

{
  TRACE;
  if(fileName.isEmpty()) {
    fileName=Message::getSaveFileName(tr( "Export image as ..." ), allImageFilter);
  }
  if(fileName.length() > 0) {
    if(imageFormat.isEmpty()) {
      imageFormat=Settings::getFilter( "filter-" + QString::number(qHash( allImageFilter) )).
                    section( ' ', 0, 0);
    }
    if(imageFormat =="PS" || imageFormat =="PDF" ) {
      QPrinter printer(QPrinter::HighResolution);
      if(dpi==0) dpi=_printResolution;
      printer.setResolution(dpi);
      printer.setFullPage(true);
      printer.setOutputFileName(fileName);
      printer.setOutputFormat(imageFormat =="PDF" ? QPrinter::PdfFormat : QPrinter::PostScriptFormat);
      print(printer);
    } else if(imageFormat =="SVG" ) {
      printSvg(fileName, dpi);
    } else {
      QPixmap pixmap=image(dpi);
      if(!pixmap.isNull()) {
        // Save pixmap to disk
        if(!pixmap.save(fileName, imageFormat.toAscii().data())) {
          Message::warning(MSG_ID, tr("Exporting as image"), tr("Failed to export image to file %1 with format %2")
                              .arg(fileName).arg(imageFormat.toAscii().data()));
        }
      }
      if(transparentMask()) updateMask();
    }
  }
}
QPixmap SciFigs::GraphicObject::image ( int  dpi = 0) [slot]

References _printBottomMargin, _printHeight, _printLeftMargin, _printRightMargin, _printTopMargin, _printWidth, colorMask(), MSG_ID, objectName, print(), printLeft(), printTop(), restoreScaleFonts(), scaleFonts(), SciFigs::SciFigsGlobal::screenResolution(), setPrintSize(), QGpCoreTools::tr(), TRACE, and transparentMask().

Referenced by copyImage(), and exportImage().

{
  TRACE;
  double resolution;
  if(dpi==0) resolution=_printResolution/2.54;
  else resolution=dpi/2.54;
  double factor=resolution/SciFigsGlobal::screenResolution();
  double hMargins=_printLeftMargin + _printRightMargin;
  double vMargins=_printTopMargin + _printBottomMargin;
  int * tmpSize=scaleFonts(factor);
  setPrintSize(resolution);
  int totalw=(int)((_printWidth+hMargins)*resolution);
  int totalh=(int)((_printHeight+vMargins)*resolution);
  QPixmap pixmap;
  if(totalw>0 && totalh>0) {
    QPainter p;
    pixmap=QPixmap(totalw, totalh);
    p.begin(&pixmap);
    p.eraseRect(0, 0, totalw, totalh);
    p.save();
    p.translate(-(printLeft()-_printLeftMargin)*resolution, -(printTop()-_printTopMargin)*resolution);
    print(p, resolution, 0, 0, false);
    p.restore();
    //SciFigsGlobal::footprint(p, resolution, totalw, totalh);
    p.end();
    if(transparentMask()) {
      QBitmap mask=colorMask(pixmap, 0xFFFFFFFF);
      p.begin(&mask);
      p.translate( -(printLeft() - _printLeftMargin) * resolution, -(printTop() - _printTopMargin) * resolution);
      print(p, resolution, 0, 0, true);
      p.end();
      pixmap.setMask(mask);
    }
    if(_transparency < 255) {

    }
  } else {
    Message::warning(MSG_ID, tr("Drawing image"), tr("Null size for image of object %1 (%2, %3).").arg(objectName()).arg(totalw).arg(totalh), Message::cancel());
  }
  restoreScaleFonts(tmpSize);
  setPrintSize(SciFigsGlobal::screenResolution());
  return pixmap;
}

Tells whether the object is selected and is the active selection.

References SciFigs::SelectionWidget::Activated, SciFigs::SelectionWidget::state(), and TRACE.

Referenced by keyPopupMenu(), and updateGeometryProperties().

{
  TRACE;
  return !_sheet || (_selected && _selected->state()==SelectionWidget::Activated);
}

Referenced by addActions(), deleteObject(), and SciFigs::GraphicSheet::removeObject().

{return _isRemovable;}

Show context menu after CTRL+M request, or for other reason. The menu is displayed in the to left corner.

TODO: it doesn't work...

References activeObject(), isActive(), keyPopupMenu(), and TRACE.

Referenced by GraphicObject(), and keyPopupMenu().

{
  TRACE;
  if(isActive()) {
    QMenu m;
    m.addActions(actions());
    m.exec(mapToGlobal( QPoint(0, 0) ));
  } else { // Insure that the menu will be displayed in the active object
    GraphicObject * obj=activeObject();
    if(obj) obj->keyPopupMenu();
  }
}
void SciFigs::GraphicObject::leaveEvent ( QEvent *  e) [protected, virtual]

References SciFigs::SelectionWidget::Hoover, sheet(), SciFigs::SelectionWidget::state(), and TRACE.

{
  TRACE;
  if(_selected && _selected->state()==SelectionWidget::Hoover) {
    ASSERT(sheet());
    QPoint p=sheet()->mapFromGlobal(QCursor::pos());
    QRect r=geometry();
    if( !r.contains(p)) {
      _selected->deleteLater();
      _selected=0;
    }
  }
}
void SciFigs::GraphicObject::mouseDoubleClickEvent ( QMouseEvent *  e) [protected, virtual]

Select the object if not already selected and active.

Open the property dialog box.

Reimplemented in SciFigs::ActivityMonitor.

References setActive(), showProperties(), and TRACE.

Referenced by SciFigs::ColorPaletteWidget::eventFilter(), and SciFigs::SelectionWidget::mouseDoubleClickEvent().

{
  TRACE;
  setActive(e->modifiers());
  if(e->buttons() & Qt::LeftButton) {
    showProperties();
  }
}
void SciFigs::GraphicObject::mouseMoveEvent ( QMouseEvent *  e) [protected, virtual]

If dragging is on and if the mouse is at more than 10 pixels from its original position, true dragging is started. It only emits a dragged() signal to be interpreted by GraphicSheet which is in charge of moving all selected object at the same time.

References QGpCoreTools::abs(), dragged(), SciFigs::SciFigsGlobal::screenResolution(), and TRACE.

Referenced by SciFigs::ColorPaletteWidget::eventFilter(), and SciFigs::SelectionWidget::mouseMoveEvent().

{
  TRACE;
  if(_draggingOn) {
    QPoint d=e->globalPos();
    d -= _oldMousePos;
    if(_draggingStarted || abs(d.x()) > 10 || abs(d.y()) > 10) {
      _draggingStarted=true;
      emit dragged(Point2D( (double) d.x()/SciFigsGlobal::screenResolution(),
                             (double) d.y()/SciFigsGlobal::screenResolution()) );
    }
  } else QWidget::mouseMoveEvent (e);
}
void SciFigs::GraphicObject::mousePressEvent ( QMouseEvent *  e) [protected, virtual]

Selection of object is not already selected and active.

Start dragging the object, the initial position is recorded in static members.

Reimplemented in SciFigs::ActivityMonitor.

References setActive(), TRACE, and wantToStartDragging().

Referenced by SciFigs::ColorPaletteWidget::eventFilter(), and SciFigs::SelectionWidget::mousePressEvent().

{
  TRACE;
  setActive(e->modifiers());
  switch (e->button()) {
  case Qt::LeftButton:
    _oldMousePos=e->globalPos();
    emit wantToStartDragging();
    _draggingOn=true;
    _draggingStarted=false;
    break;
  case Qt::RightButton: {
      QMenu m;
      m.addActions(actions());
      m.exec(mapToGlobal( e->pos()) );
    }
    break;
  default:
    break;
  }
}
void SciFigs::GraphicObject::mouseReleaseEvent ( QMouseEvent *  e) [protected, virtual]

Stop dragging the object.

Reimplemented in SciFigs::ActivityMonitor.

References SciFigs::GraphicSheet::setOrderIndex(), sheet(), and TRACE.

Referenced by SciFigs::ColorPaletteWidget::eventFilter(), and SciFigs::SelectionWidget::mouseReleaseEvent().

{
  TRACE;
  if(_draggingOn) {
    _draggingOn=false;
    if(sheet() && sheet() ->isOrderIndex()) sheet() ->setOrderIndex(this);
  }
}
GraphicObject & SciFigs::GraphicObject::operator= ( const GraphicObject o)

References _anchor, _printAnchor, _printBottomMargin, _printHeight, _printLeftMargin, _printRightMargin, _printTopMargin, _printWidth, and TRACE.

{
  TRACE;
  _printAnchor=o._printAnchor;
  _anchor=o._anchor;
  _printWidth=o._printWidth;
  _printHeight=o._printHeight;
  _constantWidthHeightRatio=o._constantWidthHeightRatio;
  _printResolution=o._printResolution;
  _printLeftMargin=o._printLeftMargin;
  _printRightMargin=o._printRightMargin;
  _printTopMargin=o._printTopMargin;
  _printBottomMargin=o._printBottomMargin;
  _transparency=o._transparency;
  _mask=o._mask;
  setFont(o.font());
  return *this;
}
void SciFigs::GraphicObject::paint ( QPainter &  p,
double  dotpercm,
int  w,
int  h,
bool  mask 
) [protected, virtual]

Virtual function to be re-implemented for each type of object to paint specific content. It is different than the classical QWidget function of the same type. Actually, the needed resolution is passed as argument as well as the screen width and height of the object. It is called by print().

Nothing is done, calling it in re-implemented function is useless.

Reimplemented in SciFigs::LegendWidget, and SciFigs::TextEdit.

References TRACE.

Referenced by paintEvent(), print(), and updateMask().

{
  TRACE;
}
void SciFigs::GraphicObject::paintEvent ( QPaintEvent *  e) [protected, virtual]

Reimplemented in SciFigs::LegendItemWidget.

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

{
  TRACE;
  QPainter p(this);
  p.fillRect(0,0,width(),height(), Qt::white);
  paint(p, SciFigsGlobal::screenResolution(), width(), height(), false);
}

Restore make-up from the clipboard if there are any

References deepUpdate(), QGpCoreTools::XMLErrorReport::exec(), SciFigs::XMLSciFigs::MakeUp, SciFigs::XMLSciFigs::restoreByteArray(), QGpCoreTools::XMLErrorReport::setTitle(), QGpCoreTools::tr(), and TRACE.

Referenced by addActions().

{
  TRACE;
  static QString title=tr("Paste make-up");
  QClipboard * cb=QApplication::clipboard();
  const QMimeData * mime=cb->mimeData(QClipboard::Clipboard);
  if(mime->hasFormat("XMLSciFigs::ObjectMakeUp")) {
    QByteArray makeup=mime->data("XMLSciFigs::ObjectMakeUp");
    XMLErrorReport xmler(XMLErrorReport::Read);
    xmler.setTitle(title);
    XMLSciFigs s;
    xmler.exec(s.restoreByteArray(makeup, this, XMLSciFigs::MakeUp));
    deepUpdate();
  }
}
void SciFigs::GraphicObject::polish ( ) [virtual]

Ensure that the widget is at least updated once.

Reimplemented in SciFigs::LegendWidget, SciFigs::TextEdit, and SciFigs::AxisWindow.

References addActions(), TRACE, and update().

Referenced by showEvent().

{
  TRACE;
  //setMouseTracking(true);
  if(actions().isEmpty()) addActions();
  update();
}
void SciFigs::GraphicObject::print ( QPrinter &  printer)

References TRACE.

Referenced by addActions(), exportImage(), image(), SciFigs::GraphicSheet::image(), SciFigs::GraphicSheet::print(), print(), and printSvg().

{
  TRACE;
  QPainter p;
  p.begin(&printer);
  print(p, (( double) printer.resolution())/2.54, 0, 0, false);
  p.end();
}
void SciFigs::GraphicObject::print ( int  dpi = 0) [slot]

User slot for printing the object at a defined resolution, overridding the internal printResolution.

If dpi is null, the internal printResolution is used.

References print(), and TRACE.

{
  TRACE;
  QPrinter printer(QPrinter::HighResolution);
  if(dpi==0) printer.setResolution(_printResolution);
  else printer.setResolution(dpi);
  if(Settings::printSetup(printer) ) {
    print(printer);
  }
}
void SciFigs::GraphicObject::print ( bool  outputToFile,
QString  name,
int  dpi 
) [slot]

Slot to be used from a script to print using the current print settings (from QSA::getPrintInfo())

References print(), printResolution(), and TRACE.

{
  TRACE;
  QPrinter printer(QPrinter::HighResolution);
  if(dpi==0) printer.setResolution(printResolution());
  else printer.setResolution(dpi);
  if(outputToFile) printer.setOutputFileName(name);
  else printer.setPrinterName(name);
  QPainter p;
  p.begin(&printer);
  print(p,((double)printer.resolution())/2.54, 0, 0, false);
  p.end();
}
void SciFigs::GraphicObject::print ( QPainter &  p,
double  dotpercm,
int  x0Sheet,
int  y0Sheet,
bool  mask 
) [protected, virtual]

Print the object to a Qpainter using relative coordinates. Relative coordinates are usefull for printing various pages. This basic implementation call the virtual function paint() to draw the object's content.

Reimplemented in SciFigs::ColorPaletteWidget, and SciFigs::AxisWindow.

References _printHeight, _printWidth, paint(), printLeft(), printTop(), TRACE, transparentMask(), and w.

{
  TRACE;
  int w=(int) (_printWidth * dotpercm);
  int h=(int) (_printHeight * dotpercm);
  int orX=(int) (printLeft() * dotpercm) - x0Sheet;
  int orY=(int) (printTop() * dotpercm) - y0Sheet;
  p.setWindow(0, 0, w, h);
  p.setViewport(orX, orY, w, h);
  if(mask && !transparentMask())
    p.fillRect(0, 0, w, h, Qt::color1);
  else
    paint(p, dotpercm, w, h, mask);
}
double SciFigs::GraphicObject::printBottom ( double  refHeight = 0.0) const

Return the printing Y position (Bottom) of the object in cm, taking anchor into account.

If refHeight is greater than 0.0, it is used rather than the current height.

References _anchor, _printAnchor, printHeight(), TRACE, QGpCoreTools::Point2D::y(), and YMask.

Referenced by SciFigs::GraphicSheet::printBottom().

{
  TRACE;
  if(_anchor & YMask) {
    if(refHeight>0.0)
      return _printAnchor.y()+refHeight;
    else
      return _printAnchor.y()+printHeight();
  } else {
    return _printAnchor.y();
  }
}
double SciFigs::GraphicObject::printBottomMargin ( ) const [inline]

Referenced by properties().

double SciFigs::GraphicObject::printHeight ( ) const [inline]
double SciFigs::GraphicObject::printLeft ( double  refWidth = 0.0) const

Return the printing X position (Left) of the object in cm, taking anchor into account.

If refWidth is greater than 0.0, it is used rather than the current width.

References _anchor, _printAnchor, printWidth(), TRACE, QGpCoreTools::Point2D::x(), and XMask.

Referenced by DinverDCGui::DCModelViewer::addText(), SciFigs::GraphicSheet::alignX(), image(), SciFigs::GraphicSheet::moveObject(), SciFigs::GraphicSheet::paste(), SciFigs::AxisWindow::print(), print(), printSvg(), MonoStation::WinResults::setLayout(), and SciFigs::GraphicSheet::showObject().

{
  TRACE;
  if(_anchor & XMask) {
    return _printAnchor.x();
  } else {
    if(refWidth>0.0)
      return _printAnchor.x()-refWidth;
    else
      return _printAnchor.x()-printWidth();
  }
}
double SciFigs::GraphicObject::printLeftMargin ( ) const [inline]

Referenced by properties().

{return _printLeftMargin;}

Referenced by SciFigs::ColorPaletteWidget::print(), print(), and properties().

{return _printResolution;}
double SciFigs::GraphicObject::printRight ( double  refWidth = 0.0) const

Return the printing X position (Right) of the object in cm, taking anchor into account.

If refWidth is greater than 0.0, it is used rather than the current width.

References _anchor, _printAnchor, printWidth(), TRACE, QGpCoreTools::Point2D::x(), and XMask.

Referenced by SciFigs::GraphicSheet::printRight(), and MonoStation::WinResults::setLayout().

{
  TRACE;
  if(_anchor & XMask) {
    if(refWidth>0.0)
      return _printAnchor.x()+refWidth;
    else
      return _printAnchor.x()+printWidth();
  } else {
    return _printAnchor.x();
  }
}
double SciFigs::GraphicObject::printRightMargin ( ) const [inline]

Referenced by properties().

void SciFigs::GraphicObject::printSvg ( const QString &  fileName,
int  dpi 
) [protected]

References _printBottomMargin, _printHeight, _printLeftMargin, _printRightMargin, _printTopMargin, _printWidth, print(), printLeft(), printTop(), restoreScaleFonts(), scaleFonts(), SciFigs::SciFigsGlobal::screenResolution(), setPrintSize(), and TRACE.

Referenced by exportImage().

{
  TRACE;
  QSvgGenerator gen;
  gen.setFileName(fileName);
  if(dpi==0) dpi=_printResolution;
  gen.setResolution(dpi);
  double resolution=dpi/2.54;
  double factor=resolution/SciFigsGlobal::screenResolution();
  double hMargins=_printLeftMargin + _printRightMargin;
  double vMargins=_printTopMargin + _printBottomMargin;
  int * tmpSize=scaleFonts(factor);
  setPrintSize(resolution);
  int totalw=(int) (( _printWidth + hMargins) * resolution);
  int totalh=(int) (( _printHeight + vMargins) * resolution);
  gen.setSize(QSize( totalw, totalh) );
  QPainter p;
  p.begin(&gen);
  if( !_mask) p.eraseRect(0, 0, totalw, totalh);
  p.save();
  p.translate( -(printLeft() - _printLeftMargin) * resolution, -(printTop() - _printTopMargin) * resolution);
  print(p, resolution, 0, 0, false);
  p.restore();
  p.end();
  restoreScaleFonts(tmpSize);
  setPrintSize(SciFigsGlobal::screenResolution());
}
double SciFigs::GraphicObject::printTop ( double  refHeight = 0.0) const

Return the printing Y position (Top) of the object in cm, taking anchor into account.

If refHeight is greater than 0.0, it is used rather than the current height.

References _anchor, _printAnchor, printHeight(), TRACE, QGpCoreTools::Point2D::y(), and YMask.

Referenced by SciFigs::GraphicSheet::alignY(), image(), SciFigs::GraphicSheet::moveObject(), SciFigs::GraphicSheet::paste(), SciFigs::AxisWindow::print(), print(), printSvg(), MonoStation::WinResults::setLayout(), and SciFigs::GraphicSheet::showObject().

{
  TRACE;
  if(_anchor & YMask) {
    return _printAnchor.y();
  } else {
    if(refHeight>0.0)
      return _printAnchor.y()-refHeight;
    else
      return _printAnchor.y()-printHeight();
  }
}
double SciFigs::GraphicObject::printTopMargin ( ) const [inline]

Referenced by properties().

{return _printTopMargin;}
double SciFigs::GraphicObject::printWidth ( ) const [inline]
double SciFigs::GraphicObject::printXAnchor ( ) const [inline]
double SciFigs::GraphicObject::printYAnchor ( ) const [inline]
void SciFigs::GraphicObject::properties ( PropertyWidget w) const [virtual]

Implements QGpGuiTools::PropertyItem.

Reimplemented in SciFigs::LegendWidget, SciFigs::ColorPaletteWidget, SciFigs::TextEdit, and SciFigs::ImageWidget.

References SciFigs::GraphicObjectGeometryProperties::Anchor, anchor(), SciFigs::GraphicObjectGeometryProperties::anchor2item(), SciFigs::GraphicObjectPrintProperties::BottomMargin, SciFigs::GraphicObjectGeometryProperties::ConstantWidthHeightRatio, constantWidthHeightRatio(), SciFigs::GraphicObjectGeometryProperties::Height, QGpGuiTools::PropertyWidget::id(), SciFigs::GraphicObjectPrintProperties::LeftMargin, SciFigs::GraphicObjectIdProperties::Name, objectName, printBottomMargin(), printHeight(), printLeftMargin(), printResolution(), printRightMargin(), printTopMargin(), printWidth(), printXAnchor(), printYAnchor(), SciFigs::GraphicObjectPrintProperties::Resolution, SciFigs::GraphicObjectPrintProperties::RightMargin, QGpGuiTools::PropertyWidget::setValue(), SciFigs::GraphicObjectPrintProperties::TopMargin, TRACE, SciFigs::GraphicObjectPrintProperties::Transparency, transparency(), SciFigs::GraphicObjectPrintProperties::TransparentMask, transparentMask(), SciFigs::GraphicObjectIdProperties::Type, SciFigs::GraphicObjectGeometryProperties::Width, SciFigs::GraphicObjectGeometryProperties::WidthHeightRatio, SciFigs::GraphicObjectGeometryProperties::X, and SciFigs::GraphicObjectGeometryProperties::Y.

void SciFigs::GraphicObject::restoreMakeUp ( QString  fileName = QString::null) [slot]

Restore make-up properties from fileName.

References QGpCoreTools::XMLErrorReport::exec(), SciFigs::XMLSciFigs::MakeUp, SciFigs::XMLSciFigs::restoreFile(), QGpCoreTools::XMLErrorReport::setFileName(), QGpCoreTools::XMLErrorReport::setTitle(), QGpCoreTools::tr(), and TRACE.

Referenced by addActions(), addPlot(), ChronogramWindow::ChronogramWindow(), GraphicWindow::GraphicWindow(), MapWindow::MapWindow(), MonoStation::WinResults::restoreMakeUp(), ChronogramWindow::subPoolUpdate(), MapWindow::subPoolUpdate(), and GraphicWindow::subPoolUpdate().

{
  TRACE;
  static QString title=tr( "Open an exisiting make-up" );
  if(fileName.isEmpty()) {
    fileName=Message::getOpenFileName(title, tr( "Graph make-up (*.mkup)" ));
  }
  if(fileName.length() > 0) {
    XMLErrorReport xmler(XMLErrorReport::Read);
    xmler.setTitle(title);
    xmler.setFileName(fileName);
    QFileInfo fi(fileName);
    XMLSciFigs s;
    xmler.exec(s.restoreFile(fileName, this, XMLSciFigs::MakeUp));
  }
}
void SciFigs::GraphicObject::restoreScaleFonts ( int *  fontSizeStorage) [protected, virtual]

Restore a saved scale for fonts

Reimplemented in SciFigs::ColorPaletteWidget, and SciFigs::AxisWindow.

References TRACE.

Referenced by image(), SciFigs::GraphicSheet::image(), and printSvg().

{
  TRACE;
  ASSERT (fontSizeStorage!=0);
  QFont f=font();
  f.setPointSize( *fontSizeStorage);
  setFont(f);
  delete fontSizeStorage;
}
void SciFigs::GraphicObject::saveMakeUp ( QString  fileName = QString::null) [slot]

Save make-up properties to fileName

References SciFigs::XMLSciFigs::MakeUp, SciFigs::MakeUpFilter::saveFile(), SciFigs::XMLSciFigs::saveString(), SciFigs::MakeUpFilter::setXml(), QGpCoreTools::tr(), and TRACE.

Referenced by addActions().

{
  TRACE;
  XMLSciFigs s;
  MakeUpFilter * d=new MakeUpFilter(this);
  d->setXml(s.saveString(this, XMLSciFigs::MakeUp));
  if(d->exec()==QDialog::Accepted) {
    if(fileName.isEmpty()) {
      fileName=Message::getSaveFileName(tr( "Save make-up as ..." ),
                                              tr( "Object make-up (*.mkup)" ));
    }
    if(fileName.length() > 0) {
      d->saveFile(fileName);
    }
  }
  delete d;
}
void SciFigs::GraphicObject::savePage ( QString  fileName = QString::null) [slot]

Save object in a .page file

References SciFigs::XMLSciFigs::Page, SciFigs::XMLSciFigs::saveFile(), QGpCoreTools::tr(), and TRACE.

Referenced by addActions().

{
  TRACE;
  if(fileName.isEmpty()) {
    fileName=Message::getSaveFileName(tr( "Save object as a page" ), tr( "Page file (*.page)" ));
  }
  if(fileName.length() > 0) {
    XMLSciFigs s;
    s.saveFile(fileName, this, XMLSciFigs::Page);
  }
}
int SciFigs::GraphicObject::scaleFont ( QFont &  f,
double  scale,
bool *  changed = 0 
) [static]

Scale the font, and replace familly if not scalable

Return the original pointSize

References QGpCoreTools::endl(), QGpCoreTools::tr(), and TRACE.

Referenced by SciFigs::SlopeEstimator::paintText(), SciFigs::NameLineLayer::paintText(), and scaleWidgetFonts().

{
  TRACE;
  int fontSizeStorage=f.pointSize();
  int scaledSize=(int) round(fontSizeStorage * scale);
  /* Test if it is a scalable font type.
     "Helvetica" is used as the default in this package, which is not
     a scalable font on my system. ghoscript replace it by "Nimbus Sans L".
     To get the same rendering for exported images, if the font familly is
     "Helvetica" and the that it is not scalable, replace it by "Nimbus Sans L"
     */
  static QFontDatabase fdb;
  if( !fdb.isScalable(f.family()) ) {
    App::stream() << tr( "WARNING font cannot be scaled: %1\n"
                  "    needed size=%2" ).arg(f.toString()).arg(scaledSize) << endl;
    QStringList subFonts=QFont::substitutes(f.family());
    QString subFamilly="Nimbus Sans L";
    for(QStringList::Iterator it=subFonts.begin();it!=subFonts.end();++it) {
      if(fdb.isScalable( *it) ) {
        subFamilly=*it;
        break;
      }
    }
    App::stream() << tr( "     --> replaced by %1" ).arg(subFamilly) << endl;
    f.setFamily(subFamilly);
    if(changed) * changed=true;
  } else if(changed) * changed=false;
  f.setPointSize(scaledSize);
  return fontSizeStorage;
}
int * SciFigs::GraphicObject::scaleFonts ( double  scale) [protected, virtual]

For some high resolution bitmap image, fonts must scaled

Reimplemented in SciFigs::ColorPaletteWidget, and SciFigs::AxisWindow.

References scaleWidgetFonts(), and TRACE.

Referenced by image(), SciFigs::GraphicSheet::image(), and printSvg().

{
  TRACE;
  int * fontSizeStorage=new int;
  QFont f=font();
  *fontSizeStorage=scaleWidgetFonts(this, scale);
  return fontSizeStorage;
}
int SciFigs::GraphicObject::scaleWidgetFonts ( QWidget *  w,
double  scale 
) [protected]

Scale the fonts of any widget, might be called by any re-implemetation of scaleFonts().

Return the original pointSize.

Used by scaleFonts(double scale) or by any re-implementation.

References scaleFont(), TRACE, and update().

Referenced by SciFigs::AxisWindow::scaleFonts(), and scaleFonts().

{
  TRACE;
  QFont f=w->font();
  bool changed;
  int fontSizeStorage=scaleFont(f, scale, &changed);
  if(changed) {
    // Recompute mask if necessary
    QFont fscreen=f;
    fscreen.setPointSize(fontSizeStorage);
    w->setFont(fscreen);
    update();
  }
  w->setFont(f);
  return fontSizeStorage;
}
void SciFigs::GraphicObject::setActive ( Qt::KeyboardModifiers  s)

Force the object to be selected and to be the active selection.

References SciFigs::SelectionWidget::Activated, SciFigs::SelectionWidget::state(), TRACE, and wantToBeSelected().

Referenced by mouseDoubleClickEvent(), and mousePressEvent().

{
  TRACE;
  if( !_selected || _selected->state()!=SelectionWidget::Activated)
    emit wantToBeSelected(this, s);
}
void SciFigs::GraphicObject::setAnchor ( QString  pa)

References BottomLeft, BottomRight, setAnchor(), TopLeft, TopRight, and TRACE.

{
  TRACE;
  if(pa=="TopLeft") setAnchor(TopLeft);
  else if(pa=="TopRight") setAnchor(TopRight);
  else if(pa=="BottomLeft") setAnchor(BottomLeft);
  else if(pa=="BottomRight") setAnchor(BottomRight);
  else setAnchor(TopLeft);
}

Referenced by SciFigs::ImageWidget::ImageWidget(), and setProperty().

{_constantWidthHeightRatio=c;}
void SciFigs::GraphicObject::setObjectName ( QString  name) [virtual]

If index is not negative, create a new OrderTip if does not exist and set its value to index. If index is negative delete the tip.

References SciFigs::OrderTip::setIndex(), and TRACE.

Referenced by SciFigs::GraphicSheet::showOrderIndex().

{
  TRACE;
  bool ret=false;
  if(index >= 0) {
    if( !_orderTip) {
      _orderTip=new OrderTip(this);
      _orderTip->move(0, 0);
      _orderTip->show();
      ret=true;
    }
    _orderTip->setIndex(index);
  } else {
    delete _orderTip;
    _orderTip=0;
  }
  return ret;
}

References _anchor, _printAnchor, _printHeight, BottomLeft, BottomRight, QGpCoreTools::Point2D::setY(), and TRACE.

Referenced by MonoStation::WinResults::setLayout().

{
  TRACE;
  if(val<0.0) val=0.0;
  switch(_anchor) {
  case BottomLeft:
  case BottomRight:
    _printAnchor.setY(val);
    break;
  default:
    _printAnchor.setY(val - _printHeight);
    break;
  }
}
void SciFigs::GraphicObject::setPrintBottomMargin ( double  val) [inline]

Set the bottom margin in cm.

Referenced by setProperty().

void SciFigs::GraphicObject::setPrintHeight ( double  val) [inline]
void SciFigs::GraphicObject::setPrintLeftMargin ( double  val) [inline]

Set the left margin in cm.

Referenced by setProperty().

void SciFigs::GraphicObject::setPrintResolution ( int  val) [inline]

Set the resolution of the object for printing tasks (dot per inch). 300 or 600 dpi is common values for classical printers. For html or slide presentations, it is better to set it as close as possible to the final screen resolution (e.g. 100 dpi). Large resizing in other softwares may reduce the quality of the image.

When printing a whole GraphicSheet, this resolution is just a minimum, it might be greater if other objects require higher resolution. To avoid surprise, select all objects and set resolution to be the same for all objects.

Referenced by SciFigs::ImageWidget::loadImage(), SciFigs::ColorPaletteWidget::print(), and setProperty().

{_printResolution=val;}

References _anchor, _printAnchor, _printWidth, BottomRight, QGpCoreTools::Point2D::setX(), TopRight, and TRACE.

Referenced by MonoStation::WinResults::setLayout().

{
  TRACE;
  if(val<0.0) val=0.0;
  switch(_anchor) {
  case TopRight:
  case BottomRight:
    _printAnchor.setX(val);
    break;
  default:
    _printAnchor.setX(val + _printWidth);
    break;
  }
}
void SciFigs::GraphicObject::setPrintRightMargin ( double  val) [inline]

Set the right margin in cm.

Referenced by setProperty().

void SciFigs::GraphicObject::setPrintSize ( double  dotpercm) [protected, virtual]

Called before and after printing to adjust the size of object. Normally what you see is what you get, but there might be some slight modification due to rounding error when scaling fonts. All object that offer options to automatically adjust size and if it depends upon fonts must re-implement this function.

The basic implemetation does nothing.

Reimplemented in SciFigs::LegendWidget, and SciFigs::TextEdit.

Referenced by image(), SciFigs::GraphicSheet::image(), and printSvg().

{
}

References _anchor, _printAnchor, _printHeight, QGpCoreTools::Point2D::setY(), TopLeft, TopRight, and TRACE.

Referenced by HistogramWidget::HistogramWidget(), and MonoStation::WinResults::setLayout().

{
  TRACE;
  if(val<0.0) val=0.0;
  switch(_anchor) {
  case TopLeft:
  case TopRight:
    _printAnchor.setY(val);
    break;
  default:
    _printAnchor.setY(val + _printHeight);
    break;
  }
}
void SciFigs::GraphicObject::setPrintTopMargin ( double  val) [inline]

Set the top margin in cm.

Referenced by setProperty().

void SciFigs::GraphicObject::setPrintWidth ( double  val) [inline]
void SciFigs::GraphicObject::setProperty ( uint  wid,
int  pid,
QVariant  val 
) [virtual]

Implements QGpGuiTools::PropertyItem.

Reimplemented in SciFigs::LegendWidget, SciFigs::ColorPaletteWidget, SciFigs::TextEdit, and SciFigs::ImageWidget.

References SciFigs::GraphicObjectGeometryProperties::Anchor, SciFigs::GraphicObjectPrintProperties::BottomMargin, SciFigs::GraphicObjectGeometryProperties::ConstantWidthHeightRatio, constantWidthHeightRatio(), SciFigs::GraphicObjectGeometryProperties::Height, SciFigs::GraphicObjectGeometryProperties::item2anchor(), SciFigs::GraphicObjectPrintProperties::LeftMargin, SciFigs::GraphicObjectIdProperties::Name, positionChanged(), printHeight(), printWidth(), SciFigs::GraphicObjectPrintProperties::Resolution, SciFigs::GraphicObjectPrintProperties::RightMargin, setAnchor(), setConstantWidthHeightRatio(), setObjectName(), setPrintBottomMargin(), setPrintHeight(), setPrintLeftMargin(), setPrintResolution(), setPrintRightMargin(), setPrintTopMargin(), setPrintWidth(), setPrintXAnchor(), setPrintYAnchor(), setTransparency(), setTransparentMask(), sizeChanged(), SciFigs::GraphicObjectPrintProperties::TopMargin, TRACE, SciFigs::GraphicObjectPrintProperties::Transparency, SciFigs::GraphicObjectPrintProperties::TransparentMask, SciFigs::GraphicObjectIdProperties::Type, SciFigs::GraphicObjectGeometryProperties::Width, SciFigs::GraphicObjectGeometryProperties::WidthHeightRatio, SciFigs::GraphicObjectGeometryProperties::X, and SciFigs::GraphicObjectGeometryProperties::Y.

{
  TRACE;

  if(wid==_tabGeomery) {
    switch(pid) {
    case GraphicObjectGeometryProperties::X:
      setPrintXAnchor(val.toDouble());
      emit positionChanged();
      break;
    case GraphicObjectGeometryProperties::Y:
      setPrintYAnchor(val.toDouble());
      emit positionChanged();
      break;
    case GraphicObjectGeometryProperties::Anchor:
      setAnchor(GraphicObjectGeometryProperties::item2anchor(val.toInt()) );
      emit positionChanged();
      break;
    case GraphicObjectGeometryProperties::Width:
      if(constantWidthHeightRatio()) {
        double rhw=printHeight()/printWidth();
        setPrintWidth(val.toDouble());
        setPrintHeight(rhw * printWidth());
      } else {
        setPrintWidth(val.toDouble());
      }
      emit sizeChanged();
      break;
    case GraphicObjectGeometryProperties::Height:
      if(constantWidthHeightRatio()) {
        double rwh=printWidth()/printHeight();
        setPrintHeight(val.toDouble());
        setPrintWidth(rwh * printHeight());
      } else {
        setPrintHeight(val.toDouble());
      }
      emit sizeChanged();
      break;
    case GraphicObjectGeometryProperties::ConstantWidthHeightRatio:
      setConstantWidthHeightRatio(val.toBool());
      break;
    case GraphicObjectGeometryProperties::WidthHeightRatio:
      break;
    }
  } else if(wid==_tabPrint) {
    switch(pid) {
    case GraphicObjectPrintProperties::LeftMargin:
      setPrintLeftMargin(val.toDouble());
      emit sizeChanged();
      break;
    case GraphicObjectPrintProperties::RightMargin:
      setPrintRightMargin(val.toDouble());
      emit sizeChanged();
      break;
    case GraphicObjectPrintProperties::TopMargin:
      setPrintTopMargin(val.toDouble());
      emit sizeChanged();
      break;
    case GraphicObjectPrintProperties::BottomMargin:
      setPrintBottomMargin(val.toDouble());
      emit sizeChanged();
      break;
    case GraphicObjectPrintProperties::Resolution:
      setPrintResolution(val.toInt());
      break;
    case GraphicObjectPrintProperties::Transparency:
      setTransparency(val.toInt());
      break;
    case GraphicObjectPrintProperties::TransparentMask:
      setTransparentMask(val.toBool());
      break;
    }
  } else if(wid==_tabId) {
    switch(pid) {
    case GraphicObjectIdProperties::Name:
      setObjectName(val.toString());
      break;
    case GraphicObjectIdProperties::Type: // Read-only
      break;
    default:
      break;
    }
  }
}
void SciFigs::GraphicObject::setRemovable ( bool  r) [inline]

Select the object by attribuing a SelectionWidget.

Select object by affecting a new selection widget s.

References TRACE.

Referenced by SciFigs::SelectionWidget::leaveEvent(), SciFigs::GraphicSheet::removeObject(), SciFigs::SelectionWidget::SelectionWidget(), and SciFigs::GraphicSheet::selectObjects().

{
  TRACE;
  _selected=s;
}
void SciFigs::GraphicObject::setToolTip ( const QString &  t)

Share tooltip with its selection widget if any.

{
  if(_selected) {
    _selected->setToolTip(t);
  }
  QWidget::setToolTip(t);
}
void SciFigs::GraphicObject::setTransparency ( int  val) [inline]

Referenced by setProperty().

{_transparency=val;}

References TRACE.

Referenced by setProperty(), and SciFigs::TextEdit::TextEdit().

{
  TRACE;
  _mask=val;
  if( !val) clearMask();
}
void SciFigs::GraphicObject::showEvent ( QShowEvent *  e) [protected, virtual]

Ensures that the widget is polished when not docked into a GraphicSheet

References polish(), and TRACE.

virtual QSize SciFigs::GraphicObject::sizeHint ( ) const [inline, virtual]

Reimplemented in SciFigs::ActivityMonitor.

{return QSize(250, 250);}
{_oldPrintPos=_printAnchor;}
int SciFigs::GraphicObject::transparency ( ) const [inline]

Referenced by properties().

{return _transparency;}
bool SciFigs::GraphicObject::transparentMask ( ) const [inline]
void SciFigs::GraphicObject::update ( ) [virtual, slot]
void SciFigs::GraphicObject::updateGeometry ( ) [virtual, slot]

Emit the signals positionChanged() and sizeChanged(). When docked in a sheet, it tells GraphicSheet to move or to resize the object together with its selection widget.

Call this function every time you modify the position or the size of the object, e.g. with printX or printWidth properties.

Reimplemented in SciFigs::AxisWindow.

References positionChanged(), sizeChanged(), TRACE, transparentMask(), and updateMask().

Referenced by TFAResults::createObjects(), MonoStation::WinResults::loadResults(), MonoStation::WinResults::setLayout(), MonoStation::WinResults::setStations(), and xml_polish().

void SciFigs::GraphicObject::updateMask ( ) [protected]

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

Referenced by SciFigs::ColorPaletteWidget::deepUpdate(), exportImage(), SciFigs::GraphicSheet::image(), SciFigs::ColorPaletteWidget::update(), update(), and updateGeometry().

{
  TRACE;
  // Repaint the widget in a pixmap (like it appear on the screen)
  if(width()==0 || height()==0) return;
  QPixmap pixmap(width(), height());
  QPainter p;
  p.begin(&pixmap);
  p.fillRect(0, 0, width(), height(), Qt::white);
  paint(p, SciFigsGlobal::screenResolution(), width(), height(), false);
  p.end();
  QBitmap mask=colorMask(pixmap, 0xFFFFFFFF);
  setMask(mask); // TODO: on next repaint this mask will be used, but the rest of the widget won't be erased
}
void SciFigs::GraphicObject::wantToBeSelected ( GraphicObject ,
Qt::KeyboardModifiers   
) [signal]

Referenced by setActive().

Referenced by mousePressEvent().

virtual XMLMember SciFigs::GraphicObject::xml_member ( XML_MEMBER_ARGS  ) [inline, protected, virtual]

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.

Reimplemented in SciFigs::ColorPaletteWidget, SciFigs::LegendWidget, SciFigs::AxisWindow, and SciFigs::TextEdit.

{return qobject_member(this, tag, attributes, context);}
void SciFigs::GraphicObject::xml_polish ( XML_POLISH_ARGS  ) [protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

Reimplemented in SciFigs::AxisWindow.

References TRACE, and updateGeometry().

{
  TRACE;
  Q_UNUSED(context);
  /* Used to re-order object according to make-up
  if(sheet()) {
    if(selectionWidget()) selectionWidget()->raise();
    raise();
  }*/
  updateGeometry();
}
virtual bool SciFigs::GraphicObject::xml_setProperty ( XML_SETPROPERTY_ARGS  ) [inline, 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.

Reimplemented in SciFigs::TextEdit.

{return qobject_setProperty(this, memberID, tag, attributes, content, context);}
virtual const QString& SciFigs::GraphicObject::xml_tagName ( ) const [inline, virtual]
virtual void SciFigs::GraphicObject::xml_writeProperties ( XML_WRITEPROPERTIES_ARGS  ) const [inline, protected, virtual]

Reimplemented from QGpCoreTools::XMLClass.

{qobject_writeProperties(this, this, s, context);}

Friends And Related Function Documentation

friend class GraphicSheet [friend]
friend class SelectionWidget [friend]

Member Data Documentation

const QString SciFigs::GraphicObject::pixelImageFilter = "PNG (*.png);;PPM (*.ppm);;XBM (*.xbm);;XPM (*.xpm)" [static]
const QString SciFigs::GraphicObject::vectorialImageFilter = "PS (*.ps);;PDF (*.pdf);;SVG (*.svg)" [static]
const QString SciFigs::GraphicObject::xmlGraphicObjectTag = "GraphicObject" [static]

Property Documentation

QString SciFigs::GraphicObject::anchor [read, write]
QString SciFigs::GraphicObject::name [read, write]

Referenced by setObjectName().

QString SciFigs::GraphicObject::objectName [read, write]

Return the bottom margin in cm.

Referenced by SciFigs::GraphicSheet::autoResizeContent().

Return the left margin in cm.

Return the printing resolution of the object in dot per inch

Referenced by SciFigs::GraphicSheet::maximumResolution().

Return the right margin in cm.

Referenced by SciFigs::GraphicSheet::autoResizeContent().

Return the top margin in cm.

double SciFigs::GraphicObject::printWidth [read, write]
double SciFigs::GraphicObject::printX [read, write]
double SciFigs::GraphicObject::printY [read, write]

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