X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/b14f98de19b97bcf8ca967f635c6df39963df2b0..64f38f89a63c7afe5fbd5181f9de65c4b3be48b7:/src/dolphinurlnavigator.cpp diff --git a/src/dolphinurlnavigator.cpp b/src/dolphinurlnavigator.cpp index d8d325bb4..5c32538b0 100644 --- a/src/dolphinurlnavigator.cpp +++ b/src/dolphinurlnavigator.cpp @@ -1,6 +1,6 @@ /* This file is part of the KDE project - SPDX-FileCopyrightText: 2020 Felix Ernst + SPDX-FileCopyrightText: 2020 Felix Ernst SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL */ @@ -12,43 +12,51 @@ #include "dolphinurlnavigatorscontroller.h" #include "global.h" -#include #include +#include #include +#include +#include #include #include -DolphinUrlNavigator::DolphinUrlNavigator(QWidget *parent) : - DolphinUrlNavigator(QUrl(), parent) -{} +DolphinUrlNavigator::DolphinUrlNavigator(QWidget *parent) + : DolphinUrlNavigator(QUrl(), parent) +{ +} -DolphinUrlNavigator::DolphinUrlNavigator(const QUrl &url, QWidget *parent) : - KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url, parent) +DolphinUrlNavigator::DolphinUrlNavigator(const QUrl &url, QWidget *parent) + : KUrlNavigator(DolphinPlacesModelSingleton::instance().placesModel(), url, parent) { - const GeneralSettings* settings = GeneralSettings::self(); + 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", - "This describes the location of the files and folders " - "displayed below.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 path to the current location because " - "following these folders from left to right leads here." - "This interactive path " - "is more powerful than one would expect. To learn more " - "about the basic and advanced features of the location bar " - "click here. " - "This will open the dedicated page in the Handbook.")); + "This describes the location of the files and folders " + "displayed below.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 path to the current location because " + "following these folders from left to right leads here." + "This interactive path " + "is more powerful than one would expect. To learn more " + "about the basic and advanced features of the location bar " + "click here. " + "This will open the dedicated page in the Handbook.")); DolphinUrlNavigatorsController::registerDolphinUrlNavigator(this); - connect(this, &KUrlNavigator::returnPressed, - this, &DolphinUrlNavigator::slotReturnPressed); + connect(this, &KUrlNavigator::returnPressed, this, &DolphinUrlNavigator::slotReturnPressed); + + auto readOnlyBadge = new QLabel(); + readOnlyBadge->setPixmap(QIcon::fromTheme(QStringLiteral("emblem-readonly")).pixmap(12, 12)); + readOnlyBadge->setToolTip(i18nc("@info:tooltip of a 'locked' symbol in url navigator", "This folder is not writable for you.")); + readOnlyBadge->hide(); + setBadgeWidget(readOnlyBadge); } DolphinUrlNavigator::~DolphinUrlNavigator() @@ -69,6 +77,9 @@ QSize DolphinUrlNavigator::sizeHint() const widthHint += widget->minimumSizeHint().width(); } } + if (readOnlyBadgeVisible()) { + widthHint += badgeWidget()->sizeHint().width(); + } return QSize(widthHint, KUrlNavigator::sizeHint().height()); } @@ -85,7 +96,7 @@ std::unique_ptr DolphinUrlNavigator::visualSta return visualState; } -void DolphinUrlNavigator::setVisualState(const VisualState& visualState) +void DolphinUrlNavigator::setVisualState(const VisualState &visualState) { setUrlEditable(visualState.isUrlEditable); if (!visualState.isUrlEditable) { @@ -111,9 +122,37 @@ void DolphinUrlNavigator::setPlaceholderText(const QString &text) editor()->lineEdit()->setPlaceholderText(text); } +void DolphinUrlNavigator::setReadOnlyBadgeVisible(bool visible) +{ + QWidget *readOnlyBadge = badgeWidget(); + if (readOnlyBadge) { + readOnlyBadge->setVisible(visible); + } +} + +bool DolphinUrlNavigator::readOnlyBadgeVisible() const +{ + QWidget *readOnlyBadge = badgeWidget(); + if (readOnlyBadge) { + return readOnlyBadge->isVisible(); + } + return false; +} + void DolphinUrlNavigator::slotReturnPressed() { if (!GeneralSettings::editableUrl()) { setUrlEditable(false); } } + +void DolphinUrlNavigator::keyPressEvent(QKeyEvent *keyEvent) +{ + if (keyEvent->key() == Qt::Key_Escape && !isUrlEditable()) { + Q_EMIT requestToLoseFocus(); + return; + } + KUrlNavigator::keyPressEvent(keyEvent); +} + +#include "moc_dolphinurlnavigator.cpp"