Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/SettingsDialog/GeneralOptionsPage.cpp
Show All 14 Lines | |||||
15 | * You should have received a copy of the GNU Lesser General Public License | 15 | * You should have received a copy of the GNU Lesser General Public License | ||
16 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "GeneralOptionsPage.h" | 21 | #include "GeneralOptionsPage.h" | ||
22 | 22 | | |||
23 | #include "settings.h" | ||||
24 | #include "ui_GeneralOptions.h" | ||||
25 | | ||||
23 | #include <KLocalizedString> | 26 | #include <KLocalizedString> | ||
24 | #include <KTitleWidget> | 27 | #include <KTitleWidget> | ||
25 | #include <KWindowSystem> | 28 | #include <KWindowSystem> | ||
26 | 29 | | |||
27 | #include <QButtonGroup> | 30 | #include <QButtonGroup> | ||
28 | #include <QCheckBox> | 31 | #include <QCheckBox> | ||
29 | #include <QLineEdit> | 32 | #include <QLineEdit> | ||
30 | #include <QFormLayout> | 33 | #include <QFormLayout> | ||
31 | #include <QRadioButton> | 34 | #include <QRadioButton> | ||
32 | #include <QSpacerItem> | 35 | #include <QSpacerItem> | ||
33 | #include <QTextEdit> | 36 | #include <QTextEdit> | ||
34 | 37 | | |||
35 | GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) : | 38 | GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) | ||
36 | QWidget{parent} | 39 | : QWidget(parent) | ||
40 | , m_ui(new Ui_GeneralOptions) | ||||
37 | { | 41 | { | ||
38 | QFormLayout *mainLayout = new QFormLayout(this); | 42 | m_ui->setupUi(this); | ||
39 | setLayout(mainLayout); | 43 | | ||
44 | m_ui->runningTitle->setLevel(2); | ||||
45 | m_ui->regionTitle->setLevel(2); | ||||
46 | | ||||
47 | m_ui->printKeyActionGroup->setId(m_ui->newScreenshotButton, Settings::TakeNewScreenshot); | ||||
48 | m_ui->printKeyActionGroup->setId(m_ui->newWindowButton, Settings::StartNewInstance); | ||||
49 | m_ui->printKeyActionGroup->setId(m_ui->activateWindowButton, Settings::FocusWindow); | ||||
40 | 50 | | |||
41 | // When spectacle is running settings | | |||
42 | KTitleWidget* runningTitle = new KTitleWidget(this); | | |||
43 | runningTitle->setText(i18n("When Spectacle is Running")); | | |||
44 | runningTitle->setLevel(2); | | |||
45 | mainLayout->addRow(runningTitle); | | |||
46 | QRadioButton* takeNew = new QRadioButton(i18n("Take a new screenshot"), this); | | |||
47 | QRadioButton* startNewInstance = new QRadioButton(i18n("Open a new Spectacle window"), this); | | |||
48 | QButtonGroup* printKeyActionGroup = new QButtonGroup(this); | | |||
49 | printKeyActionGroup->setExclusive(true); | | |||
50 | printKeyActionGroup->addButton(takeNew,0);// SpectacleConfig::PrintKeyActionRunning::TakeNewScreenshot); | | |||
51 | printKeyActionGroup->addButton(startNewInstance,1);// SpectacleConfig::PrintKeyActionRunning::StartNewInstance); | | |||
52 | mainLayout->addRow(i18n("Press screenshot key to:"), takeNew); | | |||
53 | mainLayout->addRow(QString(), startNewInstance); | | |||
54 | //On Wayland we can't programmatically raise and focus the window so we have to hide the option | 51 | //On Wayland we can't programmatically raise and focus the window so we have to hide the option | ||
55 | if (!(KWindowSystem::isPlatformWayland() || qstrcmp(qgetenv("XDG_SESSION_TYPE"), "wayland") == 0)) { | 52 | if (KWindowSystem::isPlatformWayland() || qstrcmp(qgetenv("XDG_SESSION_TYPE"), "wayland") == 0) { | ||
56 | QRadioButton* focusWindow = new QRadioButton(i18n("Return focus to Spectacle"), this); | 53 | m_ui->formLayout->removeRow(m_ui->activateWindowButton); | ||
57 | printKeyActionGroup->addButton( focusWindow,2);// SpectacleConfig::PrintKeyActionRunning::FocusWindow); | | |||
58 | mainLayout->addRow(QString(), focusWindow); | | |||
59 | } | 54 | } | ||
60 | 55 | //Workaround because KConfigDialogManager doesn't support QButtonGroup (Bug 409037) | |||
61 | //Workaround because KConfigWidgets doesn't support QButtonGroup (Bug 409037) | 56 | auto workaroundLabel = m_ui->kcfg_printKeyActionRunning; | ||
62 | auto workaroundLabel = new QLineEdit(this); | 57 | connect(workaroundLabel, &QLineEdit::textChanged, this, [this](const QString& text){ | ||
63 | workaroundLabel->setHidden(true); | 58 | auto button = m_ui->printKeyActionGroup->button(text.toInt()); | ||
64 | workaroundLabel->setObjectName(QStringLiteral("kcfg_printKeyActionRunning")); | | |||
65 | // Need to check default Button because we get no change event for that | | |||
66 | takeNew->setChecked(true); | | |||
67 | connect(workaroundLabel, &QLineEdit::textChanged, | | |||
68 | printKeyActionGroup, [printKeyActionGroup, takeNew](const QString& text){ | | |||
69 | auto button = printKeyActionGroup->button(text.toInt()); | | |||
70 | // We are missing a button on Wayland | 59 | // We are missing a button on Wayland | ||
71 | button ? button->setChecked(true) : takeNew->setChecked(true); | 60 | button ? button->setChecked(true) : m_ui->newScreenshotButton->setChecked(true); | ||
72 | }); | 61 | }); | ||
73 | connect(printKeyActionGroup, qOverload<QAbstractButton *, bool>(&QButtonGroup::buttonToggled), | 62 | connect(m_ui->printKeyActionGroup, qOverload<QAbstractButton *, bool>(&QButtonGroup::buttonToggled), | ||
74 | workaroundLabel, [workaroundLabel, printKeyActionGroup] (QAbstractButton *button, bool checked) { | 63 | workaroundLabel, [workaroundLabel, this] (QAbstractButton *button, bool checked) { | ||
75 | if (checked) { | 64 | if (checked) { | ||
76 | const int value = printKeyActionGroup->id(button); | 65 | const int value = m_ui->printKeyActionGroup->id(button); | ||
77 | workaroundLabel->setText(QString::number(value)); | 66 | workaroundLabel->setText(QString::number(value)); | ||
78 | } | 67 | } | ||
79 | }); | 68 | }); | ||
80 | // /Workaround | 69 | // /Workaround | ||
81 | 70 | | |||
82 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | 71 | } | ||
83 | | ||||
84 | // actions to take after taking a screenshot | | |||
85 | auto copyImageToClipboard = new QCheckBox(i18n("Copy image to clipboard"), this); | | |||
86 | copyImageToClipboard->setObjectName(QStringLiteral("kcfg_copyImageToClipboard")); | | |||
87 | mainLayout->addRow(i18n("After taking a screenshot:"), copyImageToClipboard); | | |||
88 | | ||||
89 | auto autoSaveImage = new QCheckBox(i18n("Autosave the image to the default location"), this); | | |||
90 | autoSaveImage->setObjectName(QStringLiteral("kcfg_autoSaveImage")); | | |||
91 | mainLayout->addRow(QString(), autoSaveImage); | | |||
92 | | ||||
93 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | | |||
94 | | ||||
95 | // Rectangular Region settings | | |||
96 | KTitleWidget *titleWidget = new KTitleWidget(this); | | |||
97 | titleWidget->setText(i18n("Rectangular Region")); | | |||
98 | titleWidget->setLevel(2); | | |||
99 | mainLayout->addRow(titleWidget); | | |||
100 | | ||||
101 | // use light background | | |||
102 | QCheckBox* kcfg_useLightMaskColour = new QCheckBox(i18n("Use light background"), this); | | |||
103 | kcfg_useLightMaskColour->setObjectName(QStringLiteral("kcfg_useLightMaskColour")); | | |||
104 | mainLayout->addRow(i18n("General:"), kcfg_useLightMaskColour); | | |||
105 | | ||||
106 | // show magnifier | | |||
107 | auto showMagnifier = new QCheckBox(i18n("Show magnifier"), this); | | |||
108 | showMagnifier->setObjectName(QStringLiteral("kcfg_showMagnifier")); | | |||
109 | mainLayout->addRow(QString(), showMagnifier); | | |||
110 | | ||||
111 | // release mouse-button to capture | | |||
112 | auto releaseToCapture = new QCheckBox(i18n("Accept on click-and-release"), this); | | |||
113 | releaseToCapture->setObjectName(QStringLiteral("kcfg_useReleaseToCapture")); | | |||
114 | mainLayout->addRow(QString(), releaseToCapture); | | |||
115 | | ||||
116 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | | |||
117 | | ||||
118 | // remember Rectangular Region box | | |||
119 | QButtonGroup* rememberGroup = new QButtonGroup(this); | | |||
120 | rememberGroup->setExclusive(true); | | |||
121 | QRadioButton* neverButton = new QRadioButton(i18n("Never"), this); | | |||
122 | auto rememberAlways = new QRadioButton(i18n("Always"), this); | | |||
123 | rememberAlways->setObjectName(QStringLiteral("kcfg_alwaysRememberRegion")); | | |||
124 | auto rememberUntilClosed = new QRadioButton(i18n("Until Spectacle is closed"), this); | | |||
125 | rememberUntilClosed->setObjectName(QStringLiteral("kcfg_rememberLastRectangularRegion")); | | |||
126 | rememberGroup->addButton(neverButton); | | |||
127 | rememberGroup->addButton(rememberAlways); | | |||
128 | rememberGroup->addButton(rememberUntilClosed); | | |||
129 | neverButton->setChecked(true); | | |||
130 | mainLayout->addRow(i18n("Remember selected area:"), neverButton); | | |||
131 | 72 | | |||
132 | mainLayout->addRow(QString(), rememberAlways); | 73 | GeneralOptionsPage::~GeneralOptionsPage() | ||
133 | mainLayout->addRow(QString(), rememberUntilClosed); | 74 | { | ||
75 | delete m_ui; | ||||
134 | } | 76 | } | ||
77 | |