Changeset View
Changeset View
Standalone View
Standalone View
src/QuickEditor/QuickEditor.cpp
Show All 19 Lines | |||||
20 | #include <KLocalizedString> | 20 | #include <KLocalizedString> | ||
21 | #include <KWayland/Client/plasmashell.h> | 21 | #include <KWayland/Client/plasmashell.h> | ||
22 | #include <KWayland/Client/surface.h> | 22 | #include <KWayland/Client/surface.h> | ||
23 | #include <QGuiApplication> | 23 | #include <QGuiApplication> | ||
24 | #include <QScreen> | 24 | #include <QScreen> | ||
25 | #include <QtCore/qmath.h> | 25 | #include <QtCore/qmath.h> | ||
26 | 26 | | |||
27 | #include "QuickEditor.h" | 27 | #include "QuickEditor.h" | ||
28 | #include "SpectacleConfig.h" | 28 | #include "settings.h" | ||
29 | 29 | | |||
30 | const int QuickEditor::handleRadiusMouse = 9; | 30 | const int QuickEditor::handleRadiusMouse = 9; | ||
31 | const int QuickEditor::handleRadiusTouch = 12; | 31 | const int QuickEditor::handleRadiusTouch = 12; | ||
32 | const qreal QuickEditor::increaseDragAreaFactor = 2.0; | 32 | const qreal QuickEditor::increaseDragAreaFactor = 2.0; | ||
33 | const int QuickEditor::minSpacingBetweenHandles = 20; | 33 | const int QuickEditor::minSpacingBetweenHandles = 20; | ||
34 | const int QuickEditor::borderDragAreaSize = 10; | 34 | const int QuickEditor::borderDragAreaSize = 10; | ||
35 | 35 | | |||
36 | const int QuickEditor::selectionSizeThreshold = 100; | 36 | const int QuickEditor::selectionSizeThreshold = 100; | ||
Show All 29 Lines | 55 | QuickEditor::QuickEditor(const QPixmap &thePixmap, KWayland::Client::PlasmaShell *plasmashell, QWidget *parent) : | |||
66 | mLabelForegroundColor(palette().windowText().color()), | 66 | mLabelForegroundColor(palette().windowText().color()), | ||
67 | mMidHelpText(i18n("Click and drag to draw a selection rectangle,\nor press Esc to quit")), | 67 | mMidHelpText(i18n("Click and drag to draw a selection rectangle,\nor press Esc to quit")), | ||
68 | mMidHelpTextFont(font()), | 68 | mMidHelpTextFont(font()), | ||
69 | mBottomHelpTextFont(font()), | 69 | mBottomHelpTextFont(font()), | ||
70 | mBottomHelpGridLeftWidth(0), | 70 | mBottomHelpGridLeftWidth(0), | ||
71 | mMouseDragState(MouseState::None), | 71 | mMouseDragState(MouseState::None), | ||
72 | mPixmap(thePixmap), | 72 | mPixmap(thePixmap), | ||
73 | mMagnifierAllowed(false), | 73 | mMagnifierAllowed(false), | ||
74 | mShowMagnifier(SpectacleConfig::instance()->showMagnifierChecked()), | 74 | mShowMagnifier(Settings::showMagnifier()), | ||
75 | mToggleMagnifier(false), | 75 | mToggleMagnifier(false), | ||
76 | mReleaseToCapture(SpectacleConfig::instance()->useReleaseToCapture()), | 76 | mReleaseToCapture(Settings::useReleaseToCapture()), | ||
77 | mRememberRegion(SpectacleConfig::instance()->alwaysRememberRegion() || SpectacleConfig::instance()->rememberLastRectangularRegion()), | 77 | mRememberRegion(Settings::alwaysRememberRegion() || Settings::rememberLastRectangularRegion()), | ||
78 | mDisableArrowKeys(false), | 78 | mDisableArrowKeys(false), | ||
79 | mPrimaryScreenGeo(QGuiApplication::primaryScreen()->geometry()), | 79 | mPrimaryScreenGeo(QGuiApplication::primaryScreen()->geometry()), | ||
80 | mbottomHelpLength(bottomHelpMaxLength), | 80 | mbottomHelpLength(bottomHelpMaxLength), | ||
81 | mHandleRadius(handleRadiusMouse) | 81 | mHandleRadius(handleRadiusMouse) | ||
82 | { | 82 | { | ||
83 | SpectacleConfig *config = SpectacleConfig::instance(); | 83 | if (Settings::useLightMaskColour()) { | ||
84 | if (config->useLightRegionMaskColour()) { | | |||
85 | mMaskColor = QColor(255, 255, 255, 100); | 84 | mMaskColor = QColor(255, 255, 255, 100); | ||
86 | } | 85 | } | ||
87 | 86 | | |||
88 | setMouseTracking(true); | 87 | setMouseTracking(true); | ||
89 | setAttribute(Qt::WA_StaticContents); | 88 | setAttribute(Qt::WA_StaticContents); | ||
90 | setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::Popup | Qt::WindowStaysOnTopHint); | 89 | setWindowFlags(Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | Qt::Popup | Qt::WindowStaysOnTopHint); | ||
91 | 90 | | |||
92 | dprI = 1.0 / devicePixelRatioF(); | 91 | dprI = 1.0 / devicePixelRatioF(); | ||
93 | setGeometry(0, 0, static_cast<int>(mPixmap.width() * dprI), static_cast<int>(mPixmap.height() * dprI)); | 92 | setGeometry(0, 0, static_cast<int>(mPixmap.width() * dprI), static_cast<int>(mPixmap.height() * dprI)); | ||
94 | // TODO This is a hack until a better interface is available | 93 | // TODO This is a hack until a better interface is available | ||
95 | if (plasmashell) { | 94 | if (plasmashell) { | ||
96 | using namespace KWayland::Client; | 95 | using namespace KWayland::Client; | ||
97 | winId(); | 96 | winId(); | ||
98 | auto surface = Surface::fromWindow(windowHandle()); | 97 | auto surface = Surface::fromWindow(windowHandle()); | ||
99 | if (!surface) { | 98 | if (!surface) { | ||
100 | return; | 99 | return; | ||
101 | } | 100 | } | ||
102 | PlasmaShellSurface *plasmashellSurface = plasmashell->createSurface(surface, this); | 101 | PlasmaShellSurface *plasmashellSurface = plasmashell->createSurface(surface, this); | ||
103 | plasmashellSurface->setRole(PlasmaShellSurface::Role::Panel); | 102 | plasmashellSurface->setRole(PlasmaShellSurface::Role::Panel); | ||
104 | plasmashellSurface->setPanelTakesFocus(true); | 103 | plasmashellSurface->setPanelTakesFocus(true); | ||
105 | plasmashellSurface->setPosition(geometry().topLeft()); | 104 | plasmashellSurface->setPosition(geometry().topLeft()); | ||
106 | } | 105 | } | ||
107 | if (config->rememberLastRectangularRegion()) { | 106 | if (Settings::rememberLastRectangularRegion() || Settings::alwaysRememberRegion()) { | ||
108 | QRect cropRegion = config->cropRegion(); | 107 | auto savedRect = Settings::cropRegion(); | ||
108 | QRect cropRegion = QRect(savedRect[0], savedRect[1], savedRect[2], savedRect[3]); | ||||
109 | if (!cropRegion.isEmpty()) { | 109 | if (!cropRegion.isEmpty()) { | ||
110 | mSelection = QRectF( | 110 | mSelection = QRectF( | ||
111 | cropRegion.x() * dprI, | 111 | cropRegion.x() * dprI, | ||
112 | cropRegion.y() * dprI, | 112 | cropRegion.y() * dprI, | ||
113 | cropRegion.width() * dprI, | 113 | cropRegion.width() * dprI, | ||
114 | cropRegion.height() * dprI | 114 | cropRegion.height() * dprI | ||
115 | ).intersected(geometry()); | 115 | ).intersected(geometry()); | ||
116 | } | 116 | } | ||
Show All 27 Lines | 143 | { | |||
144 | if (!mSelection.isEmpty()) { | 144 | if (!mSelection.isEmpty()) { | ||
145 | const qreal dpr = devicePixelRatioF(); | 145 | const qreal dpr = devicePixelRatioF(); | ||
146 | QRect scaledCropRegion = QRect( | 146 | QRect scaledCropRegion = QRect( | ||
147 | qRound(mSelection.x() * dpr), | 147 | qRound(mSelection.x() * dpr), | ||
148 | qRound(mSelection.y() * dpr), | 148 | qRound(mSelection.y() * dpr), | ||
149 | qRound(mSelection.width() * dpr), | 149 | qRound(mSelection.width() * dpr), | ||
150 | qRound(mSelection.height() * dpr) | 150 | qRound(mSelection.height() * dpr) | ||
151 | ); | 151 | ); | ||
152 | SpectacleConfig::instance()->setCropRegion(scaledCropRegion); | 152 | Settings::setCropRegion({scaledCropRegion.x(), scaledCropRegion.y(), scaledCropRegion.width(), scaledCropRegion.height()}); | ||
153 | emit grabDone(mPixmap.copy(scaledCropRegion)); | 153 | emit grabDone(mPixmap.copy(scaledCropRegion)); | ||
154 | } | 154 | } | ||
155 | } | 155 | } | ||
156 | 156 | | |||
157 | void QuickEditor::keyPressEvent(QKeyEvent* event) | 157 | void QuickEditor::keyPressEvent(QKeyEvent* event) | ||
158 | { | 158 | { | ||
159 | const auto modifiers = event->modifiers(); | 159 | const auto modifiers = event->modifiers(); | ||
160 | const bool shiftPressed = modifiers & Qt::ShiftModifier; | 160 | const bool shiftPressed = modifiers & Qt::ShiftModifier; | ||
▲ Show 20 Lines • Show All 705 Lines • Show Last 20 Lines |