Changeset View
Changeset View
Standalone View
Standalone View
src/QuickEditor/QuickEditor.cpp
Show All 12 Lines | |||||
13 | * | 13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public License | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include <KLocalizedString> | 20 | #include <KLocalizedString> | ||
21 | #include <KWayland/Client/plasmashell.h> | ||||
22 | #include <KWayland/Client/surface.h> | ||||
21 | #include <QGuiApplication> | 23 | #include <QGuiApplication> | ||
22 | #include <QScreen> | 24 | #include <QScreen> | ||
23 | #include <QtCore/qmath.h> | 25 | #include <QtCore/qmath.h> | ||
24 | 26 | | |||
25 | #include "QuickEditor.h" | 27 | #include "QuickEditor.h" | ||
26 | #include "SpectacleConfig.h" | 28 | #include "SpectacleConfig.h" | ||
27 | 29 | | |||
28 | const int QuickEditor::handleRadiusMouse = 9; | 30 | const int QuickEditor::handleRadiusMouse = 9; | ||
Show All 16 Lines | |||||
45 | const int QuickEditor::midHelpTextFontSize = 12; | 47 | const int QuickEditor::midHelpTextFontSize = 12; | ||
46 | 48 | | |||
47 | const int QuickEditor::magnifierLargeStep = 15; | 49 | const int QuickEditor::magnifierLargeStep = 15; | ||
48 | 50 | | |||
49 | const int QuickEditor::magZoom = 5; | 51 | const int QuickEditor::magZoom = 5; | ||
50 | const int QuickEditor::magPixels = 16; | 52 | const int QuickEditor::magPixels = 16; | ||
51 | const int QuickEditor::magOffset = 32; | 53 | const int QuickEditor::magOffset = 32; | ||
52 | 54 | | |||
53 | QuickEditor::QuickEditor(const QPixmap& thePixmap, QWidget *parent) : | 55 | QuickEditor::QuickEditor(const QPixmap &thePixmap, KWayland::Client::PlasmaShell *plasmashell, QWidget *parent) : | ||
54 | QWidget(parent), | 56 | QWidget(parent), | ||
55 | mMaskColor(QColor::fromRgbF(0, 0, 0, 0.15)), | 57 | mMaskColor(QColor::fromRgbF(0, 0, 0, 0.15)), | ||
56 | mStrokeColor(palette().highlight().color()), | 58 | mStrokeColor(palette().highlight().color()), | ||
57 | mCrossColor(QColor::fromRgbF(mStrokeColor.redF(), mStrokeColor.greenF(), mStrokeColor.blueF(), 0.7)), | 59 | mCrossColor(QColor::fromRgbF(mStrokeColor.redF(), mStrokeColor.greenF(), mStrokeColor.blueF(), 0.7)), | ||
58 | mLabelBackgroundColor(QColor::fromRgbF( | 60 | mLabelBackgroundColor(QColor::fromRgbF( | ||
59 | palette().light().color().redF(), | 61 | palette().light().color().redF(), | ||
60 | palette().light().color().greenF(), | 62 | palette().light().color().greenF(), | ||
61 | palette().light().color().blueF(), | 63 | palette().light().color().blueF(), | ||
Show All 22 Lines | 82 | { | |||
84 | } | 86 | } | ||
85 | 87 | | |||
86 | setMouseTracking(true); | 88 | setMouseTracking(true); | ||
87 | setAttribute(Qt::WA_StaticContents); | 89 | setAttribute(Qt::WA_StaticContents); | ||
88 | setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::Popup | Qt::WindowStaysOnTopHint); | 90 | setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::Popup | Qt::WindowStaysOnTopHint); | ||
89 | 91 | | |||
90 | dprI = 1.0 / devicePixelRatioF(); | 92 | dprI = 1.0 / devicePixelRatioF(); | ||
91 | setGeometry(0, 0, static_cast<int>(mPixmap.width() * dprI), static_cast<int>(mPixmap.height() * dprI)); | 93 | setGeometry(0, 0, static_cast<int>(mPixmap.width() * dprI), static_cast<int>(mPixmap.height() * dprI)); | ||
92 | 94 | // TODO This is a hack until a better interface is available | |||
95 | if (plasmashell) { | ||||
96 | using namespace KWayland::Client; | ||||
davidedmundson: There's a fromWindow variant that's a bit nicer.
In either case, check the return value before… | |||||
I think I tried fromWindow first but that crashed I think. What would the way forward be if it's nullptr? Just do nothing or wait till there's a surface? davidre: I think I tried fromWindow first but that crashed I think. What would the way forward be if… | |||||
oh! you need to create the platform window. winId() implicitly does that. winId(); auto surface = Surface::fromWindow(window()); if (!surface) { return; } davidedmundson: oh! you need to create the platform window. winId() implicitly does that.
```
winId();
auto… | |||||
If I need to call either way winId then is there some other reason to prefer fromWindow? davidre: If I need to call either way winId then is there some other reason to prefer fromWindow? | |||||
97 | winId(); | ||||
98 | auto surface = Surface::fromWindow(windowHandle()); | ||||
This isn't sustainable long term and that needs to be remembered. Maybe it's a sign that the plasmashell interface is too restrictive, catered around one use-case rather than being generic. Though first we can maybe follow xdg_toplevel.set_fullscreen() with upstream, which would be the best option. davidedmundson: This isn't sustainable long term and that needs to be remembered.
Maybe it's a sign that the… | |||||
99 | if (!surface) { | ||||
100 | return; | ||||
101 | } | ||||
102 | PlasmaShellSurface *plasmashellSurface = plasmashell->createSurface(surface, this); | ||||
103 | plasmashellSurface->setRole(PlasmaShellSurface::Role::Panel); | ||||
104 | plasmashellSurface->setPanelTakesFocus(true); | ||||
105 | plasmashellSurface->setPosition(geometry().topLeft()); | ||||
106 | } | ||||
93 | if (config->rememberLastRectangularRegion()) { | 107 | if (config->rememberLastRectangularRegion()) { | ||
94 | QRect cropRegion = config->cropRegion(); | 108 | QRect cropRegion = config->cropRegion(); | ||
95 | if (!cropRegion.isEmpty()) { | 109 | if (!cropRegion.isEmpty()) { | ||
96 | mSelection = QRectF( | 110 | mSelection = QRectF( | ||
97 | cropRegion.x() * dprI, | 111 | cropRegion.x() * dprI, | ||
98 | cropRegion.y() * dprI, | 112 | cropRegion.y() * dprI, | ||
99 | cropRegion.width() * dprI, | 113 | cropRegion.width() * dprI, | ||
100 | cropRegion.height() * dprI | 114 | cropRegion.height() * dprI | ||
▲ Show 20 Lines • Show All 782 Lines • Show Last 20 Lines |
There's a fromWindow variant that's a bit nicer.
In either case, check the return value before using it on the next line, it can return a nullptr