Commit 73502cc7 authored by Gilles Caulier's avatar Gilles Caulier 🗼
Browse files

Add new FullScreenMngr class dedicated manage full-screen action to digiKam...

Add new FullScreenMngr class dedicated manage full-screen action to digiKam KXMLGuiWindow instances.
This class factorize a lots of code when window is turned on/off to full-screen mode.
This fix problem about visibility restoring with status-bar, menu-bar, and thumb-bar.
First managed digiKam main window is Image Editor.
TODO :
- manage full-screen mode of main windows AlbumGUI, BQM, ImportUI, and LT, through FullScreenMngr.
- manage visibility of side-bars.
- provide a common settings widget to control visibility management in Configuration dialog.
- patch Configuration dialog to provide a fine control of visibility management in full-screen mode for each digiKam main window.

CCBUGS: 214107
CCBUGS: 220739
CCBUGS: 289262
CCBUGS: 236234
CCBUGS: 258180
CCBUGS: 293676
parent 10de712a
......@@ -980,6 +980,7 @@ IF(DIGIKAM_CAN_BE_COMPILED)
${CMAKE_CURRENT_SOURCE_DIR}/libs/widgets/common/dragdropimplementations.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libs/widgets/common/dzoombar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libs/widgets/common/filesaveoptionsbox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libs/widgets/common/fullscreenmngr.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libs/widgets/common/knotificationwrapper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libs/widgets/common/modelcompletion.cpp
${CMAKE_CURRENT_SOURCE_DIR}/libs/widgets/common/paniconwidget.cpp
......
/* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
* Date : 2013-04-29
* Description : a full screen manager for digiKam XML GUI windows
*
* Copyright (C) 2013 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
// Qt includes
#include <QString>
#include <QList>
// KDE includes
#include <kxmlguiwindow.h>
#include <ktogglefullscreenaction.h>
#include <kglobalsettings.h>
#include <kdebug.h>
#include <kmenubar.h>
#include <kstatusbar.h>
#include <ktoolbar.h>
// Local includes
#include "fullscreenmngr.h"
namespace Digikam
{
class FullScreenMngr::Private
{
public:
Private()
{
win = 0;
removeFullScreenButton = false;
}
/** Used by switchWindowToFullScreen() to switch tool-bar visibility in managed window
*/
void hideToolBars();
void showToolBars();
public:
/** Windo instance to manage */
KXmlGuiWindow* win;
/** Used by switchWindowToFullScreen() to manage state of full-screen button on managed window
*/
bool removeFullScreenButton;
static const QString configFullScreenEntry;
static const QString configFullScreenHideThumbBarEntry;
static const QString configFullScreenHideToolBarEntry;
};
const QString FullScreenMngr::Private::configFullScreenEntry("FullScreen");
const QString FullScreenMngr::Private::configFullScreenHideThumbBarEntry("FullScreen Hide ThumbBar");
const QString FullScreenMngr::Private::configFullScreenHideToolBarEntry("FullScreen Hide ToolBar");
void FullScreenMngr::Private::hideToolBars()
{
QList<KToolBar*> toolbars = win->toolBars();
foreach(KToolBar* const toolbar, toolbars)
{
toolbar->hide();
}
}
void FullScreenMngr::Private::showToolBars()
{
QList<KToolBar*> toolbars = win->toolBars();
foreach(KToolBar* const toolbar, toolbars)
{
toolbar->show();
}
}
// --------------------------------------------------------------------------------------------------------
FullScreenMngr::FullScreenMngr()
: d(new Private)
{
m_fullScreenHideToolBar = false;
m_fullScreenHideThumbBar = true;
m_fullScreenAction = 0;
}
FullScreenMngr::~FullScreenMngr()
{
delete d;
}
void FullScreenMngr::setManagedWindow(KXmlGuiWindow* const win)
{
d->win = win;
}
void FullScreenMngr::readSettings(const KConfigGroup& group)
{
m_fullScreenHideToolBar = group.readEntry(d->configFullScreenHideToolBarEntry, false);
m_fullScreenHideThumbBar = group.readEntry(d->configFullScreenHideThumbBarEntry, true);
if (group.readEntry(d->configFullScreenEntry, false))
{
if (m_fullScreenAction)
m_fullScreenAction->activate(QAction::Trigger);
}
}
void FullScreenMngr::saveSettings(KConfigGroup& group)
{
group.writeEntry(d->configFullScreenHideToolBarEntry, m_fullScreenHideToolBar);
group.writeEntry(d->configFullScreenHideThumbBarEntry, m_fullScreenHideThumbBar);
if (m_fullScreenAction)
group.writeEntry(d->configFullScreenEntry, m_fullScreenAction->isChecked());
}
void FullScreenMngr::switchWindowToFullScreen(bool set)
{
KToggleFullScreenAction::setFullScreen(d->win, set);
if (!set)
{
kDebug() << "TURN OFF fullscreen";
d->win->menuBar()->show();
d->win->statusBar()->show();
d->showToolBars();
if (d->removeFullScreenButton)
{
QList<KToolBar*> toolbars = d->win->toolBars();
foreach(KToolBar* const toolbar, toolbars)
{
// NOTE: name must be configured properly in ui.rc XML file of managed window
if (toolbar->objectName() == "mainToolBar")
{
toolbar->removeAction(m_fullScreenAction);
break;
}
}
}
}
else
{
kDebug() << "TURN ON fullscreen";
// hide menubar and statusbar
d->win->menuBar()->hide();
d->win->statusBar()->hide();
if (m_fullScreenHideToolBar)
{
d->hideToolBars();
}
else
{
d->showToolBars();
QList<KToolBar*> toolbars = d->win->toolBars();
KToolBar* mainToolbar = 0;
foreach(KToolBar* const toolbar, toolbars)
{
if (toolbar->objectName() == "mainToolBar")
{
mainToolbar = toolbar;
break;
}
}
kDebug() << mainToolbar;
// add fullscreen action if necessary in toolbar
if (mainToolbar && !mainToolbar->actions().contains(m_fullScreenAction))
{
if (mainToolbar->actions().isEmpty())
{
mainToolbar->addAction(m_fullScreenAction);
}
else
{
mainToolbar->insertAction(mainToolbar->actions().first(), m_fullScreenAction);
}
d->removeFullScreenButton = true;
}
else
{
// If FullScreen button is enabled in toolbar settings,
// we shall not remove it when leaving of fullscreen mode.
d->removeFullScreenButton = false;
}
}
}
}
void FullScreenMngr::escapePressed()
{
if (m_fullScreenAction->isChecked())
{
m_fullScreenAction->activate(QAction::Trigger);
}
}
} // namespace Digikam
/* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
* Date : 2013-04-29
* Description : a full screen manager for digiKam XML GUI windows
*
* Copyright (C) 2013 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
#ifndef FULLSCREENMNGR_H
#define FULLSCREENMNGR_H
// KDE includes
#include <kconfiggroup.h>
// Local includes
#include "digikam_export.h"
class KXmlGuiWindow;
class KToggleFullScreenAction;
namespace Digikam
{
/** Data container to use in managed window.
*/
class DIGIKAM_EXPORT FullScreenMngr
{
public:
FullScreenMngr();
virtual ~FullScreenMngr();
/** Set instance of managed window
*/
void setManagedWindow(KXmlGuiWindow* const win);
/** Read and write settings from/to KDE config file
*/
void readSettings(const KConfigGroup& group);
void saveSettings(KConfigGroup& group);
/** Switch Window 'win' to full screen mode.
* 'set' argument will set or reset the fullscreen state of window.
*/
void switchWindowToFullScreen(bool set);
/** Active full-screen action from managed window. Called typically when Escape key is pressed.
*/
void escapePressed();
public:
/** Settigns taken from managed window configuration to handle toolbar visibility in full-screen mode
*/
bool m_fullScreenHideToolBar;
/** Settigns taken from managed window configuration to handle thumbbar visibility in full-screen mode
*/
bool m_fullScreenHideThumbBar;
/** Action from window used to sxitch fullscreen state*/
KToggleFullScreenAction* m_fullScreenAction;
private:
class Private;
Private* const d;
};
} // namespace Digikam
#endif /* FULLSCREENMNGR_H */
......@@ -171,7 +171,6 @@ EditorWindow::EditorWindow(const char* const name)
m_contextMenu = 0;
m_canvas = 0;
m_imagePluginLoader = 0;
m_fullScreenAction = 0;
m_openVersionAction = 0;
m_saveAction = 0;
m_saveAsAction = 0;
......@@ -197,7 +196,6 @@ EditorWindow::EditorWindow(const char* const name)
m_animLogo = 0;
m_setExifOrientationTag = true;
m_cancelSlideShow = false;
m_fullScreenHideThumbBar = true;
m_editingOriginalImage = true;
// Settings containers instance.
......@@ -206,6 +204,8 @@ EditorWindow::EditorWindow(const char* const name)
d->toolIface = new EditorToolIface(this);
m_IOFileSettings = new IOFileSettings();
d->waitingLoop = new QEventLoop(this);
d->fullScreenMngr.setManagedWindow(this);
}
EditorWindow::~EditorWindow()
......@@ -507,9 +507,9 @@ void EditorWindow::setupStandardActions()
// --------------------------------------------------------
m_fullScreenAction = KStandardAction::fullScreen(0, 0, this, this);
actionCollection()->addAction("editorwindow_fullscreen", m_fullScreenAction);
connect(m_fullScreenAction, SIGNAL(toggled(bool)), this, SLOT(slotToggleFullScreen(bool)));
d->fullScreenMngr.m_fullScreenAction = KStandardAction::fullScreen(0, 0, this, this);
actionCollection()->addAction("editorwindow_fullscreen", d->fullScreenMngr.m_fullScreenAction);
connect(d->fullScreenMngr.m_fullScreenAction, SIGNAL(toggled(bool)), this, SLOT(slotToggleFullScreen(bool)));
d->slideShowAction = new KAction(KIcon("view-presentation"), i18n("Slideshow"), this);
d->slideShowAction->setShortcut(KShortcut(Qt::Key_F9));
......@@ -923,10 +923,7 @@ void EditorWindow::readStandardSettings()
}
// Restore full screen Mode
if (group.readEntry(d->configFullScreenEntry, false))
{
m_fullScreenAction->activate(QAction::Trigger);
}
d->fullScreenMngr.readSettings(group);
// Restore Auto zoom action
bool autoZoom = group.readEntry(d->configAutoZoomEntry, true);
......@@ -954,9 +951,7 @@ void EditorWindow::applyStandardSettings()
d->legacyUpdateSplitterState(group);
m_splitter->restoreState(group);
d->fullScreenHideToolBar = group.readEntry(d->configFullScreenHideToolBarEntry, false);
m_fullScreenHideThumbBar = group.readEntry(d->configFullScreenHideThumbBarEntry, true);
d->fullScreenMngr.readSettings(group);
slotThemeChanged();
......@@ -1065,11 +1060,10 @@ void EditorWindow::saveStandardSettings()
}
group.writeEntry("Show Thumbbar", thumbBar()->shouldBeVisible());
group.writeEntry(d->configFullScreenEntry, m_fullScreenAction->isChecked());
group.writeEntry(d->configUnderExposureIndicatorEntry, d->exposureSettings->underExposureIndicator);
group.writeEntry(d->configOverExposureIndicatorEntry, d->exposureSettings->overExposureIndicator);
d->previewToolBar->writeSettings(group);
d->fullScreenMngr.saveSettings(group);
config->sync();
}
......@@ -1182,14 +1176,6 @@ void EditorWindow::toggleToolActions(EditorTool* tool)
m_closeToolAction->setVisible(tool);
}
void EditorWindow::keyPressEvent(QKeyEvent* e)
{
if (e->key() == Qt::Key_Escape)
{
slotEscapePressed();
}
}
void EditorWindow::slotLoadingProgress(const QString&, float progress)
{
m_nameLabel->setProgressValue((int)(progress * 100.0));
......@@ -2973,119 +2959,43 @@ void EditorWindow::addAction2ContextMenu(const QString& actionName, bool addDisa
void EditorWindow::slotToggleFullScreen(bool b)
{
KToggleFullScreenAction::setFullScreen(this, b);
d->fullScreenMngr.switchWindowToFullScreen(b);
if (!b)
{
// Switch off fullscreen
kDebug() << "TURN OFF fullscreen";
m_canvas->setBackgroundColor(m_bgColor);
slotShowMenuBar();
statusBar()->show();
showToolBars();
if (d->removeFullScreenButton)
{
QList<KToolBar*> toolbars = toolBars();
foreach(KToolBar* const toolbar, toolbars)
{
// name is set in ui.rc XML file
if (toolbar->objectName() == "mainToolBar")
{
toolbar->removeAction(m_fullScreenAction);
break;
}
}
}
toggleGUI2FullScreen();
}
else // go to fullscreen
{
m_canvas->setBackgroundColor(QColor(Qt::black));
// hide the menubar and the statusbar
menuBar()->hide();
statusBar()->hide();
if (d->fullScreenHideToolBar)
{
hideToolBars();
}
else
{
showToolBars();
QList<KToolBar*> toolbars = toolBars();
KToolBar* mainToolbar = 0;
foreach(KToolBar* const toolbar, toolbars)
{
if (toolbar->objectName() == "mainToolBar")
{
mainToolbar = toolbar;
break;
}
}
kDebug() << mainToolbar;
// add fullscreen action if necessary
if (mainToolbar && !mainToolbar->actions().contains(m_fullScreenAction))
{
if (mainToolbar->actions().isEmpty())
{
mainToolbar->addAction(m_fullScreenAction);
}
else
{
mainToolbar->insertAction(mainToolbar->actions().first(), m_fullScreenAction);
}
d->removeFullScreenButton = true;
}
else
{
// If FullScreen button is enabled in toolbar settings,
// we shall not remove it when leaving of fullscreen mode.
d->removeFullScreenButton = false;
}
}
toggleGUI2FullScreen();
}
}
void EditorWindow::toggleGUI2FullScreen()
{
if (m_fullScreenAction->isChecked())
{
rightSideBar()->restore(QList<QWidget*>() << thumbBar(), d->fullscreenSizeBackup);
if (m_fullScreenHideThumbBar)
if (d->fullScreenMngr.m_fullScreenHideThumbBar)
{
thumbBar()->restoreVisibility();
}
}
else
{
kDebug() << "TURN ON fullscreen";
m_canvas->setBackgroundColor(QColor(Qt::black));
// See bug #166472, a simple backup()/restore() will hide non-sidebar splitter child widgets
// in horizontal mode thumbbar wont be member of the splitter, it is just ignored then
rightSideBar()->backup(QList<QWidget*>() << thumbBar(), &d->fullscreenSizeBackup);
if (m_fullScreenHideThumbBar)
if (d->fullScreenMngr.m_fullScreenHideThumbBar)
{
thumbBar()->hide();
}
}
}
void EditorWindow::slotEscapePressed()
void EditorWindow::keyPressEvent(QKeyEvent* e)
{
if (m_fullScreenAction->isChecked())
if (e->key() == Qt::Key_Escape)
{
m_fullScreenAction->activate(QAction::Trigger);
d->fullScreenMngr.escapePressed();
}
}
......
......@@ -54,7 +54,6 @@ class KActionMenu;
class KCategorizedView;
class KSelectAction;
class KToggleAction;
class KToggleFullScreenAction;
class KToolBarPopupAction;
class KMenu;
......@@ -103,7 +102,6 @@ Q_SIGNALS:
protected:
bool m_nonDestructive;
bool m_fullScreenHideThumbBar;
bool m_cancelSlideShow;
bool m_setExifOrientationTag;
bool m_editingOriginalImage;
......@@ -128,7 +126,6 @@ protected:
KAction* m_fileDeleteAction;
KAction* m_forwardAction;
KAction* m_backwardAction;
KToggleFullScreenAction* m_fullScreenAction;
KAction* m_lastAction;
KAction* m_firstAction;
......@@ -208,7 +205,6 @@ protected:
void colorManage();
void execSavingProgressDialog();
void toggleGUI2FullScreen();
void resetOrigin();
void resetOriginSwitchFile();
......@@ -267,7 +263,6 @@ protected Q_SLOTS:
void slotNewToolbarConfig();
void slotToggleFullScreen(bool b);
void slotEscapePressed();
void slotSelected(bool);
......
......@@ -42,6 +42,7 @@
#include "daboutdata.h"
#include "editorwindow.h"
#include "versionmanager.h"
#include "fullscreenmngr.h"
class QDialog;
class QEventLoop;
......@@ -70,8 +71,6 @@ class EditorWindow::Private
public:
Private() :
removeFullScreenButton(false),
fullScreenHideToolBar(false),
cmViewIndicator(0),
underExposureIndicator(0),
overExposureIndicator(0),
......@@ -126,9 +125,6 @@ public:
static const QString configAutoZoomEntry;
static const QString configBackgroundColorEntry;
static const QString configFullScreenEntry;
static const QString configFullScreenHideThumbBarEntry;
static const QString configFullScreenHideToolBarEntry;
static const QString configJpeg2000CompressionEntry;
static const QString configJpeg2000LossLessEntry;
static const QString configJpegCompressionEntry;
......@@ -150,9 +146,6 @@ public:
static const QString configVerticalSplitterSizesEntry;
static const QString configVerticalSplitterStateEntry;
bool removeFullScreenButton;