diff --git a/src/filewidgets/kfilewidget.h b/src/filewidgets/kfilewidget.h --- a/src/filewidgets/kfilewidget.h +++ b/src/filewidgets/kfilewidget.h @@ -592,27 +592,6 @@ private: friend class KFileWidgetPrivate; KFileWidgetPrivate *const d; - - Q_PRIVATE_SLOT(d, void _k_slotLocationChanged(const QString &)) - Q_PRIVATE_SLOT(d, void _k_urlEntered(const QUrl &)) - Q_PRIVATE_SLOT(d, void _k_enterUrl(const QUrl &)) - Q_PRIVATE_SLOT(d, void _k_enterUrl(const QString &)) - Q_PRIVATE_SLOT(d, void _k_locationAccepted(const QString &)) - Q_PRIVATE_SLOT(d, void _k_slotFilterChanged()) - Q_PRIVATE_SLOT(d, void _k_fileHighlighted(const KFileItem &)) - Q_PRIVATE_SLOT(d, void _k_fileSelected(const KFileItem &)) - Q_PRIVATE_SLOT(d, void _k_slotLoadingFinished()) - Q_PRIVATE_SLOT(d, void _k_fileCompletion(const QString &)) - Q_PRIVATE_SLOT(d, void _k_toggleSpeedbar(bool)) - Q_PRIVATE_SLOT(d, void _k_toggleBookmarks(bool)) - Q_PRIVATE_SLOT(d, void _k_slotAutoSelectExtClicked()) - Q_PRIVATE_SLOT(d, void _k_placesViewSplitterMoved(int, int)) - Q_PRIVATE_SLOT(d, void _k_activateUrlNavigator()) - Q_PRIVATE_SLOT(d, void _k_zoomOutIconsSize()) - Q_PRIVATE_SLOT(d, void _k_zoomInIconsSize()) - Q_PRIVATE_SLOT(d, void _k_slotIconSizeSliderMoved(int)) - Q_PRIVATE_SLOT(d, void _k_slotIconSizeChanged(int)) - Q_PRIVATE_SLOT(d, void _k_slotViewDoubleClicked(const QModelIndex&)) }; #endif diff --git a/src/filewidgets/kfilewidget.cpp b/src/filewidgets/kfilewidget.cpp --- a/src/filewidgets/kfilewidget.cpp +++ b/src/filewidgets/kfilewidget.cpp @@ -296,6 +296,9 @@ // files and urls. Visual settings (view mode, sorting criteria...) are not // app-specific and are stored in kdeglobals KConfigGroup configGroup; + + // To be able to disconnect it and reconnect again + QMetaObject::Connection m_connEditTextChanged; }; Q_GLOBAL_STATIC(QUrl, lastDirectory) // to set the start path @@ -433,14 +436,14 @@ d->ops->setObjectName(QStringLiteral("KFileWidget::ops")); d->ops->setIsSaving(d->operationMode == Saving); opsWidgetLayout->addWidget(d->ops); - connect(d->ops, SIGNAL(urlEntered(QUrl)), - SLOT(_k_urlEntered(QUrl))); - connect(d->ops, SIGNAL(fileHighlighted(KFileItem)), - SLOT(_k_fileHighlighted(KFileItem))); - connect(d->ops, SIGNAL(fileSelected(KFileItem)), - SLOT(_k_fileSelected(KFileItem))); - connect(d->ops, SIGNAL(finishedLoading()), - SLOT(_k_slotLoadingFinished())); + connect(d->ops, &KDirOperator::urlEntered, this, + [this](const QUrl &url){d->_k_urlEntered(url);}); + connect(d->ops, &KDirOperator::fileHighlighted, this, + [this](const KFileItem &item){d->_k_fileHighlighted(item);}); + connect(d->ops, &KDirOperator::fileSelected, this, + [this](const KFileItem &item){d->_k_fileSelected(item);}); + connect(d->ops, &KDirOperator::finishedLoading, this, + [this](){d->_k_slotLoadingFinished();}); d->ops->setupMenu(KDirOperator::SortActions | KDirOperator::FileActions | @@ -467,21 +470,23 @@ coll->action(QStringLiteral("mkdir"))->setShortcut(QKeySequence(Qt::Key_F10)); coll->action(QStringLiteral("mkdir"))->setWhatsThis(i18n("Click this button to create a new folder.")); - QAction *goToNavigatorAction = coll->addAction(QStringLiteral("gotonavigator"), this, SLOT(_k_activateUrlNavigator())); + QAction *goToNavigatorAction = coll->addAction(QStringLiteral("gotonavigator"), this, + [this](){d->_k_activateUrlNavigator();}); goToNavigatorAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L)); KToggleAction *showSidebarAction = new KToggleAction(i18n("Show Places Navigation Panel"), this); coll->addAction(QStringLiteral("toggleSpeedbar"), showSidebarAction); showSidebarAction->setShortcut(QKeySequence(Qt::Key_F9)); - connect(showSidebarAction, SIGNAL(toggled(bool)), - SLOT(_k_toggleSpeedbar(bool))); + + connect(showSidebarAction, &KToggleAction::toggled, this, + [this](const bool t){d->_k_toggleSpeedbar(t);}); KToggleAction *showBookmarksAction = new KToggleAction(i18n("Show Bookmarks"), this); coll->addAction(QStringLiteral("toggleBookmarks"), showBookmarksAction); - connect(showBookmarksAction, SIGNAL(toggled(bool)), - SLOT(_k_toggleBookmarks(bool))); + connect(showSidebarAction, &KToggleAction::toggled, this, + [this](const bool t){d->_k_toggleBookmarks(t);}); KActionMenu *menu = new KActionMenu(QIcon::fromTheme(QStringLiteral("configure")), i18n("Options"), this); coll->addAction(QStringLiteral("extra menu"), menu); @@ -505,32 +510,32 @@ menu->addAction(coll->action(QStringLiteral("preview"))); menu->setDelayed(false); - connect(menu->menu(), SIGNAL(aboutToShow()), - d->ops, SLOT(updateSelectionDependentActions())); + connect(menu->menu(), &QMenu::aboutToShow, + d->ops, &KDirOperator::updateSelectionDependentActions); d->iconSizeSlider = new QSlider(this); d->iconSizeSlider->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); d->iconSizeSlider->setMinimumWidth(40); d->iconSizeSlider->setOrientation(Qt::Horizontal); d->iconSizeSlider->setMinimum(0); d->iconSizeSlider->setMaximum(100); d->iconSizeSlider->installEventFilter(this); - connect(d->iconSizeSlider, SIGNAL(valueChanged(int)), - d->ops, SLOT(setIconsZoom(int))); - connect(d->iconSizeSlider, SIGNAL(valueChanged(int)), - this, SLOT(_k_slotIconSizeChanged(int))); - connect(d->iconSizeSlider, SIGNAL(sliderMoved(int)), - this, SLOT(_k_slotIconSizeSliderMoved(int))); + connect(d->iconSizeSlider, &QSlider::valueChanged, + d->ops, &KDirOperator::setIconsZoom); + connect(d->iconSizeSlider, &QSlider::valueChanged, + this, [this](const int val){d->_k_slotIconSizeChanged(val);}); + connect(d->iconSizeSlider, &QSlider::sliderMoved, + this, [this](const int val){d->_k_slotIconSizeSliderMoved(val);}); connect(d->ops, &KDirOperator::currentIconSizeChanged, [this](int value) { d->iconSizeSlider->setValue(value); d->zoomOutAction->setDisabled(value <= d->iconSizeSlider->minimum()); d->zoomInAction->setDisabled(value >= d->iconSizeSlider->maximum()); }); d->zoomOutAction = new QAction(QIcon::fromTheme(QStringLiteral("file-zoom-out")), i18n("Zoom out"), this); - connect(d->zoomOutAction, SIGNAL(triggered()), SLOT(_k_zoomOutIconsSize())); + connect(d->zoomOutAction, &QAction::triggered, this, [this](){d->_k_zoomOutIconsSize();}); d->zoomInAction = new QAction(QIcon::fromTheme(QStringLiteral("file-zoom-in")), i18n("Zoom in"), this); - connect(d->zoomInAction, SIGNAL(triggered()), SLOT(_k_zoomInIconsSize())); + connect(d->zoomInAction, &QAction::triggered, this, [this](){d->_k_zoomInIconsSize();}); QWidget *midSpacer = new QWidget(this); midSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -562,10 +567,10 @@ pathCombo->setCompletionObject(pathCompletionObj); pathCombo->setAutoDeleteCompletionObject(true); - connect(d->urlNavigator, SIGNAL(urlChanged(QUrl)), - this, SLOT(_k_enterUrl(QUrl))); - connect(d->urlNavigator, SIGNAL(returnPressed()), - d->ops, SLOT(setFocus())); + connect(d->urlNavigator, &KUrlNavigator::urlChanged, this, + [this](const QUrl &url){d->_k_enterUrl(url);}); + connect(d->urlNavigator, &KUrlNavigator::returnPressed, + d->ops, [this](){d->ops->setFocus();}); QString whatsThisText; @@ -577,20 +582,20 @@ // huge dialogs that can't be resized to smaller (it would be as big as the longest // item in this combo box). (ereslibre) d->locationEdit->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); - connect(d->locationEdit, SIGNAL(editTextChanged(QString)), - SLOT(_k_slotLocationChanged(QString))); + d->m_connEditTextChanged = connect(d->locationEdit, &KUrlComboBox::editTextChanged, + this, [this](const QString &text){d->_k_slotLocationChanged(text);}); d->updateLocationWhatsThis(); d->locationLabel->setBuddy(d->locationEdit); KUrlCompletion *fileCompletionObj = new KUrlCompletion(KUrlCompletion::FileCompletion); d->locationEdit->setCompletionObject(fileCompletionObj); d->locationEdit->setAutoDeleteCompletionObject(true); - connect(fileCompletionObj, SIGNAL(match(QString)), - SLOT(_k_fileCompletion(QString))); + connect(fileCompletionObj, &KUrlCompletion::match, + this, [this](const QString &m){d->_k_fileCompletion(m);}); - connect(d->locationEdit, SIGNAL(returnPressed(QString)), - this, SLOT(_k_locationAccepted(QString))); + connect(d->locationEdit, QOverload::of(&KUrlComboBox::returnPressed), + this, [this](const QString &m){d->_k_locationAccepted(m);}); // the Filter label/edit whatsThisText = i18n("This is the filter to apply to the file list. " @@ -608,19 +613,24 @@ d->filterWidget->setSizeAdjustPolicy(QComboBox::AdjustToMinimumContentsLength); d->filterWidget->setWhatsThis(whatsThisText); d->filterLabel->setBuddy(d->filterWidget); - connect(d->filterWidget, SIGNAL(filterChanged()), SLOT(_k_slotFilterChanged())); + connect(d->filterWidget, &KFileFilterCombo::filterChanged, + this, [this](){d->_k_slotFilterChanged();}); d->filterDelayTimer.setSingleShot(true); d->filterDelayTimer.setInterval(300); - connect(d->filterWidget, SIGNAL(editTextChanged(QString)), &d->filterDelayTimer, SLOT(start())); - connect(&d->filterDelayTimer, SIGNAL(timeout()), SLOT(_k_slotFilterChanged())); + connect(d->filterWidget, &KFileFilterCombo::editTextChanged, + &d->filterDelayTimer, [this](){d->filterDelayTimer.start();}); + + connect(&d->filterDelayTimer, &QTimer::timeout, + this, [this](){d->_k_slotFilterChanged();}); // the Automatically Select Extension checkbox // (the text, visibility etc. is set in updateAutoSelectExtension(), which is called by readConfig()) d->autoSelectExtCheckBox = new QCheckBox(this); const int spacingHint = style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing); d->autoSelectExtCheckBox->setStyleSheet(QStringLiteral("QCheckBox { padding-top: %1px; }").arg(spacingHint)); - connect(d->autoSelectExtCheckBox, SIGNAL(clicked()), SLOT(_k_slotAutoSelectExtClicked())); + connect(d->autoSelectExtCheckBox, &QCheckBox::clicked, + this, [this](){d->_k_slotAutoSelectExtClicked();}); d->initGUI(); // activate GM @@ -1212,8 +1222,7 @@ // setCurrentItem() will cause textChanged() being emitted, // so slotLocationChanged() will be called. Make sure we don't clear // the KDirOperator's view-selection in there - QObject::disconnect(locationEdit, SIGNAL(editTextChanged(QString)), - q, SLOT(_k_slotLocationChanged(QString))); + QObject::disconnect(m_connEditTextChanged); bool dummyExists = dummyAdded; @@ -1251,8 +1260,8 @@ locationEdit->lineEdit()->setCursorPosition(cursorPosition); - QObject::connect(locationEdit, SIGNAL(editTextChanged(QString)), - q, SLOT(_k_slotLocationChanged(QString))); + m_connEditTextChanged = QObject::connect(locationEdit, &KUrlComboBox::editTextChanged, + q, [this](const QString &text){_k_slotLocationChanged(text);}); } void KFileWidgetPrivate::removeDummyHistoryEntry() @@ -1264,17 +1273,16 @@ // setCurrentItem() will cause textChanged() being emitted, // so slotLocationChanged() will be called. Make sure we don't clear // the KDirOperator's view-selection in there - QObject::disconnect(locationEdit, SIGNAL(editTextChanged(QString)), - q, SLOT(_k_slotLocationChanged(QString))); + QObject::disconnect(m_connEditTextChanged); if (locationEdit->count()) { locationEdit->removeItem(0); } locationEdit->setCurrentIndex(-1); dummyAdded = false; - QObject::connect(locationEdit, SIGNAL(editTextChanged(QString)), - q, SLOT(_k_slotLocationChanged(QString))); + m_connEditTextChanged = QObject::connect(locationEdit, &KUrlComboBox::editTextChanged, + q, [this](const QString &text){_k_slotLocationChanged(text);}); } void KFileWidgetPrivate::setLocationText(const QUrl &url) @@ -1373,8 +1381,8 @@ placesView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); placesView->setObjectName(QStringLiteral("url bar")); - QObject::connect(placesView, SIGNAL(urlChanged(QUrl)), - q, SLOT(_k_enterUrl(QUrl))); + QObject::connect(placesView, &KFilePlacesView::urlChanged, + q, [this](const QUrl &url){_k_enterUrl(url);}); // need to set the current url of the urlbar manually (not via urlEntered() // here, because the initial url of KDirOperator might be the same as the @@ -1391,8 +1399,8 @@ // Needed for when the dialog is shown with the places panel initially hidden setPlacesViewSplitterSizes(); - QObject::connect(placesDock, SIGNAL(visibilityChanged(bool)), - q, SLOT(_k_toggleSpeedbar(bool))); + QObject::connect(placesDock, &QDockWidget::visibilityChanged, + q, [this](const bool yn){_k_toggleSpeedbar(yn);}); } void KFileWidgetPrivate::setPlacesViewSplitterSizes() @@ -1426,8 +1434,8 @@ placesViewSplitter->setChildrenCollapsible(false); boxLayout->addWidget(placesViewSplitter); - QObject::connect(placesViewSplitter, SIGNAL(splitterMoved(int,int)), - q, SLOT(_k_placesViewSplitterMoved(int,int))); + QObject::connect(placesViewSplitter, &QSplitter::splitterMoved, + q, [this](int x, int y){_k_placesViewSplitterMoved(x,y); }); placesViewSplitter->insertWidget(0, opsWidget); vbox = new QVBoxLayout(); @@ -1862,7 +1870,8 @@ d->ops->view()->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); d->hasView = true; - connect(d->ops->view(), SIGNAL(doubleClicked(QModelIndex)), this, SLOT(_k_slotViewDoubleClicked(QModelIndex))); + connect(d->ops->view(), &KFilePlacesView::doubleClicked, this, + [this](const QModelIndex &index){d->_k_slotViewDoubleClicked(index);}); } d->ops->clearHistory(); @@ -2001,16 +2010,15 @@ { // qDebug(); - QObject::disconnect(locationEdit, SIGNAL(editTextChanged(QString)), - q, SLOT(_k_slotLocationChanged(QString))); + QObject::disconnect(m_connEditTextChanged); locationEdit->setMaxItems(configGroup.readEntry(RecentFilesNumber, DefaultRecentURLsNumber)); locationEdit->setUrls(configGroup.readPathEntry(RecentFiles, QStringList()), KUrlComboBox::RemoveBottom); locationEdit->setCurrentIndex(-1); - QObject::connect(locationEdit, SIGNAL(editTextChanged(QString)), - q, SLOT(_k_slotLocationChanged(QString))); + m_connEditTextChanged = QObject::connect(locationEdit, &KUrlComboBox::editTextChanged, + q, [this](const QString &text){_k_slotLocationChanged(text);}); KUrlComboBox *combo = urlNavigator->editor(); combo->setUrls(configGroup.readPathEntry(RecentURLs, QStringList()), KUrlComboBox::RemoveTop); @@ -2627,8 +2635,8 @@ } bookmarkHandler = new KFileBookmarkHandler(q); - q->connect(bookmarkHandler, SIGNAL(openUrl(QString)), - SLOT(_k_enterUrl(QString))); + QObject::connect(bookmarkHandler, &KFileBookmarkHandler::openUrl, + q, [this](const QString &url){_k_enterUrl(url);}); bookmarkButton = new KActionMenu(QIcon::fromTheme(QStringLiteral("bookmarks")), i18n("Bookmarks"), q); bookmarkButton->setDelayed(false);