Adding upstream version 0.6.0+20150709.

upstream/0.6.0+20150709
Alf Gaida 9 years ago
parent c44b7c83a0
commit 3d7ff0b035

@ -15,7 +15,6 @@ set(QTERMWIDGET_VERSION_PATCH "0")
set(QTERMWIDGET_VERSION "${QTERMWIDGET_VERSION_MAJOR}.${QTERMWIDGET_VERSION_MINOR}.${QTERMWIDGET_VERSION_PATCH}")
include(CheckFunctionExists)
include(GNUInstallDirs)
@ -92,15 +91,15 @@ set(HDRS_DISTRIB
)
# dirs
set(KB_LAYOUT_DIR "${CMAKE_INSTALL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/kb-layouts/")
set(KB_LAYOUT_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/kb-layouts")
message(STATUS "Keyboard layouts will be installed in: ${KB_LAYOUT_DIR}")
add_definitions(-DKB_LAYOUT_DIR="${CMAKE_INSTALL_PREFIX}/${KB_LAYOUT_DIR}")
add_definitions(-DKB_LAYOUT_DIR="${KB_LAYOUT_DIR}")
set(COLORSCHEMES_DIR "${CMAKE_INSTALL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/color-schemes/")
set(COLORSCHEMES_DIR "${CMAKE_INSTALL_FULL_DATADIR}/${QTERMWIDGET_LIBRARY_NAME}/color-schemes")
message(STATUS "Color schemes will be installed in: ${COLORSCHEMES_DIR}" )
add_definitions(-DCOLORSCHEMES_DIR="${CMAKE_INSTALL_PREFIX}/${COLORSCHEMES_DIR}")
add_definitions(-DCOLORSCHEMES_DIR="${COLORSCHEMES_DIR}")
set(QTERMWIDGET_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/${QTERMWIDGET_LIBRARY_NAME}")
set(QTERMWIDGET_INCLUDE_DIR "${CMAKE_INSTALL_FULL_INCLUDEDIR}/${QTERMWIDGET_LIBRARY_NAME}")
#| Defines
add_definitions(-DHAVE_POSIX_OPENPT -DHAVE_SYS_TIME_H)
@ -133,7 +132,7 @@ set_target_properties( ${QTERMWIDGET_LIBRARY_NAME} PROPERTIES
if(APPLE)
set (CMAKE_SKIP_RPATH 1)
# this is a must to load the lib correctly
set_target_properties( ${QTERMWIDGET_LIBRARY_NAME} PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} )
set_target_properties(${QTERMWIDGET_LIBRARY_NAME} PROPERTIES INSTALL_NAME_DIR ${CMAKE_INSTALL_FULL_LIBDIR})
endif()
install(TARGETS ${QTERMWIDGET_LIBRARY_NAME} DESTINATION "${CMAKE_INSTALL_LIBDIR}")
@ -195,11 +194,11 @@ if (BUILD_DESIGNER_PLUGIN)
if(APPLE)
# this is a must to load the lib correctly
set_target_properties(qtermwidget4plugin PROPERTIES
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/qt4/plugins/designer"
INSTALL_NAME_DIR "${CMAKE_INSTALL_FULL_LIBDIR}/qt4/plugins/designer"
)
endif()
install(TARGETS qtermwidget4plugin DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/qt4/plugins/designer")
install(TARGETS qtermwidget4plugin DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/qt4/plugins/designer")
endif (BUILD_DESIGNER_PLUGIN)
# end of designer plugin

@ -218,6 +218,28 @@ int Pty::start(const QString& program,
return 0;
}
void Pty::setEmptyPTYProperties()
{
struct ::termios ttmode;
pty()->tcGetAttr(&ttmode);
if (!_xonXoff)
ttmode.c_iflag &= ~(IXOFF | IXON);
else
ttmode.c_iflag |= (IXOFF | IXON);
#ifdef IUTF8 // XXX not a reasonable place to check it.
if (!_utf8)
ttmode.c_iflag &= ~IUTF8;
else
ttmode.c_iflag |= IUTF8;
#endif
if (_eraseChar != 0)
ttmode.c_cc[VERASE] = _eraseChar;
if (!pty()->tcSetAttr(&ttmode))
qWarning() << "Unable to set terminal attributes.";
}
void Pty::setWriteable(bool writeable)
{
struct stat sbuf;

@ -107,6 +107,11 @@ Q_OBJECT
bool addToUtmp
);
/**
* set properties for "EmptyPTY"
*/
void setEmptyPTYProperties();
/** TODO: Document me */
void setWriteable(bool writeable);

@ -307,7 +307,7 @@ void Screen::resizeImage(int new_lines, int new_columns)
// create new screen lines and copy from old to new
ImageLine* newScreenLines = new ImageLine[new_lines+1];
for (int i=0; i < qMin(lines-1,new_lines+1) ;i++)
for (int i=0; i < qMin(lines,new_lines+1) ;i++)
newScreenLines[i]=screenLines[i];
for (int i=lines;(i > 0) && (i<new_lines+1);i++)
newScreenLines[i].resize( new_columns );

@ -79,6 +79,7 @@ Session::Session(QObject* parent) :
//create teletype for I/O with shell process
_shellProcess = new Pty();
ptySlaveFd = _shellProcess->pty()->slaveFd();
//create emulation backend
_emulation = new Vt102Emulation();
@ -129,7 +130,17 @@ WId Session::windowId() const
// there are multiple views, then the window ID for the
// top-level window which contains the first view is
// returned
//
// On Qt5, requesting window IDs breaks QQuickWidget and the likes,
// for example, see the following bug reports:
//
// https://bugreports.qt-project.org/browse/QTBUG-41779
// https://bugreports.qt-project.org/browse/QTBUG-40765
// https://bugreports.qt-project.org/browse/QTBUG-41942
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return 0;
#else
if ( _views.count() == 0 ) {
return 0;
} else {
@ -143,6 +154,7 @@ WId Session::windowId() const
return window->winId();
}
#endif
}
void Session::setDarkBackground(bool darkBackground)
@ -341,6 +353,22 @@ void Session::run()
emit started();
}
void Session::runEmptyPTY()
{
_shellProcess->setFlowControlEnabled(_flowControl);
_shellProcess->setErase(_emulation->eraseChar());
_shellProcess->setWriteable(false);
// disconnet send data from emulator to internal terminal process
disconnect( _emulation,SIGNAL(sendData(const char *,int)),
_shellProcess, SLOT(sendData(const char *,int)) );
_shellProcess->setEmptyPTYProperties();
qDebug() << "started!";
emit started();
}
void Session::setUserTitle( int what, const QString & caption )
{
//set to true if anything is actually changed (eg. old _nameTitle != new _nameTitle )
@ -469,8 +497,8 @@ void Session::activityStateSet(int state)
if ( _monitorActivity ) {
//FIXME: See comments in Session::monitorTimerDone()
if (!_notifiedActivity) {
emit activity();
_notifiedActivity=true;
emit activity();
}
}
}
@ -928,6 +956,10 @@ int Session::processId() const
{
return _shellProcess->pid();
}
int Session::getPtySlaveFd() const
{
return ptySlaveFd;
}
SessionGroup::SessionGroup()
: _masterMode(0)

@ -25,7 +25,6 @@
#ifndef SESSION_H
#define SESSION_H
#include <QStringList>
#include <QWidget>
@ -363,6 +362,13 @@ public:
// void cancelZModem();
// bool isZModemBusy() { return _zmodemBusy; }
/**
* Returns a pty slave file descriptor.
* This can be used for display and control
* a remote terminal.
*/
int getPtySlaveFd() const;
public slots:
/**
@ -372,6 +378,13 @@ public slots:
*/
void run();
/**
* Starts the terminal session for "as is" PTY
* (without the direction a data to internal terminal process).
* It can be used for control or display a remote/external terminal.
*/
void runEmptyPTY();
/**
* Closes the terminal session. This sends a hangup signal
* (SIGHUP) to the terminal process and causes the done(Session*)
@ -543,6 +556,8 @@ private:
static int lastSessionId;
int ptySlaveFd;
};
/**

@ -260,7 +260,7 @@ void TerminalDisplay::setVTFont(const QFont& f)
if ( !QFontInfo(font).fixedPitch() )
{
qDebug() << "Using an unsupported variable-width font in the terminal. This may produce display errors.";
qDebug() << "Using a variable-width font in the terminal. This may cause performance degradation and display/alignment errors.";
}
if ( metrics.height() < height() && metrics.maxWidth() < width() )
@ -1398,6 +1398,27 @@ void TerminalDisplay::paintFilters(QPainter& painter)
}
}
}
int TerminalDisplay::textWidth(const int startColumn, const int length, const int line) const
{
QFontMetrics fm(font());
int result = 0;
for (int column = 0; column < length; column++) {
result += fm.width(_image[loc(startColumn + column, line)].character);
}
return result;
}
QRect TerminalDisplay::calculateTextArea(int topLeftX, int topLeftY, int startColumn, int line, int length) {
int left = _fixedFont ? _fontWidth * startColumn : textWidth(0, startColumn, line);
int top = _fontHeight * line;
int width = _fixedFont ? _fontWidth * length : textWidth(startColumn, length, line);
return QRect(_leftMargin + topLeftX + left,
_topMargin + topLeftY + top,
width,
_fontHeight);
}
void TerminalDisplay::drawContents(QPainter &paint, const QRect &rect)
{
QPoint tL = contentsRect().topLeft();
@ -1405,9 +1426,9 @@ void TerminalDisplay::drawContents(QPainter &paint, const QRect &rect)
int tLy = tL.y();
int lux = qMin(_usedColumns-1, qMax(0,(rect.left() - tLx - _leftMargin ) / _fontWidth));
int luy = qMin(_usedLines-1, qMax(0,(rect.top() - tLy - _topMargin ) / _fontHeight));
int luy = qMin(_usedLines-1, qMax(0,(rect.top() - tLy - _topMargin ) / _fontHeight));
int rlx = qMin(_usedColumns-1, qMax(0,(rect.right() - tLx - _leftMargin ) / _fontWidth));
int rly = qMin(_usedLines-1, qMax(0,(rect.bottom() - tLy - _topMargin ) / _fontHeight));
int rly = qMin(_usedLines-1, qMax(0,(rect.bottom() - tLy - _topMargin ) / _fontHeight));
const int bufferSize = _usedColumns;
QString unistr;
@ -1496,7 +1517,7 @@ void TerminalDisplay::drawContents(QPainter &paint, const QRect &rect)
paint.setWorldMatrix(textScale, true);
//calculate the area in which the text will be drawn
QRect textArea = QRect( _leftMargin+tLx+_fontWidth*x , _topMargin+tLy+_fontHeight*y , _fontWidth*len , _fontHeight);
QRect textArea = calculateTextArea(tLx, tLy, x, y, len);
//move the calculated area to take account of scaling applied to the painter.
//the position of the area from the origin (0,0) is scaled
@ -2184,9 +2205,19 @@ void TerminalDisplay::mouseReleaseEvent(QMouseEvent* ev)
void TerminalDisplay::getCharacterPosition(const QPoint& widgetPoint,int& line,int& column) const
{
column = (widgetPoint.x() + _fontWidth/2 -contentsRect().left()-_leftMargin) / _fontWidth;
line = (widgetPoint.y()-contentsRect().top()-_topMargin) / _fontHeight;
if ( _fixedFont )
column = (widgetPoint.x() + _fontWidth/2 -contentsRect().left()-_leftMargin) / _fontWidth;
else
{
int x = contentsRect().left() + widgetPoint.x() - _fontWidth/2;
column = 0;
while(x > textWidth(0, column, line))
column++;
}
if ( line < 0 )
line = 0;
if ( column < 0 )
@ -2450,8 +2481,11 @@ void TerminalDisplay::setWordCharacters(const QString& wc)
void TerminalDisplay::setUsesMouse(bool on)
{
_mouseMarks = on;
setCursor( _mouseMarks ? Qt::IBeamCursor : Qt::ArrowCursor );
if (_mouseMarks != on) {
_mouseMarks = on;
setCursor( _mouseMarks ? Qt::IBeamCursor : Qt::ArrowCursor );
emit usesMouseChanged();
}
}
bool TerminalDisplay::usesMouse() const
{
@ -2913,7 +2947,7 @@ void TerminalDisplay::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasFormat("text/plain"))
event->acceptProposedAction();
if (event->mimeData()->urls().count());
if (event->mimeData()->urls().count())
event->acceptProposedAction();
}

@ -571,6 +571,7 @@ signals:
void termLostFocus();
void notifyBell(const QString&);
void usesMouseChanged();
protected:
virtual bool event( QEvent * );
@ -641,6 +642,11 @@ private:
// -- Drawing helpers --
// determine the width of this text
int textWidth(int startColumn, int length, int line) const;
// determine the area that encloses this series of characters
QRect calculateTextArea(int topLeftX, int topLeftY, int startColumn, int line, int length);
// divides the part of the display specified by 'rect' into
// fragments according to their colors and styles and calls
// drawTextFragment() to draw the fragments

@ -228,6 +228,18 @@ void QTermWidget::startShellProgram()
m_impl->m_session->run();
}
void QTermWidget::startTerminalTeletype()
{
if ( m_impl->m_session->isRunning() ) {
return;
}
m_impl->m_session->runEmptyPTY();
// redirect data from TTY to external recipient
connect( m_impl->m_session->emulation(), SIGNAL(sendData(const char *,int)),
this, SIGNAL(sendData(const char *,int)) );
}
void QTermWidget::init(int startnow)
{
m_layout = new QVBoxLayout();
@ -567,6 +579,11 @@ int QTermWidget::screenColumnsCount()
return m_impl->m_terminalDisplay->screenWindow()->screen()->getColumns();
}
int QTermWidget::screenLinesCount()
{
return m_impl->m_terminalDisplay->screenWindow()->screen()->getLines();
}
void QTermWidget::setSelectionStart(int row, int column)
{
m_impl->m_terminalDisplay->screenWindow()->screen()->setSelectionStart(column, row, true);
@ -582,9 +599,9 @@ void QTermWidget::getSelectionStart(int& row, int& column)
m_impl->m_terminalDisplay->screenWindow()->screen()->getSelectionStart(column, row);
}
void QTermWidget::setSelectionEnd(int& row, int& column)
void QTermWidget::getSelectionEnd(int& row, int& column)
{
m_impl->m_terminalDisplay->screenWindow()->screen()->setSelectionEnd(column, row);
m_impl->m_terminalDisplay->screenWindow()->screen()->getSelectionEnd(column, row);
}
QString QTermWidget::selectedText(bool preserveLineBreaks)
@ -619,3 +636,7 @@ Filter::HotSpot* QTermWidget::getHotSpotAt(int row, int column) const
return m_impl->m_terminalDisplay->filterChain()->hotSpotAt(row, column);
}
int QTermWidget::getPtySlaveFd() const
{
return m_impl->m_session->getPtySlaveFd();
}

@ -55,6 +55,13 @@ public:
//start shell program if it was not started in constructor
void startShellProgram();
/**
* Start terminal teletype as is
* and redirect data for external recipient.
* It can be used for display and control a remote terminal.
*/
void startTerminalTeletype();
int getShellPID();
void changeDir(const QString & dir);
@ -63,8 +70,7 @@ public:
// Terminal font
// Default is application font with family Monospace, size 10
// USE ONLY FIXED-PITCH FONT!
// otherwise symbols' position could be incorrect
// Beware of a performance penalty and display/alignment issues when using a proportional font.
void setTerminalFont(const QFont & font);
QFont getTerminalFont();
void setTerminalOpacity(qreal level);
@ -133,11 +139,12 @@ public:
int historyLinesCount();
int screenColumnsCount();
int screenLinesCount();
void setSelectionStart(int row, int column);
void setSelectionEnd(int row, int column);
void getSelectionStart(int& row, int& column);
void setSelectionEnd(int& row, int& column);
void getSelectionEnd(int& row, int& column);
/**
* Returns the currently selected text.
@ -165,6 +172,13 @@ public:
*/
Filter::HotSpot* getHotSpotAt(int row, int column) const;
/**
* Returns a pty slave file descriptor.
* This can be used for display and control
* a remote terminal.
*/
int getPtySlaveFd() const;
signals:
void finished();
void copyAvailable(bool);
@ -181,6 +195,13 @@ signals:
void activity();
void silence();
/**
* Emitted when emulator send data to the terminal process
* (redirected for external recipient). It can be used for
* control and display the remote terminal.
*/
void sendData(const char *,int);
public slots:
// Copy selection to clipboard
void copyClipboard();

@ -61,7 +61,7 @@ makefile = pyqtconfig.QtGuiModuleMakefile(
# specific prefixes or extensions (e.g. the "lib" prefix on UNIX, or the
# ".dll" extension on Windows).
makefile.extra_lib_dirs.append("..")
makefile.extra_libs = ["qtermwidget"]
makefile.extra_libs = ["qtermwidget4"]
# Generate the Makefile itself.
makefile.generate()

@ -11,25 +11,73 @@ class QTermWidget : QWidget {
%End
public:
QTermWidget(int startnow = 1, QWidget *parent = 0);
~QTermWidget();
enum ScrollBarPosition
enum ScrollBarPosition
{
NoScrollBar=0,
ScrollBarLeft=1,
ScrollBarRight=2
};
void setTerminalFont(QFont &font);
void setArgs(QStringList &args);
void setTextCodec(QTextCodec *codec);
void setColorScheme(int scheme);
void setSize(int h, int v);
void setHistorySize(int lines);
void setScrollBarPosition(ScrollBarPosition);
void sendText(QString &text);
QTermWidget(int startnow = 1, QWidget *parent = 0);
~QTermWidget();
QSize sizeHint() const;
void startShellProgram();
int getShellPID();
void changeDir(const QString & dir);
void setTerminalFont(QFont &font);
QFont getTerminalFont();
void setTerminalOpacity(qreal level);
void setEnvironment(const QStringList & environment);
void setShellProgram(const QString & progname);
void setWorkingDirectory(const QString & dir);
QString workingDirectory();
void setArgs(QStringList &args);
void setTextCodec(QTextCodec *codec);
void setColorScheme(const QString & name);
static QStringList availableColorSchemes();
void setSize(int h, int v);
void setHistorySize(int lines);
void setScrollBarPosition(ScrollBarPosition);
void scrollToEnd();
void sendText(QString &text);
void setFlowControlEnabled(bool enabled);
bool flowControlEnabled();
void setFlowControlWarningEnabled(bool enabled);
static QStringList availableKeyBindings();
QString keyBindings();
void setMotionAfterPasting(int);
int historyLinesCount();
int screenColumnsCount();
void setSelectionStart(int row, int column);
void setSelectionEnd(int row, int column);
void getSelectionStart(int& row, int& column);
void getSelectionEnd(int& row, int& column);
QString selectedText(bool preserveLineBreaks = true);
void setMonitorActivity(bool);
void setMonitorSilence(bool);
void setSilenceTimeout(int seconds);
signals:
void finished();
void copyAvailable(bool);
void termGetFocus();
void termLostFocus();
void termKeyPressed(QKeyEvent *);
void urlActivated(const QUrl&);
void bell(const QString& message);
void activity();
void silence();
public slots:
void copyClipboard();
void pasteClipboard();
void pasteSelection();
void zoomIn();
void zoomOut();
void setKeyBindings(const QString & kb);
void clear();
void toggleShowSearchBar();
protected:
void resizeEvent(QResizeEvent *e);
void resizeEvent(QResizeEvent *e);
private:
void *createTermWidget(int startnow, void *parent);
void *createTermWidget(int startnow, void *parent);
};

@ -19,12 +19,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
import sys, signal
from PyQt4 import Qt
from PyQt4.QtCore import SIGNAL, SLOT
import QTermWidget
signal.signal(signal.SIGINT, signal.SIG_DFL)
a = Qt.QApplication(sys.argv)
w = QTermWidget.QTermWidget()
w.show()
w.connect(w, SIGNAL('finished()'), a, SLOT('quit()'))
a.exec_()

Loading…
Cancel
Save