File indexing completed on 2025-01-05 05:23:27

0001 /*
0002     This file is part of the Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_BOOKMARKSTOOL_HPP
0010 #define KASTEN_BOOKMARKSTOOL_HPP
0011 
0012 // Kasten core
0013 #include <Kasten/AbstractTool>
0014 // Okteta core
0015 #include <Okteta/Address>
0016 
0017 namespace Okteta {
0018 class Bookmarkable;
0019 class Bookmark;
0020 class AbstractByteArrayModel;
0021 }
0022 template <class T> class QVector;
0023 
0024 namespace Kasten {
0025 
0026 class ByteArrayView;
0027 
0028 class BookmarksTool : public AbstractTool
0029 {
0030     Q_OBJECT
0031 
0032 private:
0033     static constexpr int MaxBookmarkNameSize = 40;
0034 
0035 public:
0036     BookmarksTool();
0037     ~BookmarksTool() override;
0038 
0039 public:
0040     bool hasBookmarks() const;
0041     bool canCreateBookmark() const;
0042     const Okteta::Bookmark& bookmarkAt(unsigned int index) const;
0043     int indexOf(const Okteta::Bookmark& bookmark) const;
0044     unsigned int bookmarksCount() const;
0045     int offsetCoding() const;
0046 
0047 public: // AbstractTool API
0048 //     virtual AbstractModel* targetModel() const;
0049     QString title() const override;
0050 
0051     void setTargetModel(AbstractModel* model) override;
0052 
0053 public:
0054     Okteta::Bookmark createBookmark();
0055     void gotoBookmark(const Okteta::Bookmark& bookmark);
0056     void setBookmarkName(unsigned int bookmarkIndex, const QString& name);
0057     void deleteBookmarks(const QVector<Okteta::Bookmark>& bookmarks);
0058 
0059 Q_SIGNALS:
0060     void hasBookmarksChanged(bool hasBookmarks);
0061     void bookmarksAdded(const QVector<Okteta::Bookmark>& bookmarks);
0062     void bookmarksRemoved(const QVector<Okteta::Bookmark>& bookmarks);
0063     void bookmarksModified(const QVector<int>& indizes);
0064     void canCreateBookmarkChanged(bool canCreateBookmark);
0065     void offsetCodingChanged(int offsetCoding);
0066 
0067 private Q_SLOTS:
0068     void onCursorPositionChanged(Okteta::Address newPosition);
0069     void onBookmarksModified();
0070 
0071 private: // sources
0072     ByteArrayView* mByteArrayView = nullptr;
0073     Okteta::AbstractByteArrayModel* mByteArray = nullptr;
0074     Okteta::Bookmarkable* mBookmarks = nullptr;
0075 
0076     bool mCanCreateBookmark = false;
0077 };
0078 
0079 }
0080 
0081 #endif