1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #ifndef BOOKMARKMANAGER_H
34 #define BOOKMARKMANAGER_H
36 #include <coreplugin/icontext.h>
37 #include <coreplugin/inavigationwidgetfactory.h>
39 #include <QtCore/QAbstractItemModel>
40 #include <QtCore/QMultiMap>
41 #include <QtCore/QList>
42 #include <QtGui/QListView>
43 #include <QtGui/QPixmap>
44 #include <QtGui/QStyledItemDelegate>
46 namespace ProjectExplorer {
54 namespace TextEditor {
62 class BookmarksPlugin;
63 class BookmarkContext;
65 class BookmarkManager : public QAbstractItemModel
73 QIcon bookmarkIcon() const { return m_bookmarkIcon; }
75 void updateBookmark(Bookmark *bookmark);
76 void removeBookmark(Bookmark *bookmark); // Does not remove the mark
77 void removeAllBookmarks();
78 Bookmark *bookmarkForIndex(QModelIndex index);
80 enum State { NoBookMarks, HasBookMarks, HasBookmarksInDocument };
84 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
85 QModelIndex parent(const QModelIndex &child) const;
86 int rowCount(const QModelIndex &parent = QModelIndex()) const;
87 int columnCount(const QModelIndex &parent = QModelIndex()) const;
88 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
90 // this QItemSelectionModel is shared by all views
91 QItemSelectionModel *selectionModel() const;
94 Filename = Qt::UserRole,
95 LineNumber = Qt::UserRole + 1,
96 Directory = Qt::UserRole + 2,
97 LineText = Qt::UserRole + 3
101 void toggleBookmark();
102 void toggleBookmark(const QString &fileName, int lineNumber);
103 void nextInDocument();
104 void prevInDocument();
109 bool gotoBookmark(Bookmark *bookmark);
112 void updateActions(int state);
113 void currentIndexChanged(const QModelIndex &);
116 void updateActionStatus();
117 void loadBookmarks();
120 TextEditor::ITextEditor *currentTextEditor() const;
121 ProjectExplorer::SessionManager* sessionManager() const;
123 void documentPrevNext(bool next);
125 Bookmark* findBookmark(const QString &path, const QString &fileName, int lineNumber);
126 void addBookmark(Bookmark *bookmark, bool userset = true);
127 void addBookmark(const QString &s);
128 static QString bookmarkToString(const Bookmark *b);
129 void saveBookmarks();
131 typedef QMultiMap<QString, Bookmark *> FileNameBookmarksMap;
132 typedef QMap<QString, FileNameBookmarksMap *> DirectoryFileBookmarksMap;
134 DirectoryFileBookmarksMap m_bookmarksMap;
136 const QIcon m_bookmarkIcon;
138 QList<Bookmark *> m_bookmarksList;
139 QItemSelectionModel *m_selectionModel;
142 class BookmarkView : public QListView
146 BookmarkView(QWidget *parent = 0);
148 void setModel(QAbstractItemModel *model);
150 void gotoBookmark(const QModelIndex &index);
152 void removeFromContextMenu();
155 void contextMenuEvent(QContextMenuEvent *event);
156 void removeBookmark(const QModelIndex &index);
158 BookmarkContext *m_bookmarkContext;
159 QModelIndex m_contextMenuIndex;
160 BookmarkManager *m_manager;
163 class BookmarkContext : public Core::IContext
166 BookmarkContext(BookmarkView *widget);
167 virtual Core::Context context() const;
168 virtual QWidget *widget();
170 BookmarkView *m_bookmarkView;
171 const Core::Context m_context;
174 class BookmarkViewFactory : public Core::INavigationWidgetFactory
177 BookmarkViewFactory(BookmarkManager *bm);
178 QString displayName() const;
179 int priority() const;
181 QKeySequence activationSequence() const;
182 Core::NavigationView createWidget();
184 BookmarkManager *m_manager;
187 class BookmarkDelegate : public QStyledItemDelegate
191 BookmarkDelegate(QObject * parent = 0);
193 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
194 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
197 void generateGradientPixmap(int width, int height, QColor color, bool selected) const;
198 mutable QPixmap *m_normalPixmap;
199 mutable QPixmap *m_selectedPixmap;
202 } // namespace Internal
203 } // namespace Bookmarks
205 #endif // BOOKMARKMANAGER_H