mirror of
https://github.com/ModOrganizer2/modorganizer-preview_bsa.git
synced 2026-07-27 14:06:38 -07:00
Initial conversion of previewbase to previewbsa
This commit is contained in:
+2
-2
@@ -2,9 +2,9 @@ Import('qt_env')
|
||||
|
||||
env = qt_env.Clone()
|
||||
|
||||
env.AppendUnique(CPPDEFINES = [ 'PREVIEWBASE_LIBRARY' ])
|
||||
env.AppendUnique(CPPDEFINES = [ 'PREVIEWBSA_LIBRARY' ])
|
||||
|
||||
lib = env.SharedLibrary('previewBase', env.Glob('*.cpp'))
|
||||
lib = env.SharedLibrary('previewBsa', env.Glob('*.cpp'))
|
||||
env.InstallModule(lib)
|
||||
|
||||
res = env['QT_USED_MODULES']
|
||||
|
||||
@@ -1,143 +1,143 @@
|
||||
/*
|
||||
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 <QDesktopWidget>
|
||||
|
||||
|
||||
using namespace MOBase;
|
||||
|
||||
|
||||
PreviewBase::PreviewBase()
|
||||
{
|
||||
// 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")
|
||||
continue;
|
||||
|
||||
m_PreviewGenerators[strFileType] = imageReader;
|
||||
}
|
||||
|
||||
auto textReader = std::bind(&PreviewBase::genTxtPreview, this, std::placeholders::_1, std::placeholders::_2);
|
||||
m_PreviewGenerators["txt"] = textReader;
|
||||
m_PreviewGenerators["ini"] = textReader;
|
||||
m_PreviewGenerators["json"] = textReader;
|
||||
m_PreviewGenerators["log"] = textReader;
|
||||
m_PreviewGenerators["cfg"] = textReader;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool PreviewBase::init(MOBase::IOrganizer*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QString PreviewBase::name() const
|
||||
{
|
||||
return "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);
|
||||
}
|
||||
|
||||
bool PreviewBase::isActive() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<MOBase::PluginSetting> PreviewBase::settings() const
|
||||
{
|
||||
return QList<MOBase::PluginSetting>();
|
||||
}
|
||||
|
||||
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::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;
|
||||
}
|
||||
|
||||
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 Bsa Preview plugin for MO
|
||||
|
||||
Bsa 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.
|
||||
|
||||
Bsa 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 Bsa Preview plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "previewbsa.h"
|
||||
#include <utility.h>
|
||||
#include <QImageReader>
|
||||
#include <QFileInfo>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
#include <QtPlugin>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
|
||||
using namespace MOBase;
|
||||
|
||||
|
||||
PreviewBsa::PreviewBsa()
|
||||
{
|
||||
// set up image reader to be used for all image types qt (the current installation) supports
|
||||
auto imageReader = std::bind(&PreviewBsa::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")
|
||||
continue;
|
||||
|
||||
m_PreviewGenerators[strFileType] = imageReader;
|
||||
}
|
||||
|
||||
auto textReader = std::bind(&PreviewBsa::genTxtPreview, this, std::placeholders::_1, std::placeholders::_2);
|
||||
m_PreviewGenerators["txt"] = textReader;
|
||||
m_PreviewGenerators["ini"] = textReader;
|
||||
m_PreviewGenerators["json"] = textReader;
|
||||
m_PreviewGenerators["log"] = textReader;
|
||||
m_PreviewGenerators["cfg"] = textReader;
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool PreviewBsa::init(MOBase::IOrganizer*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QString PreviewBsa::name() const
|
||||
{
|
||||
return "Preview Bsa";
|
||||
}
|
||||
|
||||
QString PreviewBsa::author() const
|
||||
{
|
||||
return "Tannin";
|
||||
}
|
||||
|
||||
QString PreviewBsa::description() const
|
||||
{
|
||||
return tr("Supports previewing various types of data files");
|
||||
}
|
||||
|
||||
MOBase::VersionInfo PreviewBsa::version() const
|
||||
{
|
||||
return VersionInfo(1, 1, 0, VersionInfo::RELEASE_FINAL);
|
||||
}
|
||||
|
||||
bool PreviewBsa::isActive() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<MOBase::PluginSetting> PreviewBsa::settings() const
|
||||
{
|
||||
return QList<MOBase::PluginSetting>();
|
||||
}
|
||||
|
||||
std::set<QString> PreviewBsa::supportedExtensions() const
|
||||
{
|
||||
std::set<QString> extensions;
|
||||
for (const auto &generator : m_PreviewGenerators) {
|
||||
extensions.insert(generator.first);
|
||||
}
|
||||
|
||||
return extensions;
|
||||
}
|
||||
|
||||
QWidget *PreviewBsa::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 *PreviewBsa::genImagePreview(const QString &fileName, const QSize&) const
|
||||
{
|
||||
QLabel *label = new QLabel();
|
||||
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;
|
||||
}
|
||||
|
||||
QWidget *PreviewBsa::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(previewBsa, PreviewBsa)
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
/*
|
||||
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);
|
||||
virtual QString name() const;
|
||||
virtual QString author() const;
|
||||
virtual QString description() const;
|
||||
virtual MOBase::VersionInfo version() const;
|
||||
virtual bool isActive() const;
|
||||
virtual QList<MOBase::PluginSetting> settings() const;
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
#endif // PREVIEWBASE_H
|
||||
/*
|
||||
Copyright (C) 2014 Sebastian Herbord. All rights reserved.
|
||||
|
||||
This file is part of bsa Preview plugin for MO
|
||||
|
||||
bsa 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.
|
||||
|
||||
bsa 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 bsa Preview plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PREVIEWBSA_H
|
||||
#define PREVIEWBSA_H
|
||||
|
||||
#include <ipluginpreview.h>
|
||||
#include <functional>
|
||||
|
||||
class PreviewBsa : 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.PreviewBsa" FILE "previewbsa.json")
|
||||
#endif
|
||||
|
||||
public:
|
||||
PreviewBsa();
|
||||
|
||||
public:
|
||||
virtual bool init(MOBase::IOrganizer *moInfo);
|
||||
virtual QString name() const;
|
||||
virtual QString author() const;
|
||||
virtual QString description() const;
|
||||
virtual MOBase::VersionInfo version() const;
|
||||
virtual bool isActive() const;
|
||||
virtual QList<MOBase::PluginSetting> settings() const;
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
#endif // PREVIEWBSA_H
|
||||
@@ -1 +1 @@
|
||||
{}
|
||||
{}
|
||||
@@ -1,26 +1,26 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-01-14T19:50:56
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
TARGET = previewBase
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += plugins
|
||||
CONFIG += dll
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets gui
|
||||
|
||||
DEFINES += PREVIEWBASE_LIBRARY
|
||||
|
||||
SOURCES += previewbase.cpp
|
||||
|
||||
HEADERS += previewbase.h
|
||||
|
||||
|
||||
include(../plugin_template.pri)
|
||||
|
||||
OTHER_FILES += \
|
||||
previewbase.json\
|
||||
SConscript
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-01-14T19:50:56
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
TARGET = previewBsa
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += plugins
|
||||
CONFIG += dll
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets gui
|
||||
|
||||
DEFINES += PREVIEWBSA_LIBRARY
|
||||
|
||||
SOURCES += previewbsa.cpp
|
||||
|
||||
HEADERS += previewbsa.h
|
||||
|
||||
|
||||
include(../plugin_template.pri)
|
||||
|
||||
OTHER_FILES += \
|
||||
previewbsa.json\
|
||||
SConscript
|
||||
Reference in New Issue
Block a user