void XDialog::showEvent(QShowEvent *event) { if(!_private->_shown) { _private->_shown = true; QRect availableGeometry = QApplication::desktop()->availableGeometry(); QString objName = objectName(); QPoint pos = xtsettingsValue(objName + "/geometry/pos").toPoint(); QSize lsize = xtsettingsValue(objName + "/geometry/size").toSize(); if(lsize.isValid() && xtsettingsValue(objName + "/geometry/rememberSize", true).toBool()) resize(lsize); // do I want to do this for a dialog? //_windowList.append(w); QRect r(pos, size()); if(!pos.isNull() && availableGeometry.contains(r) && xtsettingsValue(objName + "/geometry/rememberPos", true).toBool()) move(pos); _private->_rememberPos = new QAction(tr("Remember Posisition"), this); _private->_rememberPos->setCheckable(true); _private->_rememberPos->setChecked(xtsettingsValue(objectName() + "/geometry/rememberPos", true).toBool()); connect(_private->_rememberPos, SIGNAL(triggered(bool)), this, SLOT(setRememberPos(bool))); _private->_rememberSize = new QAction(tr("Remember Size"), this); _private->_rememberSize->setCheckable(true); _private->_rememberSize->setChecked(xtsettingsValue(objectName() + "/geometry/rememberSize", true).toBool()); connect(_private->_rememberSize, SIGNAL(triggered(bool)), this, SLOT(setRememberSize(bool))); addAction(_private->_rememberPos); addAction(_private->_rememberSize); setContextMenuPolicy(Qt::ActionsContextMenu); QStringList parts = objectName().split(" "); QStringList search_parts; QString oName; while(!parts.isEmpty()) { search_parts.append(parts.takeFirst()); oName = search_parts.join(" "); // load and run an QtScript that applies to this window qDebug() << "Looking for a script on dialog " << oName; q.prepare("SELECT script_source, script_order" " FROM script" " WHERE((script_name=:script_name)" " AND (script_enabled))" " ORDER BY script_order;"); q.bindValue(":script_name", oName); q.exec(); while(q.next()) { QString script = scriptHandleIncludes(q.value("script_source").toString()); if(!_private->_engine) { _private->_engine = new QScriptEngine(); omfgThis->loadScriptGlobals(_private->_engine); QScriptValue mywindow = _private->_engine->newQObject(this); _private->_engine->globalObject().setProperty("mywindow", mywindow); } QScriptValue result = _private->_engine->evaluate(script, objectName()); if (_private->_engine->hasUncaughtException()) { int line = _private->_engine->uncaughtExceptionLineNumber(); qDebug() << "uncaught exception at line" << line << ":" << result.toString(); } } } }
int FreehandSelection::locationEvent(const SoLocation2Event* const e, const QPoint& pos) { // do all the drawing stuff for us QPoint clPoint = pos; if (polyline.isWorking()) { // check the position QRect r = _pcView3D->getGLWidget()->rect(); if (!r.contains(clPoint)) { if (clPoint.x() < r.left()) clPoint.setX(r.left()); if (clPoint.x() > r.right()) clPoint.setX(r.right()); if (clPoint.y() < r.top()) clPoint.setY(r.top()); if (clPoint.y() > r.bottom()) clPoint.setY(r.bottom()); } SbVec2s last = _clPoly.back(); SbVec2s curr = e->getPosition(); if (abs(last[0]-curr[0]) > 20 || abs(last[1]-curr[1]) > 20) _clPoly.push_back(curr); polyline.addNode(clPoint); polyline.setCoords(clPoint.x(), clPoint.y()); } m_iXnew = clPoint.x(); m_iYnew = clPoint.y(); draw(); m_iXold = clPoint.x(); m_iYold = clPoint.y(); return Continue; }
void FFGLNode::initialiseInstance( QPoint pPoint, QSize pSize ) { InterfaceOpenGL *GL = qobject_cast<InterfaceOpenGL *>( FreeframePlugin::instance()->app()->findInterface( IID_OPENGL ) ); if( GL ) { GL->checkErrors( __FILE__, __LINE__ ); } FFMixed PMU; if( mPoint != pPoint || mSize != pSize ) { #if defined( __FFGL_H__ ) FF_Main_FuncPtr MainFunc = mLibrary->func(); if( mInstanceId ) { PMU.UIntValue = 0; PMU = MainFunc( FF_DEINSTANTIATEGL, PMU, mInstanceId ); if( GL ) { GL->checkErrors( __FILE__, __LINE__ ); } mInstanceId = 0; } FFGLViewportStruct VPS; VPS.x = pPoint.x(); VPS.y = pPoint.y(); VPS.width = pSize.width(); VPS.height = pSize.height(); PMU.PointerValue = &VPS; PMU = MainFunc( FF_INSTANTIATEGL, PMU, 0 ); if( GL ) { GL->checkErrors( __FILE__, __LINE__ ); } if( PMU.UIntValue == FF_FAIL ) { return; } mSize = pSize; if( PMU.UIntValue != FF_FAIL ) { mInstanceId = PMU.PointerValue; } #endif } }
int FreehandSelection::mouseButtonEvent(const SoMouseButtonEvent* const e, const QPoint& pos) { const int button = e->getButton(); const SbBool press = e->getState() == SoButtonEvent::DOWN ? true : false; if (press) { switch(button) { case SoMouseButtonEvent::BUTTON1: { if (!polyline.isWorking()) { polyline.setWorking(true); polyline.clear(); }; polyline.addNode(pos); polyline.setCoords(pos.x(), pos.y()); m_iXnew = pos.x(); m_iYnew = pos.y(); m_iXold = pos.x(); m_iYold = pos.y(); } break; case SoMouseButtonEvent::BUTTON2: { polyline.addNode(pos); m_iXnew = pos.x(); m_iYnew = pos.y(); m_iXold = pos.x(); m_iYold = pos.y(); } break; default: { } break; } } // release else { switch(button) { case SoMouseButtonEvent::BUTTON1: if (polyline.isWorking()) { releaseMouseModel(); return Finish; } case SoMouseButtonEvent::BUTTON2: { QCursor cur = _pcView3D->getWidget()->cursor(); _pcView3D->getWidget()->setCursor(m_cPrevCursor); // The pop-up menu should be shown when releasing mouse button because // otherwise the navigation style doesn't get the UP event and gets into // an inconsistent state. int id = popupMenu(); if (id == Finish || id == Cancel) { releaseMouseModel(); } else if (id == Restart) { _pcView3D->getWidget()->setCursor(cur); } polyline.setWorking(false); return id; } break; default: { } break; } } return Continue; }
int PolyPickerSelection::locationEvent(const SoLocation2Event* const e, const QPoint& pos) { // do all the drawing stuff for us QPoint clPoint = pos; if (polyline.isWorking()) { // check the position QRect r = _pcView3D->getGLWidget()->rect(); if (!r.contains(clPoint)) { if (clPoint.x() < r.left()) clPoint.setX(r.left()); if (clPoint.x() > r.right()) clPoint.setX(r.right()); if (clPoint.y() < r.top()) clPoint.setY(r.top()); if (clPoint.y() > r.bottom()) clPoint.setY(r.bottom()); #ifdef FC_OS_WINDOWS QPoint newPos = _pcView3D->getGLWidget()->mapToGlobal(clPoint); QCursor::setPos(newPos); #endif } if (!lastConfirmed) polyline.popNode(); polyline.addNode(clPoint); lastConfirmed = false; draw(); } m_iXnew = clPoint.x(); m_iYnew = clPoint.y(); return Continue; }
/** * \fn VideoOutWindow::GetVisibleOSDBounds(float&,float&,float) const * \brief Returns visible portions of total OSD bounds * \param visible_aspect physical aspect ratio of bounds returned * \param font_scaling scaling to apply to fonts */ QRect VideoOutWindow::GetVisibleOSDBounds( float &visible_aspect, float &font_scaling, float themeaspect) const { float dv_w = (((float)video_disp_dim.width()) / display_video_rect.width()); float dv_h = (((float)video_disp_dim.height()) / display_video_rect.height()); uint right_overflow = max( (display_video_rect.width() + display_video_rect.left()) - display_visible_rect.width(), 0); uint lower_overflow = max( (display_video_rect.height() + display_video_rect.top()) - display_visible_rect.height(), 0); bool isPBP = (kPBPLeft == pip_state || kPBPRight == pip_state); if (isPBP) { right_overflow = 0; lower_overflow = 0; } // top left and bottom right corners respecting letterboxing QPoint tl = QPoint((uint) ceil(max(-display_video_rect.left(),0)*dv_w), (uint) ceil(max(-display_video_rect.top(),0)*dv_h)); QPoint br = QPoint( (uint) floor(video_disp_dim.width() - (right_overflow * dv_w)), (uint) floor(video_disp_dim.height() - (lower_overflow * dv_h))); // adjust for overscan if ((db_scale_vert > 0.0f) || (db_scale_horiz > 0.0f)) { QRect v(tl, br); float xs = (db_scale_horiz > 0.0f) ? db_scale_horiz : 0.0f; float ys = (db_scale_vert > 0.0f) ? db_scale_vert : 0.0f; QPoint s((int)(v.width() * xs), (int)(v.height() * ys)); tl += s; br -= s; } // Work around Qt bug, QRect(QPoint(0,0), QPoint(0,0)) has area 1. QRect vb(tl.x(), tl.y(), br.x() - tl.x(), br.y() - tl.y()); // The calculation is completely bogus if the video is not centered // which happens in the EPG, where we don't actually care about the OSD. // So we just make sure the width and height are positive numbers vb = QRect(vb.x(), vb.y(), abs(vb.width()), abs(vb.height())); // set the physical aspect ratio of the displayable area float dispPixelAdj = 1.0f; if (display_visible_rect.width()) { dispPixelAdj = GetDisplayAspect() * display_visible_rect.height(); dispPixelAdj /= display_visible_rect.width(); } if ((vb.height() >= 0) && overriden_video_aspect >= 0.0f) { // now adjust for scaling of the video on the aspect ratio float vs = ((float)vb.width())/vb.height(); visible_aspect = themeaspect * (vs/overriden_video_aspect) * dispPixelAdj; } if (themeaspect >= 0.0f) { // now adjust for scaling of the video on the size float tmp = sqrtf(2.0f/(sq(visible_aspect / themeaspect) + 1.0f)); if (tmp >= 0.0f) font_scaling = 1.0f / tmp; // now adjust for aspect ratio effect on font size // (should be in osd.cpp?) font_scaling *= sqrtf(overriden_video_aspect / themeaspect); } if (isPBP) font_scaling *= 0.65f; return vb; }
bool GroundPlaneGenerator::generateGroundPlaneUnit(const QString & boardSvg, QSizeF boardImageSize, const QString & svg, QSizeF copperImageSize, QStringList & exceptions, QGraphicsItem * board, double res, const QString & color, QPointF whereToStart) { double bWidth, bHeight; QImage * image = generateGroundPlaneAux(boardSvg, boardImageSize, svg, copperImageSize, exceptions, board, res, bWidth, bHeight); if (image == NULL) return false; QRectF bsbr = board->sceneBoundingRect(); QPoint s(qRound(res * (whereToStart.x() - bsbr.topLeft().x()) / FSvgRenderer::printerScale()), qRound(res * (whereToStart.y() - bsbr.topLeft().y()) / FSvgRenderer::printerScale())); QBitArray redMarker(image->height() * image->width(), false); QRgb pixel = image->pixel(s); DebugDialog::debug(QString("unit %1").arg(pixel, 0, 16)); if (pixel != 0xffffffff) { // starting off in bad territory delete image; return false; } // step 1 flood fill white to "red" (keep max locations) int minY = image->height(); int maxY = 0; int minX = image->width(); int maxX = 0; QList<QPoint> stack; stack << s; while (stack.count() > 0) { QPoint p = stack.takeFirst(); if (p.x() < 0) continue; if (p.y() < 0) continue; if (p.x() >= image->width()) continue; if (p.y() >= image->height()) continue; if (redMarker.testBit(OFFSET(p.x(), p.y(), image))) continue; // already been here QRgb pixel = image->pixel(p); if (pixel != 0xffffffff) continue; // black; bail redMarker.setBit(OFFSET(p.x(), p.y(), image), true); if (p.x() > maxX) maxX = p.x(); if (p.x() < minX) minX = p.x(); if (p.y() > maxY) maxY = p.y(); if (p.y() < minY) minY = p.y(); stack.append(QPoint(p.x() - 1, p.y())); stack.append(QPoint(p.x() + 1, p.y())); stack.append(QPoint(p.x(), p.y() - 1)); stack.append(QPoint(p.x(), p.y() + 1)); } //image->save("testPoly1.png"); // step 2 replace white with black image->fill(0); // step 3 replace "red" with white for (int y = 0; y < image->height(); y++) { for (int x = 0; x < image->width(); x++) { if (redMarker.testBit(OFFSET(x, y, image))) { image->setPixel(x, y, 1); } } } #ifndef QT_NO_DEBUG image->save("testGroundPlaneUnit3.png"); #endif scanImage(*image, bWidth, bHeight, GraphicsUtils::StandardFritzingDPI / res, res, color, true, true, QSizeF(.05, .05), 1 / FSvgRenderer::printerScale(), QPointF(0,0)); delete image; return true; }
void ccHistogramWindow::mouseMoveEvent(QMouseEvent *event) { if (event->buttons() & Qt::LeftButton) { if (m_sfInteractionMode) { QPoint mousePos = event->pos(); if (m_histogram) { QRect rect = m_histogram->rect(); mousePos.setX(std::min(rect.x()+rect.width(),std::max(rect.x(),mousePos.x()))); } switch(m_selectedItem) { case NONE: //nothing to do break; case LEFT_AREA: if (m_areaLeft) { double newValue = m_areaLeft->pixelToKey(mousePos.x()); if (m_areaRight) newValue = std::min(newValue,m_areaRight->currentVal()); setMinDispValue(newValue); } break; case RIGHT_AREA: if (m_areaRight) { double newValue = m_areaRight->pixelToKey(mousePos.x()); if (m_areaLeft) newValue = std::max(newValue,m_areaLeft->currentVal()); setMaxDispValue(newValue); } break; case BOTH_AREAS: { int dx = m_lastMouseClick.x() - mousePos.x(); if (dx < -2) { //going to the right m_selectedItem = RIGHT_AREA; //call the same method again mouseMoveEvent(event); return; } else if (dx > 2) { //going to the left m_selectedItem = LEFT_AREA; //call the same method again mouseMoveEvent(event); return; } //else: nothing we can do right now! } break; case LEFT_ARROW: if (m_arrowLeft) { double newValue = m_arrowLeft->pixelToKey(mousePos.x()); if (m_arrowRight) newValue = std::min(newValue,m_arrowRight->currentVal()); setMinSatValue(newValue); } break; case RIGHT_ARROW: if (m_arrowRight) { double newValue = m_arrowRight->pixelToKey(mousePos.x()); if (m_arrowLeft) newValue = std::max(newValue,m_arrowLeft->currentVal()); setMaxSatValue(newValue); } break; case BOTH_ARROWS: { int dx = m_lastMouseClick.x() - mousePos.x(); if (dx < -2) { //going to the right m_selectedItem = RIGHT_ARROW; //call the same method again mouseMoveEvent(event); return; } else if (dx > 2) { //going to the left m_selectedItem = LEFT_ARROW; //call the same method again mouseMoveEvent(event); return; } //else: nothing we can do right now! } break; default: assert(false); break; } } else { if (m_histogram && !m_histoValues.empty()) { QRect roi = m_histogram->rect(); if (roi.contains(event->pos(),false)) { m_drawVerticalIndicator = true; int verticalIndicatorPosition = (static_cast<int>(m_histoValues.size()) * (event->x() - roi.x())) / roi.width(); m_verticalIndicatorPositionPercent = static_cast<double>(verticalIndicatorPosition) / m_histoValues.size(); refresh(); } } } } else { event->ignore(); } }