Commit 442db7fa authored by Nicolas Fella's avatar Nicolas Fella

Add double tap to maximize screen brightness

Summary:
For barcode scanning it's best to maximize the screen brightness. It's more useful on Android than on the desktop, but this implementation is useful for Plasma Mobile. I plan to add
support for Android later.

Test Plan: Double click on barcode, see screen getting brighter.

Reviewers: vkrause

Reviewed By: vkrause

Subscribers: kde-pim

Tags: #kde_pim, #kde_itinerary

Differential Revision: https://phabricator.kde.org/D17035
parent 3271c406
......@@ -30,6 +30,7 @@ find_package(KPimItinerary 5.9.40 CONFIG REQUIRED)
find_package(SharedMimeInfo 1.0 REQUIRED)
find_package(ZLIB REQUIRED)
set_package_properties("ZLIB" PROPERTIES PURPOSE "Needed for retrieving weather forecast data.")
set_package_properties(KF5Solid PROPERTIES TYPE OPTIONAL TYPE RUNTIME PURPOSE "Used for controlling the screen brightness.")
include(ECMQMLModules)
ecm_find_qmlmodule(org.kde.prison 1.0)
......@@ -46,8 +47,9 @@ if (ANDROID)
endif()
find_package(OpenSSL REQUIRED)
else()
find_package(Qt5 REQUIRED COMPONENTS Widgets Positioning)
find_package(Qt5 REQUIRED COMPONENTS Widgets Positioning DBus)
find_package(KF5 REQUIRED COMPONENTS DBusAddons)
find_package(KF5 COMPONENTS Solid)
endif()
add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_URL_CAST_FROM_STRING)
......
......@@ -9,12 +9,15 @@ set(itinerary_srcs
tripgroup.cpp
tripgroupmanager.cpp
tripgroupproxymodel.cpp
brightnessmanager.cpp
solidbrightnessbackend.cpp
)
ecm_qt_declare_logging_category(itinerary_srcs
HEADER logging.h
IDENTIFIER Log
CATEGORY_NAME org.kde.itinerary
)
qt5_add_dbus_interface(itinerary_srcs org.kde.Solid.PowerManagement.Actions.BrightnessControl.xml brightnesscontroldbusinterface)
add_library(itinerary STATIC ${itinerary_srcs})
target_link_libraries(itinerary PUBLIC
itinerary-weather
......@@ -23,6 +26,7 @@ target_link_libraries(itinerary PUBLIC
KF5::I18n
Qt5::Network
Qt5::Quick
Qt5::DBus
)
if (Qt5QuickCompiler_FOUND)
......@@ -103,7 +107,7 @@ if (ANDROID)
weather-storm
)
else ()
target_link_libraries(itinerary PRIVATE Qt5::Positioning)
target_link_libraries(itinerary PRIVATE Qt5::Positioning Qt5::DBus)
target_link_libraries(itinerary-app PRIVATE
KF5::DBusAddons
Qt5::Widgets
......
......@@ -30,6 +30,11 @@ Rectangle {
radius: 6
Layout.alignment: Qt.AlignCenter
MouseArea {
anchors.fill: parent
onDoubleClicked: _brightnessManager.maxBrightness();
}
ColumnLayout {
id: barcodeLayout
anchors.fill: parent
......
......@@ -62,6 +62,11 @@ ColumnLayout {
implicitHeight: visible ? implicitWidth : 0
visible: barcode.implicitHeight > 0
MouseArea {
anchors.fill: parent
onDoubleClicked: _brightnessManager.maxBrightness();
}
Prison.Barcode {
id: barcode
anchors.fill: background
......
/*
Copyright (C) 2018 Nicolas Fella <nicolas.fella@gmx.de>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "brightnessmanager.h"
#include <QDebug>
#ifdef Q_OS_LINUX
#include "solidbrightnessbackend.h"
#endif
BrightnessManager::BrightnessManager(QObject *parent)
: QObject(parent)
{
#ifdef Q_OS_LINUX
m_backend = new SolidBrightnessBackend(this);
#endif
}
BrightnessManager::~BrightnessManager() = default;
void BrightnessManager::maxBrightness()
{
if (m_backend) {
m_backend->maxBrightness();
}
}
/*
Copyright (C) 2018 Nicolas Fella <nicolas.fella@gmx.de>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BRIGHTNESSMANAGER_H
#define BRIGHTNESSMANAGER_H
#include <QObject>
class BrightnessBackend : public QObject
{
public:
explicit BrightnessBackend(QObject *parent = nullptr) : QObject(parent) {}
virtual ~BrightnessBackend() = default;
public:
virtual void maxBrightness() = 0;
};
class BrightnessManager : public QObject
{
Q_OBJECT
public:
explicit BrightnessManager(QObject *parent = nullptr);
~BrightnessManager();
public Q_SLOTS:
void maxBrightness();
private:
BrightnessBackend *m_backend;
};
#endif // BRIGHTNESSMANAGER_H
......@@ -32,6 +32,7 @@
#include "tripgroupproxymodel.h"
#include "util.h"
#include "weatherforecastmodel.h"
#include "brightnessmanager.h"
#include <weatherforecastmanager.h>
......@@ -131,6 +132,7 @@ int main(int argc, char **argv)
ApplicationController appController;
appController.setReservationManager(&resMgr);
appController.setPkPassManager(&passMgr);
BrightnessManager brightnessManager;
#ifndef Q_OS_ANDROID
QObject::connect(&service, &KDBusService::activateRequested, [&parser, &appController](const QStringList &args, const QString &workingDir) {
qCDebug(Log) << "remote activation" << args << workingDir;
......@@ -188,6 +190,7 @@ int main(int argc, char **argv)
engine.rootContext()->setContextProperty(QStringLiteral("_appController"), &appController);
engine.rootContext()->setContextProperty(QStringLiteral("_settings"), &settings);
engine.rootContext()->setContextProperty(QStringLiteral("_weatherForecastManager"), &weatherForecastMgr);
engine.rootContext()->setContextProperty(QStringLiteral("_brightnessManager"), &brightnessManager);
engine.load(QStringLiteral("qrc:/main.qml"));
handlePositionalArguments(&appController, parser.positionalArguments());
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kde.Solid.PowerManagement.Actions.BrightnessControl">
<method name="setBrightness">
<arg type="i" direction="in" />
</method>
<method name="setBrightnessSilent">
<arg type="i" direction="in" />
</method>
<method name="brightness">
<arg type="i" direction="out" />
</method>
<method name="brightnessMax">
<arg type="i" direction="out" />
</method>
<signal name="brightnessChanged">
<arg type="i" direction="out" />
</signal>
<signal name="brightnessMaxChanged">
<arg type="i" direction="out" />
</signal>
<method name="brightnessSteps">
<arg type="i" direction="out" />
</method>
</interface>
</node>
/*
Copyright (C) 2018 Nicolas Fella <nicolas.fella@gmx.de>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "solidbrightnessbackend.h"
#include <brightnesscontroldbusinterface.h>
#include <QDBusConnection>
#include <QDebug>
SolidBrightnessBackend::SolidBrightnessBackend(QObject *parent)
: BrightnessBackend(parent)
{
m_iface = new OrgKdeSolidPowerManagementActionsBrightnessControlInterface(
QStringLiteral("org.kde.Solid.PowerManagement"),
QStringLiteral("/org/kde/Solid/PowerManagement/Actions/BrightnessControl"),
QDBusConnection::sessionBus(), this);
}
SolidBrightnessBackend::~SolidBrightnessBackend()
{
}
void SolidBrightnessBackend::maxBrightness()
{
m_iface->setBrightnessSilent(m_iface->brightnessMax());
}
/*
Copyright (C) 2018 Nicolas Fella <nicolas.fella@gmx.de>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SOLIDBRIGHTNESSBACKEND_H
#define SOLIDBRIGHTNESSBACKEND_H
#include <QObject>
#include "brightnessmanager.h"
class OrgKdeSolidPowerManagementActionsBrightnessControlInterface;
class SolidBrightnessBackend : public BrightnessBackend
{
public:
explicit SolidBrightnessBackend(QObject *parent = nullptr);
virtual ~SolidBrightnessBackend();
virtual void maxBrightness();
private:
OrgKdeSolidPowerManagementActionsBrightnessControlInterface *m_iface;
};
#endif // SOLIDBRIGHTNESSBACKEND_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment