Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Network
KIO Extras
Commits
7380d965
Commit
7380d965
authored
Apr 24, 2021
by
Méven Car
Browse files
thumbnail: Port from deprecated qrand to QRandomGenerator
Adds a class member m_randomGenerator
parent
873dd7b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
thumbnail/thumbnail.cpp
View file @
7380d965
...
...
@@ -34,6 +34,7 @@
#include <QMimeDatabase>
#include <QLibrary>
#include <QDebug>
#include <QRandomGenerator>
#include <KFileItem>
#include <KLocalizedString>
...
...
@@ -116,7 +117,8 @@ extern "C" Q_DECL_EXPORT int kdemain( int argc, char **argv )
ThumbnailProtocol
::
ThumbnailProtocol
(
const
QByteArray
&
pool
,
const
QByteArray
&
app
)
:
SlaveBase
(
"thumbnail"
,
pool
,
app
),
m_maxFileSize
(
0
)
m_maxFileSize
(
0
),
m_randomGenerator
()
{
}
...
...
@@ -336,7 +338,7 @@ bool ThumbnailProtocol::isOpaque(const QImage &image) const
}
void
ThumbnailProtocol
::
drawPictureFrame
(
QPainter
*
painter
,
const
QPoint
&
centerPos
,
const
QImage
&
image
,
int
frameWidth
,
QSize
imageTargetSize
)
const
const
QImage
&
image
,
int
frameWidth
,
QSize
imageTargetSize
,
int
rotationAngle
)
const
{
// Scale the image down so it matches the aspect ratio
float
scaling
=
1.0
;
...
...
@@ -354,7 +356,7 @@ void ThumbnailProtocol::drawPictureFrame(QPainter *painter, const QPoint ¢er
float
scaledFrameWidth
=
frameWidth
/
scaling
;
QTransform
m
;
m
.
rotate
(
qrand
()
%
17
-
8
);
// Random
rotation
±8°
m
.
rotate
(
rotation
Angle
);
m
.
scale
(
scaling
,
scaling
);
QRectF
frameRect
(
QPointF
(
0
,
0
),
QPointF
(
image
.
width
()
+
scaledFrameWidth
*
2
,
image
.
height
()
+
scaledFrameWidth
*
2
));
...
...
@@ -472,7 +474,7 @@ QImage ThumbnailProtocol::thumbForDirectory(const QString& directory)
// Seed the random number generator so that it always returns the same result
// for the same directory and sequence-item
qs
rand
(
qHash
(
directory
)
+
skipValidItems
);
m_
rand
omGenerator
.
seed
(
qHash
(
directory
)
+
skipValidItems
);
while
(
dir
.
hasNext
())
{
++
iterations
;
...
...
@@ -724,7 +726,8 @@ bool ThumbnailProtocol::drawSubThumbnail(QPainter& p, QImage subThumbnail, int w
// center the image inside the segment boundaries
const
QPoint
centerPos
(
xPos
+
(
width
/
2
),
yPos
+
(
height
/
2
));
drawPictureFrame
(
&
p
,
centerPos
,
subThumbnail
,
frameWidth
,
targetSize
);
const
int
rotationAngle
=
m_randomGenerator
.
bounded
(
-
8
,
9
);
// Random rotation ±8°
drawPictureFrame
(
&
p
,
centerPos
,
subThumbnail
,
frameWidth
,
targetSize
,
rotationAngle
);
return
true
;
}
thumbnail/thumbnail.h
View file @
7380d965
...
...
@@ -10,6 +10,7 @@
#include <QHash>
#include <QPainter>
#include <QSet>
#include <QRandomGenerator>
#include <kio/slavebase.h>
...
...
@@ -28,7 +29,7 @@ protected:
ThumbCreator
*
getThumbCreator
(
const
QString
&
plugin
);
bool
isOpaque
(
const
QImage
&
image
)
const
;
void
drawPictureFrame
(
QPainter
*
painter
,
const
QPoint
&
pos
,
const
QImage
&
image
,
int
frameWidth
,
QSize
imageTargetSize
)
const
;
int
frameWidth
,
QSize
imageTargetSize
,
int
rotationAngle
)
const
;
QImage
thumbForDirectory
(
const
QString
&
directory
);
QString
pluginForMimeType
(
const
QString
&
mimeType
);
...
...
@@ -65,6 +66,7 @@ private:
QSet
<
QString
>
m_propagationDirectories
;
QString
m_thumbBasePath
;
qint64
m_maxFileSize
;
QRandomGenerator
m_randomGenerator
;
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment