File indexing completed on 2025-04-27 03:58:34
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2021-04-18 0007 * Description : ExifTool error view. 0008 * 0009 * SPDX-FileCopyrightText: 2021-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "exiftoolloadingview.h" 0016 0017 // Qt includes 0018 0019 #include <QLabel> 0020 #include <QApplication> 0021 #include <QStyle> 0022 #include <QTimer> 0023 #include <QGridLayout> 0024 0025 // KDE includes 0026 0027 #include <klocalizedstring.h> 0028 0029 // Local includes 0030 0031 #include "dworkingpixmap.h" 0032 0033 namespace Digikam 0034 { 0035 0036 class Q_DECL_HIDDEN ExifToolLoadingView::Private 0037 { 0038 0039 public: 0040 0041 explicit Private() 0042 : msgLbl (nullptr), 0043 busy (false), 0044 progressCount (0), 0045 progressPix (nullptr), 0046 progressTimer (nullptr), 0047 progressLabel (nullptr) 0048 { 0049 } 0050 0051 QLabel* msgLbl; 0052 0053 bool busy; 0054 int progressCount; 0055 DWorkingPixmap* progressPix; 0056 QTimer* progressTimer; 0057 QLabel* progressLabel; 0058 }; 0059 0060 ExifToolLoadingView::ExifToolLoadingView(QWidget* const parent) 0061 : QWidget(parent), 0062 d (new Private) 0063 { 0064 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 0065 const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0066 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0067 0068 QGridLayout* const grid = new QGridLayout(this); 0069 0070 d->progressPix = new DWorkingPixmap(this); 0071 d->progressLabel = new QLabel(this); 0072 d->progressLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); 0073 0074 d->msgLbl = new QLabel(i18nc("info", "Loading in progress"), this); 0075 d->msgLbl->setAlignment(Qt::AlignCenter); 0076 d->msgLbl->setWordWrap(true); 0077 0078 grid->addWidget(d->progressLabel, 1, 1, 1, 1); 0079 grid->addWidget(d->msgLbl, 2, 1, 1, 1); 0080 grid->setColumnStretch(0, 10); 0081 grid->setColumnStretch(2, 10); 0082 grid->setContentsMargins(spacing, spacing, spacing, spacing); 0083 grid->setRowStretch(0, 10); 0084 grid->setRowStretch(3, 10); 0085 0086 d->progressTimer = new QTimer(this); 0087 0088 connect(d->progressTimer, &QTimer::timeout, 0089 this, &ExifToolLoadingView::slotProgressTimerDone); 0090 } 0091 0092 ExifToolLoadingView::~ExifToolLoadingView() 0093 { 0094 delete d; 0095 } 0096 0097 void ExifToolLoadingView::setBusy(bool b) 0098 { 0099 d->busy = b; 0100 0101 if (d->busy) 0102 { 0103 setCursor(Qt::WaitCursor); 0104 d->progressTimer->start(300); 0105 } 0106 else 0107 { 0108 unsetCursor(); 0109 d->progressTimer->stop(); 0110 d->progressLabel->setPixmap(QPixmap()); 0111 } 0112 } 0113 0114 void ExifToolLoadingView::slotProgressTimerDone() 0115 { 0116 d->progressLabel->setPixmap(d->progressPix->frameAt(d->progressCount)); 0117 d->progressCount++; 0118 0119 if (d->progressCount == 8) 0120 { 0121 d->progressCount = 0; 0122 } 0123 0124 d->progressTimer->start(300); 0125 } 0126 0127 } // namespace Digikam 0128 0129 #include "moc_exiftoolloadingview.cpp"