void RoutingStatsScene::addToProxyWidgetsMap(uint32_t nodeId, QString title, QString content) { if(m_nodeIdProxyWidgets.find(nodeId) == m_nodeIdProxyWidgets.end()) { TextBubble * tb = new TextBubble (title, content); QFont f(tb->font()); f.setPointSizeF(StatsMode::getInstance()->getCurrentFontSize()); tb->setFont(f); QGraphicsProxyWidget * pw = addWidget(tb); QFontMetrics fm(f); pw->setMaximumHeight(fm.height() * tb->text().count("\n")); pw->adjustSize(); showInfoWidget(false); m_nodeIdProxyWidgets[nodeId] = pw; qreal newX = m_lastX + pw->widget()->width(); if(newX >= sceneRect().right()) { m_lastX = 0; m_lastY += pw->widget()->height() + INTERSTATS_SPACE; } pw->setPos(m_lastX, m_lastY); m_lastX = pw->pos().x() + pw->widget()->width() + INTERSTATS_SPACE; m_lastY = pw->pos().y(); m_bottomY = m_lastY + pw->widget()->height(); //qDebug(QString("Last X" + QString::number(m_lastX) + " w:" + QString::number(pw->widget()->width()))); adjustRect(); return; } }
bool isTextInputItem(QGraphicsItem* item) { if (item && item->isWidget()) { QGraphicsWidget *graphicsWidget = static_cast<QGraphicsWidget *>(item); QGraphicsProxyWidget * textInputProxyWidget = qobject_cast<QGraphicsProxyWidget *>(graphicsWidget); if (textInputProxyWidget && textInputProxyWidget->widget() && ( strcmp(textInputProxyWidget->widget()->metaObject()->className(), "QLineEdit") == 0 || strcmp(textInputProxyWidget->widget()->metaObject()->className(), "QTextEdit") == 0)) { return true; } } return false; }
QWidget* QGraphicsViewAdapter::getWidgetAt(const QPoint& pos) { QWidget* childAt = _graphicsView->childAt(pos); if(childAt) { return childAt; } QGraphicsItem* item = _graphicsView->itemAt(pos); if(item && item->contains(item->mapFromScene(pos))) { QGraphicsProxyWidget* p = dynamic_cast<QGraphicsProxyWidget*>(item); if(p) { childAt = p->widget(); QWidget* c; while( (c = childAt->childAt(childAt->mapFromGlobal(pos)))!=0 ) { childAt = c; } return childAt; } } return NULL; }
/*! \internal \reimp */ bool HbInputContextProxy::filterEvent(const QEvent *event) { if (mTarget) { bool orientationCompleted = HbInputSettingProxy::instance()->orientationChangeCompleted(); if (event->type() == QEvent::CloseSoftwareInputPanel && orientationCompleted) { setInputFrameworkFocus(0); return true; } else if (event->type() == QEvent::RequestSoftwareInputPanel && orientationCompleted) { if (QWidget *focusedWidget = qApp->focusWidget()) { // see if the focused widget is graphics view, if so get the focused graphics item in the view // and acivate inputmethod for the focused graphics item if (QGraphicsView *graphicsView = qobject_cast<QGraphicsView *>(focusedWidget)) { if (QGraphicsScene *scene = graphicsView->scene()) { if (QGraphicsItem *fItem = scene->focusItem()) { QGraphicsProxyWidget *proxy = qgraphicsitem_cast<QGraphicsProxyWidget *>(fItem); if (proxy) { setInputFrameworkFocus(proxy->widget()->focusWidget()); } else { setInputFrameworkFocus(static_cast<QGraphicsWidget *>(fItem)); } } } } else { // focused wiget is not graphics view, let see if it is native qt editor // and activate inputmethod for the focused widget setInputFrameworkFocus(focusedWidget); } } return true; } #ifdef Q_OS_SYMBIAN const quint32 HbInputContextProxyExternalKeyboardModifier = 0x00200000; if (event->type() == QEvent::QEvent::KeyPress || event->type() == QEvent::KeyRelease) { const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event); if (keyEvent->nativeModifiers() & HbInputContextProxyExternalKeyboardModifier) { // Operating system indicates that the event originated from an external keyboard. // We let it pass here untouched. if (mTarget) { mTarget->reset(); } return false; } } #endif if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) { const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event); if (Qt::Key_unknown == keyEvent->key()) { return false; } } return mTarget->filterEvent(event); } return false; }
void UiManager::mousePressEvent(QMouseEvent *event) { QWidget *pressedWidget = NULL; // get the clicked item through the view (respects view and item transformations) QGraphicsItem* itemAt = mWidgetView->itemAt(event->pos()); if ((itemAt) && (itemAt->isWidget())) { QGraphicsProxyWidget *proxyWidget = qgraphicsitem_cast<QGraphicsProxyWidget *>(itemAt); if (proxyWidget) { QWidget *embeddedWidget = proxyWidget->widget(); // if the widget has children, use them, otherwise use the widget directly if (embeddedWidget->children().size() > 0) { QPoint widgetPoint = proxyWidget->mapFromScene(mWidgetView->mapToScene(event->pos())).toPoint(); pressedWidget = embeddedWidget->childAt(widgetPoint); } else { pressedWidget = embeddedWidget; } } } // if there was a focused widget and there is none or a different one now, defocus if (mFocusedWidget && (!pressedWidget || pressedWidget != mFocusedWidget)) { QEvent foe(QEvent::FocusOut); QApplication::sendEvent(mFocusedWidget, &foe); mFocusedWidget = NULL; mTopLevelWidget->setFocus(); } // set the new focus if (pressedWidget) { QEvent fie(QEvent::FocusIn); QApplication::sendEvent(pressedWidget, &fie); pressedWidget->setFocus(Qt::MouseFocusReason); mFocusedWidget = pressedWidget; } QApplication::sendEvent(mWidgetView->viewport(), event); }
void FlowMonStatsScene::align() { m_lastX = 0; m_lastY = 0; m_bottomY = 0; qreal currentMaxHeight = 0; for(FlowIdProxyWidgetMap_t::const_iterator i = m_flowIdProxyWidgets.begin(); i != m_flowIdProxyWidgets.end(); ++i) { QGraphicsProxyWidget * pw = i->second; bool flowIsActive = StatsMode::getInstance()->isNodeActive(i->first); pw->setVisible(flowIsActive); if(flowIsActive) { TextBubble * tb = (TextBubble *) pw->widget(); QFont f(tb->font()); f.setPointSizeF(StatsMode::getInstance()->getCurrentFontSize()); tb->setFont(f); QFontMetrics fm(f); pw->setMaximumHeight(fm.height() * tb->text().count("\n")); pw->adjustSize(); qreal newX = m_lastX + pw->size().width(); currentMaxHeight = qMax(currentMaxHeight, pw->size().height()); if(newX >= sceneRect().right()) { m_lastX = 0; m_lastY += currentMaxHeight + INTERSTATS_SPACE; currentMaxHeight = 0; } pw->setPos(m_lastX, m_lastY); m_lastX = pw->pos().x() + pw->size().width() + INTERSTATS_SPACE; m_lastY = pw->pos().y(); m_bottomY = m_lastY + currentMaxHeight; adjustRect(); } } if(m_flowProbeWidget) { QGraphicsProxyWidget * pw = m_flowProbeWidget; TextBubble * tb = (TextBubble *) pw->widget(); QFont f(tb->font()); f.setPointSizeF(StatsMode::getInstance()->getCurrentFontSize()); tb->setFont(f); QFontMetrics fm(f); pw->setMaximumHeight(fm.height() * tb->text().count("\n")); pw->adjustSize(); qreal newX = m_lastX + pw->size().width(); currentMaxHeight = qMax(currentMaxHeight, pw->size().height()); if(newX >= sceneRect().right()) { m_lastX = 0; m_lastY += currentMaxHeight + INTERSTATS_SPACE; currentMaxHeight = 0; } pw->setPos(m_lastX, m_lastY); m_lastX = pw->pos().x() + pw->size().width() + INTERSTATS_SPACE; m_lastY = pw->pos().y(); m_bottomY = m_lastY + currentMaxHeight; adjustRect(); } }
void InterfaceStatsScene::add (uint32_t nodeId, QString pointADescription, uint32_t otherNodeId, QString pointBDescription, QString linkDescription) { if (!StatsMode::getInstance ()->isNodeActive (nodeId)) { return; } if (!pointADescription.contains ("~")) { return; } showInfoWidget (false); QStringList parts = pointADescription.split ('~'); //qDebug (pointADescription); QString IP = parts.at (0); //qDebug (IP); QString MAC = parts.at (1); QString otherIP = ""; QString otherMAC = ""; if (pointBDescription != "") { parts = pointBDescription.split ('~'); otherIP = parts.at (0); otherMAC = parts.at (1); } QString title = "Node:" + QString::number (nodeId); QString content = "IP:" + IP ; content += "\nMAC:" + MAC ; if (pointBDescription != "") { content += "\nOther Node:" + QString::number (otherNodeId) ; content += "\nOther IP:" + otherIP; content += "\nOther MAC:" + otherMAC; content += "\nInfo:" + linkDescription; } TextBubble * tb = new TextBubble (title, content); QGraphicsProxyWidget * pw = addWidget (tb); QFont f (tb->font ()); f.setPointSizeF (StatsMode::getInstance ()->getCurrentFontSize ()); tb->setFont (f); QFontMetrics fm (f); pw->setMaximumHeight (fm.height () * tb->text ().count ("\n")); addToProxyWidgetsMap (nodeId, pw); qreal newX = m_lastX + pw->widget ()->width (); m_currentMaxHeight = qMax (m_currentMaxHeight, pw->size ().height ()); if (newX >= sceneRect ().right ()) { m_lastX = 0; m_lastY += m_currentMaxHeight + INTERSTATS_SPACE; m_currentMaxHeight = 0; } pw->setPos (m_lastX, m_lastY); m_lastX = pw->pos ().x () + pw->widget ()->width () + INTERSTATS_SPACE; m_lastY = pw->pos ().y (); m_bottomY = m_lastY + m_currentMaxHeight; //qDebug (QString ("Last X" + QString::number (m_lastX) + " w:" + QString::number (pw->widget ()->width ()))); adjustRect (); }