Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pageitem_imageframe.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008                           pageitem.cpp  -  description
00009                              -------------------
00010     begin                : Sat Apr 7 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "pageitem_imageframe.h"
00025 #include "pageitem_imageframe.moc"
00026 #include <qpainter.h>
00027 #include <qpen.h>
00028 #include <qfont.h>
00029 #include <qregion.h>
00030 #include <qpoint.h>
00031 #include <qfileinfo.h>
00032 #include <qdrawutil.h>
00033 #include <qbitmap.h>
00034 #include <qregexp.h>
00035 #include <qmessagebox.h>
00036 #include <cmath>
00037 #include <cassert>
00038 
00039 #include "mpalette.h"
00040 #include "page.h"
00041 #include "pageitem.h"
00042 #include "prefsmanager.h"
00043 #include "scpaths.h"
00044 #include "scribus.h"
00045 #include "scribusstructs.h"
00046 #include "scribusdoc.h"
00047 #include "commonstrings.h"
00048 #include "undomanager.h"
00049 #include "undostate.h"
00050 #include "scconfig.h"
00051 
00052 #include "util.h"
00053 
00054 using namespace std;
00055 
00056 PageItem_ImageFrame::PageItem_ImageFrame(ScribusDoc *pa, double x, double y, double w, double h, double w2, QString fill, QString outline)
00057        : PageItem(pa, PageItem::ImageFrame, x, y, w, h, w2, fill, outline)
00058 {
00059 }
00060 
00061 void PageItem_ImageFrame::DrawObj_Item(ScPainter *p, QRect /*e*/, double sc)
00062 {
00063        if(!m_Doc->RePos)
00064        {
00065               if (!m_Doc->layerOutline(LayerNr))
00066               {
00067                      if ((fillColor() != CommonStrings::None) || (GrType != 0))
00068                      {
00069                             p->setupPolygon(&PoLine);
00070                             p->fillPath();
00071                      }
00072                      p->save();
00073 #ifdef HAVE_CAIRO
00074                      if (imageClip.size() != 0)
00075                      {
00076                             p->setupPolygon(&imageClip);
00077                             p->setClipPath();
00078                      }
00079                      p->setupPolygon(&PoLine);
00080                      p->setClipPath();
00081 #else
00082                      if (imageClip.size() != 0)
00083                      {
00084                             p->setupPolygon(&imageClip);
00085                             p->setClipPath2(&PoLine, true);
00086                      }
00087                      else
00088                      {
00089                             p->setupPolygon(&PoLine);
00090                             p->setClipPath();
00091                      }
00092 #endif
00093                      if (Pfile.isEmpty())
00094                      {
00095                             if ((Frame) && (m_Doc->guidesSettings.framesShown))
00096                             {
00097                                    p->setPen(black, 1, SolidLine, FlatCap, MiterJoin);
00098                                    p->drawLine(FPoint(0, 0), FPoint(Width, Height));
00099                                    p->drawLine(FPoint(0, Height), FPoint(Width, 0));
00100                             }
00101                      }
00102                      else
00103                      {
00104                             //If we are missing our image, draw a red cross in the frame
00105                             if ((!PicArt) || (!PicAvail))
00106                             {
00107                                    if ((Frame) && (m_Doc->guidesSettings.framesShown))
00108                                    {
00109                                           p->setPen(red, 1, SolidLine, FlatCap, MiterJoin);
00110                                           p->drawLine(FPoint(0, 0), FPoint(Width, Height));
00111                                           p->drawLine(FPoint(0, Height), FPoint(Width, 0));
00112                                    }
00113                             }
00114                             else
00115                             {
00116 #ifdef HAVE_CAIRO
00117                                    if (imageFlippedH())
00118                                    {
00119                                           p->translate(Width, 0);
00120                                           p->scale(-1, 1);
00121                                    }
00122                                    if (imageFlippedV())
00123                                    {
00124                                           p->translate(0, Height);
00125                                           p->scale(1, -1);
00126                                    }
00127                                    p->translate(LocalX*LocalScX, LocalY*LocalScY);
00128 #else
00129                                    if (imageFlippedH())
00130                                    {
00131                                           p->translate(Width * sc, 0);
00132                                           p->scale(-1, 1);
00133                                    }
00134                                    if (imageFlippedV())
00135                                    {
00136                                           p->translate(0, Height * sc);
00137                                           p->scale(1, -1);
00138                                    }
00139                                    p->translate(LocalX*LocalScX*sc, LocalY*LocalScY*sc);
00140 #endif
00141                                    p->scale(LocalScX, LocalScY);
00142                                    if (pixm.imgInfo.lowResType != 0)
00143                                           p->scale(pixm.imgInfo.lowResScale, pixm.imgInfo.lowResScale);
00144                                    p->drawImage(pixm.qImagePtr());
00145                             }
00146                      }
00147                      p->restore();
00148               }
00149        }
00150 }
00151 
00152 void PageItem_ImageFrame::clearContents()
00153 {
00154        effectsInUse.clear();
00155        PicAvail = false;
00156        Pfile = "";
00157        pixm = ScImage();
00158 
00159        LocalScX = 1;
00160        LocalScY = 1;
00161        OrigW = 0;
00162        OrigH = 0;
00163        LocalX = 0;
00164        LocalY = 0;
00165        setImageFlippedH(false);
00166        setImageFlippedV(false);
00167        EmProfile = "";
00168        ScaleType = true;
00169        AspectRatio = true;
00170        setFillTransparency(0.0);
00171        setLineTransparency(0.0);
00172        imageClip.resize(0);
00173        //                          emit UpdtObj(Doc->currentPage->pageNr(), ItemNr);
00174 }
00175 
00176 void PageItem_ImageFrame::handleModeEditKey(QKeyEvent *k, bool& keyRepeat)
00177 {
00178        double moveBy=1.0;
00179        ButtonState buttonState = k->state();
00180        bool resizingImage=false;
00181        bool controlDown=(buttonState & ControlButton);
00182        if ((buttonState & ShiftButton) && !controlDown)
00183               moveBy=10.0;
00184        else if ((buttonState & ShiftButton) && controlDown && !(buttonState & AltButton))
00185               moveBy=0.1;
00186        else if ((buttonState & ShiftButton) && controlDown && (buttonState & AltButton))
00187               moveBy=0.01;
00188        else if (!(buttonState & ShiftButton) && (buttonState & AltButton))
00189               resizingImage=true;
00190        double dX=0.0,dY=0.0;
00191        int kk = k->key();
00192        if (!resizingImage)
00193        {
00194               moveBy/=m_Doc->unitRatio();//Lets allow movement by the current doc ratio, not only points
00195               switch (kk)
00196               {
00197                      case Key_Left:
00198                             dX=-moveBy;
00199                             break;
00200                      case Key_Right:
00201                             dX=moveBy;
00202                             break;
00203                      case Key_Up:
00204                             dY=-moveBy;
00205                             break;
00206                      case Key_Down:
00207                             dY=moveBy;
00208                             break;
00209               }
00210               if (dX!=0.0 || dY!=0.0)
00211               {
00212                      moveImageInFrame(dX, dY);
00213                      ScribusView* view = m_Doc->view();
00214                      view->updateContents(getRedrawBounding(view->scale())); 
00215               }
00216        }
00217        else
00218        {
00219               switch (kk)
00220               {
00221                      case Key_Left:
00222                             dX=-moveBy+100;
00223                             break;
00224                      case Key_Right:
00225                             dX=moveBy+100;
00226                             break;
00227                      case Key_Up:
00228                             dY=-moveBy+100;
00229                             break;
00230                      case Key_Down:
00231                             dY=moveBy+100;
00232                             break;
00233                      default:
00234                             return;
00235               }             
00236               if (dX!=0.0)
00237               {
00238                      double newXScale=dX / 100.0 * LocalScX;
00239                      setImageXScale(newXScale);
00240                      if (!controlDown)
00241                      {
00242                             double newYScale=dX / 100.0 * LocalScY;
00243                             setImageYScale(newYScale);
00244                      }
00245               }
00246               else
00247               if (dY!=0.0)
00248               {
00249                      double newYScale=dY / 100.0 * LocalScY;
00250                      setImageYScale(newYScale);
00251                      if (!controlDown)
00252                      {
00253                             double newXScale=dY / 100.0 * LocalScY;
00254                             setImageXScale(newXScale);
00255                      }
00256               }
00257               if (dX!=0.0 || dY!=0.0)
00258                      if (imageClip.size() != 0)
00259                      {
00260                             imageClip = pixm.imgInfo.PDSpathData[pixm.imgInfo.usedPath].copy();
00261                             QWMatrix cl;
00262                             cl.translate(imageXOffset()*imageXScale(), imageYOffset()*imageYScale());
00263                             cl.scale(imageXScale(), imageYScale());
00264                             imageClip.map(cl);
00265                      }
00266               ScribusView* view = m_Doc->view();
00267               view->updateContents(getRedrawBounding(view->scale())); 
00268        }
00269 }