Skip to content

Commit b419148

Browse files
committed
#2074 note-relations: allow zooming
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 4d6f3ad commit b419148

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# QOwnNotes Changelog
22

3+
## 25.3.3
4+
- You can now **zoom** in the **note relation panel** with the mouse wheel
5+
(for [#2074](https://github.com/pbek/QOwnNotes/issues/2074))
6+
37
## 25.3.2
48
- In the **note relation panel**, notes can now have **circular relations**
59
between each other, no new note items will be drawn for notes that are already

Diff for: src/mainwindow.ui

+6-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@
698698
</widget>
699699
</item>
700700
<item>
701-
<widget class="QGraphicsView" name="noteGraphicsView"/>
701+
<widget class="ZoomableGraphicsView" name="noteGraphicsView"/>
702702
</item>
703703
</layout>
704704
</widget>
@@ -2897,6 +2897,11 @@ li.checked::marker { content: &quot;\2612&quot;; }
28972897
<extends>QTreeWidget</extends>
28982898
<header>widgets/notesubfoldertree.h</header>
28992899
</customwidget>
2900+
<customwidget>
2901+
<class>ZoomableGraphicsView</class>
2902+
<extends>QGraphicsView</extends>
2903+
<header location="global">widgets/noterelationscene.h</header>
2904+
</customwidget>
29002905
</customwidgets>
29012906
<tabstops>
29022907
<tabstop>noteSubFolderLineEdit</tabstop>

Diff for: src/widgets/noterelationscene.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,22 @@ QPointF NoteRelationScene::calculateRadialPosition(QPointF center, int index, in
282282

283283
return {x, y};
284284
}
285+
286+
ZoomableGraphicsView::ZoomableGraphicsView(QWidget *parent) : QGraphicsView(parent) {
287+
// Set view properties
288+
setRenderHint(QPainter::Antialiasing);
289+
setDragMode(QGraphicsView::ScrollHandDrag);
290+
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
291+
setResizeAnchor(QGraphicsView::AnchorUnderMouse);
292+
}
293+
294+
void ZoomableGraphicsView::wheelEvent(QWheelEvent *event) {
295+
// Zoom in or out depending on wheel direction
296+
if (event->angleDelta().y() > 0) {
297+
// Zoom in
298+
scale(scaleFactor, scaleFactor);
299+
} else {
300+
// Zoom out
301+
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
302+
}
303+
}

Diff for: src/widgets/noterelationscene.h

+13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#include <QGraphicsRectItem>
1919
#include <QGraphicsScene>
2020
#include <QGraphicsSceneMouseEvent>
21+
#include <QGraphicsView>
2122
#include <QPainter>
23+
#include <QWheelEvent>
2224
#include <vector>
2325

2426
#include "entities/note.h"
@@ -90,3 +92,14 @@ class NoteRelationScene : public QGraphicsScene {
9092
// This will run in the GUI thread
9193
void addItemToScene(QGraphicsItem *item);
9294
};
95+
96+
class ZoomableGraphicsView : public QGraphicsView {
97+
public:
98+
explicit ZoomableGraphicsView(QWidget *parent = nullptr);
99+
100+
protected:
101+
void wheelEvent(QWheelEvent *event) override;
102+
103+
private:
104+
double scaleFactor = 1.15; // Zoom factor when scrolling
105+
};

0 commit comments

Comments
 (0)