⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tewidget.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS and its licensors.** All rights reserved.**** This file is part of the Qtopia Environment.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.trolltech.com/gpl/ for GPL licensing information.** See below for additional copyright and license information**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************//* ------------------------------------------------------------------------ *//*                                                                          *//* [TEWidget.C]            Terminal Emulation Widget                        *//*                                                                          *//* ------------------------------------------------------------------------ *//*                                                                          *//* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>          *//*                                                                          *//* This file is part of Konsole - an X terminal for KDE                     *//*                                                                          *//* ------------------------------------------------------------------------ *//*                        *//* Konsole ported to Qt/Embedded by Trolltech                               *//*                        *//* ------------------------------------------------------------------------ *//* \class TEWidget    \brief The TEWidget class represents the visible screen contents.   This class is responsible for mapping the `image' of a terminal emulation to the   display. The emulation's dependency on a specific GUI or toolkit is   localized here. Furthermore, this widget has no knowledge of being part of an   emulation, it simply works within the terminal emulation framework by exposing   size and key events and by being ordered to show a new image.   <ul>   <li> The internal image has the size of the widget (evtl. rounded up)   <li> The external image used in setImage can have any size.   <li> (internally) the external image is simply copied to the internal        when a setImage happens. During a resizeEvent no painting is done, but a paintEvent is expected to follow anyway.   </ul>   \sa TEScreen \sa Emulation*//* FIXME:   - 'image' may also be used uninitialized (it isn't in fact) in resizeEvent   - 'font_a' is not used in mouse events   - add destructor*//* TODO   - evtl. be sensitive to `paletteChange' while using default colors.   - set different 'rounding' styles? I.e. have a mode to show clipped chars?*/// #include "config.h"#include "TEWidget.h"#include "session.h"#include <qcursor.h>#include <qregexp.h>#include <qpainter.h>#include <qclipboard.h>#include <qstyle.h>#include <qfile.h>#include <qdragobject.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <ctype.h>#include <sys/stat.h>#include <sys/types.h>#include <signal.h>#ifndef S_ISDIR// Need for WIN32#define S_ISDIR(st_mode) ((st_mode | S_IFDIR) != 0) #endif#include <assert.h>// #include "TEWidget.moc"//#include <kapp.h>//#include <kcursor.h>//#include <kurl.h>//#include <kdebug.h>//#include <klocale.h>#define HERE printf("%s(%d): %s\n",__FILE__,__LINE__,__FUNCTION__)#define HCNT(Name) // { static int cnt = 1; printf("%s(%d): %s %d\n",__FILE__,__LINE__,Name,cnt++); }#define loc(X,Y) ((Y)*columns+(X))//FIXME: the rim should normally be 1, 0 only when running in full screen mode.#define rimX 0      // left/right rim width#define rimY 0      // top/bottom rim high#define SCRWIDTH 16 // width of the scrollbar#define yMouseScroll 1// scroll increment used when dragging selection at top/bottom of window./* ------------------------------------------------------------------------- *//*                                                                           *//*                                Colors                                     *//*                                                                           *//* ------------------------------------------------------------------------- *///FIXME: the default color table is in session.C now.//       We need a way to get rid of this one, here.static const ColorEntry base_color_table[TABLE_COLORS] =// The following are almost IBM standard color codes, with some slight// gamma correction for the dim colors to compensate for bright X screens.// It contains the 8 ansiterm/xterm colors in 2 intensities.{  // Fixme: could add faint colors here, also.  // normal  ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 1, 0 ), // Dfore, Dback  ColorEntry(QColor(0x00,0x00,0x00), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0x18), 0, 0 ), // Black, Red  ColorEntry(QColor(0x18,0xB2,0x18), 0, 0 ), ColorEntry( QColor(0xB2,0x68,0x18), 0, 0 ), // Green, Yellow  ColorEntry(QColor(0x18,0x18,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ), // Blue,  Magenta  ColorEntry(QColor(0x18,0xB2,0xB2), 0, 0 ), ColorEntry( QColor(0xB2,0xB2,0xB2), 0, 0 ), // Cyan,  White  // intensiv  ColorEntry(QColor(0x00,0x00,0x00), 0, 1 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 1, 0 ),  ColorEntry(QColor(0x68,0x68,0x68), 0, 0 ), ColorEntry( QColor(0xFF,0x54,0x54), 0, 0 ),  ColorEntry(QColor(0x54,0xFF,0x54), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0x54), 0, 0 ),  ColorEntry(QColor(0x54,0x54,0xFF), 0, 0 ), ColorEntry( QColor(0xB2,0x18,0xB2), 0, 0 ),  ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 )};/* Note that we use ANSI color order (bgr), while IBMPC color order is (rgb)   Code        0       1       2       3       4       5       6       7   ----------- ------- ------- ------- ------- ------- ------- ------- -------   ANSI  (bgr) Black   Red     Green   Yellow  Blue    Magenta Cyan    White   IBMPC (rgb) Black   Blue    Green   Cyan    Red     Magenta Yellow  White*/QColor TEWidget::getDefaultBackColor(){  return color_table[DEFAULT_BACK_COLOR].color;}const ColorEntry* TEWidget::getColorTable() const{  return color_table;}const ColorEntry* TEWidget::getdefaultColorTable() const{  return base_color_table;}const QPixmap *TEWidget::backgroundPixmap(){  static QPixmap *bg = new QPixmap("~/qpim/main/pics/faded_bg.xpm");  const QPixmap *pm = bg;  return pm;}void TEWidget::setColorTable(const ColorEntry table[]){  for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i];    const QPixmap* pm = backgroundPixmap();  if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color);  update();}//FIXME: add backgroundPixmapChanged./* ------------------------------------------------------------------------- *//*                                                                           *//*                                   Font                                    *//*                                                                           *//* ------------------------------------------------------------------------- *//*   The VT100 has 32 special graphical characters. The usual vt100 extended   xterm fonts have these at 0x00..0x1f.   QT's iso mapping leaves 0x00..0x7f without any changes. But the graphicals   come in here as proper unicode characters.   We treat non-iso10646 fonts as VT100 extended and do the required mapping   from unicode to 0x00..0x1f. The remaining translation is then left to the   QCodec.*/// assert for i in [0..31] : vt100extended(vt100_graphics[i]) == i.unsigned short vt100_graphics[32] ={ // 0/8     1/9    2/10    3/11    4/12    5/13    6/14    7/15  0x0020, 0x25C6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0,  0x00b1, 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c,  0xF800, 0xF801, 0x2500, 0xF803, 0xF804, 0x251c, 0x2524, 0x2534,  0x252c, 0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00b7};static QChar vt100extended(QChar c){  switch (c.unicode())  {    case 0x25c6 : return  1;    case 0x2592 : return  2;    case 0x2409 : return  3;    case 0x240c : return  4;    case 0x240d : return  5;    case 0x240a : return  6;    case 0x00b0 : return  7;    case 0x00b1 : return  8;    case 0x2424 : return  9;    case 0x240b : return 10;    case 0x2518 : return 11;    case 0x2510 : return 12;    case 0x250c : return 13;    case 0x2514 : return 14;    case 0x253c : return 15;    case 0xf800 : return 16;    case 0xf801 : return 17;    case 0x2500 : return 18;    case 0xf803 : return 19;    case 0xf804 : return 20;    case 0x251c : return 21;    case 0x2524 : return 22;    case 0x2534 : return 23;    case 0x252c : return 24;    case 0x2502 : return 25;    case 0x2264 : return 26;    case 0x2265 : return 27;    case 0x03c0 : return 28;    case 0x2260 : return 29;    case 0x00a3 : return 30;    case 0x00b7 : return 31;  }  return c;}static QChar identicalMap(QChar c){  return c;}void TEWidget::fontChange(const QFont &){  QFontMetrics fm(font());  font_h = fm.height();  font_w = fm.maxWidth();  font_a = fm.ascent();//printf("font_h: %d\n",font_h);//printf("font_w: %d\n",font_w);//printf("font_a: %d\n",font_a);//printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii());//printf("rawname: %s\n",font().rawName().ascii());  fontMap =#if QT_VERSION < 0x030000  strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646")          ? vt100extended          :#endif  identicalMap;  propagateSize();  update();}void TEWidget::setVTFont(const QFont& f){  QFrame::setFont(f);}QFont TEWidget::getVTFont() {  return font();}void TEWidget::setFont(const QFont &){  // ignore font change request if not coming from konsole itself}/* ------------------------------------------------------------------------- *//*                                                                           *//*                         Constructor / Destructor                          *//*                                                                           *//* ------------------------------------------------------------------------- */TEWidget::TEWidget(QWidget *parent, const char *name) : QFrame(parent,name){#ifndef QT_NO_CLIPBOARD  cb = QApplication::clipboard();  QObject::connect( (QObject*)cb, SIGNAL(dataChanged()),                    this, SLOT(onClearSelection()) );#endif  scrollbar = new QScrollBar(this);  scrollbar->setCursor( arrowCursor );  connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int)));  scrollLoc = SCRRIGHT;  blinkT   = new QTimer(this);  connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent()));  // blinking = FALSE;  blinking = TRUE;  resizing = FALSE;  actSel   = 0;  image    = 0;  lines    = 1;  columns  = 1;  font_w   = 1;  font_h   = 1;  font_a   = 1;  word_selection_mode = FALSE;  setMouseMarks(TRUE);  setVTFont( QFont("fixed") );  setColorTable(base_color_table); // init color table  qApp->installEventFilter( this ); //FIXME: see below//  KCursor::setAutoHideCursor( this, true );  // Init DnD ////////////////////////////////////////////////////////////////  currentSession = NULL;//  setAcceptDrops(true); // attempt//  m_drop = new QPopupMenu(this);//  m_drop->insertItem( QString("Paste"), 0);//  m_drop->insertItem( QString("cd"),    1);//  connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int)));  // we need focus so that the auto-hide cursor feature works  setFocus();  setFocusPolicy( WheelFocus );}//FIXME: make proper destructor// Here's a start (David)TEWidget::~TEWidget(){  qApp->removeEventFilter( this );  if (image) free(image);}/* ------------------------------------------------------------------------- *//*                                                                           *//*                             Display Operations                            *//*                                                                           *//* ------------------------------------------------------------------------- *//*    attributed string draw primitive*/void TEWidget::drawAttrStr(QPainter &paint, QRect rect,                           QString& str, ca attr, BOOL pm, BOOL clear){  if (pm && color_table[attr.b].transparent)  {    paint.setBackgroundMode( TransparentMode );    if (clear) erase(rect);  }  else  {    if (blinking)      paint.fillRect(rect, color_table[attr.b].color);    else    {      paint.setBackgroundMode( OpaqueMode );      paint.setBackgroundColor( color_table[attr.b].color );    }  }  if (color_table[attr.f].bold)    paint.setPen(QColor( 0x8F, 0x00, 0x00 ));  else    paint.setPen(color_table[attr.f].color);  paint.drawText(rect.x(),rect.y()+font_a, str);  if (attr.r & RE_UNDERLINE)    paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 );}/*    The image can only be set completely.    The size of the new image may or may not match the size of the widget.*/void TEWidget::setImage(const ca* const newimg, int lines, int columns){ int y,x,len;  const QPixmap* pm = backgroundPixmap();  QPainter paint;  setUpdatesEnabled(FALSE);  paint.begin( this );HCNT("setImage");  QPoint tL  = contentsRect().topLeft();  int    tLx = tL.x();  int    tLy = tL.y();  hasBlinker = FALSE;  int cf  = -1; // undefined  int cb  = -1; // undefined  int cr  = -1; // undefined  int lins = QMIN(this->lines,  QMAX(0,lines  ));  int cols = QMIN(this->columns,QMAX(0,columns));  QChar *disstrU = new QChar[cols];//{ static int cnt = 0; printf("setImage %d\n",cnt++); }  for (y = 0; y < lins; y++)  {    const ca*       lcl = &image[y*this->columns];    const ca* const ext = &newimg[y*columns];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -