Commit fc3fd82e authored by Denis Mingulov's avatar Denis Mingulov Committed by Thorbjørn Lindeijer
Browse files

BinEditor Plugin: Remove ImageViewer



Merge-request: 2165
Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
parent 49167555
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="image/bmp">
<sub-class-of type="application/octet-stream"/>
<comment>BMP image</comment>
<glob pattern="*.bmp"/>
</mime-type>
<mime-type type="image/gif">
<sub-class-of type="application/octet-stream"/>
<comment>GIF image</comment>
<glob pattern="*.gif"/>
</mime-type>
<mime-type type="image/x-icon">
<sub-class-of type="application/octet-stream"/>
<comment>ICO image</comment>
<glob pattern="*.ico"/>
</mime-type>
<mime-type type="image/jpeg">
<sub-class-of type="application/octet-stream"/>
<comment>JPEG image</comment>
<glob pattern="*.jpg"/>
<glob pattern="*.jpeg"/>
</mime-type>
<mime-type type="video/x-mng">
<sub-class-of type="application/octet-stream"/>
<comment>MNG video</comment>
<glob pattern="*.mng"/>
</mime-type>
<mime-type type="image/x-portable-bitmap">
<sub-class-of type="application/octet-stream"/>
<comment>PBM image</comment>
<glob pattern="*.pbm"/>
</mime-type>
<mime-type type="image/x-portable-graymap">
<sub-class-of type="application/octet-stream"/>
<comment>PGM image</comment>
<glob pattern="*.pgm"/>
</mime-type>
<mime-type type="image/png">
<sub-class-of type="application/octet-stream"/>
<comment>PNG image</comment>
<glob pattern="*.png"/>
</mime-type>
<mime-type type="image/x-portable-pixmap">
<sub-class-of type="application/octet-stream"/>
<comment>PPM image</comment>
<glob pattern="*.ppm"/>
</mime-type>
<mime-type type="image/svg+xml">
<sub-class-of type="application/octet-stream"/>
<comment>SVG image</comment>
<glob pattern="*.svg"/>
</mime-type>
<mime-type type="image/tiff">
<sub-class-of type="application/octet-stream"/>
<comment>TIFF image</comment>
<glob pattern="*.tif"/>
<glob pattern="*.tiff"/>
</mime-type>
<mime-type type="image/xbm">
<sub-class-of type="application/octet-stream"/>
<comment>XBM image</comment>
<glob pattern="*.xbm"/>
</mime-type>
<mime-type type="image/xpm">
<sub-class-of type="application/octet-stream"/>
<comment>XPM image</comment>
<glob pattern="*.xpm"/>
</mime-type>
</mime-info>
......@@ -5,14 +5,11 @@ include(bineditor_dependencies.pri)
HEADERS += bineditorplugin.h \
bineditor.h \
bineditorconstants.h \
imageviewer.h
bineditorconstants.h
SOURCES += bineditorplugin.cpp \
bineditor.cpp \
imageviewer.cpp
bineditor.cpp
RESOURCES += bineditor.qrc
OTHER_FILES += BinEditor.pluginspec \
ImageViewer.mimetypes.xml
OTHER_FILES += BinEditor.pluginspec
<RCC>
<qresource prefix="/bineditor">
<file>ImageViewer.mimetypes.xml</file>
</qresource>
<qresource prefix="/bineditor"/>
</RCC>
......@@ -31,8 +31,6 @@
#include "bineditor.h"
#include "bineditorconstants.h"
#include "imageviewer.h"
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QDebug>
......@@ -472,16 +470,13 @@ void BinEditorPlugin::initializeEditor(BinEditor *editor)
bool BinEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
Q_UNUSED(arguments)
Q_UNUSED(errorMessage)
Core::ICore *core = Core::ICore::instance();
if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/bineditor/ImageViewer.mimetypes.xml"), errorMessage))
return false;
connect(core, SIGNAL(contextAboutToChange(Core::IContext *)),
this, SLOT(updateCurrentEditor(Core::IContext *)));
addAutoReleasedObject(new BinEditorFactory(this));
addAutoReleasedObject(new ImageViewerFactory);
return true;
}
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "imageviewer.h"
#include <coreplugin/icore.h>
#include <coreplugin/uniqueidmanager.h>
#include <utils/reloadpromptutils.h>
#include <QtCore/QMap>
#include <QtCore/QFileInfo>
#include <QtGui/QImageReader>
#include <QtGui/QWidget>
#include <QtGui/QGridLayout>
#include <QtGui/QMainWindow>
#include <QtDebug>
namespace {
const char * const IMAGE_VIEWER_ID = "Editors.ImageViewer";
const char * const C_IMAGE_VIEWER = "Editors.ImageViewer";
}
using namespace BINEditor::Internal;
using namespace Core;
// #pragma mark -- ImageViewerFactory
ImageViewerFactory::ImageViewerFactory(QObject *parent) :
Core::IEditorFactory(parent)
{
QMap<QByteArray, QString> possibleMimeTypes;
possibleMimeTypes.insert("bmp", QLatin1String("image/bmp"));
possibleMimeTypes.insert("gif", QLatin1String("image/gif"));
possibleMimeTypes.insert("ico", QLatin1String("image/x-icon"));
possibleMimeTypes.insert("jpeg", QLatin1String("image/jpeg"));
possibleMimeTypes.insert("jpg", QLatin1String("image/jpeg"));
possibleMimeTypes.insert("mng", QLatin1String("video/x-mng"));
possibleMimeTypes.insert("pbm", QLatin1String("image/x-portable-bitmap"));
possibleMimeTypes.insert("pgm", QLatin1String("image/x-portable-graymap"));
possibleMimeTypes.insert("png", QLatin1String("image/png"));
possibleMimeTypes.insert("ppm", QLatin1String("image/x-portable-pixmap"));
possibleMimeTypes.insert("svg", QLatin1String("image/svg+xml"));
possibleMimeTypes.insert("tif", QLatin1String("image/tiff"));
possibleMimeTypes.insert("tiff", QLatin1String("image/tiff"));
possibleMimeTypes.insert("xbm", QLatin1String("image/xbm"));
possibleMimeTypes.insert("xpm", QLatin1String("image/xpm"));
QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
foreach (const QByteArray &format, supportedFormats) {
const QString &value = possibleMimeTypes.value(format);
if (!value.isEmpty())
m_mimeTypes.append(value);
}
}
IEditor *ImageViewerFactory::createEditor(QWidget *parent)
{
return new ImageViewer(parent);
}
QStringList ImageViewerFactory::mimeTypes() const
{
return m_mimeTypes;
}
QString ImageViewerFactory::id() const
{
return QLatin1String(IMAGE_VIEWER_ID);
}
QString ImageViewerFactory::displayName() const
{
return tr("Image Viewer");
}
Core::IFile *ImageViewerFactory::open(const QString & /* fileName */)
{
return 0;
}
// #pragma mark -- ImageViewerFile
ImageViewerFile::ImageViewerFile(ImageViewer *parent)
: Core::IFile(parent),
m_editor(parent)
{
}
Core::IFile::ReloadBehavior ImageViewerFile::reloadBehavior(Core::IFile::ChangeTrigger state,
Core::IFile::ChangeType type) const
{
if (type == TypePermissions)
return BehaviorSilent;
if (type == TypeContents && state == TriggerInternal)
return BehaviorSilent;
return BehaviorAsk;
}
void ImageViewerFile::reload(Core::IFile::ReloadFlag flag,
Core::IFile::ChangeType type)
{
if (flag == FlagIgnore)
return;
if (type == TypePermissions) {
emit changed();
} else {
m_editor->open(m_fileName);
}
}
// #pragma mark -- ImageViewer
ImageViewer::ImageViewer(QObject *parent)
: IEditor(parent)
{
m_file = new ImageViewerFile(this);
m_context << Core::ICore::instance()->uniqueIDManager()->uniqueIdentifier(C_IMAGE_VIEWER);
m_scrollArea = new QScrollArea;
m_scrollArea->setWidgetResizable(true);
m_scrollArea->setFrameStyle(QFrame::NoFrame);
m_imageView = new QWidget;
QGridLayout *layout = new QGridLayout;
m_label = new QLabel;
m_label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
m_label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
layout->setMargin(0);
m_imageView->setLayout(layout);
layout->addWidget(m_label, 0, 0, 1, 1);
connect(m_file, SIGNAL(changed()),
this, SIGNAL(changed()));
}
ImageViewer::~ImageViewer()
{
delete m_scrollArea;
// m_file deleted by parent hierarchy
}
QList<int> ImageViewer::context() const
{
return m_context;
}
QWidget *ImageViewer::widget()
{
return m_scrollArea;
}
bool ImageViewer::createNew(const QString &contents)
{
Q_UNUSED(contents)
return false;
}
bool ImageViewer::open(const QString &fileName)
{
m_label->setPixmap(QPixmap(fileName));
m_scrollArea->setWidget(m_imageView);
setDisplayName(QFileInfo(fileName).fileName());
m_file->setFileName(fileName);
// m_file->setMimeType
emit changed();
return !m_label->pixmap()->isNull();
}
Core::IFile *ImageViewer::file()
{
return m_file;
}
QString ImageViewer::id() const
{
return QLatin1String(IMAGE_VIEWER_ID);
}
QString ImageViewer::displayName() const
{
return m_displayName;
}
void ImageViewer::setDisplayName(const QString &title)
{
m_displayName = title;
emit changed();
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef IMAGEVIEWER_H
#define IMAGEVIEWER_H
#include <coreplugin/editormanager/ieditorfactory.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/ifile.h>
#include <QtCore/QStringList>
#include <QtGui/QWidget>
#include <QtGui/QLabel>
#include <QtGui/QScrollArea>
namespace BINEditor {
namespace Internal {
class ImageViewerFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
explicit ImageViewerFactory(QObject *parent = 0);
Core::IEditor *createEditor(QWidget *parent);
QStringList mimeTypes() const;
QString id() const;
QString displayName() const;
Core::IFile *open(const QString &fileName);
private:
QStringList m_mimeTypes;
};
class ImageViewer;
class ImageViewerFile : public Core::IFile
{
Q_OBJECT
public:
explicit ImageViewerFile(ImageViewer *parent = 0);
bool save(const QString &fileName = QString()) { Q_UNUSED(fileName); return false; }
void rename(const QString &newName) { m_fileName = newName; }
QString fileName() const { return m_fileName; }
QString defaultPath() const { return QString(); }
QString suggestedFileName() const { return QString(); }
QString mimeType() const { return m_mimeType; }
bool isModified() const { return false; }
bool isReadOnly() const { return true; }
bool isSaveAsAllowed() const { return false; }
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
void reload(ReloadFlag flag, ChangeType type);
void setMimetype(const QString &mimetype) { m_mimeType = mimetype; emit changed(); }
void setFileName(const QString &filename) { m_fileName = filename; emit changed(); }
private:
QString m_fileName;
QString m_mimeType;
ImageViewer *m_editor;
};
class ImageViewer : public Core::IEditor
{
Q_OBJECT
public:
explicit ImageViewer(QObject *parent = 0);
~ImageViewer();
QList<int> context() const;
QWidget *widget();
bool createNew(const QString &contents = QString());
bool open(const QString &fileName = QString());
Core::IFile *file();
QString id() const;
QString displayName() const;
void setDisplayName(const QString &title);
bool duplicateSupported() const { return false; }
IEditor *duplicate(QWidget * /* parent */) { return 0; }
QByteArray saveState() const { return QByteArray(); }
bool restoreState(const QByteArray & /* state */) { return true; }
int currentLine() const { return 0; }
int currentColumn() const { return 0; }
bool isTemporary() const { return false; }
QWidget *toolBar() { return 0; }
private:
QList<int> m_context;
QString m_displayName;
ImageViewerFile *m_file;
QScrollArea *m_scrollArea;
QWidget *m_imageView;
QLabel *m_label;
};
}
}
#endif // IMAGEVIEWER_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment