Changeset View
Changeset View
Standalone View
Standalone View
wallpapers/image/image.cpp
Show First 20 Lines • Show All 185 Lines • ▼ Show 20 Line(s) | 185 | if (images.empty()) { | |||
---|---|---|---|---|---|
186 | return QString(); | 186 | return QString(); | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | //float targetAspectRatio = (m_targetSize.height() > 0 ) ? m_targetSize.width() / (float)m_targetSize.height() : 0; | 189 | //float targetAspectRatio = (m_targetSize.height() > 0 ) ? m_targetSize.width() / (float)m_targetSize.height() : 0; | ||
190 | //qCDebug(IMAGEWALLPAPER) << "wanted" << m_targetSize << "options" << images << "aspect ratio" << targetAspectRatio; | 190 | //qCDebug(IMAGEWALLPAPER) << "wanted" << m_targetSize << "options" << images << "aspect ratio" << targetAspectRatio; | ||
191 | float best = FLT_MAX; | 191 | float best = FLT_MAX; | ||
192 | 192 | | |||
193 | QString bestImage; | 193 | QString bestImage; | ||
194 | foreach (const QString &entry, images) { | 194 | for (const QString &entry : images) { | ||
195 | QSize candidate = resSize(QFileInfo(entry).baseName()); | 195 | QSize candidate = resSize(QFileInfo(entry).baseName()); | ||
196 | if (candidate == QSize()) { | 196 | if (candidate == QSize()) { | ||
197 | continue; | 197 | continue; | ||
198 | } | 198 | } | ||
199 | //float candidateAspectRatio = (candidate.height() > 0 ) ? candidate.width() / (float)candidate.height() : FLT_MAX; | 199 | //float candidateAspectRatio = (candidate.height() > 0 ) ? candidate.width() / (float)candidate.height() : FLT_MAX; | ||
200 | 200 | | |||
201 | float dist = distance(candidate, m_targetSize); | 201 | float dist = distance(candidate, m_targetSize); | ||
202 | //qCDebug(IMAGEWALLPAPER) << "candidate" << candidate << "distance" << dist << "aspect ratio" << candidateAspectRatio; | 202 | //qCDebug(IMAGEWALLPAPER) << "candidate" << candidate << "distance" << dist << "aspect ratio" << candidateAspectRatio; | ||
▲ Show 20 Lines • Show All 212 Lines • ▼ Show 20 Line(s) | |||||
415 | 415 | | |||
416 | void Image::pathDirty(const QString& path) | 416 | void Image::pathDirty(const QString& path) | ||
417 | { | 417 | { | ||
418 | updateDirWatch(QStringList(path)); | 418 | updateDirWatch(QStringList(path)); | ||
419 | } | 419 | } | ||
420 | 420 | | |||
421 | void Image::updateDirWatch(const QStringList &newDirs) | 421 | void Image::updateDirWatch(const QStringList &newDirs) | ||
422 | { | 422 | { | ||
423 | Q_FOREACH(const QString &oldDir, m_dirs) { | 423 | for (const QString &oldDir : qAsConst(m_dirs)) { | ||
424 | if(!newDirs.contains(oldDir)) { | 424 | if(!newDirs.contains(oldDir)) { | ||
425 | m_dirWatch->removeDir(oldDir); | 425 | m_dirWatch->removeDir(oldDir); | ||
426 | } | 426 | } | ||
427 | } | 427 | } | ||
428 | 428 | | |||
429 | Q_FOREACH(const QString &newDir, newDirs) { | 429 | for (const QString &newDir : newDirs) { | ||
430 | if(!m_dirWatch->contains(newDir)) { | 430 | if(!m_dirWatch->contains(newDir)) { | ||
431 | m_dirWatch->addDir(newDir, KDirWatch::WatchSubDirs | KDirWatch::WatchFiles); | 431 | m_dirWatch->addDir(newDir, KDirWatch::WatchSubDirs | KDirWatch::WatchFiles); | ||
432 | } | 432 | } | ||
433 | } | 433 | } | ||
434 | 434 | | |||
435 | m_dirs = newDirs; | 435 | m_dirs = newDirs; | ||
436 | } | 436 | } | ||
437 | 437 | | |||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 454 | { | |||
497 | if (m_wallpaperPath != oldPath) { | 497 | if (m_wallpaperPath != oldPath) { | ||
498 | Q_EMIT wallpaperPathChanged(); | 498 | Q_EMIT wallpaperPathChanged(); | ||
499 | } | 499 | } | ||
500 | } | 500 | } | ||
501 | 501 | | |||
502 | void Image::addUrls(const QList<QUrl> &urls) | 502 | void Image::addUrls(const QList<QUrl> &urls) | ||
503 | { | 503 | { | ||
504 | bool first = true; | 504 | bool first = true; | ||
505 | Q_FOREACH (const QUrl &url, urls) { | 505 | for (const QUrl &url : urls) { | ||
506 | // set the first drop as the current paper, just add the rest to the roll | 506 | // set the first drop as the current paper, just add the rest to the roll | ||
507 | addUrl(url, first); | 507 | addUrl(url, first); | ||
508 | first = false; | 508 | first = false; | ||
509 | } | 509 | } | ||
510 | } | 510 | } | ||
511 | 511 | | |||
512 | void Image::addUrl(const QUrl &url, bool setAsCurrent) | 512 | void Image::addUrl(const QUrl &url, bool setAsCurrent) | ||
513 | { | 513 | { | ||
▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Line(s) | 684 | if (!locations.isEmpty()) { | |||
685 | path = locations.at(0); | 685 | path = locations.at(0); | ||
686 | } else { | 686 | } else { | ||
687 | // HomeLocation is guaranteed not to be empty. | 687 | // HomeLocation is guaranteed not to be empty. | ||
688 | path = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0); | 688 | path = QStandardPaths::standardLocations(QStandardPaths::HomeLocation).at(0); | ||
689 | } | 689 | } | ||
690 | 690 | | |||
691 | QMimeDatabase db; | 691 | QMimeDatabase db; | ||
692 | QStringList imageGlobPatterns; | 692 | QStringList imageGlobPatterns; | ||
693 | foreach(const QByteArray &mimeType, QImageReader::supportedMimeTypes()) { | 693 | const auto mimeTypes = QImageReader::supportedMimeTypes(); | ||
694 | for (const QByteArray &mimeType : mimeTypes) { | ||||
694 | QMimeType mime(db.mimeTypeForName(mimeType)); | 695 | QMimeType mime(db.mimeTypeForName(mimeType)); | ||
695 | imageGlobPatterns << mime.globPatterns(); | 696 | imageGlobPatterns << mime.globPatterns(); | ||
696 | } | 697 | } | ||
697 | 698 | | |||
698 | m_dialog = new QFileDialog(nullptr, i18n("Open Image"), | 699 | m_dialog = new QFileDialog(nullptr, i18n("Open Image"), | ||
699 | path, | 700 | path, | ||
700 | i18n("Image Files") + " ("+imageGlobPatterns.join(' ') + ')'); | 701 | i18n("Image Files") + " ("+imageGlobPatterns.join(' ') + ')'); | ||
701 | //i18n people, this isn't a "word puzzle". there is a specific string format for QFileDialog::setNameFilters | 702 | //i18n people, this isn't a "word puzzle". there is a specific string format for QFileDialog::setNameFilters | ||
▲ Show 20 Lines • Show All 228 Lines • Show Last 20 Lines |