diff options
Diffstat (limited to 'src/views')
| -rw-r--r-- | src/views/dolphinview.cpp | 4 | ||||
| -rw-r--r-- | src/views/dolphinview.h | 7 | ||||
| -rw-r--r-- | src/views/dolphinviewactionhandler.cpp | 53 | ||||
| -rw-r--r-- | src/views/tooltips/tooltipmanager.cpp | 21 | ||||
| -rw-r--r-- | src/views/tooltips/tooltipmanager.h | 7 |
5 files changed, 39 insertions, 53 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 5646fa982..e6aecff80 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -1058,12 +1058,12 @@ void DolphinView::slotItemContextMenuRequested(int index, const QPointF& pos) } const KFileItem item = m_model->fileItem(index); - Q_EMIT requestContextMenu(pos.toPoint(), item, url(), QList<QAction*>()); + Q_EMIT requestContextMenu(pos.toPoint(), item, selectedItems(), url()); } void DolphinView::slotViewContextMenuRequested(const QPointF& pos) { - Q_EMIT requestContextMenu(pos.toPoint(), KFileItem(), url(), QList<QAction*>()); + Q_EMIT requestContextMenu(pos.toPoint(), KFileItem(), selectedItems(), url()); } void DolphinView::slotHeaderContextMenuRequested(const QPointF& pos) diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index e93ca4fa0..b40be8936 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -510,13 +510,12 @@ Q_SIGNALS: /** * Is emitted if a context menu is requested for the item \a item, * which is part of \a url. If the item is null, the context menu - * for the URL should be shown and the custom actions \a customActions - * will be added. + * for the URL should be shown. */ void requestContextMenu(const QPoint& pos, const KFileItem& item, - const QUrl& url, - const QList<QAction*>& customActions); + const KFileItemList &selectedItems, + const QUrl& url); /** * Is emitted if an information message with the content \a msg diff --git a/src/views/dolphinviewactionhandler.cpp b/src/views/dolphinviewactionhandler.cpp index 2e524f8f2..1c5298703 100644 --- a/src/views/dolphinviewactionhandler.cpp +++ b/src/views/dolphinviewactionhandler.cpp @@ -8,6 +8,7 @@ #include "dolphinviewactionhandler.h" #include "dolphindebug.h" +#include "kitemviews/kfileitemlisttostring.h" #include "kitemviews/kfileitemmodel.h" #include "settings/viewpropertiesdialog.h" #include "views/zoomlevelinfo.h" @@ -663,7 +664,7 @@ void DolphinViewActionHandler::slotSortRoleChanged(const QByteArray& role) QAction* descending = m_actionCollection->action(QStringLiteral("descending")); QAction* ascending = m_actionCollection->action(QStringLiteral("ascending")); - if (role == "text" || role == "type" || role == "tags" || role == "comment") { + if (role == "text" || role == "type" || role == "extension" || role == "tags" || role == "comment") { descending->setText(i18nc("Sort descending", "Z-A")); ascending->setText(i18nc("Sort ascending", "A-Z")); } else if (role == "size") { @@ -763,49 +764,25 @@ void DolphinViewActionHandler::slotCopyPath() void DolphinViewActionHandler::slotSelectionChanged(const KFileItemList& selection) { QString basicActionsMenuText; - switch (selection.count()) { - case 0: + if (selection.isEmpty()) { basicActionsMenuText = i18nc("@action:inmenu menu with actions like copy, paste, rename. The user's selection is empty when this text is shown.", "Actions for Current View"); - break; - case 1: - basicActionsMenuText = - i18nc("@action:inmenu menu with actions like copy, paste, rename. %1 is the name of the singular selected file/folder.", - "Actions for \"%1\"", selection.first().name()); - break; - case 2: - basicActionsMenuText = - i18nc("@action:inmenu menu with actions like copy, paste, rename. %1 and %2 are names of files/folders.", - "Actions for \"%1\" and \"%2\"", selection.first().name(), selection.last().name()); - break; - case 3: - basicActionsMenuText = - i18nc("@action:inmenu menu with actions like copy, paste, rename. %1, %2 and %3 are names of files/folders.", - "Actions for \"%1\", \"%2\" and \"%3\"", - selection.first().name(), selection.at(1).name(), selection.last().name()); - break; - default: - basicActionsMenuText = QString(); - break; + } else { + QFontMetrics fontMetrics = QMenu().fontMetrics(); + // i18n: @action:inmenu menu with actions like copy, paste, rename. + // %1 is a textual representation of the currently selected files or folders. This can be the name of + // the file/files like "file1" or "file1, file2 and file3" or an aggregate like "8 Selected Folders". + // If this sort of word puzzle can not be correctly translated in your language, translate it as "NULL" (without the quotes) + // and a fallback will be used. + basicActionsMenuText = i18n("Actions for %1", fileItemListToString(selection, fontMetrics.averageCharWidth() * 40, fontMetrics, ItemsState::Selected)); } - // At some point the added clarity from the text starts being less important than the menu width. - if (basicActionsMenuText.isEmpty() || basicActionsMenuText.length() > 40) { + if (basicActionsMenuText == QStringLiteral("NULL")) { const KFileItemListProperties properties(selection); - if (properties.isFile()) { - basicActionsMenuText = - i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.", - "Actions for One Selected File", "Actions for %1 Selected Files", selection.count()); - } else if (properties.isDirectory()) { - basicActionsMenuText = - i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.", - "Actions for One Selected Folder", "Actions for %1 Selected Folders", selection.count()); - } else { - basicActionsMenuText = - i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.", - "Actions for One Selected Item", "Actions for %1 Selected Items", selection.count()); - } + basicActionsMenuText = + i18ncp("@action:inmenu menu with actions like copy, paste, rename. %1 is the amount of selected files/folders.", + "Actions for One Selected Item", "Actions for %1 Selected Items", selection.count()); } QAction *basicActionsMenu = m_actionCollection->action(QStringLiteral("basic_actions")); diff --git a/src/views/tooltips/tooltipmanager.cpp b/src/views/tooltips/tooltipmanager.cpp index 54af9c94c..637261702 100644 --- a/src/views/tooltips/tooltipmanager.cpp +++ b/src/views/tooltips/tooltipmanager.cpp @@ -38,7 +38,6 @@ ToolTipManager::ToolTipManager(QWidget* parent) : m_showToolTipTimer(nullptr), m_contentRetrievalTimer(nullptr), m_transientParent(nullptr), - m_fileMetaDataWidget(nullptr), m_toolTipRequested(false), m_metaDataRequested(false), m_appliedWaitCursor(false), @@ -65,11 +64,14 @@ ToolTipManager::ToolTipManager(QWidget* parent) : ToolTipManager::~ToolTipManager() { + if (!m_fileMetaDatWidgetOwnershipTransferred) { + delete m_fileMetaDataWidget; + } } void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect, QWindow *transientParent) { - hideToolTip(); + hideToolTip(HideBehavior::Instantly); m_itemRect = itemRect.toRect(); @@ -81,11 +83,11 @@ void ToolTipManager::showToolTip(const KFileItem& item, const QRectF& itemRect, // Only start the retrieving of the content, when the mouse has been over this // item for 200 milliseconds. This prevents a lot of useless preview jobs and // meta data retrieval, when passing rapidly over a lot of items. - m_fileMetaDataWidget.reset(new DolphinFileMetaDataWidget()); - connect(m_fileMetaDataWidget.data(), &DolphinFileMetaDataWidget::metaDataRequestFinished, - this, &ToolTipManager::slotMetaDataRequestFinished); - connect(m_fileMetaDataWidget.data(), &DolphinFileMetaDataWidget::urlActivated, - this, &ToolTipManager::urlActivated); + if (!m_fileMetaDataWidget) { + m_fileMetaDataWidget = new DolphinFileMetaDataWidget(); + connect(m_fileMetaDataWidget, &DolphinFileMetaDataWidget::metaDataRequestFinished, this, &ToolTipManager::slotMetaDataRequestFinished); + connect(m_fileMetaDataWidget, &DolphinFileMetaDataWidget::urlActivated, this, &ToolTipManager::urlActivated); + } m_contentRetrievalTimer->start(); m_showToolTipTimer->start(); @@ -220,7 +222,10 @@ void ToolTipManager::showToolTip() if (!m_tooltipWidget) { m_tooltipWidget.reset(new KToolTipWidget()); } - m_tooltipWidget->showBelow(m_itemRect, m_fileMetaDataWidget.data(), m_transientParent); + m_tooltipWidget->showBelow(m_itemRect, m_fileMetaDataWidget, m_transientParent); + // At this point KToolTipWidget adopted our parent-less metadata widget. + m_fileMetaDatWidgetOwnershipTransferred = true; + m_toolTipRequested = false; } diff --git a/src/views/tooltips/tooltipmanager.h b/src/views/tooltips/tooltipmanager.h index 3688e815c..c86c97f6b 100644 --- a/src/views/tooltips/tooltipmanager.h +++ b/src/views/tooltips/tooltipmanager.h @@ -77,7 +77,12 @@ private: QWindow* m_transientParent; QScopedPointer<KToolTipWidget> m_tooltipWidget; - QScopedPointer<DolphinFileMetaDataWidget> m_fileMetaDataWidget; + DolphinFileMetaDataWidget *m_fileMetaDataWidget = nullptr; + + /// Whether ownership of the metadata widget was transferred + /// over to the KToolTipWidget (i.e. we should not delete it + /// anymore) + bool m_fileMetaDatWidgetOwnershipTransferred = false; bool m_toolTipRequested; bool m_metaDataRequested; |
