Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
  • core_lib
  • src
  • util
util.h
1/*
2
3Pencil2D - Traditional Animation Software
4Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5Copyright (C) 2012-2020 Matthew Chiawen Chang
6
7This program is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public License
9as published by the Free Software Foundation; version 2 of the License.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16*/
17#ifndef UTIL_H
18#define UTIL_H
19
20#include <cstddef>
21#include <functional>
22#include <QtGlobal>
23
24class QAbstractSpinBox;
25class QLineF;
26class QRect;
27class QImage;
28class QString;
29
40QLineF clipLine(const QLineF& line, const QRect& clip, qreal t0, qreal t1);
41
42void clearFocusOnFinished(QAbstractSpinBox *spinBox);
43
44// NOTE: Replace this implementation with QScopeGuard once we drop support for Qt < 5.12
45class ScopeGuard
46{
47public:
48 explicit ScopeGuard(std::function< void() > onScopeExit) { m_onScopeExit = onScopeExit; }
49 ScopeGuard(const ScopeGuard&) = delete;
50 ~ScopeGuard() { if(m_invoke) { m_onScopeExit(); } }
51
52 void dismiss() { m_invoke = false; };
53private:
54 std::function<void()> m_onScopeExit;
55 bool m_invoke = true;
56};
57
58#define SCOPEGUARD_LINENAME_CAT(name, line) name##line
59#define SCOPEGUARD_LINENAME(name, line) SCOPEGUARD_LINENAME_CAT(name, line)
60
61#define OnScopeExit( callback ) ScopeGuard SCOPEGUARD_LINENAME( myScopeGuard, __LINE__ ) ( [&] { callback; } );
62
63template <typename Container, typename Pred>
64Container filter(const Container& container, Pred predicate) {
65 Container result;
66 for (const auto& item : container) {
67 if (predicate(item)) {
68 result.push_back(item);
69 }
70 }
71 return result;
72}
73
74QString ffprobeLocation();
75QString ffmpegLocation();
76
77quint64 imageSize(const QImage&);
78QString uniqueString(int len);
79
91QString closestCanonicalPath(QString path);
113QString validateDataPath(QString filePath, QString dataDirPath);
114
115#endif // UTIL_H
ScopeGuard
Definition: util.h:46
QAbstractSpinBox
QImage
QLineF
QRect
QString
Generated on Mon Dec 15 2025 03:41:35 for Pencil2D by doxygen 1.9.6 based on revision 9bfef078cfa681fa5250352bbcb5a69281765ae9