Krita Source Code Documentation
Loading...
Searching...
No Matches
KisDlgCustomTabletResolution.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8#include "ui_KisDlgCustomTabletResolution.h"
9
10#include <QSettings>
11#include "kis_debug.h"
12
13#include <QGuiApplication>
14#include <QScreen>
15#include <QStandardPaths>
16#include <qpa/qplatformscreen.h>
17
18#include <kstandardguiitem.h>
19
20namespace {
21QString rectToString(const QRect &rc) {
22 return QString("%1, %2 %3 x %4")
23 .arg(rc.x())
24 .arg(rc.y())
25 .arg(rc.width())
26 .arg(rc.height());
27}
28}
29
31 QDialog(parent),
33{
34 ui->setupUi(this);
35 KGuiItem::assign(ui->btnBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok());
36 KGuiItem::assign(ui->btnBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
37 connect(ui->btnBox, SIGNAL(rejected()), this, SLOT(reject()));
38 connect(ui->btnBox, SIGNAL(accepted()), this, SLOT(accept()));
39
40 connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->lblXOffset, SLOT(setEnabled(bool)));
41 connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->lblYOffset, SLOT(setEnabled(bool)));
42 connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->lblWidth, SLOT(setEnabled(bool)));
43 connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->lblHeight, SLOT(setEnabled(bool)));
44
45 connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->intXOffset, SLOT(setEnabled(bool)));
46 connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->intYOffset, SLOT(setEnabled(bool)));
47 connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->intWidth, SLOT(setEnabled(bool)));
48 connect(ui->radioCustomMapping, SIGNAL(toggled(bool)), ui->intHeight, SLOT(setEnabled(bool)));
49
50 const QRect virtualScreenRect = calcNativeScreenRect();
51
52 ui->radioMapToEntireScreen->setText(i18nc("@option:radio", "Map to entire virtual screen (%1)", rectToString(virtualScreenRect)));
53
54 QRect nativeScreenRect;
55 QPlatformScreen *screen = qGuiApp->primaryScreen()->handle();
56 Q_FOREACH (QPlatformScreen *scr, screen->virtualSiblings()) {
57 nativeScreenRect |= scr->geometry();
58 }
59
60 QRect customScreenRect = virtualScreenRect;
61 Mode mode = getTabletMode(&customScreenRect);
62
63 if (mode == USE_CUSTOM) {
64 ui->radioCustomMapping->setChecked(true);
65 } else if (mode == USE_VIRTUAL_SCREEN) {
66 ui->radioMapToEntireScreen->setChecked(true);
67 } else {
68 ui->radioMapAsWintab->setChecked(true);
69 }
70
71 ui->intXOffset->setValue(customScreenRect.x());
72 ui->intYOffset->setValue(customScreenRect.y());
73 ui->intWidth->setValue(customScreenRect.width());
74 ui->intHeight->setValue(customScreenRect.height());
75}
76
78{
79 const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
80 QSettings cfg(configPath + QStringLiteral("/kritadisplayrc"), QSettings::IniFormat);
81
82 if (ui->radioMapAsWintab->isChecked()) {
83 cfg.setValue("wintabResolutionMode", "wintab");
84 } else if (ui->radioMapToEntireScreen->isChecked()) {
85 cfg.setValue("wintabResolutionMode", "virtual-screen");
86 } else if (ui->radioCustomMapping->isChecked()) {
87 cfg.setValue("wintabResolutionMode", "custom");
88
89 cfg.setValue("wintabCustomResolutionX", ui->intXOffset->value());
90 cfg.setValue("wintabCustomResolutionY", ui->intYOffset->value());
91 cfg.setValue("wintabCustomResolutionWidth", ui->intWidth->value());
92 cfg.setValue("wintabCustomResolutionHeight", ui->intHeight->value());
93 }
94
95 // apply the mode right now
96 {
97 QRect customTabletRect;
98 const Mode tabletMode = getTabletMode(&customTabletRect);
99 applyConfiguration(tabletMode, customTabletRect);
100 }
101
102 QDialog::accept();
103}
104
109
111{
112 QRect nativeScreenRect;
113 QPlatformScreen *screen = qGuiApp->primaryScreen()->handle();
114 Q_FOREACH (QPlatformScreen *scr, screen->virtualSiblings()) {
115 nativeScreenRect |= scr->geometry();
116 }
117 return nativeScreenRect;
118}
119
121{
122 const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
123 QSettings cfg(configPath + QStringLiteral("/kritadisplayrc"), QSettings::IniFormat);
124
125 const QString mode = cfg.value("wintabResolutionMode", QString("wintab")).toString();
126 Mode modeValue = USE_WINTAB;
127
128 if (mode == "custom") {
129 modeValue = USE_CUSTOM;
130 } else if (mode == "virtual-screen") {
131 modeValue = USE_VIRTUAL_SCREEN;
132 } else {
133 modeValue = USE_WINTAB;
134 }
135
136 if (mode == "custom") {
137 customRect->setX(cfg.value("wintabCustomResolutionX", customRect->x()).toInt());
138 customRect->setY(cfg.value("wintabCustomResolutionY", customRect->y()).toInt());
139 customRect->setWidth(cfg.value("wintabCustomResolutionWidth", customRect->width()).toInt());
140 customRect->setHeight(cfg.value("wintabCustomResolutionHeight", customRect->height()).toInt());
141 }
142
143 return modeValue;
144}
145
147{
149 qputenv("QT_WINTAB_DESKTOP_RECT",
150 QString("%1;%2;%3;%4")
151 .arg(customTabletRect.x())
152 .arg(customTabletRect.y())
153 .arg(customTabletRect.width())
154 .arg(customTabletRect.height()).toLatin1());
155 qunsetenv("QT_IGNORE_WINTAB_MAPPING");
156 } else if (tabletMode == KisDlgCustomTabletResolution::USE_VIRTUAL_SCREEN) {
157 qputenv("QT_IGNORE_WINTAB_MAPPING", "1");
158 qunsetenv("QT_WINTAB_DESKTOP_RECT");
159 } else {
160 qunsetenv("QT_WINTAB_DESKTOP_RECT");
161 qunsetenv("QT_IGNORE_WINTAB_MAPPING");
162 }
163}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static void applyConfiguration(Mode mode, const QRect &customRect)
static Mode getTabletMode(QRect *customRect)
KisDlgCustomTabletResolution(QWidget *parent=nullptr)
Ui::KisDlgCustomTabletResolution * ui