Commit c013771e authored by David Redondo's avatar David Redondo 🏎
Browse files

Port general settings and save setting to ui files

Summary:
Next step after porting the settings to KConfigXT. I recreated the layout as it
was before. Additionaly the KUrlRequester for the default save location now
only accepts folders.

Test Plan: Works as before

Reviewers: #spectacle, ervin, ngraham

Reviewed By: #spectacle, ervin, ngraham

Tags: #spectacle

Differential Revision: https://phabricator.kde.org/D27373
parent e8b4c291
......@@ -68,6 +68,8 @@ add_executable(
${SPECTACLE_SRCS_ALL}
)
ki18n_wrap_ui(spectacle Gui/SettingsDialog/GeneralOptions.ui Gui/SettingsDialog/SaveOptions.ui)
# link libraries
target_link_libraries(
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GeneralOptions</class>
<widget class="QWidget" name="GeneralOptions">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>463</width>
<height>442</height>
</rect>
</property>
<layout class="QFormLayout">
<item row="0" column="0" colspan="2">
<widget class="KTitleWidget" name="runningTitle">
<property name="text">
<string>When Spectacle is Running</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="printKeyActionLabel">
<property name="text">
<string>Press screenshot key to:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="newScreenshotButton">
<property name="text">
<string>Take a new Screenshot</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">printKeyActionGroup</string>
</attribute>
</widget>
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="newWindowButton">
<property name="text">
<string>Open a new Spectacle window</string>
</property>
<attribute name="buttonGroup">
<string notr="true">printKeyActionGroup</string>
</attribute>
</widget>
</item>
<item row="3" column="1">
<widget class="QRadioButton" name="activateWindowButton">
<property name="text">
<string>Return focus to Spectacle</string>
</property>
<attribute name="buttonGroup">
<string notr="true">printKeyActionGroup</string>
</attribute>
</widget>
</item>
<item row="4" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>18</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0">
<widget class="QLabel" name="afterScreenshotLabel">
<property name="text">
<string>After taking a screenshot:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QCheckBox" name="kcfg_copyImageToClipboard">
<property name="text">
<string>Copy image to clipboard</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QCheckBox" name="kcfg_autoSaveImage">
<property name="text">
<string>Autosave the image to the default location</string>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>18</height>
</size>
</property>
</spacer>
</item>
<item row="8" column="0" colspan="2">
<widget class="KTitleWidget" name="regionTitle">
<property name="text">
<string>Rectangular Region</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="generalLabel">
<property name="text">
<string>General:</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QCheckBox" name="kcfg_useLightMaskColour">
<property name="text">
<string>Use light background</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QCheckBox" name="kcfg_showMagnifier">
<property name="text">
<string>Show magnifier</string>
</property>
</widget>
</item>
<item row="11" column="1">
<widget class="QCheckBox" name="kcfg_useReleaseToCapture">
<property name="text">
<string>Accept on click-and-release</string>
</property>
</widget>
</item>
<item row="12" column="0">
<widget class="QLabel" name="rememberLabel">
<property name="text">
<string>Remember selected area:</string>
</property>
</widget>
</item>
<item row="12" column="1">
<widget class="QRadioButton" name="neverRemeberButton">
<property name="text">
<string>Never</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="13" column="1">
<widget class="QRadioButton" name="kcfg_alwaysRememberRegion">
<property name="text">
<string>Always</string>
</property>
</widget>
</item>
<item row="14" column="1">
<widget class="QRadioButton" name="kcfg_rememberLastRectangularRegion">
<property name="text">
<string>Until Spectacle is closed</string>
</property>
</widget>
</item>
</layout>
<widget class="QLineEdit" name="kcfg_printKeyActionRunning">
<property name="enabled">
<bool>true</bool>
</property>
<property name="visible">
<bool>false</bool>
</property>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>KTitleWidget</class>
<extends>QWidget</extends>
<header>ktitlewidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="printKeyActionGroup"/>
</buttongroups>
</ui>
......@@ -20,6 +20,9 @@
#include "GeneralOptionsPage.h"
#include "settings.h"
#include "ui_GeneralOptions.h"
#include <KLocalizedString>
#include <KTitleWidget>
#include <KWindowSystem>
......@@ -32,103 +35,39 @@
#include <QSpacerItem>
#include <QTextEdit>
GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) :
QWidget{parent}
GeneralOptionsPage::GeneralOptionsPage(QWidget *parent)
: QWidget(parent)
, m_ui(new Ui_GeneralOptions)
{
QFormLayout *mainLayout = new QFormLayout(this);
setLayout(mainLayout);
m_ui->setupUi(this);
m_ui->runningTitle->setLevel(2);
m_ui->regionTitle->setLevel(2);
m_ui->printKeyActionGroup->setId(m_ui->newScreenshotButton, Settings::TakeNewScreenshot);
m_ui->printKeyActionGroup->setId(m_ui->newWindowButton, Settings::StartNewInstance);
m_ui->printKeyActionGroup->setId(m_ui->activateWindowButton, Settings::FocusWindow);
// When spectacle is running settings
KTitleWidget* runningTitle = new KTitleWidget(this);
runningTitle->setText(i18n("When Spectacle is Running"));
runningTitle->setLevel(2);
mainLayout->addRow(runningTitle);
QRadioButton* takeNew = new QRadioButton(i18n("Take a new screenshot"), this);
QRadioButton* startNewInstance = new QRadioButton(i18n("Open a new Spectacle window"), this);
QButtonGroup* printKeyActionGroup = new QButtonGroup(this);
printKeyActionGroup->setExclusive(true);
printKeyActionGroup->addButton(takeNew,0);// SpectacleConfig::PrintKeyActionRunning::TakeNewScreenshot);
printKeyActionGroup->addButton(startNewInstance,1);// SpectacleConfig::PrintKeyActionRunning::StartNewInstance);
mainLayout->addRow(i18n("Press screenshot key to:"), takeNew);
mainLayout->addRow(QString(), startNewInstance);
//On Wayland we can't programmatically raise and focus the window so we have to hide the option
if (!(KWindowSystem::isPlatformWayland() || qstrcmp(qgetenv("XDG_SESSION_TYPE"), "wayland") == 0)) {
QRadioButton* focusWindow = new QRadioButton(i18n("Return focus to Spectacle"), this);
printKeyActionGroup->addButton( focusWindow,2);// SpectacleConfig::PrintKeyActionRunning::FocusWindow);
mainLayout->addRow(QString(), focusWindow);
if (KWindowSystem::isPlatformWayland() || qstrcmp(qgetenv("XDG_SESSION_TYPE"), "wayland") == 0) {
m_ui->formLayout->removeRow(m_ui->activateWindowButton);
}
//Workaround because KConfigWidgets doesn't support QButtonGroup (Bug 409037)
auto workaroundLabel = new QLineEdit(this);
workaroundLabel->setHidden(true);
workaroundLabel->setObjectName(QStringLiteral("kcfg_printKeyActionRunning"));
// Need to check default Button because we get no change event for that
takeNew->setChecked(true);
connect(workaroundLabel, &QLineEdit::textChanged,
printKeyActionGroup, [printKeyActionGroup, takeNew](const QString& text){
auto button = printKeyActionGroup->button(text.toInt());
// We are missing a button on Wayland
button ? button->setChecked(true) : takeNew->setChecked(true);
//Workaround because KConfigDialogManager doesn't support QButtonGroup (Bug 409037)
auto workaroundLabel = m_ui->kcfg_printKeyActionRunning;
connect(workaroundLabel, &QLineEdit::textChanged, this, [this](const QString& text){
auto button = m_ui->printKeyActionGroup->button(text.toInt());
// We are missing a button on Wayland
button ? button->setChecked(true) : m_ui->newScreenshotButton->setChecked(true);
});
connect(printKeyActionGroup, qOverload<QAbstractButton *, bool>(&QButtonGroup::buttonToggled),
workaroundLabel, [workaroundLabel, printKeyActionGroup] (QAbstractButton *button, bool checked) {
connect(m_ui->printKeyActionGroup, qOverload<QAbstractButton *, bool>(&QButtonGroup::buttonToggled),
workaroundLabel, [workaroundLabel, this] (QAbstractButton *button, bool checked) {
if (checked) {
const int value = printKeyActionGroup->id(button);
const int value = m_ui->printKeyActionGroup->id(button);
workaroundLabel->setText(QString::number(value));
}
});
// /Workaround
mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed));
// actions to take after taking a screenshot
auto copyImageToClipboard = new QCheckBox(i18n("Copy image to clipboard"), this);
copyImageToClipboard->setObjectName(QStringLiteral("kcfg_copyImageToClipboard"));
mainLayout->addRow(i18n("After taking a screenshot:"), copyImageToClipboard);
auto autoSaveImage = new QCheckBox(i18n("Autosave the image to the default location"), this);
autoSaveImage->setObjectName(QStringLiteral("kcfg_autoSaveImage"));
mainLayout->addRow(QString(), autoSaveImage);
mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed));
// Rectangular Region settings
KTitleWidget *titleWidget = new KTitleWidget(this);
titleWidget->setText(i18n("Rectangular Region"));
titleWidget->setLevel(2);
mainLayout->addRow(titleWidget);
// use light background
QCheckBox* kcfg_useLightMaskColour = new QCheckBox(i18n("Use light background"), this);
kcfg_useLightMaskColour->setObjectName(QStringLiteral("kcfg_useLightMaskColour"));
mainLayout->addRow(i18n("General:"), kcfg_useLightMaskColour);
// show magnifier
auto showMagnifier = new QCheckBox(i18n("Show magnifier"), this);
showMagnifier->setObjectName(QStringLiteral("kcfg_showMagnifier"));
mainLayout->addRow(QString(), showMagnifier);
// release mouse-button to capture
auto releaseToCapture = new QCheckBox(i18n("Accept on click-and-release"), this);
releaseToCapture->setObjectName(QStringLiteral("kcfg_useReleaseToCapture"));
mainLayout->addRow(QString(), releaseToCapture);
mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed));
// remember Rectangular Region box
QButtonGroup* rememberGroup = new QButtonGroup(this);
rememberGroup->setExclusive(true);
QRadioButton* neverButton = new QRadioButton(i18n("Never"), this);
auto rememberAlways = new QRadioButton(i18n("Always"), this);
rememberAlways->setObjectName(QStringLiteral("kcfg_alwaysRememberRegion"));
auto rememberUntilClosed = new QRadioButton(i18n("Until Spectacle is closed"), this);
rememberUntilClosed->setObjectName(QStringLiteral("kcfg_rememberLastRectangularRegion"));
rememberGroup->addButton(neverButton);
rememberGroup->addButton(rememberAlways);
rememberGroup->addButton(rememberUntilClosed);
neverButton->setChecked(true);
mainLayout->addRow(i18n("Remember selected area:"), neverButton);
mainLayout->addRow(QString(), rememberAlways);
mainLayout->addRow(QString(), rememberUntilClosed);
}
GeneralOptionsPage::~GeneralOptionsPage() = default;
......@@ -20,8 +20,11 @@
#ifndef GENERALOPTIONSPAGE_H
#define GENERALOPTIONSPAGE_H
#include <QScopedPointer>
#include <QWidget>
class Ui_GeneralOptions;
class GeneralOptionsPage : public QWidget
{
Q_OBJECT
......@@ -29,6 +32,11 @@ class GeneralOptionsPage : public QWidget
public:
explicit GeneralOptionsPage(QWidget *parent = nullptr);
~GeneralOptionsPage() override;
private:
QScopedPointer<Ui_GeneralOptions> m_ui;
};
#endif // GENERALOPTIONSPAGE_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SaveOptions</class>
<widget class="QWidget" name="SaveOptions">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>598</width>
<height>286</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="saveLocationLabel">
<property name="text">
<string>Save Location:</string>
</property>
<property name="buddy">
<cstring>kcfg_defaultSaveLocation</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KUrlRequester" name="kcfg_defaultSaveLocation">
<property name="mode">
<set>KFile::Directory|KFile::LocalOnly</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="kcfg_copySaveLocation">
<property name="text">
<string>Copy file location to clipboard after saving</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>18</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0">
<widget class="QLabel" name="qualityLabel">
<property name="text">
<string>Compression Quality:</string>
</property>
<property name="buddy">
<cstring>qualitySpinner</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QVBoxLayout" name="qualityVLayout">
<item>
<layout class="QHBoxLayout" name="qualityHLayout">
<item>
<widget class="QSlider" name="kcfg_compressionQuality">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="qualitySpinner">
<property name="suffix">
<string>%</string>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Choose the image quality when saving with lossy image formats like JPEG</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="filenameLabel">
<property name="text">
<string>Filename:</string>
</property>
<property name="buddy">
<cstring>kcfg_saveFilenameFormat</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="saveLayout">
<item>
<widget class="QLineEdit" name="kcfg_saveFilenameFormat">
<property name="placeholderText">
<string notr="true">%d</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="kcfg_defaultSaveImageFormat">
<property name="kcfg_property" stdset="0">
<string>currentText</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QLabel" name="PreviewLabel">
<property name="text">
<string comment="Preview of the user configured filename">Preview:</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLabel" name="preview">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLabel" name="helpTextLabel">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>18</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KUrlRequester</class>
<extends>QWidget</extends>
<header>kurlrequester.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>kcfg_compressionQuality</sender>
<signal>valueChanged(int)</signal>
<receiver>qualitySpinner</receiver>
<slot>setValue(int)</slot>
</connection>
<connection>
<sender>qualitySpinner</sender>
<signal>valueChanged(int)</signal>
<receiver>kcfg_compressionQuality</receiver>
<slot>setValue(int)</slot>
</connection>
</connections>
</ui>
......@@ -22,6 +22,7 @@
#include "SpectacleCommon.h"
#include "ExportManager.h"
#include "ui_SaveOptions.h"
#include <KIOWidgets/KUrlRequester>
#include <KLocalizedString>
......@@ -35,63 +36,13 @@
#include <QImageWriter>
#include <QCheckBox>
SaveOptionsPage::SaveOptionsPage(QWidget *parent) : QWidget(parent)
SaveOptionsPage::SaveOptionsPage(QWidget *parent)
: QWidget(parent)
, m_ui(new Ui_SaveOptions)
{
QFormLayout *mainLayout = new QFormLayout;
setLayout(mainLayout);
m_ui->setupUi(this);
// Save location
auto urlRequester = new KUrlRequester(this);
urlRequester->setObjectName(QStringLiteral("kcfg_defaultSaveLocation"));
urlRequester->setMode(KFile::Directory);
mainLayout->addRow(i18n("Save Location:"), urlRequester);
// copy file location to clipboard after saving
auto copyPathToClipboard = new QCheckBox(i18n("Copy file location to clipboard after saving"), this);
copyPathToClipboard->setObjectName(QStringLiteral("kcfg_copySaveLocation"));
mainLayout->addRow(QString(), copyPathToClipboard);
mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed));
// Compression quality slider and current value display