Commit 37327c9b authored by Felix Ernst's avatar Felix Ernst Committed by Elvis Angelaccio
Browse files

Make UrlNavigators in the toolbar the only option

The UrlNavigators will be automatically added to the toolbar. The Sort By
action is removed from the default toolbar to make space.

Remove all options to have UrlNavigators outside the toolbar and remove
those code paths.

Make it so the new NavigatorsWidgetAction contains two UrlNavigators when
in split view mode. Spacing was also added to align these UrlNavigators
with the ViewContainers when enough space is available.

Force the toolbar to be either at the top or bottom of the window.

Set a sane sizeHint for DolphinUrlNavigator. It would be better to do this
in KUrlNavigator in the future.

This commit also contains a changes which should be moved to a separate
merge requests before this gets merged:
- Add an expansion animation when split view is enabled by the user
parent 6151a7ae
......@@ -203,6 +203,7 @@ set(dolphinstatic_SRCS
dolphinmainwindow.cpp
dolphinviewcontainer.cpp
dolphincontextmenu.cpp
dolphinnavigatorswidgetaction.cpp
dolphintabbar.cpp
dolphinplacesmodelsingleton.cpp
dolphinrecenttabsmenu.cpp
......@@ -249,7 +250,6 @@ set(dolphinstatic_SRCS
statusbar/mountpointobservercache.cpp
statusbar/spaceinfoobserver.cpp
statusbar/statusbarspaceinfo.cpp
views/dolphinurlnavigatorwidgetaction.cpp
views/zoomlevelinfo.cpp
dolphindebug.cpp
global.cpp
......
......@@ -31,7 +31,7 @@
#include "views/draganddrophelper.h"
#include "views/viewproperties.h"
#include "views/dolphinnewfilemenuobserver.h"
#include "views/dolphinurlnavigatorwidgetaction.h"
#include "dolphinnavigatorswidgetaction.h"
#include "dolphin_generalsettings.h"
#include <KActionCollection>
......@@ -49,7 +49,6 @@
#include <KJobWidgets>
#include <KLocalizedString>
#include <KMessageBox>
#include <KMessageWidget>
#include <KNS3/KMoreToolsMenuFactory>
#include <KProtocolInfo>
#include <KProtocolManager>
......@@ -107,7 +106,8 @@ DolphinMainWindow::DolphinMainWindow() :
m_placesPanel(nullptr),
m_tearDownFromPlacesRequested(false),
m_backAction(nullptr),
m_forwardAction(nullptr)
m_forwardAction(nullptr),
m_updateHistoryConnection{}
{
Q_INIT_RESOURCE(dolphin);
......@@ -142,7 +142,12 @@ DolphinMainWindow::DolphinMainWindow() :
setAcceptDrops(true);
m_tabWidget = new DolphinTabWidget(this);
auto *navigatorsWidgetAction = new DolphinNavigatorsWidgetAction(this);
navigatorsWidgetAction->setText(i18nc(
"@action:inmenu When split view is enabled there are two otherwise one.",
"Url Navigator(s)"));
actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction);
m_tabWidget = new DolphinTabWidget(navigatorsWidgetAction, this);
m_tabWidget->setObjectName("tabWidget");
connect(m_tabWidget, &DolphinTabWidget::activeViewChanged,
this, &DolphinMainWindow::activeViewChanged);
......@@ -167,6 +172,11 @@ DolphinMainWindow::DolphinMainWindow() :
setupGUI(Keys | Save | Create | ToolBar);
stateChanged(QStringLiteral("new_file"));
toolBar()->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
toolBar()->setFloatable(false);
if (!toolBar()->actions().contains(navigatorsWidgetAction)) {
navigatorsWidgetAction->addToToolbarAndSave(this);
}
QClipboard* clipboard = QApplication::clipboard();
connect(clipboard, &QClipboard::dataChanged,
this, &DolphinMainWindow::updatePasteAction);
......@@ -843,64 +853,6 @@ void DolphinMainWindow::showFilterBar()
m_activeViewContainer->setFilterBarVisible(true);
}
void DolphinMainWindow::toggleLocationInToolbar()
{
// collect needed variables
QAction *locationInToolbarAction = actionCollection()->action(QStringLiteral("location_in_toolbar"));
const bool locationInToolbar = locationInToolbarAction->isChecked();
auto viewContainers = this->viewContainers();
auto urlNavigatorWidgetAction = static_cast<DolphinUrlNavigatorWidgetAction *>
(actionCollection()->action(QStringLiteral("url_navigator")));
const bool isEditable = m_activeViewContainer->urlNavigator()->isUrlEditable();
const QLineEdit *lineEdit = m_activeViewContainer->urlNavigator()->editor()->lineEdit();
const bool hasFocus = lineEdit->hasFocus();
const int cursorPosition = lineEdit->cursorPosition();
const int selectionStart = lineEdit->selectionStart();
const int selectionLength = lineEdit->selectionLength();
if (locationInToolbar && !toolBar()->actions().contains(urlNavigatorWidgetAction)) {
// There is no UrlNavigator on the toolbar. Try to fix it. Otherwise show an error.
if (!urlNavigatorWidgetAction->addToToolbarAndSave(this)) {
QAction *configureToolbars = actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars));
KMessageWidget *messageWidget = m_activeViewContainer->showMessage(
xi18nc("@info 2 is the visible text on a button just below the message",
"The location could not be moved onto the toolbar because there is currently "
"no \"%1\" item on the toolbar. Select <interface>%2</interface> and add the "
"\"%1\" item. Then this will work.", urlNavigatorWidgetAction->iconText(),
configureToolbars->iconText()), DolphinViewContainer::Information);
messageWidget->addAction(configureToolbars);
messageWidget->addAction(locationInToolbarAction);
locationInToolbarAction->setChecked(false);
return;
}
}
// do the switching
GeneralSettings::setLocationInToolbar(locationInToolbar);
if (locationInToolbar) {
for (const auto viewContainer : viewContainers) {
viewContainer->disconnectUrlNavigator();
}
m_activeViewContainer->connectUrlNavigator(urlNavigatorWidgetAction->urlNavigator());
} else {
m_activeViewContainer->disconnectUrlNavigator();
for (const auto viewContainer : viewContainers) {
viewContainer->connectToInternalUrlNavigator();
}
}
urlNavigatorWidgetAction->setUrlNavigatorVisible(locationInToolbar);
m_activeViewContainer->urlNavigator()->setUrlEditable(isEditable);
if (hasFocus) { // the rest of this method is unneeded perfectionism
m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setText(lineEdit->text());
m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setFocus();
m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setCursorPosition(cursorPosition);
if (selectionStart != -1) {
m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setSelection(selectionStart, selectionLength);
}
}
}
void DolphinMainWindow::toggleEditLocation()
{
clearStatusBar();
......@@ -1314,9 +1266,11 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
// view and url navigator) and main window.
oldViewContainer->disconnect(this);
oldViewContainer->view()->disconnect(this);
oldViewContainer->urlNavigator()->disconnect(this);
if (GeneralSettings::locationInToolbar()) {
oldViewContainer->disconnectUrlNavigator();
auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
(actionCollection()->action(QStringLiteral("url_navigators")));
navigators->primaryUrlNavigator()->disconnect(this);
if (auto secondaryUrlNavigator = navigators->secondaryUrlNavigator()) {
secondaryUrlNavigator->disconnect(this);
}
// except the requestItemInfo so that on hover the information panel can still be updated
......@@ -1324,10 +1278,6 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
this, &DolphinMainWindow::requestItemInfo);
}
if (GeneralSettings::locationInToolbar()) {
viewContainer->connectUrlNavigator(static_cast<DolphinUrlNavigatorWidgetAction *>
(actionCollection()->action(QStringLiteral("url_navigator")))->urlNavigator());
}
connectViewSignals(viewContainer);
m_actionHandler->setCurrentView(viewContainer->view());
......@@ -1559,16 +1509,6 @@ void DolphinMainWindow::setupActions()
stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
KToggleAction* locationInToolbar = actionCollection()->add<KToggleAction>(QStringLiteral("location_in_toolbar"));
locationInToolbar->setText(i18nc("@action:inmenu Navigation Bar", "Location in Toolbar"));
locationInToolbar->setWhatsThis(xi18nc("@info:whatsthis",
"This toggles between showing the <emphasis>path</emphasis> in the "
"<emphasis>Location Bar</emphasis> and in the <emphasis>Toolbar</emphasis>."));
actionCollection()->setDefaultShortcut(locationInToolbar, Qt::Key_F12);
locationInToolbar->setChecked(GeneralSettings::locationInToolbar());
connect(locationInToolbar, &KToggleAction::triggered, this, &DolphinMainWindow::toggleLocationInToolbar);
DolphinUrlNavigator::addToContextMenu(locationInToolbar);
KToggleAction* editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
......@@ -1770,12 +1710,6 @@ void DolphinMainWindow::setupActions()
connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
auto *urlNavigatorWidgetAction = new DolphinUrlNavigatorWidgetAction(this);
urlNavigatorWidgetAction->setText(i18nc("@action:inmenu auto-hide: "
"Depending on the settings this Widget is blank/invisible.",
"Url Navigator (auto-hide)"));
actionCollection()->addAction(QStringLiteral("url_navigator"), urlNavigatorWidgetAction);
// for context menu
QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
showTarget->setText(i18nc("@action:inmenu", "Show Target"));
......@@ -2107,10 +2041,6 @@ void DolphinMainWindow::updateViewActions()
showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
updateSplitAction();
QAction* editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
}
void DolphinMainWindow::updateGoActions()
......@@ -2246,15 +2176,24 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
connect(view, &DolphinView::goUpRequested,
this, &DolphinMainWindow::goUp);
const KUrlNavigator* navigator = container->urlNavigator();
auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
(actionCollection()->action(QStringLiteral("url_navigators")));
KUrlNavigator *navigator = m_tabWidget->currentTabPage()->primaryViewActive() ?
navigators->primaryUrlNavigator() :
navigators->secondaryUrlNavigator();
connect(navigator, &KUrlNavigator::urlChanged,
this, &DolphinMainWindow::changeUrl);
QAction* editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
editableLocactionAction->setChecked(navigator->isUrlEditable());
connect(navigator, &KUrlNavigator::editableStateChanged,
this, &DolphinMainWindow::slotEditableStateChanged);
connect(navigator, &KUrlNavigator::tabRequested,
this, &DolphinMainWindow::openNewTabAfterLastTab);
connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged,
disconnect(m_updateHistoryConnection);
m_updateHistoryConnection = connect(
container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged,
this, &DolphinMainWindow::updateHistory);
}
......
......@@ -69,16 +69,9 @@ public:
/**
* Returns the active view containers of all tabs.
* @see activeViewContainer()
* Use viewContainers() to also include the inactive ones.
*/
QVector<DolphinViewContainer *> activeViewContainers() const;
/**
* Returns all view containers.
*/
QVector<DolphinViewContainer *> viewContainers() const;
/**
* Opens each directory in \p dirs in a separate tab. If \a splitView is set,
* 2 directories are collected within one tab.
......@@ -312,12 +305,6 @@ private slots:
void showFilterBar();
/**
* Toggle between either using an UrlNavigator in the toolbar or the
* ones in the location bar for navigating.
*/
void toggleLocationInToolbar();
/**
* Toggles between edit and browse mode of the navigation bar.
*/
......@@ -662,6 +649,9 @@ private:
KToolBarPopupAction* m_backAction;
KToolBarPopupAction* m_forwardAction;
/** Makes sure that only one object is ever connected to the history. */
QMetaObject::Connection m_updateHistoryConnection;
QMenu m_searchTools;
};
......
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2020 Felix Ernst <fe.a.ernst@gmail.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "dolphinnavigatorswidgetaction.h"
#include "trash/dolphintrash.h"
#include <KLocalizedString>
#include <KXMLGUIFactory>
#include <KXmlGuiWindow>
#include <QDomDocument>
#include <QHBoxLayout>
#include <QPushButton>
#include <QSplitter>
DolphinNavigatorsWidgetAction::DolphinNavigatorsWidgetAction(QWidget *parent) :
QWidgetAction{parent},
m_splitter{new QSplitter(Qt::Horizontal)},
m_adjustSpacingTimer{new QTimer(this)},
m_globalXOfPrimary{-1},
m_widthOfPrimary{-1},
m_globalXOfSecondary{-1},
m_widthOfSecondary{-1}
{
setText(i18nc("@action:inmenu", "Url navigator"));
m_splitter->setChildrenCollapsible(false);
setDefaultWidget(m_splitter.get());
m_splitter->addWidget(createNavigatorWidget(Primary));
m_adjustSpacingTimer->setInterval(100);
m_adjustSpacingTimer->setSingleShot(true);
connect(m_adjustSpacingTimer.get(), &QTimer::timeout,
this, &DolphinNavigatorsWidgetAction::adjustSpacing);
}
bool DolphinNavigatorsWidgetAction::addToToolbarAndSave(KXmlGuiWindow *mainWindow)
{
const QString rawXml = KXMLGUIFactory::readConfigFile(mainWindow->xmlFile());
QDomDocument domDocument;
if (rawXml.isEmpty() || !domDocument.setContent(rawXml) || domDocument.isNull()) {
return false;
}
QDomNode toolbar = domDocument.elementsByTagName(QStringLiteral("ToolBar")).at(0);
if (toolbar.isNull()) {
return false;
}
QDomElement urlNavigatorElement = domDocument.createElement(QStringLiteral("Action"));
urlNavigatorElement.setAttribute(QStringLiteral("name"), QStringLiteral("url_navigators"));
QDomNode position = toolbar.lastChildElement(QStringLiteral("Spacer"));
if (position.isNull()) {
toolbar.appendChild(urlNavigatorElement);
} else {
toolbar.replaceChild(urlNavigatorElement, position);
}
KXMLGUIFactory::saveConfigFile(domDocument, mainWindow->xmlFile());
mainWindow->reloadXML();
mainWindow->createGUI();
return true;
}
void DolphinNavigatorsWidgetAction::createSecondaryUrlNavigator()
{
Q_ASSERT(m_splitter->count() == 1);
m_splitter->addWidget(createNavigatorWidget(Secondary));
Q_ASSERT(m_splitter->count() == 2);
}
void DolphinNavigatorsWidgetAction::followViewContainerGeometry(
int globalXOfPrimary, int widthOfPrimary)
{
followViewContainersGeometry(globalXOfPrimary, widthOfPrimary, -1, -1);
}
void DolphinNavigatorsWidgetAction::followViewContainersGeometry(
int globalXOfPrimary, int widthOfPrimary,
int globalXOfSecondary, int widthOfSecondary)
{
m_globalXOfSplitter = m_splitter->mapToGlobal(QPoint(0,0)).x();
m_globalXOfPrimary = globalXOfPrimary;
m_widthOfPrimary = widthOfPrimary;
m_globalXOfSecondary = globalXOfSecondary;
m_widthOfSecondary = widthOfSecondary;
adjustSpacing();
}
DolphinUrlNavigator* DolphinNavigatorsWidgetAction::primaryUrlNavigator() const
{
Q_ASSERT(m_splitter);
return static_cast<DolphinUrlNavigator *>(m_splitter->widget(0)->findChild<KUrlNavigator *>());
}
DolphinUrlNavigator* DolphinNavigatorsWidgetAction::secondaryUrlNavigator() const
{
Q_ASSERT(m_splitter);
if (m_splitter->count() < 2) {
return nullptr;
}
return static_cast<DolphinUrlNavigator *>(m_splitter->widget(1)->findChild<KUrlNavigator *>());
}
void DolphinNavigatorsWidgetAction::setSecondaryNavigatorVisible(bool visible)
{
if (visible) {
Q_ASSERT(m_splitter->count() == 2);
m_splitter->widget(1)->setVisible(true);
} else if (m_splitter->count() > 1) {
m_splitter->widget(1)->setVisible(false);
// Fix an unlikely event of wrong trash button visibility.
emptyTrashButton(Secondary)->setVisible(false);
}
}
void DolphinNavigatorsWidgetAction::adjustSpacing()
{
const int widthOfSplitterPrimary = m_globalXOfPrimary + m_widthOfPrimary - m_globalXOfSplitter;
const QList<int> splitterSizes = {widthOfSplitterPrimary,
m_splitter->width() - widthOfSplitterPrimary};
m_splitter->setSizes(splitterSizes);
// primary side of m_splitter
int leadingSpacing = m_globalXOfPrimary - m_globalXOfSplitter;
if (leadingSpacing < 0) {
leadingSpacing = 0;
}
int trailingSpacing = (m_globalXOfSplitter + m_splitter->width())
- (m_globalXOfPrimary + m_widthOfPrimary);
if (trailingSpacing < 0 || emptyTrashButton(Primary)->isVisible()) {
trailingSpacing = 0;
}
const int widthLeftForUrlNavigator = m_splitter->widget(0)->width() - leadingSpacing - trailingSpacing;
const int widthNeededForUrlNavigator = primaryUrlNavigator()->sizeHint().width() - widthLeftForUrlNavigator;
if (widthNeededForUrlNavigator > 0) {
trailingSpacing -= widthNeededForUrlNavigator;
if (trailingSpacing < 0) {
leadingSpacing += trailingSpacing;
trailingSpacing = 0;
}
if (leadingSpacing < 0) {
leadingSpacing = 0;
}
}
spacing(Primary, Leading)->setMinimumWidth(leadingSpacing);
spacing(Primary, Trailing)->setFixedWidth(trailingSpacing);
// secondary side of m_splitter
if (m_globalXOfSecondary == -1) {
Q_ASSERT(m_widthOfSecondary == -1);
return;
}
spacing(Primary, Trailing)->setFixedWidth(0);
trailingSpacing = (m_globalXOfSplitter + m_splitter->width())
- (m_globalXOfSecondary + m_widthOfSecondary);
if (trailingSpacing < 0 || emptyTrashButton(Secondary)->isVisible()) {
trailingSpacing = 0;
} else {
const int widthLeftForUrlNavigator2 = m_splitter->widget(1)->width() - trailingSpacing;
const int widthNeededForUrlNavigator2 = secondaryUrlNavigator()->sizeHint().width() - widthLeftForUrlNavigator2;
if (widthNeededForUrlNavigator2 > 0) {
trailingSpacing -= widthNeededForUrlNavigator2;
if (trailingSpacing < 0) {
trailingSpacing = 0;
}
}
}
spacing(Secondary, Trailing)->setMinimumWidth(trailingSpacing);
}
QWidget *DolphinNavigatorsWidgetAction::createNavigatorWidget(Side side) const
{
auto navigatorWidget = new QWidget(m_splitter.get());
auto layout = new QHBoxLayout{navigatorWidget};
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
if (side == Primary) {
auto leadingSpacing = new QWidget{navigatorWidget};
layout->addWidget(leadingSpacing);
}
auto urlNavigator = new DolphinUrlNavigator(navigatorWidget);
layout->addWidget(urlNavigator);
auto emptyTrashButton = newEmptyTrashButton(urlNavigator, navigatorWidget);
layout->addWidget(emptyTrashButton);
connect(urlNavigator, &KUrlNavigator::urlChanged, [this]() {
// We have to wait for DolphinUrlNavigator::sizeHint() to update which
// happens a little bit later than when urlChanged is emitted.
this->m_adjustSpacingTimer->start();
});
auto trailingSpacing = new QWidget{navigatorWidget};
layout->addWidget(trailingSpacing);
return navigatorWidget;
}
QPushButton * DolphinNavigatorsWidgetAction::emptyTrashButton(DolphinNavigatorsWidgetAction::Side side)
{
int sideIndex = (side == Primary ? 0 : 1);
if (side == Primary) {
return static_cast<QPushButton *>(m_splitter->widget(sideIndex)->layout()->itemAt(2)->widget());
}
return static_cast<QPushButton *>(m_splitter->widget(sideIndex)->layout()->itemAt(1)->widget());
}
QPushButton *DolphinNavigatorsWidgetAction::newEmptyTrashButton(const DolphinUrlNavigator *urlNavigator, QWidget *parent) const
{
auto emptyTrashButton = new QPushButton(QIcon::fromTheme(QStringLiteral("user-trash")),
i18nc("@action:button", "Empty Trash"), parent);
emptyTrashButton->setFlat(true);
connect(emptyTrashButton, &QPushButton::clicked,
this, [parent]() { Trash::empty(parent); });
connect(&Trash::instance(), &Trash::emptinessChanged,
emptyTrashButton, &QPushButton::setDisabled);
emptyTrashButton->hide();
connect(urlNavigator, &KUrlNavigator::urlChanged, [emptyTrashButton, urlNavigator]() {
emptyTrashButton->setVisible(urlNavigator->locationUrl().scheme() == QLatin1String("trash"));
});
emptyTrashButton->setDisabled(Trash::isEmpty());
return emptyTrashButton;
}
QWidget *DolphinNavigatorsWidgetAction::spacing(Side side, Position position) const
{
int sideIndex = (side == Primary ? 0 : 1);
if (position == Leading) {
Q_ASSERT(side == Primary); // The secondary side of the splitter has no leading spacing.
return m_splitter->widget(sideIndex)->layout()->itemAt(0)->widget();
}
if (side == Primary) {
return m_splitter->widget(sideIndex)->layout()->itemAt(3)->widget();
}
return m_splitter->widget(sideIndex)->layout()->itemAt(2)->widget();
}
/*
This file is part of the KDE project
SPDX-FileCopyrightText: 2020 Felix Ernst <fe.a.ernst@gmail.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef DOLPHINNAVIGATORSWIDGETACTION_H
#define DOLPHINNAVIGATORSWIDGETACTION_H
#include "dolphinurlnavigator.h"
#include <QSplitter>
#include <QTimer>
#include <QWidgetAction>
#include <memory>
class KXmlGuiWindow;
class QPushButton;
/**
* @brief QWidgetAction that allows to use DolphinUrlNavigators in a toolbar.
*
* This class is mainly a container that manages up to two DolphinUrlNavigator objects so they
* can be added to a toolbar. It also deals with alignment.
*
* The structure of the defaultWidget() of this QWidgetAction is as follows:
* - A QSplitter manages up to two sides which each correspond to one DolphinViewContainer.
* The secondary side only exists for split view and is created by
* createSecondaryUrlNavigator() when necessary.
* - Each side is a QWidget which I call NavigatorWidget with a QHBoxLayout.
* - Each NavigatorWidget consists an UrlNavigator, an emptyTrashButton and spacing.
* - Only the primary navigatorWidget has leading spacing. Both have trailing spacing.
* The spacing is there to align the UrlNavigator with its DolphinViewContainer.
*/
class DolphinNavigatorsWidgetAction : public QWidgetAction
{
Q_OBJECT
/**
* In Left-to-right languages the Primary side will be the left one.
*/
enum Side {
Primary,
Secondary
};
public:
DolphinNavigatorsWidgetAction(QWidget *parent = nullptr);
/**
* Adds this action to the mainWindow's toolbar and saves the change
* in the users ui configuration file.
* @return true if successful. Otherwise false.
*/
bool addToToolbarAndSave(KXmlGuiWindow *mainWindow);
/**
* Different to the primary UrlNavigator, the secondary UrlNavigator is only created on-demand.
*/
void createSecondaryUrlNavigator();
/**
* Notify the primary UrlNavigator of changes in geometry of the ViewContainer it tries to be
* aligned with. Only call this method if there is no secondary UrlNavigator.
*/
void followViewContainerGeometry(int globalXOfPrimary, int widthOfPrimary);
/**
* Notify this widget of changes in geometry of the ViewContainers it tries to be
* aligned with.
*/
void followViewContainersGeometry(int globalXOfPrimary, int widthOfPrimary,
int globalXOfSecondary, int widthOfSecondary);
/**
* @return the primary UrlNavigator.
*/
DolphinUrlNavigator *primaryUrlNavigator() const;
/**
* @return the secondary UrlNavigator and nullptr if it doesn't exist.
*/
DolphinUrlNavigator *secondaryUrlNavigator() const;
/**
* Change the visibility of the secondary UrlNavigator including spacing.
* @param visible Setting this to false will completely hide the secondary side of this
* WidgetAction's QSplitter making the QSplitter effectively disappear.
*/
void setSecondaryNavigatorVisible(bool visible);
protected:
/**
* Adjusts the width of the spacings used to align the UrlNavigators with ViewContainers.
* This can only work nicely if up-to-date geometry of ViewContainers is cached so
* followViewContainersGeometry() has to have been called at least once before.
*/