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
23class QAbstractSpinBox;
24
35QLineF clipLine(const QLineF& line, const QRect& clip, qreal t0, qreal t1);
36
37void clearFocusOnFinished(QAbstractSpinBox *spinBox);
38
39// NOTE: Replace this implementation with QScopeGuard once we drop support for Qt < 5.12
40class ScopeGuard
41{
42public:
43 explicit ScopeGuard(std::function< void() > onScopeExit) { m_onScopeExit = onScopeExit; }
44 ScopeGuard(const ScopeGuard&) = delete;
45 ~ScopeGuard() { if(m_invoke) { m_onScopeExit(); } }
46
47 void dismiss() { m_invoke = false; };
48private:
49 std::function<void()> m_onScopeExit;
50 bool m_invoke = true;
51};
52
53#define SCOPEGUARD_LINENAME_CAT(name, line) name##line
54#define SCOPEGUARD_LINENAME(name, line) SCOPEGUARD_LINENAME_CAT(name, line)
55
56#define OnScopeExit( callback ) ScopeGuard SCOPEGUARD_LINENAME( myScopeGuard, __LINE__ ) ( [&] { callback; } );
57
58template <typename Container, typename Pred>
59Container filter(const Container& container, Pred predicate) {
60 Container result;
61 std::copy_if(container.begin(), container.end(), std::back_inserter(result), predicate);
62 return result;
63}
64
65QString ffprobeLocation();
66QString ffmpegLocation();
67
68quint64 imageSize(const QImage&);
69QString uniqueString(int len);
70
91QString validateDataPath(QString filePath, QString dataDirPath);
92
93#endif // UTIL_H
ScopeGuard
Definition: util.h:41
QAbstractSpinBox
QImage
QLineF
QRect
QString
Generated on Thu Jun 5 2025 14:06:43 for Pencil2D by doxygen 1.9.6 based on revision 4c63407997b2c03e5048716586dec6fbbb755173