]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add settings page for Panels
authorBenedikt Thiemer <numerfolt@posteo.de>
Fri, 15 Mar 2024 16:28:35 +0000 (16:28 +0000)
committerFelix Ernst <felixernst@kde.org>
Fri, 15 Mar 2024 16:28:35 +0000 (16:28 +0000)
For now this just includes the settings for the information panel.

Prior to this commit the options for configuring the information panel
were only exposed via right clicking the information panel. This was
not discoverable enough. Our guidelines also state that much. See:
https://community.kde.org/Get_Involved/Design/Frequently_Discussed_Topics#Context_menus_are_not_enough

The settings page is missing the "Configure" button for the entries in
the information panel, which can only be found in the context menu.
This is because I thought it would be weird to move it to the settings
page. (The "configure" button is used to select the entries for the
information panel)

BUG: 480243
FIXED-IN: 24.05

src/CMakeLists.txt
src/dolphinmainwindow.cpp
src/panels/information/informationpanel.cpp
src/panels/information/informationpanel.h
src/settings/interface/interfacesettingspage.cpp
src/settings/interface/panelsettingspage.cpp [new file with mode: 0644]
src/settings/interface/panelsettingspage.h [new file with mode: 0644]

index 021491e40d7b39990fa6f10f8862bdd042bb085b..4c2c3cb6cb170f9110aba25ddd4e80082deb0c6e 100644 (file)
@@ -383,11 +383,18 @@ if(HAVE_BALOO)
         panels/information/informationpanelcontent.cpp
         panels/information/pixmapviewer.cpp
         panels/information/phononwidget.cpp
+        settings/interface/panelsettingspage.cpp
         panels/information/informationpanel.h
         panels/information/informationpanelcontent.h
         panels/information/pixmapviewer.h
         panels/information/phononwidget.h
+        settings/interface/panelsettingspage.h
     )
+
+    kconfig_add_kcfg_files(dolphinstatic
+        panels/information/dolphin_informationpanelsettings.kcfgc
+    )
+
 endif()
 
 if(HAVE_KUSERFEEDBACK)
@@ -405,7 +412,6 @@ endif()
 
 kconfig_add_kcfg_files(dolphinstatic
     panels/folders/dolphin_folderspanelsettings.kcfgc
-    panels/information/dolphin_informationpanelsettings.kcfgc
     panels/places/dolphin_placespanelsettings.kcfgc
     settings/dolphin_compactmodesettings.kcfgc
     settings/dolphin_detailsmodesettings.kcfgc
index 49e656ce72bba5301bef3b3affda0b554d0692c1..47a74742bef93fddbe08ffc393d8d4c1ed5cb711 100644 (file)
@@ -2162,6 +2162,7 @@ void DolphinMainWindow::setupDockWidgets()
     connect(this, &DolphinMainWindow::selectionChanged, infoPanel, &InformationPanel::setSelection);
     connect(this, &DolphinMainWindow::requestItemInfo, infoPanel, &InformationPanel::requestDelayedItemInfo);
     connect(this, &DolphinMainWindow::fileItemsChanged, infoPanel, &InformationPanel::slotFilesItemChanged);
+    connect(this, &DolphinMainWindow::settingsChanged, infoPanel, &InformationPanel::readSettings);
 #endif
 
     // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
index c1b7a56124ecd95a7bc6953447077c27a856a405..02fe3e308ae4f58bea4c56139a353c051832ef6a 100644 (file)
@@ -378,6 +378,14 @@ void InformationPanel::markUrlAsInvalid()
     m_resetUrlTimer->start();
 }
 
+void InformationPanel::readSettings()
+{
+    if (m_initialized) {
+        m_content->refreshPreview();
+        m_content->refreshMetaData();
+    }
+}
+
 void InformationPanel::init()
 {
     m_infoTimer = new QTimer(this);
index ee405cb39156be3dabbe5dc96f25fa99c3390229..eda70759ae39944cfc19b0bf457bd23087d6ba3b 100644 (file)
@@ -28,6 +28,12 @@ public:
     explicit InformationPanel(QWidget *parent = nullptr);
     ~InformationPanel() override;
 
+    /**
+     * Refreshes the view to get synchronized with the settings (e.g. icons size,
+     * font, ...).
+     */
+    void readSettings() override;
+
 Q_SIGNALS:
     void urlActivated(const QUrl &url);
 
index 0159f822c5cc3e7be92409961d937e89add36118..3f8e69ada20092a41805cc75089c174edb26a4e6 100644 (file)
 #include "previewssettingspage.h"
 #include "statusandlocationbarssettingspage.h"
 
+#if HAVE_BALOO
+#include "panelsettingspage.h"
+#endif
+
 #include <KLocalizedString>
 
 #include <QTabWidget>
@@ -41,6 +45,13 @@ InterfaceSettingsPage::InterfaceSettingsPage(QWidget *parent)
     tabWidget->addTab(confirmationsPage, i18nc("@title:tab Confirmations settings", "Confirmations"));
     connect(confirmationsPage, &ConfirmationsSettingsPage::changed, this, &InterfaceSettingsPage::changed);
 
+#if HAVE_BALOO
+    // initialize 'Panel' tab
+    PanelSettingsPage *panelPage = new PanelSettingsPage(tabWidget);
+    tabWidget->addTab(panelPage, i18nc("@title:tab Panels settings", "Panels"));
+    connect(panelPage, &PanelSettingsPage::changed, this, &InterfaceSettingsPage::changed);
+#endif
+
     // initialize 'Status & location bars' tab
     StatusAndLocationBarsSettingsPage *statusAndLocationBarsPage = new StatusAndLocationBarsSettingsPage(tabWidget, foldersTabsPage);
     tabWidget->addTab(statusAndLocationBarsPage, i18nc("@title:tab Status & Location bars settings", "Status && Location bars"));
@@ -49,6 +60,11 @@ InterfaceSettingsPage::InterfaceSettingsPage(QWidget *parent)
     m_pages.append(foldersTabsPage);
     m_pages.append(previewsPage);
     m_pages.append(confirmationsPage);
+
+#if HAVE_BALOO
+    m_pages.append(panelPage);
+#endif
+
     m_pages.append(statusAndLocationBarsPage);
 
     topLayout->addWidget(tabWidget, 0, {});
diff --git a/src/settings/interface/panelsettingspage.cpp b/src/settings/interface/panelsettingspage.cpp
new file mode 100644 (file)
index 0000000..3cd1536
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Benedikt Thiemer <numerfolt@posteo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "panelsettingspage.h"
+#include "dolphin_informationpanelsettings.h"
+#include "global.h"
+#include "kformat.h"
+#include "qbuttongroup.h"
+
+#include <KLocalizedString>
+
+#include <QCheckBox>
+#include <QFormLayout>
+#include <QLabel>
+#include <QRadioButton>
+#include <QSpacerItem>
+
+PanelSettingsPage::PanelSettingsPage(QWidget *parent)
+    : SettingsPageBase(parent)
+    , m_showPreview(nullptr)
+    , m_autoPlayMedia(nullptr)
+    , m_showHovered(nullptr)
+    , m_dateFormatLong(nullptr)
+    , m_dateFormatShort(nullptr)
+
+{
+    QFormLayout *topLayout = new QFormLayout(this);
+
+    QString m_longDateTime = (new KFormat)->formatRelativeDateTime(QDateTime(QDate(2024, 02, 28), QTime(10, 0)), QLocale::LongFormat);
+    QString m_shortDateTime = (new KFormat)->formatRelativeDateTime(QDateTime(QDate(2024, 02, 28), QTime(10, 0)), QLocale::ShortFormat);
+
+    m_showPreview = new QCheckBox(i18nc("@option:check", "Show previews"), this);
+    m_autoPlayMedia = new QCheckBox(i18nc("@option:check", "Auto-play media files"), this);
+    m_showHovered = new QCheckBox(i18nc("@option:check", "Show item on hover"), this);
+    m_dateFormatLong = new QRadioButton(i18nc("@option:check", "Use &long date, for example '%1'", m_longDateTime), this);
+    m_dateFormatShort = new QRadioButton(i18nc("@option:check", "Use &condensed date, for example '%1'", m_shortDateTime), this);
+
+    QButtonGroup *dateFormatGroup = new QButtonGroup(this);
+    dateFormatGroup->addButton(m_dateFormatLong);
+    dateFormatGroup->addButton(m_dateFormatShort);
+
+    topLayout->addRow(i18nc("@label:checkbox", "Information Panel:"), m_showPreview);
+    topLayout->addRow(QString(), m_autoPlayMedia);
+    topLayout->addRow(QString(), m_showHovered);
+    topLayout->addRow(QString(), m_dateFormatLong);
+    topLayout->addRow(QString(), m_dateFormatShort);
+    topLayout->addItem(new QSpacerItem(0, Dolphin::VERTICAL_SPACER_HEIGHT, QSizePolicy::Fixed, QSizePolicy::Fixed));
+
+    QLabel *contextMenuHint =
+        new QLabel(i18nc("@info", "Panel settings are also available through their context menu. Open it by pressing the right mouse button on a panel."),
+                   this);
+    contextMenuHint->setWordWrap(true);
+    topLayout->addRow(contextMenuHint);
+
+    loadSettings();
+
+    connect(m_showPreview, &QCheckBox::toggled, this, &PanelSettingsPage::changed);
+    connect(m_showPreview, &QCheckBox::toggled, this, &PanelSettingsPage::showPreviewToggled);
+    connect(m_autoPlayMedia, &QCheckBox::toggled, this, &PanelSettingsPage::changed);
+    connect(m_showHovered, &QCheckBox::toggled, this, &PanelSettingsPage::changed);
+    connect(m_dateFormatLong, &QRadioButton::toggled, this, &PanelSettingsPage::changed);
+    connect(m_dateFormatShort, &QRadioButton::toggled, this, &PanelSettingsPage::changed);
+}
+
+PanelSettingsPage::~PanelSettingsPage()
+{
+}
+
+void PanelSettingsPage::applySettings()
+{
+    InformationPanelSettings *settings = InformationPanelSettings::self();
+    settings->setPreviewsShown(m_showPreview->isChecked());
+    settings->setPreviewsAutoPlay(m_autoPlayMedia->isChecked());
+    settings->setShowHovered(m_showHovered->isChecked());
+    settings->setDateFormat(m_dateFormatShort->isChecked());
+    settings->save();
+}
+
+void PanelSettingsPage::restoreDefaults()
+{
+    InformationPanelSettings *settings = InformationPanelSettings::self();
+    settings->useDefaults(true);
+    loadSettings();
+    settings->useDefaults(false);
+}
+
+void PanelSettingsPage::loadSettings()
+{
+    m_showPreview->setChecked(InformationPanelSettings::previewsShown());
+    m_autoPlayMedia->setChecked(InformationPanelSettings::previewsAutoPlay());
+    m_autoPlayMedia->setEnabled(InformationPanelSettings::previewsShown());
+    m_showHovered->setChecked(InformationPanelSettings::showHovered());
+    m_dateFormatLong->setChecked(!InformationPanelSettings::dateFormat());
+    m_dateFormatShort->setChecked(InformationPanelSettings::dateFormat());
+}
+
+void PanelSettingsPage::showPreviewToggled()
+{
+    const bool checked = m_showPreview->isChecked();
+    m_autoPlayMedia->setEnabled(checked);
+}
+
+#include "moc_panelsettingspage.cpp"
diff --git a/src/settings/interface/panelsettingspage.h b/src/settings/interface/panelsettingspage.h
new file mode 100644 (file)
index 0000000..b2d0265
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Benedikt Thiemer <numerfolt@posteo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef PANELSETTINGSPAGE_H
+#define PANELSETTINGSPAGE_H
+
+#include "config-dolphin.h"
+#include "settings/settingspagebase.h"
+
+class QCheckBox;
+class QRadioButton;
+
+/**
+ * @brief Page for the information panel.
+ */
+class PanelSettingsPage : public SettingsPageBase
+{
+    Q_OBJECT
+
+public:
+    explicit PanelSettingsPage(QWidget *parent = nullptr);
+    ~PanelSettingsPage() override;
+
+    /** @see SettingsPageBase::applySettings() */
+    void applySettings() override;
+
+    /** @see SettingsPageBase::restoreDefaults() */
+    void restoreDefaults() override;
+
+private:
+    void loadSettings();
+    void showPreviewToggled();
+
+private:
+    QCheckBox *m_showPreview;
+    QCheckBox *m_autoPlayMedia;
+    QCheckBox *m_showHovered;
+    QRadioButton *m_dateFormatLong;
+    QRadioButton *m_dateFormatShort;
+};
+
+#endif