File indexing completed on 2025-04-27 03:58:32

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2013-04-29
0007  * Description : digiKam XML GUI window - Full-screen methods.
0008  *
0009  * SPDX-FileCopyrightText: 2013-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 "dxmlguiwindow_p.h"
0016 
0017 namespace Digikam
0018 {
0019 
0020 void DXmlGuiWindow::setFullScreenOptions(int options)
0021 {
0022     d->fsOptions = options;
0023 }
0024 
0025 void DXmlGuiWindow::createFullScreenAction(const QString& name)
0026 {
0027     d->fullScreenAction = KStandardAction::fullScreen(nullptr, nullptr, this, this);
0028     actionCollection()->addAction(name, d->fullScreenAction);
0029     d->fullScreenBtn    = new QToolButton(this);
0030     d->fullScreenBtn->setDefaultAction(d->fullScreenAction);
0031     d->fullScreenBtn->hide();
0032 
0033     connect(d->fullScreenAction, SIGNAL(toggled(bool)),
0034             this, SLOT(slotToggleFullScreen(bool)));
0035 }
0036 
0037 void DXmlGuiWindow::readFullScreenSettings(const KConfigGroup& group)
0038 {
0039     if (d->fsOptions & FS_TOOLBARS)
0040     {
0041         d->fullScreenHideToolBars  = group.readEntry(s_configFullScreenHideToolBarsEntry,  false);
0042     }
0043 
0044     if (d->fsOptions & FS_THUMBBAR)
0045     {
0046         d->fullScreenHideThumbBar  = group.readEntry(s_configFullScreenHideThumbBarEntry,  true);
0047     }
0048 
0049     if (d->fsOptions & FS_SIDEBARS)
0050     {
0051         d->fullScreenHideSideBars  = group.readEntry(s_configFullScreenHideSideBarsEntry,  false);
0052     }
0053 
0054     if (d->fsOptions & FS_STATUSBAR)
0055     {
0056         d->fullScreenHideStatusBar = group.readEntry(s_configFullScreenHideStatusBarEntry, false);
0057     }
0058 }
0059 
0060 void DXmlGuiWindow::slotToggleFullScreen(bool set)
0061 {
0062 
0063 #ifdef Q_OS_MACOS
0064 
0065     // Work aroung Qt bug under MacOS. See bug #414117
0066 
0067     if (set)
0068     {
0069         d->fullScreenParent = parentWidget();
0070         setParent(nullptr);
0071     }
0072 
0073 #endif
0074 
0075     KToggleFullScreenAction::setFullScreen(this, set);
0076 
0077 #ifdef Q_OS_MACOS
0078 
0079     if (!set)
0080     {
0081         setParent(d->fullScreenParent);
0082     }
0083 
0084 #endif
0085 
0086     customizedFullScreenMode(set);
0087 
0088     if (!set)
0089     {
0090         qCDebug(DIGIKAM_WIDGETS_LOG) << "TURN OFF fullscreen";
0091 
0092         // restore menubar
0093 
0094         if (d->menubarVisibility)
0095         {
0096             menuBar()->setVisible(true);
0097         }
0098 
0099         // restore statusbar
0100 
0101         if ((d->fsOptions & FS_STATUSBAR) && d->fullScreenHideStatusBar)
0102         {
0103             statusBar()->setVisible(d->statusbarVisibility);
0104         }
0105 
0106         // restore sidebars
0107 
0108         if ((d->fsOptions & FS_SIDEBARS) && d->fullScreenHideSideBars)
0109         {
0110             showSideBars(true);
0111         }
0112 
0113         // restore thumbbar
0114 
0115         if ((d->fsOptions & FS_THUMBBAR) && d->fullScreenHideThumbBar)
0116         {
0117             showThumbBar(d->thumbbarVisibility);
0118         }
0119 
0120         // restore toolbars and manage full-screen button
0121 
0122         showToolBars(true);
0123         d->fullScreenBtn->hide();
0124 
0125         if (d->dirtyMainToolBar)
0126         {
0127             KToolBar* const mainbar = mainToolBar();
0128 
0129             if (mainbar)
0130             {
0131                 mainbar->removeAction(d->fullScreenAction);
0132             }
0133         }
0134     }
0135     else
0136     {
0137         qCDebug(DIGIKAM_WIDGETS_LOG) << "TURN ON fullscreen";
0138 
0139         // hide menubar
0140 
0141 #ifdef Q_OS_WIN
0142 
0143         d->menubarVisibility = d->showMenuBarAction->isChecked();
0144 
0145 #else
0146 
0147         d->menubarVisibility = menuBar()->isVisible();
0148 
0149 #endif
0150 
0151         menuBar()->setVisible(false);
0152 
0153         // hide statusbar
0154 
0155 #ifdef Q_OS_WIN
0156 
0157         d->statusbarVisibility = d->showStatusBarAction->isChecked();
0158 
0159 #else
0160 
0161         d->statusbarVisibility = statusBar()->isVisible();
0162 
0163 #endif
0164 
0165         if ((d->fsOptions & FS_STATUSBAR) && d->fullScreenHideStatusBar)
0166         {
0167             statusBar()->setVisible(false);
0168         }
0169 
0170         // hide sidebars
0171 
0172         if ((d->fsOptions & FS_SIDEBARS) && d->fullScreenHideSideBars)
0173         {
0174             showSideBars(false);
0175         }
0176 
0177         // hide thumbbar
0178 
0179         d->thumbbarVisibility = thumbbarVisibility();
0180 
0181         if ((d->fsOptions & FS_THUMBBAR) && d->fullScreenHideThumbBar)
0182         {
0183             showThumbBar(false);
0184         }
0185 
0186         // hide toolbars and manage full-screen button
0187 
0188         if ((d->fsOptions & FS_TOOLBARS) && d->fullScreenHideToolBars)
0189         {
0190             showToolBars(false);
0191         }
0192         else
0193         {
0194             showToolBars(true);
0195 
0196             // add fullscreen action if necessary in toolbar
0197 
0198             KToolBar* const mainbar = mainToolBar();
0199 
0200             if (mainbar && !mainbar->actions().contains(d->fullScreenAction))
0201             {
0202                 if (mainbar->actions().isEmpty())
0203                 {
0204                     mainbar->addAction(d->fullScreenAction);
0205                 }
0206                 else
0207                 {
0208                     mainbar->insertAction(mainbar->actions().constFirst(), d->fullScreenAction);
0209                 }
0210 
0211                 d->dirtyMainToolBar = true;
0212             }
0213             else
0214             {
0215                 // If FullScreen button is enabled in toolbar settings,
0216                 // we shall not remove it when leaving of fullscreen mode.
0217 
0218                 d->dirtyMainToolBar = false;
0219             }
0220         }
0221     }
0222 }
0223 
0224 bool DXmlGuiWindow::fullScreenIsActive() const
0225 {
0226     if (d->fullScreenAction)
0227     {
0228         return d->fullScreenAction->isChecked();
0229     }
0230 
0231     qCDebug(DIGIKAM_WIDGETS_LOG) << "FullScreenAction is not initialized";
0232 
0233     return false;
0234 }
0235 
0236 void DXmlGuiWindow::customizedFullScreenMode(bool set)
0237 {
0238     Q_UNUSED(set);
0239 }
0240 
0241 void DXmlGuiWindow::checkFullScreenBeforeClosing()
0242 {
0243     if (fullScreenIsActive())
0244     {
0245         slotToggleFullScreen(false);
0246     }
0247 
0248     qApp->processEvents();
0249 
0250     if (!testAttribute(Qt::WA_DeleteOnClose))
0251     {
0252         setVisible(false);
0253     }
0254 }
0255 
0256 } // namespace Digikam