Moved to new version of yat. Yat is no longer a submodule but is now integrated.
This commit is contained in:
46
yat/yat_declarative/main.cpp
Normal file
46
yat/yat_declarative/main.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
/**************************************************************************************************
|
||||
* 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
|
||||
* 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 <QtGui/QGuiApplication>
|
||||
#include <QtCore/QResource>
|
||||
#include <QtCore/QThread>
|
||||
|
||||
#include <QQmlEngine>
|
||||
|
||||
#include "register_qml_types.h"
|
||||
#include "terminal_screen.h"
|
||||
#include "yat_pty.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
register_qml_types();
|
||||
|
||||
QQmlEngine engine;
|
||||
QQmlComponent component(&engine, QUrl("qrc:/qml/yat_declarative/main.qml"));
|
||||
auto errors = component.errors();
|
||||
for (int i = 0; i < errors.size(); i++) {
|
||||
qDebug() << errors.at(i).toString();
|
||||
}
|
||||
component.create();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
249
yat/yat_declarative/mono_text.cpp
Normal file
249
yat/yat_declarative/mono_text.cpp
Normal file
@@ -0,0 +1,249 @@
|
||||
/******************************************************************************
|
||||
* 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
|
||||
* 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 "mono_text.h"
|
||||
|
||||
#include <QtQuick/private/qsgadaptationlayer_p.h>
|
||||
#include <QtQuick/private/qsgrenderer_p.h>
|
||||
#include <QtQuick/private/qquickitem_p.h>
|
||||
#include <QtQuick/private/qquicktextnode_p.h>
|
||||
#include <QtGui/QTextLayout>
|
||||
|
||||
class MonoSGNode : public QSGTransformNode
|
||||
{
|
||||
public:
|
||||
MonoSGNode(QQuickItem *owner)
|
||||
: m_owner(owner)
|
||||
{
|
||||
}
|
||||
|
||||
void deleteContent()
|
||||
{
|
||||
QSGNode *subnode = firstChild();
|
||||
while (subnode) {
|
||||
// We can't delete the node now as it might be in the preprocess list
|
||||
// It will be deleted in the next preprocess
|
||||
m_nodes_to_delete.append(subnode);
|
||||
subnode = subnode->nextSibling();
|
||||
}
|
||||
removeAllChildNodes();
|
||||
}
|
||||
|
||||
void preprocess()
|
||||
{
|
||||
while (m_nodes_to_delete.count())
|
||||
delete m_nodes_to_delete.takeLast();
|
||||
}
|
||||
|
||||
void setLatinText(const QString &text, const QFont &font, const QColor &color) {
|
||||
QRawFont raw_font = QRawFont::fromFont(font, QFontDatabase::Latin);
|
||||
|
||||
if (raw_font != m_raw_font) {
|
||||
m_raw_font = raw_font;
|
||||
m_positions.clear();
|
||||
}
|
||||
|
||||
if (m_positions.size() < text.size()) {
|
||||
qreal x_pos = 0;
|
||||
qreal max_char_width = raw_font.averageCharWidth();
|
||||
qreal ascent = raw_font.ascent();
|
||||
if (m_positions.size())
|
||||
x_pos = m_positions.last().x() + max_char_width;
|
||||
int to_add = text.size() - m_positions.size();
|
||||
for (int i = 0; i < to_add; i++) {
|
||||
m_positions << QPointF(x_pos, ascent);
|
||||
x_pos += max_char_width;
|
||||
}
|
||||
}
|
||||
|
||||
deleteContent();
|
||||
QSGRenderContext *sgr = QQuickItemPrivate::get(m_owner)->sceneGraphRenderContext();
|
||||
QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr);
|
||||
node->setOwnerElement(m_owner);
|
||||
node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
|
||||
node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
|
||||
node->setStyle(QQuickText::Normal);
|
||||
|
||||
node->setColor(color);
|
||||
QGlyphRun glyphrun;
|
||||
glyphrun.setRawFont(raw_font);
|
||||
glyphrun.setGlyphIndexes(raw_font.glyphIndexesForString(text));
|
||||
|
||||
glyphrun.setPositions(m_positions);
|
||||
node->setGlyphs(QPointF(0, raw_font.ascent()), glyphrun);
|
||||
node->update();
|
||||
appendChildNode(node);
|
||||
}
|
||||
|
||||
void setUnicodeText(const QString &text, const QFont &font, const QColor &color)
|
||||
{
|
||||
deleteContent();
|
||||
QRawFont raw_font = QRawFont::fromFont(font, QFontDatabase::Latin);
|
||||
qreal line_width = raw_font.averageCharWidth() * text.size();
|
||||
QSGRenderContext *sgr = QQuickItemPrivate::get(m_owner)->sceneGraphRenderContext();
|
||||
QTextLayout layout(text,font);
|
||||
layout.beginLayout();
|
||||
QTextLine line = layout.createLine();
|
||||
line.setLineWidth(line_width);
|
||||
//Q_ASSERT(!layout.createLine().isValid());
|
||||
layout.endLayout();
|
||||
QList<QGlyphRun> glyphRuns = line.glyphRuns();
|
||||
qreal xpos = 0;
|
||||
for (int i = 0; i < glyphRuns.size(); i++) {
|
||||
QSGGlyphNode *node = sgr->sceneGraphContext()->createGlyphNode(sgr);
|
||||
node->setOwnerElement(m_owner);
|
||||
node->geometry()->setIndexDataPattern(QSGGeometry::StaticPattern);
|
||||
node->geometry()->setVertexDataPattern(QSGGeometry::StaticPattern);
|
||||
node->setGlyphs(QPointF(xpos, raw_font.ascent()), glyphRuns.at(i));
|
||||
node->setStyle(QQuickText::Normal);
|
||||
node->setColor(color);
|
||||
xpos += raw_font.averageCharWidth() * glyphRuns.at(i).positions().size();
|
||||
node->update();
|
||||
appendChildNode(node);
|
||||
}
|
||||
}
|
||||
private:
|
||||
QQuickItem *m_owner;
|
||||
QVector<QPointF> m_positions;
|
||||
QLinkedList<QSGNode *> m_nodes_to_delete;
|
||||
QRawFont m_raw_font;
|
||||
};
|
||||
|
||||
MonoText::MonoText(QQuickItem *parent)
|
||||
: QQuickItem(parent)
|
||||
, m_color_changed(false)
|
||||
, m_latin(true)
|
||||
, m_old_latin(true)
|
||||
{
|
||||
setFlag(ItemHasContents, true);
|
||||
}
|
||||
|
||||
MonoText::~MonoText()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString MonoText::text() const
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
void MonoText::setText(const QString &text)
|
||||
{
|
||||
if (m_text != text) {
|
||||
m_text = text;
|
||||
emit textChanged();
|
||||
polish();
|
||||
}
|
||||
}
|
||||
|
||||
QFont MonoText::font() const
|
||||
{
|
||||
return m_font;
|
||||
}
|
||||
|
||||
void MonoText::setFont(const QFont &font)
|
||||
{
|
||||
if (font != m_font) {
|
||||
m_font = font;
|
||||
emit fontChanged();
|
||||
polish();
|
||||
}
|
||||
}
|
||||
|
||||
QColor MonoText::color() const
|
||||
{
|
||||
return m_color;
|
||||
}
|
||||
|
||||
void MonoText::setColor(const QColor &color)
|
||||
{
|
||||
if (m_color != color) {
|
||||
m_color = color;
|
||||
emit colorChanged();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
qreal MonoText::paintedWidth() const
|
||||
{
|
||||
return implicitWidth();
|
||||
}
|
||||
|
||||
qreal MonoText::paintedHeight() const
|
||||
{
|
||||
return implicitHeight();
|
||||
}
|
||||
|
||||
bool MonoText::latin() const
|
||||
{
|
||||
return m_latin;
|
||||
}
|
||||
|
||||
void MonoText::setLatin(bool latin)
|
||||
{
|
||||
if (latin == m_latin)
|
||||
return;
|
||||
|
||||
m_latin = latin;
|
||||
emit latinChanged();
|
||||
}
|
||||
|
||||
QSGNode *MonoText::updatePaintNode(QSGNode *old, UpdatePaintNodeData *)
|
||||
{
|
||||
if (m_text.size() == 0 || m_text.trimmed().size() == 0) {
|
||||
delete old;
|
||||
return 0;
|
||||
}
|
||||
MonoSGNode *node = static_cast<MonoSGNode *>(old);
|
||||
if (!node) {
|
||||
node = new MonoSGNode(this);
|
||||
}
|
||||
|
||||
if (m_latin) {
|
||||
node->setLatinText(m_text, m_font, m_color);
|
||||
} else {
|
||||
node->setUnicodeText(m_text, m_font, m_color);
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void MonoText::updatePolish()
|
||||
{
|
||||
QRawFont raw_font = QRawFont::fromFont(m_font, QFontDatabase::Latin);
|
||||
|
||||
qreal height = raw_font.descent() + raw_font.ascent() + raw_font.lineThickness();
|
||||
qreal width = raw_font.averageCharWidth() * m_text.size();
|
||||
|
||||
bool emit_text_width_changed = width != implicitWidth();
|
||||
bool emit_text_height_changed = height != implicitHeight();
|
||||
setImplicitSize(width, height);
|
||||
|
||||
if (emit_text_width_changed)
|
||||
emit paintedWidthChanged();
|
||||
if (emit_text_height_changed)
|
||||
emit paintedHeightChanged();
|
||||
|
||||
update();
|
||||
}
|
||||
81
yat/yat_declarative/mono_text.h
Normal file
81
yat/yat_declarative/mono_text.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/******************************************************************************
|
||||
* 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
|
||||
* 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 MONO_TEXT_H
|
||||
#define MONO_TEXT_H
|
||||
|
||||
#include <QtQuick/QQuickItem>
|
||||
#include <QtGui/QRawFont>
|
||||
|
||||
class MonoText : public QQuickItem
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
||||
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
|
||||
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
|
||||
Q_PROPERTY(qreal paintedWidth READ paintedWidth NOTIFY paintedWidthChanged)
|
||||
Q_PROPERTY(qreal paintedHeight READ paintedHeight NOTIFY paintedHeightChanged)
|
||||
Q_PROPERTY(bool latin READ latin WRITE setLatin NOTIFY latinChanged);
|
||||
public:
|
||||
MonoText(QQuickItem *parent=0);
|
||||
~MonoText();
|
||||
|
||||
QString text() const;
|
||||
void setText(const QString &text);
|
||||
|
||||
QFont font() const;
|
||||
void setFont(const QFont &font);
|
||||
|
||||
QColor color() const;
|
||||
void setColor(const QColor &color);
|
||||
|
||||
qreal paintedWidth() const;
|
||||
qreal paintedHeight() const;
|
||||
|
||||
bool latin() const;
|
||||
void setLatin(bool latin);
|
||||
|
||||
signals:
|
||||
void textChanged();
|
||||
void fontChanged();
|
||||
void colorChanged();
|
||||
void paintedWidthChanged();
|
||||
void paintedHeightChanged();
|
||||
void latinChanged();
|
||||
protected:
|
||||
QSGNode *updatePaintNode(QSGNode *old, UpdatePaintNodeData *data) Q_DECL_OVERRIDE;
|
||||
void updatePolish() Q_DECL_OVERRIDE;
|
||||
private:
|
||||
Q_DISABLE_COPY(MonoText);
|
||||
void updateSize();
|
||||
|
||||
QString m_text;
|
||||
QFont m_font;
|
||||
QColor m_color;
|
||||
bool m_color_changed;
|
||||
bool m_latin;
|
||||
bool m_old_latin;
|
||||
QSizeF m_text_size;
|
||||
};
|
||||
|
||||
#endif
|
||||
55
yat/yat_declarative/object_destruct_item.cpp
Normal file
55
yat/yat_declarative/object_destruct_item.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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 "object_destruct_item.h"
|
||||
|
||||
ObjectDestructItem::ObjectDestructItem(QQuickItem *parent)
|
||||
: QQuickItem(parent)
|
||||
, m_object(0)
|
||||
{
|
||||
}
|
||||
|
||||
QObject *ObjectDestructItem::objectHandle() const
|
||||
{
|
||||
return m_object;
|
||||
}
|
||||
|
||||
void ObjectDestructItem::setObjectHandle(QObject *object)
|
||||
{
|
||||
bool emit_changed = m_object != object;
|
||||
if (m_object) {
|
||||
m_object->disconnect(this);
|
||||
}
|
||||
|
||||
m_object = object;
|
||||
connect(m_object, SIGNAL(destroyed()), this, SLOT(objectDestroyed()));
|
||||
|
||||
if (emit_changed)
|
||||
emit objectHandleChanged();
|
||||
}
|
||||
|
||||
void ObjectDestructItem::objectDestroyed()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
52
yat/yat_declarative/object_destruct_item.h
Normal file
52
yat/yat_declarative/object_destruct_item.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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 OBJECT_DESTRUCT_ITEM_H
|
||||
#define OBJECT_DESTRUCT_ITEM_H
|
||||
|
||||
#include <QtQuick/QQuickItem>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
class ObjectDestructItem : public QQuickItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QObject *objectHandle READ objectHandle WRITE setObjectHandle NOTIFY objectHandleChanged)
|
||||
|
||||
public:
|
||||
ObjectDestructItem(QQuickItem *parent = 0);
|
||||
|
||||
QObject *objectHandle() const;
|
||||
void setObjectHandle(QObject *line);
|
||||
|
||||
signals:
|
||||
void objectHandleChanged();
|
||||
|
||||
private slots:
|
||||
void objectDestroyed();
|
||||
|
||||
private:
|
||||
QObject *m_object;
|
||||
};
|
||||
|
||||
#endif //OBJECT_DESTRUCT_ITEM_H
|
||||
104
yat/yat_declarative/qml/yat_declarative/HighlightArea.qml
Normal file
104
yat/yat_declarative/qml/yat_declarative/HighlightArea.qml
Normal file
@@ -0,0 +1,104 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
|
||||
Item {
|
||||
id: highlightArea
|
||||
|
||||
property real characterWidth: 0
|
||||
property real characterHeight: 0
|
||||
property int screenWidth: 0
|
||||
|
||||
property int startX
|
||||
property int startY
|
||||
|
||||
property int endX
|
||||
property int endY
|
||||
|
||||
property color color: "grey"
|
||||
|
||||
y: startY * characterHeight
|
||||
width: parent.width
|
||||
height: (endY - startY + 1) * characterHeight
|
||||
|
||||
opacity: 0.8
|
||||
|
||||
Rectangle {
|
||||
id: begginning_rectangle
|
||||
color: parent.color
|
||||
opacity: parent.opacity
|
||||
y:0
|
||||
height: characterHeight
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: middle_rectangle
|
||||
color: parent.color
|
||||
opacity: parent.opacity
|
||||
width: parent.width
|
||||
x: 0
|
||||
anchors.top: begginning_rectangle.bottom
|
||||
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: end_rectangle
|
||||
color: parent.color
|
||||
opacity: parent.opacity
|
||||
x: 0
|
||||
height: characterHeight
|
||||
anchors.top: middle_rectangle.bottom
|
||||
}
|
||||
|
||||
onCharacterWidthChanged: calculateRectangles();
|
||||
onCharacterHeightChanged: calculateRectangles();
|
||||
onScreenWidthChanged: calculateRectangles();
|
||||
|
||||
onStartXChanged: calculateRectangles();
|
||||
onStartYChanged: calculateRectangles();
|
||||
onEndXChanged: calculateRectangles();
|
||||
onEndYChanged: calculateRectangles();
|
||||
|
||||
function calculateRectangles() {
|
||||
highlightArea.y = startY * characterHeight;
|
||||
begginning_rectangle.x = startX * characterWidth;
|
||||
if (startY === endY) {
|
||||
middle_rectangle.visible = false;
|
||||
end_rectangle.visible = false
|
||||
begginning_rectangle.width = (endX - startX) * characterWidth;
|
||||
} else {
|
||||
begginning_rectangle.width = (screenWidth - startX) * characterWidth;
|
||||
if (startY === endY - 1) {
|
||||
middle_rectangle.height = 0;
|
||||
middle_rectangle.visible = false;
|
||||
}else {
|
||||
middle_rectangle.visible = true;
|
||||
middle_rectangle.height = (endY - startY - 1) * characterHeight;
|
||||
}
|
||||
end_rectangle.visible = true;
|
||||
end_rectangle.width = endX * characterWidth;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
66
yat/yat_declarative/qml/yat_declarative/TerminalCursor.qml
Normal file
66
yat/yat_declarative/qml/yat_declarative/TerminalCursor.qml
Normal file
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
|
||||
import org.yat 1.0
|
||||
|
||||
ObjectDestructItem {
|
||||
id: cursor
|
||||
|
||||
property real fontHeight
|
||||
property real fontWidth
|
||||
|
||||
height: fontHeight
|
||||
width: fontWidth
|
||||
x: objectHandle.x * fontWidth
|
||||
y: objectHandle.y * fontHeight
|
||||
z: 1.1
|
||||
|
||||
visible: objectHandle.visible
|
||||
|
||||
ShaderEffect {
|
||||
anchors.fill: parent
|
||||
|
||||
property variant source: fragmentSource
|
||||
|
||||
fragmentShader:
|
||||
"uniform lowp float qt_Opacity;" +
|
||||
"uniform sampler2D source;" +
|
||||
"varying highp vec2 qt_TexCoord0;" +
|
||||
|
||||
"void main() {" +
|
||||
" lowp vec4 color = texture2D(source, qt_TexCoord0 ) * qt_Opacity;" +
|
||||
" gl_FragColor = vec4(1.0 - color.r, 1.0 - color.g, 1.0 - color.b, color.a);" +
|
||||
"}"
|
||||
|
||||
ShaderEffectSource {
|
||||
id: fragmentSource
|
||||
sourceItem: background
|
||||
live: true
|
||||
|
||||
sourceRect: Qt.rect(cursor.x,cursor.y,cursor.width,cursor.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
285
yat/yat_declarative/qml/yat_declarative/TerminalScreen.qml
Normal file
285
yat/yat_declarative/qml/yat_declarative/TerminalScreen.qml
Normal file
@@ -0,0 +1,285 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.1
|
||||
|
||||
import org.yat 1.0
|
||||
|
||||
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: "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();
|
||||
}
|
||||
}
|
||||
|
||||
Keys.onPressed: {
|
||||
if (event.text === "?") {
|
||||
terminal.screen.printScreen()
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: fontMetricText
|
||||
text: "B"
|
||||
font: parent.font
|
||||
visible: false
|
||||
textFormat: Text.PlainText
|
||||
}
|
||||
|
||||
Flickable {
|
||||
id: flickable
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
contentWidth: width
|
||||
contentHeight: textContainer.height
|
||||
interactive: true
|
||||
flickableDirection: Flickable.VerticalFlick
|
||||
contentY: ((screen.contentHeight - screen.height) * screenItem.fontHeight)
|
||||
|
||||
Item {
|
||||
id: textContainer
|
||||
width: parent.width
|
||||
height: screen.contentHeight * screenItem.fontHeight
|
||||
Rectangle {
|
||||
id: background
|
||||
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);
|
||||
screen.ensureVisiblePages(top_line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
id: connections
|
||||
|
||||
target: terminal.screen
|
||||
|
||||
onFlash: {
|
||||
flashAnimation.start()
|
||||
}
|
||||
|
||||
onReset: {
|
||||
resetScreenItems();
|
||||
}
|
||||
|
||||
onTextCreated: {
|
||||
var textSegment = textComponent.createObject(screenItem,
|
||||
{
|
||||
"parent" : background,
|
||||
"objectHandle" : text,
|
||||
"font" : screenItem.font,
|
||||
"fontWidth" : screenItem.fontWidth,
|
||||
"fontHeight" : screenItem.fontHeight,
|
||||
})
|
||||
}
|
||||
|
||||
onCursorCreated: {
|
||||
if (cursorComponent.status != Component.Ready) {
|
||||
console.log(cursorComponent.errorString());
|
||||
return;
|
||||
}
|
||||
var cursorVariable = cursorComponent.createObject(screenItem,
|
||||
{
|
||||
"parent" : textContainer,
|
||||
"objectHandle" : cursor,
|
||||
"fontWidth" : screenItem.fontWidth,
|
||||
"fontHeight" : screenItem.fontHeight,
|
||||
})
|
||||
}
|
||||
|
||||
onRequestHeightChange: {
|
||||
terminalWindow.height = newHeight * screenItem.fontHeight;
|
||||
terminalWindow.contentItem.height = newHeight * screenItem.fontHeight;
|
||||
}
|
||||
|
||||
onRequestWidthChange: {
|
||||
terminalWindow.width = newWidth * screenItem.fontWidth;
|
||||
terminalWindow.contentItem.width = newWidth * screenItem.fontWidth;
|
||||
}
|
||||
}
|
||||
|
||||
onFontChanged: {
|
||||
setTerminalHeight();
|
||||
setTerminalWidth();
|
||||
}
|
||||
|
||||
onWidthChanged: {
|
||||
setTerminalWidth();
|
||||
}
|
||||
onHeightChanged: {
|
||||
setTerminalHeight();
|
||||
}
|
||||
Component.onCompleted: {
|
||||
setTerminalWidth();
|
||||
setTerminalHeight();
|
||||
}
|
||||
|
||||
function setTerminalWidth() {
|
||||
if (fontWidth > 0) {
|
||||
var pty_width = Math.floor(width / fontWidth);
|
||||
flickable.width = pty_width * fontWidth;
|
||||
screen.width = pty_width;
|
||||
}
|
||||
}
|
||||
|
||||
function setTerminalHeight() {
|
||||
if (fontHeight > 0) {
|
||||
var pty_height = Math.floor(height / fontHeight);
|
||||
flickable.height = pty_height * fontHeight;
|
||||
screen.height = pty_height;
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: flash
|
||||
z: 1.2
|
||||
anchors.fill: parent
|
||||
color: "grey"
|
||||
opacity: 0
|
||||
SequentialAnimation {
|
||||
id: flashAnimation
|
||||
NumberAnimation {
|
||||
target: flash
|
||||
property: "opacity"
|
||||
to: 1
|
||||
duration: 75
|
||||
}
|
||||
NumberAnimation {
|
||||
target: flash
|
||||
property: "opacity"
|
||||
to: 0
|
||||
duration: 75
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id:mousArea
|
||||
|
||||
property int drag_start_x
|
||||
property int drag_start_y
|
||||
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
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 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;
|
||||
}else {
|
||||
screen.selection.startX = drag_start_x;
|
||||
screen.selection.startY = drag_start_y;
|
||||
screen.selection.endX = character;
|
||||
screen.selection.endY = line;
|
||||
}
|
||||
}
|
||||
|
||||
onReleased: {
|
||||
if (mouse.button == Qt.LeftButton) {
|
||||
hoverEnabled = false;
|
||||
screen.selection.sendToSelection();
|
||||
}
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
if (mouse.button == Qt.MiddleButton) {
|
||||
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);
|
||||
screen.doubleClicked(Qt.point(character,line));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
81
yat/yat_declarative/qml/yat_declarative/TerminalText.qml
Normal file
81
yat/yat_declarative/qml/yat_declarative/TerminalText.qml
Normal file
@@ -0,0 +1,81 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
|
||||
import org.yat 1.0
|
||||
|
||||
ObjectDestructItem {
|
||||
id: textItem
|
||||
property font font
|
||||
property real fontWidth
|
||||
property real fontHeight
|
||||
|
||||
y: objectHandle.line * fontHeight;
|
||||
x: objectHandle.index * fontWidth;
|
||||
|
||||
width: textElement.paintedWidth
|
||||
height: textElement.paintedHeight
|
||||
|
||||
visible: objectHandle.visible
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: objectHandle.backgroundColor
|
||||
|
||||
MonoText {
|
||||
id: textElement
|
||||
anchors.fill: parent
|
||||
text: objectHandle.text
|
||||
color: objectHandle.foregroundColor
|
||||
font.family: textItem.font.family
|
||||
font.pixelSize: textItem.font.pixelSize
|
||||
font.pointSize: textItem.font.pointSize
|
||||
font.bold: objectHandle.bold
|
||||
font.underline: objectHandle.underline
|
||||
latin: objectHandle.latin
|
||||
|
||||
SequentialAnimation {
|
||||
running: objectHandle.blinking
|
||||
loops: Animation.Infinite
|
||||
onRunningChanged: {
|
||||
if (running === false)
|
||||
textElement.opacity = 1
|
||||
}
|
||||
NumberAnimation {
|
||||
target: textElement
|
||||
property: "opacity"
|
||||
to: 0
|
||||
duration: 250
|
||||
}
|
||||
NumberAnimation {
|
||||
target: textElement
|
||||
property: "opacity"
|
||||
to: 1
|
||||
duration: 250
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
37
yat/yat_declarative/qml/yat_declarative/main.qml
Normal file
37
yat/yat_declarative/qml/yat_declarative/main.qml
Normal file
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2013 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.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
import QtQuick 2.0
|
||||
import QtQuick.Window 2.0
|
||||
|
||||
Window {
|
||||
id: terminalWindow
|
||||
TerminalScreen {
|
||||
id: terminal
|
||||
anchors.fill: parent
|
||||
Component.onCompleted: terminalWindow.visible = true
|
||||
}
|
||||
width: 800
|
||||
height: 600
|
||||
color: terminal.screen.defaultBackgroundColor
|
||||
}
|
||||
9
yat/yat_declarative/qml_sources.qrc
Normal file
9
yat/yat_declarative/qml_sources.qrc
Normal file
@@ -0,0 +1,9 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>qml/yat_declarative/main.qml</file>
|
||||
<file>qml/yat_declarative/TerminalScreen.qml</file>
|
||||
<file>qml/yat_declarative/TerminalText.qml</file>
|
||||
<file>qml/yat_declarative/TerminalCursor.qml</file>
|
||||
<file>qml/yat_declarative/HighlightArea.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
22
yat/yat_declarative/register_qml_types.cpp
Normal file
22
yat/yat_declarative/register_qml_types.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "register_qml_types.h"
|
||||
|
||||
#include <QtQml>
|
||||
|
||||
#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"
|
||||
|
||||
void register_qml_types()
|
||||
{
|
||||
qmlRegisterType<TerminalScreen>("org.yat", 1, 0, "TerminalScreen");
|
||||
qmlRegisterType<ObjectDestructItem>("org.yat", 1, 0, "ObjectDestructItem");
|
||||
qmlRegisterType<MonoText>("org.yat", 1, 0, "MonoText");
|
||||
qmlRegisterType<Screen>();
|
||||
qmlRegisterType<Text>();
|
||||
qmlRegisterType<Cursor>();
|
||||
qmlRegisterType<Selection>();
|
||||
}
|
||||
6
yat/yat_declarative/register_qml_types.h
Normal file
6
yat/yat_declarative/register_qml_types.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef REGISTER_QML_TYPES_H
|
||||
#define REGISTER_QML_TYPES_H
|
||||
|
||||
void register_qml_types();
|
||||
|
||||
#endif // REGISTER_QML_TYPES_H
|
||||
65
yat/yat_declarative/terminal_screen.cpp
Normal file
65
yat/yat_declarative/terminal_screen.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/**************************************************************************************************
|
||||
* 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
|
||||
* 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 "terminal_screen.h"
|
||||
|
||||
TerminalScreen::TerminalScreen(QQuickItem *parent)
|
||||
: QQuickItem(parent)
|
||||
, m_screen(new Screen(this))
|
||||
{
|
||||
setFlag(QQuickItem::ItemAcceptsInputMethod);
|
||||
}
|
||||
|
||||
Screen *TerminalScreen::screen() const
|
||||
{
|
||||
return m_screen;
|
||||
}
|
||||
|
||||
QVariant TerminalScreen::inputMethodQuery(Qt::InputMethodQuery query) const
|
||||
{
|
||||
switch (query) {
|
||||
case Qt::ImEnabled:
|
||||
return QVariant(true);
|
||||
case Qt::ImHints:
|
||||
return QVariant(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
void TerminalScreen::inputMethodEvent(QInputMethodEvent *event)
|
||||
{
|
||||
QString commitString = event->commitString();
|
||||
if (commitString.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Qt::Key key = Qt::Key_unknown;
|
||||
if (commitString == " ") {
|
||||
key = Qt::Key_Space; // screen requires
|
||||
}
|
||||
|
||||
m_screen->sendKey(commitString, key, 0);
|
||||
}
|
||||
|
||||
void TerminalScreen::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
m_screen->sendKey(event->text(), Qt::Key(event->key()), event->modifiers());
|
||||
}
|
||||
54
yat/yat_declarative/terminal_screen.h
Normal file
54
yat/yat_declarative/terminal_screen.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/******************************************************************************
|
||||
* 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
|
||||
* 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 TERMINALITEM_H
|
||||
#define TERMINALITEM_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtQuick/QQuickItem>
|
||||
#include <QInputMethodEvent>
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include "screen.h"
|
||||
|
||||
class TerminalScreen : public QQuickItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(Screen *screen READ screen CONSTANT)
|
||||
public:
|
||||
TerminalScreen(QQuickItem *parent = 0);
|
||||
|
||||
Screen *screen() const;
|
||||
|
||||
QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
|
||||
|
||||
protected:
|
||||
void inputMethodEvent(QInputMethodEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
|
||||
private:
|
||||
Screen *m_screen;
|
||||
};
|
||||
|
||||
#endif // TERMINALITEM_H
|
||||
18
yat/yat_declarative/yat_declarative.pro
Normal file
18
yat/yat_declarative/yat_declarative.pro
Normal file
@@ -0,0 +1,18 @@
|
||||
QT += gui quick
|
||||
TARGET = yat
|
||||
|
||||
include(../backend/backend.pri)
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
SOURCES += $$PWD/terminal_screen.cpp \
|
||||
$$PWD/object_destruct_item.cpp \
|
||||
$$PWD/register_qml_types.cpp \
|
||||
$$PWD/mono_text.cpp \
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/terminal_screen.h \
|
||||
$$PWD/object_destruct_item.h \
|
||||
$$PWD/register_qml_types.h \
|
||||
$$PWD/mono_text.h \
|
||||
|
||||
Reference in New Issue
Block a user