File indexing completed on 2025-01-19 03:50:46

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2002-16-10
0007  * Description : Item icon view interface - Zoom methods.
0008  *
0009  * SPDX-FileCopyrightText: 2002-2005 by Renchi Raju <renchi dot raju at gmail dot com>
0010  * SPDX-FileCopyrightText: 2002-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2009-2011 by Johannes Wienke <languitar at semipol dot de>
0012  * SPDX-FileCopyrightText: 2010-2011 by Andi Clemens <andi dot clemens at gmail dot com>
0013  * SPDX-FileCopyrightText: 2011-2013 by Michael G. Hansen <mike at mghansen dot de>
0014  * SPDX-FileCopyrightText: 2014-2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0015  * SPDX-FileCopyrightText: 2017      by Simon Frei <freisim93 at gmail dot com>
0016  *
0017  * SPDX-License-Identifier: GPL-2.0-or-later
0018  *
0019  * ============================================================ */
0020 
0021 #include "itemiconview_p.h"
0022 
0023 namespace Digikam
0024 {
0025 
0026 double ItemIconView::zoomMin() const
0027 {
0028     return d->stackedView->zoomMin();
0029 }
0030 
0031 double ItemIconView::zoomMax() const
0032 {
0033     return d->stackedView->zoomMax();
0034 }
0035 
0036 void ItemIconView::setZoomFactor(double zoom)
0037 {
0038     d->stackedView->setZoomFactorSnapped(zoom);
0039 }
0040 
0041 void ItemIconView::slotZoomFactorChanged(double zoom)
0042 {
0043     toggleZoomActions();
0044 
0045     Q_EMIT signalZoomChanged(zoom);
0046 }
0047 
0048 void ItemIconView::toggleZoomActions()
0049 {
0050     if      (viewMode() == StackedView::PreviewImageMode)
0051     {
0052         d->parent->enableZoomMinusAction(true);
0053         d->parent->enableZoomPlusAction(true);
0054 
0055         if (d->stackedView->maxZoom())
0056         {
0057             d->parent->enableZoomPlusAction(false);
0058         }
0059 
0060         if (d->stackedView->minZoom())
0061         {
0062             d->parent->enableZoomMinusAction(false);
0063         }
0064     }
0065     else if ((viewMode() == StackedView::IconViewMode) ||
0066              (viewMode() == StackedView::TableViewMode))
0067     {
0068         d->parent->enableZoomMinusAction(true);
0069         d->parent->enableZoomPlusAction(true);
0070 
0071         if (d->thumbSize >= ThumbnailSize::maxThumbsSize())
0072         {
0073             d->parent->enableZoomPlusAction(false);
0074         }
0075 
0076         if (d->thumbSize <= ThumbnailSize::Small)
0077         {
0078             d->parent->enableZoomMinusAction(false);
0079         }
0080     }
0081     else
0082     {
0083         d->parent->enableZoomMinusAction(false);
0084         d->parent->enableZoomPlusAction(false);
0085     }
0086 }
0087 
0088 void ItemIconView::slotZoomIn()
0089 {
0090     if      ((viewMode() == StackedView::IconViewMode) ||
0091              (viewMode() == StackedView::TableViewMode))
0092     {
0093         setThumbSize(d->thumbSize + ThumbnailSize::Step);
0094         toggleZoomActions();
0095         Q_EMIT signalThumbSizeChanged(d->thumbSize);
0096     }
0097     else if (viewMode() == StackedView::PreviewImageMode)
0098     {
0099         d->stackedView->increaseZoom();
0100     }
0101 }
0102 
0103 void ItemIconView::slotZoomOut()
0104 {
0105     if      ((viewMode() == StackedView::IconViewMode) ||
0106              (viewMode() == StackedView::TableViewMode))
0107     {
0108         setThumbSize(d->thumbSize - ThumbnailSize::Step);
0109         toggleZoomActions();
0110         Q_EMIT signalThumbSizeChanged(d->thumbSize);
0111     }
0112     else if (viewMode() == StackedView::PreviewImageMode)
0113     {
0114         d->stackedView->decreaseZoom();
0115     }
0116 }
0117 
0118 void ItemIconView::slotZoomTo100Percents()
0119 {
0120     if (viewMode() == StackedView::PreviewImageMode)
0121     {
0122         d->stackedView->toggleFitToWindowOr100();
0123     }
0124 }
0125 
0126 void ItemIconView::slotFitToWindow()
0127 {
0128     if      (viewMode() == StackedView::TableViewMode)
0129     {
0130         /// @todo We should choose an appropriate thumbnail size here
0131     }
0132     else if (viewMode() == StackedView::IconViewMode)
0133     {
0134         int nts = d->iconView->fitToWidthIcons();
0135         qCDebug(DIGIKAM_GENERAL_LOG) << "new thumb size = " << nts;
0136         setThumbSize(nts);
0137         toggleZoomActions();
0138         Q_EMIT signalThumbSizeChanged(d->thumbSize);
0139     }
0140     else if (viewMode() == StackedView::PreviewImageMode)
0141     {
0142         d->stackedView->fitToWindow();
0143     }
0144 }
0145 
0146 void ItemIconView::setThumbSize(int size)
0147 {
0148     if      (viewMode() == StackedView::PreviewImageMode)
0149     {
0150         double z = DZoomBar::zoomFromSize(size, zoomMin(), zoomMax());
0151         setZoomFactor(z);
0152     }
0153     else if ((viewMode() == StackedView::IconViewMode)  ||
0154              (viewMode() == StackedView::TableViewMode) ||
0155              (viewMode() == StackedView::TrashViewMode))
0156     {
0157         if      (size > ThumbnailSize::maxThumbsSize())
0158         {
0159             d->thumbSize = ThumbnailSize::maxThumbsSize();
0160         }
0161         else if (size < ThumbnailSize::Small)
0162         {
0163             d->thumbSize = ThumbnailSize::Small;
0164         }
0165         else
0166         {
0167             d->thumbSize = size;
0168         }
0169 
0170         Q_EMIT signalThumbSizeChanged(d->thumbSize);
0171 
0172         d->thumbSizeTimer->start();
0173     }
0174 }
0175 
0176 void ItemIconView::slotThumbSizeEffect()
0177 {
0178     d->iconView->setThumbnailSize(ThumbnailSize(d->thumbSize));
0179     d->tableView->setThumbnailSize(ThumbnailSize(d->thumbSize));
0180     d->trashView->setThumbnailSize(ThumbnailSize(d->thumbSize));
0181     toggleZoomActions();
0182 
0183     ApplicationSettings::instance()->setDefaultIconSize(d->thumbSize);
0184 }
0185 
0186 } // namespace Digikam