mirror of
https://invent.kde.org/system/dolphin
synced 2024-10-05 16:19:10 +00:00
ed2d352c42
* speeds up incremental builds as changes to a header will not always need the full mocs_compilation.cpp for all the target's headers rebuild, while having a moc file sourced into a source file only adds minor extra costs, due to small own code and the used headers usually already covered by the source file, being for the same class/struct * seems to not slow down clean builds, due to empty mocs_compilation.cpp resulting in those quickly processed, while the minor extra cost of the sourced moc files does not outweigh that in summary. Measured times actually improved by some percent points. (ideally CMake would just skip empty mocs_compilation.cpp & its object file one day) * enables compiler to see all methods of a class in same compilation unit to do some sanity checks * potentially more inlining in general, due to more in the compilation unit * allows to keep using more forward declarations in the header, as with the moc code being sourced into the cpp file there definitions can be ensured and often are already for the needs of the normal class methods
122 lines
4.4 KiB
C++
122 lines
4.4 KiB
C++
/*
|
|
This file is part of the KDE project
|
|
SPDX-FileCopyrightText: 2020 Felix Ernst <felixernst@kde.org>
|
|
|
|
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 <KLocalizedString>
|
|
#include <KUrlComboBox>
|
|
|
|
#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::clearText() const
|
|
{
|
|
editor()->lineEdit()->clear();
|
|
}
|
|
|
|
void DolphinUrlNavigator::setPlaceholderText(const QString &text)
|
|
{
|
|
editor()->lineEdit()->setPlaceholderText(text);
|
|
}
|
|
|
|
void DolphinUrlNavigator::slotReturnPressed()
|
|
{
|
|
if (!GeneralSettings::editableUrl()) {
|
|
setUrlEditable(false);
|
|
}
|
|
}
|
|
|
|
#include "moc_dolphinurlnavigator.cpp"
|