1
0
mirror of https://github.com/Swordfish90/cool-retro-term.git synced 2025-02-21 20:39:00 +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 characterWidth: 0
property real characterHeight: 0 property real characterHeight: 0
property int screenWidth: 0 property int screenWidth: width / characterWidth
property int startX property point start
property int startY property point end
property int endX
property int endY
property color color: "grey" property color color: "grey"
y: startY * characterHeight
width: parent.width width: parent.width
height: (endY - startY + 1) * characterHeight height: parent.height
opacity: 0.8 opacity: 0.8
@ -75,29 +71,27 @@ Item {
onCharacterHeightChanged: calculateRectangles(); onCharacterHeightChanged: calculateRectangles();
onScreenWidthChanged: calculateRectangles(); onScreenWidthChanged: calculateRectangles();
onStartXChanged: calculateRectangles(); onStartChanged: calculateRectangles();
onStartYChanged: calculateRectangles(); onEndChanged: calculateRectangles();
onEndXChanged: calculateRectangles();
onEndYChanged: calculateRectangles();
function calculateRectangles() { function calculateRectangles() {
highlightArea.y = startY * characterHeight; highlightArea.y = start.y * characterHeight;
begginning_rectangle.x = startX * characterWidth; begginning_rectangle.x = start.x * characterWidth;
if (startY === endY) { if (start.y === end.y) {
middle_rectangle.visible = false; middle_rectangle.visible = false;
end_rectangle.visible = false end_rectangle.visible = false
begginning_rectangle.width = (endX - startX) * characterWidth; begginning_rectangle.width = (end.x - start.x) * characterWidth;
} else { } else {
begginning_rectangle.width = (screenWidth - startX) * characterWidth; begginning_rectangle.width = (screenWidth - start.x) * characterWidth;
if (startY === endY - 1) { if (start.y === end.y - 1) {
middle_rectangle.height = 0; middle_rectangle.height = 0;
middle_rectangle.visible = false; middle_rectangle.visible = false;
}else { }else {
middle_rectangle.visible = true; 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.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 2.0
import QtQuick.Controls 1.1
import org.yat 1.0 import org.yat 1.0
@ -41,17 +40,6 @@ TerminalScreen {
font.pixelSize: 20 font.pixelSize: 20
focus: true 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: { onActiveFocusChanged: {
if (activeFocus) { if (activeFocus) {
Qt.inputMethod.show(); Qt.inputMethod.show();
@ -78,9 +66,10 @@ TerminalScreen {
anchors.left: parent.left anchors.left: parent.left
contentWidth: width contentWidth: width
contentHeight: textContainer.height contentHeight: textContainer.height
interactive: true interactive: false
flickableDirection: Flickable.VerticalFlick flickableDirection: Flickable.VerticalFlick
contentY: ((screen.contentHeight - screen.height) * screenItem.fontHeight) contentY: ((screen.contentHeight - screen.height) * screenItem.fontHeight)
boundsBehavior: Flickable.StopAtBounds
Item { Item {
id: textContainer id: textContainer
@ -91,22 +80,7 @@ TerminalScreen {
anchors.fill: parent anchors.fill: parent
color: terminal.screen.defaultBackgroundColor 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: { onContentYChanged: {
if (!atYEnd) { if (!atYEnd) {
var top_line = Math.floor(Math.max(contentY,0) / screenItem.fontHeight); var top_line = Math.floor(Math.max(contentY,0) / screenItem.fontHeight);
@ -156,11 +130,13 @@ TerminalScreen {
onRequestHeightChange: { onRequestHeightChange: {
terminalWindow.height = newHeight * screenItem.fontHeight; terminalWindow.height = newHeight * screenItem.fontHeight;
terminalWindow.contentItem.height = newHeight * screenItem.fontHeight; terminalWindow.contentItem.height = newHeight * screenItem.fontHeight;
console.log("banana");
} }
onRequestWidthChange: { onRequestWidthChange: {
terminalWindow.width = newWidth * screenItem.fontWidth; terminalWindow.width = newWidth * screenItem.fontWidth;
terminalWindow.contentItem.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 { Rectangle {
id: flash id: flash
z: 1.2 z: 1.2
@ -222,49 +208,39 @@ TerminalScreen {
MouseArea { MouseArea {
id:mousArea id:mousArea
property int drag_start_x property point drag_start
property int drag_start_y
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.MiddleButton acceptedButtons: Qt.LeftButton | Qt.MiddleButton
onPressed: { onPressed: {
if (mouse.button == Qt.LeftButton) { if (mouse.button == Qt.LeftButton) {
hoverEnabled = true; hoverEnabled = true;
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); var character = Math.floor((mouse.x / screen.charWidth));
var character = Math.floor((transformed_mouse.x / fontWidth)); var line = Math.floor(mouse.y / screen.lineHeight);
var line = Math.floor(transformed_mouse.y / fontHeight);
var start = Qt.point(character,line); var start = Qt.point(character,line);
drag_start_x = character; drag_start = start;
drag_start_y = line; screen.selectionAreaStart = start;
screen.selection.startX = character; screen.selectionAreaEnd = start;
screen.selection.startY = line;
screen.selection.endX = character;
screen.selection.endY = line;
} }
} }
onPositionChanged: { onPositionChanged: {
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); var character = Math.floor(mouse.x / screen.charWidth);
var character = Math.floor(transformed_mouse.x / fontWidth); var line = Math.floor(mouse.y / screen.lineHeight);
var line = Math.floor(transformed_mouse.y / fontHeight);
var current_pos = Qt.point(character,line); var current_pos = Qt.point(character,line);
if (line < drag_start_y || (line === drag_start_y && character < drag_start_x)) { if (line < drag_start.y || (line === drag_start.y && character < drag_start.x)) {
screen.selection.startX = character; screen.selectionAreaStart = current_pos;
screen.selection.startY = line; screen.selectionAreaEnd = drag_start;
screen.selection.endX = drag_start_x;
screen.selection.endY = drag_start_y;
}else { }else {
screen.selection.startX = drag_start_x; screen.selectionAreaEnd = current_pos;
screen.selection.startY = drag_start_y; screen.selectionAreaStart = drag_start;
screen.selection.endX = character;
screen.selection.endY = line;
} }
} }
onReleased: { onReleased: {
if (mouse.button == Qt.LeftButton) { if (mouse.button == Qt.LeftButton) {
hoverEnabled = false; hoverEnabled = false;
screen.selection.sendToSelection(); screen.sendSelectionToSelection();
} }
} }
@ -273,12 +249,10 @@ TerminalScreen {
screen.pasteFromSelection(); screen.pasteFromSelection();
} }
} }
onDoubleClicked: { onDoubleClicked: {
if (mouse.button == Qt.LeftButton) { if (mouse.button == Qt.LeftButton) {
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); var character = Math.floor(mouse.x / screen.charWidth);
var character = Math.floor(transformed_mouse.x / fontWidth); var line = Math.floor(mouse.y / screen.lineHeight);
var line = Math.floor(transformed_mouse.y / fontHeight);
screen.doubleClicked(Qt.point(character,line)); screen.doubleClicked(Qt.point(character,line));
} }
} }

View File

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

View File

@ -30,7 +30,7 @@ import QtQuick.Controls 1.0
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
ApplicationWindow{ ApplicationWindow{
id: mainwindow id: terminalWindow
width: 1024 width: 1024
height: 768 height: 768
@ -48,7 +48,7 @@ ApplicationWindow{
text: qsTr("Settings") text: qsTr("Settings")
onTriggered: { onTriggered: {
var component = Qt.createComponent("SettingsWindow.qml"); 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++ 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 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/cursor.h \
$$PWD/nrc_text_codec.h \ $$PWD/nrc_text_codec.h \
$$PWD/scrollback.h \ $$PWD/scrollback.h \
$$PWD/utf8_decoder.h \ $$PWD/utf8_decoder.h
$$PWD/selection.h
SOURCES += \ SOURCES += \
$$PWD/yat_pty.cpp \ $$PWD/yat_pty.cpp \
@ -36,6 +35,5 @@ SOURCES += \
$$PWD/screen_data.cpp \ $$PWD/screen_data.cpp \
$$PWD/cursor.cpp \ $$PWD/cursor.cpp \
$$PWD/nrc_text_codec.cpp \ $$PWD/nrc_text_codec.cpp \
$$PWD/scrollback.cpp \ $$PWD/scrollback.cpp
$$PWD/selection.cpp

View File

@ -37,7 +37,6 @@ Block::Block(Screen *screen)
: m_screen(screen) : m_screen(screen)
, m_line(0) , m_line(0)
, m_new_line(-1) , m_new_line(-1)
, m_screen_index(0)
, m_width(m_screen->width()) , m_width(m_screen->width())
, m_visible(true) , m_visible(true)
, m_changed(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() QString *Block::textLine()
{ {
return &m_text_line; 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 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 insertAtPos(int i, const QString &text, const TextStyle &style, bool only_latin = true);
void setScreenIndex(int index) { m_screen_index = index; } void setIndex(int index);
int screenIndex() const { return m_screen_index; } int index() const { return m_new_line; }
size_t line() { return m_new_line; }
void setLine(size_t line) {
if (line != m_new_line) {
m_changed = true;
m_new_line = line;
}
}
QString *textLine(); QString *textLine();
int textSize() { return m_text_line.size(); } int textSize() { return m_text_line.size(); }
@ -95,10 +88,8 @@ private:
Screen *m_screen; Screen *m_screen;
QString m_text_line; QString m_text_line;
QVector<TextStyleLine> m_style_list; QVector<TextStyleLine> m_style_list;
size_t m_line; int m_line;
size_t m_new_line; int m_new_line;
int m_screen_index;
int m_width; int m_width;
bool m_visible; bool m_visible;

View File

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

View File

@ -28,7 +28,6 @@
#include "cursor.h" #include "cursor.h"
#include "text.h" #include "text.h"
#include "scrollback.h" #include "scrollback.h"
#include "selection.h"
#include "controll_chars.h" #include "controll_chars.h"
#include "character_sets.h" #include "character_sets.h"
@ -48,11 +47,12 @@ Screen::Screen(QObject *parent)
, m_timer_event_id(0) , m_timer_event_id(0)
, m_width(1) , m_width(1)
, m_height(0) , 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_alternate_data(new ScreenData(0, this))
, m_current_data(m_primary_data) , m_current_data(m_primary_data)
, m_old_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_flash(false)
, m_cursor_changed(false) , m_cursor_changed(false)
, m_application_cursor_key_mode(false) , m_application_cursor_key_mode(false)
@ -64,8 +64,6 @@ Screen::Screen(QObject *parent)
m_new_cursors << cursor; m_new_cursors << cursor;
connect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); 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())); connect(m_palette, SIGNAL(changed()), this, SLOT(paletteChanged()));
setHeight(25); setHeight(25);
@ -156,11 +154,9 @@ void Screen::useAlternateScreenBuffer()
{ {
if (m_current_data == m_primary_data) { if (m_current_data == m_primary_data) {
disconnect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); 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 = m_alternate_data;
m_current_data->clear(); m_current_data->clear();
connect(m_alternate_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); connect(m_alternate_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged()));
connect(m_primary_data, &ScreenData::contentModified, this, &Screen::contentModified);
emit contentHeightChanged(); emit contentHeightChanged();
} }
} }
@ -169,10 +165,8 @@ void Screen::useNormalScreenBuffer()
{ {
if (m_current_data == m_alternate_data) { if (m_current_data == m_alternate_data) {
disconnect(m_alternate_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); disconnect(m_alternate_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged()));
disconnect(m_alternate_data, &ScreenData::contentModified, this, &Screen::contentModified);
m_current_data = m_primary_data; m_current_data = m_primary_data;
connect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged())); connect(m_primary_data, SIGNAL(contentHeightChanged()), this, SIGNAL(contentHeightChanged()));
connect(m_alternate_data, &ScreenData::contentModified, this, &Screen::contentModified);
emit contentHeightChanged(); emit contentHeightChanged();
} }
} }
@ -235,9 +229,65 @@ bool Screen::fastScroll() const
return m_fast_scroll; 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) void Screen::doubleClicked(const QPointF &clicked)
@ -319,7 +369,15 @@ void Screen::dispatchChanges()
m_cursor_stack[i]->dispatchEvents(); 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() 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 *) void Screen::timerEvent(QTimerEvent *)

View File

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

View File

@ -167,7 +167,7 @@ void ScreenData::deleteCharacters(const QPoint &point, int to)
if (it == m_screen_blocks.end()) if (it == m_screen_blocks.end())
return; 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; int chars_to_line = line_in_block * m_width;
(*it)->deleteCharacters(chars_to_line + point.x(), chars_to_line + to); (*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) if (from == to)
return; return;
const size_t old_content_height = contentHeight();
const int orig_to = to;
if (to > from) if (to > from)
to++; to++;
auto from_it = it_for_row_ensure_single_line_block(from); 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(); (*from_it)->clear();
m_screen_blocks.splice(to_it, m_screen_blocks, from_it); 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) void ScreenData::insertLine(int row, int topMargin)
{ {
auto row_it = it_for_row(row + 1); auto row_it = it_for_row(row + 1);
const size_t old_content_height = contentHeight(); if (!topMargin && m_height - m_screen_blocks.front()->lineCount() >= m_screen_height) {
if (!topMargin && m_height >= m_screen_height) {
push_at_most_to_scrollback(1); push_at_most_to_scrollback(1);
} else { } else {
auto row_top_margin = it_for_row_ensure_single_line_block(topMargin); 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_screen_blocks.insert(row_it,block_to_insert);
m_height++; m_height++;
m_block_count++; 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) if (!m_block_count)
return; return;
const int scrollback_height = m_scrollback->height(); const int content_height = contentHeight();
int i = 0; int i = 0;
for (auto it = m_screen_blocks.begin(); it != m_screen_blocks.end(); ++it) { for (auto it = m_screen_blocks.begin(); it != m_screen_blocks.end(); ++it) {
int line = scrollback_height + i; int line = content_height - m_height + i;
(*it)->setLine(line); (*it)->setIndex(line);
//(*it)->setScreenIndex(i);
(*it)->dispatchEvents(); (*it)->dispatchEvents();
i+= (*it)->lineCount(); i+= (*it)->lineCount();
} }
if (contentHeight() != m_old_total_lines) { if (content_height != m_old_total_lines) {
m_old_total_lines = contentHeight(); m_old_total_lines = contentHeight();
emit contentHeightChanged(); emit contentHeightChanged();
} }
@ -298,66 +289,14 @@ Scrollback *ScreenData::scrollback() const
return m_scrollback; 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) CursorDiff ScreenData::modify(const QPoint &point, const QString &text, const TextStyle &style, bool replace, bool only_latin)
{ {
auto it = it_for_row(point.y()); auto it = it_for_row(point.y());
Block *block = *it; Block *block = *it;
const int start_char = (point.y() - block->screenIndex()) * m_width + point.x(); int start_char = (point.y() - block->index()) * m_width + point.x();
const size_t lines_before = block->lineCount(); size_t lines_before = block->lineCount();
const int lines_changed = int lines_changed =
block->lineCountAfterModified(start_char, text.size(), replace) - lines_before; block->lineCountAfterModified(start_char, text.size(), replace) - lines_before;
const size_t old_content_height = contentHeight();
m_height += lines_changed; m_height += lines_changed;
if (lines_changed > 0) { if (lines_changed > 0) {
int removed = 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; int end_char = (start_char + text.size()) % m_width;
if (end_char == 0) if (end_char == 0)
end_char = m_width -1; 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()}; 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) std::list<Block *>::iterator ScreenData::it_for_row_ensure_single_line_block(int row)
{ {
auto it = it_for_row(row); auto it = it_for_row(row);
const int index = (*it)->screenIndex(); int index = (*it)->index();
const int lines = (*it)->lineCount(); int lines = (*it)->lineCount();
if (index == row && lines == 1) { if (index == row && lines == 1) {
return it; return it;
@ -434,12 +371,12 @@ std::list<Block *>::iterator ScreenData::split_out_row_from_block(std::list<Bloc
if (row_in_block == 0) { if (row_in_block == 0) {
auto insert_before = (*it)->takeLine(0); auto insert_before = (*it)->takeLine(0);
insert_before->setScreenIndex(row_in_block); insert_before->setIndex(row_in_block);
m_block_count++; m_block_count++;
return m_screen_blocks.insert(it,insert_before); return m_screen_blocks.insert(it,insert_before);
} else if (row_in_block == lines -1) { } else if (row_in_block == lines -1) {
auto insert_after = (*it)->takeLine(lines -1); auto insert_after = (*it)->takeLine(lines -1);
insert_after->setScreenIndex(row_in_block); insert_after->setIndex(row_in_block);
++it; ++it;
m_block_count++; m_block_count++;
return m_screen_blocks.insert(it, insert_after); 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; 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 <QtCore/QObject>
#include <QtGui/QClipboard> #include <QtGui/QClipboard>
#include <QtCore/QDebug>
class Screen; class Screen;
class Scrollback; class Scrollback;
@ -82,8 +81,6 @@ public:
Scrollback *scrollback() const; Scrollback *scrollback() const;
void sendSelectionToClipboard(const QPoint &start, const QPoint &end, QClipboard::Mode mode);
inline std::list<Block *>::iterator it_for_row(int row); inline std::list<Block *>::iterator it_for_row(int row);
public slots: public slots:
void setHeight(int height, int currentCursorLine, int currentContentHeight); void setHeight(int height, int currentCursorLine, int currentContentHeight);
@ -91,7 +88,6 @@ public slots:
signals: signals:
void contentHeightChanged(); void contentHeightChanged();
void contentModified(size_t lineModified, int lineDiff, int contentDiff);
private: private:
CursorDiff modify(const QPoint &pos, const QString &text, const TextStyle &style, bool replace, bool only_latin); 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 reclaim_at_least(int lines);
void remove_lines_from_end(int lines); void remove_lines_from_end(int lines);
void ensure_at_least_height(int height); void ensure_at_least_height(int height);
int content_height_diff(size_t old_content_height);
Screen *m_screen; Screen *m_screen;
Scrollback *m_scrollback; Scrollback *m_scrollback;
int m_screen_height; int m_screen_height;
@ -116,21 +111,20 @@ private:
std::list<Block *>::iterator ScreenData::it_for_row(int row) 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(); auto it = m_screen_blocks.end();
int line_for_block = m_screen_height; int line_for_block = m_screen_height;
size_t abs_line = contentHeight();
while (it != m_screen_blocks.begin()) { while (it != m_screen_blocks.begin()) {
--it; --it;
int end_line = line_for_block - 1;
line_for_block -= (*it)->lineCount(); line_for_block -= (*it)->lineCount();
abs_line -= (*it)->lineCount(); if (line_for_block <= row && end_line >= row) {
if (line_for_block <= row) { (*it)->setIndex(line_for_block);
(*it)->setScreenIndex(line_for_block);
(*it)->setLine(abs_line);
return it; return it;
} }
if (end_line < row) {
break;
}
} }
return m_screen_blocks.end(); 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) void Scrollback::addBlock(Block *block)
{ {
if (!m_max_size) {
delete block;
return;
}
m_blocks.push_back(block); m_blocks.push_back(block);
block->releaseTextObjects(); block->releaseTextObjects();
m_block_count++; m_block_count++;
m_height += m_blocks.back()->lineCount(); m_height += m_blocks.back()->lineCount();
if (!m_max_size || m_height == m_max_size - 1) {
while (m_height - m_blocks.front()->lineCount() >= m_max_size) {
m_block_count--; m_block_count--;
m_height -= m_blocks.front()->lineCount(); m_height -= m_blocks.front()->lineCount();
delete m_blocks.front(); delete m_blocks.front();
m_blocks.pop_front(); m_blocks.pop_front();
m_adjust_visible_pages++; m_adjust_visible_pages++;
} }
m_visible_pages.clear(); m_visible_pages.clear();
} }
@ -135,7 +128,7 @@ void Scrollback::ensurePageVisible(Page &page, int new_height)
auto it = page.it; auto it = page.it;
std::advance(it, page.size); std::advance(it, page.size);
for (int i = page.size; i < new_height; ++it, i++) { for (int i = page.size; i < new_height; ++it, i++) {
(*it)->setLine(line_no + i); (*it)->setIndex(line_no + i);
(*it)->dispatchEvents(); (*it)->dispatchEvents();
} }
page.size = new_height; page.size = new_height;
@ -206,10 +199,3 @@ void Scrollback::setWidth(int width)
{ {
m_width = 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 <list>
#include <QtCore/qglobal.h> #include <QtCore/qglobal.h>
#include <QtCore/QPoint>
class ScreenData; class ScreenData;
class Block; class Block;
@ -52,8 +51,6 @@ public:
void setWidth(int width); void setWidth(int width);
size_t blockCount() { return m_block_count; } size_t blockCount() { return m_block_count; }
QString selection(const QPoint &start, const QPoint &end) const;
private: private:
void ensurePageVisible(Page &page, int new_height); void ensurePageVisible(Page &page, int new_height);
void ensurePageNotVisible(Page &page); void ensurePageNotVisible(Page &page);

View File

@ -28,19 +28,15 @@ Item {
property real characterWidth: 0 property real characterWidth: 0
property real characterHeight: 0 property real characterHeight: 0
property int screenWidth: 0 property int screenWidth: width / characterWidth
property int startX property point start
property int startY property point end
property int endX
property int endY
property color color: "grey" property color color: "grey"
y: startY * characterHeight
width: parent.width width: parent.width
height: (endY - startY + 1) * characterHeight height: parent.height
opacity: 0.8 opacity: 0.8
@ -75,29 +71,27 @@ Item {
onCharacterHeightChanged: calculateRectangles(); onCharacterHeightChanged: calculateRectangles();
onScreenWidthChanged: calculateRectangles(); onScreenWidthChanged: calculateRectangles();
onStartXChanged: calculateRectangles(); onStartChanged: calculateRectangles();
onStartYChanged: calculateRectangles(); onEndChanged: calculateRectangles();
onEndXChanged: calculateRectangles();
onEndYChanged: calculateRectangles();
function calculateRectangles() { function calculateRectangles() {
highlightArea.y = startY * characterHeight; highlightArea.y = start.y * characterHeight;
begginning_rectangle.x = startX * characterWidth; begginning_rectangle.x = start.x * characterWidth;
if (startY === endY) { if (start.y === end.y) {
middle_rectangle.visible = false; middle_rectangle.visible = false;
end_rectangle.visible = false end_rectangle.visible = false
begginning_rectangle.width = (endX - startX) * characterWidth; begginning_rectangle.width = (end.x - start.x) * characterWidth;
} else { } else {
begginning_rectangle.width = (screenWidth - startX) * characterWidth; begginning_rectangle.width = (screenWidth - start.x) * characterWidth;
if (startY === endY - 1) { if (start.y === end.y - 1) {
middle_rectangle.height = 0; middle_rectangle.height = 0;
middle_rectangle.visible = false; middle_rectangle.visible = false;
}else { }else {
middle_rectangle.visible = true; 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.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 2.0
import QtQuick.Controls 1.1
import org.yat 1.0 import org.yat 1.0
@ -40,17 +39,6 @@ TerminalScreen {
font.family: "menlo" font.family: "menlo"
focus: true 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: { onActiveFocusChanged: {
if (activeFocus) { if (activeFocus) {
Qt.inputMethod.show(); Qt.inputMethod.show();
@ -90,22 +78,7 @@ TerminalScreen {
anchors.fill: parent anchors.fill: parent
color: terminal.screen.defaultBackgroundColor 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: { onContentYChanged: {
if (!atYEnd) { if (!atYEnd) {
var top_line = Math.floor(Math.max(contentY,0) / screenItem.fontHeight); 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 { Rectangle {
id: flash id: flash
z: 1.2 z: 1.2
@ -221,49 +204,39 @@ TerminalScreen {
MouseArea { MouseArea {
id:mousArea id:mousArea
property int drag_start_x property point drag_start
property int drag_start_y
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.MiddleButton acceptedButtons: Qt.LeftButton | Qt.MiddleButton
onPressed: { onPressed: {
if (mouse.button == Qt.LeftButton) { if (mouse.button == Qt.LeftButton) {
hoverEnabled = true; hoverEnabled = true;
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); var character = Math.floor((mouse.x / screen.charWidth));
var character = Math.floor((transformed_mouse.x / fontWidth)); var line = Math.floor(mouse.y / screen.lineHeight);
var line = Math.floor(transformed_mouse.y / fontHeight);
var start = Qt.point(character,line); var start = Qt.point(character,line);
drag_start_x = character; drag_start = start;
drag_start_y = line; screen.selectionAreaStart = start;
screen.selection.startX = character; screen.selectionAreaEnd = start;
screen.selection.startY = line;
screen.selection.endX = character;
screen.selection.endY = line;
} }
} }
onPositionChanged: { onPositionChanged: {
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); var character = Math.floor(mouse.x / screen.charWidth);
var character = Math.floor(transformed_mouse.x / fontWidth); var line = Math.floor(mouse.y / screen.lineHeight);
var line = Math.floor(transformed_mouse.y / fontHeight);
var current_pos = Qt.point(character,line); var current_pos = Qt.point(character,line);
if (line < drag_start_y || (line === drag_start_y && character < drag_start_x)) { if (line < drag_start.y || (line === drag_start.y && character < drag_start.x)) {
screen.selection.startX = character; screen.selectionAreaStart = current_pos;
screen.selection.startY = line; screen.selectionAreaEnd = drag_start;
screen.selection.endX = drag_start_x;
screen.selection.endY = drag_start_y;
}else { }else {
screen.selection.startX = drag_start_x; screen.selectionAreaEnd = current_pos;
screen.selection.startY = drag_start_y; screen.selectionAreaStart = drag_start;
screen.selection.endX = character;
screen.selection.endY = line;
} }
} }
onReleased: { onReleased: {
if (mouse.button == Qt.LeftButton) { if (mouse.button == Qt.LeftButton) {
hoverEnabled = false; hoverEnabled = false;
screen.selection.sendToSelection(); screen.sendSelectionToSelection();
} }
} }
@ -272,12 +245,10 @@ TerminalScreen {
screen.pasteFromSelection(); screen.pasteFromSelection();
} }
} }
onDoubleClicked: { onDoubleClicked: {
if (mouse.button == Qt.LeftButton) { if (mouse.button == Qt.LeftButton) {
var transformed_mouse = mapToItem(textContainer, mouse.x, mouse.y); var character = Math.floor(mouse.x / screen.charWidth);
var character = Math.floor(transformed_mouse.x / fontWidth); var line = Math.floor(mouse.y / screen.lineHeight);
var line = Math.floor(transformed_mouse.y / fontHeight);
screen.doubleClicked(Qt.point(character,line)); screen.doubleClicked(Qt.point(character,line));
} }
} }

View File

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