Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 602db1bc authored by Peter Mühlenpfordt's avatar Peter Mühlenpfordt

Adjust sidebar code and config entries to statusbar

Summary:
Setup config entries and default values of sidebar states in
`gwenview.kcfg` and use the generated access functions like it
is done for statusbar in D10577.
From a user's sight the sidebar behaviour and state saving is
not changed.

Test Plan:
Switch browse/view, normal/fullscreen modes.
The sidebar state should always restore to previous setting and
button on statusbar should correspond to this state.
Three different states are (re)stored:
* Browse mode (always equal in normal/fullscreen mode)
* View mode normal (windowed) mode
* View mode fullscreen mode

Switch the different tabs on sidebar and check if the last
activated is restored on next restart.

Reviewers: #gwenview, rkflx

Reviewed By: #gwenview, rkflx

Subscribers: rkflx

Differential Revision: https://phabricator.kde.org/D10687
parent 0b1ce57b
......@@ -85,7 +85,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <lib/disabledactionshortcutmonitor.h>
#include <lib/document/documentfactory.h>
#include <lib/documentonlyproxymodel.h>
#include <lib/eventwatcher.h>
#include <lib/gvdebug.h>
#include <lib/gwenviewconfig.h>
#include <lib/mimetypeutils.h>
......@@ -113,11 +112,6 @@ namespace Gwenview
static const int BROWSE_PRELOAD_DELAY = 1000;
static const int VIEW_PRELOAD_DELAY = 100;
static const char* BROWSE_MODE_SIDE_BAR_GROUP = "SideBar-BrowseMode";
static const char* VIEW_MODE_SIDE_BAR_GROUP = "SideBar-ViewMode";
static const char* FULLSCREEN_MODE_SIDE_BAR_GROUP = "SideBar-FullScreenMode";
static const char* SIDE_BAR_IS_VISIBLE_KEY = "IsVisible";
static const char* SESSION_CURRENT_PAGE_KEY = "Page";
static const char* SESSION_URL_KEY = "Url";
......@@ -229,8 +223,6 @@ struct MainWindow::Private
// Left side of splitter
mSideBar = new SideBar(mCentralSplitter);
EventWatcher::install(mSideBar, QList<QEvent::Type>() << QEvent::Show << QEvent::Hide,
q, SLOT(updateToggleSideBarAction()));
// Right side of splitter
mContentWidget = new QWidget(mCentralSplitter);
......@@ -445,8 +437,7 @@ struct MainWindow::Private
action->setToolTip(i18nc("@info:tooltip", "Open the start page"));
mToggleSideBarAction = view->add<KToggleAction>("toggle_sidebar");
connect(mToggleSideBarAction, SIGNAL(toggled(bool)),
q, SLOT(toggleSideBar(bool)));
connect(mToggleSideBarAction, &KToggleAction::triggered, q, &MainWindow::toggleSideBar);
mToggleSideBarAction->setIcon(QIcon::fromTheme("view-sidetree"));
actionCollection->setDefaultShortcut(mToggleSideBarAction, Qt::Key_F4);
mToggleSideBarAction->setText(i18nc("@action", "Sidebar"));
......@@ -684,46 +675,40 @@ struct MainWindow::Private
actionCollection->action("file_print")->setEnabled(isRasterImage);
}
const char* sideBarConfigGroupName() const
bool sideBarVisibility() const
{
const char* name = 0;
switch (mCurrentMainPageId) {
case StartMainPageId:
GV_WARN_AND_RETURN_VALUE(BROWSE_MODE_SIDE_BAR_GROUP, "mCurrentMainPageId == 'StartMainPageId'");
GV_WARN_AND_RETURN_VALUE(false, "Sidebar not implemented on start page");
break;
case BrowseMainPageId:
name = BROWSE_MODE_SIDE_BAR_GROUP;
return GwenviewConfig::sideBarVisibleBrowseMode();
break;
case ViewMainPageId:
name = q->isFullScreen()
? FULLSCREEN_MODE_SIDE_BAR_GROUP
: VIEW_MODE_SIDE_BAR_GROUP;
return q->isFullScreen()
? GwenviewConfig::sideBarVisibleViewModeFullScreen()
: GwenviewConfig::sideBarVisibleViewMode();
break;
}
return name;
}
void loadSideBarConfig()
{
static QMap<const char*, bool> defaultVisibility;
if (defaultVisibility.isEmpty()) {
defaultVisibility[BROWSE_MODE_SIDE_BAR_GROUP] = true;
defaultVisibility[VIEW_MODE_SIDE_BAR_GROUP] = true;
defaultVisibility[FULLSCREEN_MODE_SIDE_BAR_GROUP] = false;
}
const char* name = sideBarConfigGroupName();
KConfigGroup group(KSharedConfig::openConfig(), name);
mSideBar->setVisible(group.readEntry(SIDE_BAR_IS_VISIBLE_KEY, defaultVisibility[name]));
mSideBar->setCurrentPage(GwenviewConfig::sideBarPage());
q->updateToggleSideBarAction();
return false;
}
void saveSideBarConfig() const
void saveSideBarVisibility(const bool visible)
{
KConfigGroup group(KSharedConfig::openConfig(), sideBarConfigGroupName());
group.writeEntry(SIDE_BAR_IS_VISIBLE_KEY, mSideBar->isVisible());
GwenviewConfig::setSideBarPage(mSideBar->currentPage());
switch (mCurrentMainPageId) {
case StartMainPageId:
GV_WARN_AND_RETURN("Sidebar not implemented on start page");
break;
case BrowseMainPageId:
GwenviewConfig::setSideBarVisibleBrowseMode(visible);
break;
case ViewMainPageId:
q->isFullScreen()
? GwenviewConfig::setSideBarVisibleViewModeFullScreen(visible)
: GwenviewConfig::setSideBarVisibleViewMode(visible);
break;
}
}
bool statusBarVisibility() const
......@@ -914,9 +899,6 @@ void MainWindow::startSlideShow()
void MainWindow::setActiveViewModeAction(QAction* action)
{
if (d->mCurrentMainPageId != StartMainPageId) {
d->saveSideBarConfig();
}
if (action == d->mViewAction) {
d->mCurrentMainPageId = ViewMainPageId;
// Switching to view mode
......@@ -939,8 +921,8 @@ void MainWindow::setActiveViewModeAction(QAction* action)
}
setCaption(QString());
}
d->loadSideBarConfig();
d->autoAssignThumbnailProvider();
toggleSideBar(d->sideBarVisibility());
toggleStatusBar(d->statusBarVisibility());
emit viewModeChanged();
......@@ -1021,10 +1003,7 @@ void MainWindow::goUp()
void MainWindow::showStartMainPage()
{
if (d->mCurrentMainPageId != StartMainPageId) {
d->saveSideBarConfig();
d->mCurrentMainPageId = StartMainPageId;
}
d->mCurrentMainPageId = StartMainPageId;
d->setActionsDisabledOnStartMainPageEnabled(false);
d->mSideBar->hide();
......@@ -1102,9 +1081,27 @@ void MainWindow::folderViewUrlChanged(const QUrl &url) {
}
}
void MainWindow::toggleSideBar(bool on)
void MainWindow::toggleSideBar(bool visible)
{
d->mSideBar->setVisible(on);
d->mToggleSideBarAction->setChecked(visible);
d->saveSideBarVisibility(visible);
d->mSideBar->setVisible(visible);
const QString text = QApplication::isRightToLeft()
? QString::fromUtf8(visible ? "▮→" : "▮←")
: QString::fromUtf8(visible ? "▮←" : "▮→");
const QString toolTip = visible
? i18nc("@info:tooltip", "Hide sidebar")
: i18nc("@info:tooltip", "Show sidebar");
const QList<QToolButton*> buttonList {
d->mBrowseMainPage->toggleSideBarButton(),
d->mViewMainPage->toggleSideBarButton()
};
for (auto button : buttonList) {
button->setText(text);
button->setToolTip(toolTip);
}
}
void MainWindow::toggleStatusBar(bool visible)
......@@ -1116,29 +1113,6 @@ void MainWindow::toggleStatusBar(bool visible)
d->mBrowseMainPage->setStatusBarVisible(visible);
}
void MainWindow::updateToggleSideBarAction()
{
SignalBlocker blocker(d->mToggleSideBarAction);
bool visible = d->mSideBar->isVisible();
d->mToggleSideBarAction->setChecked(visible);
QString text;
if (QApplication::isRightToLeft()) {
text = QString::fromUtf8(visible ? "▮→" : "▮←");
} else {
text = QString::fromUtf8(visible ? "▮←" : "▮→");
}
QString toolTip = visible ? i18nc("@info:tooltip", "Hide sidebar") : i18nc("@info:tooltip", "Show sidebar");
QList<QToolButton*> lst;
lst << d->mBrowseMainPage->toggleSideBarButton()
<< d->mViewMainPage->toggleSideBarButton();
Q_FOREACH(QToolButton * button, lst) {
button->setText(text);
button->setToolTip(toolTip);
}
}
void MainWindow::slotPartCompleted()
{
d->updateActions();
......@@ -1294,7 +1268,6 @@ void MainWindow::leaveFullScreen()
void MainWindow::toggleFullScreen(bool checked)
{
setUpdatesEnabled(false);
d->saveSideBarConfig();
if (checked) {
// Save MainWindow config now, this way if we quit while in
// fullscreen, we are sure latest MainWindow changes are remembered.
......@@ -1339,7 +1312,7 @@ void MainWindow::toggleFullScreen(bool checked)
d->mViewMainPage->setFullScreenMode(checked);
d->mSaveBar->setFullScreenMode(checked);
d->loadSideBarConfig();
toggleSideBar(d->sideBarVisibility());
toggleStatusBar(d->statusBarVisibility());
setUpdatesEnabled(true);
......@@ -1443,7 +1416,6 @@ void MainWindow::updateSlideShowAction()
bool MainWindow::queryClose()
{
saveConfig();
d->saveSideBarConfig();
QList<QUrl> list = DocumentFactory::instance()->modifiedDocumentList();
if (list.size() == 0) {
return true;
......@@ -1507,6 +1479,7 @@ void MainWindow::loadConfig()
d->mViewMainPage->loadConfig();
d->mBrowseMainPage->loadConfig();
d->mContextManager->loadConfig();
d->mSideBar->loadConfig();
}
void MainWindow::saveConfig()
......
......@@ -89,7 +89,6 @@ private Q_SLOTS:
void goUp();
void toggleSideBar(bool visible);
void updateToggleSideBarAction();
void slotModifiedDocumentListChanged();
void slotUpdateCaption(const QString& caption);
void slotPartCompleted();
......
......@@ -34,6 +34,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <QFontDatabase>
// Local
#include <lib/gwenviewconfig.h>
#include <lib/signalblocker.h>
namespace Gwenview
{
......@@ -218,6 +220,10 @@ SideBar::SideBar(QWidget* parent)
tabBar()->setFocusPolicy(Qt::NoFocus);
setTabPosition(QTabWidget::South);
setElideMode(Qt::ElideRight);
connect(tabBar(), &QTabBar::currentChanged, [=]() {
GwenviewConfig::setSideBarPage(currentPage());
});
}
SideBar::~SideBar()
......@@ -232,6 +238,8 @@ QSize SideBar::sizeHint() const
void SideBar::addPage(SideBarPage* page)
{
// Prevent emitting currentChanged() while populating pages
SignalBlocker blocker(tabBar());
addTab(page, page->title());
}
......@@ -249,4 +257,9 @@ void SideBar::setCurrentPage(const QString& name)
}
}
void SideBar::loadConfig()
{
setCurrentPage(GwenviewConfig::sideBarPage());
}
} // namespace
......@@ -79,6 +79,8 @@ public:
QString currentPage() const;
void setCurrentPage(const QString& name);
void loadConfig();
QSize sizeHint() const Q_DECL_OVERRIDE;
private:
......
......@@ -17,6 +17,16 @@
<entry name="PreferredMetaInfoKeyList" type="StringList">
<default>General.Name,General.ImageSize,Exif.Photo.ExposureTime,Exif.Photo.Flash</default>
</entry>
<entry name="SideBarVisibleBrowseMode" key="IsVisible BrowseMode" type="Bool">
<default>true</default>
</entry>
<entry name="SideBarVisibleViewMode" key="IsVisible ViewMode" type="Bool">
<default>true</default>
</entry>
<entry name="SideBarVisibleViewModeFullScreen" key="IsVisible ViewMode FullScreen" type="Bool">
<default>false</default>
</entry>
</group>
<group name="General">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment