Commit 9c9f078f authored by Allen Winter's avatar Allen Winter
Browse files

improve discoverability and usabllity of the F9 Hide Sidebar feature

parent c70b6cc3
......@@ -21,6 +21,7 @@
*/
#include "iconsidepane.h"
#include "mainwindow.h"
#include "prefs.h"
using namespace Kontact;
......@@ -98,7 +99,7 @@ public:
void emitReset()
{
//FIXME
//FIXME
//Q_EMIT reset();
}
......@@ -244,7 +245,7 @@ private:
}
Navigator::Navigator(SidePaneBase *parent)
: QListView(parent), mSidePane(parent)
: QListView(parent), mSidePane(parent), mMainWindow(nullptr)
{
setViewport(new QWidget(this));
......@@ -256,6 +257,7 @@ Navigator::Navigator(SidePaneBase *parent)
mShowText = Prefs::self()->sidePaneShowText();
QActionGroup *viewMode = new QActionGroup(this);
connect(viewMode, &QActionGroup::triggered, this, &Navigator::slotActionTriggered);
mShowIconsAction = new QAction(i18nc("@action:inmenu", "Show Icons Only"), this);
mShowIconsAction->setCheckable(true);
......@@ -290,10 +292,6 @@ Navigator::Navigator(SidePaneBase *parent)
i18nc("@info:whatsthis",
"Choose this option if you want the sidebar items to have icons and text."));
QAction *sep = new QAction(this);
sep->setSeparator(true);
connect(viewMode, &QActionGroup::triggered, this, &Navigator::slotActionTriggered);
QActionGroup *iconSize = new QActionGroup(this);
connect(iconSize, &QActionGroup::triggered, this, &Navigator::slotActionTriggered);
......@@ -330,9 +328,24 @@ Navigator::Navigator(SidePaneBase *parent)
i18nc("@info:whatsthis",
"Choose this option if you want the sidebar icons to be extra small."));
mHideSideBarAction = new QAction(i18nc("@action:inmenu", "Hide Sidebar"), this);
mHideSideBarAction->setCheckable(true);
mHideSideBarAction->setChecked(false);
setHelpText(mHideSideBarAction, i18nc("@info:status", "Hide the icon sidebar"));
mHideSideBarAction->setWhatsThis(
i18nc("@info:whatsthis",
"Choose this option if you to hide the icon sidebar. Press F9 to unhide."));
connect(mHideSideBarAction, &QAction::triggered, this, &Navigator::slotHideSideBarTriggered);
QAction *sep = new QAction(this);
sep->setSeparator(true);
QAction *sep2 = new QAction(this);
sep2->setSeparator(true);
QList<QAction *> actionList;
actionList << mShowIconsAction << mShowTextAction << mShowBothAction << sep
<< mBigIconsAction << mNormalIconsAction << mSmallIconsAction;
<< mBigIconsAction << mNormalIconsAction << mSmallIconsAction << sep2
<< mHideSideBarAction;
insertActions(nullptr, actionList);
......@@ -527,6 +540,14 @@ void Navigator::slotActionTriggered(QAction *object)
QTimer::singleShot(0, this, &Navigator::updateNavigatorSize);
}
void Navigator::slotHideSideBarTriggered()
{
if (mainWindow()) {
mainWindow()->showHideSideBar(false);
mHideSideBarAction->setChecked(false);
}
}
void Navigator::updateNavigatorSize()
{
parentWidget()->setMaximumWidth(sizeHint().width());
......@@ -539,6 +560,7 @@ IconSidePane::IconSidePane(KontactInterface::Core *core, QWidget *parent)
mNavigator = new Navigator(this);
layout()->addWidget(mNavigator);
mNavigator->setFocusPolicy(Qt::NoFocus);
mNavigator->setMainWindow(dynamic_cast<MainWindow *>(core));
connect(mNavigator, &Navigator::pluginActivated, this, &IconSidePane::pluginSelected);
}
......@@ -565,4 +587,3 @@ void IconSidePane::resizeEvent(QResizeEvent *event)
}
#include "iconsidepane.moc"
......@@ -39,6 +39,7 @@ namespace Kontact
{
class Model;
class MainWindow;
class Navigator;
class Navigator : public QListView
......@@ -66,6 +67,16 @@ public:
return mShowText;
}
void setMainWindow(MainWindow *mainWindow)
{
mMainWindow = mainWindow;
}
MainWindow *mainWindow()
{
return mMainWindow;
}
QSize sizeHint() const override;
Q_SIGNALS:
......@@ -80,11 +91,13 @@ protected:
private Q_SLOTS:
void slotCurrentChanged(const QModelIndex &current);
void slotActionTriggered(QAction *checked);
void slotHideSideBarTriggered();
void updateNavigatorSize();
private:
void setHelpText(QAction *act, const QString &text);
SidePaneBase *mSidePane;
MainWindow *mMainWindow;
Model *mModel;
int mIconSize;
......@@ -97,6 +110,7 @@ private:
QAction *mBigIconsAction;
QAction *mNormalIconsAction;
QAction *mSmallIconsAction;
QAction *mHideSideBarAction;
};
class IconSidePane : public SidePaneBase
......
......@@ -34,8 +34,8 @@ using namespace Kontact;
#include <KLocalizedString>
#include <QCheckBox>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
extern "C"
{
......@@ -48,10 +48,9 @@ extern "C"
KcmKontact::KcmKontact(QWidget *parent)
: KPrefsModule(Prefs::self(), parent)
{
QBoxLayout *topLayout = new QVBoxLayout(this);
QFormLayout *topLayout = new QFormLayout(this);
QBoxLayout *pluginStartupLayout = new QHBoxLayout();
topLayout->addItem(pluginStartupLayout);
topLayout->addStretch();
KPrefsWidBool *forceStartupPlugin =
addWidBool(Prefs::self()->forceStartupPluginItem(), this);
......@@ -68,6 +67,10 @@ KcmKontact::KcmKontact(QWidget *parent)
connect(forceStartupPlugin->checkBox(), &QAbstractButton::toggled,
selection->comboBox(), &QWidget::setEnabled);
KPrefsWidBool *showSideBar = addWidBool(Prefs::self()->sideBarOpenItem(), this);
topLayout->addWidget(showSideBar->checkBox());
load();
}
......@@ -153,4 +156,3 @@ QList<QWidget *> PluginSelection::widgets() const
const QList<QWidget *> widgets{mPluginCombo};
return widgets;
}
......@@ -20,6 +20,13 @@
<entry type="String" name="ForcedStartupPlugin" hidden="true">
</entry>
<entry type="Bool" name="SideBarOpen">
<default>true</default>
<label>Show the component sidebar:</label>
<tooltip>Show/Hide the icon sidebar</tooltip>
<whatsthis>To save screen real estate you might chose to hide the icon sidebar. Uncheck this box to hide the component sidebar. Note that the F9 key will hide/show the icon sidebar.</whatsthis>
</entry>
<entry type="IntList" name="SidePaneSplitter" hidden="true">
<default>1</default>
</entry>
......
......@@ -145,7 +145,7 @@ int ServiceStarter::startServiceFor(const QString &serviceType,
MainWindow::MainWindow()
: KontactInterface::Core(), mSplitter(nullptr), mCurrentPlugin(nullptr), mAboutDialog(nullptr),
mReallyClose(false)
mReallyClose(false), mSaveSideBarWidth(10)
{
// The ServiceStarter created here will be deleted by the KDbusServiceStarter
// base class, which is a global static.
......@@ -347,15 +347,10 @@ void MainWindow::initWidgets()
setCentralWidget(mTopWidget);
mSplitter = new QSplitter(mTopWidget);
connect(mSplitter, &QSplitter::splitterMoved, this, &MainWindow::slotSplitterMoved);
layout->addWidget(mSplitter);
mSidePane = new IconSidePane(this, mSplitter);
/*
// don't occupy screen estate on load
QList<int> sizes;
sizes << 0;
mSplitter->setSizes(sizes);
*/
connect(mSidePane, SIGNAL(pluginSelected(KontactInterface::Plugin*)), SLOT(selectPlugin(KontactInterface::Plugin*)));
mPartsStack = new QStackedWidget(mSplitter);
......@@ -436,9 +431,15 @@ void MainWindow::setupActions()
actionCollection()->addAction(QStringLiteral("help_introduction"), action);
connect(action, &QAction::triggered, this, &MainWindow::slotShowIntroduction);
//TODO 4.12: add description
QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_F9), this);
connect(shortcut, &QShortcut::activated, this, &MainWindow::slotShowHideSideBar);
mShowHideAction = new QAction(QIcon::fromTheme(QStringLiteral("zoom-fit-width")),
i18nc("@action:inmenu", "Hide/Show the component sidebar"), this);
setHelpText(mShowHideAction, i18nc("@info:status", "Hide/Show the component sidebar"));
mShowHideAction->setWhatsThis(
i18nc("@info:whatsthis",
"Allows you to show or hide the component sidebar as desired."));
mShowHideAction->setShortcut(QKeySequence(Qt::Key_F9));
actionCollection()->addAction(QStringLiteral("hide_show_sidebar"), mShowHideAction);
connect(mShowHideAction, &QAction::triggered, this, &MainWindow::slotShowHideSideBar);
}
bool MainWindow::isPluginLoaded(const KPluginInfo &info)
......@@ -856,12 +857,7 @@ void MainWindow::selectPlugin(const QString &pluginName)
void MainWindow::loadSettings()
{
if (mSplitter) {
// if the preferences do not contain useful values, the side pane part of the splitter
// takes up the full width of the window, so leave the splitter sizing at the widget defaults
QList<int> sizes = Prefs::self()->sidePaneSplitter();
if (sizes.count() == mSplitter->count()) {
mSplitter->setSizes(sizes);
}
showHideSideBar(Prefs::self()->sideBarOpen());
}
// Preload Plugins. This _must_ happen before the default part is loaded
......@@ -1108,16 +1104,54 @@ QVariantHash MainWindow::introductionData()
return data;
}
void MainWindow::slotShowHideSideBar()
void MainWindow::showHideSideBar(bool show)
{
QList<int> sizes = mSplitter->sizes();
if (!sizes.isEmpty()) {
if (sizes.at(0) != 0) {
sizes[0] = 0;
if (show) {
sizes[0] = mSaveSideBarWidth;
} else {
sizes[0] = 10;
mSaveSideBarWidth = qMax(sizes[0], 10);
sizes[0] = 0;
}
mSplitter->setSizes(sizes);
Prefs::self()->setSideBarOpen(show);
}
}
QString MainWindow::showHideSideBarMessage(bool hidden) const
{
if (hidden) {
return i18nc("@info:status",
"Sidebar is hidden. Show the sidebar again using the %1 key.",
mShowHideAction->shortcut().toString());
} else {
return QString();
}
}
void MainWindow::slotShowHideSideBar()
{
QList<int> sizes = mSplitter->sizes();
if (!sizes.isEmpty()) {
bool open = (sizes.at(0) != 0);
showHideSideBar(!open);
if (open) {
statusBar()->showMessage(showHideSideBarMessage(true));
} else {
statusBar()->showMessage(showHideSideBarMessage(false));
}
}
}
void MainWindow::slotSplitterMoved(int pos, int index)
{
if (index == 1) {
if (pos == 0) {
statusBar()->showMessage(showHideSideBarMessage(true));
} else {
statusBar()->showMessage(showHideSideBarMessage(false));
}
}
}
......
......@@ -64,6 +64,7 @@ public:
static bool pluginActionWeightLessThan(const QAction *left, const QAction *right);
static bool pluginWeightLessThan(const KontactInterface::Plugin *left,
const KontactInterface::Plugin *right);
void showHideSideBar(bool show);
public Q_SLOTS:
void selectPlugin(KontactInterface::Plugin *plugin) override;
......@@ -108,6 +109,7 @@ private:
void paintAboutScreen(const QString &templateName, const QVariantHash &data);
static QVariantHash introductionData();
KToolBar *findToolBar(const char *name);
QString showHideSideBarMessage(bool hidden) const;
private Q_SLOTS:
void pluginsChanged();
......@@ -115,6 +117,7 @@ private Q_SLOTS:
void configureShortcuts();
void configureToolbars() override;
void slotShowHideSideBar();
void slotSplitterMoved(int pos, int index);
private:
void setHelpText(QAction *action, const QString &text);
......@@ -142,6 +145,8 @@ private:
AboutDialog *mAboutDialog;
bool mReallyClose;
int mSaveSideBarWidth;
QAction *mShowHideAction;
};
}
......
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