mirror of
https://github.com/ModOrganizer2/modorganizer-preview_base.git
synced 2026-07-27 14:01:41 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfd985876e | ||
|
|
b89b52296a | ||
|
|
11b4d13da8 | ||
|
|
be7c5f0d0b | ||
|
|
27718aecc2 | ||
|
|
4deb451f14 | ||
|
|
f6c7a516d3 | ||
|
|
32399c01a2 | ||
|
|
23c4ce331a | ||
|
|
ed9f6d9b63 | ||
|
|
01daa7e9c9 | ||
|
|
f47d910bd2 |
@@ -0,0 +1,41 @@
|
||||
---
|
||||
# We'll use defaults from the LLVM style, but with 4 columns indentation.
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 2
|
||||
---
|
||||
Language: Cpp
|
||||
DeriveLineEnding: false
|
||||
UseCRLF: true
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
AlignConsecutiveAssignments: true
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: Empty
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AccessModifierOffset: -2
|
||||
AlignTrailingComments: true
|
||||
SpacesBeforeTrailingComments: 2
|
||||
NamespaceIndentation: Inner
|
||||
MaxEmptyLinesToKeep: 1
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: false
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: true
|
||||
ColumnLimit: 88
|
||||
ForEachMacros: ['Q_FOREACH', 'foreach']
|
||||
@@ -0,0 +1 @@
|
||||
01daa7e9c9f396f83451703fc6cdc046a4e87b16
|
||||
@@ -0,0 +1,7 @@
|
||||
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||
* text=auto
|
||||
|
||||
# Explicitly declare text files you want to always be normalized and converted
|
||||
# to native line endings on checkout.
|
||||
*.cpp text eol=crlf
|
||||
*.h text eol=crlf
|
||||
@@ -0,0 +1,20 @@
|
||||
name: Build Preview Base
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
env:
|
||||
VCPKG_BINARY_SOURCES: clear;x-azblob,${{ vars.AZ_BLOB_VCPKG_URL }},${{ secrets.AZ_BLOB_SAS }},readwrite
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- name: Build Preview Base
|
||||
id: build-preview-base
|
||||
uses: ModOrganizer2/build-with-mob-action@master
|
||||
with:
|
||||
mo2-dependencies: uibase
|
||||
@@ -0,0 +1,16 @@
|
||||
name: Lint Preview Base Plugin
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Check format
|
||||
uses: ModOrganizer2/check-formatting-action@master
|
||||
with:
|
||||
check-path: "."
|
||||
@@ -0,0 +1,20 @@
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v6.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-merge-conflict
|
||||
- id: check-case-conflict
|
||||
- repo: https://github.com/pre-commit/mirrors-clang-format
|
||||
rev: v22.1.5
|
||||
hooks:
|
||||
- id: clang-format
|
||||
'types_or': [c++, c]
|
||||
|
||||
ci:
|
||||
autofix_commit_msg: "[pre-commit.ci] Auto fixes from pre-commit.com hooks."
|
||||
autofix_prs: true
|
||||
autoupdate_commit_msg: "[pre-commit.ci] Pre-commit autoupdate."
|
||||
autoupdate_schedule: quarterly
|
||||
submodules: false
|
||||
+1
-6
@@ -1,10 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
if(DEFINED DEPENDENCIES_DIR)
|
||||
include(${DEPENDENCIES_DIR}/modorganizer_super/cmake_common/mo2.cmake)
|
||||
else()
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake_common/mo2.cmake)
|
||||
endif()
|
||||
|
||||
project(preview_base)
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"configurePresets": [
|
||||
{
|
||||
"errors": {
|
||||
"deprecated": true
|
||||
},
|
||||
"hidden": true,
|
||||
"name": "cmake-dev",
|
||||
"warnings": {
|
||||
"deprecated": true,
|
||||
"dev": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"cacheVariables": {
|
||||
"VCPKG_MANIFEST_NO_DEFAULT_FEATURES": {
|
||||
"type": "BOOL",
|
||||
"value": "ON"
|
||||
}
|
||||
},
|
||||
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
|
||||
"hidden": true,
|
||||
"name": "vcpkg"
|
||||
},
|
||||
{
|
||||
"hidden": true,
|
||||
"inherits": ["vcpkg"],
|
||||
"name": "vcpkg-dev"
|
||||
},
|
||||
{
|
||||
"binaryDir": "${sourceDir}/vsbuild",
|
||||
"architecture": {
|
||||
"strategy": "set",
|
||||
"value": "x64"
|
||||
},
|
||||
"cacheVariables": {
|
||||
"CMAKE_CXX_FLAGS": "/EHsc /MP /W4",
|
||||
"VCPKG_TARGET_TRIPLET": {
|
||||
"type": "STRING",
|
||||
"value": "x64-windows-static-md"
|
||||
}
|
||||
},
|
||||
"generator": "Visual Studio 17 2022",
|
||||
"inherits": ["cmake-dev", "vcpkg-dev"],
|
||||
"name": "vs2022-windows",
|
||||
"toolset": "v143"
|
||||
},
|
||||
{
|
||||
"cacheVariables": {
|
||||
"VCPKG_MANIFEST_FEATURES": {
|
||||
"type": "STRING",
|
||||
"value": "standalone"
|
||||
}
|
||||
},
|
||||
"inherits": "vs2022-windows",
|
||||
"name": "vs2022-windows-standalone"
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "vs2022-windows",
|
||||
"resolvePackageReferences": "on",
|
||||
"configurePreset": "vs2022-windows"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
version: 1.0.{build}
|
||||
skip_branch_with_pr: true
|
||||
image: Visual Studio 2019
|
||||
environment:
|
||||
WEBHOOK_URL:
|
||||
secure: gOKbXaZM9ImtMD5XrYITvdyZUW/az082G9OIN1EC1Vbg57wBaeLhi49uGjxPw5GVujHku6kxN6ab89zhbS5GVeluR76GM83IbKV4Sh7udXzoYZZdg6YudtYHzdhCgUeiedpswbuczTq9ceIkkfSEWZuh/lMAAVVwvcGsJAnoPFw=
|
||||
build:
|
||||
parallel: true
|
||||
build_script:
|
||||
- pwsh: >-
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
git clone --depth=1 --no-single-branch https://github.com/ModOrganizer2/modorganizer-umbrella.git c:\projects\modorganizer-umbrella
|
||||
|
||||
New-Item -ItemType Directory -Path c:\projects\modorganizer-build
|
||||
|
||||
cd c:\projects\modorganizer-umbrella
|
||||
|
||||
($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH -eq $null) ? ($branch = $env:APPVEYOR_REPO_BRANCH) : ($branch = $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH)
|
||||
|
||||
git checkout $(git show-ref --verify --quiet refs/remotes/origin/${branch} || echo '-b') ${branch}
|
||||
|
||||
C:\Python37-x64\python.exe unimake.py -d c:\projects\modorganizer-build -s Appveyor_Build=True ${env:APPVEYOR_PROJECT_NAME}
|
||||
|
||||
if($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode ) }
|
||||
artifacts:
|
||||
- path: vsbuild\src\RelWithDebInfo\preview_base.dll
|
||||
name: preview_base_dll
|
||||
- path: vsbuild\src\RelWithDebInfo\preview_base.pdb
|
||||
name: preview_base_pdb
|
||||
- path: vsbuild\src\RelWithDebInfo\preview_base.lib
|
||||
name: preview_base_lib
|
||||
on_success:
|
||||
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
|
||||
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
|
||||
- ps: ./send.ps1 success $env:WEBHOOK_URL
|
||||
on_failure:
|
||||
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
|
||||
- ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stdout.log
|
||||
- ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stderr.log
|
||||
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
|
||||
- ps: ./send.ps1 failure $env:WEBHOOK_URL
|
||||
+7
-3
@@ -1,5 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
add_library(preview_base SHARED)
|
||||
mo2_configure_plugin(preview_base WARNINGS OFF)
|
||||
mo2_install_target(preview_base)
|
||||
find_package(mo2-cmake CONFIG REQUIRED)
|
||||
find_package(mo2-uibase CONFIG REQUIRED)
|
||||
|
||||
add_library(preview_base SHARED previewbase.cpp previewbase.h)
|
||||
mo2_configure_plugin(preview_base NO_SOURCES WARNINGS 4)
|
||||
target_link_libraries(preview_base PRIVATE mo2::uibase)
|
||||
mo2_install_plugin(preview_base)
|
||||
|
||||
@@ -4,22 +4,22 @@
|
||||
<context>
|
||||
<name>PreviewBase</name>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="82"/>
|
||||
<location filename="previewbase.cpp" line="86"/>
|
||||
<source>Preview Base</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="92"/>
|
||||
<location filename="previewbase.cpp" line="96"/>
|
||||
<source>Supports previewing various types of data files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="103"/>
|
||||
<location filename="previewbase.cpp" line="109"/>
|
||||
<source>Enable previewing of basic file types, such as images and text files.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="104"/>
|
||||
<location filename="previewbase.cpp" line="113"/>
|
||||
<source>Specify a list of comma separated extensions (without ".") that should not be previewed by this plugin.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
||||
+185
-157
@@ -1,157 +1,185 @@
|
||||
/*
|
||||
Copyright (C) 2014 Sebastian Herbord. All rights reserved.
|
||||
|
||||
This file is part of Base Preview plugin for MO
|
||||
|
||||
Base Preview plugin is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Base Preview plugin is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Base Preview plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "previewbase.h"
|
||||
#include <utility.h>
|
||||
#include <QImageReader>
|
||||
#include <QFileInfo>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
#include <QtPlugin>
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
|
||||
|
||||
using namespace MOBase;
|
||||
|
||||
|
||||
PreviewBase::PreviewBase()
|
||||
: m_MOInfo(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
bool PreviewBase::init(IOrganizer *moInfo)
|
||||
{
|
||||
m_MOInfo = moInfo;
|
||||
|
||||
const QStringList& blacklist = m_MOInfo->pluginSetting(name(), "blacklisted_extensions").toString().toLower().split(',');
|
||||
|
||||
// set up image reader to be used for all image types qt (the current installation) supports
|
||||
auto imageReader = std::bind(&PreviewBase::genImagePreview, this, std::placeholders::_1, std::placeholders::_2);
|
||||
|
||||
foreach(const QByteArray & fileType, QImageReader::supportedImageFormats()) {
|
||||
auto strFileType = QString(fileType).toLower();
|
||||
|
||||
// skip dds as that one is handled by the dds preview plugin.
|
||||
if (strFileType == "dds" || blacklist.contains(strFileType))
|
||||
continue;
|
||||
|
||||
m_PreviewGenerators[strFileType] = imageReader;
|
||||
}
|
||||
|
||||
const QStringList supportedTextFormats = { "txt", "ini", "json", "log", "cfg" };
|
||||
|
||||
auto textReader = std::bind(&PreviewBase::genTxtPreview, this, std::placeholders::_1, std::placeholders::_2);
|
||||
|
||||
foreach(const QString fileType, supportedTextFormats) {
|
||||
|
||||
// skip blacklisted ones
|
||||
if (blacklist.contains(fileType))
|
||||
continue;
|
||||
|
||||
m_PreviewGenerators[fileType] = textReader;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString PreviewBase::name() const
|
||||
{
|
||||
return "Preview Base";
|
||||
}
|
||||
|
||||
QString PreviewBase::localizedName() const
|
||||
{
|
||||
return tr("Preview Base");
|
||||
}
|
||||
|
||||
QString PreviewBase::author() const
|
||||
{
|
||||
return "Tannin";
|
||||
}
|
||||
|
||||
QString PreviewBase::description() const
|
||||
{
|
||||
return tr("Supports previewing various types of data files");
|
||||
}
|
||||
|
||||
MOBase::VersionInfo PreviewBase::version() const
|
||||
{
|
||||
return VersionInfo(1, 1, 0, VersionInfo::RELEASE_FINAL);
|
||||
}
|
||||
|
||||
QList<MOBase::PluginSetting> PreviewBase::settings() const
|
||||
{
|
||||
QList<PluginSetting> result;
|
||||
result.push_back(PluginSetting("enabled", tr("Enable previewing of basic file types, such as images and text files."), QVariant(true)));
|
||||
result.push_back(PluginSetting("blacklisted_extensions", tr("Specify a list of comma separated extensions (without \".\") "
|
||||
"that should not be previewed by this plugin."), QVariant("")));
|
||||
return result;
|
||||
}
|
||||
|
||||
std::set<QString> PreviewBase::supportedExtensions() const
|
||||
{
|
||||
std::set<QString> extensions;
|
||||
for (const auto &generator : m_PreviewGenerators) {
|
||||
extensions.insert(generator.first);
|
||||
}
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
QWidget *PreviewBase::genFilePreview(const QString &fileName, const QSize &maxSize) const
|
||||
{
|
||||
auto iter = m_PreviewGenerators.find(QFileInfo(fileName).suffix().toLower());
|
||||
if (iter != m_PreviewGenerators.end()) {
|
||||
return iter->second(fileName, maxSize);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *PreviewBase::genImagePreview(const QString &fileName, const QSize&) const
|
||||
{
|
||||
QLabel *label = new QLabel();
|
||||
QPixmap pic = QPixmap(fileName);
|
||||
QSize screenSize = QApplication::primaryScreen()->geometry().size();
|
||||
// ensure the output image is no more than 80% of the screen height.
|
||||
// If the aspect ratio is higher than that of the screen this would still allow the image to extend
|
||||
// beyond the screen but it ensures you can drag the window and close it
|
||||
int maxHeight = static_cast<int>(screenSize.height() * 0.8f);
|
||||
if (pic.size().height() > maxHeight) {
|
||||
pic = pic.scaledToHeight(maxHeight, Qt::SmoothTransformation);
|
||||
}
|
||||
label->setPixmap(pic);
|
||||
return label;
|
||||
}
|
||||
|
||||
QWidget *PreviewBase::genTxtPreview(const QString &fileName, const QSize&) const
|
||||
{
|
||||
QTextEdit *edit = new QTextEdit();
|
||||
edit->setText(MOBase::readFileText(fileName));
|
||||
edit->setReadOnly(true);
|
||||
return edit;
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
|
||||
Q_EXPORT_PLUGIN2(previewBase, PreviewBase)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
Copyright (C) 2014 Sebastian Herbord. All rights reserved.
|
||||
|
||||
This file is part of Base Preview plugin for MO
|
||||
|
||||
Base Preview plugin is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Base Preview plugin is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Base Preview plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "previewbase.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QImageReader>
|
||||
#include <QLabel>
|
||||
#include <QScreen>
|
||||
#include <QTextEdit>
|
||||
#include <QtPlugin>
|
||||
|
||||
#include <uibase/utility.h>
|
||||
|
||||
using namespace MOBase;
|
||||
|
||||
PreviewBase::PreviewBase() : m_MOInfo(nullptr) {}
|
||||
|
||||
bool PreviewBase::init(IOrganizer* moInfo)
|
||||
{
|
||||
m_MOInfo = moInfo;
|
||||
|
||||
const QStringList& blacklist =
|
||||
m_MOInfo->pluginSetting(name(), "blacklisted_extensions")
|
||||
.toString()
|
||||
.toLower()
|
||||
.split(',');
|
||||
|
||||
// set up image reader to be used for all image types qt (the current installation)
|
||||
// supports
|
||||
auto imageReader =
|
||||
std::bind(&PreviewBase::genImagePreview, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3);
|
||||
|
||||
foreach (const QByteArray& fileType, QImageReader::supportedImageFormats()) {
|
||||
auto strFileType = QString(fileType).toLower();
|
||||
|
||||
// skip dds as that one is handled by the dds preview plugin.
|
||||
if (strFileType == "dds" || blacklist.contains(strFileType))
|
||||
continue;
|
||||
|
||||
m_PreviewGenerators[strFileType] = imageReader;
|
||||
}
|
||||
|
||||
const QStringList supportedTextFormats = {"txt", "ini", "json", "log", "cfg", "psc"};
|
||||
|
||||
auto textReader = std::bind(&PreviewBase::genTxtPreview, this, std::placeholders::_1,
|
||||
std::placeholders::_2, std::placeholders::_3);
|
||||
|
||||
foreach (const QString fileType, supportedTextFormats) {
|
||||
|
||||
// skip blacklisted ones
|
||||
if (blacklist.contains(fileType))
|
||||
continue;
|
||||
|
||||
m_PreviewGenerators[fileType] = textReader;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString PreviewBase::name() const
|
||||
{
|
||||
return "Preview Base";
|
||||
}
|
||||
|
||||
QString PreviewBase::localizedName() const
|
||||
{
|
||||
return tr("Preview Base");
|
||||
}
|
||||
|
||||
QString PreviewBase::author() const
|
||||
{
|
||||
return "Tannin";
|
||||
}
|
||||
|
||||
QString PreviewBase::description() const
|
||||
{
|
||||
return tr("Supports previewing various types of data files");
|
||||
}
|
||||
|
||||
MOBase::VersionInfo PreviewBase::version() const
|
||||
{
|
||||
return VersionInfo(1, 1, 0, VersionInfo::RELEASE_FINAL);
|
||||
}
|
||||
|
||||
QList<MOBase::PluginSetting> PreviewBase::settings() const
|
||||
{
|
||||
QList<PluginSetting> result;
|
||||
result.push_back(PluginSetting(
|
||||
"enabled",
|
||||
tr("Enable previewing of basic file types, such as images and text files."),
|
||||
QVariant(true)));
|
||||
result.push_back(
|
||||
PluginSetting("blacklisted_extensions",
|
||||
tr("Specify a list of comma separated extensions (without \".\") "
|
||||
"that should not be previewed by this plugin."),
|
||||
QVariant("")));
|
||||
return result;
|
||||
}
|
||||
|
||||
std::set<QString> PreviewBase::supportedExtensions() const
|
||||
{
|
||||
std::set<QString> extensions;
|
||||
for (const auto& generator : m_PreviewGenerators) {
|
||||
extensions.insert(generator.first);
|
||||
}
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
QWidget* PreviewBase::genFilePreview(const QString& fileName,
|
||||
const QSize& maxSize) const
|
||||
{
|
||||
return genDataPreview(nullptr, fileName, maxSize);
|
||||
}
|
||||
|
||||
QWidget* PreviewBase::genDataPreview(const QByteArray& fileData,
|
||||
const QString& fileName,
|
||||
const QSize& maxSize) const
|
||||
{
|
||||
auto iter = m_PreviewGenerators.find(QFileInfo(fileName).suffix().toLower());
|
||||
if (iter != m_PreviewGenerators.end()) {
|
||||
return iter->second(fileName, maxSize, fileData);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QWidget* PreviewBase::genImagePreview(const QString& fileName, const QSize&,
|
||||
const QByteArray& fileData) const
|
||||
{
|
||||
QLabel* label = new QLabel();
|
||||
QPixmap pic;
|
||||
if (fileData == nullptr) {
|
||||
pic = QPixmap(fileName);
|
||||
} else {
|
||||
pic.loadFromData(fileData);
|
||||
}
|
||||
QSize screenSize = QApplication::primaryScreen()->geometry().size();
|
||||
// ensure the output image is no more than 80% of the screen height.
|
||||
// If the aspect ratio is higher than that of the screen this would still allow the
|
||||
// image to extend beyond the screen but it ensures you can drag the window and close
|
||||
// it
|
||||
int maxHeight = static_cast<int>(screenSize.height() * 0.8f);
|
||||
if (pic.size().height() > maxHeight) {
|
||||
pic = pic.scaledToHeight(maxHeight, Qt::SmoothTransformation);
|
||||
}
|
||||
label->setPixmap(pic);
|
||||
return label;
|
||||
}
|
||||
|
||||
QWidget* PreviewBase::genTxtPreview(const QString& fileName, const QSize&,
|
||||
const QByteArray& fileData) const
|
||||
{
|
||||
QTextEdit* edit = new QTextEdit();
|
||||
if (fileData == nullptr) {
|
||||
edit->setText(MOBase::readFileText(fileName));
|
||||
} else {
|
||||
edit->setText(MOBase::decodeTextData(fileData));
|
||||
}
|
||||
edit->setReadOnly(true);
|
||||
return edit;
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
Q_EXPORT_PLUGIN2(previewBase, PreviewBase)
|
||||
#endif
|
||||
|
||||
+68
-64
@@ -1,64 +1,68 @@
|
||||
/*
|
||||
Copyright (C) 2014 Sebastian Herbord. All rights reserved.
|
||||
|
||||
This file is part of Base Preview plugin for MO
|
||||
|
||||
Base Preview plugin is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Base Preview plugin is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Base Preview plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PREVIEWBASE_H
|
||||
#define PREVIEWBASE_H
|
||||
|
||||
#include <ipluginpreview.h>
|
||||
#include <functional>
|
||||
|
||||
class PreviewBase : public MOBase::IPluginPreview
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(MOBase::IPlugin MOBase::IPluginPreview)
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
|
||||
Q_PLUGIN_METADATA(IID "org.tannin.PreviewBase" FILE "previewbase.json")
|
||||
#endif
|
||||
|
||||
public:
|
||||
PreviewBase();
|
||||
|
||||
public:
|
||||
virtual bool init(MOBase::IOrganizer *moInfo) override;
|
||||
virtual QString name() const override;
|
||||
virtual QString localizedName() const override;
|
||||
virtual QString author() const override;
|
||||
virtual QString description() const override;
|
||||
virtual MOBase::VersionInfo version() const override;
|
||||
virtual QList<MOBase::PluginSetting> settings() const override;
|
||||
|
||||
public:
|
||||
virtual std::set<QString> supportedExtensions() const;
|
||||
virtual QWidget *genFilePreview(const QString &fileName, const QSize &maxSize) const;
|
||||
|
||||
private:
|
||||
|
||||
QWidget *genImagePreview(const QString &fileName, const QSize &maxSize) const;
|
||||
QWidget *genTxtPreview(const QString &fileName, const QSize &maxSize) const;
|
||||
|
||||
private:
|
||||
std::map<QString, std::function<QWidget*(const QString&, const QSize&)> > m_PreviewGenerators;
|
||||
|
||||
private:
|
||||
const MOBase::IOrganizer* m_MOInfo;
|
||||
};
|
||||
|
||||
#endif // PREVIEWBASE_H
|
||||
/*
|
||||
Copyright (C) 2014 Sebastian Herbord. All rights reserved.
|
||||
|
||||
This file is part of Base Preview plugin for MO
|
||||
|
||||
Base Preview plugin is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Base Preview plugin is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Base Preview plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef PREVIEWBASE_H
|
||||
#define PREVIEWBASE_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <uibase/ipluginpreview.h>
|
||||
|
||||
class PreviewBase : public MOBase::IPluginPreview
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(MOBase::IPlugin MOBase::IPluginPreview)
|
||||
Q_PLUGIN_METADATA(IID "org.tannin.PreviewBase")
|
||||
|
||||
public:
|
||||
PreviewBase();
|
||||
|
||||
public:
|
||||
virtual bool init(MOBase::IOrganizer* moInfo) override;
|
||||
virtual QString name() const override;
|
||||
virtual QString localizedName() const override;
|
||||
virtual QString author() const override;
|
||||
virtual QString description() const override;
|
||||
virtual MOBase::VersionInfo version() const override;
|
||||
virtual QList<MOBase::PluginSetting> settings() const override;
|
||||
|
||||
public:
|
||||
virtual std::set<QString> supportedExtensions() const;
|
||||
virtual bool supportsArchives() const override { return true; }
|
||||
virtual QWidget* genFilePreview(const QString& fileName, const QSize& maxSize) const;
|
||||
virtual QWidget* genDataPreview(const QByteArray& fileData, const QString& fileName,
|
||||
const QSize& maxSize) const override;
|
||||
|
||||
private:
|
||||
QWidget* genImagePreview(const QString& fileName, const QSize& maxSize,
|
||||
const QByteArray& fileData) const;
|
||||
QWidget* genTxtPreview(const QString& fileName, const QSize& maxSize,
|
||||
const QByteArray& fileData) const;
|
||||
|
||||
private:
|
||||
std::map<QString,
|
||||
std::function<QWidget*(const QString&, const QSize&, const QByteArray&)>>
|
||||
m_PreviewGenerators;
|
||||
|
||||
private:
|
||||
const MOBase::IOrganizer* m_MOInfo;
|
||||
};
|
||||
|
||||
#endif // PREVIEWBASE_H
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
{}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"features": {
|
||||
"standalone": {
|
||||
"description": "Build Standalone.",
|
||||
"dependencies": ["mo2-cmake", "mo2-uibase"]
|
||||
}
|
||||
},
|
||||
"vcpkg-configuration": {
|
||||
"default-registry": {
|
||||
"kind": "git",
|
||||
"repository": "https://github.com/Microsoft/vcpkg",
|
||||
"baseline": "294f76666c3000630d828703e675814c05a4fd43"
|
||||
},
|
||||
"registries": [
|
||||
{
|
||||
"kind": "git",
|
||||
"repository": "https://github.com/ModOrganizer2/vcpkg-registry",
|
||||
"baseline": "8beb2e0efa9c17dd6d17bb05288dd1e40727f673",
|
||||
"packages": ["mo2-*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user