File indexing completed on 2025-02-02 04:26:10
0001 /* 0002 * SPDX-FileCopyrightText: 2019 David Redondo <kde@david-redondo.de> 0003 * SPDX-FileCopyrightText: 2015 Boudhayan Gupta <bgupta@kde.org> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "SettingsDialog.h" 0009 0010 #include "GeneralOptionsPage.h" 0011 #include "ImageSaveOptionsPage.h" 0012 #include "VideoSaveOptionsPage.h" 0013 #include "ShortcutsOptionsPage.h" 0014 #include "settings.h" 0015 0016 #include <QFontDatabase> 0017 #include <QScreen> 0018 #include <QStyle> 0019 #include <QWindow> 0020 0021 #include <KLocalizedString> 0022 #include <KShortcutWidget> 0023 0024 using namespace Qt::StringLiterals; 0025 0026 SettingsDialog::SettingsDialog(QWidget *parent) 0027 : KConfigDialog(parent, "settings"_L1, Settings::self()) 0028 , m_generalPage(new GeneralOptionsPage(this)) 0029 , m_imagesPage(new ImageSaveOptionsPage(this)) 0030 , m_videosPage(new VideoSaveOptionsPage(this)) 0031 , m_shortcutsPage(new ShortcutsOptionsPage(this)) 0032 { 0033 setFaceType(KPageDialog::List); 0034 addPage(m_generalPage, Settings::self(), i18nc("Settings category", "General"), "spectacle"_L1); 0035 addPage(m_imagesPage, Settings::self(), i18nc("Settings category", "Image Saving"), "image-x-generic"_L1); 0036 addPage(m_videosPage, Settings::self(), i18nc("Settings category", "Video Saving"), "video-x-generic"_L1); 0037 addPage(m_shortcutsPage, i18nc("Settings category", "Shortcuts"), "preferences-desktop-keyboard"_L1); 0038 connect(m_shortcutsPage, &ShortcutsOptionsPage::shortCutsChanged, this, [this] { 0039 updateButtons(); 0040 }); 0041 connect(this, &KConfigDialog::currentPageChanged, this, &SettingsDialog::updateButtons); 0042 } 0043 0044 QSize SettingsDialog::sizeHint() const 0045 { 0046 // Avoid having pages that need to be scrolled, 0047 // unless size is larger than available screen height. 0048 const auto headerSize = pageWidget()->pageHeader()->sizeHint(); 0049 const auto footerSize = pageWidget()->pageFooter()->sizeHint(); 0050 auto sh = m_generalPage->sizeHint(); 0051 sh = sh.expandedTo(m_imagesPage->sizeHint()); 0052 sh = sh.expandedTo(m_videosPage->sizeHint()); 0053 sh = sh.expandedTo(m_shortcutsPage->sizeHint()); 0054 sh.rheight() += headerSize.height() + footerSize.height() 0055 + style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing) * 2; 0056 sh = KConfigDialog::sizeHint().expandedTo(sh); 0057 const auto screenHeight = screen() ? screen()->availableGeometry().height() : 0; 0058 sh.setHeight(std::min(sh.height(), screenHeight)); 0059 return sh; 0060 } 0061 0062 void SettingsDialog::showEvent(QShowEvent *event) 0063 { 0064 auto parent = parentWidget(); 0065 bool onTop = parent && parent->windowHandle()->flags().testFlag(Qt::WindowStaysOnTopHint); 0066 windowHandle()->setFlag(Qt::WindowStaysOnTopHint, onTop); 0067 KConfigDialog::showEvent(event); 0068 } 0069 0070 bool SettingsDialog::hasChanged() 0071 { 0072 return m_shortcutsPage->isModified() || KConfigDialog::hasChanged(); 0073 } 0074 0075 bool SettingsDialog::isDefault() 0076 { 0077 return currentPage()->name() != i18n("Shortcuts") && KConfigDialog::isDefault(); 0078 } 0079 0080 void SettingsDialog::updateSettings() 0081 { 0082 KConfigDialog::updateSettings(); 0083 m_shortcutsPage->saveChanges(); 0084 } 0085 0086 void SettingsDialog::updateWidgets() 0087 { 0088 KConfigDialog::updateWidgets(); 0089 m_shortcutsPage->resetChanges(); 0090 } 0091 0092 void SettingsDialog::updateWidgetsDefault() 0093 { 0094 KConfigDialog::updateWidgetsDefault(); 0095 m_shortcutsPage->defaults(); 0096 } 0097 0098 #include "moc_SettingsDialog.cpp"