labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Image.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  File : Image.cpp
3  Project : LabPlot
4  Description : Worksheet element to draw images
5  --------------------------------------------------------------------
6  Copyright : (C) 2019 Alexander Semke (alexander.semke@web.de)
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19  * GNU General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU General Public License *
22  * along with this program; if not, write to the Free Software *
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
24  * Boston, MA 02110-1301 USA *
25  * *
26  ***************************************************************************/
27 
28 #include "Image.h"
29 #include "Worksheet.h"
30 #include "ImagePrivate.h"
33 
34 #include <QPainter>
35 #include <QGraphicsScene>
36 #include <QGraphicsSceneMouseEvent>
37 #include <QMenu>
38 
39 #include <QIcon>
40 #include <KConfig>
41 #include <KConfigGroup>
42 #include <KLocalizedString>
43 
44 /**
45  * \class Image
46  * \brief A label supporting rendering of html- and tex-formatted texts.
47  *
48  * The label is aligned relative to the specified position.
49  * The position can be either specified by providing the x- and y- coordinates
50  * in parent's coordinate system, or by specifying one of the predefined position
51  * flags (\c HorizontalPosition, \c VerticalPosition).
52  */
53 
54 
55 Image::Image(const QString& name)
56  : WorksheetElement(name, AspectType::Image), d_ptr(new ImagePrivate(this)) {
57 
58  init();
59 }
60 
61 Image::Image(const QString &name, ImagePrivate *dd)
62  : WorksheetElement(name, AspectType::Image), d_ptr(dd) {
63 
64  init();
65 }
66 
67 void Image::init() {
68  Q_D(Image);
69 
70  KConfig config;
71  KConfigGroup group = config.group("Image");
72 
73  d->opacity = group.readEntry("opacity", d->opacity);
74 
75  //geometry
76  d->position.point.setX( group.readEntry("PositionXValue", d->position.point.x()) );
77  d->position.point.setY( group.readEntry("PositionYValue", d->position.point.y()) );
78  d->position.horizontalPosition = (WorksheetElement::HorizontalPosition) group.readEntry("PositionX", (int)d->position.horizontalPosition);
79  d->position.verticalPosition = (WorksheetElement::VerticalPosition) group.readEntry("PositionY", (int)d->position.verticalPosition);
80  d->horizontalAlignment = (WorksheetElement::HorizontalAlignment) group.readEntry("HorizontalAlignment", (int)d->horizontalAlignment);
81  d->verticalAlignment = (WorksheetElement::VerticalAlignment) group.readEntry("VerticalAlignment", (int)d->verticalAlignment);
82  d->rotationAngle = group.readEntry("Rotation", d->rotationAngle);
83 
84  //border
85  d->borderPen = QPen(group.readEntry("BorderColor", d->borderPen.color()),
86  group.readEntry("BorderWidth", d->borderPen.widthF()),
87  (Qt::PenStyle) group.readEntry("BorderStyle", (int)(d->borderPen.style())));
88  d->borderOpacity = group.readEntry("BorderOpacity", d->borderOpacity);
89 
90  //initial placeholder image
91  d->image = QIcon::fromTheme("viewimage").pixmap(d->width, d->height).toImage();
92 }
93 
94 //no need to delete the d-pointer here - it inherits from QGraphicsItem
95 //and is deleted during the cleanup in QGraphicsScene
96 Image::~Image() = default;
97 
98 QGraphicsItem* Image::graphicsItem() const {
99  return d_ptr;
100 }
101 
102 void Image::setParentGraphicsItem(QGraphicsItem* item) {
103  Q_D(Image);
104  d->setParentItem(item);
105  d->updatePosition();
106 }
107 
109  Q_D(Image);
110  d->retransform();
111 }
112 
113 void Image::handleResize(double horizontalRatio, double verticalRatio, bool pageResize) {
114  DEBUG("Image::handleResize()");
115  Q_UNUSED(pageResize);
116  Q_UNUSED(horizontalRatio);
117  Q_UNUSED(verticalRatio);
118 // Q_D(Image);
119 
120 // double ratio = 0;
121 // if (horizontalRatio > 1.0 || verticalRatio > 1.0)
122 // ratio = qMax(horizontalRatio, verticalRatio);
123 // else
124 // ratio = qMin(horizontalRatio, verticalRatio);
125 }
126 
127 /*!
128  Returns an icon to be used in the project explorer.
129 */
130 QIcon Image::icon() const{
131  return QIcon::fromTheme("viewimage");
132 }
133 
135  QMenu *menu = WorksheetElement::createContextMenu();
136  QAction* firstAction = menu->actions().at(1); //skip the first action because of the "title-action"
137 
138  if (!visibilityAction) {
139  visibilityAction = new QAction(i18n("Visible"), this);
140  visibilityAction->setCheckable(true);
141  connect(visibilityAction, &QAction::triggered, this, &Image::visibilityChanged);
142  }
143 
144  visibilityAction->setChecked(isVisible());
145  menu->insertAction(firstAction, visibilityAction);
146  menu->insertSeparator(firstAction);
147 
148  return menu;
149 }
150 
151 /* ============================ getter methods ================= */
152 CLASS_SHARED_D_READER_IMPL(Image, QString, fileName, fileName)
153 BASIC_SHARED_D_READER_IMPL(Image, qreal, opacity, opacity)
154 BASIC_SHARED_D_READER_IMPL(Image, int, width, width)
155 BASIC_SHARED_D_READER_IMPL(Image, int, height, height)
156 BASIC_SHARED_D_READER_IMPL(Image, bool, keepRatio, keepRatio)
158 BASIC_SHARED_D_READER_IMPL(Image, WorksheetElement::HorizontalAlignment, horizontalAlignment, horizontalAlignment)
159 BASIC_SHARED_D_READER_IMPL(Image, WorksheetElement::VerticalAlignment, verticalAlignment, verticalAlignment)
160 BASIC_SHARED_D_READER_IMPL(Image, qreal, rotationAngle, rotationAngle)
161 
162 CLASS_SHARED_D_READER_IMPL(Image, QPen, borderPen, borderPen)
163 BASIC_SHARED_D_READER_IMPL(Image, qreal, borderOpacity, borderOpacity)
164 
165 /* ============================ setter methods and undo commands ================= */
166 STD_SETTER_CMD_IMPL_F_S(Image, SetFileName, QString, fileName, updateImage)
167 void Image::setFileName(const QString& fileName) {
168  Q_D(Image);
169  if (fileName != d->fileName)
170  exec(new ImageSetFileNameCmd(d, fileName, ki18n("%1: set image")));
171 }
172 
173 STD_SETTER_CMD_IMPL_F_S(Image, SetOpacity, qreal, opacity, update)
174 void Image::setOpacity(qreal opacity) {
175  Q_D(Image);
176  if (opacity != d->opacity)
177  exec(new ImageSetOpacityCmd(d, opacity, ki18n("%1: set border opacity")));
178 }
179 
180 STD_SETTER_CMD_IMPL_F_S(Image, SetWidth, int, width, scaleImage)
181 void Image::setWidth(int width) {
182  Q_D(Image);
183  if (width != d->width)
184  exec(new ImageSetWidthCmd(d, width, ki18n("%1: set width")));
185 }
186 
187 STD_SETTER_CMD_IMPL_F_S(Image, SetHeight, int, height, scaleImage)
188 void Image::setHeight(int height) {
189  Q_D(Image);
190  if (height != d->height)
191  exec(new ImageSetHeightCmd(d, height, ki18n("%1: set height")));
192 }
193 
194 STD_SETTER_CMD_IMPL_S(Image, SetKeepRatio, bool, keepRatio)
195 void Image::setKeepRatio(bool keepRatio) {
196  Q_D(Image);
197  if (keepRatio != d->keepRatio)
198  exec(new ImageSetKeepRatioCmd(d, keepRatio, ki18n("%1: change keep ratio")));
199 }
200 
203  Q_D(Image);
204  if (pos.point != d->position.point || pos.horizontalPosition != d->position.horizontalPosition || pos.verticalPosition != d->position.verticalPosition)
205  exec(new ImageSetPositionCmd(d, pos, ki18n("%1: set position")));
206 }
207 
208 /*!
209  sets the position without undo/redo-stuff
210 */
211 void Image::setPosition(QPointF point) {
212  Q_D(Image);
213  if (point != d->position.point) {
214  d->position.point = point;
215  retransform();
216  }
217 }
218 
219 STD_SETTER_CMD_IMPL_F_S(Image, SetRotationAngle, qreal, rotationAngle, recalcShapeAndBoundingRect);
220 void Image::setRotationAngle(qreal angle) {
221  Q_D(Image);
222  if (angle != d->rotationAngle)
223  exec(new ImageSetRotationAngleCmd(d, angle, ki18n("%1: set rotation angle")));
224 }
225 
226 STD_SETTER_CMD_IMPL_F_S(Image, SetHorizontalAlignment, WorksheetElement::HorizontalAlignment, horizontalAlignment, retransform);
227 void Image::setHorizontalAlignment(const WorksheetElement::HorizontalAlignment hAlign) {
228  Q_D(Image);
229  if (hAlign != d->horizontalAlignment)
230  exec(new ImageSetHorizontalAlignmentCmd(d, hAlign, ki18n("%1: set horizontal alignment")));
231 }
232 
233 STD_SETTER_CMD_IMPL_F_S(Image, SetVerticalAlignment, WorksheetElement::VerticalAlignment, verticalAlignment, retransform);
234 void Image::setVerticalAlignment(const WorksheetElement::VerticalAlignment vAlign) {
235  Q_D(Image);
236  if (vAlign != d->verticalAlignment)
237  exec(new ImageSetVerticalAlignmentCmd(d, vAlign, ki18n("%1: set vertical alignment")));
238 }
239 
240 //Border
241 STD_SETTER_CMD_IMPL_F_S(Image, SetBorderPen, QPen, borderPen, update)
242 void Image::setBorderPen(const QPen &pen) {
243  Q_D(Image);
244  if (pen != d->borderPen)
245  exec(new ImageSetBorderPenCmd(d, pen, ki18n("%1: set border")));
246 }
247 
248 STD_SETTER_CMD_IMPL_F_S(Image, SetBorderOpacity, qreal, borderOpacity, update)
249 void Image::setBorderOpacity(qreal opacity) {
250  Q_D(Image);
251  if (opacity != d->borderOpacity)
252  exec(new ImageSetBorderOpacityCmd(d, opacity, ki18n("%1: set border opacity")));
253 }
254 
255 //misc
256 STD_SWAP_METHOD_SETTER_CMD_IMPL_F(Image, SetVisible, bool, swapVisible, retransform);
257 void Image::setVisible(bool on) {
258  Q_D(Image);
259  exec(new ImageSetVisibleCmd(d, on, on ? ki18n("%1: set visible") : ki18n("%1: set invisible")));
260 }
261 
262 bool Image::isVisible() const {
263  Q_D(const Image);
264  return d->isVisible();
265 }
266 
267 void Image::setPrinting(bool on) {
268  Q_D(Image);
269  d->m_printing = on;
270 }
271 
272 //##############################################################################
273 //###### SLOTs for changes triggered via QActions in the context menu ########
274 //##############################################################################
276  Q_D(const Image);
277  this->setVisible(!d->isVisible());
278 }
279 
280 //##############################################################################
281 //####################### Private implementation ###############################
282 //##############################################################################
283 ImagePrivate::ImagePrivate(Image* owner) : q(owner) {
284  setFlag(QGraphicsItem::ItemIsSelectable);
285  setFlag(QGraphicsItem::ItemIsMovable);
286  setFlag(QGraphicsItem::ItemSendsGeometryChanges);
287  setAcceptHoverEvents(true);
288 }
289 
290 QString ImagePrivate::name() const {
291  return q->name();
292 }
293 
294 /*!
295  calculates the position and the bounding box of the label. Called on geometry or text changes.
296  */
299  return;
300 
303  updatePosition();
304 
305  float x = position.point.x();
306  float y = position.point.y();
307  float w = image.width();
308  float h = image.height();
309 
310  //depending on the alignment, calculate the new GraphicsItem's position in parent's coordinate system
311  QPointF itemPos;
312  switch (horizontalAlignment) {
314  itemPos.setX(x - w/2);
315  break;
317  itemPos.setX(x);
318  break;
320  itemPos.setX(x + w/2);
321  break;
322  }
323 
324  switch (verticalAlignment) {
326  itemPos.setY(y - h/2);
327  break;
329  itemPos.setY(y);
330  break;
332  itemPos.setY(y + h/2);
333  break;
334  }
335 
337  setPos(itemPos);
338  suppressItemChangeEvent = false;
339 
340  boundingRectangle.setX(-w/2);
341  boundingRectangle.setY(-h/2);
342  boundingRectangle.setWidth(w);
343  boundingRectangle.setHeight(h);
344 
345  updateBorder();
346 }
347 
349  if (!fileName.isEmpty()) {
350  image = QImage(fileName);
351  width = image.width();
352  height = image.height();
353  q->widthChanged(width);
355  } else {
358  image = QIcon::fromTheme("viewimage").pixmap(width, height).toImage();
359  q->widthChanged(width);
361  }
362 
363  retransform();
364 }
365 
367  if (keepRatio) {
368  if (width != image.width()) {
369  //width was changed -> rescale the height to keep the ratio
370  if (image.width() != 0)
371  height = image.height()*width/image.width();
372  else
373  height = 0;
375  } else {
376  //height was changed -> rescale the width to keep the ratio
377  if (image.height() != 0)
378  width = image.width()*height/image.height();
379  else
380  width = 0;
381  q->widthChanged(width);
382  }
383  }
384 
385  if (width != 0 && height != 0)
386  image = image.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
387  retransform();
388 }
389 
390 /*!
391  calculates the position of the label, when the position relative to the parent was specified (left, right, etc.)
392 */
394  //determine the parent item
395  QRectF parentRect;
396  QGraphicsItem* parent = parentItem();
397  if (parent) {
398  parentRect = parent->boundingRect();
399  } else {
400  if (!scene())
401  return;
402 
403  parentRect = scene()->sceneRect();
404  }
405 
408  position.point.setX( parentRect.x() );
410  position.point.setX( parentRect.x() + parentRect.width()/2 );
412  position.point.setX( parentRect.x() + parentRect.width() );
413  }
414 
417  position.point.setY( parentRect.y() );
419  position.point.setY( parentRect.y() + parentRect.height()/2 );
421  position.point.setY( parentRect.y() + parentRect.height() );
422  }
423 
424  emit q->positionChanged(position);
425 }
426 
428  borderShapePath = QPainterPath();
431 }
432 
434  bool oldValue = isVisible();
435  setVisible(on);
436  emit q->changed();
437  emit q->visibleChanged(on);
438  return oldValue;
439 }
440 
441 /*!
442  Returns the outer bounds of the item as a rectangle.
443  */
446 }
447 
448 /*!
449  Returns the shape of this item as a QPainterPath in local coordinates.
450 */
451 QPainterPath ImagePrivate::shape() const {
452  return imageShape;
453 }
454 
455 /*!
456  recalculates the outer bounds and the shape of the label.
457 */
459  prepareGeometryChange();
460 
461  QMatrix matrix;
462  matrix.rotate(-rotationAngle);
463  imageShape = QPainterPath();
464  if (borderPen.style() != Qt::NoPen) {
466  transformedBoundingRectangle = matrix.mapRect(imageShape.boundingRect());
467  } else {
468  imageShape.addRect(boundingRectangle);
470  }
471 
472  imageShape = matrix.map(imageShape);
473 
474  emit q->changed();
475 }
476 
477 void ImagePrivate::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
478  Q_UNUSED(option)
479  Q_UNUSED(widget)
480 
481  painter->save();
482 
483  //draw the image
484  painter->rotate(-rotationAngle);
485  painter->setOpacity(opacity);
486  painter->drawImage(boundingRectangle.topLeft(), image, image.rect());
487  painter->restore();
488 
489  //draw the border
490  if (borderPen.style() != Qt::NoPen) {
491  painter->save();
492  painter->rotate(-rotationAngle);
493  painter->setPen(borderPen);
494  painter->setOpacity(borderOpacity);
495  painter->drawPath(borderShapePath);
496  painter->restore();
497  }
498 
499  if (m_hovered && !isSelected() && !m_printing) {
500  painter->setPen(QPen(QApplication::palette().color(QPalette::Shadow), 2, Qt::SolidLine));
501  painter->drawPath(imageShape);
502  }
503 
504  if (isSelected() && !m_printing) {
505  painter->setPen(QPen(QApplication::palette().color(QPalette::Highlight), 2, Qt::SolidLine));
506  painter->drawPath(imageShape);
507  }
508 }
509 
510 QVariant ImagePrivate::itemChange(GraphicsItemChange change, const QVariant &value) {
512  return value;
513 
514  if (change == QGraphicsItem::ItemPositionChange) {
515  //convert item's center point in parent's coordinates
517  tempPosition.point = positionFromItemPosition(value.toPointF());
520 
521  //emit the signals in order to notify the UI.
522  //we don't set the position related member variables during the mouse movements.
523  //this is done on mouse release events only.
524  emit q->positionChanged(tempPosition);
525  }
526 
527  return QGraphicsItem::itemChange(change, value);
528 }
529 
530 void ImagePrivate::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) {
531  //convert position of the item in parent coordinates to label's position
532  QPointF point = positionFromItemPosition(pos());
533  if (qAbs(point.x()-position.point.x())>20 && qAbs(point.y()-position.point.y())>20 ) {
534  //position was changed -> set the position related member variables
535  suppressRetransform = true;
537  tempPosition.point = point;
540  q->setPosition(tempPosition);
541  suppressRetransform = false;
542  }
543 
544  QGraphicsItem::mouseReleaseEvent(event);
545 }
546 
547 /*!
548  * converts label's position to GraphicsItem's position.
549  */
550 QPointF ImagePrivate::positionFromItemPosition(QPointF itemPos) {
551  float x = itemPos.x();
552  float y = itemPos.y();
553  float w = image.width();
554  float h = image.height();
555  QPointF tmpPosition;
556 
557  //depending on the alignment, calculate the new position
558  switch (horizontalAlignment) {
560  tmpPosition.setX(x + w/2);
561  break;
563  tmpPosition.setX(x);
564  break;
566  tmpPosition.setX(x - w/2);
567  break;
568  }
569 
570  switch (verticalAlignment) {
572  tmpPosition.setY(y + h/2);
573  break;
575  tmpPosition.setY(y);
576  break;
578  tmpPosition.setY(y - h/2);
579  break;
580  }
581 
582  return tmpPosition;
583 }
584 
585 void ImagePrivate::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) {
586  q->createContextMenu()->exec(event->screenPos());
587 }
588 
589 void ImagePrivate::hoverEnterEvent(QGraphicsSceneHoverEvent*) {
590  if (!isSelected()) {
591  m_hovered = true;
592  emit q->hovered();
593  update();
594  }
595 }
596 
597 void ImagePrivate::hoverLeaveEvent(QGraphicsSceneHoverEvent*) {
598  if (m_hovered) {
599  m_hovered = false;
600  emit q->unhovered();
601  update();
602  }
603 }
604 
605 //##############################################################################
606 //################## Serialization/Deserialization ###########################
607 //##############################################################################
608 //! Save as XML
609 void Image::save(QXmlStreamWriter* writer) const {
610  Q_D(const Image);
611 
612  writer->writeStartElement("image");
613  writeBasicAttributes(writer);
614  writeCommentElement(writer);
615 
616  //general
617  writer->writeStartElement("general");
618  writer->writeAttribute("fileName", d->fileName);
619  writer->writeAttribute("opacity", QString::number(d->opacity));
620  writer->writeEndElement();
621 
622  //geometry
623  writer->writeStartElement("geometry");
624  writer->writeAttribute("width", QString::number(d->width));
625  writer->writeAttribute("height", QString::number(d->height));
626  writer->writeAttribute("keepRatio", QString::number(d->keepRatio));
627  writer->writeAttribute("x", QString::number(d->position.point.x()));
628  writer->writeAttribute("y", QString::number(d->position.point.y()));
629  writer->writeAttribute("horizontalPosition", QString::number(static_cast<int>(d->position.horizontalPosition)));
630  writer->writeAttribute("verticalPosition", QString::number(static_cast<int>(d->position.verticalPosition)));
631  writer->writeAttribute("horizontalAlignment", QString::number(static_cast<int>(d->horizontalAlignment)));
632  writer->writeAttribute("verticalAlignment", QString::number(static_cast<int>(d->verticalAlignment)));
633  writer->writeAttribute("rotationAngle", QString::number(d->rotationAngle));
634  writer->writeAttribute("visible", QString::number(d->isVisible()));
635  writer->writeEndElement();
636 
637  //border
638  writer->writeStartElement("border");
639  WRITE_QPEN(d->borderPen);
640  writer->writeAttribute("borderOpacity", QString::number(d->borderOpacity));
641  writer->writeEndElement();
642 
643  writer->writeEndElement(); // close "image" section
644 }
645 
646 //! Load from XML
647 bool Image::load(XmlStreamReader* reader, bool preview) {
648  if (!readBasicAttributes(reader))
649  return false;
650 
651  Q_D(Image);
652  KLocalizedString attributeWarning = ki18n("Attribute '%1' missing or empty, default value is used");
653  QXmlStreamAttributes attribs;
654  QString str;
655 
656  while (!reader->atEnd()) {
657  reader->readNext();
658  if (reader->isEndElement() && reader->name() == "image")
659  break;
660 
661  if (!reader->isStartElement())
662  continue;
663 
664  if (!preview && reader->name() == "comment") {
665  if (!readCommentElement(reader)) return false;
666  } else if (!preview && reader->name() == "general") {
667  attribs = reader->attributes();
668  d->fileName = attribs.value("fileName").toString();
669  READ_DOUBLE_VALUE("opacity", opacity);
670  } else if (!preview && reader->name() == "geometry") {
671  attribs = reader->attributes();
672 
673  READ_INT_VALUE("width", width, int);
674  READ_INT_VALUE("height", height, int);
675  READ_INT_VALUE("keepRatio", keepRatio, bool);
676 
677  str = attribs.value("x").toString();
678  if (str.isEmpty())
679  reader->raiseWarning(attributeWarning.subs("x").toString());
680  else
681  d->position.point.setX(str.toDouble());
682 
683  str = attribs.value("y").toString();
684  if (str.isEmpty())
685  reader->raiseWarning(attributeWarning.subs("y").toString());
686  else
687  d->position.point.setY(str.toDouble());
688 
689  READ_INT_VALUE("horizontalPosition", position.horizontalPosition, WorksheetElement::HorizontalPosition);
690  READ_INT_VALUE("verticalPosition", position.verticalPosition, WorksheetElement::VerticalPosition);
691  READ_INT_VALUE("horizontalAlignment", horizontalAlignment, WorksheetElement::HorizontalAlignment);
692  READ_INT_VALUE("verticalAlignment", verticalAlignment, WorksheetElement::VerticalAlignment);
693  READ_DOUBLE_VALUE("rotationAngle", rotationAngle);
694 
695  str = attribs.value("visible").toString();
696  if (str.isEmpty())
697  reader->raiseWarning(attributeWarning.subs("visible").toString());
698  else
699  d->setVisible(str.toInt());
700  } else if (!preview && reader->name() == "border") {
701  attribs = reader->attributes();
702  READ_QPEN(d->borderPen);
703  READ_DOUBLE_VALUE("borderOpacity", borderOpacity);
704  } else { // unknown element
705  reader->raiseWarning(i18n("unknown element '%1'", reader->name().toString()));
706  if (!reader->skipToEndElement()) return false;
707  }
708  }
709 
710  if (!preview) {
711  d->image = QImage(d->fileName);
712  d->scaleImage();
713  }
714 
715  return true;
716 }
717 
718 //##############################################################################
719 //######################### Theme management ##################################
720 //##############################################################################
721 void Image::loadThemeConfig(const KConfig& config) {
722  Q_UNUSED(config)
723 }
724 
725 void Image::saveThemeConfig(const KConfig& config) {
726  Q_UNUSED(config)
727 }
AspectType
STD_SWAP_METHOD_SETTER_CMD_IMPL_F(Image, SetVisible, bool, swapVisible, retransform)
STD_SETTER_CMD_IMPL_F_S(Image, SetPosition, WorksheetElement::PositionWrapper, position, retransform)
bool readCommentElement(XmlStreamReader *)
Load comment from an XML element.
QString name() const
void writeBasicAttributes(QXmlStreamWriter *) const
Save name and creation time to XML.
void exec(QUndoCommand *)
Execute the given command, pushing it on the undoStack() if available.
bool readBasicAttributes(XmlStreamReader *)
Load name and creation time from XML.
void writeCommentElement(QXmlStreamWriter *) const
Save the comment to XML.
AbstractAspectPrivate * d
QString fileName
Definition: ImagePrivate.h:43
bool suppressItemChangeEvent
Definition: ImagePrivate.h:75
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *widget=nullptr) override
Definition: Image.cpp:477
qreal rotationAngle
Definition: ImagePrivate.h:48
QString name() const
Definition: Image.cpp:290
void contextMenuEvent(QGraphicsSceneContextMenuEvent *) override
Definition: Image.cpp:585
bool suppressRetransform
Definition: ImagePrivate.h:76
TextLabel::PositionWrapper position
Definition: ImagePrivate.h:51
void updatePosition()
Definition: Image.cpp:393
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
Definition: Image.cpp:589
TextLabel::VerticalAlignment verticalAlignment
Definition: ImagePrivate.h:59
QPainterPath borderShapePath
Definition: ImagePrivate.h:82
ImagePrivate(Image *)
Definition: Image.cpp:283
void updateBorder()
Definition: Image.cpp:427
QRectF boundingRect() const override
Definition: Image.cpp:444
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
Definition: Image.cpp:530
QRectF boundingRectangle
Definition: ImagePrivate.h:80
TextLabel::HorizontalAlignment horizontalAlignment
Definition: ImagePrivate.h:58
QPointF positionFromItemPosition(QPointF)
Definition: Image.cpp:550
void retransform()
Definition: Image.cpp:297
bool swapVisible(bool on)
Definition: Image.cpp:433
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
Definition: Image.cpp:597
QPainterPath imageShape
Definition: ImagePrivate.h:83
void updateImage()
Definition: Image.cpp:348
QImage image
Definition: ImagePrivate.h:42
Image *const q
Definition: ImagePrivate.h:91
void scaleImage()
Definition: Image.cpp:366
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
Definition: Image.cpp:510
qreal borderOpacity
Definition: ImagePrivate.h:63
virtual void recalcShapeAndBoundingRect()
Definition: Image.cpp:458
QRectF transformedBoundingRectangle
Definition: ImagePrivate.h:81
QPainterPath shape() const override
Definition: Image.cpp:451
A label supporting rendering of html- and tex-formatted texts.
Definition: Image.h:41
void changed()
void init()
Definition: Image.cpp:67
void heightChanged(int)
void save(QXmlStreamWriter *) const override
Save as XML.
Definition: Image.cpp:609
void positionChanged(const WorksheetElement::PositionWrapper &)
void visibilityChanged()
Definition: Image.cpp:275
void setVisible(bool on) override
Show/hide the element.
Definition: Image.cpp:257
QMenu * createContextMenu() override
Return a new context menu.
Definition: Image.cpp:134
~Image() override
QGraphicsItem * graphicsItem() const override
Return the graphics item representing this element.
Definition: Image.cpp:98
ImagePrivate *const d_ptr
Definition: Image.h:86
void setParentGraphicsItem(QGraphicsItem *)
Definition: Image.cpp:102
void setPrinting(bool) override
Switches the printing mode on/off.
Definition: Image.cpp:267
Image(const QString &name)
Definition: Image.cpp:55
void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override
Definition: Image.cpp:113
void loadThemeConfig(const KConfig &) override
Definition: Image.cpp:721
void setPosition(QPointF)
Definition: Image.cpp:202
void visibleChanged(bool)
bool isVisible() const override
Return whether the element is (at least) partially visible.
Definition: Image.cpp:262
void saveThemeConfig(const KConfig &) override
Definition: Image.cpp:725
void widthChanged(int)
QIcon icon() const override
Definition: Image.cpp:130
void retransform() override
Tell the element to newly transform its graphics item into its coordinate system.
Definition: Image.cpp:108
bool load(XmlStreamReader *, bool preview) override
Load from XML.
Definition: Image.cpp:647
QAction * visibilityAction
Definition: Image.h:93
Base class for all Worksheet children.
static QPainterPath shapeFromPath(const QPainterPath &, const QPen &)
QMenu * createContextMenu() override
Return a new context menu.
static double convertToSceneUnits(const double value, const Worksheet::Unit unit)
Definition: Worksheet.cpp:113
XML stream parser that supports errors as well as warnings. This class also adds line and column numb...
void raiseWarning(const QString &)
#define READ_DOUBLE_VALUE(name, var)
Definition: macros.h:475
#define CLASS_SHARED_D_READER_IMPL(classname, type, method, var)
Definition: macros.h:154
#define DEBUG(x)
Definition: macros.h:50
#define STD_SETTER_CMD_IMPL_S(class_name, cmd_name, value_type, field_name)
Definition: macros.h:207
#define READ_INT_VALUE(name, var, type)
Definition: macros.h:468
#define READ_QPEN(pen)
Definition: macros.h:324
#define WRITE_QPEN(pen)
Definition: macros.h:315
#define BASIC_SHARED_D_READER_IMPL(classname, type, method, var)
Definition: macros.h:127
@ Shadow
Definition: OriginObj.h:71
#define i18n(m)
Definition: nsl_common.h:38
WorksheetElement::VerticalPosition verticalPosition
WorksheetElement::HorizontalPosition horizontalPosition