• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

palapeli/libpala

  • sources
  • kde-4.14
  • kdegames
  • palapeli
  • libpala
slicerjob.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***************************************************************************/
18 
19 #include "slicerjob.h"
20 #include "slicer.h"
21 
22 #include <QtGui/QPainter>
23 
24 //BEGIN Pala::SlicerJob::Private
25 
26 class Pala::SlicerJob::Private
27 {
28  public:
29  Private() : m_mode(0) {}
30 
31  QMap<QByteArray, QVariant> m_args;
32  QImage m_image;
33  const Pala::SlicerMode* m_mode;
34 
35  QMap<int, QImage> m_pieces;
36  QMap<int, QPoint> m_pieceOffsets;
37  QList<QPair<int, int> > m_relations;
38 };
39 
40 //END Pala::SlicerJob::Private
41 
42 Pala::SlicerJob::SlicerJob(const QImage& image, const QMap<QByteArray, QVariant>& args)
43  : p(new Private)
44 {
45  p->m_args = args;
46  p->m_image = image;
47 }
48 
49 Pala::SlicerJob::~SlicerJob()
50 {
51  delete p;
52 }
53 
54 QVariant Pala::SlicerJob::argument(const QByteArray& key) const
55 {
56  return p->m_args.value(key, QVariant());
57 }
58 
59 QImage Pala::SlicerJob::image() const
60 {
61  return p->m_image;
62 }
63 
64 const Pala::SlicerMode* Pala::SlicerJob::mode() const
65 {
66  return p->m_mode;
67 }
68 
69 QMap<int, QImage> Pala::SlicerJob::pieces() const
70 {
71  return p->m_pieces;
72 }
73 
74 QMap<int, QPoint> Pala::SlicerJob::pieceOffsets() const
75 {
76  return p->m_pieceOffsets;
77 }
78 
79 QList<QPair<int, int> > Pala::SlicerJob::relations() const
80 {
81  return p->m_relations;
82 }
83 
84 void Pala::SlicerJob::setMode(const Pala::SlicerMode* mode)
85 {
86  p->m_mode = mode;
87 }
88 
89 void Pala::SlicerJob::respectSlicerFlags(int flags)
90 {
91  if (!(flags & Pala::Slicer::AllowFullTransparency))
92  {
93  QImage image(p->m_image.size(), p->m_image.format());
94  QColor blackShade(Qt::black); blackShade.setAlpha(42);
95  image.fill(blackShade.rgba());
96  QPainter painter(&image);
97  painter.drawImage(QPoint(), p->m_image);
98  painter.end();
99  p->m_image = image;
100  }
101 }
102 
103 void Pala::SlicerJob::addPiece(int pieceID, const QImage& image, const QPoint& offset)
104 {
105  p->m_pieces.insert(pieceID, image);
106  p->m_pieceOffsets.insert(pieceID, offset);
107 }
108 
109 //A modified version of QImage::copy, which avoids rendering errors even if rect is outside the bounds of the source image.
110 QImage safeQImageCopy(const QImage& source, const QRect& rect)
111 {
112  QRect targetRect(QPoint(), rect.size());
113  //copy image
114  QImage target(rect.size(), source.format());
115  QPainter p(&target);
116  p.drawImage(targetRect, source, rect);
117  p.end();
118  return target;
119  //Strangely, source.copy(rect) does not work. It produces black borders.
120 }
121 
122 void Pala::SlicerJob::addPieceFromMask(int pieceID, const QImage& mask, const QPoint& offset)
123 {
124  QImage pieceImage(mask);
125  QPainter painter(&pieceImage);
126  painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
127  painter.drawImage(QPoint(), safeQImageCopy(p->m_image, QRect(offset, mask.size())));
128  painter.end();
129  addPiece(pieceID, pieceImage, offset);
130 }
131 
132 void Pala::SlicerJob::addRelation(int pieceID1, int pieceID2)
133 {
134  p->m_relations << QPair<int, int>(pieceID1, pieceID2);
135 }
QRect::size
QSize size() const
slicer.h
QPainter::end
bool end()
QPainter::setCompositionMode
void setCompositionMode(CompositionMode mode)
QByteArray
Pala::SlicerJob::addPieceFromMask
void addPieceFromMask(int pieceID, const QImage &mask, const QPoint &offset=QPoint())
Generate a piece, and add it to the result set of this slicing job.
Definition: slicerjob.cpp:122
QMap< QByteArray, QVariant >
QVariant::value
T value() const
QPoint
Pala::Slicer::AllowFullTransparency
By default, libpala will increase the minimum alpha value of input images to avoid invisible pieces...
Definition: slicer.h:70
Pala::SlicerJob::respectSlicerFlags
void respectSlicerFlags(int flags)
Definition: slicerjob.cpp:89
Pala::SlicerJob::addRelation
void addRelation(int pieceID1, int pieceID2)
Define a neighborship relation between two pieces.
Definition: slicerjob.cpp:132
Pala::SlicerJob::setMode
void setMode(const Pala::SlicerMode *mode)
Definition: slicerjob.cpp:84
Pala::SlicerJob::argument
QVariant argument(const QByteArray &key) const
Returns an argument of this job, i.e. the value that the user has chosen for the slicing algorithm's ...
Definition: slicerjob.cpp:54
Pala::SlicerJob::image
QImage image() const
Returns the image that should be sliced.
Definition: slicerjob.cpp:59
QRect
Pala::SlicerMode
Representation of an operational mode of a slicing algorithm.
Definition: slicermode.h:46
QPainter
Pala::SlicerJob::~SlicerJob
virtual ~SlicerJob()
Deletes this slicer job.
Definition: slicerjob.cpp:49
Pala::SlicerJob::SlicerJob
SlicerJob(const QImage &image, const QMap< QByteArray, QVariant > &args)
Creates a new slicer job.
Definition: slicerjob.cpp:42
Pala::SlicerJob::relations
QList< QPair< int, int > > relations() const
Definition: slicerjob.cpp:79
QList
QColor
QPair< int, int >
QImage
Pala::SlicerJob::pieces
QMap< int, QImage > pieces() const
Definition: slicerjob.cpp:69
slicerjob.h
QPainter::drawImage
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, QFlags< Qt::ImageConversionFlag > flags)
Pala::SlicerJob::mode
const Pala::SlicerMode * mode() const
Returns the selected slicer mode, or 0 if the slicer does not define any slicer modes.
Definition: slicerjob.cpp:64
safeQImageCopy
QImage safeQImageCopy(const QImage &source, const QRect &rect)
Definition: slicerjob.cpp:110
QImage::size
QSize size() const
Pala::SlicerJob::addPiece
void addPiece(int pieceID, const QImage &image, const QPoint &offset=QPoint())
Add a generated piece to the result set of this slicing job.
Definition: slicerjob.cpp:103
Pala::SlicerJob::pieceOffsets
QMap< int, QPoint > pieceOffsets() const
Definition: slicerjob.cpp:74
QImage::format
Format format() const
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:19:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

palapeli/libpala

Skip menu "palapeli/libpala"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal