File indexing completed on 2024-04-28 15:51:42

0001 /*
0002     SPDX-FileCopyrightText: 2006 Pino Toscano <toscano.pino@tiscali.it>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "dlggeneral.h"
0008 
0009 #include <KAuthorized>
0010 #include <KColorButton>
0011 #include <KLocalizedString>
0012 
0013 #include <QCheckBox>
0014 #include <QComboBox>
0015 #include <QFormLayout>
0016 #include <QGuiApplication>
0017 #include <QHBoxLayout>
0018 #include <QLabel>
0019 #include <QSpinBox>
0020 
0021 #include <config-okular.h>
0022 
0023 #include "settings.h"
0024 
0025 DlgGeneral::DlgGeneral(QWidget *parent, Okular::EmbedMode embedMode)
0026     : QWidget(parent)
0027 {
0028     QFormLayout *layout = new QFormLayout(this);
0029 
0030     // BEGIN Appearance section
0031     // Checkbox: use smooth scrolling
0032     QCheckBox *useSmoothScrolling = new QCheckBox(this);
0033     useSmoothScrolling->setText(i18nc("@option:check Config dialog, general page", "Use smooth scrolling"));
0034     useSmoothScrolling->setObjectName(QStringLiteral("kcfg_SmoothScrolling"));
0035     layout->addRow(i18nc("@title:group Config dialog, general page", "Appearance:"), useSmoothScrolling);
0036 
0037     // Checkbox: show scrollbars
0038     QCheckBox *showScrollbars = new QCheckBox(this);
0039     showScrollbars->setText(i18nc("@option:check Config dialog, general page", "Show scrollbars"));
0040     showScrollbars->setObjectName(QStringLiteral("kcfg_ShowScrollBars"));
0041     layout->addRow(QString(), showScrollbars);
0042 
0043     if (embedMode != Okular::ViewerWidgetMode) {
0044         // Checkbox: scroll thumbnails automatically
0045         QCheckBox *scrollThumbnails = new QCheckBox(this);
0046         scrollThumbnails->setText(i18nc("@option:check Config dialog, general page", "Link the thumbnails with the page"));
0047         scrollThumbnails->setObjectName(QStringLiteral("kcfg_SyncThumbnailsViewport"));
0048         layout->addRow(QString(), scrollThumbnails);
0049     }
0050 
0051     // Checkbox: Show welcoming messages (the balloons or OSD)
0052     QCheckBox *showOSD = new QCheckBox(this);
0053     showOSD->setText(i18nc("@option:check Config dialog, general page", "Show hints and info messages"));
0054     showOSD->setObjectName(QStringLiteral("kcfg_ShowOSD"));
0055     layout->addRow(QString(), showOSD);
0056 
0057     // Checkbox: Notify about embedded files, forms, or signatures
0058     QCheckBox *showEmbeddedContentMessages = new QCheckBox(this);
0059     showEmbeddedContentMessages->setText(i18nc("@option:check Config dialog, general page", "Notify about embedded files, forms, or signatures"));
0060     showEmbeddedContentMessages->setObjectName(QStringLiteral("kcfg_ShowEmbeddedContentMessages"));
0061     layout->addRow(QString(), showEmbeddedContentMessages);
0062 
0063     if (embedMode != Okular::ViewerWidgetMode) {
0064         // Checkbox: display document title in titlebar
0065         QCheckBox *showTitle = new QCheckBox(this);
0066         showTitle->setText(i18nc("@option:check Config dialog, general page", "Display document title in titlebar if available"));
0067         showTitle->setObjectName(QStringLiteral("kcfg_DisplayDocumentTitle"));
0068         layout->addRow(QString(), showTitle);
0069 
0070         // Combobox: prefer file name or full path in titlebar
0071         QComboBox *nameOrPath = new QComboBox(this);
0072         nameOrPath->addItem(i18nc("item:inlistbox Config dialog, general page", "Display file name only"));
0073         nameOrPath->addItem(i18nc("item:inlistbox Config dialog, general page", "Display full file path"));
0074         nameOrPath->setObjectName(QStringLiteral("kcfg_DisplayDocumentNameOrPath"));
0075         layout->addRow(i18nc("label:listbox Config dialog, general page", "When not displaying document title:"), nameOrPath);
0076     }
0077 
0078     // Checkbox and color button: custom background color
0079     QCheckBox *useCustomColor = new QCheckBox(this);
0080     useCustomColor->setText(QString());
0081     useCustomColor->setObjectName(QStringLiteral("kcfg_UseCustomBackgroundColor"));
0082 
0083     KColorButton *customColor = new KColorButton(this);
0084     customColor->setObjectName(QStringLiteral("kcfg_BackgroundColor"));
0085 
0086     QHBoxLayout *customColorLayout = new QHBoxLayout();
0087     customColorLayout->addWidget(useCustomColor);
0088     useCustomColor->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
0089     customColorLayout->addWidget(customColor);
0090     layout->addRow(i18nc("@label:listbox Config dialog, general page", "Use custom background color:"), customColorLayout);
0091 
0092     useCustomColor->setChecked(false);
0093     customColor->setEnabled(false);
0094     connect(useCustomColor, &QCheckBox::toggled, customColor, &QWidget::setEnabled);
0095     // END Appearance section
0096 
0097     layout->addRow(new QLabel(this));
0098 
0099     // BEGIN Program features section
0100     bool programFeaturesLabelPlaced = false;
0101     /**
0102      * This ensures the and only the first checkbox gets the “Program features:” label.
0103      *
0104      * (Right now I could move @c showBackendSelectionDialog to the first row,
0105      * but maybe someone wants to make it conditional too later.)
0106      */
0107     auto programFeaturesLabel = [&programFeaturesLabelPlaced]() -> QString {
0108         if (programFeaturesLabelPlaced) {
0109             return QString();
0110         } else {
0111             programFeaturesLabelPlaced = true;
0112             return i18nc("@title:group Config dialog, general page", "Program features:");
0113         }
0114     };
0115 
0116     if (embedMode == Okular::NativeShellMode) {
0117         // Two checkboxes: use tabs, switch to open tab
0118         QCheckBox *useTabs = new QCheckBox(this);
0119         useTabs->setText(i18nc("@option:check Config dialog, general page", "Open new files in tabs"));
0120         useTabs->setObjectName(QStringLiteral("kcfg_ShellOpenFileInTabs"));
0121         layout->addRow(programFeaturesLabel(), useTabs);
0122 
0123         QCheckBox *switchToTab = new QCheckBox(this);
0124         switchToTab->setText(i18nc("@option:check Config dialog, general page", "Switch to existing tab if file is already open"));
0125         switchToTab->setObjectName(QStringLiteral("kcfg_SwitchToTabIfOpen"));
0126         layout->addRow(QString(), switchToTab);
0127 
0128         useTabs->setChecked(false);
0129         switchToTab->setEnabled(false);
0130         connect(useTabs, &QCheckBox::toggled, switchToTab, &QWidget::setEnabled);
0131     }
0132 
0133 #if !OKULAR_FORCE_DRM
0134     if (KAuthorized::authorize(QStringLiteral("skip_drm"))) {
0135         // Checkbox: Obey DRM
0136         QCheckBox *obeyDrm = new QCheckBox(this);
0137         obeyDrm->setText(i18nc("@option:check Config dialog, general page", "Obey DRM limitations"));
0138         obeyDrm->setObjectName(QStringLiteral("kcfg_ObeyDRM"));
0139         layout->addRow(programFeaturesLabel(), obeyDrm);
0140     }
0141 #endif
0142 
0143     if (embedMode != Okular::ViewerWidgetMode) {
0144         // Checkbox: watch file for changes
0145         QCheckBox *watchFile = new QCheckBox(this);
0146         watchFile->setText(i18nc("@option:check Config dialog, general page", "Reload document on file change"));
0147         watchFile->setObjectName(QStringLiteral("kcfg_WatchFile"));
0148         layout->addRow(programFeaturesLabel(), watchFile);
0149     }
0150 
0151     // Checkbox: show backend selection dialog
0152     QCheckBox *showBackendSelectionDialog = new QCheckBox(this);
0153     showBackendSelectionDialog->setText(i18nc("@option:check Config dialog, general page", "Show backend selection dialog"));
0154     showBackendSelectionDialog->setObjectName(QStringLiteral("kcfg_ChooseGenerators"));
0155     layout->addRow(programFeaturesLabel(), showBackendSelectionDialog);
0156 
0157     if (embedMode != Okular::ViewerWidgetMode) { // TODO Makes sense?
0158         // Checkbox: RTL document layout
0159         QCheckBox *useRtl = new QCheckBox(this);
0160         useRtl->setText(i18nc("@option:check Config dialog, general page", "Right to left reading direction"));
0161         useRtl->setObjectName(QStringLiteral("kcfg_rtlReadingDirection"));
0162         layout->addRow(programFeaturesLabel(), useRtl);
0163     }
0164 
0165     QCheckBox *openInContinuousModeByDefault = new QCheckBox(this);
0166     openInContinuousModeByDefault->setText(i18nc("@option:check Config dialog, general page", "Open in continuous mode by default"));
0167     openInContinuousModeByDefault->setObjectName(QStringLiteral("kcfg_ViewContinuous"));
0168     layout->addRow(programFeaturesLabel(), openInContinuousModeByDefault);
0169 
0170     // Under Wayland the cursor wrap feature is unavailable
0171     if (QGuiApplication::platformName() != QLatin1String("wayland")) {
0172         QCheckBox *dragBeyondScreenEdges = new QCheckBox(this);
0173         dragBeyondScreenEdges->setText(i18nc("@option:check Config dialog, general page", "When using Browse Tool, wrap cursor at screen edges"));
0174         dragBeyondScreenEdges->setObjectName(QStringLiteral("kcfg_DragBeyondScreenEdges"));
0175         layout->addRow(programFeaturesLabel(), dragBeyondScreenEdges);
0176     }
0177     // END Program features section
0178 
0179     // If no Program features section, don’t add a second spacer:
0180     if (programFeaturesLabelPlaced) {
0181         layout->addRow(new QLabel(this));
0182     }
0183 
0184     // BEGIN View options section
0185     // Spinbox: overview columns
0186     QSpinBox *overviewColumns = new QSpinBox(this);
0187     overviewColumns->setMinimum(3);
0188     overviewColumns->setMaximum(10);
0189     overviewColumns->setObjectName(QStringLiteral("kcfg_ViewColumns"));
0190     layout->addRow(i18nc("@label:spinbox Config dialog, general page", "Overview columns:"), overviewColumns);
0191 
0192     // Spinbox: page up/down overlap
0193     QSpinBox *pageUpDownOverlap = new QSpinBox(this);
0194     pageUpDownOverlap->setMinimum(0);
0195     pageUpDownOverlap->setMaximum(50);
0196     pageUpDownOverlap->setSingleStep(5);
0197     pageUpDownOverlap->setSuffix(i18nc("Page Up/Down overlap, spinbox suffix", "%"));
0198     pageUpDownOverlap->setToolTip(i18nc("@info:tooltip Config dialog, general page", "Defines how much of the current viewing area will still be visible when pressing the Page Up/Down keys."));
0199     pageUpDownOverlap->setObjectName(QStringLiteral("kcfg_ScrollOverlap"));
0200     layout->addRow(i18nc("@label:spinbox Config dialog, general page", "Page Up/Down overlap:"), pageUpDownOverlap);
0201 
0202     // Combobox: prefer file name or full path in titlebar
0203     QComboBox *defaultZoom = new QComboBox(this);
0204     defaultZoom->addItem(i18nc("item:inlistbox Config dialog, general page, default zoom", "100%"));
0205     defaultZoom->addItem(i18nc("item:inlistbox Config dialog, general page, default zoom", "Fit Width"));
0206     defaultZoom->addItem(i18nc("item:inlistbox Config dialog, general page, default zoom", "Fit Page"));
0207     defaultZoom->addItem(i18nc("item:inlistbox Config dialog, general page, default zoom", "Auto Fit"));
0208     defaultZoom->setToolTip(i18nc("item:inlistbox Config dialog, general page, default zoom", "Defines the default zoom mode for files which were never opened before. For files which were opened before the previous zoom is applied."));
0209     defaultZoom->setObjectName(QStringLiteral("kcfg_ZoomMode"));
0210     layout->addRow(i18nc("label:listbox Config dialog, general page, default zoom", "Default zoom:"), defaultZoom);
0211     // END View options section
0212 }