15#include "trackmouseconfig.h"
27#include <KGlobalAccel>
28#include <KLocalizedString>
42 m_mousePolling =
false;
44 m_action =
new QAction(
this);
45 m_action->setObjectName(QStringLiteral(
"TrackMouse"));
46 m_action->setText(i18n(
"Track mouse"));
47 KGlobalAccel::self()->setDefaultShortcut(m_action, QList<QKeySequence>());
48 KGlobalAccel::self()->setShortcut(m_action, QList<QKeySequence>());
50 connect(m_action, &QAction::triggered,
this, &TrackMouseEffect::toggle);
65 m_modifiers = Qt::KeyboardModifiers();
66 TrackMouseConfig::self()->read();
67 if (TrackMouseConfig::shift()) {
68 m_modifiers |= Qt::ShiftModifier;
70 if (TrackMouseConfig::alt()) {
71 m_modifiers |= Qt::AltModifier;
73 if (TrackMouseConfig::control()) {
74 m_modifiers |= Qt::ControlModifier;
76 if (TrackMouseConfig::meta()) {
77 m_modifiers |= Qt::MetaModifier;
81 if (!m_mousePolling) {
84 m_mousePolling =
true;
85 }
else if (m_mousePolling) {
87 m_mousePolling =
false;
93 QTime t = QTime::currentTime();
94 m_angle = ((t.second() % 4) * m_angleBase) + (t.msec() / 1000.0 * m_angleBase);
95 m_lastRect[0].moveCenter(
cursorPos().toPoint());
96 m_lastRect[1].moveCenter(
cursorPos().toPoint());
97 data.
paint += m_lastRect[0].adjusted(-1, -1, 1, 1);
114 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
116 const QPointF p = m_lastRect[0].topLeft() + QPoint(m_lastRect[0].width() / 2.0, m_lastRect[0].height() / 2.0);
117 const float x = p.x();
118 const float y = p.y();
119 const auto scale = viewport.
scale();
120 for (
int i = 0; i < 2; ++i) {
121 matrix.translate(x * scale, y * scale, 0.0);
122 matrix.rotate(i ? -2 * m_angle : m_angle, 0, 0, 1.0);
123 matrix.translate(-x * scale, -y * scale, 0.0);
124 QMatrix4x4 mvp(matrix);
125 mvp.translate(m_lastRect[i].x() * scale, m_lastRect[i].y() * scale);
127 m_texture[i]->render(m_lastRect[i].size() * scale);
132 const QPointF p = m_lastRect[0].topLeft() + QPoint(m_lastRect[0].width() / 2.0, m_lastRect[0].height() / 2.0);
133 for (
int i = 0; i < 2; ++i) {
135 painter->translate(p.x(), p.y());
136 painter->rotate(i ? -2 * m_angle : m_angle);
137 painter->translate(-p.x(), -p.y());
138 painter->drawImage(m_lastRect[i], m_image[i]);
150bool TrackMouseEffect::init()
153 if (!m_texture[0] && m_image[0].isNull()) {
155 if (!m_texture[0] && m_image[0].isNull()) {
159 m_lastRect[0].moveCenter(
cursorPos().toPoint());
160 m_lastRect[1].moveCenter(
cursorPos().toPoint());
165void TrackMouseEffect::toggle()
168 case State::ActivatedByModifiers:
169 m_state = State::ActivatedByShortcut;
172 case State::ActivatedByShortcut:
173 m_state = State::Inactive;
176 case State::Inactive:
180 m_state = State::ActivatedByShortcut;
191void TrackMouseEffect::slotMouseChanged(
const QPointF &,
const QPointF &,
192 Qt::MouseButtons, Qt::MouseButtons,
193 Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers)
195 if (!m_mousePolling) {
200 case State::ActivatedByModifiers:
204 m_state = State::Inactive;
207 case State::ActivatedByShortcut:
210 case State::Inactive:
217 m_state = State::ActivatedByModifiers;
228void TrackMouseEffect::loadTexture()
230 QString f[2] = {QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral(
"tm_outer.png")),
231 QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral(
"tm_inner.png"))};
232 if (f[0].isEmpty() || f[1].isEmpty()) {
236 for (
int i = 0; i < 2; ++i) {
240 m_lastRect[i].setSize(img.size());
243 m_image[i] = QImage(f[i]);
244 m_lastRect[i].setSize(m_image[i].size());
251 return m_state != State::Inactive;
256#include "moc_trackmouse.cpp"
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen)
Q_SCRIPTABLE void addRepaint(const QRectF &r)
bool makeOpenGLContextCurrent()
Makes the OpenGL compositing context current.
CompositingType compositingType
void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
bool isOpenGLCompositing() const
Whether the Compositor is OpenGL based (either GL 1 or 2).
void mouseChanged(const QPointF &pos, const QPointF &oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers)
KSharedConfigPtr config() const
QPainter * scenePainter()
Provides access to the QPainter which is rendering to the back buffer.
bool setColorspaceUniformsFromSRGB(const ColorDescription &dst)
@ ModelViewProjectionMatrix
bool setUniform(const char *name, float value)
static std::unique_ptr< GLTexture > upload(const QImage &image)
const ColorDescription & colorDescription() const
QMatrix4x4 projectionMatrix() const
void prePaintScreen(ScreenPrePaintData &data, std::chrono::milliseconds presentTime) override
void postPaintScreen() override
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen) override
void reconfigure(ReconfigureFlags) override
~TrackMouseEffect() override
Qt::KeyboardModifiers modifiers
bool isActive() const override
static QPointF cursorPos()