X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/615838083dfe7ff6845069cc18a88d38be56a478..7165ea7afdf150600025f9c8ec28dadfe0b28406:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 342c22638..3597a2aa4 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -97,7 +98,7 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : { m_topLayout = new QVBoxLayout(this); m_topLayout->setSpacing(0); - m_topLayout->setMargin(0); + m_topLayout->setContentsMargins(0, 0, 0, 0); // When a new item has been created by the "Create New..." menu, the item should // get selected and it must be assured that the item will get visible. As the @@ -128,8 +129,8 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : m_container = new KItemListContainer(controller, this); m_container->installEventFilter(this); setFocusProxy(m_container); - connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip); - connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, &DolphinView::hideToolTip); + connect(m_container->horizontalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); }); + connect(m_container->verticalScrollBar(), &QScrollBar::valueChanged, this, [=] { hideToolTip(); }); controller->setSelectionBehavior(KItemListController::MultiSelection); connect(controller, &KItemListController::itemActivated, this, &DolphinView::slotItemActivated); @@ -176,10 +177,13 @@ DolphinView::DolphinView(const QUrl& url, QWidget* parent) : connect(selectionManager, &KItemListSelectionManager::selectionChanged, this, &DolphinView::slotSelectionChanged); +#ifdef HAVE_BALOO m_toolTipManager = new ToolTipManager(this); connect(m_toolTipManager, &ToolTipManager::urlActivated, this, &DolphinView::urlActivated); +#endif m_versionControlObserver = new VersionControlObserver(this); + m_versionControlObserver->setView(this); m_versionControlObserver->setModel(m_model); connect(m_versionControlObserver, &VersionControlObserver::infoMessage, this, &DolphinView::infoMessage); connect(m_versionControlObserver, &VersionControlObserver::errorMessage, this, &DolphinView::errorMessage); @@ -636,9 +640,7 @@ void DolphinView::renameSelectedItems() RenameDialog* dialog = new RenameDialog(this, items); connect(dialog, &RenameDialog::renamingFinished, this, &DolphinView::slotRenameDialogRenamingFinished); - dialog->show(); - dialog->raise(); - dialog->activateWindow(); + dialog->open(); } // Assure that the current index remains visible when KFileItemModel @@ -708,7 +710,7 @@ void DolphinView::stopLoading() void DolphinView::updatePalette() { - QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); + QColor color = KColorScheme(isActiveWindow() ? QPalette::Active : QPalette::Inactive, KColorScheme::View).background().color(); if (!m_active) { color.setAlpha(150); } @@ -737,7 +739,13 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event) QPixmapCache::clear(); break; + case QEvent::WindowActivate: + case QEvent::WindowDeactivate: + updatePalette(); + break; + case QEvent::KeyPress: + hideToolTip(ToolTipManager::HideBehavior::Instantly); if (GeneralSettings::useTabForSwitchingSplitView()) { QKeyEvent* keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_Tab && keyEvent->modifiers() == Qt::NoModifier) { @@ -755,6 +763,7 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event) case QEvent::GraphicsSceneDragEnter: if (watched == m_view) { m_dragging = true; + abortTwoClicksRenaming(); } break; @@ -846,7 +855,7 @@ void DolphinView::slotItemsActivated(const KItemSet& indexes) const QUrl& url = openItemAsFolderUrl(item); if (!url.isEmpty()) { // Open folders in new tabs - emit tabRequested(url); + emit tabRequested(url, DolphinTabWidget::AfterLastTab); } else { items.append(item); } @@ -864,9 +873,9 @@ void DolphinView::slotItemMiddleClicked(int index) const KFileItem& item = m_model->fileItem(index); const QUrl& url = openItemAsFolderUrl(item); if (!url.isEmpty()) { - emit tabRequested(url); + emit tabRequested(url, DolphinTabWidget::AfterCurrentTab); } else if (isTabsForFilesEnabled()) { - emit tabRequested(item.url()); + emit tabRequested(item.url(), DolphinTabWidget::AfterCurrentTab); } } @@ -1030,7 +1039,9 @@ void DolphinView::slotItemHovered(int index) const QPoint pos = m_container->mapToGlobal(itemRect.topLeft().toPoint()); itemRect.moveTo(pos); +#ifdef HAVE_BALOO m_toolTipManager->showToolTip(item, itemRect, nativeParentWidget()->windowHandle()); +#endif } emit requestItemInfo(item); @@ -1115,7 +1126,7 @@ void DolphinView::slotMouseButtonPressed(int itemIndex, Qt::MouseButtons buttons void DolphinView::slotSelectedItemTextPressed(int index) { - if (GeneralSettings::renameInline()) { + if (GeneralSettings::renameInline() && !m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick)) { const KFileItem item = m_model->fileItem(index); const KFileItemListProperties capabilities(KFileItemList() << item); if (capabilities.supportsMoving()) { @@ -1328,6 +1339,20 @@ QUrl DolphinView::openItemAsFolderUrl(const KFileItem& item, const bool browseTh return QUrl(); } +void DolphinView::resetZoomLevel() +{ + ViewModeSettings::ViewMode mode; + + switch (m_mode) { + case IconsView: mode = ViewModeSettings::IconsMode; break; + case CompactView: mode = ViewModeSettings::CompactMode; break; + case DetailsView: mode = ViewModeSettings::DetailsMode; break; + } + const ViewModeSettings settings(mode); + const QSize iconSize = QSize(settings.iconSize(), settings.iconSize()); + setZoomLevel(ZoomLevelInfo::zoomLevelForIconSize(iconSize)); +} + void DolphinView::observeCreatedItem(const QUrl& url) { if (m_active) { @@ -1405,11 +1430,13 @@ void DolphinView::updateViewState() } } -void DolphinView::hideToolTip() +void DolphinView::hideToolTip(const ToolTipManager::HideBehavior behavior) { +#ifdef HAVE_BALOO if (GeneralSettings::showToolTips()) { - m_toolTipManager->hideToolTip(); + m_toolTipManager->hideToolTip(behavior); } +#endif } void DolphinView::calculateItemCount(int& fileCount, @@ -1432,8 +1459,8 @@ void DolphinView::slotTwoClicksRenamingTimerTimeout() { const KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - // verify that only one item is selected and that no item is dragged - if (selectionManager->selectedItems().count() == 1 && !m_dragging) { + // verify that only one item is selected + if (selectionManager->selectedItems().count() == 1) { const int index = selectionManager->currentItem(); const QUrl fileItemUrl = m_model->fileItem(index).url(); @@ -1481,7 +1508,7 @@ void DolphinView::slotRenamingResult(KJob* job) void DolphinView::slotDirectoryLoadingStarted() { // Disable the writestate temporary until it can be determined in a fast way - // in DolphinView::slotLoadingCompleted() + // in DolphinView::slotDirectoryLoadingCompleted() if (m_isFolderWritable) { m_isFolderWritable = false; emit writeStateChanged(m_isFolderWritable); @@ -1562,12 +1589,35 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con if (role == "text") { const KFileItem oldItem = m_model->fileItem(index); const QString newName = value.toString(); - if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) { + if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1Char('.') && newName != QLatin1String("..")) { const QUrl oldUrl = oldItem.url(); QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename); newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName)); +#ifndef Q_OS_WIN + //Confirm hiding file/directory by renaming inline + if (!hiddenFilesShown() && newName.startsWith(QLatin1Char('.')) && !oldItem.name().startsWith(QLatin1Char('.'))) { + KGuiItem yesGuiItem(KStandardGuiItem::yes()); + yesGuiItem.setText(i18nc("@action:button", "Rename and Hide")); + + const auto code = KMessageBox::questionYesNo(this, + oldItem.isFile() ? i18n("Adding a dot to the beginning of this file's name will hide it from view.\n" + "Do you still want to rename it?") + : i18n("Adding a dot to the beginning of this folder's name will hide it from view.\n" + "Do you still want to rename it?"), + oldItem.isFile() ? i18n("Hide this File?") : i18n("Hide this Folder?"), + yesGuiItem, + KStandardGuiItem::cancel(), + QStringLiteral("ConfirmHide") + ); + + if (code == KMessageBox::No) { + return; + } + } +#endif + const bool newNameExistsAlready = (m_model->index(newUrl) >= 0); if (!newNameExistsAlready) { // Only change the data in the model if no item with the new name