OSDN Git Service

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