//! \brief Clears focus if escape key pressed. Otherwise calls base method. void PropertyItem::keyPressEvent(QKeyEvent *e) { if(e->key() == Qt::Key_Escape) { clearFocus(); return; } QVariant oldProperty(component()->property(m_propertyName)); if(e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) { if(m_edited && component()->setProperty(m_propertyName, QVariant(toPlainText()))) { updateGroupGeometry(); m_edited = false; QVariant newProperty(component()->property(m_propertyName)); PropertiesGroup *parentGroup = static_cast<PropertiesGroup*>(group()); Q_ASSERT(parentGroup); SchematicScene *schScene = parentGroup->schematicScene(); schScene->undoStack()->push(new PropertyChangeCmd(m_propertyName, newProperty, oldProperty, component())); } clearFocus(); return; } m_edited = true; QGraphicsTextItem::keyPressEvent(e); }
void lcQColorPicker::buttonPressed(bool toggled) { if (!toggled) return; lcQColorPickerPopup *popup = new lcQColorPickerPopup(this, currentColorIndex); connect(popup, SIGNAL(changed(int)), SLOT(changed(int))); connect(popup, SIGNAL(selected(int)), SLOT(selected(int))); connect(popup, SIGNAL(hid()), SLOT(popupClosed())); popup->setMinimumSize(300, 200); const QRect desktop = QApplication::desktop()->geometry(); QPoint pos = mapToGlobal(rect().bottomLeft()); if (pos.x() < desktop.left()) pos.setX(desktop.left()); if (pos.y() < desktop.top()) pos.setY(desktop.top()); if ((pos.x() + popup->width()) > desktop.width()) pos.setX(desktop.width() - popup->width()); if ((pos.y() + popup->height()) > desktop.bottom()) pos.setY(desktop.bottom() - popup->height()); popup->move(pos); clearFocus(); update(); popup->setFocus(); popup->show(); }
/**This function displays the window after losing the game. * @brief Game::lose() creates a panel to obscure the background and places a message on the screen along with quit and retry buttons. */ void Game::lose(){ // play lose music lose_music->play(); // stop game music game_music->stop(); ash_lose = true; clearFocus(); drawPanel(400,0,400,400,QBrush(QImage(":/new/prefix1/sad_pika.png").scaledToWidth(400)), 1); QGraphicsTextItem* message= new QGraphicsTextItem("GAME OVER"); message->setDefaultTextColor(Qt::red); message->setFont(QFont("Gill Sans",40)); message->setPos(500, 75); scene->addItem(message); QPushButton* quit_button= new QPushButton("Quit"); quit_button->setGeometry(450, 200, 80, 40); scene->addWidget(quit_button); QPushButton* retry_button = new QPushButton("Retry"); retry_button->setGeometry(650,200,80,40); scene->addWidget(retry_button); QObject::connect(quit_button, SIGNAL(clicked(bool)), this, SLOT(close())); QObject::connect(retry_button,SIGNAL(clicked(bool)),this,SLOT(retry())); }
/**This function displays the window after winning the game. * @brief Game::win() creates a panel to obscure the background and places a message on the screen along with quit and retry buttons. */ void Game::win(){ // play win music win_music->play(); // stop game music game_music->stop(); ash_win = true; clearFocus(); drawPanel(400,0,400,400,QBrush(QImage(":/new/prefix1/Ca1P-6TVAAE6x19.jpg").scaledToWidth(400)), 1); QGraphicsTextItem* message= new QGraphicsTextItem("YOU WON!!"); message->setFont(QFont("Gill Sans",40)); message->setPos(500, 100); scene->addItem(message); QPushButton* quit_button= new QPushButton("Quit"); quit_button->setGeometry(450, 200, 80, 40); scene->addWidget(quit_button); QPushButton* retry_button = new QPushButton("Retry"); retry_button->setGeometry(650,200,80,40); scene->addWidget(retry_button); QObject::connect(quit_button, SIGNAL(clicked(bool)), this, SLOT(close())); QObject::connect(retry_button,SIGNAL(clicked(bool)),this,SLOT(retry())); }
void Label::setTextInteraction(bool on, bool selectAll) { if(on && textInteractionFlags() == Qt::NoTextInteraction) { // switch on editor mode: qDebug() << textInteractionFlags(); setTextInteractionFlags(Qt::TextEditorInteraction); qDebug() << textInteractionFlags(); // manually do what a mouse click would do else: setFocus(Qt::MouseFocusReason); // this gives the item keyboard focus setSelected(true); // this ensures that itemChange() gets called when we click out of the item if(selectAll) // option to select the whole text (e.g. after creation of the TextItem) { QTextCursor c = textCursor(); c.select(QTextCursor::Document); setTextCursor(c); } } else if(!on && textInteractionFlags() == Qt::TextEditorInteraction) { // turn off editor mode: setTextInteractionFlags(Qt::NoTextInteraction); // deselect text (else it keeps gray shade): QTextCursor c = this->textCursor(); c.clearSelection(); this->setTextCursor(c); clearFocus(); } }
void Connection::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { QGraphicsObject::mouseReleaseEvent(event); if (drag_state == CONNECTED) return; ungrabMouse(); clearFocus(); setFlag(QGraphicsItem::ItemIsFocusable, false); InputPort* target = gscene()->getInputPortAt(endPos()); Datum* datum = target ? target->getDatum() : NULL; if (target && datum->acceptsLink(link)) { datum->addLink(link); drag_state = CONNECTED; connect(endInspector(), &NodeInspector::moved, this, &Connection::onInspectorMoved); connect(endInspector(), &NodeInspector::hiddenChanged, this, &Connection::onHiddenChanged); App::instance()->pushStack(new UndoAddLinkCommand(link)); } else { link->deleteLater(); } prepareGeometryChange(); }
void KeyButton::keyPressEvent(QKeyEvent *keyEvent) { std::string keyText = QKeyUtil::keyName(keyEvent); if (keyEvent->key() == Key_Return) { grabKeyboard(); return; } if (keyEvent->key() == Key_Up || keyEvent->key() == Key_Down) { clearFocus(); releaseKeyboard(); return; } if (!keyText.empty()) { myKeyView.myCurrentKey = keyText; myKeyView.myLabel->setText("Action For " + QString::fromUtf8(keyText.c_str())); myKeyView.myLabel->show(); #if 0 QSizePolicy pol = myKeyView.myLabel->sizePolicy(); pol.setHorData(QSizePolicy::Fixed); myKeyView.myLabel->setSizePolicy(pol); myKeyView.myLabel->setLineWidth(80); pol = myKeyView.myComboBox->sizePolicy(); pol.setHorData(QSizePolicy::Fixed); myKeyView.myComboBox->setSizePolicy(pol); #endif myKeyView.myComboBox->setCurrentItem(((ZLKeyOptionEntry*)myKeyView.myOption)->actionIndex(keyText)); myKeyView.myComboBox->show(); } }
void Connection::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { QGraphicsObject::mouseReleaseEvent(event); if (drag_state == CONNECTED) return; ungrabMouse(); clearFocus(); setFlag(QGraphicsItem::ItemIsFocusable, false); InputPort* t = gscene()->getInputPortAt(endPos()); Datum* datum = target ? target->getDatum() : NULL; if (t && datum->acceptsLink(source->getDatum())) { target = t; t->install(this); datum->installLink(source->getDatum()); drag_state = CONNECTED; App::instance()->pushStack( new UndoAddLinkCommand(source->getDatum(), datum)); onPortsMoved(); emit(changed()); } else { deleteLater(); } prepareGeometryChange(); }
void AMGraphicsTextItem::keyPressEvent(QKeyEvent *event){ if(event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return){ emit returnPressed(shapeIndex_); clearFocus(); event->accept(); }// for no particular reason delete doesn't work, so reimplemented here else if(event->key() == Qt::Key_Delete) { QString docString = toPlainText(); if(docString.count() > 0) { int cursorPosition = textCursor().position(); if(cursorPosition >= 0) { docString.remove((cursorPosition), 1); setPlainText(docString); QTextCursor newCursor = textCursor(); newCursor.setPosition(cursorPosition); setTextCursor(newCursor); } } } else QGraphicsTextItem::keyPressEvent(event); }
void SpellItem::keyPressEvent(QKeyEvent * event) { Spell * spellParent = NULL; switch (event->key()) { // Delete : remove that spell case Qt::Key::Key_Delete : spellParent = spell_->getParent(); if (spellParent == NULL) { // Can't remove the top level spell, so just clear it cout << "Clearing top level spell" << endl; spell_->clear(); } else { cout << "Removing spell" << endl; spellParent->remove(spell_); } emit(changedSpell()); break; case Qt::Key::Key_Plus: // No need for the alternative add //if (event->modifiers() & Qt::ShiftModifier) spell_->addEmptyChild(); emit(changedSpell()); break; case Qt::Key::Key_Escape: clearFocus(); break; } }
/*! \internal Pops up the color grid, and makes sure the status of QtColorPicker's button is right. */ void QtColorPicker::buttonPressed(bool toggled) { if (!toggled) return; const QRect desktop = QApplication::desktop()->geometry(); // Make sure the popup is inside the desktop. QPoint pos = mapToGlobal(rect().bottomLeft()); if (pos.x() < desktop.left()) pos.setX(desktop.left()); if (pos.y() < desktop.top()) pos.setY(desktop.top()); if ((pos.x() + popup->sizeHint().width()) > desktop.width()) pos.setX(desktop.width() - popup->sizeHint().width()); if ((pos.y() + popup->sizeHint().height()) > desktop.bottom()) pos.setY(desktop.bottom() - popup->sizeHint().height()); popup->move(pos); if (ColorPickerItem *item = popup->find(col)) item->setSelected(true); // Remove focus from this widget, preventing the focus rect // from showing when the popup is shown. Order an update to // make sure the focus rect is cleared. clearFocus(); update(); // Allow keyboard navigation as soon as the popup shows. popup->setFocus(); // Execute the popup. The popup will enter the event loop. popup->show(); }
void ToolbarSearch::clear() { m_stringListModel->setStringList(QStringList()); m_autosaver->changeOccurred(); QLineEdit::clear(); clearFocus(); }
void FilterHeaderWidget::keyPressEvent(QKeyEvent *ev) { if(ev->key() == Qt::Key_Escape) clearFocus(); else QLineEdit::keyPressEvent(ev); }
void SpinBox::valueChange() { if (!mSuppressSignals) { int val = value(); if (mShiftMinBound && val >= mMinValue) { // Reinstate the minimum bound now that the value has returned to the normal range. QSpinBox::setMinValue(mMinValue); mShiftMinBound = false; } if (mShiftMaxBound && val <= mMaxValue) { // Reinstate the maximum bound now that the value has returned to the normal range. QSpinBox::setMaxValue(mMaxValue); mShiftMaxBound = false; } bool focus = !mSelectOnStep && hasFocus(); if (focus) clearFocus(); // prevent selection of the spin box text QSpinBox::valueChange(); if (focus) setFocus(); } }
//! Function to set the selected scale from text bool QgsScaleComboBox::setScaleString( const QString& scaleTxt ) { bool ok; double newScale = toDouble( scaleTxt, &ok ); double oldScale = mScale; if ( newScale < mMinScale ) { newScale = mMinScale; } if ( ! ok ) { return false; } else { mScale = newScale; setEditText( toString( mScale ) ); clearFocus(); if ( mScale != oldScale ) { emit scaleChanged( mScale ); } return true; } }
void Preview::mouseMoveEvent( QMouseEvent* e ) { e; QCursor c = cursor(); QPoint mapFromGlobal = this->mapFromGlobal( c.pos() ); if ( GetAsyncKeyState( VK_LBUTTON ) < 0 && mapFromGlobal.x() >= 0 && mapFromGlobal.x() <= width() && mapFromGlobal.y() >= 0 && mapFromGlobal.y() <= height() && MouseInput::globalMouseInput.oldMousePosition != glm::vec2( c.pos().x() , c.pos().y() ) ) { if ( !MouseInput::globalMouseInput.getDeltaTracking() )MouseInput::globalMouseInput.setDeltaTracking( true ); glm::vec2 oldPos = MouseInput::globalMouseInput.oldMousePosition; MouseInput::globalMouseInput.updateMousePosition( glm::vec2( c.pos().x() , c.pos().y() ) ); c.setPos( QPoint( oldPos.x , oldPos.y ) ); c.setShape( Qt::BlankCursor ); } else if ( MouseInput::globalMouseInput.oldMousePosition != glm::vec2( c.pos().x() , c.pos().y() ) ) { c.setShape( Qt::ArrowCursor ); if ( MouseInput::globalMouseInput.getDeltaTracking() )MouseInput::globalMouseInput.setDeltaTracking( false ); MouseInput::globalMouseInput.oldMousePosition = glm::vec2( c.pos().x() , c.pos().y() ); MouseInput::globalMouseInput.updateMousePosition( glm::vec2( c.pos().x() , c.pos().y() ) ); } clearFocus(); setCursor( c ); setFocus(); }
BOOL LLViewerMediaFocus::handleKey(KEY key, MASK mask, BOOL called_from_parent) { LLViewerMediaImpl* media_impl = getFocusedMediaImpl(); if(media_impl) { media_impl->handleKeyHere(key, mask); if (KEY_ESCAPE == key) { // Reset camera zoom in this case. if(mFocusedImplID.notNull()) { if(mMediaControls.get()) { mMediaControls.get()->resetZoomLevel(true); } } clearFocus(); } if ( KEY_F1 == key && LLUI::sHelpImpl && mMediaControls.get()) { std::string help_topic; if (mMediaControls.get()->findHelpTopic(help_topic)) { LLUI::sHelpImpl->showTopic(help_topic); } } } return true; }
void SceneViewWidget::leaveEvent(QEvent* e) { if (isActiveWindow()) { clearFocus(); } emit mouseLeft(); }
void SpinBox::stepDown() { QSpinBox::stepDown(); if (_clearFocus) clearFocus(); else _clearFocus = true; }
void FilterWidget::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) { clear(); clearFocus(); } QLineEdit::keyPressEvent(event); }
void QKeyButton::click() { if (hasFocus()) { clearFocus(); } else { setFocus(); } }
void GalleryTreeView::slotCheckSelection(const QModelIndex &selected) { clearFocus(); if (selected.isValid()) { emit signalSelected(true); } else emit signalSelected(false); }
void ScaleSliderQWidget::leaveEvent(QEvent* e) { if ( hasFocus() ) { clearFocus(); } QWidget::leaveEvent(e); }
void ScrollLine::setText( const QString &text ) { QLineEdit::setText( text ); mDirection = 1; mPosition = 0; setCursorPosition( mPosition ); clearFocus(); }
caTextEntry::caTextEntry(QWidget *parent) : caLineEdit(parent) { connect(this, SIGNAL(returnPressed()), this, SLOT(dataInput())); clearFocus(); setAccessW(true); installEventFilter(this); newFocusPolicy(Qt::ClickFocus); }
void ToolbarSearch::clear() { m_recentSearches.clear(); m_autosaver->changeOccurred(); setupMenu(); QLineEdit::clear(); clearFocus(); }
void KstTopLevelView::updateFocus(const QPoint& pos) { if (_activeHandler) { _activeHandler->updateFocus(this, pos); return; } if (_mode == DisplayMode || _mode == Unknown || tracking()) { return; } //TODO: make this work better with click-select mode KstViewObjectPtr p = findDeepestChild(pos, false); if (p) { KstViewObjectPtr p2 = p; while (p2->_parent && p2->_parent->_container) { p2 = p2->_parent; } if (p2->_parent && !p2->_parent->_container) { p = p2->_parent; } } if (p) { if (p->focused()) { setCursorFor(pos, p); _focusOn = true; // just in case - seems to be false on occasion return; } p->setFocus(true); if (_focusOn) { // something else has the focus, clear it clearFocus(); } setCursorFor(pos, p); KstPainter painter; painter.begin(_w); painter.setRasterOp(Qt::NotROP); painter.setPen(QPen(Qt::black, 0, Qt::SolidLine)); painter.setBrush(Qt::NoBrush); p->drawFocusRect(painter); painter.end(); _focusOn = true; _hoverFocus = p; } else { clearFocus(); } }
// apply the changes if valid values have been entered void QtArc2DWidget::applyChanges() { if(radius_line_edit_->hasAcceptableInput()) { arc_primitive_->SetRadiusValue(radius_line_edit_->text().toDouble()); clearFocus(); emit modelChanged(); } }
// apply the changes if valid values have been entered void QtAngleLine2DWidget::applyChanges() { if(angle_line_edit_->hasAcceptableInput()) { angle_constraint_primitive_->SetAngleValue(angle_line_edit_->text().toDouble()*(mmcPI/180.0)); clearFocus(); emit modelChanged(); } }
void MyIntervalSlider::mousePressEvent(QMouseEvent *event) { QPoint pos = event->pos(); if (event->button() == Qt::LeftButton) { activeSubControl = subcontrolOnPosition(pos); clearFocus(); } event->accept(); }