Skip to content

Commit

Permalink
Implement a Yat terminal screen as a plugin
Browse files Browse the repository at this point in the history
This should hopfully make it easier for others to use Yat for other
applications. No styling etc is possible, but maybe someone finds a good
way to make it customizable.
  • Loading branch information
jorgen committed Feb 26, 2014
1 parent 305b882 commit 9354b07
Show file tree
Hide file tree
Showing 24 changed files with 175 additions and 135 deletions.
10 changes: 5 additions & 5 deletions README
@@ -1,6 +1,6 @@
YAT is a terminal emulator written in qml and c++
Yat is a qml plugin for the a VT100 emulation screen and an example of how to use this plugin

The main goal of the project was to find out if it was possible to use qml to
write a terminal emulator which performed on par with xterm and konsole.

Turns out, it's possible.
Do
$ qmake && make
in the top level directory. Then you can run the example from the same directory with the command:
$ qmlscene -I imports yat_app/main.qml
2 changes: 1 addition & 1 deletion backend/screen.cpp
Expand Up @@ -321,10 +321,10 @@ void Screen::dispatchChanges()
currentScreenData()->dispatchLineEvents();
emit dispatchTextSegmentChanges();

//be smarter than this
static int max_to_delete_size = 0;
if (max_to_delete_size < m_to_delete.size()) {
max_to_delete_size = m_to_delete.size();
qDebug() << "TO DELETE SIZE :" << max_to_delete_size;
}

if (m_flash) {
Expand Down
Expand Up @@ -23,7 +23,7 @@

import QtQuick 2.0

import org.yat 1.0
import Yat 1.0

ObjectDestructItem {
id: cursor
Expand Down
Expand Up @@ -24,23 +24,29 @@
import QtQuick 2.0
import QtQuick.Controls 1.1

import org.yat 1.0
import Yat 1.0 as Yat

TerminalScreen {
Yat.TerminalScreen {
id: screenItem

property font font
property real fontWidth: fontMetricText.paintedWidth
property real fontHeight: fontMetricText.paintedHeight

property var lineComponent : Qt.createComponent("TerminalLine.qml")
property var textComponent : Qt.createComponent("TerminalText.qml")
property var cursorComponent : Qt.createComponent("TerminalCursor.qml")

font.family: screen.platformName != "cocoa" ? "monospace" : "menlo"
anchors.fill: parent
focus: true

Component {
id: textComponent
Yat.Text {
}
}
Component {
id: cursorComponent
Yat.Cursor {
}
}
Action {
id: copyAction
shortcut: "Ctrl+Shift+C"
Expand Down Expand Up @@ -93,7 +99,7 @@ TerminalScreen {
width: parent.width
height: screen.contentHeight * screenItem.fontHeight

HighlightArea {
Selection {
characterHeight: fontHeight
characterWidth: fontWidth
screenWidth: screenItem.width
Expand Down Expand Up @@ -144,7 +150,7 @@ TerminalScreen {
"font" : screenItem.font,
"fontWidth" : screenItem.fontWidth,
"fontHeight" : screenItem.fontHeight,
})
});
}

onCursorCreated: {
Expand Down Expand Up @@ -183,6 +189,7 @@ TerminalScreen {
onHeightChanged: {
setTerminalHeight();
}

Component.onCompleted: {
setTerminalWidth();
setTerminalHeight();
Expand Down Expand Up @@ -261,7 +268,7 @@ TerminalScreen {
screen.selection.startY = line;
screen.selection.endX = drag_start_x;
screen.selection.endY = drag_start_y;
}else {
} else {
screen.selection.startX = drag_start_x;
screen.selection.startY = drag_start_y;
screen.selection.endX = character;
Expand Down
File renamed without changes.
Expand Up @@ -23,7 +23,7 @@

import QtQuick 2.0

import org.yat 1.0
import Yat 1.0

ObjectDestructItem {
id: textItem
Expand Down Expand Up @@ -55,6 +55,8 @@ ObjectDestructItem {
font.underline: objectHandle.underline
latin: objectHandle.latin

onTextChanged: {
}
SequentialAnimation {
running: objectHandle.blinking
loops: Animation.Infinite
Expand Down
25 changes: 25 additions & 0 deletions imports/Yat/Yat.pro
@@ -0,0 +1,25 @@
QT += core-private gui-private qml-private quick quick-private
TARGET = yat_qml_plugin
TEMPLATE = lib
CONFIG += plugin

include(../../backend/backend.pri)

SOURCES += \
plugin/terminal_screen.cpp \
plugin/object_destruct_item.cpp \
plugin/mono_text.cpp \
plugin/yat_extension_plugin.cpp \

HEADERS += \
plugin/terminal_screen.h \
plugin/object_destruct_item.h \
plugin/mono_text.h \
plugin/yat_extension_plugin.h \

OTHER_FILES = \
Line.qml \
Screen.qml \
Text.qml \
Selection.qml

Expand Up @@ -78,7 +78,7 @@ class MonoSGNode : public QSGTransformNode

deleteContent();
QSGRenderContext *sgr = QQuickItemPrivate::get(m_owner)->sceneGraphRenderContext();
QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr);
QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr, false);
node->setOwnerElement(m_owner);
node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
Expand Down Expand Up @@ -110,7 +110,7 @@ class MonoSGNode : public QSGTransformNode
QList<QGlyphRun> glyphRuns = line.glyphRuns();
qreal xpos = 0;
for (int i = 0; i < glyphRuns.size(); i++) {
QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr);
QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr, false);
node->setOwnerElement(m_owner);
node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -67,7 +67,6 @@ void TerminalScreen::inputMethodEvent(QInputMethodEvent *event)

void TerminalScreen::hangupReceived()
{
qDebug() << "hangup received";
emit aboutToBeDestroyed(this);
deleteLater();
}
File renamed without changes.
68 changes: 68 additions & 0 deletions imports/Yat/plugin/yat_extension_plugin.cpp
@@ -0,0 +1,68 @@
/*******************************************************************************
* Copyright (c) 2014 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
* 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 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.
*
*******************************************************************************/

#include "yat_extension_plugin.h"

#include <QtCore/QByteArray>

#include <QQmlEngine>

#include "terminal_screen.h"
#include "object_destruct_item.h"
#include "screen.h"
#include "text.h"
#include "cursor.h"
#include "mono_text.h"
#include "selection.h"

static const struct {
const char *type;
int major, minor;
} qmldir [] = {
{ "Screen", 1, 0},
{ "Text", 1, 0},
{ "Cursor", 1, 0},
{ "Selection", 1, 0},
};

void YatExtensionPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QByteArrayLiteral("Yat"));
qmlRegisterType<TerminalScreen>("Yat", 1, 0, "TerminalScreen");
qmlRegisterType<ObjectDestructItem>("Yat", 1, 0, "ObjectDestructItem");
qmlRegisterType<MonoText>("Yat", 1, 0, "MonoText");
qmlRegisterType<Screen>();
qmlRegisterType<Text>();
qmlRegisterType<Cursor>();
qmlRegisterType<Selection>();

const QString filesLocation = baseUrl().toString();
for (int i = 0; i < int(sizeof(qmldir)/sizeof(qmldir[0])); i++)
qmlRegisterType(QUrl(filesLocation + "/" + qmldir[i].type + ".qml"), uri, qmldir[i].major, qmldir[i].minor, qmldir[i].type);
}

void YatExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
Q_UNUSED(uri);
Q_UNUSED(engine);
}
38 changes: 38 additions & 0 deletions imports/Yat/plugin/yat_extension_plugin.h
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2014 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
* 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 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 YAT_EXTENSION_PLUGIN
#define YAT_EXTENSION_PLUGIN

#include <QtQml/qqmlextensionplugin.h>

class YatExtensionPlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface/1.0")
public:
void registerTypes(const char *uri);
void initializeEngine(QQmlEngine *engine, const char *uri);
};

#endif
3 changes: 3 additions & 0 deletions imports/Yat/qmldir
@@ -0,0 +1,3 @@
module Yat
plugin yat_qml_plugin
classname YatExtensionPlugin
3 changes: 3 additions & 0 deletions imports/imports.pro
@@ -0,0 +1,3 @@
TEMPLATE=subdirs
SUBDIRS= \
Yat \
2 changes: 1 addition & 1 deletion yat.pro
@@ -1,5 +1,5 @@
TEMPLATE=subdirs
CONFIG += ordered
SUBDIRS= \
yat_declarative \
imports \
tests
Expand Up @@ -25,6 +25,8 @@ import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 1.1

import Yat 1.0 as Yat

Window {
id: terminalWindow

Expand All @@ -40,9 +42,15 @@ Window {
terminalWindow.show();
}

Component {
id: terminalScreenComponent
Yat.Screen {
}
}

function add_terminal()
{
var tab = tabView.addTab("", Qt.createComponent("TerminalScreen.qml"));
var tab = tabView.addTab("", terminalScreenComponent);
tab.active = true;
tab.title = Qt.binding(function() { return tab.item.screen.title; } );
tab.item.aboutToBeDestroyed.connect(destroy_tab);
Expand Down
47 changes: 0 additions & 47 deletions yat_declarative/main.cpp

This file was deleted.

9 changes: 0 additions & 9 deletions yat_declarative/qml_sources.qrc

This file was deleted.

0 comments on commit 9354b07

Please sign in to comment.