OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / imageviewer / imageviewerfactory.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 ** Copyright (c) 2010 Denis Mingulov.
7 **
8 ** Contact: Nokia Corporation (info@qt.nokia.com)
9 **
10 **
11 ** GNU Lesser General Public License Usage
12 **
13 ** This file may be used under the terms of the GNU Lesser General Public
14 ** License version 2.1 as published by the Free Software Foundation and
15 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
16 ** Please review the following information to ensure the GNU Lesser General
17 ** Public License version 2.1 requirements will be met:
18 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 **
20 ** In addition, as a special exception, Nokia gives you certain additional
21 ** rights. These rights are described in the Nokia Qt LGPL Exception
22 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 **
24 ** Other Usage
25 **
26 ** Alternatively, this file may be used in accordance with the terms and
27 ** conditions contained in a signed written agreement between you and Nokia.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "imageviewerfactory.h"
35 #include "imagevieweractionhandler.h"
36 #include "imageviewerconstants.h"
37 #include "imageviewer.h"
38
39 #include <QtCore/QMap>
40 #include <QtGui/QImageReader>
41 #include <QtCore/QtDebug>
42
43 namespace ImageViewer {
44 namespace Internal {
45
46 struct ImageViewerFactoryPrivate
47 {
48     QStringList mimeTypes;
49     QPointer<ImageViewerActionHandler> actionHandler;
50 };
51
52 ImageViewerFactory::ImageViewerFactory(QObject *parent) :
53     Core::IEditorFactory(parent),
54     d_ptr(new ImageViewerFactoryPrivate)
55 {
56     d_ptr->actionHandler = new ImageViewerActionHandler(this);
57
58     QMap<QByteArray, QString> possibleMimeTypes;
59     possibleMimeTypes.insert("bmp", QLatin1String("image/bmp"));
60     possibleMimeTypes.insert("gif", QLatin1String("image/gif"));
61     possibleMimeTypes.insert("ico", QLatin1String("image/x-icon"));
62     possibleMimeTypes.insert("jpeg", QLatin1String("image/jpeg"));
63     possibleMimeTypes.insert("jpg", QLatin1String("image/jpeg"));
64     possibleMimeTypes.insert("mng", QLatin1String("video/x-mng"));
65     possibleMimeTypes.insert("pbm", QLatin1String("image/x-portable-bitmap"));
66     possibleMimeTypes.insert("pgm", QLatin1String("image/x-portable-graymap"));
67     possibleMimeTypes.insert("png", QLatin1String("image/png"));
68     possibleMimeTypes.insert("ppm", QLatin1String("image/x-portable-pixmap"));
69     possibleMimeTypes.insert("svg", QLatin1String("image/svg+xml"));
70     possibleMimeTypes.insert("tif", QLatin1String("image/tiff"));
71     possibleMimeTypes.insert("tiff", QLatin1String("image/tiff"));
72     possibleMimeTypes.insert("xbm", QLatin1String("image/xbm"));
73     possibleMimeTypes.insert("xpm", QLatin1String("image/xpm"));
74
75     QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats();
76     foreach (const QByteArray &format, supportedFormats) {
77         const QString &value = possibleMimeTypes.value(format);
78         if (!value.isEmpty())
79             d_ptr->mimeTypes.append(value);
80     }
81 }
82
83 ImageViewerFactory::~ImageViewerFactory()
84 {
85 }
86
87 Core::IEditor *ImageViewerFactory::createEditor(QWidget *parent)
88 {
89     return new ImageViewer(parent);
90 }
91
92 QStringList ImageViewerFactory::mimeTypes() const
93 {
94     return d_ptr->mimeTypes;
95 }
96
97 QString ImageViewerFactory::id() const
98 {
99     return QLatin1String(Constants::IMAGEVIEWER_ID);
100 }
101
102 QString ImageViewerFactory::displayName() const
103 {
104     return tr(Constants::IMAGEVIEWER_DISPLAY_NAME);
105 }
106
107 Core::IFile *ImageViewerFactory::open(const QString & /*fileName*/)
108 {
109     return 0;
110 }
111
112 void ImageViewerFactory::extensionsInitialized()
113 {
114     d_ptr->actionHandler->createActions();
115 }
116
117 } // namespace Internal
118 } // namespace ImageViewer