┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/dolphinurlnavigator.cpp
diff options
context:
space:
mode:
authorElvis Angelaccio <[email protected]>2020-11-10 00:05:27 +0100
committerElvis Angelaccio <[email protected]>2020-11-10 00:05:27 +0100
commit6719072837f30c1822768da65e6ea222e987e32f (patch)
treeb61a3c588561946e9d462e23379d44fbdeed185b /src/dolphinurlnavigator.cpp
parente5d137b81debbbfe51c18d16d361fd28a3448416 (diff)
parent63f4981fe01d88b2ef1b27e0577d7f5d4c8cc485 (diff)
Merge branch 'release/20.12'
Diffstat (limited to 'src/dolphinurlnavigator.cpp')
-rw-r--r--src/dolphinurlnavigator.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/dolphinurlnavigator.cpp b/src/dolphinurlnavigator.cpp
new file mode 100644
index 000000000..1dfe5420f
--- /dev/null
+++ b/src/dolphinurlnavigator.cpp
@@ -0,0 +1,109 @@
+/*
+ This file is part of the KDE project
+ SPDX-FileCopyrightText: 2020 Felix Ernst <[email protected]>
+
+ SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
+*/
+
+#include "dolphinurlnavigator.h"
+
+#include "dolphin_generalsettings.h"
+#include "dolphinplacesmodelsingleton.h"
+#include "dolphinurlnavigatorscontroller.h"
+#include "global.h"
+
+#include <KUrlComboBox>
+#include <KLocalizedString>
+
+#include <QAbstractButton>
+#include <QLayout>
+#include <QLineEdit>
+
+DolphinUrlNavigator::DolphinUrlNavigator(QWidget *parent) :
+ DolphinUrlNavigator(QUrl(), parent)
+{}
+
+DolphinUrlNavigator::DolphinUrlNavigator(const QUrl &url, QWidget *parent) :
+ KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url, parent)
+{
+ const GeneralSettings* settings = GeneralSettings::self();
+ setUrlEditable(settings->editableUrl());
+ setShowFullPath(settings->showFullPath());
+ setHomeUrl(Dolphin::homeUrl());
+ setPlacesSelectorVisible(DolphinUrlNavigatorsController::placesSelectorVisible());
+ editor()->setCompletionMode(KCompletion::CompletionMode(settings->urlCompletionMode()));
+ setWhatsThis(xi18nc("@info:whatsthis location bar",
+ "<para>This describes the location of the files and folders "
+ "displayed below.</para><para>The name of the currently viewed "
+ "folder can be read at the very right. To the left of it is the "
+ "name of the folder that contains it. The whole line is called "
+ "the <emphasis>path</emphasis> to the current location because "
+ "following these folders from left to right leads here.</para>"
+ "<para>This interactive path "
+ "is more powerful than one would expect. To learn more "
+ "about the basic and advanced features of the location bar "
+ "<link url='help:/dolphin/location-bar.html'>click here</link>. "
+ "This will open the dedicated page in the Handbook.</para>"));
+
+ DolphinUrlNavigatorsController::registerDolphinUrlNavigator(this);
+
+ connect(this, &KUrlNavigator::returnPressed,
+ this, &DolphinUrlNavigator::slotReturnPressed);
+}
+
+DolphinUrlNavigator::~DolphinUrlNavigator()
+{
+ DolphinUrlNavigatorsController::unregisterDolphinUrlNavigator(this);
+}
+
+QSize DolphinUrlNavigator::sizeHint() const
+{
+ if (isUrlEditable()) {
+ return editor()->lineEdit()->sizeHint();
+ }
+ int widthHint = 0;
+ for (int i = 0; i < layout()->count(); ++i) {
+ QWidget *widget = layout()->itemAt(i)->widget();
+ const QAbstractButton *button = qobject_cast<QAbstractButton *>(widget);
+ if (button && button->icon().isNull()) {
+ widthHint += widget->minimumSizeHint().width();
+ }
+ }
+ return QSize(widthHint, KUrlNavigator::sizeHint().height());
+}
+
+std::unique_ptr<DolphinUrlNavigator::VisualState> DolphinUrlNavigator::visualState() const
+{
+ std::unique_ptr<VisualState> visualState{new VisualState};
+ visualState->isUrlEditable = (isUrlEditable());
+ const QLineEdit *lineEdit = editor()->lineEdit();
+ visualState->hasFocus = lineEdit->hasFocus();
+ visualState->text = lineEdit->text();
+ visualState->cursorPosition = lineEdit->cursorPosition();
+ visualState->selectionStart = lineEdit->selectionStart();
+ visualState->selectionLength = lineEdit->selectionLength();
+ return visualState;
+}
+
+void DolphinUrlNavigator::setVisualState(const VisualState& visualState)
+{
+ setUrlEditable(visualState.isUrlEditable);
+ if (!visualState.isUrlEditable) {
+ return;
+ }
+ editor()->lineEdit()->setText(visualState.text);
+ if (visualState.hasFocus) {
+ editor()->lineEdit()->setFocus();
+ editor()->lineEdit()->setCursorPosition(visualState.cursorPosition);
+ if (visualState.selectionStart != -1) {
+ editor()->lineEdit()->setSelection(visualState.selectionStart, visualState.selectionLength);
+ }
+ }
+}
+
+void DolphinUrlNavigator::slotReturnPressed()
+{
+ if (!GeneralSettings::editableUrl()) {
+ setUrlEditable(false);
+ }
+}