File indexing completed on 2024-06-16 05:24:57

0001 /*
0002     This file is part of the Okteta Kasten module, 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_SELECTRANGETOOL_HPP
0010 #define KASTEN_SELECTRANGETOOL_HPP
0011 
0012 // Okteta core
0013 #include <Okteta/Address>
0014 // Kasten core
0015 #include <Kasten/AbstractTool>
0016 
0017 namespace Okteta {
0018 class AbstractByteArrayModel;
0019 }
0020 
0021 namespace Kasten {
0022 
0023 class ByteArrayView;
0024 
0025 /**
0026  */
0027 class SelectRangeTool : public AbstractTool
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     SelectRangeTool();
0033     ~SelectRangeTool() override;
0034 
0035 public: // AbstractTool API
0036 //     virtual AbstractModel* targetModel() const;
0037     QString title() const override;
0038 
0039     void setTargetModel(AbstractModel* model) override;
0040 
0041 public: // status
0042     int currentSelectionStart() const;
0043     int currentSelectionEnd() const;
0044     int targetSelectionStart() const;
0045     int targetSelectionEnd() const;
0046     bool isEndRelative() const;
0047     bool isEndBackwards() const;
0048 
0049     bool isUsable() const;
0050     bool isApplyable() const; // candidate for AbstractTool API
0051 
0052 public Q_SLOTS: // settings
0053     void setTargetStart(Okteta::Address start);
0054     void setTargetEnd(Okteta::Address end);
0055     void setIsEndRelative(bool isEndRelative);
0056     void setIsEndBackwards(bool isEndBackwards);
0057 
0058 public Q_SLOTS: // actions
0059     void select();
0060 
0061 Q_SIGNALS:
0062     void isUsableChanged(bool isUsable);
0063     void isApplyableChanged(bool isApplyable);    // candidate for AbstractTool API
0064     // TODO: isAtLine useful, to prevent noop actions, or should they be allowed, too?
0065 
0066 private:
0067     int finalTargetSelectionStart() const;
0068     int finalTargetSelectionEnd() const;
0069 
0070 private Q_SLOTS:
0071     void onContentsChanged();
0072 
0073 private: // settings
0074     int mTargetStart = 0;
0075     int mTargetEnd = -1;
0076     bool mIsEndRelative : 1;
0077     bool mIsEndBackwards : 1;
0078 
0079 private: // target
0080     ByteArrayView* mByteArrayView = nullptr;
0081     Okteta::AbstractByteArrayModel* mByteArrayModel = nullptr;
0082 };
0083 
0084 inline int SelectRangeTool::targetSelectionStart()   const { return mTargetStart; }
0085 inline int SelectRangeTool::targetSelectionEnd()     const { return mTargetEnd; }
0086 inline bool SelectRangeTool::isEndRelative() const { return mIsEndRelative; }
0087 inline bool SelectRangeTool::isEndBackwards() const { return mIsEndBackwards; }
0088 
0089 }
0090 
0091 #endif