File indexing completed on 2024-05-19 12:17:48
0001 /* 0002 SPDX-FileCopyrightText: 2006, 2008 Pino Toscano <pino@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "dlgpresentation.h" 0008 0009 #include "widgetdrawingtools.h" 0010 0011 #include <KColorButton> 0012 #include <KLocalizedString> 0013 #include <KPluralHandlingSpinBox> 0014 0015 #include <QApplication> 0016 #include <QCheckBox> 0017 #include <QComboBox> 0018 #include <QFormLayout> 0019 #include <QHBoxLayout> 0020 #include <QLabel> 0021 #include <QScreen> 0022 0023 #include "settings.h" 0024 0025 DlgPresentation::DlgPresentation(QWidget *parent) 0026 : QWidget(parent) 0027 { 0028 QFormLayout *layout = new QFormLayout(this); 0029 0030 // BEGIN Navigation section 0031 // Spinbox with a checkbox attached to the left: advance automatically 0032 QCheckBox *advanceAutomatically = new QCheckBox(this); 0033 advanceAutomatically->setText(QString()); 0034 advanceAutomatically->setObjectName(QStringLiteral("kcfg_SlidesAdvance")); 0035 0036 KPluralHandlingSpinBox *advanceTime = new KPluralHandlingSpinBox(this); 0037 advanceTime->setPrefix(i18nc("Spinbox prefix: Advance automatically: every n seconds", "every ")); 0038 advanceTime->setSuffix(ki18ncp("Advance every %1 seconds", " second", " seconds")); 0039 advanceTime->setObjectName(QStringLiteral("kcfg_SlidesAdvanceTime")); 0040 0041 QHBoxLayout *advanceAutomaticallyLayout = new QHBoxLayout(); 0042 advanceAutomaticallyLayout->addWidget(advanceAutomatically); 0043 advanceAutomatically->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); 0044 advanceAutomaticallyLayout->addWidget(advanceTime); 0045 layout->addRow(i18nc("@label:spinbox Config dialog, presentation page", "Advance automatically:"), advanceAutomaticallyLayout); 0046 0047 advanceAutomatically->setChecked(false); 0048 advanceTime->setEnabled(false); 0049 connect(advanceAutomatically, &QCheckBox::toggled, advanceTime, &KPluralHandlingSpinBox::setEnabled); 0050 0051 // Checkbox: Loop after last page 0052 QCheckBox *loopAfterLastPage = new QCheckBox(this); 0053 loopAfterLastPage->setText(i18nc("@option:check Config dialog, presentation page", "Loop after last page")); 0054 loopAfterLastPage->setObjectName(QStringLiteral("kcfg_SlidesLoop")); 0055 layout->addRow(QString(), loopAfterLastPage); 0056 0057 // Combobox: Touch navigation 0058 QComboBox *tapNavigation = new QComboBox(this); 0059 tapNavigation->addItem(i18nc("@item:inlistbox Config dialog, presentation page, tap navigation", "Tap left/right side to go back/forward")); 0060 tapNavigation->addItem(i18nc("@item:inlistbox Config dialog, presentation page, tap navigation", "Tap anywhere to go forward")); 0061 tapNavigation->addItem(i18nc("@item:inlistbox Config dialog, presentation page, tap navigation", "Disabled")); 0062 tapNavigation->setObjectName(QStringLiteral("kcfg_SlidesTapNavigation")); 0063 layout->addRow(i18nc("@label:listbox Config dialog, presentation page, tap navigation", "Touch navigation:"), tapNavigation); 0064 // END Navigation section 0065 0066 layout->addRow(new QLabel(this)); 0067 0068 // BEGIN Appearance section 0069 // Color button: Background color 0070 KColorButton *backgroundColor = new KColorButton(this); 0071 backgroundColor->setObjectName(QStringLiteral("kcfg_SlidesBackgroundColor")); 0072 layout->addRow(i18nc("@label:chooser Config dialog, presentation page", "Background color:"), backgroundColor); 0073 0074 // Combobox: Cursor visibility 0075 QComboBox *cursorVisibility = new QComboBox(this); 0076 cursorVisibility->addItem(i18nc("@item:inlistbox Config dialog, presentation page, cursor visibility", "Hidden after delay")); 0077 cursorVisibility->addItem(i18nc("@item:inlistbox Config dialog, presentation page, cursor visibility", "Always visible")); 0078 cursorVisibility->addItem(i18nc("@item:inlistbox Config dialog, presentation page, cursor visibility", "Always hidden")); 0079 cursorVisibility->setObjectName(QStringLiteral("kcfg_SlidesCursor")); 0080 layout->addRow(i18nc("@label:listbox Config dialog, presentation page, cursor visibility", "Mouse cursor:"), cursorVisibility); 0081 0082 // Checkbox: Show progress indicator 0083 QCheckBox *showProgressIndicator = new QCheckBox(this); 0084 showProgressIndicator->setText(i18nc("@option:check Config dialog, presentation page", "Show progress indicator")); 0085 showProgressIndicator->setObjectName(QStringLiteral("kcfg_SlidesShowProgress")); 0086 layout->addRow(QString(), showProgressIndicator); 0087 0088 // Checkbox: Show summary page 0089 QCheckBox *showSummaryPage = new QCheckBox(this); 0090 showSummaryPage->setText(i18nc("@option:check Config dialog, presentation page", "Show summary page")); 0091 showSummaryPage->setObjectName(QStringLiteral("kcfg_SlidesShowSummary")); 0092 layout->addRow(QString(), showSummaryPage); 0093 // END Appearance section 0094 0095 layout->addRow(new QLabel(this)); 0096 0097 // BEGIN Transitions section 0098 // Combobox: Default transition 0099 QComboBox *defaultTransition = new QComboBox(this); 0100 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Instant (Never use animations)")); 0101 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Replace")); 0102 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Random transition")); 0103 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Blinds vertical")); 0104 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Blinds horizontal")); 0105 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Box in")); 0106 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Box out")); 0107 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Dissolve")); 0108 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Fade")); 0109 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Glitter down")); 0110 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Glitter right")); 0111 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Glitter right-down")); 0112 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Split horizontal in")); 0113 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Split horizontal out")); 0114 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Split vertical in")); 0115 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Split vertical out")); 0116 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Wipe down")); 0117 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Wipe right")); 0118 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Wipe left")); 0119 defaultTransition->addItem(i18nc("@item:inlistbox Config dialog, presentation page, transitions", "Wipe up")); 0120 defaultTransition->setObjectName(QStringLiteral("kcfg_SlidesTransition")); 0121 layout->addRow(i18nc("@label:listbox Config dialog, presentation page, transitions", "Default transition:"), defaultTransition); 0122 // END Transitions section 0123 0124 layout->addRow(new QLabel(this)); 0125 0126 // BEGIN Placement section 0127 // Combobox: Preferred screen 0128 PreferredScreenSelector *preferredScreen = new PreferredScreenSelector(this); 0129 preferredScreen->setObjectName(QStringLiteral("kcfg_SlidesScreen")); 0130 layout->addRow(i18nc("@label:listbox Config dialog, presentation page, preferred screen", "Preferred screen:"), preferredScreen); 0131 // END Placement section 0132 0133 layout->addRow(new QLabel(this)); 0134 0135 // BEGIN Drawing tools section: WidgetDrawingTools manages drawing tools. 0136 QLabel *toolsLabel = new QLabel(this); 0137 toolsLabel->setText(i18nc("@label Config dialog, presentation page, heading line for drawing tool manager", "<h3>Drawing Tools</h3>")); 0138 layout->addRow(toolsLabel); 0139 0140 WidgetDrawingTools *kcfg_DrawingTools = new WidgetDrawingTools(this); 0141 kcfg_DrawingTools->setObjectName(QStringLiteral("kcfg_DrawingTools")); 0142 0143 layout->addRow(kcfg_DrawingTools); 0144 // END Drawing tools section 0145 } 0146 0147 PreferredScreenSelector::PreferredScreenSelector(QWidget *parent) 0148 : QComboBox(parent) 0149 , m_disconnectedScreenIndex(-1) 0150 , m_disconnectedScreenNumber(k_noDisconnectedScreenNumber) 0151 { 0152 repopulateList(); 0153 connect(qApp, &QGuiApplication::screenAdded, this, &PreferredScreenSelector::repopulateList); 0154 connect(qApp, &QGuiApplication::screenRemoved, this, &PreferredScreenSelector::repopulateList); 0155 0156 // KConfigWidgets setup: 0157 setProperty("kcfg_property", QByteArray("preferredScreen")); 0158 connect(this, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) { Q_EMIT preferredScreenChanged(index - k_specialScreenCount); }); 0159 } 0160 0161 void PreferredScreenSelector::repopulateList() 0162 { 0163 // Remember which index was selected before: 0164 const int screenBeforeRepopulation = preferredScreen(); 0165 0166 QSignalBlocker signalBlocker(this); 0167 clear(); 0168 0169 // Populate list: 0170 static_assert(k_specialScreenCount == 2, "Special screens unknown to PreferredScreenSelector::repopulateList()."); 0171 addItem(i18nc("@item:inlistbox Config dialog, presentation page, preferred screen", "Current Screen")); 0172 addItem(i18nc("@item:inlistbox Config dialog, presentation page, preferred screen", "Default Screen")); 0173 0174 const QList<QScreen *> screens = qApp->screens(); 0175 for (int screenNumber = 0; screenNumber < screens.count(); ++screenNumber) { 0176 QScreen *screen = screens.at(screenNumber); 0177 addItem(i18nc("@item:inlistbox Config dialog, presentation page, preferred screen. %1 is the screen number (0, 1, ...). %2 is the screen manufacturer name. %3 is the screen model name. %4 is the screen name like DVI-0", 0178 "Screen %1 (%2 %3 %4)", 0179 screenNumber, 0180 screen->manufacturer(), 0181 screen->model(), 0182 screen->name())); 0183 } 0184 0185 // If a disconnected screen is configured, it will be appended last: 0186 m_disconnectedScreenIndex = count(); 0187 0188 // If a screen of currently disconnected index was selected, keep its list item: 0189 if (m_disconnectedScreenNumber >= m_disconnectedScreenIndex - k_specialScreenCount) { 0190 addItem(i18nc("@item:inlistbox Config dialog, presentation page, preferred screen. %1 is the screen number (0, 1, ...), hopefully not 0.", "Screen %1 (disconnected)", m_disconnectedScreenNumber)); 0191 } 0192 0193 // Select the index that was selected before: 0194 setPreferredScreen(screenBeforeRepopulation); 0195 } 0196 0197 void PreferredScreenSelector::setPreferredScreen(int newScreen) 0198 { 0199 // Check whether the new screen is not in the list of connected screens: 0200 if (newScreen >= m_disconnectedScreenIndex - k_specialScreenCount) { 0201 if (m_disconnectedScreenNumber != newScreen) { 0202 m_disconnectedScreenNumber = newScreen; 0203 repopulateList(); 0204 } 0205 setCurrentIndex(m_disconnectedScreenIndex); 0206 return; 0207 } 0208 0209 setCurrentIndex(newScreen + k_specialScreenCount); 0210 0211 // screenChanged() is emitted through currentIndexChanged(). 0212 } 0213 0214 int PreferredScreenSelector::preferredScreen() const 0215 { 0216 if (currentIndex() == m_disconnectedScreenIndex) { 0217 return m_disconnectedScreenNumber; 0218 } else { 0219 return currentIndex() - k_specialScreenCount; 0220 } 0221 }