From 1ff74854ecb4e5c9a2099759b71c378225c9e988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9ven=20Car?= Date: Sun, 17 Mar 2019 17:24:30 +0100 Subject: [PATCH] Fix a todo: InformationPanelContent::configureSettings code is moved to InformationPanel::contextMenuEvent Summary: Fix a TODO : InformationPanelContent::configureSettings code is moved to InformationPanel::contextMenuEvent Adding necessary accessors and changing visibility of one slot. Test Plan: 1 compile 2 in dolphin right on the information panel 3 toggle preview 4 from the same context menu, click configure, metadadata settings appears 5 toggle "condensed date" if available Reviewers: elvisangelaccio, #dolphin Reviewed By: elvisangelaccio, #dolphin Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D19832 --- src/panels/information/informationpanel.cpp | 59 +++++++++++++++++- src/panels/information/informationpanel.h | 6 ++ .../information/informationpanelcontent.cpp | 60 +++---------------- .../information/informationpanelcontent.h | 23 ++++--- 4 files changed, 81 insertions(+), 67 deletions(-) diff --git a/src/panels/information/informationpanel.cpp b/src/panels/information/informationpanel.cpp index a0aeaaa376..a864cb0057 100644 --- a/src/panels/information/informationpanel.cpp +++ b/src/panels/information/informationpanel.cpp @@ -25,11 +25,18 @@ #include #include #include +#include + +#include #include #include #include #include +#include + +#include "dolphin_informationpanelsettings.h" +#include "filemetadataconfigurationdialog.h" InformationPanel::InformationPanel(QWidget* parent) : Panel(parent), @@ -157,11 +164,59 @@ void InformationPanel::resizeEvent(QResizeEvent* event) void InformationPanel::contextMenuEvent(QContextMenuEvent* event) { - // TODO: Move code from InformationPanelContent::configureSettings() here - m_content->configureSettings(customContextMenuActions(), event->globalPos()); + showContextMenu(event->globalPos()); Panel::contextMenuEvent(event); } +void InformationPanel::showContextMenu(const QPoint &pos) { + QMenu popup(this); + + QAction* previewAction = popup.addAction(i18nc("@action:inmenu", "Preview")); + previewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-preview"))); + previewAction->setCheckable(true); + previewAction->setChecked(InformationPanelSettings::previewsShown()); + + QAction* configureAction = popup.addAction(i18nc("@action:inmenu", "Configure...")); + configureAction->setIcon(QIcon::fromTheme(QStringLiteral("configure"))); + + QAction* dateformatAction = popup.addAction(i18nc("@action:inmenu", "Condensed Date")); + dateformatAction->setIcon(QIcon::fromTheme(QStringLiteral("change-date-symbolic"))); + dateformatAction->setCheckable(true); + dateformatAction->setChecked(InformationPanelSettings::dateFormat() == static_cast(Baloo::DateFormats::ShortFormat)); + + popup.addSeparator(); + foreach (QAction* action, customContextMenuActions()) { + popup.addAction(action); + } + + // Open the popup and adjust the settings for the + // selected action. + QAction* action = popup.exec(pos); + if (!action) { + return; + } + + const bool isChecked = action->isChecked(); + if (action == previewAction) { + m_content->setPreviewVisible(isChecked); + InformationPanelSettings::setPreviewsShown(isChecked); + } else if (action == configureAction) { + FileMetaDataConfigurationDialog* dialog = new FileMetaDataConfigurationDialog(this); + dialog->setDescription(i18nc("@label::textbox", + "Select which data should be shown in the information panel:")); + dialog->setItems(m_content->items()); + dialog->setAttribute(Qt::WA_DeleteOnClose); + dialog->show(); + connect(dialog, &FileMetaDataConfigurationDialog::destroyed, m_content, &InformationPanelContent::refreshMetaData); + } + if (action == dateformatAction) { + int dateFormat = static_cast(isChecked ? Baloo::DateFormats::ShortFormat : Baloo::DateFormats::LongFormat); + + InformationPanelSettings::setDateFormat(dateFormat); + m_content->refreshMetaData(); + } +} + void InformationPanel::showItemInfo() { if (!isVisible()) { diff --git a/src/panels/information/informationpanel.h b/src/panels/information/informationpanel.h index 1eea8fcd27..05947145d6 100644 --- a/src/panels/information/informationpanel.h +++ b/src/panels/information/informationpanel.h @@ -128,6 +128,12 @@ private: */ void markUrlAsInvalid(); + /** + * Opens a menu which allows to configure which meta information + * should be shown. + */ + void showContextMenu(const QPoint &point); + void init(); private: diff --git a/src/panels/information/informationpanelcontent.cpp b/src/panels/information/informationpanelcontent.cpp index bf87f9b5a5..7704bdf165 100644 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@ -29,7 +29,6 @@ #include #include -#include #include #include @@ -48,7 +47,6 @@ #include #include "dolphin_informationpanelsettings.h" -#include "filemetadataconfigurationdialog.h" #include "phononwidget.h" #include "pixmapviewer.h" @@ -264,56 +262,6 @@ bool InformationPanelContent::eventFilter(QObject* obj, QEvent* event) return QWidget::eventFilter(obj, event); } -void InformationPanelContent::configureSettings(const QList& customContextMenuActions, const QPointF& pos) -{ - QMenu popup(this); - - QAction* previewAction = popup.addAction(i18nc("@action:inmenu", "Preview")); - previewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-preview"))); - previewAction->setCheckable(true); - previewAction->setChecked(InformationPanelSettings::previewsShown()); - - QAction* configureAction = popup.addAction(i18nc("@action:inmenu", "Configure...")); - configureAction->setIcon(QIcon::fromTheme(QStringLiteral("configure"))); - - QAction* dateformatAction = popup.addAction(i18nc("@action:inmenu", "Condensed Date")); - dateformatAction->setIcon(QIcon::fromTheme(QStringLiteral("change-date-symbolic"))); - dateformatAction->setCheckable(true); - dateformatAction->setChecked(InformationPanelSettings::dateFormat() == static_cast(Baloo::DateFormats::ShortFormat)); - - popup.addSeparator(); - foreach (QAction* action, customContextMenuActions) { - popup.addAction(action); - } - - // Open the popup and adjust the settings for the - // selected action. - QAction* action = popup.exec(pos.toPoint()); - if (!action) { - return; - } - - const bool isChecked = action->isChecked(); - if (action == previewAction) { - m_preview->setVisible(isChecked); - InformationPanelSettings::setPreviewsShown(isChecked); - } else if (action == configureAction) { - FileMetaDataConfigurationDialog* dialog = new FileMetaDataConfigurationDialog(this); - dialog->setDescription(i18nc("@label::textbox", - "Select which data should be shown in the information panel:")); - dialog->setItems(m_metaDataWidget->items()); - dialog->setAttribute(Qt::WA_DeleteOnClose); - dialog->show(); - connect(dialog, &FileMetaDataConfigurationDialog::destroyed, this, &InformationPanelContent::refreshMetaData); - } - if (action == dateformatAction) { - int dateFormat = static_cast(isChecked ? Baloo::DateFormats::ShortFormat : Baloo::DateFormats::LongFormat); - - InformationPanelSettings::setDateFormat(dateFormat); - refreshMetaData(); - } -} - void InformationPanelContent::showIcon(const KFileItem& item) { m_outdatedPreviewTimer->stop(); @@ -342,6 +290,14 @@ void InformationPanelContent::markOutdatedPreview() m_preview->setPixmap(disabledPixmap); } +void InformationPanelContent::setPreviewVisible(bool visible) { + m_preview->setVisible(visible); +} + +KFileItemList InformationPanelContent::items() { + return m_metaDataWidget->items(); +} + void InformationPanelContent::slotHasVideoChanged(bool hasVideo) { m_preview->setVisible(!hasVideo); diff --git a/src/panels/information/informationpanelcontent.h b/src/panels/information/informationpanelcontent.h index ca9afab09f..a80775aaa6 100644 --- a/src/panels/information/informationpanelcontent.h +++ b/src/panels/information/informationpanelcontent.h @@ -72,17 +72,20 @@ public: */ void showItems(const KFileItemList& items); - /** - * Opens a menu which allows to configure which meta information - * should be shown. - * - * TODO: Move this code to the class InformationPanel - */ - void configureSettings(const QList& customContextMenuActions, const QPointF& pos); + void setPreviewVisible(bool visible); + + KFileItemList items(); signals: void urlActivated( const QUrl& url ); +public slots: + /** + * Is invoked after the file meta data configuration dialog has been + * closed and refreshes the visibility of the meta data. + */ + void refreshMetaData(); + protected: /** @see QObject::eventFilter() */ bool eventFilter(QObject* obj, QEvent* event) override; @@ -108,12 +111,6 @@ private slots: void slotHasVideoChanged(bool hasVideo); - /** - * Is invoked after the file meta data configuration dialog has been - * closed and refreshes the visibility of the meta data. - */ - void refreshMetaData(); - private: /** * Sets the text for the label \a m_nameLabel and assures that the