diff --git a/src/settings/viewmodes/dolphinfontrequester.cpp b/src/settings/viewmodes/dolphinfontrequester.cpp index 0a9eb166c..ff42e39aa 100644 --- a/src/settings/viewmodes/dolphinfontrequester.cpp +++ b/src/settings/viewmodes/dolphinfontrequester.cpp @@ -1,103 +1,103 @@ /*************************************************************************** * Copyright (C) 2008 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "dolphinfontrequester.h" -#include #include +#include #include #include #include #include DolphinFontRequester::DolphinFontRequester(QWidget* parent) : QWidget(parent), m_modeCombo(nullptr), m_chooseFontButton(nullptr), m_mode(SystemFont), m_customFont() { QHBoxLayout* topLayout = new QHBoxLayout(this); topLayout->setMargin(0); - m_modeCombo = new KComboBox(this); + m_modeCombo = new QComboBox(this); m_modeCombo->addItem(i18nc("@item:inlistbox Font", "System Font")); m_modeCombo->addItem(i18nc("@item:inlistbox Font", "Custom Font")); - connect(m_modeCombo, static_cast(&KComboBox::activated), + connect(m_modeCombo, static_cast(&QComboBox::activated), this, &DolphinFontRequester::changeMode); m_chooseFontButton = new QPushButton(i18nc("@action:button Choose font", "Choose..."), this); connect(m_chooseFontButton, &QPushButton::clicked, this, &DolphinFontRequester::openFontDialog); changeMode(m_modeCombo->currentIndex()); topLayout->addWidget(m_modeCombo); topLayout->addWidget(m_chooseFontButton); } DolphinFontRequester::~DolphinFontRequester() { } void DolphinFontRequester::setMode(Mode mode) { m_mode = mode; m_modeCombo->setCurrentIndex(m_mode); m_chooseFontButton->setEnabled(m_mode == CustomFont); } DolphinFontRequester::Mode DolphinFontRequester::mode() const { return m_mode; } QFont DolphinFontRequester::currentFont() const { return (m_mode == CustomFont) ? m_customFont : QFontDatabase::systemFont(QFontDatabase::GeneralFont); } void DolphinFontRequester::setCustomFont(const QFont& font) { m_customFont = font; } QFont DolphinFontRequester::customFont() const { return m_customFont; } void DolphinFontRequester::openFontDialog() { bool ok = false; const QFont font = QFontDialog::getFont(&ok, this); if (ok) { m_customFont = font; m_modeCombo->setFont(m_customFont); emit changed(); } } void DolphinFontRequester::changeMode(int index) { setMode((index == CustomFont) ? CustomFont : SystemFont); emit changed(); } diff --git a/src/settings/viewmodes/dolphinfontrequester.h b/src/settings/viewmodes/dolphinfontrequester.h index 6f1b8400e..ac7ef222a 100644 --- a/src/settings/viewmodes/dolphinfontrequester.h +++ b/src/settings/viewmodes/dolphinfontrequester.h @@ -1,75 +1,75 @@ /*************************************************************************** * Copyright (C) 2008 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef DOLPHINFONTREQUESTER_H #define DOLPHINFONTREQUESTER_H #include #include -class KComboBox; +class QComboBox; class QPushButton; /** * @brief Allows to select between using the system font or a custom font. */ class DolphinFontRequester : public QWidget { Q_OBJECT public: enum Mode { SystemFont = 0, CustomFont = 1 }; explicit DolphinFontRequester(QWidget* parent); ~DolphinFontRequester() override; void setMode(Mode mode); Mode mode() const; /** * Returns the custom font (see DolphinFontRequester::customFont()), * if the mode is \a CustomFont, otherwise the system font is * returned. */ QFont currentFont() const; void setCustomFont(const QFont& font); QFont customFont() const; signals: /** Is emitted, if the font has been changed. */ void changed(); private slots: void openFontDialog(); void changeMode(int index); private: - KComboBox* m_modeCombo; + QComboBox* m_modeCombo; QPushButton* m_chooseFontButton; Mode m_mode; QFont m_customFont; }; #endif diff --git a/src/settings/viewmodes/viewsettingstab.cpp b/src/settings/viewmodes/viewsettingstab.cpp index 85af5b083..3971c8ed8 100644 --- a/src/settings/viewmodes/viewsettingstab.cpp +++ b/src/settings/viewmodes/viewsettingstab.cpp @@ -1,291 +1,291 @@ /*************************************************************************** * Copyright (C) 2008-2011 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "viewsettingstab.h" #include "dolphin_compactmodesettings.h" #include "dolphin_detailsmodesettings.h" #include "dolphin_iconsmodesettings.h" #include "dolphinfontrequester.h" #include "views/zoomlevelinfo.h" -#include #include #include #include +#include #include #include #include #include ViewSettingsTab::ViewSettingsTab(Mode mode, QWidget* parent) : QWidget(parent), m_mode(mode), m_defaultSizeSlider(nullptr), m_previewSizeSlider(nullptr), m_fontRequester(nullptr), m_widthBox(nullptr), m_maxLinesBox(nullptr), m_expandableFolders(nullptr) { QVBoxLayout* topLayout = new QVBoxLayout(this); // Create "Icon Size" group QGroupBox* iconSizeGroup = new QGroupBox(this); iconSizeGroup->setTitle(i18nc("@title:group", "Icon Size")); const int minRange = ZoomLevelInfo::minimumLevel(); const int maxRange = ZoomLevelInfo::maximumLevel(); QLabel* defaultLabel = new QLabel(i18nc("@label:listbox", "Default:"), this); m_defaultSizeSlider = new QSlider(Qt::Horizontal, this); m_defaultSizeSlider->setPageStep(1); m_defaultSizeSlider->setTickPosition(QSlider::TicksBelow); m_defaultSizeSlider->setRange(minRange, maxRange); connect(m_defaultSizeSlider, &QSlider::valueChanged, this, &ViewSettingsTab::slotDefaultSliderMoved); QLabel* previewLabel = new QLabel(i18nc("@label:listbox", "Preview:"), this); m_previewSizeSlider = new QSlider(Qt::Horizontal, this); m_previewSizeSlider->setPageStep(1); m_previewSizeSlider->setTickPosition(QSlider::TicksBelow); m_previewSizeSlider->setRange(minRange, maxRange); connect(m_previewSizeSlider, &QSlider::valueChanged, this, &ViewSettingsTab::slotPreviewSliderMoved); QGridLayout* layout = new QGridLayout(iconSizeGroup); layout->addWidget(defaultLabel, 0, 0, Qt::AlignRight); layout->addWidget(m_defaultSizeSlider, 0, 1); layout->addWidget(previewLabel, 1, 0, Qt::AlignRight); layout->addWidget(m_previewSizeSlider, 1, 1); // Create "Text" group QGroupBox* textGroup = new QGroupBox(i18nc("@title:group", "Text"), this); QLabel* fontLabel = new QLabel(i18nc("@label:listbox", "Font:"), textGroup); m_fontRequester = new DolphinFontRequester(textGroup); QGridLayout* textGroupLayout = new QGridLayout(textGroup); textGroupLayout->addWidget(fontLabel, 0, 0, Qt::AlignRight); textGroupLayout->addWidget(m_fontRequester, 0, 1); switch (m_mode) { case IconsMode: { QLabel* widthLabel = new QLabel(i18nc("@label:listbox", "Width:"), textGroup); - m_widthBox = new KComboBox(textGroup); + m_widthBox = new QComboBox(textGroup); m_widthBox->addItem(i18nc("@item:inlistbox Text width", "Small")); m_widthBox->addItem(i18nc("@item:inlistbox Text width", "Medium")); m_widthBox->addItem(i18nc("@item:inlistbox Text width", "Large")); m_widthBox->addItem(i18nc("@item:inlistbox Text width", "Huge")); QLabel* maxLinesLabel = new QLabel(i18nc("@label:listbox", "Maximum lines:"), textGroup); - m_maxLinesBox = new KComboBox(textGroup); + m_maxLinesBox = new QComboBox(textGroup); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "Unlimited")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "1")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "2")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "3")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "4")); m_maxLinesBox->addItem(i18nc("@item:inlistbox Maximum lines", "5")); textGroupLayout->addWidget(widthLabel, 2, 0, Qt::AlignRight); textGroupLayout->addWidget(m_widthBox, 2, 1); textGroupLayout->addWidget(maxLinesLabel, 3, 0, Qt::AlignRight); textGroupLayout->addWidget(m_maxLinesBox, 3, 1); break; } case CompactMode: { QLabel* maxWidthLabel = new QLabel(i18nc("@label:listbox", "Maximum width:"), textGroup); - m_widthBox = new KComboBox(textGroup); + m_widthBox = new QComboBox(textGroup); m_widthBox->addItem(i18nc("@item:inlistbox Maximum width", "Unlimited")); m_widthBox->addItem(i18nc("@item:inlistbox Maximum width", "Small")); m_widthBox->addItem(i18nc("@item:inlistbox Maximum width", "Medium")); m_widthBox->addItem(i18nc("@item:inlistbox Maximum width", "Large")); textGroupLayout->addWidget(maxWidthLabel, 2, 0, Qt::AlignRight); textGroupLayout->addWidget(m_widthBox, 2, 1); break; } case DetailsMode: m_expandableFolders = new QCheckBox(i18nc("@option:check", "Expandable folders"), this); break; default: break; } topLayout->addWidget(iconSizeGroup); topLayout->addWidget(textGroup); if (m_expandableFolders) { topLayout->addWidget(m_expandableFolders); } topLayout->addStretch(1); loadSettings(); connect(m_defaultSizeSlider, &QSlider::valueChanged, this, &ViewSettingsTab::changed); connect(m_previewSizeSlider, &QSlider::valueChanged, this, &ViewSettingsTab::changed); connect(m_fontRequester, &DolphinFontRequester::changed, this, &ViewSettingsTab::changed); switch (m_mode) { case IconsMode: - connect(m_widthBox, static_cast(&KComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); - connect(m_maxLinesBox, static_cast(&KComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); + connect(m_widthBox, static_cast(&QComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); + connect(m_maxLinesBox, static_cast(&QComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); break; case CompactMode: - connect(m_widthBox, static_cast(&KComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); + connect(m_widthBox, static_cast(&QComboBox::currentIndexChanged), this, &ViewSettingsTab::changed); break; case DetailsMode: connect(m_expandableFolders, &QCheckBox::toggled, this, &ViewSettingsTab::changed); break; default: break; } } ViewSettingsTab::~ViewSettingsTab() { } void ViewSettingsTab::applySettings() { const QFont font = m_fontRequester->currentFont(); const bool useSystemFont = (m_fontRequester->mode() == DolphinFontRequester::SystemFont); switch (m_mode) { case IconsMode: IconsModeSettings::setTextWidthIndex(m_widthBox->currentIndex()); IconsModeSettings::setMaximumTextLines(m_maxLinesBox->currentIndex()); break; case CompactMode: CompactModeSettings::setMaximumTextWidthIndex(m_widthBox->currentIndex()); break; case DetailsMode: DetailsModeSettings::setExpandableFolders(m_expandableFolders->isChecked()); break; default: break; } ViewModeSettings settings(viewMode()); const int iconSize = ZoomLevelInfo::iconSizeForZoomLevel(m_defaultSizeSlider->value()); const int previewSize = ZoomLevelInfo::iconSizeForZoomLevel(m_previewSizeSlider->value()); settings.setIconSize(iconSize); settings.setPreviewSize(previewSize); settings.setUseSystemFont(useSystemFont); settings.setFontFamily(font.family()); settings.setFontSize(font.pointSizeF()); settings.setItalicFont(font.italic()); settings.setFontWeight(font.weight()); settings.save(); } void ViewSettingsTab::restoreDefaultSettings() { KConfigSkeleton* settings = nullptr; switch (m_mode) { case IconsMode: settings = IconsModeSettings::self(); break; case CompactMode: settings = CompactModeSettings::self(); break; case DetailsMode: settings = DetailsModeSettings::self(); break; default: Q_ASSERT(false); break; } settings->useDefaults(true); loadSettings(); settings->useDefaults(false); } void ViewSettingsTab::loadSettings() { switch (m_mode) { case IconsMode: m_widthBox->setCurrentIndex(IconsModeSettings::textWidthIndex()); m_maxLinesBox->setCurrentIndex(IconsModeSettings::maximumTextLines()); break; case CompactMode: m_widthBox->setCurrentIndex(CompactModeSettings::maximumTextWidthIndex()); break; case DetailsMode: m_expandableFolders->setChecked(DetailsModeSettings::expandableFolders()); break; default: break; } const ViewModeSettings settings(viewMode()); const QSize iconSize(settings.iconSize(), settings.iconSize()); m_defaultSizeSlider->setValue(ZoomLevelInfo::zoomLevelForIconSize(iconSize)); const QSize previewSize(settings.previewSize(), settings.previewSize()); m_previewSizeSlider->setValue(ZoomLevelInfo::zoomLevelForIconSize(previewSize)); m_fontRequester->setMode(settings.useSystemFont() ? DolphinFontRequester::SystemFont : DolphinFontRequester::CustomFont); QFont font(settings.fontFamily(), qRound(settings.fontSize())); font.setItalic(settings.italicFont()); font.setWeight(settings.fontWeight()); font.setPointSizeF(settings.fontSize()); m_fontRequester->setCustomFont(font); } ViewModeSettings::ViewMode ViewSettingsTab::viewMode() const { ViewModeSettings::ViewMode mode; switch (m_mode) { case ViewSettingsTab::IconsMode: mode = ViewModeSettings::IconsMode; break; case ViewSettingsTab::CompactMode: mode = ViewModeSettings::CompactMode; break; case ViewSettingsTab::DetailsMode: mode = ViewModeSettings::DetailsMode; break; default: mode = ViewModeSettings::IconsMode; Q_ASSERT(false); break; } return mode; } void ViewSettingsTab::slotDefaultSliderMoved(int value) { showToolTip(m_defaultSizeSlider, value); } void ViewSettingsTab::slotPreviewSliderMoved(int value) { showToolTip(m_previewSizeSlider, value); } void ViewSettingsTab::showToolTip(QSlider* slider, int value) { const int size = ZoomLevelInfo::iconSizeForZoomLevel(value); slider->setToolTip(i18ncp("@info:tooltip", "Size: 1 pixel", "Size: %1 pixels", size)); if (!slider->isVisible()) { return; } QPoint global = slider->rect().topLeft(); global.ry() += slider->height() / 2; QHelpEvent toolTipEvent(QEvent::ToolTip, QPoint(0, 0), slider->mapToGlobal(global)); QApplication::sendEvent(slider, &toolTipEvent); } diff --git a/src/settings/viewmodes/viewsettingstab.h b/src/settings/viewmodes/viewsettingstab.h index 0c1b8a3b5..fff882e5e 100644 --- a/src/settings/viewmodes/viewsettingstab.h +++ b/src/settings/viewmodes/viewsettingstab.h @@ -1,77 +1,77 @@ /*************************************************************************** * Copyright (C) 2008-2011 by Peter Penz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef VIEWSETTINGSTAB_H #define VIEWSETTINGSTAB_H #include "settings/viewmodes/viewmodesettings.h" #include class DolphinFontRequester; -class KComboBox; +class QComboBox; class QCheckBox; class QSlider; /** * @brief Represents one tab of the view-settings page. */ class ViewSettingsTab : public QWidget { Q_OBJECT public: enum Mode { IconsMode, CompactMode, DetailsMode }; explicit ViewSettingsTab(Mode mode, QWidget* parent = nullptr); ~ViewSettingsTab() override; void applySettings(); void restoreDefaultSettings(); signals: void changed(); private slots: void slotDefaultSliderMoved(int value); void slotPreviewSliderMoved(int value); private: void loadSettings(); void showToolTip(QSlider* slider, int value); ViewModeSettings::ViewMode viewMode() const; private: Mode m_mode; QSlider* m_defaultSizeSlider; QSlider* m_previewSizeSlider; DolphinFontRequester* m_fontRequester; - KComboBox* m_widthBox; - KComboBox* m_maxLinesBox; + QComboBox* m_widthBox; + QComboBox* m_maxLinesBox; QCheckBox* m_expandableFolders; }; #endif diff --git a/src/settings/viewpropertiesdialog.cpp b/src/settings/viewpropertiesdialog.cpp index 88dea041a..f22287912 100644 --- a/src/settings/viewpropertiesdialog.cpp +++ b/src/settings/viewpropertiesdialog.cpp @@ -1,458 +1,458 @@ /*************************************************************************** * Copyright (C) 2006 by Peter Penz * * Copyright (C) 2018 by Elvis Angelaccio * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #include "viewpropertiesdialog.h" #include "dolphin_generalsettings.h" #include "dolphin_iconsmodesettings.h" #include "kitemviews/kfileitemmodel.h" #include "viewpropsprogressinfo.h" #include "views/dolphinview.h" #include -#include #include #include #include #ifdef HAVE_BALOO #include #endif #include #include +#include #include #include #include #include #include #include #include ViewPropertiesDialog::ViewPropertiesDialog(DolphinView* dolphinView) : QDialog(dolphinView), m_isDirty(false), m_dolphinView(dolphinView), m_viewProps(nullptr), m_viewMode(nullptr), m_sortOrder(nullptr), m_sorting(nullptr), m_sortFoldersFirst(nullptr), m_previewsShown(nullptr), m_showInGroups(nullptr), m_showHiddenFiles(nullptr), m_applyToCurrentFolder(nullptr), m_applyToSubFolders(nullptr), m_applyToAllFolders(nullptr), m_useAsDefault(nullptr) { Q_ASSERT(dolphinView); const bool useGlobalViewProps = GeneralSettings::globalViewProps(); setWindowTitle(i18nc("@title:window", "View Properties")); const QUrl& url = dolphinView->url(); m_viewProps = new ViewProperties(url); m_viewProps->setAutoSaveEnabled(false); auto layout = new QVBoxLayout(this); // Otherwise the dialog won't resize when we collapse the KCollapsibleGroupBox. layout->setSizeConstraint(QLayout::SetFixedSize); setLayout(layout); auto propsGrid = new QWidget(this); layout->addWidget(propsGrid); // create 'Properties' group containing view mode, sorting, sort order and show hidden files QWidget* propsBox = this; if (!useGlobalViewProps) { propsBox = new QGroupBox(i18nc("@title:group", "Properties"), this); layout->addWidget(propsBox); } QLabel* viewModeLabel = new QLabel(i18nc("@label:listbox", "View mode:"), propsGrid); - m_viewMode = new KComboBox(propsGrid); + m_viewMode = new QComboBox(propsGrid); m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-icons")), i18nc("@item:inlistbox", "Icons"), DolphinView::IconsView); m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-details")), i18nc("@item:inlistbox", "Compact"), DolphinView::CompactView); m_viewMode->addItem(QIcon::fromTheme(QStringLiteral("view-list-tree")), i18nc("@item:inlistbox", "Details"), DolphinView::DetailsView); QLabel* sortingLabel = new QLabel(i18nc("@label:listbox", "Sorting:"), propsGrid); QWidget* sortingBox = new QWidget(propsGrid); - m_sortOrder = new KComboBox(sortingBox); + m_sortOrder = new QComboBox(sortingBox); m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Ascending")); m_sortOrder->addItem(i18nc("@item:inlistbox Sort", "Descending")); - m_sorting = new KComboBox(sortingBox); + m_sorting = new QComboBox(sortingBox); const QList rolesInfo = KFileItemModel::rolesInformation(); foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { m_sorting->addItem(info.translation, info.role); } m_sortFoldersFirst = new QCheckBox(i18nc("@option:check", "Show folders first")); m_previewsShown = new QCheckBox(i18nc("@option:check", "Show preview")); m_showInGroups = new QCheckBox(i18nc("@option:check", "Show in groups")); m_showHiddenFiles = new QCheckBox(i18nc("@option:check", "Show hidden files")); auto additionalInfoBox = new KCollapsibleGroupBox(); additionalInfoBox->setTitle(i18nc("@title:group", "Additional Information Shown")); auto innerLayout = new QVBoxLayout(); { QList visibleRoles = m_viewProps->visibleRoles(); const bool useDefaultRoles = (m_viewProps->viewMode() == DolphinView::DetailsView) && visibleRoles.isEmpty(); if (useDefaultRoles) { // Using the details view without any additional information (-> additional column) // makes no sense and leads to a usability problem as no viewport area is available // anymore. Hence as fallback provide at least a size and date column. visibleRoles.clear(); visibleRoles.append("text"); visibleRoles.append("size"); visibleRoles.append("modificationtime"); m_viewProps->setVisibleRoles(visibleRoles); } // Add checkboxes bool indexingEnabled = false; #ifdef HAVE_BALOO Baloo::IndexerConfig config; indexingEnabled = config.fileIndexingEnabled(); #endif m_listWidget = new QListWidget(); connect(m_listWidget, &QListWidget::itemChanged, this, &ViewPropertiesDialog::slotItemChanged); m_listWidget->setSelectionMode(QAbstractItemView::NoSelection); const QList rolesInfo = KFileItemModel::rolesInformation(); foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { QListWidgetItem* item = new QListWidgetItem(info.translation, m_listWidget); item->setCheckState(visibleRoles.contains(info.role) ? Qt::Checked : Qt::Unchecked); const bool enable = ((!info.requiresBaloo && !info.requiresIndexer) || (info.requiresBaloo) || (info.requiresIndexer && indexingEnabled)) && info.role != "text"; if (!enable) { item->setFlags(item->flags() & ~Qt::ItemIsEnabled); } } innerLayout->addWidget(m_listWidget); } additionalInfoBox->setLayout(innerLayout); QHBoxLayout* sortingLayout = new QHBoxLayout(); sortingLayout->setMargin(0); sortingLayout->addWidget(m_sortOrder); sortingLayout->addWidget(m_sorting); sortingBox->setLayout(sortingLayout); QGridLayout* propsGridLayout = new QGridLayout(propsGrid); propsGridLayout->addWidget(viewModeLabel, 0, 0, Qt::AlignRight); propsGridLayout->addWidget(m_viewMode, 0, 1); propsGridLayout->addWidget(sortingLabel, 1, 0, Qt::AlignRight); propsGridLayout->addWidget(sortingBox, 1, 1); QVBoxLayout* propsBoxLayout = propsBox == this ? layout : new QVBoxLayout(propsBox); propsBoxLayout->addWidget(propsGrid); propsBoxLayout->addWidget(m_sortFoldersFirst); propsBoxLayout->addWidget(m_previewsShown); propsBoxLayout->addWidget(m_showInGroups); propsBoxLayout->addWidget(m_showHiddenFiles); propsBoxLayout->addWidget(additionalInfoBox); - connect(m_viewMode, static_cast(&KComboBox::currentIndexChanged), + connect(m_viewMode, static_cast(&QComboBox::currentIndexChanged), this, &ViewPropertiesDialog::slotViewModeChanged); - connect(m_sorting, static_cast(&KComboBox::currentIndexChanged), + connect(m_sorting, static_cast(&QComboBox::currentIndexChanged), this, &ViewPropertiesDialog::slotSortingChanged); - connect(m_sortOrder, static_cast(&KComboBox::currentIndexChanged), + connect(m_sortOrder, static_cast(&QComboBox::currentIndexChanged), this, &ViewPropertiesDialog::slotSortOrderChanged); connect(m_sortFoldersFirst, &QCheckBox::clicked, this, &ViewPropertiesDialog::slotSortFoldersFirstChanged); connect(m_previewsShown, &QCheckBox::clicked, this, &ViewPropertiesDialog::slotShowPreviewChanged); connect(m_showInGroups, &QCheckBox::clicked, this, &ViewPropertiesDialog::slotGroupedSortingChanged); connect(m_showHiddenFiles, &QCheckBox::clicked, this, &ViewPropertiesDialog::slotShowHiddenFilesChanged); // Only show the following settings if the view properties are remembered // for each directory: if (!useGlobalViewProps) { // create 'Apply View Properties To' group QGroupBox* applyBox = new QGroupBox(i18nc("@title:group", "Apply View Properties To"), this); layout->addWidget(applyBox); m_applyToCurrentFolder = new QRadioButton(i18nc("@option:radio Apply View Properties To", "Current folder"), applyBox); m_applyToCurrentFolder->setChecked(true); m_applyToSubFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To", "Current folder including all sub-folders"), applyBox); m_applyToAllFolders = new QRadioButton(i18nc("@option:radio Apply View Properties To", "All folders"), applyBox); QButtonGroup* applyGroup = new QButtonGroup(this); applyGroup->addButton(m_applyToCurrentFolder); applyGroup->addButton(m_applyToSubFolders); applyGroup->addButton(m_applyToAllFolders); QVBoxLayout* applyBoxLayout = new QVBoxLayout(applyBox); applyBoxLayout->addWidget(m_applyToCurrentFolder); applyBoxLayout->addWidget(m_applyToSubFolders); applyBoxLayout->addWidget(m_applyToAllFolders); m_useAsDefault = new QCheckBox(i18nc("@option:check", "Use these view properties as default"), this); layout->addWidget(m_useAsDefault); connect(m_applyToCurrentFolder, &QRadioButton::clicked, this, &ViewPropertiesDialog::markAsDirty); connect(m_applyToSubFolders, &QRadioButton::clicked, this, &ViewPropertiesDialog::markAsDirty); connect(m_applyToAllFolders, &QRadioButton::clicked, this, &ViewPropertiesDialog::markAsDirty); connect(m_useAsDefault, &QCheckBox::clicked, this, &ViewPropertiesDialog::markAsDirty); } layout->addStretch(); auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Apply, this); connect(buttonBox, &QDialogButtonBox::accepted, this, &ViewPropertiesDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &ViewPropertiesDialog::reject); layout->addWidget(buttonBox); auto okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setShortcut(Qt::CTRL + Qt::Key_Return); okButton->setDefault(true); auto applyButton = buttonBox->button(QDialogButtonBox::Apply); applyButton->setEnabled(false); connect(applyButton, &QPushButton::clicked, this, &ViewPropertiesDialog::slotApply); connect(this, &ViewPropertiesDialog::isDirtyChanged, applyButton, [applyButton](bool isDirty) { applyButton->setEnabled(isDirty); }); const KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "ViewPropertiesDialog"); KWindowConfig::restoreWindowSize(windowHandle(), dialogConfig); loadSettings(); } ViewPropertiesDialog::~ViewPropertiesDialog() { m_isDirty = false; delete m_viewProps; m_viewProps = nullptr; KConfigGroup dialogConfig(KSharedConfig::openConfig(QStringLiteral("dolphinrc")), "ViewPropertiesDialog"); KWindowConfig::saveWindowSize(windowHandle(), dialogConfig); } void ViewPropertiesDialog::accept() { applyViewProperties(); QDialog::accept(); } void ViewPropertiesDialog::slotApply() { applyViewProperties(); markAsDirty(false); } void ViewPropertiesDialog::slotViewModeChanged(int index) { const QVariant itemData = m_viewMode->itemData(index); const DolphinView::Mode viewMode = static_cast(itemData.toInt()); m_viewProps->setViewMode(viewMode); markAsDirty(true); } void ViewPropertiesDialog::slotSortingChanged(int index) { const QByteArray role = m_sorting->itemData(index).toByteArray(); m_viewProps->setSortRole(role); markAsDirty(true); } void ViewPropertiesDialog::slotSortOrderChanged(int index) { const Qt::SortOrder sortOrder = (index == 0) ? Qt::AscendingOrder : Qt::DescendingOrder; m_viewProps->setSortOrder(sortOrder); markAsDirty(true); } void ViewPropertiesDialog::slotGroupedSortingChanged() { m_viewProps->setGroupedSorting(m_showInGroups->isChecked()); markAsDirty(true); } void ViewPropertiesDialog::slotSortFoldersFirstChanged() { const bool foldersFirst = m_sortFoldersFirst->isChecked(); m_viewProps->setSortFoldersFirst(foldersFirst); markAsDirty(true); } void ViewPropertiesDialog::slotShowPreviewChanged() { const bool show = m_previewsShown->isChecked(); m_viewProps->setPreviewsShown(show); markAsDirty(true); } void ViewPropertiesDialog::slotShowHiddenFilesChanged() { const bool show = m_showHiddenFiles->isChecked(); m_viewProps->setHiddenFilesShown(show); markAsDirty(true); } void ViewPropertiesDialog::slotItemChanged(QListWidgetItem *item) { Q_UNUSED(item) markAsDirty(true); } void ViewPropertiesDialog::markAsDirty(bool isDirty) { if (m_isDirty != isDirty) { m_isDirty = isDirty; emit isDirtyChanged(isDirty); } } void ViewPropertiesDialog::applyViewProperties() { // if nothing changed in the dialog, we have nothing to apply if (!m_isDirty) { return; } // Update visible roles. { QList visibleRoles; int index = 0; const QList rolesInfo = KFileItemModel::rolesInformation(); foreach (const KFileItemModel::RoleInfo& info, rolesInfo) { const QListWidgetItem* item = m_listWidget->item(index); if (item->checkState() == Qt::Checked) { visibleRoles.append(info.role); } ++index; } m_viewProps->setVisibleRoles(visibleRoles); } const bool applyToSubFolders = m_applyToSubFolders && m_applyToSubFolders->isChecked(); if (applyToSubFolders) { const QString text(i18nc("@info", "The view properties of all sub-folders will be changed. Do you want to continue?")); if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { return; } ViewPropsProgressInfo* info = new ViewPropsProgressInfo(m_dolphinView, m_dolphinView->url(), *m_viewProps); info->setAttribute(Qt::WA_DeleteOnClose); info->setWindowModality(Qt::NonModal); info->show(); } const bool applyToAllFolders = m_applyToAllFolders && m_applyToAllFolders->isChecked(); // If the user selected 'Apply To All Folders' the view properties implicitely // are also used as default for new folders. const bool useAsDefault = applyToAllFolders || (m_useAsDefault && m_useAsDefault->isChecked()); if (useAsDefault) { // For directories where no .directory file is available, the .directory // file stored for the global view properties is used as fallback. To update // this file we temporary turn on the global view properties mode. Q_ASSERT(!GeneralSettings::globalViewProps()); GeneralSettings::setGlobalViewProps(true); ViewProperties defaultProps(m_dolphinView->url()); defaultProps.setDirProperties(*m_viewProps); defaultProps.save(); GeneralSettings::setGlobalViewProps(false); } if (applyToAllFolders) { const QString text(i18nc("@info", "The view properties of all folders will be changed. Do you want to continue?")); if (KMessageBox::questionYesNo(this, text) == KMessageBox::No) { return; } // Updating the global view properties time stamp in the general settings makes // all existing viewproperties invalid, as they have a smaller time stamp. GeneralSettings* settings = GeneralSettings::self(); settings->setViewPropsTimestamp(QDateTime::currentDateTime()); settings->save(); } m_dolphinView->setMode(m_viewProps->viewMode()); m_dolphinView->setSortRole(m_viewProps->sortRole()); m_dolphinView->setSortOrder(m_viewProps->sortOrder()); m_dolphinView->setSortFoldersFirst(m_viewProps->sortFoldersFirst()); m_dolphinView->setGroupedSorting(m_viewProps->groupedSorting()); m_dolphinView->setVisibleRoles(m_viewProps->visibleRoles()); m_dolphinView->setPreviewsShown(m_viewProps->previewsShown()); m_dolphinView->setHiddenFilesShown(m_viewProps->hiddenFilesShown()); m_viewProps->save(); markAsDirty(false); } void ViewPropertiesDialog::loadSettings() { // Load view mode switch (m_viewProps->viewMode()) { case DolphinView::IconsView: m_viewMode->setCurrentIndex(0); break; case DolphinView::CompactView: m_viewMode->setCurrentIndex(1); break; case DolphinView::DetailsView: m_viewMode->setCurrentIndex(2); break; default: break; } // Load sort order and sorting const int sortOrderIndex = (m_viewProps->sortOrder() == Qt::AscendingOrder) ? 0 : 1; m_sortOrder->setCurrentIndex(sortOrderIndex); const QList rolesInfo = KFileItemModel::rolesInformation(); int sortRoleIndex = 0; for (int i = 0; i < rolesInfo.count(); ++i) { if (rolesInfo[i].role == m_viewProps->sortRole()) { sortRoleIndex = i; break; } } m_sorting->setCurrentIndex(sortRoleIndex); m_sortFoldersFirst->setChecked(m_viewProps->sortFoldersFirst()); // Load show preview, show in groups and show hidden files settings m_previewsShown->setChecked(m_viewProps->previewsShown()); m_showInGroups->setChecked(m_viewProps->groupedSorting()); m_showHiddenFiles->setChecked(m_viewProps->hiddenFilesShown()); markAsDirty(false); } diff --git a/src/settings/viewpropertiesdialog.h b/src/settings/viewpropertiesdialog.h index 80cddbf4e..aabf21c90 100644 --- a/src/settings/viewpropertiesdialog.h +++ b/src/settings/viewpropertiesdialog.h @@ -1,93 +1,93 @@ /*************************************************************************** * Copyright (C) 2006 by Peter Penz * * Copyright (C) 2018 by Elvis Angelaccio * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * ***************************************************************************/ #ifndef VIEWPROPERTIESDIALOG_H #define VIEWPROPERTIESDIALOG_H #include "dolphin_export.h" #include class QCheckBox; class QListWidget; class QListWidgetItem; -class KComboBox; +class QComboBox; class QPushButton; class QRadioButton; class ViewProperties; class DolphinView; /** * @brief Dialog for changing the current view properties of a directory. * * It is possible to specify the view mode, the sorting order, whether hidden files * and previews should be shown. The properties can be assigned to the current folder, * or recursively to all sub folders. */ class DOLPHIN_EXPORT ViewPropertiesDialog : public QDialog { Q_OBJECT public: explicit ViewPropertiesDialog(DolphinView* dolphinView); ~ViewPropertiesDialog() override; public slots: void accept() override; private slots: void slotApply(); void slotViewModeChanged(int index); void slotSortingChanged(int index); void slotSortOrderChanged(int index); void slotGroupedSortingChanged(); void slotSortFoldersFirstChanged(); void slotShowPreviewChanged(); void slotShowHiddenFilesChanged(); void slotItemChanged(QListWidgetItem *item); void markAsDirty(bool isDirty); signals: void isDirtyChanged(bool isDirty); private: void applyViewProperties(); void loadSettings(); private: bool m_isDirty; DolphinView* m_dolphinView; ViewProperties* m_viewProps; - KComboBox* m_viewMode; - KComboBox* m_sortOrder; - KComboBox* m_sorting; + QComboBox* m_viewMode; + QComboBox* m_sortOrder; + QComboBox* m_sorting; QCheckBox* m_sortFoldersFirst; QCheckBox* m_previewsShown; QCheckBox* m_showInGroups; QCheckBox* m_showHiddenFiles; QRadioButton* m_applyToCurrentFolder; QRadioButton* m_applyToSubFolders; QRadioButton* m_applyToAllFolders; QCheckBox* m_useAsDefault; QListWidget* m_listWidget; }; #endif