mirror of
https://github.com/ModOrganizer2/modorganizer-preview_base.git
synced 2026-07-27 14:01:41 -07:00
Compare commits
39
Commits
release_v1.1.0
...
2_3_0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0bdfcb7ae5 | ||
|
|
15f34d3fbd | ||
|
|
9eb356a24b | ||
|
|
1e2c008cab | ||
|
|
886bd07410 | ||
|
|
aaa57ae734 | ||
|
|
c232536d14 | ||
|
|
f661415c23 | ||
|
|
027e07ef09 | ||
|
|
29b8a77baa | ||
|
|
02c564c53c | ||
|
|
e387e6fdb2 | ||
|
|
da3160e088 | ||
|
|
da9ce4a3ba | ||
|
|
0188c4b5e9 | ||
|
|
9934cc4319 | ||
|
|
df3f5458f2 | ||
|
|
1f3a5068f8 | ||
|
|
0eb25c6f75 | ||
|
|
bfbfe2c7da | ||
|
|
0a83590936 | ||
|
|
9c29e470cd | ||
|
|
7a680df548 | ||
|
|
c31c70486f | ||
|
|
1d77e869cd | ||
|
|
72a8636f85 | ||
|
|
f77b5daf9d | ||
|
|
1dc5a32871 | ||
|
|
db0a791155 | ||
|
|
65ce23f906 | ||
|
|
4fddc311c5 | ||
|
|
c863a94793 | ||
|
|
77f074f59e | ||
|
|
b72216ad8c | ||
|
|
0a8bcff070 | ||
|
|
b8118074c0 | ||
|
|
344965df52 | ||
|
|
ff3b241f6c | ||
|
|
070086d83e |
@@ -0,0 +1,5 @@
|
||||
edit
|
||||
CMakeLists.txt.user
|
||||
/msbuild.log
|
||||
/*std*.log
|
||||
/*build
|
||||
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(preview_base)
|
||||
set(project_type plugin)
|
||||
|
||||
if(DEFINED DEPENDENCIES_DIR)
|
||||
include(${DEPENDENCIES_DIR}/modorganizer_super/cmake_common/project.cmake)
|
||||
else()
|
||||
include(../cmake_common/project.cmake)
|
||||
endif()
|
||||
add_subdirectory(src)
|
||||
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
if(DEFINED DEPENDENCIES_DIR)
|
||||
include(${DEPENDENCIES_DIR}/modorganizer_super/cmake_common/src.cmake)
|
||||
else()
|
||||
include(../../cmake_common/src.cmake)
|
||||
endif()
|
||||
@@ -0,0 +1,11 @@
|
||||
Import('qt_env')
|
||||
|
||||
env = qt_env.Clone()
|
||||
|
||||
env.AppendUnique(CPPDEFINES = [ 'PREVIEWBASE_LIBRARY' ])
|
||||
|
||||
lib = env.SharedLibrary('previewBase', env.Glob('*.cpp'))
|
||||
env.InstallModule(lib)
|
||||
|
||||
res = env['QT_USED_MODULES']
|
||||
Return('res')
|
||||
@@ -10,6 +10,8 @@ TEMPLATE = lib
|
||||
CONFIG += plugins
|
||||
CONFIG += dll
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets gui
|
||||
|
||||
DEFINES += PREVIEWBASE_LIBRARY
|
||||
|
||||
SOURCES += previewbase.cpp
|
||||
@@ -18,3 +20,7 @@ HEADERS += previewbase.h
|
||||
|
||||
|
||||
include(../plugin_template.pri)
|
||||
|
||||
OTHER_FILES += \
|
||||
previewbase.json\
|
||||
SConscript
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE TS>
|
||||
<TS version="2.1" language="en_US">
|
||||
<context>
|
||||
<name>PreviewBase</name>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="91"/>
|
||||
<source>Supports previewing various types of data files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="107"/>
|
||||
<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="108"/>
|
||||
<source>Specify a list of comma separated extensions (without ".") that should not be previewed by this plugin.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
+54
-14
@@ -25,33 +25,60 @@ along with Base Preview plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
#include <QtPlugin>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
|
||||
using namespace MOBase;
|
||||
|
||||
|
||||
PreviewBase::PreviewBase()
|
||||
: m_MOInfo(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
bool PreviewBase::init(IOrganizer *moInfo)
|
||||
{
|
||||
m_MOInfo = moInfo;
|
||||
|
||||
if (!isActive()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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()) {
|
||||
m_PreviewGenerators[QString(fileType).toLower()] = imageReader;
|
||||
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;
|
||||
}
|
||||
|
||||
m_PreviewGenerators["txt"]
|
||||
= std::bind(&PreviewBase::genTxtPreview, this, std::placeholders::_1, std::placeholders::_2);
|
||||
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;
|
||||
}
|
||||
|
||||
bool PreviewBase::init(MOBase::IOrganizer*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QString PreviewBase::name() const
|
||||
{
|
||||
return tr("Preview Base");
|
||||
return "Preview Base";
|
||||
}
|
||||
|
||||
QString PreviewBase::author() const
|
||||
@@ -66,23 +93,27 @@ QString PreviewBase::description() const
|
||||
|
||||
MOBase::VersionInfo PreviewBase::version() const
|
||||
{
|
||||
return VersionInfo(0, 1, 0, VersionInfo::RELEASE_BETA);
|
||||
return VersionInfo(1, 1, 0, VersionInfo::RELEASE_FINAL);
|
||||
}
|
||||
|
||||
bool PreviewBase::isActive() const
|
||||
{
|
||||
return true;
|
||||
return m_MOInfo->pluginSetting(name(), "enabled").toBool();
|
||||
}
|
||||
|
||||
QList<MOBase::PluginSetting> PreviewBase::settings() const
|
||||
{
|
||||
return QList<MOBase::PluginSetting>();
|
||||
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;
|
||||
foreach (const auto &generator, m_PreviewGenerators) {
|
||||
for (const auto &generator : m_PreviewGenerators) {
|
||||
extensions.insert(generator.first);
|
||||
}
|
||||
|
||||
@@ -91,7 +122,7 @@ std::set<QString> PreviewBase::supportedExtensions() const
|
||||
|
||||
QWidget *PreviewBase::genFilePreview(const QString &fileName, const QSize &maxSize) const
|
||||
{
|
||||
auto iter = m_PreviewGenerators.find(QFileInfo(fileName).completeSuffix().toLower());
|
||||
auto iter = m_PreviewGenerators.find(QFileInfo(fileName).suffix().toLower());
|
||||
if (iter != m_PreviewGenerators.end()) {
|
||||
return iter->second(fileName, maxSize);
|
||||
} else {
|
||||
@@ -102,7 +133,16 @@ QWidget *PreviewBase::genFilePreview(const QString &fileName, const QSize &maxSi
|
||||
QWidget *PreviewBase::genImagePreview(const QString &fileName, const QSize&) const
|
||||
{
|
||||
QLabel *label = new QLabel();
|
||||
label->setPixmap(QPixmap(fileName));
|
||||
QPixmap pic = QPixmap(fileName);
|
||||
QSize screenSize = QApplication::desktop()->screenGeometry().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;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ private:
|
||||
private:
|
||||
std::map<QString, std::function<QWidget*(const QString&, const QSize&)> > m_PreviewGenerators;
|
||||
|
||||
private:
|
||||
const MOBase::IOrganizer* m_MOInfo;
|
||||
};
|
||||
|
||||
#endif // PREVIEWBASE_H
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef PREVIEWBASE_GLOBAL_H
|
||||
#define PREVIEWBASE_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(PREVIEWBASE_LIBRARY)
|
||||
# define PREVIEWBASESHARED_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define PREVIEWBASESHARED_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // PREVIEWBASE_GLOBAL_H
|
||||
Reference in New Issue
Block a user