void VoxOxToolTipLineEdit::keyPressEvent(QKeyEvent * event) { if (!_cleared) { clearLineEdit(); repaintPrimaryColor(); } if (event->key()==Qt::Key_Return || event->key()==Qt::Key_Enter) {//if key pressed was return or enter if(!QLineEdit::text().isEmpty()){ updateMessageText(QLineEdit::text()); QLineEdit::setText(_shortMessage); currentTextChanged(text()); } QLineEdit::keyPressEvent(event); changeFocusToParent();//VOXOX CHANGE by Rolando - 2009.05.22 - method to send focus to another widget when mouse leaves the lineedit } else{//if key pressed was not return or enter key int cursorPositionValue = cursorPosition();//VOXOX CHANGE by Rolando - 2009.06.02 - gets current Cursor Position bool isShortMessage = QLineEdit::text() == _shortMessage;//VOXOX CHANGE by Rolando - 2009.06.02 - we need to check if current text is equal to _shortMessage int intSelectedStart = -1; QString text; if(hasSelectedText()){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is selected text text = selectedText();//VOXOX CHANGE by Rolando - 2009.06.02 - gets selected text intSelectedStart = selectionStart();//VOXOX CHANGE by Rolando - 2009.06.02 - gets position where selection starts } QLineEdit::setText(_message);//VOXOX CHANGE by Rolando - 2009.06.02 - sets long message if(intSelectedStart >= 0){//VOXOX CHANGE by Rolando - 2009.06.02 - if there is a text selected setSelection(intSelectedStart, text.length());//VOXOX CHANGE by Rolando - 2009.06.02 - as we set the long message in lineedit, we need to set the text was selected } else{ //VOXOX CHANGE by Rolando - 2009.06.02 - if there is not a text selected if(isShortMessage){//VOXOX CHANGE by Rolando - 2009.06.02 - if we had currentText equal to _shortMessage //VOXOX CHANGE by Rolando - 2009.10.13 if(cursorPositionValue == _shortMessage.length()){//VOXOX CHANGE by Rolando - 2009.06.02 - if cursor position is the rightest pos allowed setCursorPosition(_message.length());//VOXOX CHANGE by Rolando - 2009.06.02 - we move the cursor to rightest position after we changed the current text by _message } else{ //VOXOX CHANGE by Rolando - 2009.06.02 - if cursor position is not the rightest pos allowed setCursorPosition(cursorPositionValue);//VOXOX CHANGE by Rolando - 2009.06.02 - if cursor position is not the rightest pos allowed } } else{ //VOXOX CHANGE by Rolando - 2009.06.02 - if we had not currentText equal to _shortMessage setCursorPosition(cursorPositionValue);//VOXOX CHANGE by Rolando - 2009.06.02 - we move the cursor to old position + 1 } } QLineEdit::keyPressEvent(event);//processes event - it should be processed before update _shortMessage and _message variables updateMessageText(QLineEdit::text());//VOXOX CHANGE by Rolando - 2009.06.02 - we update the short and long messages } keyPressedSignal(event->key()); }
void TEWidget::emitSelection() // Paste Clipboard by simulating keypress events { #ifndef QT_NO_CLIPBOARD QString text = QApplication::clipboard()->text(); if ( ! text.isNull() ) { text.replace(QRegExp("\n"), "\r"); //QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); QKeyEvent e(QEvent::KeyPress, 0, Qt::NoModifier, text); emit keyPressedSignal(&e); // expose as a big fat keypress event emit clearSelectionSignal(); } #endif }
List::List(Layer& layer): Widget(layer), m_editable(false), m_editing(false), m_offset(0), m_maxOffset(0), m_selection(NO_ITEM), m_scroller(nullptr), m_entry(nullptr) { areaChangedSignal().connect(*this, &List::onAreaChanged); buttonClickedSignal().connect(*this, &List::onMouseButton); keyPressedSignal().connect(*this, &List::onKey); scrolledSignal().connect(*this, &List::onScroll); m_scroller = new Scroller(layer, VERTICAL); m_scroller->setValueRange(0.f, 1.f); m_scroller->setPercentage(1.f); m_scroller->valueChangedSignal().connect(*this, &List::onValueChanged); addChild(*m_scroller); onAreaChanged(*this); }
Scroller::Scroller(Layer& layer, Orientation orientation): Widget(layer), m_minValue(0.f), m_maxValue(1.f), m_value(0.f), m_percentage(0.5f), m_reference(0.f), m_orientation(orientation) { const float em = layer.drawer().currentEM(); if (m_orientation == HORIZONTAL) setSize(vec2(em * 10.f, em * 1.5f)); else setSize(vec2(em * 1.5f, em * 10.f)); keyPressedSignal().connect(*this, &Scroller::onKey); buttonClickedSignal().connect(*this, &Scroller::onMouseButton); scrolledSignal().connect(*this, &Scroller::onScroll); dragBegunSignal().connect(*this, &Scroller::onDragBegun); dragMovedSignal().connect(*this, &Scroller::onDragMoved); setDraggable(true); }
void TEWidget::inputMethodEvent( QInputMethodEvent * e) // is a virtual function { static int c=0; qDebug("in TEWidget::inputMethodEvent : %d", c++); static QString preedit_string; preedit_string=e->preeditString(); if (!e->commitString().isEmpty()) { qDebug("!e->commitString() : %d", e->commitString().length() ); static QString commit_string; commit_string=e->commitString(); const char *ch=commit_string.toStdString().c_str(); for (int i=0 ; i < commit_string.toStdString().length() ; ++i) qDebug("ch[i] : %x", ch[i]); //input_text_->setText(preedit_string+"*"+commit_string); input_text_->clear(); //input_text_->setText("test"+commit_string); //input_text_->set_text("commit"+e->commitString() ); //input_text_->show(); //onRcvBlock(); // QKeyEvent ( Type type, int key, Qt::KeyboardModifiers modifiers, const QString & text = QString(), bool autorep = false, ushort count = 1 ) #if 0 int encode=get_encoding(); QTextDecoder* decoder; QTextCodec *codec; QByteArray qba; const QChar * qchar; if ( get_input_encoding() == DS::BIG5) { codec = QTextCodec::codecForName("BIG5"); //qDebug("(encoding==DS::BIG5)"); //qDebug("(encoding==DS::UTF8)"); qDebug("in encode==DS::BIG5"); } if ( get_input_encoding() == DS::UTF8) { codec = QTextCodec::codecForName("UTF-8"); //qchar= e->commitString().unicode(); //codec = QTextCodec::codecForName("UTF-8"); //qDebug("in encode==DS::UTF8"); //qba=e->commitString().toUtf8(); } QByteArray ba = codec->fromUnicode(ev->text()); char *ba_data=ba.data(); emit sndBlock(ba_data ,strlen(ba_data)); //for (int i=0 ; i < e->commitString().length() ; ++i) //qDebug("qchar[i] : %x", qchar[i].unicode () ); //qDebug("qchar[i] : %x", i); decoder = codec->makeDecoder(); const char *c_str= e->commitString().toStdString().c_str(); qDebug("c_str len: %d", strlen(c_str)); for (int i=0 ; i < strlen(c_str) ; ++i) qDebug("c_str[i]: %x", c_str[i]); commit_string=decoder->toUnicode(c_str, strlen(c_str)); #endif //QString str(qba); QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier, commit_string); //actSel=0; // Key stroke implies a screen update, so TEWidget won't // know where the current selection is. emit keyPressedSignal(ke); // expose //preedit_string=""; //commit_string=""; //sleep(3); } else { qDebug("e->commitString()"); #if 0 if (!preedit_string.isEmpty()) { input_text_->set_text("preedit"+preedit_string); input_text_->show(); } #endif } #if 0 if (!preedit_string.isEmpty()) { input_text_->set_text(preedit_string); input_text_->show(); } #endif }
bool TEWidget::eventFilter( QObject *obj, QEvent *e ) { #if 0 // because QT4 using QShortcut, so I diable this function if ( (e->type() == QEvent::Accel || e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { static_cast<QKeyEvent *>( e )->ignore(); return true; } #endif if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) return FALSE; // not us if ( e->type() == QEvent::Wheel) { QApplication::sendEvent(scrollbar, e); } #ifdef FAKE_CTRL_AND_ALT static bool control = FALSE; static bool alt = FALSE; // Has a keyboard with no CTRL and ALT keys, but we fake it: bool dele=FALSE; if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { QKeyEvent* ke = (QKeyEvent*)e; bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); switch (ke->key()) { case Key_F9: // let this be "Control" control = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); dele=TRUE; break; case Key_F13: // let this be "Alt" alt = keydown; e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); dele=TRUE; break; default: if ( control ) { int a = toupper(ke->ascii())-64; if ( a >= 0 && a < ' ' ) { e = new QKeyEvent(e->type(), ke->key(), a, ke->state()|ControlButton, QChar(a,0)); dele=TRUE; } } if ( alt ) { e = new QKeyEvent(e->type(), ke->key(), ke->ascii(), ke->state()|AltButton, ke->text()); dele=TRUE; } } } #endif if ( e->type() == QEvent::KeyPress ) { QKeyEvent* ke = (QKeyEvent*)e; actSel=0; // Key stroke implies a screen update, so TEWidget won't // know where the current selection is. emit keyPressedSignal(ke); // expose ke->accept(); #ifdef FAKE_CTRL_AND_ALT if ( dele ) delete e; #endif return true; // stop the event } if ( e->type() == QEvent::Enter ) { QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); } if ( e->type() == QEvent::Leave ) { QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), this, SLOT(onClearSelection()) ); } return QFrame::eventFilter( obj, e ); }
void TEWidget::emitText(QString text) { QKeyEvent e(QEvent::KeyPress, 0, Qt::NoModifier, text); emit keyPressedSignal(&e); // expose as a big fat keypress event }