Commit 9658891a authored by David Redondo's avatar David Redondo 🏎
Browse files

Port towards KConfig XT

Summary:
Port settings to Kconfig XT. This enables us to drop our own settings class and
our own configuration dialog logic with it's logic. Setting the objectNames of
the Widgets accordingly enables us to reuse them.
The settings not managed through the Dialog (last save locations and screenshot
options in the main window) are written now on exit but are still instant apply.
Using this opportunity this also unifies the naming style and moves some
settings inside the config file around: In general they are now in the same group
as they are in the settings dialog. Additionally [Save] includes
lastSave(As)Location, too. In [GuiConfig] are the options which are set in the
main window and the last crop region.
Also includes a behavioral change: "Open Screenshots Folder" will now open the
default folder as configured. The folder with the the last saved screenshot can
be opened from the inline message when saving.

BUG: 389894
FIXED-IN: 19.12.0

Test Plan: Works as before but the dialog has now more buttons

Reviewers: #spectacle, ngraham

Reviewed By: #spectacle, ngraham

Subscribers: guoyunhe, ervin, crossi, ngraham

Tags: #spectacle

Differential Revision: https://phabricator.kde.org/D23316
parent 9c43e1e6
......@@ -24,6 +24,10 @@ install(
FILES spectacle_shortcuts.upd
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}
)
install(
FILES spectacle_newConfig.upd
DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR}
)
add_executable(spectacle-migrate-shortcuts MigrateShortcuts.cpp)
target_link_libraries(spectacle-migrate-shortcuts Qt5::DBus KF5::GlobalAccel KF5::ConfigCore KF5::XmlGui KF5::I18n)
install(
......
Version=5
Id=spectacle-new-config
File=spectaclerc
Group=GuiConfig,General
Key=showMagnifier
Key=useReleaseToCapture
Key=useLightMaskColour
Key=rememberLastRectangularRegion
Key=alwaysRememberRegion
Key=printKeyActionRunning
Group=GuiConfig,Save
Key=compressionQuality
Key=lastUsedSaveMode
Group=General,Save
Key=copySaveLocation
Key=lastSaveAsFile,lastSaveAsLocation
Key=lastSaveFile,lastSaveLocation
Key=save-filename-format,saveFilenameFormat
Key=default-save-location,defaultSaveLocation
Key=default-save-image-format,defaultSaveImageFormat
Group=GuiConfig
Key=captureModeIndex,captureMode
......@@ -26,8 +26,8 @@ set(
Main.cpp
ExportManager.cpp
SpectacleCore.cpp
SpectacleConfig.cpp
SpectacleDBusAdapter.cpp
ShortcutActions.cpp
${SPECTACLE_SRCS_PLATFORM}
Gui/KSMainWindow.cpp
Gui/KSWidget.cpp
......@@ -35,14 +35,15 @@ set(
Gui/ExportMenu.cpp
Gui/ProgressButton.cpp
Gui/SmartSpinBox.cpp
Gui/SettingsDialog/SettingsDialog.cpp
Gui/SettingsDialog/SettingsPage.cpp
Gui/SettingsDialog/SaveOptionsPage.cpp
Gui/SettingsDialog/SettingsDialog.cpp
Gui/SettingsDialog/GeneralOptionsPage.cpp
Gui/SettingsDialog/ShortcutsOptionsPage.cpp
QuickEditor/QuickEditor.cpp
)
kconfig_add_kcfg_files(SPECTACLE_SRCS_DEFAULT Gui/SettingsDialog/settings.kcfgc)
ecm_qt_declare_logging_category(SPECTACLE_SRCS_DEFAULT HEADER spectacle_core_debug.h IDENTIFIER SPECTACLE_CORE_LOG CATEGORY_NAME org.kde.spectacle.core)
ecm_qt_declare_logging_category(SPECTACLE_SRCS_DEFAULT HEADER spectacle_gui_debug.h IDENTIFIER SPECTACLE_GUI_LOG CATEGORY_NAME org.kde.spectacle.gui)
......
/* This file is part of Spectacle, the KDE screenshot utility
* Copyright 2019 David Redondo <kde@david-redondo.de>
* Copyright (C) 2015 Boudhayan Gupta <bgupta@kde.org>
*
* This program is free software; you can redistribute it and/or modify
......@@ -21,6 +22,8 @@
#include "ExportManager.h"
#include "settings.h"
#include <QDir>
#include <QMimeData>
#include <QMimeDatabase>
......@@ -42,7 +45,7 @@
#include <KIO/FileCopyJob>
#include <KIO/StatJob>
#include "SpectacleConfig.h"
ExportManager::ExportManager(QObject *parent) :
QObject(parent),
......@@ -50,9 +53,7 @@ ExportManager::ExportManager(QObject *parent) :
mTempFile(QUrl()),
mTempDir(nullptr)
{
connect(this, &ExportManager::imageSaved, [](const QUrl &savedAt) {
SpectacleConfig::instance()->setLastSaveFile(savedAt);
});
connect(this, &ExportManager::imageSaved, &Settings::setLastSaveLocation);
}
ExportManager::~ExportManager()
......@@ -120,7 +121,7 @@ void ExportManager::setTimestamp(const QDateTime &timestamp)
QString ExportManager::defaultSaveLocation() const
{
QString savePath = SpectacleConfig::instance()->defaultSaveLocation().toLocalFile();
QString savePath = Settings::self()->defaultSaveLocation().toLocalFile();
savePath = QDir::cleanPath(savePath);
QDir savePathDir(savePath);
......@@ -137,7 +138,7 @@ QUrl ExportManager::getAutosaveFilename()
const QDir baseDirPath(baseDir);
const QString filename = makeAutosaveFilename();
const QString fullpath = autoIncrementFilename(baseDirPath.filePath(filename),
SpectacleConfig::instance()->saveImageFormat(),
Settings::self()->defaultSaveImageFormat(),
&ExportManager::isFileExists);
const QUrl fileNameUrl = QUrl::fromUserInput(fullpath);
......@@ -161,7 +162,7 @@ QString ExportManager::truncatedFilename(QString const &filename)
QString ExportManager::makeAutosaveFilename()
{
return formatFilename(SpectacleConfig::instance()->autoSaveFilenameFormat());
return formatFilename(Settings::self()->saveFilenameFormat());
}
QString ExportManager::formatFilename(const QString &nameTemplate)
......@@ -246,7 +247,7 @@ QString ExportManager::formatFilename(const QString &nameTemplate)
}
if (result.isEmpty()) {
result = SpectacleConfig::instance()->defaultFilename();
result = QStringLiteral("Screenshot");
}
return truncatedFilename(result);
}
......@@ -280,7 +281,7 @@ QString ExportManager::makeSaveMimetype(const QUrl &url)
QString type = mimedb.mimeTypeForUrl(url).preferredSuffix();
if (type.isEmpty()) {
return SpectacleConfig::instance()->saveImageFormat();
return Settings::self()->defaultSaveImageFormat();
}
return type;
}
......@@ -288,7 +289,7 @@ QString ExportManager::makeSaveMimetype(const QUrl &url)
bool ExportManager::writeImage(QIODevice *device, const QByteArray &format)
{
QImageWriter imageWriter(device, format);
imageWriter.setQuality(SpectacleConfig::instance()->compressionQuality());
imageWriter.setQuality(Settings::self()->compressionQuality());
/** Set compression 50 if the format is png. Otherwise if no compression value is specified
* it will fallback to using quality (QTBUG-43618) and produce huge files.
* See also qpnghandler.cpp#n1075. The other formats that do compression seem to have it
......@@ -455,7 +456,6 @@ void ExportManager::doSave(const QUrl &url, bool notify)
if (save(savePath)) {
QDir dir(savePath.path());
dir.cdUp();
SpectacleConfig::instance()->setLastSaveFile(savePath);
emit imageSaved(savePath);
if (notify) {
......@@ -467,7 +467,6 @@ void ExportManager::doSave(const QUrl &url, bool notify)
bool ExportManager::doSaveAs(QWidget *parentWindow, bool notify)
{
QStringList supportedFilters;
SpectacleConfig *config = SpectacleConfig::instance();
// construct the supported mimetype list
const auto mimeTypes = QImageWriter::supportedMimeTypes();
......@@ -476,12 +475,12 @@ bool ExportManager::doSaveAs(QWidget *parentWindow, bool notify)
}
// construct the file name
const QString filenameExtension = SpectacleConfig::instance()->saveImageFormat();
const QString mimetype = QMimeDatabase().mimeTypeForFile(QLatin1String("~/fakefile.") + filenameExtension, QMimeDatabase::MatchExtension).name();
const QString filenameExtension = Settings::self()->defaultSaveImageFormat();
const QString mimetype = QMimeDatabase().mimeTypeForFile(QStringLiteral("~/fakefile.") + filenameExtension, QMimeDatabase::MatchExtension).name();
QFileDialog dialog(parentWindow);
dialog.setAcceptMode(QFileDialog::AcceptSave);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setDirectoryUrl(config->lastSaveAsLocation());
dialog.setDirectoryUrl(Settings::self()->lastSaveAsLocation());
dialog.selectFile(makeAutosaveFilename() + QStringLiteral(".") + filenameExtension);
dialog.setDefaultSuffix(QStringLiteral(".") + filenameExtension);
dialog.setMimeTypeFilters(supportedFilters);
......@@ -493,8 +492,7 @@ bool ExportManager::doSaveAs(QWidget *parentWindow, bool notify)
if (saveUrl.isValid()) {
if (save(saveUrl)) {
emit imageSaved(saveUrl);
config->setLastSaveAsFile(saveUrl);
Settings::setLastSaveAsLocation(saveUrl);
if (notify) {
emit forceNotify(saveUrl);
}
......@@ -516,7 +514,7 @@ void ExportManager::doSaveAndCopy(const QUrl &url)
if (save(savePath)) {
QDir dir(savePath.path());
dir.cdUp();
SpectacleConfig::instance()->setLastSaveFile(savePath);
Settings::setLastSaveLocation(savePath);
doCopyToClipboard(false);
emit imageSavedAndCopied(savePath);
......@@ -524,7 +522,6 @@ void ExportManager::doSaveAndCopy(const QUrl &url)
}
// misc helpers
void ExportManager::doCopyToClipboard(bool notify)
{
auto data = new QMimeData();
......
......@@ -23,7 +23,11 @@
#include "KSMainWindow.h"
#include "Config.h"
#include "settings.h"
#include "SettingsDialog/SettingsDialog.h"
#include "SettingsDialog/GeneralOptionsPage.h"
#include "SettingsDialog/SaveOptionsPage.h"
#include "SettingsDialog/ShortcutsOptionsPage.h"
#include <QApplication>
#include <QClipboard>
......@@ -47,7 +51,10 @@
#include <KGuiItem>
#include <KHelpMenu>
#include <KIO/OpenFileManagerWindowJob>
#include <KRun>
#include <KLocalizedString>
#include <KConfigGroup>
#include <KSharedConfig>
#include <KStandardAction>
#include <KWindowSystem>
......@@ -174,7 +181,7 @@ void KSMainWindow::init()
// the tools menu
mToolsMenu->addAction(QIcon::fromTheme(QStringLiteral("document-open-folder")),
i18n("Open Screenshots Folder"),
i18n("Open Default Screenshots Folder"),
this, &KSMainWindow::openScreenshotsFolder);
mToolsMenu->addAction(KStandardAction::print(this, &KSMainWindow::showPrintDialog, this));
mScreenRecorderToolsMenu = mToolsMenu->addMenu(i18n("Record Screen"));
......@@ -228,11 +235,11 @@ void KSMainWindow::init()
// message: open containing folder
mOpenContaining = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), i18n("Open Containing Folder"), mMessageWidget);
connect(mOpenContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({SpectacleConfig::instance()->lastSaveFile()});});
connect(mOpenContaining, &QAction::triggered, [=] { KIO::highlightInFileManager({Settings::lastSaveLocation()});});
mHideMessageWidgetTimer = new QTimer(this);
connect(mHideMessageWidgetTimer, &QTimer::timeout,
mMessageWidget, &KMessageWidget::animatedHide);
// connect(mHideMessageWidgetTimer, &QTimer::timeout,
// mMessageWidget, &KMessageWidget::animatedHide);
mHideMessageWidgetTimer->setInterval(10000);
// done with the init
}
......@@ -249,19 +256,17 @@ int KSMainWindow::windowWidth(const QPixmap &pixmap) const
int alignedWindowWidth = qMin(mKSWidget->imagePaddingWidth() + imageWidth, MAXIMUM_WINDOW_WIDTH);
alignedWindowWidth += layout()->contentsMargins().left() + layout()->contentsMargins().right();
alignedWindowWidth += 2; // margins is removing 1 - 1 pixel for some reason
return alignedWindowWidth;
}
void KSMainWindow::setDefaultSaveAction()
{
switch (SpectacleConfig::instance()->lastUsedSaveMode()) {
case SaveMode::SaveAs:
default:
switch (Settings::lastUsedSaveMode()) {
case Settings::SaveAs:
mSaveButton->setDefaultAction(mSaveAsAction);
mSaveButton->setText(i18n("Save As..."));
break;
case SaveMode::Save:
case Settings::Save:
mSaveButton->setDefaultAction(mSaveAction);
break;
}
......@@ -367,31 +372,7 @@ void KSMainWindow::showPrintDialog()
void KSMainWindow::openScreenshotsFolder()
{
// Highlight last screenshot in file manager if user saved at least once ever
// (since last save and saveas file names are stored in spectaclerc), otherwise,
// if in save mode, open default save location from configure > save > location
// if in save as mode, open last save as files location
// failsafe for either option is default save location from configure > save > location
SpectacleConfig *cfgManager = SpectacleConfig::instance();
ExportManager *exportManager = ExportManager::instance();
QUrl location;
switch(cfgManager->lastUsedSaveMode()) {
case SaveMode::Save:
location = cfgManager->lastSaveFile();
if (!exportManager->isFileExists(location)) {
location = cfgManager->defaultSaveLocation();
}
break;
case SaveMode::SaveAs:
location = cfgManager->lastSaveAsFile(); // already has a "/" at the end
if (!exportManager->isFileExists(location)) {
location = cfgManager->lastSaveAsLocation();
}
break;
}
KIO::highlightInFileManager({location});
new KRun(Settings::defaultSaveLocation(), this);
}
void KSMainWindow::quit(const QuitBehavior quitBehavior)
......@@ -464,7 +445,7 @@ void KSMainWindow::showImageSharedFeedback(bool error, const QString &message)
void KSMainWindow::copy()
{
const bool quitChecked = SpectacleConfig::instance()->quitAfterSaveOrCopyChecked();
const bool quitChecked = Settings::quitAfterSaveCopyExport();
ExportManager::instance()->doCopyToClipboard();
if (quitChecked) {
quit(QuitBehavior::QuitExternally);
......@@ -479,8 +460,10 @@ void KSMainWindow::imageCopied()
void KSMainWindow::showPreferencesDialog()
{
SettingsDialog prefDialog(this);
prefDialog.exec();
if (KConfigDialog::showDialog(QStringLiteral("settings"))) {
return;
}
(new SettingsDialog(this))->show();
}
void KSMainWindow::imageSaved(const QUrl &location)
......@@ -503,10 +486,10 @@ void KSMainWindow::imageSavedAndCopied(const QUrl &location)
void KSMainWindow::save()
{
SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save);
Settings::setLastUsedSaveMode(Settings::Save);
setDefaultSaveAction();
const bool quitChecked = SpectacleConfig::instance()->quitAfterSaveOrCopyChecked();
const bool quitChecked = Settings::quitAfterSaveCopyExport();
ExportManager::instance()->doSave(QUrl(), /* notify */ quitChecked);
if (quitChecked) {
quit(QuitBehavior::QuitExternally);
......@@ -515,10 +498,10 @@ void KSMainWindow::save()
void KSMainWindow::saveAs()
{
SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::SaveAs);
Settings::setLastUsedSaveMode(Settings::SaveAs);
setDefaultSaveAction();
const bool quitChecked = SpectacleConfig::instance()->quitAfterSaveOrCopyChecked();
const bool quitChecked = Settings::quitAfterSaveCopyExport();
if (ExportManager::instance()->doSaveAs(this, /* notify */ quitChecked) && quitChecked) {
quit(QuitBehavior::QuitExternally);
}
......@@ -529,7 +512,7 @@ void KSMainWindow::restoreWindowTitle()
if (isWindowModified()) {
setWindowTitle(i18nc("@title:window Unsaved Screenshot", "Unsaved[*]"));
} else {
setWindowTitle(SpectacleConfig::instance()->lastSaveFile().fileName());
setWindowTitle(Settings::lastSaveLocation().fileName());
}
}
......
......@@ -31,7 +31,7 @@
#include <KNS3/KMoreToolsMenuFactory>
#include "SpectacleCommon.h"
#include "SpectacleConfig.h"
#include "KSWidget.h"
#include "ExportMenu.h"
#include "Platforms/Platform.h"
......
/*
* Copyright 2019 David Redondo <kde@david-redondo.de>
* Copyright (C) 2015 Boudhayan Gupta <bgupta@kde.org>
*
* This program is free software; you can redistribute it and/or modify
......@@ -21,8 +22,8 @@
#include "spectacle_gui_debug.h"
#include "KSImageWidget.h"
#include "settings.h"
#include "SmartSpinBox.h"
#include "SpectacleConfig.h"
#include "ProgressButton.h"
#include <QAction>
......@@ -40,9 +41,6 @@
KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) :
QWidget(parent)
{
// get a handle to the configuration manager
SpectacleConfig *lConfigMgr = SpectacleConfig::instance();
// we'll init the widget that holds the image first
mImageWidget = new KSImageWidget(this);
mImageWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
......@@ -55,19 +53,25 @@ KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) :
? i18n("Full Screen")
: i18n("Full Screen (All Monitors)");
if (theGrabModes.testFlag(Platform::GrabMode::AllScreens))
mCaptureArea->insertItem(1, lFullScreenLabel, Spectacle::CaptureMode::AllScreens);
if (theGrabModes.testFlag(Platform::GrabMode::CurrentScreen))
if (theGrabModes.testFlag(Platform::GrabMode::AllScreens)) {
mCaptureArea->insertItem(0, lFullScreenLabel, Spectacle::CaptureMode::AllScreens);
mCaptureArea->insertItem(1, i18n("Rectangular Region"), Spectacle::CaptureMode::RectangularRegion);
}
if (theGrabModes.testFlag(Platform::GrabMode::CurrentScreen)) {
mCaptureArea->insertItem(2, i18n("Current Screen"), Spectacle::CaptureMode::CurrentScreen);
if (theGrabModes.testFlag(Platform::GrabMode::ActiveWindow))
}
if (theGrabModes.testFlag(Platform::GrabMode::ActiveWindow)) {
mCaptureArea->insertItem(3, i18n("Active Window"), Spectacle::CaptureMode::ActiveWindow);
if (theGrabModes.testFlag(Platform::GrabMode::WindowUnderCursor))
}
if (theGrabModes.testFlag(Platform::GrabMode::WindowUnderCursor)) {
mCaptureArea->insertItem(4, i18n("Window Under Cursor"), Spectacle::CaptureMode::WindowUnderCursor);
}
if (theGrabModes.testFlag(Platform::GrabMode::TransientWithParent)) {
mTransientWithParentAvailable = true;
}
mCaptureArea->insertItem(5, i18n("Rectangular Region"), Spectacle::CaptureMode::RectangularRegion);
mCaptureArea->setMinimumWidth(240);
int index = mCaptureArea->findData(Settings::captureMode());
mCaptureArea->setCurrentIndex(index >= 0 ? index : 0);
connect(mCaptureArea, qOverload<int>(&QComboBox::currentIndexChanged), this, &KSWidget::captureModeChanged);
mDelayMsec = new SmartSpinBox(this);
......@@ -77,12 +81,12 @@ KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) :
mDelayMsec->setMaximum(999.9);
mDelayMsec->setSpecialValueText(i18n("No Delay"));
mDelayMsec->setMinimumWidth(160);
connect(mDelayMsec, qOverload<qreal>(&SmartSpinBox::valueChanged), lConfigMgr, &SpectacleConfig::setCaptureDelay);
connect(mDelayMsec, qOverload<qreal>(&SmartSpinBox::valueChanged), &Settings::setCaptureDelay);
mCaptureOnClick = new QCheckBox(i18n("On Click"), this);
mCaptureOnClick->setToolTip(i18n("Wait for a mouse click before capturing the screenshot image"));
connect(mCaptureOnClick, &QCheckBox::stateChanged, this, &KSWidget::onClickStateChanged);
connect(mCaptureOnClick, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setOnClickChecked);
connect(mCaptureOnClick, &QCheckBox::clicked, &Settings::setOnClickChecked);
mDelayLayout = new QHBoxLayout;
mDelayLayout->addWidget(mDelayMsec);
......@@ -99,22 +103,22 @@ KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) :
mMousePointer = new QCheckBox(i18n("Include mouse pointer"), this);
mMousePointer->setToolTip(i18n("Show the mouse cursor in the screenshot image"));
connect(mMousePointer, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludePointerChecked);
connect(mMousePointer, &QCheckBox::clicked, &Settings::setIncludePointer);
mWindowDecorations = new QCheckBox(i18n("Include window titlebar and borders"), this);
mWindowDecorations->setToolTip(i18n("Show the window title bar, the minimize/maximize/close buttons, and the window border"));
mWindowDecorations->setEnabled(false);
connect(mWindowDecorations, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setIncludeDecorationsChecked);
connect(mWindowDecorations, &QCheckBox::clicked, &Settings::setIncludeDecorations);
mCaptureTransientOnly = new QCheckBox(i18n("Capture the current pop-up only"), this);
mCaptureTransientOnly->setToolTip(i18n("Capture only the current pop-up window (like a menu, tooltip etc).\n"
"If disabled, the pop-up is captured along with the parent window"));
mCaptureTransientOnly->setEnabled(false);
connect(mCaptureTransientOnly, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setCaptureTransientWindowOnlyChecked);
connect(mCaptureTransientOnly, &QCheckBox::clicked, &Settings::setTransientOnly);
mQuitAfterSaveOrCopy = new QCheckBox(i18n("Quit after manual Save or Copy"), this);
mQuitAfterSaveOrCopy->setToolTip(i18n("Quit Spectacle after manually saving or copying the image"));
connect(mQuitAfterSaveOrCopy, &QCheckBox::clicked, lConfigMgr, &SpectacleConfig::setQuitAfterSaveOrCopyChecked);
connect(mQuitAfterSaveOrCopy, &QCheckBox::clicked, &Settings::setQuitAfterSaveCopyExport);
mContentOptionsForm = new QVBoxLayout;
mContentOptionsForm->addWidget(mMousePointer);
......@@ -160,15 +164,12 @@ KSWidget::KSWidget(const Platform::GrabModes &theGrabModes, QWidget *parent) :
mMainLayout->setColumnMinimumWidth(1, 320);
// and read in the saved checkbox states and capture mode indices
mMousePointer->setChecked (lConfigMgr->includePointerChecked());
mWindowDecorations->setChecked (lConfigMgr->includeDecorationsChecked());
mCaptureOnClick->setChecked (lConfigMgr->onClickChecked());
mCaptureTransientOnly->setChecked (lConfigMgr->captureTransientWindowOnlyChecked());
mQuitAfterSaveOrCopy->setChecked (lConfigMgr->quitAfterSaveOrCopyChecked());
if (lConfigMgr->captureMode() >= 0) {
mCaptureArea->setCurrentIndex (lConfigMgr->captureMode());
}
mDelayMsec->setValue (lConfigMgr->captureDelay());
mMousePointer->setChecked(Settings::includePointer());
mWindowDecorations->setChecked(Settings::includeDecorations());
mCaptureOnClick->setChecked(Settings::onClickChecked());
mCaptureTransientOnly->setChecked(Settings::transientOnly());
mQuitAfterSaveOrCopy->setChecked(Settings::quitAfterSaveCopyExport());
mDelayMsec->setValue(Settings::captureDelay());
}
int KSWidget::imagePaddingWidth() const
......@@ -234,11 +235,10 @@ void KSWidget::onClickStateChanged(int theState)
void KSWidget::captureModeChanged(int theIndex)
{
SpectacleConfig::instance()->setCaptureMode(theIndex);
Spectacle::CaptureMode captureMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->itemData(theIndex).toInt());
Settings::setCaptureMode(captureMode);
Spectacle::CaptureMode lCaptureMode = static_cast<Spectacle::CaptureMode>(mCaptureArea->itemData(theIndex).toInt());
switch(lCaptureMode) {
switch(captureMode) {
case Spectacle::CaptureMode::WindowUnderCursor:
mWindowDecorations->setEnabled(true);
if (mTransientWithParentAvailable) {
......
/*
* Copyright 2019 David Redondo <kde@david-redondo.de>
* Copyright (C) 2015 Boudhayan Gupta <bgupta@kde.org>
*
* This program is free software; you can redistribute it and/or modify
......@@ -19,20 +20,20 @@
#include "GeneralOptionsPage.h"
#include "SpectacleConfig.h"
#include <KLocalizedString>
#include <KTitleWidget>
#include <KWindowSystem>
#include <QButtonGroup>
#include <QCheckBox>
#include <QLineEdit>
#include <QFormLayout>
#include <QRadioButton>
#include <QSpacerItem>
#include <QTextEdit>
GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) :
SettingsPage(parent)
QWidget{parent}
{
QFormLayout *mainLayout = new QFormLayout(this);
setLayout(mainLayout);
......@@ -44,30 +45,49 @@ GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) :
mainLayout->addRow(runningTitle);
QRadioButton* takeNew = new QRadioButton(i18n("Take a new screenshot"), this);
QRadioButton* startNewInstance = new QRadioButton(i18n("Open a new Spectacle window"), this);
mPrintKeyActionGroup = new QButtonGroup(this);
mPrintKeyActionGroup->setExclusive(true);
mPrintKeyActionGroup->addButton(takeNew, SpectacleConfig::PrintKeyActionRunning::TakeNewScreenshot);
mPrintKeyActionGroup->addButton(startNewInstance, SpectacleConfig::PrintKeyActionRunning::StartNewInstance);
connect( mPrintKeyActionGroup, qOverload<int, bool>(&QButtonGroup::buttonToggled), this, &GeneralOptionsPage::markDirty);
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);
mPrintKeyActionGroup->addButton( focusWindow, SpectacleConfig::PrintKeyActionRunning::FocusWindow);
printKeyActionGroup->addButton( focusWindow,2);// SpectacleConfig::PrintKeyActionRunning::FocusWindow);
mainLayout->addRow(QString(), focusWindow);
}
//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);
});
connect(printKeyActionGroup, qOverload<int, bool>(&QButtonGroup::buttonToggled),
workaroundLabel, [workaroundLabel] (int value, bool checked) {
if (checked) {
workaroundLabel->setText(QString::number(value));
}
});
// /Workaround
mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed));
// actions to take after taking a screenshot
mCopyImageToClipboard = new QCheckBox(i18n("Copy image to clipboard"), this);
connect(mCopyImageToClipboard, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty);
mainLayout->addRow(i18n("After taking a screenshot:"), mCopyImageToClipboard);
auto copyImageToClipboard = new QCheckBox(i18n("Copy image to clipboard"), this);
copyImageToClipboard->setObjectName(QStringLiteral("kcfg_copyImageToClipboard"));
mainLayout->addRow(i18n("After taking a screenshot:"), copyImageToClipboard);
mAutoSaveImage = new QCheckBox(i18n("Autosave the image to the default location"), this);
connect(mAutoSaveImage, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty);
mainLayout->addRow(QString(), mAutoSaveImage);
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));
......@@ -78,19 +98,19 @@ GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) :
mainLayout->addRow(titleWidget);
// use light background
mUseLightBackground = new QCheckBox(i18n("Use light background"), this);
connect(mUseLightBackground, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty);
mainLayout->addRow(i18n("General:"), mUseLightBackground);
QCheckBox* kcfg_useLightMaskColour = new QCheckBox(i18n("Use light background"), this);