All Classes Namespaces Functions Variables Enumerations Properties Pages
util.cpp
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 #include "util.h"
18 #include <QAbstractSpinBox>
19 #include <QApplication>
20 #include <QStandardPaths>
21 
22 QTransform RectMapTransform( QRectF source, QRectF target )
23 {
24  qreal x1 = source.left();
25  qreal y1 = source.top();
26  qreal x2 = source.right();
27  qreal y2 = source.bottom();
28  qreal x1P = target.left();
29  qreal y1P = target.top();
30  qreal x2P = target.right();
31  qreal y2P = target.bottom();
32 
33  QTransform matrix;
34  if ( ( x1 != x2 ) && ( y1 != y2 ) )
35  {
36  matrix = QTransform( ( x2P - x1P ) / ( x2 - x1 ), // scale x
37  0,
38  0,
39  ( y2P - y1P ) / ( y2 - y1 ), // scale y
40  ( x1P * x2 - x2P * x1 ) / ( x2 - x1 ), // dx
41  ( y1P * y2 - y2P * y1 ) / ( y2 - y1 ) ); // dy
42  }
43  else
44  {
45  matrix.reset();
46  }
47  return matrix;
48 }
49 
50 void clearFocusOnFinished(QAbstractSpinBox *spinBox)
51 {
53 }
54 
55 QString ffprobeLocation()
56 {
57 #ifdef _WIN32
58  return QApplication::applicationDirPath() + "/plugins/ffprobe.exe";
59 #elif __APPLE__
60  return QApplication::applicationDirPath() + "/plugins/ffprobe";
61 #else
63  "ffprobe",
64  QStringList()
65  << QApplication::applicationDirPath() + "/plugins"
66  << QApplication::applicationDirPath() + "/../plugins" // linuxdeployqt in FHS-like mode
67  );
68  if (!ffprobePath.isEmpty())
69  {
70  return ffprobePath;
71  }
72  return QStandardPaths::findExecutable("ffprobe"); // ffprobe is a standalone project.
73 #endif
74 }
75 
76 QString ffmpegLocation()
77 {
78 #ifdef _WIN32
79  return QApplication::applicationDirPath() + "/plugins/ffmpeg.exe";
80 #elif __APPLE__
81  return QApplication::applicationDirPath() + "/plugins/ffmpeg";
82 #else
84  "ffmpeg",
85  QStringList()
86  << QApplication::applicationDirPath() + "/plugins"
87  << QApplication::applicationDirPath() + "/../plugins" // linuxdeployqt in FHS-like mode
88  );
89  if (!ffmpegPath.isEmpty())
90  {
91  return ffmpegPath;
92  }
93  return QStandardPaths::findExecutable("ffmpeg"); // ffmpeg is a standalone project.
94 #endif
95 }
96 
97 quint64 imageSize(const QImage& img)
98 {
99 #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
100  return img.sizeInBytes();
101 #else
102  return img.byteCount();
103 #endif
104 }
void reset()
QString findExecutable(const QString &executableName, const QStringList &paths)
qreal top() const const
qsizetype sizeInBytes() const const
int byteCount() const const
qreal left() const const
qreal bottom() const const
bool isEmpty() const const
qreal right() const const
void clearFocus()
void editingFinished()
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString applicationDirPath()