File indexing completed on 2024-07-07 05:13:45

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "tabpreferenceshandler.h"
0007 
0008 //! local
0009 #include <coretypes.h>
0010 #include "ui_settingsdialog.h"
0011 #include "settingsdialog.h"
0012 #include "../universalsettings.h"
0013 #include "../actionsdialog/actionsdialog.h"
0014 #include "../../apptypes.h"
0015 #include "../../lattecorona.h"
0016 #include "../../plasma/extended/theme.h"
0017 
0018 
0019 namespace Latte {
0020 namespace Settings {
0021 namespace Handler {
0022 
0023 
0024 TabPreferences::TabPreferences(Latte::Settings::Dialog::SettingsDialog *parent)
0025     : Generic(parent),
0026       m_parentDialog(parent),
0027       m_corona(m_parentDialog->corona()),
0028       m_ui(m_parentDialog->ui())
0029 {
0030     initSettings();
0031     initUi();
0032 }
0033 
0034 void TabPreferences::initUi()
0035 {
0036     //! exclusive groups
0037     m_parabolicSpreadButtons = new QButtonGroup(this);
0038     m_parabolicSpreadButtons->addButton(m_ui->smallParabolicBtn, Data::Preferences::PARABOLICSPREAD);
0039     m_parabolicSpreadButtons->addButton(m_ui->mediumParabolicBtn, 5);
0040     m_parabolicSpreadButtons->addButton(m_ui->largeParabolicBtn, 7);
0041     m_parabolicSpreadButtons->setExclusive(true);
0042 
0043     m_thicknessMarginInfluenceButtons = new QButtonGroup(this);
0044     m_thicknessMarginInfluenceButtons->addButton(m_ui->noMarginInfluenceBtn, 0); // 0%
0045     m_thicknessMarginInfluenceButtons->addButton(m_ui->halfMarginInfluenceBtn, 50); // 50%
0046     m_thicknessMarginInfluenceButtons->addButton(m_ui->fullMarginInfluenceBtn, 100); // 100%
0047     m_thicknessMarginInfluenceButtons->setExclusive(true);
0048 
0049     m_ui->noMarginInfluenceBtn->setText(i18nc("number in percentage, e.g. 85%","%1%").arg(0));
0050     m_ui->halfMarginInfluenceBtn->setText(i18nc("number in percentage, e.g. 85%","%1%").arg(50));
0051     m_ui->fullMarginInfluenceBtn->setText(i18nc("number in percentage, e.g. 85%","%1%").arg(100));
0052 
0053     //! Buttons
0054     connect(m_ui->contextMenuActionsBtn, &QPushButton::clicked, this, &TabPreferences::onActionsBtnPressed);
0055 
0056     //! signals
0057     connect(m_parabolicSpreadButtons, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::buttonToggled),
0058             [ = ](int id, bool checked) {
0059         if (checked) {
0060             m_preferences.parabolicSpread = id;
0061             emit dataChanged();
0062         }
0063     });
0064 
0065     connect(m_thicknessMarginInfluenceButtons, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::buttonToggled),
0066             [ = ](int id, bool checked) {
0067         if (checked) {
0068             m_preferences.thicknessMarginInfluence = (id / 100.0f);
0069             emit dataChanged();
0070         }
0071     });
0072 
0073     connect(m_ui->screenTrackerSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), [ = ](int i) {
0074         m_preferences.screensDelay = m_ui->screenTrackerSpinBox->value();
0075         emit dataChanged();
0076     });
0077 
0078     connect(m_ui->autostartChkBox, &QCheckBox::stateChanged, this, [&]() {
0079         m_preferences.autostart = m_ui->autostartChkBox->isChecked();
0080         emit dataChanged();
0081     });
0082 
0083     connect(m_ui->badges3DStyleChkBox, &QCheckBox::stateChanged, this, [&]() {
0084         m_preferences.badgeStyle3D = m_ui->badges3DStyleChkBox->isChecked();
0085         emit dataChanged();
0086     });
0087 
0088     connect(m_ui->broadcastGeomChkBox, &QCheckBox::stateChanged, this, [&]() {
0089         m_preferences.isAvailableGeometryBroadcastedToPlasma = m_ui->broadcastGeomChkBox->isChecked();
0090         emit dataChanged();
0091     });
0092 
0093     connect(m_ui->screenTrackerSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), [ = ](int i) {
0094         m_preferences.screensDelay = m_ui->screenTrackerSpinBox->value();
0095         emit dataChanged();
0096     });
0097 
0098     connect(m_ui->metaPressChkBox, &QCheckBox::stateChanged, this, [&]() {
0099         m_preferences.metaPressForAppLauncher = m_ui->metaPressChkBox->isChecked();
0100         emit dataChanged();
0101     });
0102 
0103     connect(m_ui->metaPressHoldChkBox, &QCheckBox::stateChanged, this, [&]() {
0104         m_preferences.metaHoldForBadges = m_ui->metaPressHoldChkBox->isChecked();
0105         emit dataChanged();
0106     });
0107 
0108     connect(m_ui->infoWindowChkBox, &QCheckBox::stateChanged, this, [&]() {
0109         m_preferences.layoutsInformationWindow = m_ui->infoWindowChkBox->isChecked();
0110         emit dataChanged();
0111     });
0112 
0113     connect(m_ui->noBordersForMaximizedChkBox, &QCheckBox::stateChanged, this, [&]() {
0114         m_preferences.borderlessMaximized = m_ui->noBordersForMaximizedChkBox->isChecked();
0115         emit dataChanged();
0116     });
0117 
0118     connect(this, &TabPreferences::contextActionsChanged, this, &TabPreferences::dataChanged);
0119 }
0120 
0121 void TabPreferences::initSettings()
0122 {
0123     o_preferences.autostart = m_corona->universalSettings()->autostart();
0124     o_preferences.badgeStyle3D = m_corona->universalSettings()->badges3DStyle();
0125     o_preferences.contextMenuAlwaysActions = m_corona->universalSettings()->contextMenuActionsAlwaysShown();
0126     o_preferences.isAvailableGeometryBroadcastedToPlasma = m_corona->universalSettings()->isAvailableGeometryBroadcastedToPlasma();
0127     o_preferences.layoutsInformationWindow = m_corona->universalSettings()->showInfoWindow();
0128     o_preferences.metaPressForAppLauncher = m_corona->universalSettings()->kwin_metaForwardedToLatte();
0129     o_preferences.metaHoldForBadges = m_corona->universalSettings()->metaPressAndHoldEnabled();
0130     o_preferences.borderlessMaximized = m_corona->universalSettings()->canDisableBorders();
0131     o_preferences.parabolicSpread = m_corona->universalSettings()->parabolicSpread();
0132     o_preferences.thicknessMarginInfluence = m_corona->universalSettings()->thicknessMarginInfluence();
0133     o_preferences.screensDelay = m_corona->universalSettings()->screenTrackerInterval();
0134 
0135     m_preferences = o_preferences;
0136 
0137     updateUi();
0138 }
0139 
0140 QStringList TabPreferences::contextMenuAlwaysActions() const
0141 {
0142     return m_preferences.contextMenuAlwaysActions;
0143 }
0144 
0145 void TabPreferences::setContextMenuAlwaysActions(const QStringList &actions)
0146 {
0147     if (m_preferences.contextMenuAlwaysActions == actions) {
0148         return;
0149     }
0150 
0151     m_preferences.contextMenuAlwaysActions = actions;
0152     emit contextActionsChanged();
0153 }
0154 
0155 void TabPreferences::updateUi()
0156 {
0157     //! ui load
0158     m_ui->autostartChkBox->setChecked(m_preferences.autostart);
0159     m_ui->badges3DStyleChkBox->setChecked(m_preferences.badgeStyle3D);
0160     m_ui->infoWindowChkBox->setChecked(m_preferences.layoutsInformationWindow);
0161     m_ui->broadcastGeomChkBox->setChecked(m_preferences.isAvailableGeometryBroadcastedToPlasma);
0162     m_ui->metaPressChkBox->setChecked(m_preferences.metaPressForAppLauncher);
0163     m_ui->metaPressHoldChkBox->setChecked(m_preferences.metaHoldForBadges);
0164     m_ui->noBordersForMaximizedChkBox->setChecked(m_preferences.borderlessMaximized);
0165     m_ui->screenTrackerSpinBox->setValue(m_preferences.screensDelay);
0166 
0167     if (m_preferences.parabolicSpread == Data::Preferences::PARABOLICSPREAD) {
0168         m_ui->smallParabolicBtn->setChecked(true);
0169     } else if (m_preferences.parabolicSpread == 5) {
0170         m_ui->mediumParabolicBtn->setChecked(true);
0171     } else if (m_preferences.parabolicSpread == 7) {
0172         m_ui->largeParabolicBtn->setChecked(true);
0173     }
0174 
0175     if (m_preferences.thicknessMarginInfluence == 0.0f) {
0176         m_ui->noMarginInfluenceBtn->setChecked(true);
0177     } else if (m_preferences.thicknessMarginInfluence == 0.5f) {
0178         m_ui->halfMarginInfluenceBtn->setChecked(true);
0179     } else if (m_preferences.thicknessMarginInfluence == Data::Preferences::THICKNESSMARGININFLUENCE) {
0180         m_ui->fullMarginInfluenceBtn->setChecked(true);
0181     }
0182 
0183     emit dataChanged();
0184 }
0185 
0186 bool TabPreferences::hasChangedData() const
0187 {
0188     return o_preferences != m_preferences;
0189 }
0190 
0191 bool TabPreferences::inDefaultValues() const
0192 {
0193     return m_preferences.inDefaultValues();
0194 }
0195 
0196 void TabPreferences::onActionsBtnPressed()
0197 {
0198     auto viewsDlg = new Settings::Dialog::ActionsDialog(m_parentDialog, this);
0199     viewsDlg->exec();
0200 }
0201 
0202 void TabPreferences::reset()
0203 {
0204     m_preferences = o_preferences;
0205     updateUi();
0206 }
0207 
0208 void TabPreferences::resetDefaults()
0209 {
0210     m_preferences.setToDefaults();
0211     updateUi();
0212 }
0213 
0214 void TabPreferences::save()
0215 {
0216     m_corona->universalSettings()->setAutostart(m_preferences.autostart);
0217     m_corona->universalSettings()->setBadges3DStyle(m_preferences.badgeStyle3D);
0218     m_corona->universalSettings()->setContextMenuActionsAlwaysShown(m_preferences.contextMenuAlwaysActions);
0219     m_corona->universalSettings()->kwin_forwardMetaToLatte(m_preferences.metaPressForAppLauncher);
0220     m_corona->universalSettings()->setIsAvailableGeometryBroadcastedToPlasma(m_preferences.isAvailableGeometryBroadcastedToPlasma);
0221     m_corona->universalSettings()->setMetaPressAndHoldEnabled(m_preferences.metaHoldForBadges);
0222     m_corona->universalSettings()->setShowInfoWindow(m_preferences.layoutsInformationWindow);
0223     m_corona->universalSettings()->setCanDisableBorders(m_preferences.borderlessMaximized);
0224     m_corona->universalSettings()->setParabolicSpread(m_preferences.parabolicSpread);
0225     m_corona->universalSettings()->setThicknessMarginInfluence(m_preferences.thicknessMarginInfluence);
0226     m_corona->universalSettings()->setScreenTrackerInterval(m_preferences.screensDelay);
0227 
0228     o_preferences = m_preferences;
0229     emit dataChanged();
0230 }
0231 
0232 }
0233 }
0234 }
0235