Commit fd951247 authored by Alexander Semke's avatar Alexander Semke
Browse files

Stop the animation of the promt cursor when the worksheet looses the focus and...

Stop the animation of the promt cursor when the worksheet looses the focus and resume it once the worksheet gets the focus again.
This is helpful when the user is switching to one of the panels in Cantor and we want to stop the animation. This also helpful in LabPlot
where the user can have multiple Cantor worksheets places besides each other and we only want to have that animation in the currently
active worksheet.
parent 29bacbd2
Pipeline #63487 passed with stage
in 25 minutes and 9 seconds
......@@ -56,7 +56,6 @@ Worksheet::Worksheet(Cantor::Backend* backend, QWidget* parent, bool useDefaultW
m_cursorItemTimer(new QTimer(this)),
m_useDefaultWorksheetParameters(useDefaultWorksheetParameters)
{
m_entryCursorItem = addLine(0,0,0,0);
const QColor& color = (palette().color(QPalette::Base).lightness() < 128) ? Qt::white : Qt::black;
QPen pen(color);
......@@ -71,6 +70,20 @@ Worksheet::Worksheet(Cantor::Backend* backend, QWidget* parent, bool useDefaultW
initSession(backend);
}
void Worksheet::stopAnimations()
{
m_cursorItemTimer->stop();
m_entryCursorItem->hide();
}
void Worksheet::resumeAnimations()
{
delete m_cursorItemTimer;
m_cursorItemTimer = new QTimer(this);
connect(m_cursorItemTimer, &QTimer::timeout, this, &Worksheet::animateEntryCursor);
m_cursorItemTimer->start(500);
}
Worksheet::~Worksheet()
{
m_isClosing = true;
......
......@@ -66,6 +66,9 @@ class Worksheet : public QGraphicsScene
WorksheetView* worksheetView();
void stopAnimations();
void resumeAnimations();
void makeVisible(WorksheetEntry*);
void makeVisible(const WorksheetCursor&);
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2012 Martin Kuettler <martin.kuettler@gmail.com>
SPDX-FileCopyrightText: 2018-2021 Alexander Semke <alexander.semke@web.de>
*/
#include "worksheetview.h"
#include "worksheet.h"
#include <QFocusEvent>
#include <QParallelAnimationGroup>
#include <QPropertyAnimation>
#include <QScrollBar>
WorksheetView::WorksheetView(Worksheet* scene, QWidget* parent) : QGraphicsView(scene, parent),
m_scale(1),
m_animation(nullptr),
m_hAnimation(nullptr),
m_vAnimation(nullptr),
m_worksheet(scene)
{
connect(scene, SIGNAL(sceneRectChanged(QRectF)),
......@@ -230,6 +228,20 @@ void WorksheetView::resizeEvent(QResizeEvent* event)
updateSceneSize();
}
void WorksheetView::focusInEvent(QFocusEvent* event)
{
QGraphicsView::focusInEvent(event);
m_worksheet->resumeAnimations();
}
void WorksheetView::focusOutEvent(QFocusEvent* event)
{
QGraphicsView::focusOutEvent(event);
if (!scene()->hasFocus())
m_worksheet->stopAnimations();
}
qreal WorksheetView::scaleFactor() const
{
return m_scale;
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2012 Martin Kuettler <martin.kuettler@gmail.com>
SPDX-FileCopyrightText: 2018-2021 Alexander Semke <alexander.semke@web.de>
*/
#ifndef WORKSHEETVIEW_H
......@@ -17,10 +18,10 @@ class WorksheetView : public QGraphicsView
{
Q_OBJECT
public:
WorksheetView(Worksheet* scene, QWidget* parent);
WorksheetView(Worksheet*, QWidget*);
void makeVisible(const QRectF& sceneRect);
bool isVisible(const QRectF& sceneRect) const;
void makeVisible(const QRectF&);
bool isVisible(const QRectF&) const;
bool isAtEnd() const;
void scrollToEnd() const;
void scrollBy(int dy);
......@@ -34,7 +35,7 @@ public:
void updateSceneSize();
Q_SIGNALS:
void viewRectChanged(QRectF rect) const;
void viewRectChanged(QRectF) const;
void scaleFactorChanged(double scale);
public Q_SLOTS:
......@@ -42,16 +43,18 @@ public Q_SLOTS:
void zoomOut();
void actualSize();
void endAnimation();
void sceneRectChanged(const QRectF& sceneRect) const;
void sceneRectChanged(const QRectF&) const;
void sendViewRectChange() const;
private:
void resizeEvent(QResizeEvent*) override;
void focusInEvent(QFocusEvent*) override;
void focusOutEvent(QFocusEvent*) override;
qreal m_scale;
QParallelAnimationGroup* m_animation;
QPropertyAnimation* m_hAnimation;
QPropertyAnimation* m_vAnimation;
qreal m_scale = 1.;
QParallelAnimationGroup* m_animation{nullptr};
QPropertyAnimation* m_hAnimation{nullptr};
QPropertyAnimation* m_vAnimation{nullptr};
Worksheet* m_worksheet;
};
......
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