File indexing completed on 2024-05-12 05:56:49

0001 /*
0002   SPDX-FileCopyrightText: 2008-2009 Eike Hein <hein@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "windowsettings.h"
0008 #include "settings.h"
0009 
0010 #include <KLocalizedString>
0011 #include <KMessageBox>
0012 
0013 WindowSettings::WindowSettings(QWidget *parent)
0014     : QWidget(parent)
0015 {
0016     setupUi(this);
0017 
0018     for (int i = 2; i <= QGuiApplication::screens().count(); i++)
0019         kcfg_Screen->insertItem(i, xi18nc("@item:inlistbox", "Screen %1", i));
0020 
0021     if (QGuiApplication::screens().count() > 1) {
0022         screenLabel->setEnabled(true);
0023         kcfg_Screen->setEnabled(true);
0024     }
0025 
0026     connect(kcfg_ShowTitleBar, SIGNAL(stateChanged(int)), this, SLOT(interceptHideTitleBar(int)));
0027 
0028     connect(kcfg_Width, SIGNAL(valueChanged(int)), this, SLOT(updateWidthSlider(int)));
0029     connect(widthSlider, SIGNAL(valueChanged(int)), this, SLOT(updateWidthSpinBox(int)));
0030 
0031     connect(kcfg_Height, SIGNAL(valueChanged(int)), this, SLOT(updateHeightSlider(int)));
0032     connect(heightSlider, SIGNAL(valueChanged(int)), this, SLOT(updateHeightSpinBox(int)));
0033 
0034     connect(kcfg_Frames, SIGNAL(valueChanged(int)), this, SLOT(updateFramesSpinBox(int)));
0035     connect(framesSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateFramesSlider(int)));
0036 
0037     connect(kcfg_Position, SIGNAL(valueChanged(int)), this, SLOT(updatePosition(int)));
0038 
0039     updateFramesSpinBox(Settings::frames() * 10);
0040 }
0041 
0042 WindowSettings::~WindowSettings()
0043 {
0044 }
0045 
0046 void WindowSettings::updateWidthSlider(int width)
0047 {
0048     widthSlider->setValue(width / 10);
0049 
0050     Q_EMIT updateWindowGeometry(width, kcfg_Height->value(), kcfg_Position->value());
0051 }
0052 
0053 void WindowSettings::updateWidthSpinBox(int width)
0054 {
0055     kcfg_Width->setValue(width * 10);
0056 }
0057 
0058 void WindowSettings::updateHeightSlider(int height)
0059 {
0060     heightSlider->setValue(height / 10);
0061 
0062     Q_EMIT updateWindowGeometry(kcfg_Width->value(), height, kcfg_Position->value());
0063 }
0064 
0065 void WindowSettings::updateHeightSpinBox(int height)
0066 {
0067     kcfg_Height->setValue(height * 10);
0068 }
0069 
0070 void WindowSettings::updateFramesSlider(int speed)
0071 {
0072     kcfg_Frames->setValue(speed / 10);
0073 }
0074 
0075 void WindowSettings::updateFramesSpinBox(int speed)
0076 {
0077     framesSpinBox->setValue(speed * 10);
0078 }
0079 
0080 void WindowSettings::updatePosition(int position)
0081 {
0082     Q_EMIT updateWindowGeometry(kcfg_Width->value(), kcfg_Height->value(), position);
0083 }
0084 
0085 void WindowSettings::interceptHideTitleBar(int state)
0086 {
0087     if (state == 0) {
0088         if (Settings::showTitleBar()) { // If the title bar is hidden don't ask if toggling is ok
0089 
0090             const char *message =
0091                 "You are about to hide the title bar. This will keep you "
0092                 "from accessing the settings menu via the mouse. To show "
0093                 "the title bar again press the keyboard shortcut (default "
0094                 "Ctrl+Shift+m) or access the settings menu via keyboard "
0095                 "shortcut (default: Ctrl+Shift+,).";
0096 
0097             const int result = KMessageBox::warningContinueCancel(this,
0098                                                                   xi18nc("@info", message),
0099                                                                   xi18nc("@title:window", "Hiding Title Bar"),
0100                                                                   KStandardGuiItem::cont(),
0101                                                                   KStandardGuiItem::cancel(),
0102                                                                   QStringLiteral("hinding_title_bar"));
0103 
0104             if (result == KMessageBox::ButtonCode::Cancel) {
0105                 kcfg_ShowTitleBar->setCheckState(Qt::CheckState::Checked);
0106             }
0107         }
0108     }
0109 }
0110 
0111 #include "moc_windowsettings.cpp"