Mercurial > hg > octave-nkf
comparison libgui/qterminal/libqterminal/unix/QUnixTerminalImpl.cpp @ 15681:018c46ef8a0c
maint: move everything under libgui/qterminal
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Mon, 26 Nov 2012 12:07:51 -0500 |
parents | libqterminal/unix/QUnixTerminalImpl.cpp@6b1369106141 |
children | 98902367c781 |
comparison
equal
deleted
inserted
replaced
15680:6b1369106141 | 15681:018c46ef8a0c |
---|---|
1 /* Copyright (C) 2008 e_k (e_k@users.sourceforge.net) | |
2 Copyright (C) 2012 Jacob Dawid <jacob.dawid@googlemail.com> | |
3 | |
4 This library is free software; you can redistribute it and/or | |
5 modify it under the terms of the GNU Library General Public | |
6 License as published by the Free Software Foundation; either | |
7 version 2 of the License, or (at your option) any later version. | |
8 | |
9 This library is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 Library General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU Library General Public License | |
15 along with this library; see the file COPYING.LIB. If not, write to | |
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
17 Boston, MA 02110-1301, USA. | |
18 */ | |
19 | |
20 #include <QDebug> | |
21 | |
22 #include "unix/QUnixTerminalImpl.h" | |
23 #include "unix/kpty.h" | |
24 | |
25 #include <termios.h> | |
26 | |
27 QUnixTerminalImpl::QUnixTerminalImpl(QWidget *parent) | |
28 : QTerminalInterface(parent) { | |
29 setMinimumSize(600, 400); | |
30 initialize(); | |
31 } | |
32 | |
33 void QUnixTerminalImpl::initialize() | |
34 { | |
35 m_terminalView = new TerminalView(this); | |
36 m_terminalView->setKeyboardCursorShape(TerminalView::UnderlineCursor); | |
37 m_terminalView->setBlinkingCursor(true); | |
38 m_terminalView->setBellMode(TerminalView::NotifyBell); | |
39 m_terminalView->setTerminalSizeHint(true); | |
40 m_terminalView->setContextMenuPolicy(Qt::CustomContextMenu); | |
41 m_terminalView->setTripleClickMode(TerminalView::SelectWholeLine); | |
42 m_terminalView->setTerminalSizeStartup(true); | |
43 m_terminalView->setSize(80, 40); | |
44 m_terminalView->setScrollBarPosition(TerminalView::ScrollBarRight); | |
45 | |
46 connect(m_terminalView, SIGNAL(customContextMenuRequested(QPoint)), | |
47 this, SLOT(handleCustomContextMenuRequested(QPoint))); | |
48 | |
49 #ifdef Q_OS_MAC | |
50 QFont font = QFont("Monaco"); | |
51 font.setStyleHint(QFont::TypeWriter); | |
52 font.setPointSize(11); | |
53 #else | |
54 QFont font = QFont("Monospace"); | |
55 font.setStyleHint(QFont::TypeWriter); | |
56 font.setPointSize(10); | |
57 #endif | |
58 setTerminalFont(font); | |
59 setFocusProxy(m_terminalView); | |
60 setFocus(Qt::OtherFocusReason); | |
61 | |
62 m_kpty = new KPty(); | |
63 m_kpty->open(); | |
64 | |
65 m_terminalModel = new TerminalModel(m_kpty); | |
66 m_terminalModel->setAutoClose(true); | |
67 m_terminalModel->setCodec(QTextCodec::codecForName("UTF-8")); | |
68 m_terminalModel->setHistoryType(HistoryTypeBuffer(1000)); | |
69 m_terminalModel->setDarkBackground(true); | |
70 m_terminalModel->setKeyBindings(""); | |
71 m_terminalModel->run(); | |
72 m_terminalModel->addView(m_terminalView); | |
73 connectToPty(); | |
74 } | |
75 | |
76 void QUnixTerminalImpl::connectToPty() | |
77 { | |
78 int fds = m_kpty->slaveFd(); | |
79 | |
80 dup2 (fds, STDIN_FILENO); | |
81 dup2 (fds, STDOUT_FILENO); | |
82 dup2 (fds, STDERR_FILENO); | |
83 | |
84 if(!isatty(STDIN_FILENO)) { | |
85 qDebug("Error: stdin is not a tty."); | |
86 } | |
87 | |
88 if(!isatty(STDOUT_FILENO)) { | |
89 qDebug("Error: stdout is not a tty."); | |
90 } | |
91 | |
92 if(!isatty(STDERR_FILENO)) { | |
93 qDebug("Error: stderr is not a tty."); | |
94 } | |
95 } | |
96 | |
97 QUnixTerminalImpl::~QUnixTerminalImpl() | |
98 { | |
99 emit destroyed(); | |
100 } | |
101 | |
102 void QUnixTerminalImpl::setTerminalFont(const QFont &font) | |
103 { | |
104 if(!m_terminalView) | |
105 return; | |
106 m_terminalView->setVTFont(font); | |
107 } | |
108 | |
109 void QUnixTerminalImpl::setSize(int h, int v) | |
110 { | |
111 if(!m_terminalView) | |
112 return; | |
113 m_terminalView->setSize(h, v); | |
114 } | |
115 | |
116 void QUnixTerminalImpl::sendText(const QString& text) | |
117 { | |
118 m_terminalModel->sendText(text); | |
119 } | |
120 | |
121 void QUnixTerminalImpl::setCursorType(CursorType type, bool blinking) | |
122 { | |
123 switch(type) { | |
124 case UnderlineCursor: m_terminalView->setKeyboardCursorShape(TerminalView::UnderlineCursor); break; | |
125 case BlockCursor: m_terminalView->setKeyboardCursorShape(TerminalView::BlockCursor); break; | |
126 case IBeamCursor: m_terminalView->setKeyboardCursorShape(TerminalView::IBeamCursor); break; | |
127 } | |
128 m_terminalView->setBlinkingCursor(blinking); | |
129 } | |
130 | |
131 void QUnixTerminalImpl::focusInEvent(QFocusEvent *focusEvent) | |
132 { | |
133 Q_UNUSED(focusEvent); | |
134 m_terminalView->updateImage(); | |
135 m_terminalView->repaint(); | |
136 m_terminalView->update(); | |
137 } | |
138 | |
139 void QUnixTerminalImpl::showEvent(QShowEvent *) | |
140 { | |
141 m_terminalView->updateImage(); | |
142 m_terminalView->repaint(); | |
143 m_terminalView->update(); | |
144 } | |
145 | |
146 void QUnixTerminalImpl::resizeEvent(QResizeEvent*) | |
147 { | |
148 m_terminalView->resize(this->size()); | |
149 m_terminalView->updateImage(); | |
150 m_terminalView->repaint(); | |
151 m_terminalView->update(); | |
152 } | |
153 | |
154 void QUnixTerminalImpl::copyClipboard() | |
155 { | |
156 m_terminalView->copyClipboard(); | |
157 } | |
158 | |
159 void QUnixTerminalImpl::pasteClipboard() | |
160 { | |
161 m_terminalView->pasteClipboard(); | |
162 } | |
163 |