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);
createControlButton();
}
+ updateAllowedToolbarAreas();
+
// enable middle-click on back/forward/up to open in a new tab
auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotToolBarActionMiddleClicked);
}
}
+void DolphinMainWindow::updateAllowedToolbarAreas()
+{
+ auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
+ (actionCollection()->action(QStringLiteral("url_navigators")));
+ if (toolBar()->actions().contains(navigators)) {
+ toolBar()->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
+ if (toolBarArea(toolBar()) == Qt::LeftToolBarArea ||
+ toolBarArea(toolBar()) == Qt::RightToolBarArea) {
+ addToolBar(Qt::TopToolBarArea, toolBar());
+ }
+ } else {
+ toolBar()->setAllowedAreas(Qt::AllToolBarAreas);
+ }
+}
+
bool DolphinMainWindow::isKompareInstalled() const
{
static bool initialized = false;
return false;
}
+void DolphinMainWindow::saveNewToolbarConfig()
+{
+ KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
+ // because the rest of this method decides things
+ // based on the new config.
+ auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
+ (actionCollection()->action(QStringLiteral("url_navigators")));
+ if (!toolBar()->actions().contains(navigators)) {
+ m_tabWidget->currentTabPage()->insertNavigatorsWidget(navigators);
+ }
+ updateAllowedToolbarAreas();
+}
+
void DolphinMainWindow::focusTerminalPanel()
{
if (m_terminalPanel->isVisible()) {
/** Handles QWhatsThisClickedEvent and passes all others on. */
bool eventFilter(QObject*, QEvent*) override;
+protected slots:
+ /**
+ * Calls the base method KXmlGuiWindow::saveNewToolbarConfig().
+ * Is also used to set toolbar constraints and UrlNavigator position
+ * based on the newly changed toolbar configuration.
+ */
+ void saveNewToolbarConfig() override;
+
private slots:
/**
* Refreshes the views of the main window by recreating them according to
*/
void updateSplitAction();
+ /**
+ * Sets the window sides the toolbar may be moved to based on toolbar contents.
+ */
+ void updateAllowedToolbarAreas();
+
bool isKompareInstalled() const;
/**
#include <QHBoxLayout>
#include <QPushButton>
#include <QSplitter>
+#include <QToolBar>
#include <limits>
setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
m_splitter->setChildrenCollapsible(false);
- setDefaultWidget(m_splitter.get());
m_splitter->addWidget(createNavigatorWidget(Primary));
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.firstChildElement(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);
adjustSpacing();
}
+bool DolphinNavigatorsWidgetAction::isInToolbar() const
+{
+ return qobject_cast<QToolBar *>(m_splitter->parentWidget());
+}
+
DolphinUrlNavigator* DolphinNavigatorsWidgetAction::primaryUrlNavigator() const
{
Q_ASSERT(m_splitter);
updateText();
}
+QWidget *DolphinNavigatorsWidgetAction::createWidget(QWidget *parent)
+{
+ QWidget *oldParent = m_splitter->parentWidget();
+ if (oldParent && oldParent->layout()) {
+ oldParent->layout()->removeWidget(m_splitter.get());
+ QGridLayout *layout = qobject_cast<QGridLayout *>(oldParent->layout());
+ if (qobject_cast<QToolBar *>(parent) && layout) {
+ // in DolphinTabPage::insertNavigatorsWidget the minimumHeight of this row was
+ // set to fit the m_splitter. Since we are now removing it again, the
+ // minimumHeight can be reset to 0.
+ layout->setRowMinimumHeight(0, 0);
+ }
+ }
+ m_splitter->setParent(parent);
+ return m_splitter.get();
+}
+
+void DolphinNavigatorsWidgetAction::deleteWidget(QWidget *widget)
+{
+ Q_UNUSED(widget)
+ m_splitter->setParent(nullptr);
+}
+
void DolphinNavigatorsWidgetAction::adjustSpacing()
{
Q_ASSERT(m_globalXOfSplitter != INT_MIN);
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);
-
/**
* The secondary UrlNavigator is only created on-demand. Such an action is not necessary
* for the primary UrlNavigator which is created preemptively.
void followViewContainersGeometry(int globalXOfPrimary, int widthOfPrimary,
int globalXOfSecondary, int widthOfSecondary);
+ bool isInToolbar() const;
+
/**
* @return the primary UrlNavigator.
*/
*/
void setSecondaryNavigatorVisible(bool visible);
+protected:
+ /**
+ * There should always ever be one navigatorsWidget for this action so
+ * this method always returns the same widget and reparents it.
+ * You normally don't have to use this method directly because
+ * QWidgetAction::requestWidget() is used to obtain the navigatorsWidget
+ * and to steal it from whereever it was prior.
+ * @param parent the new parent of the navigatorsWidget.
+ */
+ QWidget *createWidget(QWidget *parent) override;
+
+ /** @see QWidgetAction::deleteWidget() */
+ void deleteWidget(QWidget *widget) override;
+
private:
/**
* Adjusts the width of the spacings used to align the UrlNavigators with ViewContainers.
#include "dolphinviewcontainer.h"
#include <QSplitter>
-#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QWidgetAction>
DolphinTabPage::DolphinTabPage(const QUrl &primaryUrl, const QUrl &secondaryUrl, QWidget* parent) :
QWidget(parent),
m_splitViewEnabled(false),
m_active(true)
{
- QVBoxLayout* layout = new QVBoxLayout(this);
+ QGridLayout *layout = new QGridLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
m_splitter->setChildrenCollapsible(false);
connect(m_splitter, &QSplitter::splitterMoved,
this, &DolphinTabPage::splitterMoved);
- layout->addWidget(m_splitter);
+ layout->addWidget(m_splitter, 1, 0);
+ layout->setRowStretch(1, 1);
// Create a new primary view
m_primaryViewContainer = createViewContainer(primaryUrl);
void DolphinTabPage::connectNavigators(DolphinNavigatorsWidgetAction *navigatorsWidget)
{
+ insertNavigatorsWidget(navigatorsWidget);
m_navigatorsWidget = navigatorsWidget;
auto primaryNavigator = navigatorsWidget->primaryUrlNavigator();
m_primaryViewContainer->connectUrlNavigator(primaryNavigator);
return QWidget::eventFilter(watched, event);
}
+void DolphinTabPage::insertNavigatorsWidget(DolphinNavigatorsWidgetAction* navigatorsWidget)
+{
+ QGridLayout *gridLayout = static_cast<QGridLayout *>(layout());
+ if (navigatorsWidget->isInToolbar()) {
+ gridLayout->setRowMinimumHeight(0, 0);
+ } else {
+ // We set a row minimum height, so the height does not visibly change whenever
+ // navigatorsWidget is inserted which happens every time the current tab is changed.
+ gridLayout->setRowMinimumHeight(0, navigatorsWidget->primaryUrlNavigator()->height());
+ gridLayout->addWidget(navigatorsWidget->requestWidget(this), 0, 0);
+ }
+}
+
+
void DolphinTabPage::resizeNavigators() const
{
if (!m_splitViewEnabled) {
*/
bool eventFilter(QObject *watched, QEvent *event) override;
+ void insertNavigatorsWidget(DolphinNavigatorsWidgetAction *navigatorsWidget);
+
/**
* Notify the connected DolphinNavigatorsWidgetAction of geometry changes which it
* needs for visual alignment.
#include <KCrash>
#include <KDBusService>
#include <KLocalizedString>
-#include <KToolBar>
#include <Kdelibs4ConfigMigrator>
#include <KConfigGui>
}
}
}
- Qt::ToolBarArea area = mainWindow->toolBarArea(mainWindow->toolBar());
- if (area != Qt::TopToolBarArea && area != Qt::BottomToolBarArea) {
- // Migrate users with disabled tool bar positions.
- // Remove this a few years from now (2020).
- mainWindow->addToolBar(Qt::TopToolBarArea, mainWindow->toolBar());
- }
#ifdef HAVE_KUSERFEEDBACK
auto feedbackProvider = DolphinFeedbackProvider::instance();