Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 71371bbc authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implement a dialog passing Qt forced tablet mapping

Go to Preferences->Tablet Settings->Wintab->Advanced...

In the dialog one can select between modes:

* Use information provided by tablet ---  we fetch the mapping
  from the tablet driver

* Map to entire virtual screen --- default way how Qt handled it
  before

* Map to custom area --- just map to the custom area of the screen
  in **hardware** (that is, unscaled) pixels.
parent 26838096
......@@ -64,6 +64,8 @@
#ifndef USE_QT_TABLET_WINDOWS
#include <kis_tablet_support_win.h>
#include <kis_tablet_support_win8.h>
#else
#include <dialogs/KisDlgCustomTabletResolution.h>
#endif
#include <QLibrary>
#endif
......@@ -308,6 +310,26 @@ extern "C" int main(int argc, char **argv)
#if defined Q_OS_WIN && defined USE_QT_TABLET_WINDOWS && defined QT_HAS_WINTAB_SWITCH
const bool forceWinTab = !KisConfig::useWin8PointerInputNoApp(&kritarc);
QCoreApplication::setAttribute(Qt::AA_MSWindowsUseWinTabAPI, forceWinTab);
if (qEnvironmentVariableIsEmpty("QT_WINTAB_DESKTOP_RECT") &&
qEnvironmentVariableIsEmpty("QT_IGNORE_WINTAB_MAPPING")) {
QRect customTabletRect;
KisDlgCustomTabletResolution::Mode tabletMode =
KisDlgCustomTabletResolution::getTabletMode(&customTabletRect);
if (tabletMode == KisDlgCustomTabletResolution::USE_CUSTOM) {
qputenv("QT_WINTAB_DESKTOP_RECT",
QString("%1;%2;%3;%4")
.arg(customTabletRect.x())
.arg(customTabletRect.y())
.arg(customTabletRect.width())
.arg(customTabletRect.height()).toLatin1());
} else if (tabletMode == KisDlgCustomTabletResolution::USE_VIRTUAL_SCREEN) {
qputenv("QT_IGNORE_WINTAB_MAPPING", "1");
}
}
#endif
// first create the application so we can create a pixmap
......
......@@ -404,6 +404,12 @@ if(WIN32)
input/wintab/kis_screen_size_choice_dialog.cpp
input/wintab/kis_tablet_support_win8.cpp
)
else()
include_directories(SYSTEM ${Qt5Gui_PRIVATE_INCLUDE_DIRS})
set(kritaui_LIB_SRCS
${kritaui_LIB_SRCS}
dialogs/KisDlgCustomTabletResolution.cpp
)
endif()
endif()
......@@ -527,11 +533,17 @@ ki18n_wrap_ui(kritaui_LIB_SRCS
)
if(WIN32 AND NOT USE_QT_TABLET_WINDOWS)
ki18n_wrap_ui(kritaui_LIB_SRCS
input/wintab/kis_screen_size_choice_dialog.ui
)
endif()
if(WIN32)
if(USE_QT_TABLET_WINDOWS)
ki18n_wrap_ui(kritaui_LIB_SRCS
dialogs/KisDlgCustomTabletResolution.ui
)
else()
ki18n_wrap_ui(kritaui_LIB_SRCS
input/wintab/kis_screen_size_choice_dialog.ui
)
endif()
endif()
add_library(kritaui SHARED ${kritaui_HEADERS_MOC} ${kritaui_LIB_SRCS} )
......
/*
* Copyright (c) 2019 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KisDlgCustomTabletResolution.h"
#include "ui_KisDlgCustomTabletResolution.h"
#include <QSettings>
#include "kis_debug.h"
#include <QGuiApplication>
#include <QScreen>
#include <QStandardPaths>
#include <qpa/qplatformscreen.h>
KisDlgCustomTabletResolution::KisDlgCustomTabletResolution(QWidget *parent) :
QDialog(parent),
ui(new Ui::KisDlgCustomTabletResolution)
{
ui->setupUi(this);
connect(ui->btnBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui->btnBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->lblXOffset, SLOT(setEnabled(bool)));
connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->lblYOffset, SLOT(setEnabled(bool)));
connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->lblWidth, SLOT(setEnabled(bool)));
connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->lblHeight, SLOT(setEnabled(bool)));
connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->intXOffset, SLOT(setEnabled(bool)));
connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->intYOffset, SLOT(setEnabled(bool)));
connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->intWidth, SLOT(setEnabled(bool)));
connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->intHeight, SLOT(setEnabled(bool)));
const QRect virtualScreenRect = calcNativeScreenRect();
const QString rectToString =
QString("%1, %2 %3 x %4")
.arg(virtualScreenRect.x())
.arg(virtualScreenRect.y())
.arg(virtualScreenRect.width())
.arg(virtualScreenRect.height());
ui->radioMapToEntireScreen->setText(i18nc("@option:radio", "Map to entire virtual screen (%1)", rectToString));
QRect customScreenRect = virtualScreenRect;
Mode mode = getTabletMode(&customScreenRect);
if (mode == USE_CUSTOM) {
ui->radioCustomMapping->setChecked(true);
} else if (mode == USE_VIRTUAL_SCREEN) {
ui->radioMapToEntireScreen->setChecked(true);
} else {
ui->radioMapAsWintab->setChecked(true);
}
ui->intXOffset->setValue(customScreenRect.x());
ui->intYOffset->setValue(customScreenRect.y());
ui->intWidth->setValue(customScreenRect.width());
ui->intHeight->setValue(customScreenRect.height());
}
void KisDlgCustomTabletResolution::accept()
{
const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
QSettings cfg(configPath + QStringLiteral("/kritadisplayrc"), QSettings::IniFormat);
if (ui->radioMapAsWintab->isChecked()) {
cfg.setValue("wintabResolutionMode", "wintab");
} else if (ui->radioMapToEntireScreen->isChecked()) {
cfg.setValue("wintabResolutionMode", "virtual-screen");
} else if (ui->radioCustomMapping->isChecked()) {
cfg.setValue("wintabResolutionMode", "custom");
cfg.setValue("wintabCustomResolutionX", ui->intXOffset->value());
cfg.setValue("wintabCustomResolutionY", ui->intYOffset->value());
cfg.setValue("wintabCustomResolutionWidth", ui->intWidth->value());
cfg.setValue("wintabCustomResolutionHeight", ui->intHeight->value());
}
QDialog::accept();
}
KisDlgCustomTabletResolution::~KisDlgCustomTabletResolution()
{
delete ui;
}
QRect KisDlgCustomTabletResolution::calcNativeScreenRect()
{
QRect nativeScreenRect;
QPlatformScreen *screen = qGuiApp->primaryScreen()->handle();
Q_FOREACH (QPlatformScreen *scr, screen->virtualSiblings()) {
nativeScreenRect |= scr->geometry();
}
return nativeScreenRect;
}
KisDlgCustomTabletResolution::Mode KisDlgCustomTabletResolution::getTabletMode(QRect *customRect)
{
const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
QSettings cfg(configPath + QStringLiteral("/kritadisplayrc"), QSettings::IniFormat);
const QString mode = cfg.value("wintabResolutionMode", QString("wintab")).toString();
Mode modeValue = USE_WINTAB;
if (mode == "custom") {
modeValue = USE_CUSTOM;
} else if (mode == "virtual-screen") {
modeValue = USE_VIRTUAL_SCREEN;
} else {
modeValue = USE_WINTAB;
}
if (mode == "custom") {
customRect->setX(cfg.value("wintabCustomResolutionX", customRect->x()).toInt());
customRect->setY(cfg.value("wintabCustomResolutionY", customRect->y()).toInt());
customRect->setWidth(cfg.value("wintabCustomResolutionWidth", customRect->width()).toInt());
customRect->setHeight(cfg.value("wintabCustomResolutionHeight", customRect->height()).toInt());
}
return modeValue;
}
/*
* Copyright (c) 2019 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISDLGCUSTOMTABLETRESOLUTION_H
#define KISDLGCUSTOMTABLETRESOLUTION_H
#include <QDialog>
#include "kritaui_export.h"
namespace Ui {
class KisDlgCustomTabletResolution;
}
class KRITAUI_EXPORT KisDlgCustomTabletResolution : public QDialog
{
Q_OBJECT
public:
enum Mode {
USE_WINTAB = 0,
USE_VIRTUAL_SCREEN,
USE_CUSTOM
};
void accept();
public:
explicit KisDlgCustomTabletResolution(QWidget *parent = 0);
~KisDlgCustomTabletResolution();
static QRect calcNativeScreenRect();
static Mode getTabletMode(QRect *customRect);
private:
Ui::KisDlgCustomTabletResolution *ui;
};
#endif // KISDLGCUSTOMTABLETRESOLUTION_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>KisDlgCustomTabletResolution</class>
<widget class="QDialog" name="KisDlgCustomTabletResolution">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>321</width>
<height>237</height>
</rect>
</property>
<property name="windowTitle">
<string>Advanced Tablet Setting</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Select area your tablet is mappet to (needs restart):</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="radioMapAsWintab">
<property name="text">
<string>Use information provided by tablet</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioMapToEntireScreen">
<property name="text">
<string notr="true">Map to entire virtual screen NO_I18N</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioCustomMapping">
<property name="text">
<string>Map to custom area</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QLabel" name="lblWidth">
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="intWidth">
<property name="suffix">
<string>px</string>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="lblXOffset">
<property name="text">
<string>X offset:</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QSpinBox" name="intXOffset">
<property name="suffix">
<string>px</string>
</property>
<property name="minimum">
<number>-10000</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="lblHeight">
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="intHeight">
<property name="suffix">
<string>px</string>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="lblYOffset">
<property name="text">
<string>Y offset:</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QSpinBox" name="intYOffset">
<property name="suffix">
<string>px</string>
</property>
<property name="minimum">
<number>-10000</number>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>29</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="btnBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -758,6 +758,15 @@ TabletSettingsTab::TabletSettingsTab(QWidget* parent, const char* name): QWidget
m_page->radioWin8PointerInput->setChecked(false);
m_page->grpTabletApi->setVisible(false);
}
#ifdef USE_QT_TABLET_WINDOWS
connect(m_page->btnResolutionSettings, SIGNAL(clicked()), SLOT(slotResolutionSettings()));
connect(m_page->radioWintab, SIGNAL(toggled(bool)), m_page->btnResolutionSettings, SLOT(setEnabled(bool)));
m_page->btnResolutionSettings->setEnabled(m_page->radioWintab->isChecked());
#else
m_page->btnResolutionSettings->setVisible(false);
#endif
#else
m_page->grpTabletApi->setVisible(false);
#endif
......@@ -770,6 +779,18 @@ void TabletSettingsTab::slotTabletTest()
tabletTestDialog.exec();
}
#if defined Q_OS_WIN && defined USE_QT_TABLET_WINDOWS
#include "KisDlgCustomTabletResolution.h"
#endif
void TabletSettingsTab::slotResolutionSettings()
{
#if defined Q_OS_WIN && defined USE_QT_TABLET_WINDOWS
KisDlgCustomTabletResolution dlg(this);
dlg.exec();
#endif
}
//---------------------------------------------------------------------------------------------------
#include "kis_acyclic_signal_connector.h"
......
......@@ -197,6 +197,7 @@ public:
private Q_SLOTS:
void slotTabletTest();
void slotResolutionSettings();
public:
void setDefault();
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>569</width>
<height>433</height>
<height>453</height>
</rect>
</property>
<property name="sizePolicy">
......@@ -179,11 +179,35 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="radioWintab">
<property name="text">
<string>WinTab</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="radioWintab">
<property name="text">
<string>WinTab</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnResolutionSettings">
<property name="text">
<string>Advanced...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="radioWin8PointerInput">
......
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