All Classes Namespaces Functions Variables Enumerations Properties Pages
util.h
1 /*
2 
3 Pencil2D - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2020 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
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 */
17 #ifndef UTIL_H
18 #define UTIL_H
19 
20 #include <cstddef>
21 #include <functional>
22 
23 class QAbstractSpinBox;
24 
25 QTransform RectMapTransform( QRectF source, QRectF target );
26 
27 void clearFocusOnFinished(QAbstractSpinBox *spinBox);
28 
29 // NOTE: Replace this implementation with QScopeGuard once we drop support for Qt < 5.12
31 {
32 public:
33  explicit ScopeGuard(std::function< void() > onScopeExit) { m_onScopeExit = onScopeExit; }
34  ScopeGuard(const ScopeGuard&) = delete;
35  ~ScopeGuard() { if(m_invoke) { m_onScopeExit(); } }
36 
37  void dismiss() { m_invoke = false; };
38 private:
39  std::function<void()> m_onScopeExit;
40  bool m_invoke = true;
41 };
42 
43 #define SCOPEGUARD_LINENAME_CAT(name, line) name##line
44 #define SCOPEGUARD_LINENAME(name, line) SCOPEGUARD_LINENAME_CAT(name, line)
45 
46 #define OnScopeExit( callback ) ScopeGuard SCOPEGUARD_LINENAME( myScopeGuard, __LINE__ ) ( [&] { callback; } );
47 
48 template <typename Container, typename Pred>
49 Container filter(const Container& container, Pred predicate) {
50  Container result;
51  std::copy_if(container.begin(), container.end(), std::back_inserter(result), predicate);
52  return result;
53 }
54 
55 QString ffprobeLocation();
56 QString ffmpegLocation();
57 
58 quint64 imageSize(const QImage&);
59 QString uniqueString(int len);
60 
61 #endif // UTIL_H