@@ -42,7 +42,7 @@ WallpaperGenerator::Result WallpaperGenerator::generate()
42
42
43
43
WallpaperGenerator::Result result;
44
44
45
- Set* tempSet = getRandomSet (- 1 , QVector<Set*>() );
45
+ Set* tempSet = getRandomSet ();
46
46
47
47
if (tempSet == NULL )
48
48
{
@@ -88,14 +88,11 @@ WallpaperGenerator::Result WallpaperGenerator::generate()
88
88
tempFiles.append (getFile (0 , &result));
89
89
}
90
90
91
+ m_enviro->setWallpaper (generateFile (tempFiles, &result));
92
+
91
93
QLOG_DEBUG () << " Current type:" << result.type ;
92
94
QLOG_DEBUG () << " Current sets:" << result.sets ;
93
95
QLOG_DEBUG () << " Current files:" << result.files ;
94
-
95
- QString filepath = generateFile (tempFiles, &result);
96
-
97
- m_enviro->setWallpaper (filepath);
98
-
99
96
QLOG_INFO () << " Wallpaper generated in" << timer.elapsed () << " milliseconds" ;
100
97
101
98
return result;
@@ -143,7 +140,13 @@ Set* WallpaperGenerator::getRandomSet(const int _monitor, const QVector<Set*> &_
143
140
for (int i=0 ; i<nbSets; i++)
144
141
{
145
142
Set* set = sets.at (i);
143
+
146
144
int setWeight = qRound (set->nbFiles () * set->frequency ());
145
+ if (set->type () == UM::W_DESKTOP && set->style () != UM::IM_CUSTOM)
146
+ {
147
+ setWeight*= m_settings->nbEnabledMonitors ();
148
+ }
149
+
147
150
nbWalls.append (nbWalls.last () + setWeight);
148
151
}
149
152
@@ -217,13 +220,13 @@ QString WallpaperGenerator::getFile(int _idx, Result* _context)
217
220
* @param Set* _set
218
221
* @return string
219
222
*/
220
- QString WallpaperGenerator::getRandomFolder (Set * _set)
223
+ QString WallpaperGenerator::getRandomFolder (Set* _set)
221
224
{
222
225
int nbFolders = _set->nbFolders ();
223
226
224
227
if (nbFolders == 0 )
225
228
{
226
- return _set-> path () ;
229
+ return " " ;
227
230
}
228
231
229
232
if (nbFolders == 1 )
@@ -241,7 +244,7 @@ QString WallpaperGenerator::getRandomFolder(Set *_set)
241
244
* @brief Get a file in set a position _idx and adapt it for the monitor
242
245
* @param int _idx
243
246
* @param Result* _context
244
- * @return
247
+ * @return string
245
248
*/
246
249
QString WallpaperGenerator::getAndAdaptFile (int _idx, Result* _context)
247
250
{
@@ -275,7 +278,7 @@ QString WallpaperGenerator::getAndAdaptFile(int _idx, Result* _context)
275
278
* @param Set* _set
276
279
* @param int _nb
277
280
* @param Result* _context
278
- * @return
281
+ * @return string[]
279
282
*/
280
283
QVector<QString> WallpaperGenerator::getFilesForCustom (Set* _set, int _nb, Result* _context)
281
284
{
@@ -293,7 +296,7 @@ QVector<QString> WallpaperGenerator::getFilesForCustom(Set* _set, int _nb, Resul
293
296
294
297
for (int i=0 ; i<_nb; i++)
295
298
{
296
- files.append (getRandomFile (_set, folder));
299
+ files.append (getRandomFile (_set, folder, files ));
297
300
}
298
301
299
302
if (layout.perFolder )
@@ -363,7 +366,7 @@ QString WallpaperGenerator::getNextFile(Set* _set)
363
366
* @param string _folder optional
364
367
* @return string
365
368
*/
366
- QString WallpaperGenerator::getRandomFile (Set * _set, const QString &_folder)
369
+ QString WallpaperGenerator::getRandomFile (Set* _set, const QString &_folder, const QVector<QString> &_files )
367
370
{
368
371
int totalFiles = _set->nbFilesInFolder (_folder);
369
372
@@ -379,13 +382,35 @@ QString WallpaperGenerator::getRandomFile(Set *_set, const QString &_folder)
379
382
}
380
383
381
384
std::uniform_int<int > unif (0 , totalFiles-1 );
382
- int counter = unif (m_randomEngine);
383
385
384
- return _set->fileInFolder (_folder, counter);
386
+ // search a random unused file
387
+ short loop = 10 ; // the collisions detection will only try 10 times
388
+ QString file;
389
+
390
+ // if all files are already used, disable collisions detection
391
+ if (totalFiles <= _files.size ())
392
+ {
393
+ loop = 1 ;
394
+ }
395
+
396
+ while (loop > 0 )
397
+ {
398
+ loop--;
399
+
400
+ int counter = unif (m_randomEngine);
401
+ file = _set->fileInFolder (_folder, counter);
402
+
403
+ if (!_files.contains (file))
404
+ {
405
+ loop = 0 ;
406
+ }
407
+ }
408
+
409
+ return file;
385
410
}
386
411
387
412
/* *
388
- * @brief Generate one custom layout file for set at position _idx
413
+ * @brief Generate one custom layout file for the set at position _idx
389
414
* @param int _idx
390
415
* @param Result* _context
391
416
* @return string
@@ -412,7 +437,7 @@ QString WallpaperGenerator::generateCustomFile(int _idx, WallpaperGenerator::Res
412
437
double wRatio = scrRect.width () / (double ) layout.cols ;
413
438
double hRatio = scrRect.height () / (double ) layout.rows ;
414
439
415
- foreach (const QRect block, rawBlocks)
440
+ foreach (const QRect & block, rawBlocks)
416
441
{
417
442
QRect newBlock = UM::scaledRect (block, wRatio, hRatio);
418
443
@@ -432,6 +457,8 @@ QString WallpaperGenerator::generateCustomFile(int _idx, WallpaperGenerator::Res
432
457
// get necessary files from set
433
458
QVector<QString> files = getFilesForCustom (set, blocks.size (), _context);
434
459
460
+ QLOG_DEBUG ()<<" Custom sources:" <<files;
461
+
435
462
QImage image (scrRect.size (), QImage::Format_RGB32);
436
463
QPainter painter (&image);
437
464
@@ -463,9 +490,9 @@ QString WallpaperGenerator::generateCustomFile(int _idx, WallpaperGenerator::Res
463
490
pen.setWidth (layout.borderWidth );
464
491
painter.setPen (pen);
465
492
466
- foreach (const QRect block, blocks)
493
+ foreach (const QRect & block, blocks)
467
494
{
468
- foreach (const QLine line, UM::rectBorders (block))
495
+ foreach (const QLine & line, UM::rectBorders (block))
469
496
{
470
497
if (
471
498
(line.x1 ()==0 && line.x2 ()==0 ) ||
@@ -773,7 +800,7 @@ QString WallpaperGenerator::generateFile(const QVector<QString> &_files, Result*
773
800
774
801
/* *
775
802
* @brief Compute the total size of enabled monitors
776
- * @return QRect
803
+ * @return QRect
777
804
*/
778
805
QRect WallpaperGenerator::getDesktopEnabledRect ()
779
806
{
0 commit comments