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

📄 qeditor.cpp

📁 Gambas is a graphical development environment based on a Basic interpreter, like Visual Basic. It us
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    p.setPen(color[Normal]);    //p.drawText(x, y, w, h, Qt::ExpandTabs, s.mid(pos));    p.drawText(x, y, s.mid(pos));  }}void QEditorRow::drawNormal(QPainter & p, int x, int y, int w, int h, QColor color[]){  y += p.fontMetrics().ascent();  p.setPen(color[Normal]);  p.drawText(x, y, s);}QColor QEditor::default_color[NUM_COLORS] = {  Qt::black,  Qt::white,  Qt::yellow,  Qt::yellow,  Qt::yellow,  Qt::white,  Qt::cyan,  Qt::green,  Qt::gray,  Qt::red,  Qt::yellow,  QColor(0xFF, 0x80, 0x00),  Qt::blue,  Qt::yellow,  QColor(0x10, 0x10, 0x10),};bool QEditor::init = false;QAsciiDict<char> QEditor::firstDict(15, false, true);QAsciiDict<char> QEditor::keywordDict(127, false, true);QAsciiDict<char> QEditor::subrDict(127, false, true);QAsciiDict<char> QEditor::typeDict(31, false, true);static void initDictWith(QAsciiDict<char> &dict, const char *init[]){  int i;  uint j;  const char *p;  char key[32];  for (i = 0; ; i++)  {    p = init[i];    if (p == 0)      break;    strcpy(key, p);    for (j = 0; j < strlen(key); j++)      key[j] = GB.tolower(key[j]);    dict.insert(key, p);  }}void QEditor::initDict(void){  static const char *first[] = {    "CLASS","INHERITS", //"IMPLEMENTS",    NULL    };  static const char *keyword[] = {    "FUNCTION","STRUCT","CONST","PRIVATE","PUBLIC",    "STATIC","EVENT","AS","DIM","NEW","PROCEDURE","SUB",    "PARAM","OPTIONAL","OUTPUT","RETURN",    "DO","LOOP","WHILE","UNTIL","REPEAT","WEND","IF","THEN","ELSE","ENDIF","END","FOR",    "TO","STEP","NEXT","SELECT","CASE","EXIT","BREAK","CONTINUE","GOTO","ME","LAST","TRY",    "FINALLY","CATCH","WITH","TRUE","FALSE","SWAP","NULL","EXTERN","EACH","IN","DEFAULT",    "STOP","QUIT","PRINT","INPUT","READ","WRITE","OPEN","CLOSE","SEEK","APPEND","CREATE",    "BINARY","DIRECT","LINE","FLUSH","NOT","AND","OR","XOR","MOD","IS","LIKE","WAIT","EXEC",    "SHELL","KILL","RENAME","INC","DEC","MKDIR","RMDIR","WATCH","USE","BIG","LITTLE","COPY",    "PROPERTY","RAISE","LINK","ERROR",    NULL    };  static const char *type[] = {    "Boolean","Byte","Date","Float","Integer","Long","Short","String","Variant",    "Class","Collection","Application","Error","File","Process","Object","System",    "Boolean[]","Byte[]","Short[]","Integer[]","String[]","Date[]","Float[]",    "Variant[]","Object[]",    NULL    };  static const char *subr[] = {    "Left","Left$","Mid","Mid$","Right","Right$","Len","Space","Space$","String","String$",    "Trim","Trim$","Upper","Upper$","Lower","Lower$","UCase","UCase$","LCase","LCase$",    "Chr","Chr$","Asc","Instr","RInstr","Subst","Subst$","Compare","Replace","Replace$",    "Split","Abs","Int","Frac","Log","Exp","Sqr","Sin","Cos","Tan","Atn","ATan","Asn",    "ASin","Acs","ACos","Deg","Rad","Log10","Sinh","Cosh","Tanh","Asnh","ASinh","Acsh",    "ACosh","Atnh","ATanh","Sgn","Fix","Pi","Round","Randomize","Rnd","Min","Max","BClr",    "BSet","BTst","BChg","Shl","Shr","Rol","Ror","CBool","CByte","CShort","CInt",    "CInteger","CLng","CLong","CFloat","CDate","CStr","CString","Bin","Bin$","Hex","Hex$",    "Val","Str","Str$","Format","Format$","Timer","Now","Year","Month","Day","Hour",    "Minute","Second","WeekDay","Date","Time","Shell","Beep","Wait",    "Eof","Lof","Seek", "Exist","Stat","Dir","Dir$","IsBoolean","Boolean?",    "IsByte","Byte?","IsShort","Short?","IsInteger","Integer?","IsLong","Long?","IsFloat",    "Float?","IsDate","Date?","IsString","String?","IsNull","Null?","IsObject","Object?",    "IsNumber","Number?","TypeOf","If","IIf","Choose","LTrim","LTrim$",    "RTrim","RTrim$","Eval","New","Conv","Conv$","Temp","Temp$","Array","IsDir","Dir?",    "Access",    NULL    };  if (init)    return;  initDictWith(keywordDict, keyword);  initDictWith(subrDict, subr);  initDictWith(typeDict, type);  initDictWith(firstDict, first);}QColor QEditor::getColor(int elt){  if (elt < 0 || elt >= NUM_COLORS)    return QColor(0, 0, 0);  else    return color[elt];}void QEditor::setColor(int elt, QColor col){  if (elt >= 0 && elt < NUM_COLORS)  {    color[elt] = col;    //qDebug("color[%d] = #%lX", elt, col.rgb());    if (elt == QEditorRow::Background)      viewport()->setPaletteBackgroundColor(col);  }}long QEditor::toPos(int row, int col){  int i;  long pos;  row = QMAX( QMIN( row, numLines() - 1), 0 );  col = QMAX( QMIN( col,  lineLength( row )), 0 );  if (row == 0)	  return QMIN(col, lineLength(0));  pos = 0;	for(i = 0; i < row ; i++)  {    pos += lineLength(i);    if (isEndOfParagraph(i))      pos++;	}	pos += col;  return pos;}void QEditor::fromPos(long pos, int *row, int *col){  int l = 0;  if (pos <= 0)  {    *row = 0;    *col = 0;    return;  }  for (l = 0; l < numLines(); l++)  {    if (pos <= lineLength(l))    {      *row = l;      *col = pos;      return;    }    pos -= lineLength(l);    if (isEndOfParagraph(l))      pos--;  }  *row = l - 1;  *col = lineLength(l - 1);}void QEditor::getSelection(long *start, long *length){  bool sel;  int line1, col1, line2, col2;  sel = getMarkedRegion(&line1, &col1, &line2, &col2 );  if (!sel)  {    getCursorPosition(&line1, &col1);    *start = toPos(line1, col1);    *length = 0;    return;  }  *start = toPos(line1, col1);  *length = toPos(line2, col2) - *start;}void QEditor::setSelection(long start, long length){  int line1, col1, line2, col2;  fromPos(start, &line1, &col1);  if (length <= 0)  {    deselect();    setCursorPosition(line1, col1);    return;  }  fromPos(start + length, &line2, &col2);  setMarkedRegion(line1, col1, line2, col2 );}void QEditor::setLineType(int row, int type){  contents->at(row)->type = type;  repaintCell(row, 0, false);}int QEditor::findNextBreakpoint(int row){  for(;;)  {    if ((unsigned int)row >= contents->count())      return -1;    if (contents->at(row)->type & QEditorRow::TypeBreakpoint)      return row;    row++;  }}/////////////////////////////////////////////////////////////////////////////////class QEditorCommand{public:  enum Commands  { Invalid, Begin, End, Insert, Delete, InsertTab, DeleteTab };  virtual ~ QEditorCommand()  {  };  virtual Commands type()  {    return Invalid;  };  virtual int terminator()  {    return 0;  }  virtual bool merge(QEditorCommand *)  {    return false;  }};class QBeginCommand:public QEditorCommand{public:  QBeginCommand()  {  }  int terminator()  {    return 1;  }  Commands type()  {    return Begin;  };};class QEndCommand:public QEditorCommand{public:  QEndCommand()  {  }  int terminator()  {    return -1;  }  Commands type()  {    return End;  };  bool merge(QEditorCommand * other)  {    return (other->type() == Begin);  }};// QEditorUndoRedo methodsclass QDelTextCmd:public QEditorCommand{public:  int mOffset;  QString mStr;  // have to handle deletion of current selection  QDelTextCmd(int offset, const QString & str):mOffset(offset), mStr(str)  {  }  Commands type()  {    return Delete;  };  bool merge(QEditorCommand * other)  {    if (other->type() == type())    {      QDelTextCmd *o = (QDelTextCmd *) other;      if (mOffset + int (mStr.length()) == o->mOffset)      {        o->mStr.prepend(mStr);        o->mOffset = mOffset;        return true;      }    }    return false;  }};class QInsTextCmd:public QDelTextCmd{public:  QInsTextCmd(int offset, const QString & str):QDelTextCmd(offset, str)  {  }  Commands type()  {    return Insert;  };  bool merge(QEditorCommand * other)  {    if (other->type() == type())    {      QInsTextCmd *o = (QInsTextCmd *) other;      if (mOffset == o->mOffset + int (o->mStr.length()))      {        o->mStr += mStr;        return true;      }    }    return false;  }};class QDelTabCmd:public QEditorCommand{public:  int line1, line2;  QDelTabCmd(int l1, int l2): line1(l1), line2(l2)  {  }  Commands type()  {    return DeleteTab;  };  bool merge(QEditorCommand * other)  {    return false;  }};class QInsTabCmd:public QDelTabCmd{public:  QInsTabCmd(int l1, int l2): QDelTabCmd(l1, l2)  {  }  Commands type()  {    return InsertTab;  };  bool merge(QEditorCommand * other)  {    return false;  }};// NOT REVISED/*=  \class QMultiLineEdit qeditor.h  \brief The QMultiLineEdit widget is a simple editor for inputting text.  \ingroup advanced  The QMultiLineEdit widget provides multiple line text input and display.  It is intended for moderate amounts of text. There are no arbitrary  limitations, but if you try to handle megabytes of data, performance  will suffer.  Per default, the edit widget does not perform any word  wrapping. This can be adjusted by calling setWordWrap(). Both  dynamic wrapping according to the visible width or a fixed number of  character or pixels is supported.  The widget can be used to display text by calling setReadOnly(true)  The default key bindings are described in keyPressEvent(); they cannot  be customized except by inheriting the class.  <img src=qmlined-m.png> <img src=qmlined-w.png>*//*static const char *const arrow_xpm[] = {  "     8     8        2            1",  ". c None",  "# c #000000",  "........",  "..####..",  "..#####.",  ".....##.",  ".#..###.",  ".#####..",  ".####...",  ".#####.."};*/enum{  IdUndo,  IdRedo,#ifndef QT_NO_CLIPBOARD  IdCut,  IdCopy,  IdPaste,  IdPasteSpecial,#endif  IdClear,  IdSelectAll,  IdCount};struct QMultiLineData{  QMultiLineData():isHandlingEvent(false),    edited(false),    maxLineWidth(0),    maxlines(-1),    maxlinelen(-1),    maxlen(-1),    //wordwrap(QEditor::NoWrap), wrapcol(-1), wrappolicy(QEditor::AtWhiteSpace),    // This doesn't use font bearings, as textWidthWithTabs does that.    // This is just an aesthetics value.    // It should probably be QMAX(0,3-fontMetrics().minLeftBearing()) though,    // as bearings give some border anyway.    lr_marg(6),    marg_extra(0),    //echomode(QEditor::Normal),    val(0),    dnd_primed(false), dnd_forcecursor(false), undo(true), undodepth(256),    blinkLevel(0)    {      undoList.setAutoDelete(true);      redoList.setAutoDelete(true);      clearChartable();    }  bool isHandlingEvent;  bool edited;  int maxLineWidth;  int scrollTime;  int scrollAccel;  int numlines;  int maxlines;  int maxlinelen;  int maxlen;  //QEditor::WordWrap wordwrap;  int wrapcol;  //QEditor::WrapPolicy wrappolicy;  int lr_marg;  int marg_extra;  //QEditor::EchoMode echomode;  const QValidator *val;  bool dnd_primed;              // If true, user has pressed  bool dnd_forcecursor;         // If true show cursor for DND feedback,  // even if !hasFocus()  QPtrList < QEditorCommand > undoList;  QPtrList < QEditorCommand > redoList;  bool undo;  int undodepth;  short chartable[256];  void clearChartable()  {    int i = 256;    while (i)      chartable[--i] = 0;  }  QPixmap arrow;  QPoint dnd_startpos;  QTimer *blinkTimer, *scrollTimer;  int blinkLevel;#ifndef QT_NO_DRAGANDDROP  QTimer *dnd_timer;#endif};#define CLEAR_UNDO {d->undoList.clear(); emit undoAvailable( false );\    d->redoList.clear(); emit redoAvailable( false );}void QEditor::addUndoCmd(QEditorCommand * c){  if (d->undoList.isEmpty())  {    emit undoAvailable(true);  }  else if (c->merge(d->undoList.last()))  {    delete c;    return;  }  if (int (d->undoList.count()) >= d->undodepth)    d->undoList.removeFirst();  d->undoList.append(c);  if (!d->redoList.isEmpty())  {    d->redoList.clear();    emit redoAvailable(false);  }}void QEditor::addRedoCmd(QEditorCommand * c){  if (d->redoList.isEmpty())    emit redoAvailable(true);  d->redoList.append(c);}void QEditor::colorize(int line){  QString old, s;  QEditorRow *r = contents->at(line);  if (!useColor)    return;  old = r->s;  r->colorize();  if (old.length() != r->s.length())  {    s = old;    old = r->s;    r->s = s;    setTextLine(line, old);  }}static const int initialScrollTime = 50;        // mark text scroll timestatic const int initialScrollAccel = 3;        // mark text scroll accel (0=fastest)static const int scroll_margin = 16;    // auto-scroll edge in DND#define WORD_WRAP false#define DYNAMIC_WRAP false

⌨️ 快捷键说明

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