QHexEdit::QHexEdit(ExecutableViewer *executableViewer, QWidget *parent) : QAbstractScrollArea(parent), executableViewer(executableViewer) { _chunks = new Chunks(); _undoStack = new UndoStack(_chunks, this); #ifdef Q_OS_WIN32 setFont(QFont("Courier", 10)); #else setFont(QFont("Monospace", 10)); #endif setAddressAreaColor(this->palette().alternateBase().color()); setHighlightingColor(QColor(0xff, 0xff, 0x99, 0xff)); setSelectionColor(this->palette().highlight().color()); connect(&_cursorTimer, SIGNAL(timeout()), this, SLOT(updateCursor())); connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjust())); connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjust())); connect(_undoStack, SIGNAL(indexChanged(int)), this, SLOT(dataChangedPrivate(int))); _cursorTimer.setInterval(500); _cursorTimer.start(); setAddressWidth(4); setAddressArea(true); setAsciiArea(true); setOverwriteMode(true); setHighlighting(true); setReadOnly(false); init(); connect(this, SIGNAL(dataChanged()), executableViewer, SLOT(hexDataChanged())); }
VBoxDbgConsoleOutput::VBoxDbgConsoleOutput(QWidget *pParent/* = NULL*/, const char *pszName/* = NULL*/) : QTextEdit(pParent), m_uCurLine(0), m_uCurPos(0), m_hGUIThread(RTThreadNativeSelf()) { setReadOnly(true); setUndoRedoEnabled(false); setOverwriteMode(false); setPlainText(""); setTextInteractionFlags(Qt::TextBrowserInteraction); setAutoFormatting(QTextEdit::AutoAll); setTabChangesFocus(true); setAcceptRichText(false); /* * Font. * Create actions for font menu items. */ m_pCourierFontAction = new QAction(tr("Courier"), this); m_pCourierFontAction->setCheckable(true); m_pCourierFontAction->setShortcut(Qt::ControlModifier + Qt::Key_D); connect(m_pCourierFontAction, SIGNAL(triggered()), this, SLOT(setFontCourier())); m_pMonospaceFontAction = new QAction(tr("Monospace"), this); m_pMonospaceFontAction->setCheckable(true); m_pMonospaceFontAction->setShortcut(Qt::ControlModifier + Qt::Key_M); connect(m_pMonospaceFontAction, SIGNAL(triggered()), this, SLOT(setFontMonospace())); /* Create action group for grouping of exclusive font menu items. */ QActionGroup *pActionFontGroup = new QActionGroup(this); pActionFontGroup->addAction(m_pCourierFontAction); pActionFontGroup->addAction(m_pMonospaceFontAction); pActionFontGroup->setExclusive(true); /* * Color scheme. * Create actions for color-scheme menu items. */ m_pGreenOnBlackAction = new QAction(tr("Green On Black"), this); m_pGreenOnBlackAction->setCheckable(true); m_pGreenOnBlackAction->setShortcut(Qt::ControlModifier + Qt::Key_1); connect(m_pGreenOnBlackAction, SIGNAL(triggered()), this, SLOT(setColorGreenOnBlack())); m_pBlackOnWhiteAction = new QAction(tr("Black On White"), this); m_pBlackOnWhiteAction->setCheckable(true); m_pBlackOnWhiteAction->setShortcut(Qt::ControlModifier + Qt::Key_2); connect(m_pBlackOnWhiteAction, SIGNAL(triggered()), this, SLOT(setColorBlackOnWhite())); /* Create action group for grouping of exclusive color-scheme menu items. */ QActionGroup *pActionColorGroup = new QActionGroup(this); pActionColorGroup->addAction(m_pGreenOnBlackAction); pActionColorGroup->addAction(m_pBlackOnWhiteAction); pActionColorGroup->setExclusive(true); /* * Set the defaults (which syncs with the menu item checked state). */ setFontCourier(); setColorGreenOnBlack(); NOREF(pszName); }
QHexEditPrivate::QHexEditPrivate(QScrollArea *parent) : QWidget(parent) { _undoStack = new QUndoStack(this); _scrollArea = parent; setAddressWidth(4); setAddressOffset(0); setAddressArea(true); setAsciiArea(true); setHighlighting(true); setOverwriteMode(true); setReadOnly(false); setAddressAreaColor(QColor(0xd4, 0xd4, 0xd4, 0xff)); setHighlightingColor(QColor(0xff, 0xff, 0x99, 0xff)); setSelectionColor(QColor(0x6d, 0x9e, 0xff, 0xff)); setFont(QFont("Courier", 10)); _size = 0; resetSelection(0); setFocusPolicy(Qt::StrongFocus); connect(&_cursorTimer, SIGNAL(timeout()), this, SLOT(updateCursor())); _cursorTimer.setInterval(500); _cursorTimer.start(); }
void DialogOptions::saveOptions() { setLanguage(); setOverwriteMode(); close(); }
QHexEdit::QHexEdit(QWidget *parent) : QAbstractScrollArea(parent) { _chunks = new Chunks(); _undoStack = new UndoStack(_chunks, this); #ifdef Q_OS_WIN32 setFont(QFont("Fixedsys", 12)); #else setFont(QFont("Monospace", 12)); #endif setAddressAreaColor(this->palette().alternateBase().color()); setHighlightingColor(QColor(0, 0, 0, 0xff)); setSelectionColor(QColor(0xff, 0xff, 0, 0xff)); setStyleSheet(QString::fromUtf8("background-color:Black; color:green")); connect(&_cursorTimer, SIGNAL(timeout()), this, SLOT(updateCursor())); connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjust())); connect(_undoStack, SIGNAL(indexChanged(int)), this, SLOT(dataChangedPrivate(int))); _cursorTimer.setInterval(500); _cursorTimer.start(); setAddressWidth(4); setAddressArea(true); setAsciiArea(true); setOverwriteMode(true); setHighlighting(true); setReadOnly(false); init(); }
void GenericCodeEditor::toggleOverwriteMode() { setOverwriteMode(!overwriteMode()); // FIXME: reset cursor to the same position in to force a repaint // there might be a nicer solution for this issue, though setTextCursor(textCursor()); }
ClientTextEdit::ClientTextEdit(QWidget* parent) : QTextEdit(parent) { setReadOnly(true); setOverwriteMode(true); setUndoRedoEnabled(false); setDocumentTitle("mClient"); setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); setTabChangesFocus(false); //_doc->setMaximumBlockCount(Config().scrollbackSize); // max number of lines? document()->setUndoRedoEnabled(false); QTextFrame* frame = document()->rootFrame(); _cursor = frame->firstCursorPosition(); // Default Colors _foregroundColor = Qt::lightGray; _backgroundColor = Qt::black; _blackColor = Qt::darkGray; _redColor = Qt::darkRed; _greenColor = Qt::darkGreen; _yellowColor = Qt::darkYellow; _blueColor = Qt::darkBlue; _magentaColor = Qt::darkMagenta; _cyanColor = Qt::darkCyan; _grayColor = Qt::lightGray; _darkGrayColor = Qt::gray; _brightRedColor = Qt::red; _brightGreenColor = Qt::green; _brightYellowColor = Qt::yellow; _brightBlueColor = Qt::blue; _brightMagentaColor = Qt::magenta; _brightCyanColor = Qt::cyan; _whiteColor = Qt::white; // Default Fonts _serverOutputFont = QFont("Monospace", 10); _inputLineFont = QFont("Monospace", 10); //QApplication::font(); _serverOutputFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias); QTextFrameFormat frameFormat = frame->frameFormat(); frameFormat.setBackground(_backgroundColor); frameFormat.setForeground(_foregroundColor); frame->setFrameFormat(frameFormat); _format = _cursor.charFormat(); setDefaultFormat(_format); _defaultFormat = _format; _cursor.setCharFormat(_format); QFontMetrics fm(_serverOutputFont); setTabStopWidth(fm.width(" ") * 8); // A tab is 8 spaces wide QScrollBar* scrollbar = verticalScrollBar(); scrollbar->setSingleStep(fm.leading()+fm.height()); connect(scrollbar, SIGNAL(sliderReleased()), this, SLOT(scrollBarReleased())); previous = 0; }
int QHexEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QScrollArea::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: currentAddressChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 1: currentSizeChanged((*reinterpret_cast< int(*)>(_a[1]))); break; case 2: dataChanged(); break; case 3: overwriteModeChanged((*reinterpret_cast< bool(*)>(_a[1]))); break; case 4: setAddressWidth((*reinterpret_cast< int(*)>(_a[1]))); break; case 5: setAddressArea((*reinterpret_cast< bool(*)>(_a[1]))); break; case 6: setAsciiArea((*reinterpret_cast< bool(*)>(_a[1]))); break; case 7: setHighlighting((*reinterpret_cast< bool(*)>(_a[1]))); break; default: ; } _id -= 8; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QByteArray*>(_v) = data(); break; case 1: *reinterpret_cast< int*>(_v) = addressOffset(); break; case 2: *reinterpret_cast< QColor*>(_v) = addressAreaColor(); break; case 3: *reinterpret_cast< QColor*>(_v) = highlightingColor(); break; case 4: *reinterpret_cast< bool*>(_v) = overwriteMode(); break; } _id -= 5; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setData(*reinterpret_cast< QByteArray*>(_v)); break; case 1: setAddressOffset(*reinterpret_cast< int*>(_v)); break; case 2: setAddressAreaColor(*reinterpret_cast< QColor*>(_v)); break; case 3: setHighlightingColor(*reinterpret_cast< QColor*>(_v)); break; case 4: setOverwriteMode(*reinterpret_cast< bool*>(_v)); break; } _id -= 5; } else if (_c == QMetaObject::ResetProperty) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 5; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 5; } #endif // QT_NO_PROPERTIES return _id; }
int QTextControl::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 38) qt_static_metacall(this, _c, _id, _a); _id -= 38; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = toHtml(); break; case 1: *reinterpret_cast< bool*>(_v) = overwriteMode(); break; case 2: *reinterpret_cast< bool*>(_v) = acceptRichText(); break; case 3: *reinterpret_cast< int*>(_v) = cursorWidth(); break; case 4: *reinterpret_cast< Qt::TextInteractionFlags*>(_v) = textInteractionFlags(); break; case 5: *reinterpret_cast< bool*>(_v) = openExternalLinks(); break; case 6: *reinterpret_cast< bool*>(_v) = ignoreUnusedNavigationEvents(); break; } _id -= 7; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setHtml(*reinterpret_cast< QString*>(_v)); break; case 1: setOverwriteMode(*reinterpret_cast< bool*>(_v)); break; case 2: setAcceptRichText(*reinterpret_cast< bool*>(_v)); break; case 3: setCursorWidth(*reinterpret_cast< int*>(_v)); break; case 4: setTextInteractionFlags(*reinterpret_cast< Qt::TextInteractionFlags*>(_v)); break; case 5: setOpenExternalLinks(*reinterpret_cast< bool*>(_v)); break; case 6: setIgnoreUnusedNavigationEvents(*reinterpret_cast< bool*>(_v)); break; } _id -= 7; } else if (_c == QMetaObject::ResetProperty) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 7; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 7; } #endif // QT_NO_PROPERTIES return _id; }
Console::Console(QWidget *parent) :QTextEdit(parent) { //text = new QTextEdit(this); setReadOnly(true); setOverwriteMode(false); setFont(QFont("Consolas", 8)); append(tr("ahoj")); append(tr("zdur")); //update(); setFrameStyle(QFrame::NoFrame); }
QHexEdit::QHexEdit(QWidget *parent) : QAbstractScrollArea(parent) { _addressArea = true; _addressWidth = 4; _asciiArea = true; _overwriteMode = true; _highlighting = true; _readOnly = false; _cursorPosition = 0; _lastEventSize = 0; _hexCharsInLine = 47; _bytesPerLine = 16; _editAreaIsAscii = false; _hexCaps = false; _dynamicBytesPerLine = false; _chunks = new Chunks(this); _undoStack = new UndoStack(_chunks, this); #ifdef Q_OS_WIN32 setFont(QFont("Courier", 10)); #else setFont(QFont("Monospace", 10)); #endif setAddressAreaColor(this->palette().alternateBase().color()); setHighlightingColor(QColor(0xff, 0xff, 0x99, 0xff)); setSelectionColor(this->palette().highlight().color()); connect(&_cursorTimer, SIGNAL(timeout()), this, SLOT(updateCursor())); connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjust())); connect(horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(adjust())); connect(_undoStack, SIGNAL(indexChanged(int)), this, SLOT(dataChangedPrivate(int))); _cursorTimer.setInterval(500); _cursorTimer.start(); setAddressWidth(4); setAddressArea(true); setAsciiArea(true); setOverwriteMode(true); setHighlighting(true); setReadOnly(false); init(); }
DisplayWidget::DisplayWidget(QWidget *parent) : QTextEdit(parent) { setReadOnly(true); setTabChangesFocus(true); setOverwriteMode(true); setAlignment(Qt::AlignCenter); resetLine(); append(tr("Welcome to the Free Group Calculator!\n")); setAlignment(Qt::AlignLeft); setFontFamily("Monaco"); setFontPointSize(12.0); append(tr("[%1 %2]:>").arg(Input).arg(lineNumber)); moveCursor(QTextCursor::End); }
QHexEditPrivate::QHexEditPrivate(QScrollArea *parent) : QWidget(parent) { _scrollArea = parent; setAddressWidth(4); setAddressOffset(0); setAddressArea(true); setAsciiArea(true); setHighlighting(true); setOverwriteMode(true); setAddressAreaColor(QColor(Qt::lightGray).lighter(110)); setHighlightingColor(QColor(Qt::yellow).lighter(160)); setFont(QFont("Mono", 10)); connect(&_cursorTimer, SIGNAL(timeout()), this, SLOT(updateCursor())); _cursorTimer.setInterval(500); _cursorTimer.start(); setFocusPolicy(Qt::StrongFocus); _size = -1; }
void HaiQTextEdit::process_key(QKeyEvent event) { if ((event.text()!="")&&(textCursor().selectedText().count()<=1)) { ///this is to avoid spreading of marker highlighting bool holdmodified=document()->isModified(); QTextCharFormat format=currentCharFormat(); format.clearBackground(); setCurrentCharFormat(format); document()->setModified(holdmodified); } if ((event.key()==Qt::Key_Tab)||(event.key()==Qt::Key_Backtab)||(event.text()=="\t")) { process_tab(event); } else if (event.key()==Qt::Key_Insert && QApplication::keyboardModifiers() == Qt::NoModifier) { setOverwriteMode(!overwriteMode()); } else if ((event.key()==Qt::Key_Home)&&((event.modifiers()==Qt::NoModifier)||(event.modifiers()==Qt::ShiftModifier))) { bool shift_key=(event.modifiers()==Qt::ShiftModifier); QTextCursor cursor=textCursor(); int col=cursor.columnNumber(); QString txt=cursor.block().text(); if (shift_key) cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::KeepAnchor); else cursor.movePosition(QTextCursor::StartOfLine); int ct=0; while ((ct<txt.count())&&((txt[ct]==' ')||(txt[ct]=='\t'))) { if (shift_key) cursor.movePosition(QTextCursor::Right,QTextCursor::KeepAnchor); else cursor.movePosition(QTextCursor::Right); ct++; } int col2=cursor.columnNumber(); if (col2==col) { //moved nowhere if (shift_key) cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::KeepAnchor); else cursor.movePosition(QTextCursor::StartOfLine); } setTextCursor(cursor); } else if (event.key()==Qt::Key_Backspace) { process_backspace(); return; } else if ((event.key()==Qt::Key_Space)&&(event.modifiers()==Qt::ControlModifier)) { return; // don't process a space, because Ctrl+Space is for completion } else { QTextEdit::keyPressEvent(&event); } if ((event.key()==Qt::Key_Enter)||(event.key()==Qt::Key_Return)) { indent_to_previous_line(); QTextCursor cursor=textCursor(); do_marker_highlighting(cursor); QString line=cursor.block().previous().text(); QStringList symbols=split_into_symbols(line); if ((symbols.count()>0)&& ( (symbols[symbols.count()-1]=="{") || (((symbols[symbols.count()-1]!=";"))&&((symbols[0]=="if") || (symbols[0]=="else") || (symbols[0]=="while") || (symbols[0]=="do") || (symbols[0]=="for"))) ) ) { QString line2=cursor.block().text(); QStringList symbols2=split_into_symbols(line2); if ((symbols2.count()==0)||(symbols2[0]!="}")) //only indent if there is not a "{" starting the line cursor.insertText(tab_text(cursor)); } //kind of a hack if (!blocks_highlighted_for_braces.isEmpty()) { blocks_highlighted_for_braces << textCursor().block(); } } if (event.text()=="}") { QTextCursor cursor=textCursor(); QString line=cursor.block().text(); QStringList symbols=split_into_symbols(line); if (symbols.count()==1) { //unindent to last brace QTextBlock block=cursor.block(); bool found=false; int braces_level=1; while ((!found)&&(block.isValid())) { block=block.previous(); QString line2=block.text(); QStringList symbols=split_into_symbols(line2); for (int j=symbols.count()-1; j>=0; j--) { if (symbols[j]=="{") braces_level--; if (symbols[j]=="}") braces_level++; if (braces_level==0) found=true; } } if (found) { QString line2=block.text(); for (int j=0; j<line.count(); j++) cursor.deletePreviousChar(); int j=0; while ((j<line2.count())&&((line2[j]==' ')||(line2[j]=='\t'))) { cursor.insertText(QString(line2[j])); j++; } cursor.insertText("}"); } } } if ((event.text()==")")||(event.text()=="}")/*||(event.text()==">")*/) { highlight_braces(event.text(),true); } if ((event.text()=="(")||(event.text()=="{")/*||(event.text()=="<")*/) { highlight_braces(event.text(),false); } }
VBoxDbgConsoleOutput::VBoxDbgConsoleOutput(QWidget *pParent/* = NULL*/, IVirtualBox *a_pVirtualBox /* = NULL */, const char *pszName/* = NULL*/) : QTextEdit(pParent), m_uCurLine(0), m_uCurPos(0), m_hGUIThread(RTThreadNativeSelf()), m_pVirtualBox(a_pVirtualBox) { setReadOnly(true); setUndoRedoEnabled(false); setOverwriteMode(false); setPlainText(""); setTextInteractionFlags(Qt::TextBrowserInteraction); setAutoFormatting(QTextEdit::AutoAll); setTabChangesFocus(true); setAcceptRichText(false); /* * Create actions for color-scheme menu items. */ m_pGreenOnBlackAction = new QAction(tr("Green On Black"), this); m_pGreenOnBlackAction->setCheckable(true); m_pGreenOnBlackAction->setShortcut(Qt::ControlModifier + Qt::Key_1); m_pGreenOnBlackAction->setData((int)kGreenOnBlack); connect(m_pGreenOnBlackAction, SIGNAL(triggered()), this, SLOT(sltSelectColorScheme())); m_pBlackOnWhiteAction = new QAction(tr("Black On White"), this); m_pBlackOnWhiteAction->setCheckable(true); m_pBlackOnWhiteAction->setShortcut(Qt::ControlModifier + Qt::Key_2); m_pBlackOnWhiteAction->setData((int)kBlackOnWhite); connect(m_pBlackOnWhiteAction, SIGNAL(triggered()), this, SLOT(sltSelectColorScheme())); /* Create action group for grouping of exclusive color-scheme menu items. */ QActionGroup *pActionColorGroup = new QActionGroup(this); pActionColorGroup->addAction(m_pGreenOnBlackAction); pActionColorGroup->addAction(m_pBlackOnWhiteAction); pActionColorGroup->setExclusive(true); /* * Create actions for font menu items. */ m_pCourierFontAction = new QAction(tr("Courier"), this); m_pCourierFontAction->setCheckable(true); m_pCourierFontAction->setShortcut(Qt::ControlModifier + Qt::Key_D); m_pCourierFontAction->setData((int)kFontType_Courier); connect(m_pCourierFontAction, SIGNAL(triggered()), this, SLOT(sltSelectFontType())); m_pMonospaceFontAction = new QAction(tr("Monospace"), this); m_pMonospaceFontAction->setCheckable(true); m_pMonospaceFontAction->setShortcut(Qt::ControlModifier + Qt::Key_M); m_pMonospaceFontAction->setData((int)kFontType_Monospace); connect(m_pMonospaceFontAction, SIGNAL(triggered()), this, SLOT(sltSelectFontType())); /* Create action group for grouping of exclusive font menu items. */ QActionGroup *pActionFontGroup = new QActionGroup(this); pActionFontGroup->addAction(m_pCourierFontAction); pActionFontGroup->addAction(m_pMonospaceFontAction); pActionFontGroup->setExclusive(true); /* * Create actions for font size menu. */ uint32_t const uDefaultFontSize = font().pointSize(); m_pActionFontSizeGroup = new QActionGroup(this); for (uint32_t i = 0; i < RT_ELEMENTS(m_apFontSizeActions); i++) { char szTitle[32]; RTStrPrintf(szTitle, sizeof(szTitle), s_uMinFontSize + i != uDefaultFontSize ? "%upt" : "%upt (default)", s_uMinFontSize + i); m_apFontSizeActions[i] = new QAction(tr(szTitle), this); m_apFontSizeActions[i]->setCheckable(true); m_apFontSizeActions[i]->setData(i + s_uMinFontSize); connect(m_apFontSizeActions[i], SIGNAL(triggered()), this, SLOT(sltSelectFontSize())); m_pActionFontSizeGroup->addAction(m_apFontSizeActions[i]); } /* * Set the defaults (which syncs with the menu item checked state). */ /* color scheme: */ com::Bstr bstrColor; HRESULT hrc = m_pVirtualBox ? m_pVirtualBox->GetExtraData(com::Bstr("DbgConsole/ColorScheme").raw(), bstrColor.asOutParam()) : E_FAIL; if ( SUCCEEDED(hrc) && bstrColor.compareUtf8("blackonwhite", com::Bstr::CaseInsensitive) == 0) setColorScheme(kBlackOnWhite, false /*fSaveIt*/); else setColorScheme(kGreenOnBlack, false /*fSaveIt*/); /* font: */ com::Bstr bstrFont; hrc = m_pVirtualBox ? m_pVirtualBox->GetExtraData(com::Bstr("DbgConsole/Font").raw(), bstrFont.asOutParam()) : E_FAIL; if ( SUCCEEDED(hrc) && bstrFont.compareUtf8("monospace", com::Bstr::CaseInsensitive) == 0) setFontType(kFontType_Monospace, false /*fSaveIt*/); else setFontType(kFontType_Courier, false /*fSaveIt*/); /* font size: */ com::Bstr bstrFontSize; hrc = m_pVirtualBox ? m_pVirtualBox->GetExtraData(com::Bstr("DbgConsole/FontSize").raw(), bstrFontSize.asOutParam()) : E_FAIL; if (SUCCEEDED(hrc)) { com::Utf8Str strFontSize(bstrFontSize); uint32_t uFontSizePrf = strFontSize.strip().toUInt32(); if ( uFontSizePrf - s_uMinFontSize < (uint32_t)RT_ELEMENTS(m_apFontSizeActions) && uFontSizePrf != uDefaultFontSize) setFontSize(uFontSizePrf, false /*fSaveIt*/); } NOREF(pszName); }
int eInput::event(int event, void *data, void *data2) { switch (event) { case evtPaint: { gPainter &painter = *(gPainter*)data2; ePtr<eWindowStyle> style; getStyle(style); eWidget::event(event, data, data2); ePtr<eTextPara> para = new eTextPara(eRect(0, 0, size().width(), size().height())); std::string text; int cursor = -1; if (m_content) m_content->getDisplay(text, cursor); eDebug("cursor is %d", cursor); para->setFont(m_font); para->renderString(text.empty()?0:text.c_str(), 0); int glyphs = para->size(); if (m_have_focus) { if (m_mode && cursor < glyphs) { /* in overwrite mode, when not at end of line, invert the current cursor position. */ para->setGlyphFlag(cursor, GS_INVERT); eRect bbox = para->getGlyphBBox(cursor); bbox = eRect(bbox.left(), 0, bbox.width(), size().height()); painter.fill(bbox); } else { /* otherwise, insert small cursor */ eRect bbox; if (cursor < glyphs) { bbox = para->getGlyphBBox(cursor); bbox = eRect(bbox.left()-1, 0, 2, size().height()); } else if (cursor) { bbox = para->getGlyphBBox(cursor - 1); bbox = eRect(bbox.right(), 0, 2, size().height()); } else { bbox = eRect(0, 0, 2, size().height()); } painter.fill(bbox); } } painter.renderPara(para, ePoint(0, 0)); return 0; } case evtAction: if (isVisible()) { if ((long)data == ASCII_ACTIONS) { if ((long)data2 == gotAsciiCode) { if (m_content) { extern int getPrevAsciiCode(); // defined in enigma.cpp return m_content->haveKey(getPrevAsciiCode(), m_mode); } } } else if ((long)data == INPUT_ACTIONS) { switch((long)data2) { case moveLeft: if (m_content) m_content->moveCursor(eInputContent::dirLeft); break; case moveRight: if (m_content) m_content->moveCursor(eInputContent::dirRight); break; case moveHome: if (m_content) m_content->moveCursor(eInputContent::dirHome); break; case moveEnd: if (m_content) m_content->moveCursor(eInputContent::dirEnd); break; case deleteForward: if (m_content) m_content->deleteChar(eInputContent::deleteForward); break; case deleteBackward: if (m_content) m_content->deleteChar(eInputContent::deleteBackward); break; case toggleOverwrite: setOverwriteMode(!m_mode); break; case accept: changed(); mayKillFocus(); } return 1; } } return 0; case evtKey: { long key = (long)data; long flags = (long)data2; if (m_content && !(flags & 1)) // only make/repeat, no break return m_content->haveKey(key, m_mode); break; } case evtFocusGot: { eDebug("focus got in %p", this); ePtr<eActionMap> ptr; eActionMap::getInstance(ptr); ptr->bindAction("InputActions", 0, INPUT_ACTIONS, this); ptr->bindAction("AsciiActions", 0, ASCII_ACTIONS, this); m_have_focus = 1; eRCInput::getInstance()->setKeyboardMode(eRCInput::kmAscii); // fixme. we should use a style for this. setBackgroundColor(gRGB(64, 64, 128)); invalidate(); break; } case evtFocusLost: { eDebug("focus lostin %p", this); ePtr<eActionMap> ptr; eActionMap::getInstance(ptr); ptr->unbindAction(this, INPUT_ACTIONS); ptr->unbindAction(this, ASCII_ACTIONS); m_have_focus = 0; if (m_content) m_content->validate(); eRCInput::getInstance()->setKeyboardMode(eRCInput::kmNone); clearBackgroundColor(); invalidate(); break; } default: break; } return eWidget::event(event, data, data2); }
void GenericCodeEditor::toggleOverwriteMode() { setOverwriteMode(!overwriteMode()); }
void QHexEditPrivate::keyPressEvent(QKeyEvent *event) { int charX = (_cursorX - _xPosHex) / _charWidth; int posX = (charX / 3) * 2 + (charX % 3); int posBa = (_cursorY / _charHeight) * BYTES_PER_LINE + posX / 2; /*****************************************************************************/ /* Cursor movements */ /*****************************************************************************/ if (event->matches(QKeySequence::MoveToNextChar)) { setCursorPos(_cursorPosition + 1); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousChar)) { setCursorPos(_cursorPosition - 1); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToEndOfLine)) { setCursorPos(_cursorPosition | (2 * BYTES_PER_LINE -1)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToStartOfLine)) { setCursorPos(_cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE))); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousLine)) { setCursorPos(_cursorPosition - (2 * BYTES_PER_LINE)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToNextLine)) { setCursorPos(_cursorPosition + (2 * BYTES_PER_LINE)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToNextPage)) { setCursorPos(_cursorPosition + (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousPage)) { setCursorPos(_cursorPosition - (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToEndOfDocument)) { setCursorPos(_data.size() * 2); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToStartOfDocument)) { setCursorPos(0); resetSelection(_cursorPosition); } /*****************************************************************************/ /* Select commands */ /*****************************************************************************/ if (event->matches(QKeySequence::SelectAll)) { resetSelection(0); setSelection(2*_data.length() + 1); } if (event->matches(QKeySequence::SelectNextChar)) { int pos = _cursorPosition + 1; setCursorPos(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousChar)) { int pos = _cursorPosition - 1; setSelection(pos); setCursorPos(pos); } if (event->matches(QKeySequence::SelectEndOfLine)) { int pos = _cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE)) + (2 * BYTES_PER_LINE); setCursorPos(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectStartOfLine)) { int pos = _cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE)); setCursorPos(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousLine)) { int pos = _cursorPosition - (2 * BYTES_PER_LINE); setCursorPos(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectNextLine)) { int pos = _cursorPosition + (2 * BYTES_PER_LINE); setCursorPos(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectNextPage)) { int pos = _cursorPosition + (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE); setCursorPos(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousPage)) { int pos = _cursorPosition - (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE); setCursorPos(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectEndOfDocument)) { int pos = _data.size() * 2; setCursorPos(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectStartOfDocument)) { int pos = 0; setCursorPos(pos); setSelection(pos); } /*****************************************************************************/ /* Edit Commands */ /*****************************************************************************/ if (!_readOnly) { /* Hex input */ int key = int(event->text()[0].toAscii()); if ((key>='0' && key<='9') || (key>='a' && key <= 'f')) { if (getSelectionBegin() != getSelectionEnd()) { posBa = getSelectionBegin(); remove(posBa, getSelectionEnd() - posBa); setCursorPos(2*posBa); resetSelection(2*posBa); } // If insert mode, then insert a byte if (_overwriteMode == false) if ((charX % 3) == 0) { insert(posBa, char(0)); adjust(); } // Change content if (_data.size() > 0) { QByteArray hexValue = _data.mid(posBa, 1).toHex(); if ((charX % 3) == 0) hexValue[0] = key; else hexValue[1] = key; replace(posBa, 1, QByteArray().fromHex(hexValue)); setCursorPos(_cursorPosition + 1); resetSelection(_cursorPosition); } } /* Cut & Paste */ if (event->matches(QKeySequence::Cut)) { QString result = QString(); for (int idx = getSelectionBegin(); idx < getSelectionEnd(); idx++) { result += _data.mid(idx, 1).toHex() + " "; if ((idx % 16) == 15) result.append("\n"); } remove(getSelectionBegin(), getSelectionEnd()); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(result); setCursorPos(getSelectionBegin()); resetSelection(getSelectionBegin()); } if (event->matches(QKeySequence::Paste)) { QClipboard *clipboard = QApplication::clipboard(); QByteArray ba = QByteArray().fromHex(clipboard->text().toLatin1()); insert(_cursorPosition / 2, ba); setCursorPos((_cursorPosition + (2 * ba.length()) + 1) & 0xfffffffe); resetSelection(getSelectionBegin()); } /* Delete char */ if (event->matches(QKeySequence::Delete)) { if (getSelectionBegin() != getSelectionEnd()) { posBa = getSelectionBegin(); remove(posBa, getSelectionEnd() - posBa); setCursorPos(2*posBa); resetSelection(2*posBa); } else { remove(posBa); } } /* Backspace */ if ((event->key() == Qt::Key_Backspace) && (event->modifiers() == Qt::NoModifier)) { if (getSelectionBegin() != getSelectionEnd()) { posBa = getSelectionBegin(); remove(posBa, getSelectionEnd() - posBa); setCursorPos(2*posBa); resetSelection(2*posBa); } else { remove(posBa - 1); setCursorPos(_cursorPosition - 2); } } } if (event->matches(QKeySequence::Copy)) { QString result = QString(); for (int idx = getSelectionBegin(); idx < getSelectionEnd(); idx++) { result += _data.mid(idx, 1).toHex() + " "; if ((idx % 16) == 15) result.append('\n'); } QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(result); } // Switch between insert/overwrite mode if ((event->key() == Qt::Key_Insert) && (event->modifiers() == Qt::NoModifier)) { setOverwriteMode(!_overwriteMode); setCursorPos(_cursorPosition); } _scrollArea->ensureVisible(_cursorX, _cursorY + _charHeight/2, 3, _charHeight/2 + 2); update(); }
// ********************************************************************** Handle events void QHexEdit::keyPressEvent(QKeyEvent *event) { // Cursor movements if (event->matches(QKeySequence::MoveToNextChar)) { setCursorPosition(_cursorPosition + 1); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousChar)) { setCursorPosition(_cursorPosition - 1); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToEndOfLine)) { setCursorPosition(_cursorPosition | (2 * BYTES_PER_LINE -1)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToStartOfLine)) { setCursorPosition(_cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE))); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousLine)) { setCursorPosition(_cursorPosition - (2 * BYTES_PER_LINE)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToNextLine)) { setCursorPosition(_cursorPosition + (2 * BYTES_PER_LINE)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToNextPage)) { setCursorPosition(_cursorPosition + (((_rowsShown - 1) * 2 * BYTES_PER_LINE))); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousPage)) { setCursorPosition(_cursorPosition - (((_rowsShown - 1) * 2 * BYTES_PER_LINE))); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToEndOfDocument)) { setCursorPosition(_chunks->size() * 2); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToStartOfDocument)) { setCursorPosition(0); resetSelection(_cursorPosition); } // Select commands if (event->matches(QKeySequence::SelectAll)) { resetSelection(0); setSelection(2*_chunks->size() + 1); } if (event->matches(QKeySequence::SelectNextChar)) { qint64 pos = _cursorPosition + 1; setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousChar)) { qint64 pos = _cursorPosition - 1; setSelection(pos); setCursorPosition(pos); } if (event->matches(QKeySequence::SelectEndOfLine)) { qint64 pos = _cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE)) + (2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectStartOfLine)) { qint64 pos = _cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE)); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousLine)) { qint64 pos = _cursorPosition - (2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectNextLine)) { qint64 pos = _cursorPosition + (2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectNextPage)) { qint64 pos = _cursorPosition + (((viewport()->height() / _pxCharHeight) - 1) * 2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousPage)) { qint64 pos = _cursorPosition - (((viewport()->height() / _pxCharHeight) - 1) * 2 * BYTES_PER_LINE); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectEndOfDocument)) { qint64 pos = _chunks->size() * 2; setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectStartOfDocument)) { qint64 pos = 0; setCursorPosition(pos); setSelection(pos); } // Edit Commands if (!_readOnly) { if ((QApplication::keyboardModifiers() == Qt::NoModifier) || (QApplication::keyboardModifiers() == Qt::KeypadModifier)) { /* Hex input */ int key = int(event->text()[0].toLatin1()); if ((key>='0' && key<='9') || (key>='a' && key <= 'f')) { if (getSelectionBegin() != getSelectionEnd()) { if (_overwriteMode) { qint64 len = getSelectionEnd() - getSelectionBegin(); replace(getSelectionBegin(), (int)len, QByteArray((int)len, char(0))); } else { remove(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()); _bPosCurrent = getSelectionBegin(); } setCursorPosition(2*_bPosCurrent); resetSelection(2*_bPosCurrent); } // If insert mode, then insert a byte if (_overwriteMode == false) if ((_cursorPosition % 2) == 0) insert(_bPosCurrent, char(0)); // Change content if (_chunks->size() > 0) { QByteArray hexValue = _chunks->data(_bPosCurrent, 1).toHex(); if ((_cursorPosition % 2) == 0) hexValue[0] = key; else hexValue[1] = key; replace(_bPosCurrent, QByteArray().fromHex(hexValue)[0]); setCursorPosition(_cursorPosition + 1); resetSelection(_cursorPosition); } } } /* Cut */ if (event->matches(QKeySequence::Cut)) { QByteArray ba = _chunks->data(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()).toHex(); for (qint64 idx = 32; idx < ba.size(); idx +=33) ba.insert(idx, "\n"); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(ba); if (_overwriteMode) { qint64 len = getSelectionEnd() - getSelectionBegin(); replace(getSelectionBegin(), (int)len, QByteArray((int)len, char(0))); } else { remove(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()); } setCursorPosition(2*getSelectionBegin()); resetSelection(2*getSelectionBegin()); } /* Paste */ if (event->matches(QKeySequence::Paste)) { QClipboard *clipboard = QApplication::clipboard(); QByteArray ba = QByteArray().fromHex(clipboard->text().toLatin1()); if (_overwriteMode) replace(_bPosCurrent, ba.size(), ba); else insert(_bPosCurrent, ba); setCursorPosition(_cursorPosition + 2 * ba.size()); resetSelection(getSelectionBegin()); } /* Delete char */ if (event->matches(QKeySequence::Delete)) { if (getSelectionBegin() != getSelectionEnd()) { _bPosCurrent = getSelectionBegin(); if (_overwriteMode) { QByteArray ba = QByteArray(getSelectionEnd() - getSelectionBegin(), char(0)); replace(_bPosCurrent, ba.size(), ba); } else { remove(_bPosCurrent, getSelectionEnd() - getSelectionBegin()); } } else { if (_overwriteMode) replace(_bPosCurrent, char(0)); else remove(_bPosCurrent, 1); } setCursorPosition(2 * _bPosCurrent); resetSelection(2 * _bPosCurrent); } /* Backspace */ if ((event->key() == Qt::Key_Backspace) && (event->modifiers() == Qt::NoModifier)) { if (getSelectionBegin() != getSelectionEnd()) { _bPosCurrent = getSelectionBegin(); setCursorPosition(2 * _bPosCurrent); if (_overwriteMode) { QByteArray ba = QByteArray(getSelectionEnd() - getSelectionBegin(), char(0)); replace(_bPosCurrent, ba.size(), ba); } else { remove(_bPosCurrent, getSelectionEnd() - getSelectionBegin()); } resetSelection(2 * _bPosCurrent); } else { bool behindLastByte = false; if ((_cursorPosition / 2) == _chunks->size()) behindLastByte = true; _bPosCurrent -= 1; if (_overwriteMode) replace(_bPosCurrent, char(0)); else remove(_bPosCurrent, 1); if (!behindLastByte) _bPosCurrent -= 1; setCursorPosition(2 * _bPosCurrent); resetSelection(2 * _bPosCurrent); } } /* undo */ if (event->matches(QKeySequence::Undo)) { undo(); } /* redo */ if (event->matches(QKeySequence::Redo)) { redo(); } } /* Copy */ if (event->matches(QKeySequence::Copy)) { QByteArray ba = _chunks->data(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()).toHex(); for (qint64 idx = 32; idx < ba.size(); idx +=33) ba.insert(idx, "\n"); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(ba); } // Switch between insert/overwrite mode if ((event->key() == Qt::Key_Insert) && (event->modifiers() == Qt::NoModifier)) { setOverwriteMode(!overwriteMode()); setCursorPosition(_cursorPosition); } // Refresh Event if ((event->key() == Qt::Key_F5)) executableViewer->getMainWindow()->refresh(); refresh(); }
void QHexEditPrivate::keyPressEvent(QKeyEvent *event) { bool down = false; int charX = (_cursorX - _xPosHex) / _charWidth; int posX = (charX / 3) * 2 + (charX % 3); int posBa = (_cursorY / _charHeight) * BYTES_PER_LINE + posX / 2; int key = int(event->text()[0].toAscii()); if ((key>='0' && key<='9') || (key>='a' && key <= 'f')) { // insert char if (_overwriteMode == false) if ((charX % 3) == 0) { insert(posBa, char(0)); adjust(); } if (_data.size() > 0) { QByteArray hexValue = _data.mid(posBa, 1).toHex(); if ((charX % 3) == 0) hexValue[0] = key; else hexValue[1] = key; _data.replace(posBa, 1, QByteArray().fromHex(hexValue)); emit dataChanged(); setCursorPos(_cursorPosition + 1); down = true; } } // delete char if (event->matches(QKeySequence::Delete)) remove(posBa); if (event->key() == Qt::Key_Backspace) { remove(posBa - 1); setCursorPos(_cursorPosition - 2); } // handle other function keys if (event->key() == Qt::Key_Insert) { setOverwriteMode(!_overwriteMode); setCursorPos(_cursorPosition); } if (event->matches(QKeySequence::MoveToNextChar)) { setCursorPos(_cursorPosition + 1); down = true; } if (event->matches(QKeySequence::MoveToPreviousChar)) setCursorPos(_cursorPosition - 1); if (event->matches(QKeySequence::MoveToStartOfLine)) setCursorPos(_cursorPosition - (_cursorPosition % (2 * BYTES_PER_LINE))); if (event->matches(QKeySequence::MoveToEndOfLine)) setCursorPos(_cursorPosition | (2 * BYTES_PER_LINE -1)); if (event->matches(QKeySequence::MoveToPreviousLine)) setCursorPos(_cursorPosition - (2 * BYTES_PER_LINE)); if (event->matches(QKeySequence::MoveToPreviousPage)) setCursorPos(_cursorPosition - (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE)); if (event->matches(QKeySequence::MoveToStartOfDocument)) setCursorPos(0); if (event->matches(QKeySequence::MoveToNextLine)) { setCursorPos(_cursorPosition + (2 * BYTES_PER_LINE)); down = true; } if (event->matches(QKeySequence::MoveToEndOfDocument)) { setCursorPos(_data.size() * 2); down = true; } if (event->matches(QKeySequence::MoveToNextPage)) { setCursorPos(_cursorPosition + (((_scrollArea->viewport()->height() / _charHeight) - 1) * 2 * BYTES_PER_LINE)); down = true; } // when we move downwards, we have to go a little further if (down) _scrollArea->ensureVisible(_cursorX, _cursorY, 3, 3 + _charHeight); else _scrollArea->ensureVisible(_cursorX, _cursorY, 3, 3); update(); }
int QPlainTextEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QAbstractScrollArea::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 25) qt_static_metacall(this, _c, _id, _a); _id -= 25; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< bool*>(_v) = tabChangesFocus(); break; case 1: *reinterpret_cast< QString*>(_v) = documentTitle(); break; case 2: *reinterpret_cast< bool*>(_v) = isUndoRedoEnabled(); break; case 3: *reinterpret_cast< LineWrapMode*>(_v) = lineWrapMode(); break; case 4: *reinterpret_cast< bool*>(_v) = isReadOnly(); break; case 5: *reinterpret_cast< QString*>(_v) = toPlainText(); break; case 6: *reinterpret_cast< bool*>(_v) = overwriteMode(); break; case 7: *reinterpret_cast< int*>(_v) = tabStopWidth(); break; case 8: *reinterpret_cast< int*>(_v) = cursorWidth(); break; case 9: *reinterpret_cast< Qt::TextInteractionFlags*>(_v) = textInteractionFlags(); break; case 10: *reinterpret_cast< int*>(_v) = blockCount(); break; case 11: *reinterpret_cast< int*>(_v) = maximumBlockCount(); break; case 12: *reinterpret_cast< bool*>(_v) = backgroundVisible(); break; case 13: *reinterpret_cast< bool*>(_v) = centerOnScroll(); break; } _id -= 14; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setTabChangesFocus(*reinterpret_cast< bool*>(_v)); break; case 1: setDocumentTitle(*reinterpret_cast< QString*>(_v)); break; case 2: setUndoRedoEnabled(*reinterpret_cast< bool*>(_v)); break; case 3: setLineWrapMode(*reinterpret_cast< LineWrapMode*>(_v)); break; case 4: setReadOnly(*reinterpret_cast< bool*>(_v)); break; case 5: setPlainText(*reinterpret_cast< QString*>(_v)); break; case 6: setOverwriteMode(*reinterpret_cast< bool*>(_v)); break; case 7: setTabStopWidth(*reinterpret_cast< int*>(_v)); break; case 8: setCursorWidth(*reinterpret_cast< int*>(_v)); break; case 9: setTextInteractionFlags(*reinterpret_cast< Qt::TextInteractionFlags*>(_v)); break; case 11: setMaximumBlockCount(*reinterpret_cast< int*>(_v)); break; case 12: setBackgroundVisible(*reinterpret_cast< bool*>(_v)); break; case 13: setCenterOnScroll(*reinterpret_cast< bool*>(_v)); break; } _id -= 14; } else if (_c == QMetaObject::ResetProperty) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 14; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 14; } #endif // QT_NO_PROPERTIES return _id; }
// ********************************************************************** Handle events void QHexEdit::keyPressEvent(QKeyEvent *event) { // Cursor movements if (event->matches(QKeySequence::MoveToNextChar)) { qint64 pos = _cursorPosition + 1; if (_editAreaIsAscii) pos += 1; setCursorPosition(pos); resetSelection(pos); } if (event->matches(QKeySequence::MoveToPreviousChar)) { qint64 pos = _cursorPosition - 1; if (_editAreaIsAscii) pos -= 1; setCursorPosition(pos); resetSelection(pos); } if (event->matches(QKeySequence::MoveToEndOfLine)) { qint64 pos = _cursorPosition - (_cursorPosition % (2 * _bytesPerLine)) + (2 * _bytesPerLine) - 1; setCursorPosition(pos); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToStartOfLine)) { qint64 pos = _cursorPosition - (_cursorPosition % (2 * _bytesPerLine)); setCursorPosition(pos); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousLine)) { setCursorPosition(_cursorPosition - (2 * _bytesPerLine)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToNextLine)) { setCursorPosition(_cursorPosition + (2 * _bytesPerLine)); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToNextPage)) { setCursorPosition(_cursorPosition + (((_rowsShown - 1) * 2 * _bytesPerLine))); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToPreviousPage)) { setCursorPosition(_cursorPosition - (((_rowsShown - 1) * 2 * _bytesPerLine))); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToEndOfDocument)) { setCursorPosition(_chunks->size() * 2 ); resetSelection(_cursorPosition); } if (event->matches(QKeySequence::MoveToStartOfDocument)) { setCursorPosition(0); resetSelection(_cursorPosition); } // Select commands if (event->matches(QKeySequence::SelectAll)) { resetSelection(0); setSelection(2 * _chunks->size() + 1); } if (event->matches(QKeySequence::SelectNextChar)) { qint64 pos = _cursorPosition + 1; if (_editAreaIsAscii) pos += 1; setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousChar)) { qint64 pos = _cursorPosition - 1; if (_editAreaIsAscii) pos -= 1; setSelection(pos); setCursorPosition(pos); } if (event->matches(QKeySequence::SelectEndOfLine)) { qint64 pos = _cursorPosition - (_cursorPosition % (2 * _bytesPerLine)) + (2 * _bytesPerLine) - 1; setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectStartOfLine)) { qint64 pos = _cursorPosition - (_cursorPosition % (2 * _bytesPerLine)); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousLine)) { qint64 pos = _cursorPosition - (2 * _bytesPerLine); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectNextLine)) { qint64 pos = _cursorPosition + (2 * _bytesPerLine); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectNextPage)) { qint64 pos = _cursorPosition + (((viewport()->height() / _pxCharHeight) - 1) * 2 * _bytesPerLine); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectPreviousPage)) { qint64 pos = _cursorPosition - (((viewport()->height() / _pxCharHeight) - 1) * 2 * _bytesPerLine); setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectEndOfDocument)) { qint64 pos = _chunks->size() * 2; setCursorPosition(pos); setSelection(pos); } if (event->matches(QKeySequence::SelectStartOfDocument)) { qint64 pos = 0; setCursorPosition(pos); setSelection(pos); } // Edit Commands if (!_readOnly) { /* Cut */ if (event->matches(QKeySequence::Cut)) { QByteArray ba = _chunks->data(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()).toHex(); for (qint64 idx = 32; idx < ba.size(); idx +=33) ba.insert(idx, "\n"); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(ba); if (_overwriteMode) { qint64 len = getSelectionEnd() - getSelectionBegin(); replace(getSelectionBegin(), (int)len, QByteArray((int)len, char(0))); } else { remove(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()); } setCursorPosition(2 * getSelectionBegin()); resetSelection(2 * getSelectionBegin()); } else /* Paste */ if (event->matches(QKeySequence::Paste)) { QClipboard *clipboard = QApplication::clipboard(); QByteArray ba = QByteArray().fromHex(clipboard->text().toLatin1()); if (_overwriteMode) { ba = ba.left(std::min<qint64>(ba.size(), (_chunks->size() - _bPosCurrent))); replace(_bPosCurrent, ba.size(), ba); } else insert(_bPosCurrent, ba); setCursorPosition(_cursorPosition + 2 * ba.size()); resetSelection(getSelectionBegin()); } else /* Delete char */ if (event->matches(QKeySequence::Delete)) { if (getSelectionBegin() != getSelectionEnd()) { _bPosCurrent = getSelectionBegin(); if (_overwriteMode) { QByteArray ba = QByteArray(getSelectionEnd() - getSelectionBegin(), char(0)); replace(_bPosCurrent, ba.size(), ba); } else { remove(_bPosCurrent, getSelectionEnd() - getSelectionBegin()); } } else { if (_overwriteMode) replace(_bPosCurrent, char(0)); else remove(_bPosCurrent, 1); } setCursorPosition(2 * _bPosCurrent); resetSelection(2 * _bPosCurrent); } else /* Backspace */ if ((event->key() == Qt::Key_Backspace) && (event->modifiers() == Qt::NoModifier)) { if (getSelectionBegin() != getSelectionEnd()) { _bPosCurrent = getSelectionBegin(); setCursorPosition(2 * _bPosCurrent); if (_overwriteMode) { QByteArray ba = QByteArray(getSelectionEnd() - getSelectionBegin(), char(0)); replace(_bPosCurrent, ba.size(), ba); } else { remove(_bPosCurrent, getSelectionEnd() - getSelectionBegin()); } resetSelection(2 * _bPosCurrent); } else { bool behindLastByte = false; if ((_cursorPosition / 2) == _chunks->size()) behindLastByte = true; _bPosCurrent -= 1; if (_overwriteMode) replace(_bPosCurrent, char(0)); else remove(_bPosCurrent, 1); if (!behindLastByte) _bPosCurrent -= 1; setCursorPosition(2 * _bPosCurrent); resetSelection(2 * _bPosCurrent); } } else /* undo */ if (event->matches(QKeySequence::Undo)) { undo(); } else /* redo */ if (event->matches(QKeySequence::Redo)) { redo(); } else if ((QApplication::keyboardModifiers() == Qt::NoModifier) || (QApplication::keyboardModifiers() == Qt::KeypadModifier) || (QApplication::keyboardModifiers() == Qt::ShiftModifier) || (QApplication::keyboardModifiers() == (Qt::AltModifier | Qt::ControlModifier)) || (QApplication::keyboardModifiers() == Qt::GroupSwitchModifier)) { /* Hex and ascii input */ int key; if (_editAreaIsAscii) key = (uchar)event->text()[0].toLatin1(); else key = int(event->text()[0].toLower().toLatin1()); if ((((key >= '0' && key <= '9') || (key >= 'a' && key <= 'f')) && _editAreaIsAscii == false) || (key >= ' ' && _editAreaIsAscii)) { if (getSelectionBegin() != getSelectionEnd()) { if (_overwriteMode) { qint64 len = getSelectionEnd() - getSelectionBegin(); replace(getSelectionBegin(), (int)len, QByteArray((int)len, char(0))); } else { remove(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()); _bPosCurrent = getSelectionBegin(); } setCursorPosition(2 * _bPosCurrent); resetSelection(2 * _bPosCurrent); } // If insert mode, then insert a byte if (_overwriteMode == false) if ((_cursorPosition % 2) == 0) insert(_bPosCurrent, char(0)); // Change content if (_chunks->size() > 0) { char ch = key; if (!_editAreaIsAscii){ QByteArray hexValue = _chunks->data(_bPosCurrent, 1).toHex(); if ((_cursorPosition % 2) == 0) hexValue[0] = key; else hexValue[1] = key; ch = QByteArray().fromHex(hexValue)[0]; } replace(_bPosCurrent, ch); if (_editAreaIsAscii) setCursorPosition(_cursorPosition + 2); else setCursorPosition(_cursorPosition + 1); resetSelection(_cursorPosition); } } } } /* Copy */ if (event->matches(QKeySequence::Copy)) { QByteArray ba = _chunks->data(getSelectionBegin(), getSelectionEnd() - getSelectionBegin()).toHex(); for (qint64 idx = 32; idx < ba.size(); idx +=33) ba.insert(idx, "\n"); QClipboard *clipboard = QApplication::clipboard(); clipboard->setText(ba); } // Switch between insert/overwrite mode if ((event->key() == Qt::Key_Insert) && (event->modifiers() == Qt::NoModifier)) { setOverwriteMode(!overwriteMode()); setCursorPosition(_cursorPosition); } // switch from hex to ascii edit if (event->key() == Qt::Key_Tab && !_editAreaIsAscii){ _editAreaIsAscii = true; setCursorPosition(_cursorPosition); } // switch from ascii to hex edit if (event->key() == Qt::Key_Backtab && _editAreaIsAscii){ _editAreaIsAscii = false; setCursorPosition(_cursorPosition); } refresh(); }