2017-12-25 21:53:37 +00:00
|
|
|
#include "SysReqTableView.hpp"
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
#include <QSequentialAnimationGroup>
|
|
|
|
#include <QHeaderView>
|
2018-01-02 04:21:45 +00:00
|
|
|
#include <QJsonDocument>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
2018-01-03 00:24:45 +00:00
|
|
|
#include <QDomDocument>
|
2018-01-02 04:21:45 +00:00
|
|
|
#include <QProcess>
|
2018-01-10 06:19:48 +00:00
|
|
|
#include <QStorageInfo>
|
2021-06-30 18:20:45 +00:00
|
|
|
#include "hecl/Blender/FindBlender.hpp"
|
2018-06-08 20:59:22 +00:00
|
|
|
#include <QDebug>
|
2017-12-25 21:53:37 +00:00
|
|
|
|
|
|
|
#if _WIN32
|
2017-12-27 04:10:44 +00:00
|
|
|
#include <Windows.h>
|
|
|
|
#include <VersionHelpers.h>
|
2017-12-25 21:53:37 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if __APPLE__
|
|
|
|
#include "MacOSSystemVersion.hpp"
|
2017-12-27 04:10:44 +00:00
|
|
|
#elif _WIN32
|
2018-12-08 05:19:40 +00:00
|
|
|
static QString GetWindowsVersionString() {
|
|
|
|
if (IsWindows10OrGreater())
|
2019-08-30 06:38:10 +00:00
|
|
|
return QObject::tr("Windows 10");
|
2018-12-08 05:19:40 +00:00
|
|
|
else if (IsWindows8Point1OrGreater())
|
2019-08-30 06:38:10 +00:00
|
|
|
return QObject::tr("Windows 8.1");
|
2018-12-08 05:19:40 +00:00
|
|
|
else if (IsWindows8OrGreater())
|
2019-08-30 06:38:10 +00:00
|
|
|
return QObject::tr("Windows 8");
|
2018-12-08 05:19:40 +00:00
|
|
|
else if (IsWindows7SP1OrGreater())
|
2019-08-30 06:38:10 +00:00
|
|
|
return QObject::tr("Windows 7 SP1");
|
2018-12-08 05:19:40 +00:00
|
|
|
else if (IsWindows7OrGreater())
|
2019-08-30 06:38:10 +00:00
|
|
|
return QObject::tr("Windows 7");
|
2018-12-08 05:19:40 +00:00
|
|
|
else if (IsWindowsVistaOrGreater())
|
2019-08-30 06:38:10 +00:00
|
|
|
return QObject::tr("Windows Vista");
|
2018-12-08 05:19:40 +00:00
|
|
|
else if (IsWindowsXPOrGreater())
|
2019-08-30 06:38:10 +00:00
|
|
|
return QObject::tr("Windows XP");
|
2018-12-08 05:19:40 +00:00
|
|
|
else
|
2019-08-30 06:38:10 +00:00
|
|
|
return QObject::tr("Windows Old And Won't Work");
|
2017-12-27 04:10:44 +00:00
|
|
|
}
|
2017-12-25 21:53:37 +00:00
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
SysReqTableModel::SysReqTableModel(QObject* parent) : QAbstractTableModel(parent) {
|
2017-12-25 21:53:37 +00:00
|
|
|
#if _WIN32
|
2018-12-08 05:19:40 +00:00
|
|
|
ULONGLONG memSize;
|
|
|
|
GetPhysicallyInstalledSystemMemory(&memSize);
|
|
|
|
m_memorySize = memSize * 1024;
|
2017-12-25 21:53:37 +00:00
|
|
|
#else
|
2018-12-08 05:19:40 +00:00
|
|
|
m_memorySize = uint64_t(sysconf(_SC_PHYS_PAGES)) * sysconf(_SC_PAGESIZE);
|
2017-12-25 21:53:37 +00:00
|
|
|
#endif
|
2019-08-30 06:38:10 +00:00
|
|
|
m_memorySizeStr = tr("%1 GiB").arg(m_memorySize / 1024.f / 1024.f / 1024.f);
|
2017-12-25 21:53:37 +00:00
|
|
|
#ifdef __APPLE__
|
2018-12-08 05:19:40 +00:00
|
|
|
GetMacOSSystemVersion(m_macosMajor, m_macosMinor, m_macosPatch);
|
2019-08-30 06:38:10 +00:00
|
|
|
if (m_macosPatch == 0) {
|
|
|
|
m_osVersion = tr("macOS %1.%2").arg(m_macosMajor, m_macosMinor);
|
|
|
|
} else {
|
2020-04-16 22:15:37 +00:00
|
|
|
m_osVersion = tr("macOS %1.%2.%3")
|
|
|
|
.arg(QString::number(m_macosMajor), QString::number(m_macosMinor), QString::number(m_macosPatch));
|
2019-08-30 06:38:10 +00:00
|
|
|
}
|
2017-12-27 04:10:44 +00:00
|
|
|
#elif _WIN32
|
2018-12-08 05:19:40 +00:00
|
|
|
m_win7SP1OrGreater = IsWindows7SP1OrGreater();
|
|
|
|
m_osVersion = GetWindowsVersionString();
|
2018-01-02 04:21:45 +00:00
|
|
|
#elif __linux__
|
2019-08-30 06:38:10 +00:00
|
|
|
m_osVersion = tr("Linux");
|
2017-12-25 21:53:37 +00:00
|
|
|
#endif
|
2018-12-08 05:19:40 +00:00
|
|
|
hecl::blender::FindBlender(m_blendMajor, m_blendMinor);
|
2020-04-14 06:52:01 +00:00
|
|
|
if (m_blendMajor != 0) {
|
2019-08-30 06:38:10 +00:00
|
|
|
m_blendVersionStr = tr("Blender %1.%2").arg(QString::number(m_blendMajor), QString::number(m_blendMinor));
|
2019-08-28 01:35:51 +00:00
|
|
|
} else {
|
2019-08-30 06:38:10 +00:00
|
|
|
m_blendVersionStr = tr("Not Found");
|
2019-08-28 01:35:51 +00:00
|
|
|
}
|
2018-01-10 06:19:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
void SysReqTableModel::updateFreeDiskSpace(const QString& path) {
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
m_freeDiskSpace = 0;
|
2019-08-30 06:38:10 +00:00
|
|
|
m_freeDiskSpaceStr = tr("<Set Working Directory>");
|
2018-12-08 05:19:40 +00:00
|
|
|
} else {
|
|
|
|
m_freeDiskSpace = QStorageInfo(path).bytesFree();
|
2019-08-30 06:38:10 +00:00
|
|
|
m_freeDiskSpaceStr = tr("%1 GB").arg(m_freeDiskSpace / 1000.f / 1000.f / 1000.f, 1, 'f', 1);
|
2018-12-08 05:19:40 +00:00
|
|
|
}
|
2021-03-19 22:46:56 +00:00
|
|
|
emit dataChanged(index(1, 0), index(1, 0));
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|
2022-01-09 01:56:28 +00:00
|
|
|
void SysReqTableModel::updateBlender() {
|
|
|
|
hecl::blender::FindBlender(m_blendMajor, m_blendMinor);
|
|
|
|
if (m_blendMajor != 0) {
|
|
|
|
m_blendVersionStr = tr("Blender %1.%2").arg(QString::number(m_blendMajor), QString::number(m_blendMinor));
|
|
|
|
} else {
|
|
|
|
m_blendVersionStr = tr("Not Found");
|
|
|
|
}
|
|
|
|
emit dataChanged(index(1, 3), index(1, 3));
|
|
|
|
}
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2021-03-19 22:46:56 +00:00
|
|
|
int SysReqTableModel::rowCount(const QModelIndex& parent) const { return 4; }
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
int SysReqTableModel::columnCount(const QModelIndex& parent) const { return 2; }
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QVariant SysReqTableModel::data(const QModelIndex& index, int role) const {
|
|
|
|
if (role != Qt::DisplayRole && role != Qt::UserRole) {
|
|
|
|
return {};
|
|
|
|
}
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
if (role == Qt::UserRole) {
|
|
|
|
switch (index.row()) {
|
|
|
|
case 0:
|
|
|
|
return m_memorySize >= 0xC0000000;
|
2021-03-19 22:46:56 +00:00
|
|
|
case 1:
|
2018-12-08 05:19:40 +00:00
|
|
|
return m_freeDiskSpace >= qint64(5) * 1000 * 1000 * 1000;
|
2021-03-19 22:46:56 +00:00
|
|
|
case 2:
|
2017-12-25 21:53:37 +00:00
|
|
|
#ifdef __APPLE__
|
2021-03-19 18:59:34 +00:00
|
|
|
return m_macosMajor > 10 || m_macosMinor >= 11;
|
2017-12-27 04:10:44 +00:00
|
|
|
#elif defined(_WIN32)
|
2018-12-08 05:19:40 +00:00
|
|
|
return m_win7SP1OrGreater;
|
2017-12-25 21:53:37 +00:00
|
|
|
#else
|
2018-12-08 05:19:40 +00:00
|
|
|
return true;
|
2017-12-25 21:53:37 +00:00
|
|
|
#endif
|
2021-03-19 22:46:56 +00:00
|
|
|
case 3:
|
2018-12-08 05:19:40 +00:00
|
|
|
return isBlenderVersionOk();
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|
2018-12-08 05:19:40 +00:00
|
|
|
} else {
|
|
|
|
if (index.column() == 0) {
|
|
|
|
/* Recommended */
|
|
|
|
switch (index.row()) {
|
|
|
|
case 0:
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("3 GiB");
|
2021-03-19 22:46:56 +00:00
|
|
|
case 1:
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("5 GB (MP1)");
|
2021-03-19 22:46:56 +00:00
|
|
|
case 2:
|
2017-12-25 21:53:37 +00:00
|
|
|
#ifdef __APPLE__
|
2021-03-19 18:59:34 +00:00
|
|
|
return tr("macOS 10.11");
|
2017-12-27 04:10:44 +00:00
|
|
|
#elif defined(_WIN32)
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("Windows 7 SP1");
|
2018-01-02 04:21:45 +00:00
|
|
|
#elif defined(__linux__)
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("Linux");
|
2017-12-25 21:53:37 +00:00
|
|
|
#else
|
2018-12-08 05:19:40 +00:00
|
|
|
return {};
|
2017-12-25 21:53:37 +00:00
|
|
|
#endif
|
2021-03-19 22:46:56 +00:00
|
|
|
case 3:
|
2022-01-09 01:56:28 +00:00
|
|
|
auto [major, minor] = hecl::blender::GetRecommendedVersion();
|
2021-02-28 20:33:28 +00:00
|
|
|
return QStringLiteral("Blender %1.%2+")
|
2022-01-09 01:56:28 +00:00
|
|
|
.arg(major)
|
|
|
|
.arg(minor);
|
2018-12-08 05:19:40 +00:00
|
|
|
}
|
|
|
|
} else if (index.column() == 1) {
|
|
|
|
/* Your System */
|
|
|
|
switch (index.row()) {
|
|
|
|
case 0:
|
|
|
|
return m_memorySizeStr;
|
2021-03-19 22:46:56 +00:00
|
|
|
case 1:
|
2018-12-08 05:19:40 +00:00
|
|
|
return m_freeDiskSpaceStr;
|
2021-03-19 22:46:56 +00:00
|
|
|
case 2:
|
2018-12-08 05:19:40 +00:00
|
|
|
return m_osVersion;
|
2021-03-19 22:46:56 +00:00
|
|
|
case 3:
|
2018-12-08 05:19:40 +00:00
|
|
|
return m_blendVersionStr;
|
|
|
|
}
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|
2018-12-08 05:19:40 +00:00
|
|
|
}
|
|
|
|
return {};
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QVariant SysReqTableModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
|
|
|
if (role != Qt::DisplayRole) {
|
|
|
|
return {};
|
|
|
|
}
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
if (orientation == Qt::Horizontal) {
|
|
|
|
switch (section) {
|
|
|
|
case 0:
|
|
|
|
default:
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("Recommended");
|
2018-12-08 05:19:40 +00:00
|
|
|
case 1:
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("Your System");
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|
2018-12-08 05:19:40 +00:00
|
|
|
} else {
|
|
|
|
switch (section) {
|
|
|
|
default:
|
2021-03-19 22:46:56 +00:00
|
|
|
case 0:
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("Memory");
|
2021-03-19 22:46:56 +00:00
|
|
|
case 1:
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("Disk Space");
|
2021-03-19 22:46:56 +00:00
|
|
|
case 2:
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("OS");
|
2021-03-19 22:46:56 +00:00
|
|
|
case 3:
|
2019-08-30 06:38:10 +00:00
|
|
|
return tr("Blender");
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|
2018-12-08 05:19:40 +00:00
|
|
|
}
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|
2021-03-19 22:46:56 +00:00
|
|
|
|
2021-02-28 20:33:28 +00:00
|
|
|
bool SysReqTableModel::isBlenderVersionOk() const {
|
2022-01-09 01:56:28 +00:00
|
|
|
return hecl::blender::IsVersionSupported(m_blendMajor, m_blendMinor);
|
2021-02-28 20:33:28 +00:00
|
|
|
}
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
void SysReqTableView::paintEvent(QPaintEvent* e) {
|
|
|
|
int tableWidth = columnWidth(0) + columnWidth(1);
|
|
|
|
int tableX = verticalHeader()->width() + columnViewportPosition(0);
|
|
|
|
int tableY = horizontalHeader()->height();
|
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
QWidget* w = std::get<0>(m_backgroundWidgets[i]);
|
2018-01-10 06:19:48 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QPalette pal = palette();
|
|
|
|
if (m_model.data(m_model.index(i, 0), Qt::UserRole).toBool())
|
2019-07-20 04:25:42 +00:00
|
|
|
pal.setColor(QPalette::Window, QColor::fromRgbF(0.f, 1.f, 0.f, 0.2f));
|
2018-12-08 05:19:40 +00:00
|
|
|
else
|
2019-07-20 04:25:42 +00:00
|
|
|
pal.setColor(QPalette::Window, QColor::fromRgbF(1.f, 0.f, 0.f, 0.2f));
|
2018-12-08 05:19:40 +00:00
|
|
|
w->setPalette(pal);
|
2018-01-10 06:19:48 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QSequentialAnimationGroup* animation = std::get<1>(m_backgroundWidgets[i]);
|
|
|
|
QPropertyAnimation* pAnimation = static_cast<QPropertyAnimation*>(animation->animationAt(1));
|
|
|
|
bool& running = std::get<2>(m_backgroundWidgets[i]);
|
|
|
|
if (!running) {
|
|
|
|
w->setGeometry(QRect(tableX, tableY + rowViewportPosition(i), 0, rowHeight(i)));
|
|
|
|
pAnimation->setStartValue(QRect(tableX, tableY + rowViewportPosition(i), 0, rowHeight(i)));
|
|
|
|
pAnimation->setEndValue(QRect(tableX, tableY + rowViewportPosition(i), tableWidth, rowHeight(i)));
|
|
|
|
animation->start();
|
|
|
|
running = true;
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|
2018-12-08 05:19:40 +00:00
|
|
|
if (animation->state() == QAbstractAnimation::State::Running)
|
|
|
|
pAnimation->setEndValue(QRect(tableX, tableY + rowViewportPosition(i), tableWidth, rowHeight(i)));
|
|
|
|
else
|
|
|
|
w->setGeometry(QRect(tableX, tableY + rowViewportPosition(i), tableWidth, rowHeight(i)));
|
|
|
|
}
|
|
|
|
QTableView::paintEvent(e);
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|
|
|
|
|
2021-03-19 22:46:56 +00:00
|
|
|
SysReqTableView::SysReqTableView(QWidget* parent) : QTableView(parent) {
|
2018-12-08 05:19:40 +00:00
|
|
|
setModel(&m_model);
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);
|
|
|
|
setSelectionMode(QAbstractItemView::SelectionMode::NoSelection);
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
for (int i = 0; i < 6; ++i) {
|
|
|
|
QWidget* w = new QWidget(this);
|
|
|
|
std::get<0>(m_backgroundWidgets[i]) = w;
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QPalette pal = palette();
|
|
|
|
if (m_model.data(m_model.index(i, 0), Qt::UserRole).toBool())
|
2019-07-20 04:25:42 +00:00
|
|
|
pal.setColor(QPalette::Window, QColor::fromRgbF(0.f, 1.f, 0.f, 0.2f));
|
2018-12-08 05:19:40 +00:00
|
|
|
else
|
2019-07-20 04:25:42 +00:00
|
|
|
pal.setColor(QPalette::Window, QColor::fromRgbF(1.f, 0.f, 0.f, 0.2f));
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
w->setAutoFillBackground(true);
|
|
|
|
w->setPalette(pal);
|
|
|
|
w->lower();
|
|
|
|
w->show();
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QPropertyAnimation* animation = new QPropertyAnimation(w, "geometry", this);
|
|
|
|
animation->setDuration(2000);
|
|
|
|
animation->setEasingCurve(QEasingCurve::Type::InOutCubic);
|
2017-12-25 21:53:37 +00:00
|
|
|
|
2018-12-08 05:19:40 +00:00
|
|
|
QSequentialAnimationGroup* seq = new QSequentialAnimationGroup(this);
|
|
|
|
std::get<1>(m_backgroundWidgets[i]) = seq;
|
|
|
|
seq->addPause(i * 100);
|
|
|
|
seq->addAnimation(animation);
|
|
|
|
}
|
2017-12-25 21:53:37 +00:00
|
|
|
}
|