1 /* This file is part of the KDE libraries
2 Copyright (C) 2005 Hamish Rodda <rodda@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #ifndef CURSOREXPECTATION_H
20 #define CURSOREXPECTATION_H
22 #include <QtCore/QBool>
23 #include <ktexteditor/cursor.h>
24 #include <ktexteditor/cursorfeedback.h>
26 class CursorExpectation
: public QObject
, public KTextEditor::SmartCursorWatcher
33 CharacterDeletedBefore
= 0x1,
34 CharacterDeletedAfter
= 0x2,
35 CharacterInsertedBefore
= 0x4,
36 CharacterInsertedAfter
= 0x8,
37 PositionChanged
= 0x10,
38 PositionDeleted
= 0x20,
41 static const int numSignals
= 7;
42 Q_DECLARE_FLAGS(CursorSignals
, CursorSignal
)
44 CursorExpectation(KTextEditor::Cursor
* cursor
, CursorSignals signalsExpected
= NoSignal
, const KTextEditor::Cursor
& positionExpected
= KTextEditor::Cursor::invalid());
45 virtual ~CursorExpectation();
47 void checkExpectationsFulfilled() const;
50 virtual void positionChanged(KTextEditor::SmartCursor
* cursor
);
51 virtual void positionDeleted(KTextEditor::SmartCursor
* cursor
);
52 virtual void characterDeleted(KTextEditor::SmartCursor
* cursor
, bool deletedBefore
);
53 virtual void characterInserted(KTextEditor::SmartCursor
* cursor
, bool insertedBefore
);
54 virtual void deleted(KTextEditor::SmartCursor
* cursor
);
57 QString
nameForSignal(int signal
) const;
58 void signalReceived(int signal
);
60 KTextEditor::SmartCursor
* m_smartCursor
;
61 KTextEditor::Cursor m_expectedCursor
;
63 CursorSignals m_expectations
;
65 int m_notifierNotifications
[numSignals
];
66 int m_watcherNotifications
[numSignals
];
67 bool m_smartCursorDeleted
;
70 Q_DECLARE_OPERATORS_FOR_FLAGS(CursorExpectation::CursorSignals
)