1 /***
2
3 Olive - Non-Linear Video Editor
4 Copyright (C) 2019 Olive Team
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 ***/
20
21 #include "cursors.h"
22
23 #include <QApplication>
24 #include <QDesktopWidget>
25 #include <QPixmap>
26 #include <QSvgRenderer>
27 #include <QPainter>
28 #include <QCursor>
29 #include <QDebug>
30
31 QCursor olive::cursor::LeftTrim;
32 QCursor olive::cursor::RightTrim;
33 QCursor olive::cursor::LeftRipple;
34 QCursor olive::cursor::RightRipple;
35 QCursor olive::cursor::Slip;
36 QCursor olive::cursor::Razor;
37
38 const int cursor_size = 24;
39
load_cursor(const QString & file,int hotX=-1,int hotY=-1,bool right_aligned=false)40 QCursor load_cursor(const QString& file, int hotX = -1, int hotY = -1, bool right_aligned = false){
41 // load specified file into a pixmap
42 QSvgRenderer renderer(file);
43
44 int cursor_size_dpiaware = cursor_size * QApplication::desktop()->devicePixelRatio();
45 QPixmap pixmap(cursor_size_dpiaware, cursor_size_dpiaware);
46 pixmap.fill(Qt::transparent);
47
48 QPainter painter(&pixmap);
49 renderer.render(&painter, pixmap.rect());
50
51 // set cursor's horizontal hotspot
52 if (right_aligned) {
53 hotX = pixmap.width() - hotX;
54 }
55
56 // return cursor
57 return QCursor(pixmap, hotX, hotY);
58 }
59
Initialize()60 void olive::cursor::Initialize(){
61 qInfo() << "Initializing custom cursors";
62 olive::cursor::LeftTrim = load_cursor(":/cursors/1_left.svg");
63 olive::cursor::RightTrim = load_cursor(":/cursors/1_right.svg");
64 olive::cursor::LeftRipple = load_cursor(":/cursors/3_left.svg");
65 olive::cursor::RightRipple = load_cursor(":/cursors/3_right.svg");
66 olive::cursor::Slip = load_cursor(":/cursors/4.svg");
67 olive::cursor::Razor = load_cursor(":/cursors/5.svg");
68 qInfo() << "Finished initializing custom cursors";
69 }
70