OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / shared / qrceditor / resourceview.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** Other Usage
24 **
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 #ifndef RESOURCEVIEW_H
34 #define RESOURCEVIEW_H
35
36 #include "namespace_global.h"
37
38 #include "resourcefile_p.h"
39
40 #include <QtGui/QTreeView>
41 #include <QtCore/QPoint>
42
43 using namespace qdesigner_internal;
44
45 QT_BEGIN_NAMESPACE
46 class QAction;
47 class QMenu;
48 class QMouseEvent;
49 class QUndoStack;
50 QT_END_NAMESPACE
51
52 namespace SharedTools {
53
54 /*!
55     \class EntryBackup
56
57     Holds the backup of a tree node including children.
58 */
59 class EntryBackup
60 {
61 protected:
62     ResourceModel *m_model;
63     int m_prefixIndex;
64     QString m_name;
65
66     EntryBackup(ResourceModel &model, int prefixIndex, const QString &name)
67             : m_model(&model), m_prefixIndex(prefixIndex), m_name(name) { }
68
69 public:
70     virtual void restore() const = 0;
71     virtual ~EntryBackup() { }
72 };
73
74 namespace Internal {
75     class RelativeResourceModel;
76 }
77
78 class ResourceView : public QTreeView
79 {
80     Q_OBJECT
81
82 public:
83     enum NodeProperty {
84         AliasProperty,
85         PrefixProperty,
86         LanguageProperty
87     };
88
89     explicit ResourceView(QUndoStack *history, QWidget *parent = 0);
90     ~ResourceView();
91
92     bool load(const QString &fileName);
93     bool save();
94     QString fileName() const;
95     void setFileName(const QString &fileName);
96
97     bool isDirty() const;
98     void setDirty(bool dirty);
99
100     void enableContextMenu(bool enable);
101
102     void addFiles(QStringList fileList, const QModelIndex &index);
103
104     void addFile(const QString &prefix, const QString &file);
105 //    void removeFile(const QString &prefix, const QString &file);
106
107     bool isPrefix(const QModelIndex &index) const;
108
109     QString currentAlias() const;
110     QString currentPrefix() const;
111     QString currentLanguage() const;
112
113     void setResourceDragEnabled(bool e);
114     bool resourceDragEnabled() const;
115
116     void setDefaultAddFileEnabled(bool enable);
117     bool defaultAddFileEnabled() const;
118
119     void findSamePlacePostDeletionModelIndex(int &row, QModelIndex &parent) const;
120     EntryBackup *removeEntry(const QModelIndex &index);
121     void addFiles(int prefixIndex, const QStringList &fileNames, int cursorFile,
122                   int &firstFile, int &lastFile);
123     void removeFiles(int prefixIndex, int firstFileIndex, int lastFileIndex);
124     QStringList fileNamesToAdd();
125     QModelIndex addPrefix();
126
127 public slots:
128     void onAddFiles();
129     void setCurrentAlias(const QString &before, const QString &after);
130     void setCurrentPrefix(const QString &before, const QString &after);
131     void setCurrentLanguage(const QString &before, const QString &after);
132     void advanceMergeId();
133
134 protected:
135     void setupMenu();
136     void changePrefix(const QModelIndex &index);
137     void changeLang(const QModelIndex &index);
138     void changeAlias(const QModelIndex &index);
139     void mouseReleaseEvent(QMouseEvent *e);
140     void keyPressEvent(QKeyEvent *e);
141
142 signals:
143     void removeItem();
144     void dirtyChanged(bool b);
145
146     void addFilesTriggered(const QString &prefix);
147     void addPrefixTriggered();
148
149 private slots:
150     void onEditAlias();
151     void onEditPrefix();
152     void onEditLang();
153     void popupMenu(const QModelIndex &index);
154
155 public:
156     QString getCurrentValue(NodeProperty property) const;
157     void changeValue(const QModelIndex &nodeIndex, NodeProperty property, const QString &value);
158
159 private:
160     void addUndoCommand(const QModelIndex &nodeIndex, NodeProperty property,
161                         const QString &before, const QString &after);
162
163     QPoint m_releasePos;
164
165     qdesigner_internal::ResourceFile m_qrcFile;
166     Internal::RelativeResourceModel *m_qrcModel;
167
168     QAction *m_addFile;
169     QAction *m_editAlias;
170     QAction *m_removeItem;
171     QAction *m_addPrefix;
172     QAction *m_editPrefix;
173     QAction *m_editLang;
174     QMenu *m_viewMenu;
175     bool m_defaultAddFile;
176     QUndoStack *m_history;
177     int m_mergeId;
178 };
179
180 } // namespace SharedTools
181
182 #endif // RESOURCEVIEW_H