File indexing completed on 2025-01-05 03:56:39
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2014-09-12 0007 * Description : A working pixmap manager. 0008 * 0009 * SPDX-FileCopyrightText: 2014-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 "dworkingpixmap.h" 0016 0017 // Qt includes 0018 0019 #include <QApplication> 0020 #include <QStandardPaths> 0021 0022 // Local includes 0023 0024 #include "digikam_debug.h" 0025 0026 namespace Digikam 0027 { 0028 0029 DWorkingPixmap::DWorkingPixmap(QObject* const parent) 0030 : QObject(parent) 0031 { 0032 QPixmap pix(QStandardPaths::locate(QStandardPaths::GenericDataLocation, 0033 QLatin1String("digikam/data/process-working.png"))); 0034 if (pix.isNull()) 0035 { 0036 qCWarning(DIGIKAM_WIDGETS_LOG) << "Invalid pixmap specified."; 0037 0038 return; 0039 } 0040 0041 QSize size = QSize(pix.width(), pix.width()); 0042 0043 if (((pix.width()) % size.width()) || (pix.height() % size.height())) 0044 { 0045 qCWarning(DIGIKAM_WIDGETS_LOG) << "Invalid framesize."; 0046 0047 return; 0048 } 0049 0050 const int rowCount = pix.height() / size.height(); 0051 const int colCount = pix.width() / size.width(); 0052 m_frames.resize(rowCount * colCount); 0053 0054 int pos = 0; 0055 0056 for (int row = 0 ; row < rowCount ; ++row) 0057 { 0058 for (int col = 0 ; col < colCount ; ++col) 0059 { 0060 QPixmap frm = pix.copy(col * size.width(), row * size.height(), size.width(), size.height()); 0061 m_frames[pos++] = frm; 0062 } 0063 } 0064 } 0065 0066 DWorkingPixmap::~DWorkingPixmap() 0067 { 0068 } 0069 0070 bool DWorkingPixmap::isEmpty() const 0071 { 0072 return m_frames.isEmpty(); 0073 } 0074 0075 QSize DWorkingPixmap::frameSize() const 0076 { 0077 if (isEmpty()) 0078 { 0079 qCWarning(DIGIKAM_WIDGETS_LOG) << "No frame loaded."; 0080 0081 return QSize(); 0082 } 0083 0084 return m_frames[0].size(); 0085 } 0086 0087 int DWorkingPixmap::frameCount() const 0088 { 0089 return m_frames.size(); 0090 } 0091 0092 QPixmap DWorkingPixmap::frameAt(int index) const 0093 { 0094 if (isEmpty()) 0095 { 0096 qCWarning(DIGIKAM_WIDGETS_LOG) << "No frame loaded."; 0097 0098 return QPixmap(); 0099 } 0100 0101 return m_frames.at(index); 0102 } 0103 0104 } // namespace Digikam 0105 0106 #include "moc_dworkingpixmap.cpp"