1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
|
#ifndef CODEEDITOR_H
#define CODEEDITOR_H
#include <QPlainTextEdit>
#include <QObject>
#include <QGroupBox>
#include <QLineEdit>
#include <QToolButton>
#include <QToolButton>
#include <QCheckBox>
#include <QGridLayout>
#include <QComboBox>
#include <QGraphicsScene>
#include "highlighter.h"
#include "multitextcursor.h"
#if defined Q_WS_WIN || defined Q_OS_WIN
#define FONTFAM "Lucida Console"
#elif defined Q_WS_MAC || defined Q_OS_MAC
#define FONTFAM "Monaco"
#else
#define FONTFAM "Droid Sans Mono"
#endif
QT_BEGIN_NAMESPACE
class QPaintEvent;
class QResizeEvent;
class QSize;
class QCompleter;
class QWidget;
class ChGL;
class PlayOpenGL;
QT_END_NAMESPACE
class LineNumberArea;
class AfixHighlightArea;
static inline bool isPrintableText(const QString &text) {
return !text.isEmpty() && (text.at(0).isPrint() || text.at(0) == QLatin1Char('\t'));
}
class CodeEditor : public QPlainTextEdit {
Q_OBJECT
public:
CodeEditor(QWidget *parent = 0);
~CodeEditor();
QList<int> sfac;
QStringList sfacsmbl;
QStringList easf;
QStringList xasf;
int sortierWeise;
int midCursorpos;
bool ListFile;
bool uCanSeeMe;
bool dark;
double smin;
double smax;
QString unitAlt, unitNeu;
Highlighter *highlighter;
void setCompleter(QCompleter *c);
QCompleter *completer() const;
QStringList blocks;
QList<int> errorInLine;
void lineNumberAreaPaintEvent(QPaintEvent *event);
void afixHighlightAreaPaintEvent(QPaintEvent *event);
void hoverLineNumber(QMouseEvent *event);
int lineNumberAreaWidth();
void diffTo(QString org);
QList<int> parenthesis;
QList<int> parenthesis2;
QList<bool> comment;
QList<double> fv;
int fvMinLine;
QGroupBox *suchbox;
QLineEdit *searchLE, *replace;
QToolButton *hidesearch;
QToolButton *prev,*next,*replaceButton,*replacePButton,*replaceAButton;
QCheckBox *wholeLine;
QGridLayout *slt;
QComboBox *resiFinder;
QString dispFromWave(int an);
QString sortLabelList(CEnvironment &asymm, MyAtom &tatze);
void searchchanged(bool current,bool back);
MultiTextCursor multiTextCursor() const;
void setMultiTextCursor(const MultiTextCursor &cursor);
QRect cursorUpdateRect(const MultiTextCursor &cursor);
void doSetTextCursor1(const QTextCursor &cursor);
void doSetTextCursor(const QTextCursor &cursor, bool keepMultiSelection);
void startCursorFlashTimer();
void resetCursorFlashTimer();
QBasicTimer m_cursorFlashTimer;
bool m_cursorVisible;
void updateCursorSelections();
void moveCursor(QTextCursor::MoveOperation operation, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
bool cursorMoveKeyEvent(QKeyEvent *e);
void handleHomeKey(bool anchor, bool block);
void handleBackspaceKey();
struct BlockSelection{
int blockNumber;
int column;
int anchorBlockNumber;
int anchorColumn;
};
QList<BlockSelection> m_blockSelections;
QList<QTextCursor> generateCursorsForBlockSelection(const BlockSelection &blockSelection);
void initBlockSelection();
void clearBlockSelection();
void handleMoveBlockSelection(QTextCursor::MoveOperation op);
struct CursorData
{
QTextLayout *layout;
QPointF offset;
int pos;
QPen pen;
};
struct PaintEventData{
PaintEventData(CodeEditor *editor, QPaintEvent *event, QPointF offset)
: offset(offset)
, viewportRect(editor->viewport()->rect())
, eventRect(event->rect())
, doc(editor->document())
, documentLayout(qobject_cast<QPlainTextDocumentLayout *>(doc->documentLayout()))
, documentWidth(int(doc->size().width()))
, textCursor(editor->textCursor())
, textCursorBlock(textCursor.block())
, isEditable(!editor->isReadOnly())
{ }
QPointF offset;
const QRect viewportRect;
const QRect eventRect;
qreal rightMargin;
const QTextDocument *doc;
QPlainTextDocumentLayout *documentLayout;
const int documentWidth;
const QTextCursor textCursor;
const QTextBlock textCursorBlock;
const bool isEditable;
const QTextCharFormat searchScopeFormat;
const QTextCharFormat searchResultFormat;
const QTextCharFormat visualWhitespaceFormat;
const QTextCharFormat ifdefedOutFormat;
QAbstractTextDocumentLayout::PaintContext context;
QTextBlock visibleCollapsedBlock;
QPointF visibleCollapsedBlockOffset;
QTextBlock block;
QList<CursorData> cursors;
};
struct PaintEventBlockData{
QRectF boundingRect;
QVector<QTextLayout::FormatRange> selections;
QTextLayout *layout;
int position;
int length;
};
void setupBlockLayout(const PaintEventData &data, QPainter &painter, PaintEventBlockData &blockData) const;
void setupSelections(const PaintEventData &data, PaintEventBlockData &blockData) const;
void addCursorsPosition(PaintEventData &data, QPainter &painter, const PaintEventBlockData &blockData) const;
void paintCursor(const PaintEventData &data, QPainter &painter) const;
static bool blockContainsCursor(const PaintEventBlockData &blockData, const QTextCursor &cursor);
static CursorData generateCursorData(const int cursorPos,
const PaintEventData &data,
const PaintEventBlockData &blockData,
QPainter &painter);
signals:
void findInStructure(const QString &);
void openIncludeFile(const QString &);
void electInStructure(const QString &);
void deleteSelected();
void saveMe(bool spell, bool loadafter);
void updateLabel();
protected:
void resizeEvent(QResizeEvent *event);
bool viewportEvent(QEvent *event);
void keyPressEvent(QKeyEvent *e);
void mouseMoveEvent(QMouseEvent *);
void mousePressEvent(QMouseEvent *);
void timerEvent(QTimerEvent *);
void focusInEvent(QFocusEvent *e);
void contextMenuEvent(QContextMenuEvent *event);
void focusOutEvent(QFocusEvent *e);
void paintEvent(QPaintEvent *);
public slots:
void testCpd();
void mpaste();
void mcut();
void plotSFAC();
void slotCursorPositionChanged();
void updateCursorPosition();
void handleCBstates(int state);
void vis(bool b){ uCanSeeMe=b; }
void fitWidth();
void restoreMinimumWidth();
void updateLineNumberAreaWidth(int newBlockCount);
void insertAnis();
void insertActa();
void insertCONF();
void insertList4();
void insertList6();
void insertBind();
void insertEXTI();
void insertFree();
void insertElectronSFACs();
void insertXRaySFACs();
void findResi(int);
void findText();
void hideSearch();
void replaceAll();
void replaceNext();
void replacePrev();
void showSearch();
void changeSortierWeise(QAction* action);
void sortAtoms();
void sortAtoms(CEnvironment &as);
void sortSelectedRegion();
void expandGreaterThan();
void findNext();
void findPrev();
void weedEmptySfacs();
void updateUnit();
void dispFromWave();
void resiFinderDestroyed();
void decreaseEdtiorFont();
void increaseEdtiorFont();
void jumpToError();
void jumpToAtom(int index);
void omitsome(const QString &s);
void insertDFIX(double value, double esd, QList<MyAtom> selected, QString resiSpec="");
void insertDANG(double value, double esd, QList<MyAtom> selected, QString resiSpec="");
void insertFLAT(double esd, QList<MyAtom> selected, QString resiSpec="");
void insertEXYZ(QList<MyAtom> selected, QString resiSpec="");
void insertEADP(QList<MyAtom> selected, QString resiSpec="");
void insertDELU(double esd1, double esd2, QList<MyAtom> selected, QString resiSpec="");
void insertSIMU(double esd1, double esd2, double dmax, QList<MyAtom> selected, QString resiSpec="");
void insertISOR(double esd1, double esd2, QList<MyAtom> selected, QString resiSpec="");
void insertRIGU(double esd1, double esd2, QList<MyAtom> selected, QString resiSpec="");
void insertCHIV(double vol, double esd1, QList<MyAtom> selected, QString resiSpec="");
void insertANIS(QList<MyAtom> selected);
void updateLineNumberArea(const QRect &, int);
void updateAfix();
void updateWght();
void insertCompletion(const QString &completion);
void searchInStructure();
void openAnIncludeFile();
void selectInStructure();
void lineNumberToggled(QMouseEvent *event);
void remark(int line);
void toggleRemarks();
void setgl(PlayOpenGL *g){
chgl=g;
}
private:
QString selectedRestraintsAtoms(QString buffer, QList<MyAtom> selected, QString resiSpec, bool exclude_H=false);
QString textUnderCursor() const;
QWidget *lineNumberArea;
QCompleter *c;
QWidget *afixHighlightArea;
PlayOpenGL *chgl;
bool cbhandled=true;
MultiTextCursor m_cursors;
bool startMouseMoveCursor1;
double cromerMann(double sintl, double a1, double b1, double a2, double b2, double a3, double b3, double a4, double b4, double c);
const QRegularExpression spaces = QRegularExpression("\\s+");
const QRegularExpression comments = QRegularExpression("^REM",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression onlydigits = QRegularExpression("^[0-9]+$");
const QRegularExpression nodigits = QRegularExpression("\\D");
const QRegularExpression digits = QRegularExpression("\\d+");
const QRegularExpression plusfloat = QRegularExpression("[.0-9]+");
const QRegularExpression grossbuch = QRegularExpression("^[A-Z]");
const QRegularExpression onlysmall = QRegularExpression("^[a-z]$");
const QRegularExpression linecontinue = QRegularExpression("^[0-9]+");
const QRegularExpression listinst = QRegularExpression("\nLIST",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression unitinst = QRegularExpression("^UNIT",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression actainst = QRegularExpression("^ACTA",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression sfacinst = QRegularExpression("^SFAC",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression hklfinst = QRegularExpression("^HKLF",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression extiinst = QRegularExpression("^EXTI",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression confinst = QRegularExpression("^CONF",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression omithklinst = QRegularExpression("^OMIT\\s+\\d+\\s+\\d+\\s+\\d+");
const QRegularExpression afix0inst = QRegularExpression("^AFIX\\s+0",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression afixinst = QRegularExpression("^AFIX\\s+\\d+",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression part0inst = QRegularExpression("^PART\\s+0",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression partinst = QRegularExpression("^PART\\s+[-0-9]{1,}",QRegularExpression::CaseInsensitiveOption);
const QRegularExpression startsmall = QRegularExpression("^[a-z]+");
};
class AfixHighlightArea : public QWidget{
public:
AfixHighlightArea(CodeEditor *editor) : QWidget(editor){
codeEditor = editor;
}
QSize sizeHint() const {
return QSize(5,0);
}
protected:
void paintEvent(QPaintEvent *event){
codeEditor->afixHighlightAreaPaintEvent(event);
}
void mouseMoveEvent(QMouseEvent *event){
codeEditor->hoverLineNumber(event);
}
private:
CodeEditor *codeEditor;
};
class LineNumberArea : public QWidget{
public:
LineNumberArea(CodeEditor *editor) : QWidget(editor) {
codeEditor = editor;
}
QSize sizeHint() const {
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
protected:
void paintEvent(QPaintEvent *event) {
codeEditor->lineNumberAreaPaintEvent(event);
}
void mousePressEvent ( QMouseEvent * event ){
codeEditor->lineNumberToggled(event);
}
void mouseMoveEvent(QMouseEvent *event){
codeEditor->hoverLineNumber(event);
}
private:
CodeEditor *codeEditor;
};
class CheckBox : public QCheckBox{
public:
CheckBox(QGraphicsScene * scene, const QString & text, QWidget * parent = 0);
protected:
void hoverEnter(QHoverEvent *event);
void hoverLeave(QHoverEvent *event);
void hoverMove(QHoverEvent *event);
bool event(QEvent *event){
switch (event->type()){
case QEvent::HoverEnter:
hoverEnter(static_cast<QHoverEvent*>(event));
return true;
break;
case QEvent::HoverLeave:
hoverLeave(static_cast<QHoverEvent*>(event));
return true;
break;
case QEvent::HoverMove:
hoverMove(static_cast<QHoverEvent*>(event));
return true;
break;
default:
break;
}
return QWidget::event(event);
}
private:
QGraphicsScene *scene;
};
#endif
|