Source Code (Use browser search to find items of interest.)

Class Index

killustrator'AlignCmd (./koffice/killustrator/share/AlignCmd.h:38)

class AlignCmd : public ObjectManipCmd {
public:
  AlignCmd (GDocument* doc, HorizAlignment halign, VertAlignment valign,
	    bool centerToPage = false, bool snapToGrid = false);

  void execute ();

private:
  HorizAlignment horizAlign;
  VertAlignment vertAlign;
  bool center, snap;
};

killustrator'AlignCmd::AlignCmd() (./koffice/killustrator/share/AlignCmd.cc:31)

AlignCmd::AlignCmd (GDocument* doc, HorizAlignment halign, 
                    VertAlignment valign, bool centerToPage, 
		    bool snapToGrid) : ObjectManipCmd (doc, i18n("Align")) {
  horizAlign = halign;
  vertAlign = valign;
  center = centerToPage;
  snap = snapToGrid;
}


killustrator'AlignCmd::execute() (./koffice/killustrator/share/AlignCmd.cc:40)

void AlignCmd::execute () {
  GObject* alignObject; // the object for aligning the others
  Rect alignBox;
  float dx, dy;
  unsigned int i;

  unsigned int nobjs = document->selectionCount ();
  
  if (nobjs == 0)
    return;

  ObjectManipCmd::execute ();
  document->setAutoUpdate (false);
  if (nobjs > 1) {
    // alignment is possible only for two or more objects

    list<GObject*>::iterator it = document->getSelection ().begin ();
    alignObject = document->getSelection ().back ();
    alignBox = alignObject->boundingBox ();

    for (i = 0, it = document->getSelection ().begin ();
	 it != document->getSelection ().end (); it++, i++) {
      GObject* obj = *it;
      if (obj == alignObject)
        continue;

      Rect objBox = obj->boundingBox ();
  
      switch (horizAlign) {
      case HAlign_Left:
        dx = alignBox.left () - objBox.left ();
        break;
      case HAlign_Center:
        {
          Coord aCoord = alignBox.center ();
          Coord oCoord = objBox.center ();
          dx = aCoord.x () - oCoord.x ();
          break;
        }
      case HAlign_Right:
        dx = alignBox.right () - objBox.right ();
        break;
      default:
        dx = 0;
        break;
      }

      switch (vertAlign) {
      case VAlign_Top:
        dy = alignBox.top () - objBox.top ();
        break;
      case VAlign_Center:
        {
          Coord aCoord = alignBox.center ();
          Coord oCoord = objBox.center ();
          dy = aCoord.y () - oCoord.y ();
          break;
        }
      case VAlign_Bottom:
        dy = alignBox.bottom () - objBox.bottom ();
        break;
      default:
        dy = 0;
        break;
      }

      QWMatrix matrix;
      matrix.translate (dx, dy);
      obj->transform (matrix, ! center);
    }
  }

  if (center) {
    // center the selection to the page
    Rect page (0, 0, document->getPaperWidth (), document->getPaperHeight ());
    Coord pcenter = page.center ();
    Coord bcenter = document->boundingBoxForSelection ().center ();
    QWMatrix matrix;
    matrix.translate (pcenter.x () - bcenter.x (),
		      pcenter.y () - bcenter.y ());
    for (list<GObject*>::iterator it = document->getSelection ().begin ();
	 it != document->getSelection ().end (); it++)
      (*it)->transform (matrix, true);
  }
  document->setAutoUpdate (true);
}