-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HexViewrPlugin: load files using an hex viewer
I am amazed that this was so fast, and simple. 30 minutes work, with playing and finding this new widget.
- Loading branch information
Showing
5 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* \file imageviewer_plg | ||
* \brief Definition of | ||
* \author Diego Iastrubni [email protected] | ||
* License MIT | ||
* \see class name | ||
*/ | ||
|
||
#include "hexviewer_plg.h" | ||
#include <QFileInfo> | ||
#include <model/buffer/qmemorybuffer.h> | ||
#include <qhexview.h> | ||
|
||
class qmdiHexViewer : public QHexView, public qmdiClient { | ||
public: | ||
QString thisFileName; | ||
qmdiHexViewer(QWidget *p, const QString &fileName) : QHexView(p) { | ||
QHexDocument *document = QHexDocument::fromMappedFile(fileName, this); | ||
this->setDocument(document); | ||
|
||
auto fi = QFileInfo(fileName); | ||
this->mdiClientName = fi.fileName(); | ||
this->thisFileName = fileName; | ||
} | ||
|
||
virtual QString mdiClientFileName() override { return thisFileName; } | ||
|
||
virtual std::optional<std::tuple<int, int, int>> get_coordinates() const override { return {}; } | ||
}; | ||
|
||
HexViewrPlugin::HexViewrPlugin() { | ||
name = tr("Image viewer plugin - based on QutePart"); | ||
author = tr("Diego Iastrubni <[email protected]>"); | ||
iVersion = 0; | ||
sVersion = "0.0.1"; | ||
autoEnabled = true; | ||
alwaysEnabled = false; | ||
} | ||
|
||
HexViewrPlugin::~HexViewrPlugin() {} | ||
|
||
QStringList HexViewrPlugin::myExtensions() { | ||
QStringList s; | ||
// s << tr("Images", "ImageViewrPlugin::myExtensions") + " (*.jpg *.jpeg *.bmp *.png *.pcx | ||
// *.ico)"; | ||
return s; | ||
} | ||
|
||
int HexViewrPlugin::canOpenFile(const QString fileName) { | ||
static const QStringList extensions = {".bin", ".img", "blob", ".so", ".AppImage", | ||
".a", ".exe", ".dll", ".dlib"}; | ||
for (const QString &ext : extensions) { | ||
if (fileName.endsWith(ext, Qt::CaseInsensitive)) { | ||
return 5; | ||
} | ||
} | ||
|
||
if (!fileName.contains(".")) { | ||
return 5; | ||
} | ||
return 1; | ||
} | ||
|
||
bool HexViewrPlugin::openFile(const QString fileName, int x, int y, int z) { | ||
auto tabWidget = dynamic_cast<QTabWidget *>(mdiServer); | ||
auto fi = QFileInfo(fileName); | ||
auto viewer = new qmdiHexViewer(tabWidget, fileName); | ||
mdiServer->addClient(viewer); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* \file imageviewer_plg.h | ||
* \brief Definition of the image viewer system plugin | ||
* \author Diego Iastrubni ([email protected]) | ||
* License MIT | ||
* \see ImageViewer plugin | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "iplugin.h" | ||
|
||
class QAction; | ||
|
||
class HexViewrPlugin : public IPlugin { | ||
Q_OBJECT | ||
public: | ||
HexViewrPlugin(); | ||
~HexViewrPlugin(); | ||
|
||
QStringList myExtensions() override; | ||
int canOpenFile(const QString fileName) override; | ||
bool openFile(const QString fileName, int x = -1, int y = -1, int z = -1) override; | ||
}; |