File indexing completed on 2018-12-11 17:32:26

0001 /*
0002  *  This file is part of Konsole, a terminal emulator for KDE.
0003  *
0004  *  Copyright 2012  Frederik Gladhorn <gladhorn@kde.org>
0005  *
0006  *  This program is free software; you can redistribute it and/or modify
0007  *  it under the terms of the GNU General Public License as published by
0008  *  the Free Software Foundation; either version 2 of the License, or
0009  *  (at your option) any later version.
0010  *
0011  *  This program is distributed in the hope that it will be useful,
0012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  *  GNU General Public License for more details.
0015  *
0016  *  You should have received a copy of the GNU General Public License
0017  *  along with this program; if not, write to the Free Software
0018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0019  *  02110-1301  USA.
0020  */
0021 
0022 #ifndef TERMINALDISPLAYACCESSIBLE_H
0023 #define TERMINALDISPLAYACCESSIBLE_H
0024 
0025 //#include <QtGlobal>
0026 
0027 #include <QAccessibleTextInterface>
0028 #include <QAccessibleWidget>
0029 
0030 #include "TerminalDisplay.h"
0031 #include "ScreenWindow.h"
0032 #include "Screen.h"
0033 
0034 namespace Konsole {
0035 /**
0036  * Class implementing the QAccessibleInterface for the terminal display.
0037  * This exposes information about the display to assistive technology using the QAccessible framework.
0038  *
0039  * Most functions are re-implemented from QAccessibleTextInterface.
0040  */
0041 class TerminalDisplayAccessible : public QAccessibleWidget, public QAccessibleTextInterface
0042 {
0043 public:
0044     explicit TerminalDisplayAccessible(TerminalDisplay *display);
0045 
0046     QString text(QAccessible::Text t) const override;
0047     QString text(int startOffset, int endOffset) const override;
0048     int characterCount() const override;
0049 
0050     int selectionCount() const override;
0051     void selection(int selectionIndex, int *startOffset, int *endOffset) const override;
0052     void addSelection(int startOffset, int endOffset) override;
0053     void setSelection(int selectionIndex, int startOffset, int endOffset) override;
0054     void removeSelection(int selectionIndex) override;
0055 
0056     QRect characterRect(int offset) const override;
0057     int offsetAtPoint(const QPoint &point) const override;
0058     void scrollToSubstring(int startIndex, int endIndex) override;
0059 
0060     QString attributes(int offset, int *startOffset, int *endOffset) const override;
0061 
0062     int cursorPosition() const override;
0063     void setCursorPosition(int position) override;
0064 
0065     void *interface_cast(QAccessible::InterfaceType type) override;
0066 
0067 private:
0068     Konsole::TerminalDisplay *display() const;
0069 
0070     inline int positionToOffset(int column, int line) const
0071     {
0072         return line * display()->_usedColumns + column;
0073     }
0074 
0075     inline int lineForOffset(int offset) const
0076     {
0077         return offset / display()->_usedColumns;
0078     }
0079 
0080     inline int columnForOffset(int offset) const
0081     {
0082         return offset % display()->_usedColumns;
0083     }
0084 
0085     QString visibleText() const;
0086 };
0087 } // namespace
0088 
0089 #endif // TERMINALDISPLAYACCESSIBLE_H