Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

lensdialog.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 *   Copyright (C) 2007 by Franz Schmid                                    *
00009 *   franz.schmid@altmuehlnet.de                                           *
00010 *                                                                         *
00011 *   This program is free software; you can redistribute it and/or modify  *
00012 *   it under the terms of the GNU General Public License as published by  *
00013 *   the Free Software Foundation; either version 2 of the License, or     *
00014 *   (at your option) any later version.                                   *
00015 *                                                                         *
00016 *   This program is distributed in the hope that it will be useful,       *
00017 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00019 *   GNU General Public License for more details.                          *
00020 *                                                                         *
00021 *   You should have received a copy of the GNU General Public License     *
00022 *   along with this program; if not, write to the                         *
00023 *   Free Software Foundation, Inc.,                                       *
00024 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00025 ***************************************************************************/
00026 
00027 #include "lensdialog.h"
00028 #include <QRadialGradient>
00029 #include "util_icon.h"
00030 #include "selection.h"
00031 #include "sccolorengine.h"
00032 #include "scpattern.h"
00033 #include "commonstrings.h"
00034 
00035 LensItem::LensItem(QRectF geom, LensDialog *parent) : QGraphicsRectItem(geom)
00036 {
00037     dialog = parent;
00038     strength = -100.0;
00039     scaling = 1.0,
00040     handle = -1;
00041     setPen(QPen(Qt::black));
00042     QRadialGradient radialGrad(QPointF(0.5, 0.5), 1.0);
00043     radialGrad.setColorAt(0.0, QColor(255, 0, 0, 127));
00044     radialGrad.setColorAt(0.1, QColor(255, 0, 0, 127));
00045     radialGrad.setColorAt(1.0, QColor(255, 255, 255, 0));
00046 #if QT_VERSION  >= 0x040301
00047     radialGrad.setCoordinateMode(QGradient::ObjectBoundingMode);
00048 #endif
00049     setBrush(radialGrad);
00050     setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
00051     setAcceptsHoverEvents(true);
00052 }
00053 
00054 void LensItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
00055 {
00056     Q_UNUSED(widget);
00057     painter->setPen(QPen(Qt::black, 1.0 / option->levelOfDetail));
00058     QRadialGradient radialGrad(QPointF(0.5, 0.5), 1.0);
00059     radialGrad.setColorAt(0.0, QColor(255, 0, 0, 127));
00060     radialGrad.setColorAt(0.1, QColor(255, 0, 0, 127));
00061     radialGrad.setColorAt(1.0, QColor(255, 255, 255, 0));
00062 #if QT_VERSION  >= 0x040301
00063     radialGrad.setCoordinateMode(QGradient::ObjectBoundingMode);
00064 #endif
00065     painter->setBrush(radialGrad);
00066     painter->drawEllipse(rect().toRect());
00067     if (option->state & QStyle::State_Selected)
00068     {
00069         scaling = option->levelOfDetail;
00070         double siz = 6.0 / option->levelOfDetail;
00071         QRectF br = boundingRect();
00072         painter->setBrush(Qt::NoBrush);
00073         painter->setPen(QPen(Qt::red, 1.0 / option->levelOfDetail, Qt::DotLine));
00074         painter->drawRect(br);
00075         painter->setBrush(Qt::red);
00076         painter->setPen(Qt::NoPen);
00077         painter->drawRect(QRectF(br.x() + br.width(), br.y() + br.height(), -siz, -siz));
00078         painter->drawRect(QRectF(br.x() + br.width(), br.y(), -siz, siz));
00079         painter->drawRect(QRectF(br.x(), br.y() + br.height(), siz, -siz));
00080         painter->drawRect(QRectF(br.x(), br.y(), siz, siz));
00081     }
00082 }
00083 
00084 void LensItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
00085 {
00086     mousePoint = event->screenPos();
00087     QRectF br = boundingRect();
00088     double siz = 6.0 / scaling;
00089     if (QRectF(br.x(), br.y(), siz, siz).contains(event->pos()))
00090         handle = 0;
00091     else if (QRectF(br.x() + br.width(), br.y(), -siz, siz).contains(event->pos()))
00092         handle = 1;
00093     else if (QRectF(br.x() + br.width(), br.y() + br.height(), -siz, -siz).contains(event->pos()))
00094         handle = 2;
00095     else if (QRectF(br.x(), br.y() + br.height(), siz, -siz).contains(event->pos()))
00096         handle = 3;
00097     else
00098         handle = -1;
00099     QGraphicsItem::mousePressEvent(event);
00100 }
00101 
00102 void LensItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
00103 {
00104     QRectF r = rect();
00105     double dx = (mousePoint.x() - event->screenPos().x()) / scaling;
00106     if (handle == 0)
00107     {
00108         QPointF tl = r.topLeft();
00109         tl = tl - QPointF(dx, dx);
00110         r.setTopLeft(tl);
00111         setRect(r.normalized());
00112     }
00113     else if (handle == 1)
00114     {
00115         QPointF tl = r.topRight();
00116         tl = tl - QPointF(dx, -dx);
00117         r.setTopRight(tl);
00118         setRect(r.normalized());
00119     }
00120     else if (handle == 2)
00121     {
00122         QPointF tl = r.bottomRight();
00123         tl = tl - QPointF(dx, dx);
00124         r.setBottomRight(tl);
00125         setRect(r.normalized());
00126     }
00127     else if (handle == 3)
00128     {
00129         QPointF tl = r.bottomLeft();
00130         tl = tl - QPointF(dx, -dx);
00131         r.setBottomLeft(tl);
00132         setRect(r.normalized());
00133     }
00134     else
00135         QGraphicsItem::mouseMoveEvent(event);
00136     mousePoint = event->screenPos();
00137     dialog->lensSelected(this);
00138 }
00139 
00140 void LensItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
00141 {
00142     handle = -1;
00143     updateEffect();
00144     QGraphicsItem::mouseReleaseEvent(event);
00145 }
00146 
00147 void LensItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
00148 {
00149     QPainterPath p;
00150     p.addEllipse(rect());
00151     if ((p.contains(event->pos())) && (isSelected()))
00152         qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
00153     else
00154         qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
00155 }
00156 
00157 void LensItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
00158 {
00159     QPainterPath p;
00160     p.addEllipse(rect());
00161     if (isSelected())
00162     {
00163         if (p.contains(event->pos()))
00164             qApp->changeOverrideCursor(QCursor(Qt::SizeAllCursor));
00165         else
00166         {
00167             QRectF br = boundingRect();
00168             double siz = 6.0 / scaling;
00169             if (QRectF(br.x(), br.y(), siz, siz).contains(event->pos()))
00170                 qApp->changeOverrideCursor(QCursor(Qt::SizeFDiagCursor));
00171             else if (QRectF(br.x() + br.width(), br.y(), -siz, siz).contains(event->pos()))
00172                 qApp->changeOverrideCursor(QCursor(Qt::SizeBDiagCursor));
00173             else if (QRectF(br.x() + br.width(), br.y() + br.height(), -siz, -siz).contains(event->pos()))
00174                 qApp->changeOverrideCursor(QCursor(Qt::SizeFDiagCursor));
00175             else if (QRectF(br.x(), br.y() + br.height(), siz, -siz).contains(event->pos()))
00176                 qApp->changeOverrideCursor(QCursor(Qt::SizeBDiagCursor));
00177             else
00178                 qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
00179         }
00180     }
00181     else
00182         qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
00183 }
00184 
00185 void LensItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
00186 {
00187     qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
00188 }
00189 
00190 void LensItem::setStrength(double s)
00191 {
00192     strength = s;
00193 }
00194 
00195 QVariant LensItem::itemChange(GraphicsItemChange change, const QVariant &value)
00196 {
00197     switch (change)
00198     {
00199         case ItemSelectedChange:
00200             dialog->lensSelected(this);
00201             break;
00202         case ItemPositionHasChanged:
00203             dialog->setLensPositionValues(mapToScene(rect().center()));
00204             updateEffect();
00205             break;
00206         default:
00207             break;
00208     }
00209     return QGraphicsItem::itemChange(change, value);
00210 }
00211 
00212 void LensItem::updateEffect()
00213 {
00214     LensItem *item;
00215     for (int a = 0; a < dialog->origPathItem.count(); a++)
00216     {
00217         QGraphicsPathItem* pItem = dialog->origPathItem[a];
00218         QPainterPath path = dialog->origPath[a];
00219         path = pItem->mapToScene(path);
00220         for (int b = 0; b < dialog->lensList.count(); b++)
00221         {
00222             item = dialog->lensList[b];
00223             path = lensDeform(path, item->mapToScene(item->rect().center()), item->rect().width() / 2.0, item->strength / 100.0);
00224         }
00225         path = pItem->mapFromScene(path);
00226         pItem->setPath(path);
00227     }
00228 }
00229 
00230 QPainterPath LensItem::lensDeform(const QPainterPath &source, const QPointF &offset, double m_radius, double s)
00231 {
00232     QPainterPath path;
00233     path.addPath(source);
00234     for (int i = 0; i < path.elementCount(); ++i)
00235     {
00236         const QPainterPath::Element &e = path.elementAt(i);
00237         double dx = e.x - offset.x();
00238         double dy = e.y - offset.y();
00239         double len = m_radius - sqrt(dx * dx + dy * dy);
00240         if (len > 0)
00241             path.setElementPositionAt(i, e.x - s * dx * len / m_radius, e.y - s * dy * len / m_radius);
00242     }
00243     return path;
00244 }
00245 
00246 LensDialog::LensDialog(QWidget* parent, ScribusDoc *doc) : QDialog(parent)
00247 {
00248     setupUi(this);
00249     buttonRemove->setEnabled(false);
00250     setModal(true);
00251     buttonZoomOut->setIcon(QIcon(loadIcon("16/zoom-out.png")));
00252     buttonZoomI->setIcon(QIcon(loadIcon("16/zoom-in.png")));
00253 
00254     PageItem *currItem;
00255     double gx, gy, gh, gw;
00256     doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
00257     uint selectedItemCount = doc->m_Selection->count();
00258     if (selectedItemCount == 1)
00259     {
00260         currItem = doc->m_Selection->itemAt(0);
00261         gx = currItem->xPos();
00262         gy = currItem->yPos();
00263     }
00264     QStack<PageItem*> groupStack;
00265     QStack<QGraphicsPathItem*> groupStack2;
00266     QStack<PageItem*> groupStack3;
00267     groupStack2.push(0);
00268     for (uint i = 0; i < selectedItemCount; ++i)
00269     {
00270         currItem = doc->m_Selection->itemAt(i);
00271         FPointArray path = currItem->PoLine;
00272         QPainterPath pp;
00273         if (currItem->itemType() == PageItem::PolyLine)
00274             pp = path.toQPainterPath(false);
00275         else
00276             pp = path.toQPainterPath(true);
00277         origPath.append(pp);
00278         QGraphicsPathItem* pItem = new QGraphicsPathItem(pp, groupStack2.top());
00279         if (groupStack2.top() == 0)
00280         {
00281             scene.addItem(pItem);
00282             pItem->setPos(currItem->xPos() - gx, currItem->yPos() - gy);
00283             pItem->rotate(currItem->rotation());
00284         }
00285         else
00286         {
00287             PageItem* parent = groupStack3.top();
00288             QMatrix mm;
00289             mm.rotate(-parent->rotation());
00290             mm.translate(-parent->xPos(), -parent->yPos());
00291             pItem->setPos(mm.map(QPointF(currItem->xPos(), currItem->yPos())));
00292         }
00293         pItem->setZValue(i);
00294         origPathItem.append(pItem);
00295         if (((currItem->fillColor() == CommonStrings::None) && (currItem->GrType == 0)) || (currItem->controlsGroup()))
00296             pItem->setBrush(Qt::NoBrush);
00297         else
00298         {
00299             if (currItem->GrType != 0)
00300             {
00301                 if (currItem->GrType != 8)
00302                 {
00303                     QGradient pat;
00304                     double x1 = currItem->GrStartX;
00305                     double y1 = currItem->GrStartY;
00306                     double x2 = currItem->GrEndX;
00307                     double y2 = currItem->GrEndY;
00308                     switch (currItem->GrType)
00309                     {
00310                         case 1:
00311                         case 2:
00312                         case 3:
00313                         case 4:
00314                         case 6:
00315                             pat = QLinearGradient(x1, y1,  x2, y2);
00316                             break;
00317                         case 5:
00318                         case 7:
00319                             pat = QRadialGradient(x1, y1, sqrt(pow(x2 - x1, 2) + pow(y2 - y1,2)), x1, y1);
00320                             break;
00321                     }
00322                     QList<VColorStop*> colorStops = currItem->fill_gradient.colorStops();
00323                     QColor qStopColor;
00324                     for( int offset = 0 ; offset < colorStops.count() ; offset++ )
00325                     {
00326                         qStopColor = colorStops[ offset ]->color;
00327                         int h, s, v, sneu, vneu;
00328                         int shad = colorStops[offset]->shade;
00329                         qStopColor.getHsv(&h, &s, &v);
00330                         sneu = s * shad / 100;
00331                         vneu = 255 - ((255 - v) * shad / 100);
00332                         qStopColor.setHsv(h, sneu, vneu);
00333                         qStopColor.setAlphaF(colorStops[offset]->opacity);
00334                         pat.setColorAt(colorStops[ offset ]->rampPoint, qStopColor);
00335                     }
00336                     pItem->setBrush(pat);
00337                 }
00338                 else if ((currItem->GrType == 8) && (!currItem->pattern().isEmpty()) && (doc->docPatterns.contains(currItem->pattern())))
00339                 {
00340                     double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation;
00341                     currItem->patternTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation);
00342                     QMatrix qmatrix;
00343                     qmatrix.translate(patternOffsetX, patternOffsetY);
00344                     qmatrix.rotate(patternRotation);
00345                     qmatrix.scale(patternScaleX / 100.0, patternScaleY / 100.0);
00346                     QImage pat = *doc->docPatterns[currItem->pattern()].getPattern();
00347                     QBrush brush = QBrush(pat);
00348                     brush.setMatrix(qmatrix);
00349                     pItem->setBrush(brush);
00350                 }
00351             }
00352             else
00353             {
00354                 QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->fillColor()], doc, currItem->fillShade());
00355                 paint.setAlphaF(1.0 - currItem->fillTransparency());
00356                 pItem->setBrush(paint);
00357             }
00358         }
00359         if ((currItem->lineColor() == CommonStrings::None) || (currItem->controlsGroup()))
00360             pItem->setPen(Qt::NoPen);
00361         else
00362         {
00363             QColor paint = ScColorEngine::getShadeColorProof(doc->PageColors[currItem->lineColor()], doc, currItem->lineShade());
00364             paint.setAlphaF(1.0 - currItem->lineTransparency());
00365             pItem->setPen(QPen(paint, currItem->lineWidth(), currItem->lineStyle(), currItem->lineEnd(), currItem->lineJoin()));
00366         }
00367         if (currItem->controlsGroup())
00368         {
00369             groupStack.push(currItem->groupsLastItem);
00370             groupStack2.push(pItem);
00371             groupStack3.push(currItem);
00372             pItem->setFlags(QGraphicsItem::ItemClipsChildrenToShape);
00373         }
00374         if (groupStack.count() != 0)
00375         {
00376             while (currItem == groupStack.top())
00377             {
00378                 groupStack3.pop();
00379                 groupStack2.pop();
00380                 groupStack.pop();
00381                 if (groupStack.count() == 0)
00382                     break;
00383             }
00384         }
00385     }
00386 
00387     previewWidget->setRenderHint(QPainter::Antialiasing);
00388     previewWidget->setScene(&scene);
00389     isFirst = true;
00390     addLens();
00391     connect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double)));
00392     connect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double)));
00393     connect(spinRadius, SIGNAL(valueChanged(double)), this, SLOT(setNewLensRadius(double)));
00394     connect(spinStrength, SIGNAL(valueChanged(double)), this, SLOT(setNewLensStrength(double)));
00395     connect(buttonAdd, SIGNAL(clicked()), this, SLOT(addLens()));
00396     connect(buttonRemove, SIGNAL(clicked()), this, SLOT(removeLens()));
00397     connect(buttonMagnify, SIGNAL(toggled(bool)), this, SLOT(changeLens()));
00398     connect(buttonZoomI, SIGNAL(clicked()), this, SLOT(doZoomIn()));
00399     connect(buttonZoomOut, SIGNAL(clicked()), this, SLOT(doZoomOut()));
00400     connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
00401     connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
00402     connect(&scene, SIGNAL(selectionChanged()), this, SLOT(selectionHasChanged()));
00403 }
00404 
00405 void LensDialog::showEvent(QShowEvent *e)
00406 {
00407     QDialog::showEvent(e);
00408     if (isFirst)
00409         previewWidget->fitInView(scene.itemsBoundingRect(), Qt::KeepAspectRatio);
00410     isFirst = false;
00411 }
00412 
00413 void LensDialog::doZoomIn()
00414 {
00415     previewWidget->scale(2.0, 2.0);
00416 }
00417 
00418 void LensDialog::doZoomOut()
00419 {
00420     previewWidget->scale(0.5, 0.5);
00421 }
00422 
00423 void LensDialog::addLens()
00424 {
00425     disconnect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double)));
00426     disconnect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double)));
00427     disconnect(spinRadius, SIGNAL(valueChanged(double)), this, SLOT(setNewLensRadius(double)));
00428     disconnect(spinStrength, SIGNAL(valueChanged(double)), this, SLOT(setNewLensStrength(double)));
00429     disconnect(buttonMagnify, SIGNAL(toggled(bool)), this, SLOT(changeLens()));
00430     if (lensList.count() > 0)
00431     {
00432         lensList[currentLens]->setSelected(false);
00433         lensList[currentLens]->update();
00434     }
00435     QRectF bBox = scene.itemsBoundingRect();
00436     double r = qMin(bBox.width(), bBox.height());
00437     double x = (bBox.width() - r) / 2.0;
00438     double y = (bBox.height() - r) / 2.0;
00439     LensItem *item = new LensItem(QRectF(x, y, r, r), this);
00440     scene.addItem(item);
00441     lensList.append(item);
00442     currentLens = lensList.count() - 1;
00443     item->setZValue(currentLens+999999);
00444     spinXPos->setValue(x + r / 2.0);
00445     spinYPos->setValue(y + r / 2.0);
00446     spinRadius->setValue(r / 2.0);
00447     spinStrength->setValue(100.0);
00448     buttonMagnify->setChecked(true);
00449     lensList[currentLens]->updateEffect();
00450     if (lensList.count() > 1)
00451         buttonRemove->setEnabled(true);
00452     lensList[currentLens]->setSelected(true);
00453     connect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double)));
00454     connect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double)));
00455     connect(spinRadius, SIGNAL(valueChanged(double)), this, SLOT(setNewLensRadius(double)));
00456     connect(spinStrength, SIGNAL(valueChanged(double)), this, SLOT(setNewLensStrength(double)));
00457     connect(buttonMagnify, SIGNAL(toggled(bool)), this, SLOT(changeLens()));
00458 }
00459 
00460 void LensDialog::removeLens()
00461 {
00462     LensItem *item = lensList.takeAt(currentLens);
00463     scene.removeItem(item);
00464     delete item;
00465     if (lensList.count() > 1)
00466         buttonRemove->setEnabled(true);
00467     else
00468         buttonRemove->setEnabled(false);
00469     currentLens = lensList.count() - 1;
00470     lensList[currentLens]->setSelected(true);
00471     lensList[currentLens]->updateEffect();
00472     lensSelected(lensList[currentLens]);
00473 }
00474 
00475 void LensDialog::changeLens()
00476 {
00477     double s = qAbs(lensList[currentLens]->strength);
00478     if (buttonMagnify->isChecked())
00479         lensList[currentLens]->setStrength(s * -1.0);
00480     else
00481         lensList[currentLens]->setStrength(s);
00482     lensList[currentLens]->updateEffect();
00483 }
00484 
00485 void LensDialog::selectionHasChanged()
00486 {
00487     bool setter = true;
00488     if (scene.selectedItems().count() == 0)
00489         setter = false;
00490     spinXPos->setEnabled(setter);
00491     spinYPos->setEnabled(setter);
00492     spinRadius->setEnabled(setter);
00493     spinStrength->setEnabled(setter);
00494     buttonMagnify->setEnabled(setter);
00495     buttonFishEye->setEnabled(setter);
00496     if (lensList.count() == 1)
00497         buttonRemove->setEnabled(false);
00498     else
00499         buttonRemove->setEnabled(setter);
00500 }
00501 
00502 void LensDialog::lensSelected(LensItem *item)
00503 {
00504     disconnect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double)));
00505     disconnect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double)));
00506     disconnect(spinRadius, SIGNAL(valueChanged(double)), this, SLOT(setNewLensRadius(double)));
00507     disconnect(spinStrength, SIGNAL(valueChanged(double)), this, SLOT(setNewLensStrength(double)));
00508     disconnect(buttonMagnify, SIGNAL(toggled(bool)), this, SLOT(changeLens()));
00509     QPointF p = item->mapToScene(item->rect().center());
00510     spinXPos->setValue(p.x());
00511     spinYPos->setValue(p.y());
00512     spinRadius->setValue(item->rect().width() / 2.0);
00513     if (item->strength < 0.0)
00514         buttonMagnify->setChecked(true);
00515     else
00516         buttonFishEye->setChecked(true);
00517     spinStrength->setValue(qAbs(item->strength));
00518     currentLens = lensList.indexOf(item);
00519     if (currentLens < 0)
00520         currentLens = 0;
00521     connect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double)));
00522     connect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double)));
00523     connect(spinRadius, SIGNAL(valueChanged(double)), this, SLOT(setNewLensRadius(double)));
00524     connect(spinStrength, SIGNAL(valueChanged(double)), this, SLOT(setNewLensStrength(double)));
00525     connect(buttonMagnify, SIGNAL(toggled(bool)), this, SLOT(changeLens()));
00526 }
00527 
00528 void LensDialog::setLensPositionValues(QPointF p)
00529 {
00530     disconnect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double)));
00531     disconnect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double)));
00532     spinXPos->setValue(p.x());
00533     spinYPos->setValue(p.y());
00534     connect(spinXPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensX(double)));
00535     connect(spinYPos, SIGNAL(valueChanged(double)), this, SLOT(setNewLensY(double)));
00536 }
00537 
00538 void LensDialog::setNewLensX(double x)
00539 {
00540     QRectF r = lensList[currentLens]->rect();
00541     r.moveCenter(QPointF(x, r.center().y()));
00542     lensList[currentLens]->setRect(r);
00543     lensList[currentLens]->updateEffect();
00544 }
00545 
00546 void LensDialog::setNewLensY(double y)
00547 {
00548     QRectF r = lensList[currentLens]->rect();
00549     r.moveCenter(QPointF(r.center().x(), y));
00550     lensList[currentLens]->setRect(r);
00551     lensList[currentLens]->updateEffect();
00552 }
00553 
00554 void LensDialog::setNewLensRadius(double radius)
00555 {
00556     QRectF r = lensList[currentLens]->rect();
00557     QPointF center = r.center();
00558     r.setWidth(radius * 2.0);
00559     r.setHeight(radius * 2.0);
00560     QPointF centerN = r.center();
00561     r.translate(center.x() - centerN.x(), center.y() - centerN.y());
00562     setLensPositionValues(lensList[currentLens]->mapToScene(r.center()));
00563     lensList[currentLens]->setRect(r);
00564     lensList[currentLens]->updateEffect();
00565 }
00566 
00567 void LensDialog::setNewLensStrength(double s)
00568 {
00569     if (buttonMagnify->isChecked())
00570         lensList[currentLens]->setStrength(s * -1.0);
00571     else
00572         lensList[currentLens]->setStrength(s);
00573     lensList[currentLens]->updateEffect();
00574 }
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.