1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-02-20 20:09:14 +00:00

Moved to old version on yat due to crashes. Disabled scrolling due to glitches.

This commit is contained in:
Filippo Scognamiglio 2013-12-27 16:27:33 +01:00
parent 53c77a9364
commit 1bb866f312
18 changed files with 242 additions and 327 deletions

View File

@ -28,19 +28,15 @@ Item {
property real characterWidth: 0
property real characterHeight: 0
property int screenWidth: 0
property int screenWidth: width / characterWidth
property int startX
property int startY
property int endX
property int endY
property point start
property point end
property color color: "grey"
y: startY * characterHeight
width: parent.width
height: (endY - startY + 1) * characterHeight
height: parent.height
opacity: 0.8
@ -75,29 +71,27 @@ Item {
onCharacterHeightChanged: calculateRectangles();
onScreenWidthChanged: calculateRectangles();
onStartXChanged: calculateRectangles();
onStartYChanged: calculateRectangles();
onEndXChanged: calculateRectangles();
onEndYChanged: calculateRectangles();
onStartChanged: calculateRectangles();
onEndChanged: calculateRectangles();
function calculateRectangles() {
highlightArea.y = startY * characterHeight;
begginning_rectangle.x = startX * characterWidth;
if (startY === endY) {
highlightArea.y = start.y * characterHeight;
begginning_rectangle.x = start.x * characterWidth;
if (start.y === end.y) {
middle_rectangle.visible = false;
end_rectangle.visible = false
begginning_rectangle.width = (endX - startX) * characterWidth;
begginning_rectangle.width = (end.x - start.x) * characterWidth;
} else {
begginning_rectangle.width = (screenWidth - startX) * characterWidth;
if (startY === endY - 1) {
begginning_rectangle.width = (screenWidth - start.x) * characterWidth;
if (start.y === end.y - 1) {
middle_rectangle.height = 0;
middle_rectangle.visible = false;
}else {
middle_rectangle.visible = true;
middle_rectangle.height = (endY - startY - 1) * characterHeight;
middle_rectangle.height = (end.y - start.y - 1) * characterHeight;
}
end_rectangle.visible = true;
end_rectangle.width = endX * characterWidth;
end_rectangle.width = end.x * characterWidth;
}
}

View File

@ -22,7 +22,6 @@
*******************************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.1
import org.yat 1.0
@ -41,17 +40,6 @@ TerminalScreen {
font.pixelSize: 20
focus: true
Action {
id: copyAction
shortcut: "Ctrl+Shift+C"
onTriggered: screen.selection.sendToClipboard()
}
Action {
id: paseAction
shortcut: "Ctrl+Shift+V"
onTriggered: screen.selection.pasteFromClipboard()
}
onActiveFocusChanged: {
if (activeFocus) {
Qt.inputMethod.show();
@ -78,9 +66,10 @@ TerminalScreen {
anchors.left: parent.left
contentWidth: width
contentHeight: textContainer.height
interactive: true
interactive: false
flickableDirection: Flickable.VerticalFlick
contentY: ((screen.contentHeight - screen.height) * screenItem.fontHeight)
boundsBehavior: Flickable.StopAtBounds
Item {
id: textContainer
@ -91,22 +80,7 @@ TerminalScreen {
anchors.fill: parent
color: terminal.screen.defaultBackgroundColor
}
HighlightArea {
characterHeight: fontHeight
characterWidth: fontWidth
screenWidth: terminalWindow.width
startX: screen.selection.startX
startY: screen.selection.startY
endX: screen.selection.endX
endY: screen.selection.endY
visible: screen.selection.enable
}
}
onContentYChanged: {
if (!atYEnd) {
var top_line = Math.floor(Math.max(contentY,0) / screenItem.fontHeight);
@ -156,11 +130,13 @@ TerminalScreen {
onRequestHeightChange: {
terminalWindow.height = newHeight * screenItem.fontHeight;
terminalWindow.contentItem.height = newHeight * screenItem.fontHeight;
console.log("banana");
}
onRequestWidthChange: {
terminalWindow.width = newWidth * screenItem.fontWidth;
terminalWindow.contentItem.width = newWidth * screenItem.fontWidth;
console.log("a");
}
}
@ -196,6 +172,16 @@ TerminalScreen {
}
}
HighlightArea {
characterHeight: fontHeight
characterWidth: fontWidth
start: screen.selectionAreaStart
end: screen.selectionAreaEnd
visible: screen.selectionEnabled
}
Rectangle {
id: flash
z: 1.2
@ -222,49 +208,39 @@ TerminalScreen {
MouseArea {
id:mousArea
property int drag_start_x
property int drag_start_y
property point drag_start
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
onPressed: {
if (mouse.button == Qt.LeftButton) {
hoverEnabled = true;
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y);
var character = Math.floor((transformed_mouse.x / fontWidth));
var line = Math.floor(transformed_mouse.y / fontHeight);
var character = Math.floor((mouse.x / screen.charWidth));
var line = Math.floor(mouse.y / screen.lineHeight);
var start = Qt.point(character,line);
drag_start_x = character;
drag_start_y = line;
screen.selection.startX = character;
screen.selection.startY = line;
screen.selection.endX = character;
screen.selection.endY = line;
drag_start = start;
screen.selectionAreaStart = start;
screen.selectionAreaEnd = start;
}
}
onPositionChanged: {
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y);
var character = Math.floor(transformed_mouse.x / fontWidth);
var line = Math.floor(transformed_mouse.y / fontHeight);
var character = Math.floor(mouse.x / screen.charWidth);
var line = Math.floor(mouse.y / screen.lineHeight);
var current_pos = Qt.point(character,line);
if (line < drag_start_y || (line === drag_start_y && character < drag_start_x)) {
screen.selection.startX = character;
screen.selection.startY = line;
screen.selection.endX = drag_start_x;
screen.selection.endY = drag_start_y;
if (line < drag_start.y || (line === drag_start.y && character < drag_start.x)) {
screen.selectionAreaStart = current_pos;
screen.selectionAreaEnd = drag_start;
}else {
screen.selection.startX = drag_start_x;
screen.selection.startY = drag_start_y;
screen.selection.endX = character;
screen.selection.endY = line;
screen.selectionAreaEnd = current_pos;
screen.selectionAreaStart = drag_start;
}
}
onReleased: {
if (mouse.button == Qt.LeftButton) {
hoverEnabled = false;
screen.selection.sendToSelection();
screen.sendSelectionToSelection();
}
}
@ -273,12 +249,10 @@ TerminalScreen {
screen.pasteFromSelection();
}
}
onDoubleClicked: {
if (mouse.button == Qt.LeftButton) {
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y);
var character = Math.floor(transformed_mouse.x / fontWidth);
var line = Math.floor(transformed_mouse.y / fontHeight);
var character = Math.floor(mouse.x / screen.charWidth);
var line = Math.floor(mouse.y / screen.lineHeight);
screen.doubleClicked(Qt.point(character,line));
}
}

View File

@ -41,13 +41,13 @@ ObjectDestructItem {
Rectangle {
anchors.fill: parent
color: "black" //objectHandle.backgroundColor
color: "black"
MonoText {
id: textElement
anchors.fill: parent
text: objectHandle.text
color: "white" //objectHandle.foregroundColor
color: "white"
font.family: textItem.font.family
font.pixelSize: textItem.font.pixelSize
font.pointSize: textItem.font.pointSize

View File

@ -30,7 +30,7 @@ import QtQuick.Controls 1.0
import QtGraphicalEffects 1.0
ApplicationWindow{
id: mainwindow
id: terminalWindow
width: 1024
height: 768
@ -48,7 +48,7 @@ ApplicationWindow{
text: qsTr("Settings")
onTriggered: {
var component = Qt.createComponent("SettingsWindow.qml");
component.createObject(mainwindow);
component.createObject(terminalWindow);
}
}
}

View File

@ -1,5 +1,3 @@
forked at 8c3d6c85c3dc981bca817bd9052a693570e26e6e
YAT is a terminal emulator written in qml and c++
The main goal of the project was to find out if it was possible to use qml to

View File

@ -21,8 +21,7 @@ HEADERS += \
$$PWD/cursor.h \
$$PWD/nrc_text_codec.h \
$$PWD/scrollback.h \
$$PWD/utf8_decoder.h \
$$PWD/selection.h
$$PWD/utf8_decoder.h
SOURCES += \
$$PWD/yat_pty.cpp \
@ -36,6 +35,5 @@ SOURCES += \
$$PWD/screen_data.cpp \
$$PWD/cursor.cpp \
$$PWD/nrc_text_codec.cpp \
$$PWD/scrollback.cpp \
$$PWD/selection.cpp
$$PWD/scrollback.cpp

View File

@ -37,7 +37,6 @@ Block::Block(Screen *screen)
: m_screen(screen)
, m_line(0)
, m_new_line(-1)
, m_screen_index(0)
, m_width(m_screen->width())
, m_visible(true)
, m_changed(true)
@ -309,6 +308,14 @@ void Block::insertAtPos(int pos, const QString &text, const TextStyle &style, bo
}
}
void Block::setIndex(int index)
{
if (index != m_new_line) {
m_changed = true;
m_new_line = index;
}
}
QString *Block::textLine()
{
return &m_text_line;

View File

@ -49,15 +49,8 @@ public:
void replaceAtPos(int i, const QString &text, const TextStyle &style, bool only_latin = true);
void insertAtPos(int i, const QString &text, const TextStyle &style, bool only_latin = true);
void setScreenIndex(int index) { m_screen_index = index; }
int screenIndex() const { return m_screen_index; }
size_t line() { return m_new_line; }
void setLine(size_t line) {
if (line != m_new_line) {
m_changed = true;
m_new_line = line;
}
}
void setIndex(int index);
int index() const { return m_new_line; }
QString *textLine();
int textSize() { return m_text_line.size(); }
@ -95,10 +88,8 @@ private:
Screen *m_screen;
QString m_text_line;
QVector<TextStyleLine> m_style_list;
size_t m_line;
size_t m_new_line;
int m_screen_index;
int m_line;
int m_new_line;
int m_width;
bool m_visible;

View File

@ -97,7 +97,6 @@ void Cursor::setDocumentHeight(int height, int currentCursorBlock, int currentSc
if (!removeLinesAtTop) {
new_ry() -= removeLinesAtTop;
notifyChanged();
}
} else {
int height_diff = height - m_document_height;

View File

@ -28,7 +28,6 @@
#include "cursor.h"
#include "text.h"
#include "scrollback.h"
#include "selection.h"
#include "controll_chars.h"
#include "character_sets.h"
@ -48,11 +47,12 @@ Screen::Screen(QObject *parent)
, m_timer_event_id(0)
, m_width(1)
, m_height(0)
, m_primary_data(new ScreenData(500, this))
, m_primary_data(new ScreenData(0, this))
, m_alternate_data(new ScreenData(0, this))
, m_current_data(m_primary_data)
, m_old_current_data(m_primary_data)
, m_selection(new Selection(this))
, m_selection_valid(false)
, m_selection_moved(0)
, m_flash(false)
, m_cursor_changed(false)
, m_application_cursor_key_mode(false)
@ -64,8 +64,6 @@ Screen::Screen(QObject *parent)
m_new_cursors << cursor;
connect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged()));
connect(m_primary_data, &ScreenData::contentModified,
this, &Screen::contentModified);
connect(m_palette, SIGNAL(changed()), this, SLOT(paletteChanged()));
setHeight(25);
@ -156,11 +154,9 @@ void Screen::useAlternateScreenBuffer()
{
if (m_current_data == m_primary_data) {
disconnect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged()));
disconnect(m_primary_data, &ScreenData::contentModified, this, &Screen::contentModified);
m_current_data = m_alternate_data;
m_current_data->clear();
connect(m_alternate_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged()));
connect(m_primary_data, &ScreenData::contentModified, this, &Screen::contentModified);
emit contentHeightChanged();
}
}
@ -169,10 +165,8 @@ void Screen::useNormalScreenBuffer()
{
if (m_current_data == m_alternate_data) {
disconnect(m_alternate_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged()));
disconnect(m_alternate_data, &ScreenData::contentModified, this, &Screen::contentModified);
m_current_data = m_primary_data;
connect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged()));
connect(m_alternate_data, &ScreenData::contentModified, this, &Screen::contentModified);
emit contentHeightChanged();
}
}
@ -235,9 +229,65 @@ bool Screen::fastScroll() const
return m_fast_scroll;
}
Selection *Screen::selection() const
QPointF Screen::selectionAreaStart() const
{
return m_selection;
return m_selection_start;
}
void Screen::setSelectionAreaStart(const QPointF &start)
{
bool emitChanged = m_selection_start != start;
m_selection_start = start;
setSelectionValidity();
if (emitChanged)
emit selectionAreaStartChanged();
}
QPointF Screen::selectionAreaEnd() const
{
return m_selection_end;
}
void Screen::setSelectionAreaEnd(const QPointF &end)
{
bool emitChanged = m_selection_end != end;
m_selection_end = end;
setSelectionValidity();
if (emitChanged)
emit selectionAreaEndChanged();
}
bool Screen::selectionEnabled() const
{
return m_selection_valid;
}
void Screen::setSelectionEnabled(bool enabled)
{
bool emitchanged = m_selection_valid != enabled;
m_selection_valid = enabled;
if (emitchanged)
emit selectionEnabledChanged();
}
void Screen::sendSelectionToClipboard() const
{
//currentScreenData()->sendSelectionToClipboard(m_selection_start, m_selection_end, QClipboard::Clipboard);
}
void Screen::sendSelectionToSelection() const
{
//currentScreenData()->sendSelectionToClipboard(m_selection_start, m_selection_end, QClipboard::Selection);
}
void Screen::pasteFromSelection()
{
m_pty.write(QGuiApplication::clipboard()->text(QClipboard::Selection).toUtf8());
}
void Screen::pasteFromClipboard()
{
m_pty.write(QGuiApplication::clipboard()->text(QClipboard::Clipboard).toUtf8());
}
void Screen::doubleClicked(const QPointF &clicked)
@ -319,7 +369,15 @@ void Screen::dispatchChanges()
m_cursor_stack[i]->dispatchEvents();
}
m_selection->dispatchChanges();
if (m_selection_valid && m_selection_moved) {
if (m_selection_start.y() < 0 ||
m_selection_end.y() >= height()) {
setSelectionEnabled(false);
} else {
emit selectionAreaStartChanged();
emit selectionAreaEndChanged();
}
}
}
void Screen::sendPrimaryDA()
@ -608,6 +666,16 @@ void Screen::paletteChanged()
}
}
void Screen::setSelectionValidity()
{
if (m_selection_end.y() > m_selection_start.y() ||
(m_selection_end.y() == m_selection_start.y() &&
m_selection_end.x() > m_selection_start.x())) {
setSelectionEnabled(true);
} else {
setSelectionEnabled(false);
}
}
void Screen::timerEvent(QTimerEvent *)

View File

@ -1,25 +1,22 @@
/*******************************************************************************
/**************************************************************************************************
* Copyright (c) 2012 Jørgen Lind
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
* OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*******************************************************************************/
***************************************************************************************************/
#ifndef TERMINALSCREEN_H
#define TERMINALSCREEN_H
@ -40,7 +37,6 @@ class Block;
class Cursor;
class Text;
class ScreenData;
class Selection;
class Screen : public QObject
{
@ -50,7 +46,9 @@ class Screen : public QObject
Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged)
Q_PROPERTY(int contentHeight READ contentHeight NOTIFY contentHeightChanged)
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY screenTitleChanged)
Q_PROPERTY(Selection *selection READ selection CONSTANT)
Q_PROPERTY(bool selectionEnabled READ selectionEnabled NOTIFY selectionEnabledChanged)
Q_PROPERTY(QPointF selectionAreaStart READ selectionAreaStart WRITE setSelectionAreaStart NOTIFY selectionAreaStartChanged)
Q_PROPERTY(QPointF selectionAreaEnd READ selectionAreaEnd WRITE setSelectionAreaEnd NOTIFY selectionAreaEndChanged)
Q_PROPERTY(QColor defaultBackgroundColor READ defaultBackgroundColor NOTIFY defaultBackgroundColorChanged)
public:
@ -89,7 +87,18 @@ public:
void setFastScroll(bool fast);
bool fastScroll() const;
Selection *selection() const;
QPointF selectionAreaStart() const;
void setSelectionAreaStart(const QPointF &start);
QPointF selectionAreaEnd() const;
void setSelectionAreaEnd(const QPointF &end);
bool selectionEnabled() const;
Q_INVOKABLE void setSelectionEnabled(bool enabled);
Q_INVOKABLE void sendSelectionToClipboard() const;
Q_INVOKABLE void sendSelectionToSelection() const;
Q_INVOKABLE void pasteFromSelection();
Q_INVOKABLE void pasteFromClipboard();
Q_INVOKABLE void doubleClicked(const QPointF &clicked);
@ -129,6 +138,10 @@ signals:
void dispatchLineChanges();
void dispatchTextSegmentChanges();
void selectionAreaStartChanged();
void selectionAreaEndChanged();
void selectionEnabledChanged();
void screenTitleChanged();
void textCreated(Text *text);
@ -144,12 +157,12 @@ signals:
void widthChanged();
void defaultBackgroundColorChanged();
void contentModified(size_t lineModified, int lineDiff, int contentDiff);
protected:
void timerEvent(QTimerEvent *);
private:
void setSelectionValidity();
ColorPalette *m_palette;
YatPty m_pty;
Parser m_parser;
@ -171,7 +184,10 @@ private:
QString m_title;
Selection *m_selection;
bool m_selection_valid;
bool m_selection_moved;
QPointF m_selection_start;
QPointF m_selection_end;
bool m_flash;
bool m_cursor_changed;

View File

@ -167,7 +167,7 @@ void ScreenData::deleteCharacters(const QPoint &point, int to)
if (it == m_screen_blocks.end())
return;
int line_in_block = point.y() - (*it)->screenIndex();
int line_in_block = point.y() - (*it)->index();
int chars_to_line = line_in_block * m_width;
(*it)->deleteCharacters(chars_to_line + point.x(), chars_to_line + to);
@ -189,8 +189,6 @@ void ScreenData::moveLine(int from, int to)
if (from == to)
return;
const size_t old_content_height = contentHeight();
const int orig_to = to;
if (to > from)
to++;
auto from_it = it_for_row_ensure_single_line_block(from);
@ -198,17 +196,13 @@ void ScreenData::moveLine(int from, int to)
(*from_it)->clear();
m_screen_blocks.splice(to_it, m_screen_blocks, from_it);
qDebug() << Q_FUNC_INFO << to;
emit contentModified(m_scrollback->height() + to, 1, content_height_diff(old_content_height));
}
void ScreenData::insertLine(int row, int topMargin)
{
auto row_it = it_for_row(row + 1);
const size_t old_content_height = contentHeight();
if (!topMargin && m_height >= m_screen_height) {
if (!topMargin && m_height - m_screen_blocks.front()->lineCount() >= m_screen_height) {
push_at_most_to_scrollback(1);
} else {
auto row_top_margin = it_for_row_ensure_single_line_block(topMargin);
@ -226,8 +220,6 @@ void ScreenData::insertLine(int row, int topMargin)
m_screen_blocks.insert(row_it,block_to_insert);
m_height++;
m_block_count++;
emit contentModified(m_scrollback->height() + row + 1, 1, content_height_diff(old_content_height));
}
@ -245,17 +237,16 @@ void ScreenData::dispatchLineEvents()
{
if (!m_block_count)
return;
const int scrollback_height = m_scrollback->height();
const int content_height = contentHeight();
int i = 0;
for (auto it = m_screen_blocks.begin(); it != m_screen_blocks.end(); ++it) {
int line = scrollback_height + i;
(*it)->setLine(line);
//(*it)->setScreenIndex(i);
int line = content_height - m_height + i;
(*it)->setIndex(line);
(*it)->dispatchEvents();
i+= (*it)->lineCount();
}
if (contentHeight() != m_old_total_lines) {
if (content_height != m_old_total_lines) {
m_old_total_lines = contentHeight();
emit contentHeightChanged();
}
@ -298,66 +289,14 @@ Scrollback *ScreenData::scrollback() const
return m_scrollback;
}
void ScreenData::sendSelectionToClipboard(const QPoint &start, const QPoint &end, QClipboard::Mode mode)
{
if (start.y() < 0)
return;
if (end.y() >= contentHeight())
return;
QString to_clip_board_buffer;
bool started_in_scrollback = false;
if (size_t(start.y()) < m_scrollback->height()) {
started_in_scrollback = true;
QPoint end_scrollback = end;
if (size_t(end.y()) >= m_scrollback->height()) {
end_scrollback = QPoint(m_width, m_scrollback->height() - 1);
}
to_clip_board_buffer = m_scrollback->selection(start, end_scrollback);
}
if (size_t(end.y()) >= m_scrollback->height()) {
QPoint start_in_screen;
if (started_in_scrollback) {
start_in_screen = QPoint(0,0);
} else {
start_in_screen = start;
start_in_screen.ry() -= m_scrollback->height();
}
QPoint end_in_screen = end;
end_in_screen.ry() -= m_scrollback->height();
auto it = it_for_row(start_in_screen.y());
size_t screen_index = (*it)->screenIndex();
int start_pos = (start_in_screen.y() - (*it)->screenIndex()) * m_width + start.x();
for (; it != m_screen_blocks.end(); ++it, start_pos = 0) {
int end_pos = (*it)->textSize();
bool should_break = false;
if (size_t(screen_index + (*it)->lineCount()) > size_t(end_in_screen.y())) {
end_pos = (end_in_screen.y() - screen_index) * m_width + end_in_screen.x();
should_break = true;
}
if (to_clip_board_buffer.size())
to_clip_board_buffer += '\n';
to_clip_board_buffer += (*it)->textLine()->mid(start_pos, end_pos - start_pos);
if (should_break)
break;
screen_index += (*it)->lineCount();
}
}
QGuiApplication::clipboard()->setText(to_clip_board_buffer, mode);
}
CursorDiff ScreenData::modify(const QPoint &point, const QString &text, const TextStyle &style, bool replace, bool only_latin)
{
auto it = it_for_row(point.y());
Block *block = *it;
const int start_char = (point.y() - block->screenIndex()) * m_width + point.x();
const size_t lines_before = block->lineCount();
const int lines_changed =
int start_char = (point.y() - block->index()) * m_width + point.x();
size_t lines_before = block->lineCount();
int lines_changed =
block->lineCountAfterModified(start_char, text.size(), replace) - lines_before;
const size_t old_content_height = contentHeight();
m_height += lines_changed;
if (lines_changed > 0) {
int removed = 0;
@ -392,8 +331,6 @@ CursorDiff ScreenData::modify(const QPoint &point, const QString &text, const Te
int end_char = (start_char + text.size()) % m_width;
if (end_char == 0)
end_char = m_width -1;
emit contentModified(m_scrollback->height() + point.y(), lines_changed, content_height_diff(old_content_height));
return { lines_changed, end_char - point.x()};
}
@ -414,8 +351,8 @@ void ScreenData::clearBlock(std::list<Block *>::iterator line)
std::list<Block *>::iterator ScreenData::it_for_row_ensure_single_line_block(int row)
{
auto it = it_for_row(row);
const int index = (*it)->screenIndex();
const int lines = (*it)->lineCount();
int index = (*it)->index();
int lines = (*it)->lineCount();
if (index == row && lines == 1) {
return it;
@ -434,12 +371,12 @@ std::list<Block *>::iterator ScreenData::split_out_row_from_block(std::list<Bloc
if (row_in_block == 0) {
auto insert_before = (*it)->takeLine(0);
insert_before->setScreenIndex(row_in_block);
insert_before->setIndex(row_in_block);
m_block_count++;
return m_screen_blocks.insert(it,insert_before);
} else if (row_in_block == lines -1) {
auto insert_after = (*it)->takeLine(lines -1);
insert_after->setScreenIndex(row_in_block);
insert_after->setIndex(row_in_block);
++it;
m_block_count++;
return m_screen_blocks.insert(it, insert_after);
@ -521,10 +458,3 @@ void ScreenData::ensure_at_least_height(int height)
m_block_count += to_insert;
}
}
int ScreenData::content_height_diff(size_t old_content_height)
{
const size_t content_height = contentHeight();
return old_content_height < content_height ? content_height - old_content_height :
- int(old_content_height - content_height);
}

View File

@ -32,7 +32,6 @@
#include <QtCore/QObject>
#include <QtGui/QClipboard>
#include <QtCore/QDebug>
class Screen;
class Scrollback;
@ -82,8 +81,6 @@ public:
Scrollback *scrollback() const;
void sendSelectionToClipboard(const QPoint &start, const QPoint &end, QClipboard::Mode mode);
inline std::list<Block *>::iterator it_for_row(int row);
public slots:
void setHeight(int height, int currentCursorLine, int currentContentHeight);
@ -91,7 +88,6 @@ public slots:
signals:
void contentHeightChanged();
void contentModified(size_t lineModified, int lineDiff, int contentDiff);
private:
CursorDiff modify(const QPoint &pos, const QString &text, const TextStyle &style, bool replace, bool only_latin);
@ -102,7 +98,6 @@ private:
void reclaim_at_least(int lines);
void remove_lines_from_end(int lines);
void ensure_at_least_height(int height);
int content_height_diff(size_t old_content_height);
Screen *m_screen;
Scrollback *m_scrollback;
int m_screen_height;
@ -116,21 +111,20 @@ private:
std::list<Block *>::iterator ScreenData::it_for_row(int row)
{
if (row >= m_screen_height) {
return m_screen_blocks.end();
}
auto it = m_screen_blocks.end();
int line_for_block = m_screen_height;
size_t abs_line = contentHeight();
while (it != m_screen_blocks.begin()) {
--it;
int end_line = line_for_block - 1;
line_for_block -= (*it)->lineCount();
abs_line -= (*it)->lineCount();
if (line_for_block <= row) {
(*it)->setScreenIndex(line_for_block);
(*it)->setLine(abs_line);
if (line_for_block <= row && end_line >= row) {
(*it)->setIndex(line_for_block);
return it;
}
if (end_line < row) {
break;
}
}
return m_screen_blocks.end();

View File

@ -42,24 +42,17 @@ Scrollback::Scrollback(size_t max_size, ScreenData *screen_data)
void Scrollback::addBlock(Block *block)
{
if (!m_max_size) {
delete block;
return;
}
m_blocks.push_back(block);
block->releaseTextObjects();
m_block_count++;
m_height += m_blocks.back()->lineCount();
while (m_height - m_blocks.front()->lineCount() >= m_max_size) {
if (!m_max_size || m_height == m_max_size - 1) {
m_block_count--;
m_height -= m_blocks.front()->lineCount();
delete m_blocks.front();
m_blocks.pop_front();
m_adjust_visible_pages++;
}
m_visible_pages.clear();
}
@ -135,7 +128,7 @@ void Scrollback::ensurePageVisible(Page &page, int new_height)
auto it = page.it;
std::advance(it, page.size);
for (int i = page.size; i < new_height; ++it, i++) {
(*it)->setLine(line_no + i);
(*it)->setIndex(line_no + i);
(*it)->dispatchEvents();
}
page.size = new_height;
@ -206,10 +199,3 @@ void Scrollback::setWidth(int width)
{
m_width = width;
}
QString Scrollback::selection(const QPoint &start, const QPoint &end) const
{
Q_UNUSED(start);
Q_UNUSED(end);
return QString();
}

View File

@ -28,7 +28,6 @@
#include <list>
#include <QtCore/qglobal.h>
#include <QtCore/QPoint>
class ScreenData;
class Block;
@ -52,8 +51,6 @@ public:
void setWidth(int width);
size_t blockCount() { return m_block_count; }
QString selection(const QPoint &start, const QPoint &end) const;
private:
void ensurePageVisible(Page &page, int new_height);
void ensurePageNotVisible(Page &page);

View File

@ -28,19 +28,15 @@ Item {
property real characterWidth: 0
property real characterHeight: 0
property int screenWidth: 0
property int screenWidth: width / characterWidth
property int startX
property int startY
property int endX
property int endY
property point start
property point end
property color color: "grey"
y: startY * characterHeight
width: parent.width
height: (endY - startY + 1) * characterHeight
height: parent.height
opacity: 0.8
@ -75,29 +71,27 @@ Item {
onCharacterHeightChanged: calculateRectangles();
onScreenWidthChanged: calculateRectangles();
onStartXChanged: calculateRectangles();
onStartYChanged: calculateRectangles();
onEndXChanged: calculateRectangles();
onEndYChanged: calculateRectangles();
onStartChanged: calculateRectangles();
onEndChanged: calculateRectangles();
function calculateRectangles() {
highlightArea.y = startY * characterHeight;
begginning_rectangle.x = startX * characterWidth;
if (startY === endY) {
highlightArea.y = start.y * characterHeight;
begginning_rectangle.x = start.x * characterWidth;
if (start.y === end.y) {
middle_rectangle.visible = false;
end_rectangle.visible = false
begginning_rectangle.width = (endX - startX) * characterWidth;
begginning_rectangle.width = (end.x - start.x) * characterWidth;
} else {
begginning_rectangle.width = (screenWidth - startX) * characterWidth;
if (startY === endY - 1) {
begginning_rectangle.width = (screenWidth - start.x) * characterWidth;
if (start.y === end.y - 1) {
middle_rectangle.height = 0;
middle_rectangle.visible = false;
}else {
middle_rectangle.visible = true;
middle_rectangle.height = (endY - startY - 1) * characterHeight;
middle_rectangle.height = (end.y - start.y - 1) * characterHeight;
}
end_rectangle.visible = true;
end_rectangle.width = endX * characterWidth;
end_rectangle.width = end.x * characterWidth;
}
}

View File

@ -22,7 +22,6 @@
*******************************************************************************/
import QtQuick 2.0
import QtQuick.Controls 1.1
import org.yat 1.0
@ -40,17 +39,6 @@ TerminalScreen {
font.family: "menlo"
focus: true
Action {
id: copyAction
shortcut: "Ctrl+Shift+C"
onTriggered: screen.selection.sendToClipboard()
}
Action {
id: paseAction
shortcut: "Ctrl+Shift+V"
onTriggered: screen.selection.pasteFromClipboard()
}
onActiveFocusChanged: {
if (activeFocus) {
Qt.inputMethod.show();
@ -90,22 +78,7 @@ TerminalScreen {
anchors.fill: parent
color: terminal.screen.defaultBackgroundColor
}
HighlightArea {
characterHeight: fontHeight
characterWidth: fontWidth
screenWidth: terminalWindow.width
startX: screen.selection.startX
startY: screen.selection.startY
endX: screen.selection.endX
endY: screen.selection.endY
visible: screen.selection.enable
}
}
onContentYChanged: {
if (!atYEnd) {
var top_line = Math.floor(Math.max(contentY,0) / screenItem.fontHeight);
@ -195,6 +168,16 @@ TerminalScreen {
}
}
HighlightArea {
characterHeight: fontHeight
characterWidth: fontWidth
start: screen.selectionAreaStart
end: screen.selectionAreaEnd
visible: screen.selectionEnabled
}
Rectangle {
id: flash
z: 1.2
@ -221,49 +204,39 @@ TerminalScreen {
MouseArea {
id:mousArea
property int drag_start_x
property int drag_start_y
property point drag_start
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
onPressed: {
if (mouse.button == Qt.LeftButton) {
hoverEnabled = true;
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y);
var character = Math.floor((transformed_mouse.x / fontWidth));
var line = Math.floor(transformed_mouse.y / fontHeight);
var character = Math.floor((mouse.x / screen.charWidth));
var line = Math.floor(mouse.y / screen.lineHeight);
var start = Qt.point(character,line);
drag_start_x = character;
drag_start_y = line;
screen.selection.startX = character;
screen.selection.startY = line;
screen.selection.endX = character;
screen.selection.endY = line;
drag_start = start;
screen.selectionAreaStart = start;
screen.selectionAreaEnd = start;
}
}
onPositionChanged: {
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y);
var character = Math.floor(transformed_mouse.x / fontWidth);
var line = Math.floor(transformed_mouse.y / fontHeight);
var character = Math.floor(mouse.x / screen.charWidth);
var line = Math.floor(mouse.y / screen.lineHeight);
var current_pos = Qt.point(character,line);
if (line < drag_start_y || (line === drag_start_y && character < drag_start_x)) {
screen.selection.startX = character;
screen.selection.startY = line;
screen.selection.endX = drag_start_x;
screen.selection.endY = drag_start_y;
if (line < drag_start.y || (line === drag_start.y && character < drag_start.x)) {
screen.selectionAreaStart = current_pos;
screen.selectionAreaEnd = drag_start;
}else {
screen.selection.startX = drag_start_x;
screen.selection.startY = drag_start_y;
screen.selection.endX = character;
screen.selection.endY = line;
screen.selectionAreaEnd = current_pos;
screen.selectionAreaStart = drag_start;
}
}
onReleased: {
if (mouse.button == Qt.LeftButton) {
hoverEnabled = false;
screen.selection.sendToSelection();
screen.sendSelectionToSelection();
}
}
@ -272,12 +245,10 @@ TerminalScreen {
screen.pasteFromSelection();
}
}
onDoubleClicked: {
if (mouse.button == Qt.LeftButton) {
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y);
var character = Math.floor(transformed_mouse.x / fontWidth);
var line = Math.floor(transformed_mouse.y / fontHeight);
var character = Math.floor(mouse.x / screen.charWidth);
var line = Math.floor(mouse.y / screen.lineHeight);
screen.doubleClicked(Qt.point(character,line));
}
}

View File

@ -8,7 +8,6 @@
#include "text.h"
#include "cursor.h"
#include "mono_text.h"
#include "selection.h"
void register_qml_types()
{
@ -18,5 +17,4 @@ void register_qml_types()
qmlRegisterType<Screen>();
qmlRegisterType<Text>();
qmlRegisterType<Cursor>();
qmlRegisterType<Selection>();
}