void ToolButton::enterEvent( QEvent * _e ) { m_mouseOver = true; if( !s_toolTipsDisabled && !m_title.isEmpty() && !m_descr.isEmpty() ) { QPoint p = mapToGlobal( QPoint( 0, 0 ) ); int scr = QApplication::desktop()->isVirtualDesktop() ? QApplication::desktop()->screenNumber( p ) : QApplication::desktop()->screenNumber( this ); #ifdef Q_WS_MAC QRect screen = QApplication::desktop()->availableGeometry( scr ); #else QRect screen = QApplication::desktop()->screenGeometry( scr ); #endif ToolButtonTip * tbt = new ToolButtonTip( m_pixmap, m_title, m_descr, QApplication::desktop()->screen( scr ), this ); connect( this, SIGNAL( mouseLeftButton() ), tbt, SLOT( close() ) ); if( p.x() + tbt->width() > screen.x() + screen.width() ) p.rx() -= 4;// + tbt->width(); if( p.y() + tbt->height() > screen.y() + screen.height() ) p.ry() -= 30 + tbt->height(); if( p.y() < screen.y() ) p.setY( screen.y() ); if( p.x() + tbt->width() > screen.x() + screen.width() ) p.setX( screen.x() + screen.width() - tbt->width() ); if( p.x() < screen.x() ) p.setX( screen.x() ); if( p.y() + tbt->height() > screen.y() + screen.height() ) p.setY( screen.y() + screen.height() - tbt->height() ); tbt->move( p += QPoint( -4, height() ) ); tbt->show(); } QToolButton::enterEvent( _e ); }
void MemcheckErrorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &basicOption, const QModelIndex &index) const { QStyleOptionViewItemV4 opt(basicOption); initStyleOption(&opt, index); const QListView *const view = qobject_cast<const QListView *>(parent()); const bool isSelected = view->selectionModel()->currentIndex() == index; QFontMetrics fm(opt.font); QPoint pos = opt.rect.topLeft(); painter->save(); const QColor bgColor = isSelected ? opt.palette.highlight().color() : opt.palette.background().color(); painter->setBrush(bgColor); // clear background painter->setPen(Qt::NoPen); painter->drawRect(opt.rect); pos.rx() += s_itemMargin; pos.ry() += s_itemMargin; const Error error = index.data(ErrorListModel::ErrorRole).value<Error>(); if (isSelected) { // only show detailed widget and let it handle everything QTC_ASSERT(m_detailsIndex == index, qt_noop()); QTC_ASSERT(m_detailsWidget, return); // should have been set in sizeHint() m_detailsWidget->move(pos); // when scrolling quickly, the widget can get stuck in a visible part of the scroll area // even though it should not be visible. therefore we hide it every time the scroll value // changes and un-hide it when the item with details widget is paint()ed, i.e. visible. m_detailsWidget->show(); const int viewportWidth = view->viewport()->width(); const int widthExcludingMargins = viewportWidth - 2 * s_itemMargin; QTC_ASSERT(m_detailsWidget->width() == widthExcludingMargins, qt_noop()); QTC_ASSERT(m_detailsWidgetHeight == m_detailsWidget->height(), qt_noop()); } else {
KDiamond::Board::Board(KGameRenderer* renderer) : m_difficultyIndex(Kg::difficultyLevel() / 10 - 2) , m_size(boardSizes[m_difficultyIndex]) , m_colorCount(boardColorCounts[m_difficultyIndex]) , m_paused(false) , m_renderer(renderer) , m_diamonds(m_size * m_size, 0) { for (QPoint point; point.x() < m_size; ++point.rx()) for (point.ry() = 0; point.y() < m_size; ++point.ry()) { //displacement vectors needed for the following algorithm const QPoint dispY1(0, -1), dispY2(0, -2); const QPoint dispX1(-1, 0), dispX2(-2, 0); //roll the dice to get a color, but ensure that there are not three of a color in a row from the start int color; while (true) { color = qrand() % m_colorCount + 1; // +1 because numbering of enum KDiamond::Color starts at 1 //condition: no triplet in y axis (attention: only the diamonds above us are defined already) if (point.y() >= 2) //no triplet possible for i = 0, 1 { const int otherColor1 = diamond(point + dispY1)->color(); const int otherColor2 = diamond(point + dispY2)->color(); if (otherColor1 == color && otherColor2 == color) continue; //roll the dice again } //same condition on x axis if (point.x() >= 2) { const int otherColor1 = diamond(point + dispX1)->color(); const int otherColor2 = diamond(point + dispX2)->color(); if (otherColor1 == color && otherColor2 == color) continue; } break; } rDiamond(point) = spawnDiamond(color); diamond(point)->setPos(point); } }
void AnimationModule::renameSelectedNode() { const std::list<NodeAnimPtr >& selectedNodes = _imp->selectionModel->getCurrentNodesSelection(); if ( selectedNodes.empty() || (selectedNodes.size() > 1) ) { Dialogs::errorDialog( tr("Rename node").toStdString(), tr("You must select exactly 1 node to rename.").toStdString() ); return; } EditNodeNameDialog* dialog = new EditNodeNameDialog(selectedNodes.front()->getNodeGui(), _imp->editor); QPoint global = QCursor::pos(); QSize sizeH = dialog->sizeHint(); global.rx() -= sizeH.width() / 2; global.ry() -= sizeH.height() / 2; QPoint realPos = global; QObject::connect( dialog, SIGNAL(rejected()), this, SLOT(onNodeNameEditDialogFinished()) ); QObject::connect( dialog, SIGNAL(accepted()), this, SLOT(onNodeNameEditDialogFinished()) ); dialog->move( realPos.x(), realPos.y() ); dialog->raise(); dialog->show(); }
void FormEditorGraphicsView::mouseMoveEvent(QMouseEvent *event) { if (rect().contains(event->pos())) { QGraphicsView::mouseMoveEvent(event); } else { QPoint position = event->pos(); QPoint topLeft = rect().topLeft(); QPoint bottomRight = rect().bottomRight(); position.rx() = qMax(topLeft.x(), qMin(position.x(), bottomRight.x())); position.ry() = qMax(topLeft.y(), qMin(position.y(), bottomRight.y())); QMouseEvent *mouseEvent = QMouseEvent::createExtendedMouseEvent(event->type(), position, mapToGlobal(position), event->button(), event->buttons(), event->modifiers()); QGraphicsView::mouseMoveEvent(mouseEvent); delete mouseEvent; } // Keeps the feedback bubble within screen boundraries int tx = qMin(width() - 114, qMax(16, event->pos().x() + 50)); int ty = qMin(height() - 45, qMax(10, event->pos().y() - 70)); m_feedbackOriginPoint = QPoint(tx, ty); }
void CMoveWidget::mouseMoveEvent(QMouseEvent *mouseEvent) { QPoint p = mouseEvent->globalPos() - dragStartMousePosition; if (p.manhattanLength() < QApplication::startDragDistance()) return; QPoint r = dragStartWidgetPosition + p; if (r.x() < 0) r.setX(0); if (r.y() < 0) r.setY(0); int maxW = this->parentWidget()->geometry().width() - this->geometry().width(); int maxH = this->parentWidget()->geometry().height() - this->geometry().height(); if (r.rx() > maxW) r.setX(maxW); if (r.ry() > maxH) r.setY(maxH); move(r); QWidget::mouseMoveEvent(mouseEvent); }
uint VirtualDesktopManager::toLeft(uint id, bool wrap) const { if (id == 0) { id = current(); } QPoint coords = m_grid.gridCoords(id); Q_ASSERT(coords.x() >= 0); while (true) { coords.rx()--; if (coords.x() < 0) { if (wrap) { coords.setX(m_grid.width() - 1); } else { return id; // Already at the left-most desktop } } const uint desktop = m_grid.at(coords); if (desktop > 0) { return desktop; } } }
void DJGameUserContext::moveToAppropriatePos() { QDesktopWidget desktop; QRect availableRect = desktop.availableGeometry(); QPoint currentPos = QCursor::pos(); QSize contextSize = size(); QRect contextRect( currentPos, contextSize ); if ( !availableRect.contains( contextRect ) ) { QPoint rightTop = QPoint( currentPos.x() + contextSize.width(), currentPos.y() ); QPoint leftBottom = QPoint( currentPos.x(), currentPos.y() + contextSize.height() ); if ( !availableRect.contains(rightTop) ) { currentPos.rx() -= contextSize.width(); } if ( !availableRect.contains(leftBottom) ) { currentPos.ry() -= contextSize.height(); } } move( currentPos ); }
void PopupWidget::prepare(PlayListTrack *item, QPoint pos) { pos += QPoint(15,10); m_url = item->url(); hide(); if(!item) { m_timer->stop(); return; } m_label1->setText(m_formatter.format(item)); qApp->processEvents(); updateGeometry (); resize(sizeHint()); qApp->processEvents(); m_timer->start(); QRect rect = QApplication::desktop()->availableGeometry(this); if(pos.x() + width() > rect.x() + rect.width()) pos.rx() -= width(); move(pos); }
void Cocos2dxView::attachSpriteToMouse() { ListWidgetItem *item = (ListWidgetItem*)m_listwidget->currentItem(); if (!item) return; EditorScene *scene = getEditorScene(); if (scene) { QRect r = this->geometry(); if (!m_mouseSprite) { m_mouseSprite = CCSprite::create(item->getAbsoluteFilePath().toLatin1().data()); m_mouseSprite->setOpacity(128); scene->addChild(m_mouseSprite); } QPoint pos = mapFromGlobal(QCursor::pos()); m_mouseSprite->setPosition(ccp(pos.rx(), r.height() - pos.ry())); //qt的ui y轴坐标转换为opengl的y轴坐标 m_mouseTimer.setParent(this); connect(&m_mouseTimer, SIGNAL(timeout()), this, SLOT(mouseMoveInView())); m_mouseTimer.start(20); } }
LockedDialog::LockedDialog(QWidget *parent, const QString &text, bool unlockButton) : QDialog(parent) , ui(new Ui::LockedDialog) , m_UnlockClicked(false) { ui->setupUi(this); this->setWindowFlags(this->windowFlags() | Qt::ToolTip | Qt::FramelessWindowHint); if (parent != nullptr) { QPoint position = parent->mapToGlobal(QPoint(parent->width() / 2, parent->height() / 2)); position.rx() -= this->width() / 2; position.ry() -= this->height() / 2; move(position); } if (text.length() > 0) { ui->label->setText(text); } if (!unlockButton) { ui->unlockButton->hide(); } }
void MathTest::doProblem() { TESTPARM *pt = &testMatrix[testIndex]; QString opStr = mt::opStrings[testIndex]; QPoint ops; if(pt->bFirst) { pt->bFirst = false; pt->opLimits.setRect(0, pt->maxops.iaLop[iGradeLevel], 0, pt->maxops.iaRop[iGradeLevel]); rnd.setMinMax(pt->opLimits); } switch((int)pt->eOp) { case op_add: rnd.getPair(ops); pt->iAnswer = ops.x() + ops.y(); break; case op_sub: rnd.getPair(ops, true ); pt->iAnswer = ops.x() - ops.y(); break; case op_mul: rnd.getPair(ops); pt->iAnswer = ops.x() * ops.y(); break; case op_div: ops.ry() = rnd.getOneUnique(1, pt->maxops.iaRop[iGradeLevel]); ops.rx() = rnd.getOne(1, pt->maxops.iaLop[iGradeLevel]) * ops.y(); pt->iAnswer = ops.x() / ops.y(); break; } printProb(ops, opStr); }
//----------------------------------------------------------------------------- //! //----------------------------------------------------------------------------- QRect tWindPlotGraph::DrawXAxisLabel(QPainter* pPainter, eGraphType graphType, qreal value, eXAxisLabel labelType, QRect& avoidRect) { QFontMetrics fm = QFontMetrics(pPainter->font()); QPoint textPoint = GraphToPixel(graphType, 0, value).toPoint(); textPoint.ry() -= (m_GraphConfig.topMarginHeight ); QString label; if(graphType == eGraphType_TWD) { if(value < 0.0F) { label = QString("%1").arg( static_cast<int>( m_GraphConfig.circularLimit[graphType] ) + ( static_cast<int>(value) % static_cast<int>( m_GraphConfig.circularLimit[graphType] ) ), 3, 10, QChar( '0' ) ); } else { label = QString("%1").arg( static_cast<int>( value ) % static_cast<int>( m_GraphConfig.circularLimit[graphType] ), 3, 10, QChar( '0' ) ); } if( "360" == label ) { label = "000"; } } else { label = QString("%1").arg(value, 0, 'f', 1); } QRect boundingRect = fm.boundingRect( " " + label + " " ); // Determine the X position depending on the label type int labelXPos; switch(labelType) { case eXAxisLabel_Left : // Start label at the left hand axis labelXPos = textPoint.rx(); break; case eXAxisLabel_Average : // Put centre of label where average value is labelXPos = textPoint.rx() - (boundingRect.width() / 2); // Check the label doesn't go past either axis if(labelXPos < m_GraphConfig.originX[graphType]) { labelXPos = m_GraphConfig.originX[graphType]; } if((labelXPos + boundingRect.width()) > (m_GraphConfig.originX[graphType] + m_GraphConfig.extentX[graphType])) { labelXPos = m_GraphConfig.originX[graphType] + m_GraphConfig.extentX[graphType] - boundingRect.width(); } break; case eXAxisLabel_Right : // Put right of label at the right hand axis labelXPos = textPoint.rx() - boundingRect.width(); break; default : Q_ASSERT(0); labelXPos = textPoint.rx() - (boundingRect.width() / 2); break; } QRect textRect = QRect(labelXPos, textPoint.ry(), boundingRect.width(), boundingRect.height() ); if ( labelType == eXAxisLabel_Average ) { QColor averageColor( Qt::red ); pPainter->save(); pPainter->setPen( averageColor ); pPainter->drawText(textRect, Qt::AlignCenter, label ); averageColor.setAlpha(128); pPainter->setPen( averageColor ); pPainter->drawLine( textPoint.rx(), m_GraphConfig.originY, textPoint.rx(), (m_GraphConfig.originY + m_GraphConfig.extentY) ); pPainter->restore(); } else { // Check if this text will avoid the average text already displayed if(textRect.intersects(avoidRect) == false) { pPainter->drawText(textRect, Qt::AlignCenter, label ); } } // Return the rect containing the text with a bit of a margin textRect.adjust(-10, 0, 10, 0); return textRect; }
void IsometricRenderer::drawTileLayer(QPainter *painter, const TileLayer *layer, const QRectF &exposed) const { const int tileWidth = map()->tileWidth(); const int tileHeight = map()->tileHeight(); if (tileWidth <= 0 || tileHeight <= 1) return; QRect rect = exposed.toAlignedRect(); if (rect.isNull()) rect = boundingRect(layer->bounds()); QMargins drawMargins = layer->drawMargins(); drawMargins.setTop(drawMargins.top() - tileHeight); drawMargins.setRight(drawMargins.right() - tileWidth); rect.adjust(-drawMargins.right(), -drawMargins.bottom(), drawMargins.left(), drawMargins.top()); // Determine the tile and pixel coordinates to start at QPointF tilePos = pixelToTileCoords(rect.x(), rect.y()); QPoint rowItr = QPoint((int) std::floor(tilePos.x()), (int) std::floor(tilePos.y())); QPointF startPos = tileToPixelCoords(rowItr); startPos.rx() -= tileWidth / 2; startPos.ry() += tileHeight; // Compensate for the layer position rowItr -= QPoint(layer->x(), layer->y()); /* Determine in which half of the tile the top-left corner of the area we * need to draw is. If we're in the upper half, we need to start one row * up due to those tiles being visible as well. How we go up one row * depends on whether we're in the left or right half of the tile. */ const bool inUpperHalf = startPos.y() - rect.y() > tileHeight / 2; const bool inLeftHalf = rect.x() - startPos.x() < tileWidth / 2; if (inUpperHalf) { if (inLeftHalf) { --rowItr.rx(); startPos.rx() -= tileWidth / 2; } else { --rowItr.ry(); startPos.rx() += tileWidth / 2; } startPos.ry() -= tileHeight / 2; } // Determine whether the current row is shifted half a tile to the right bool shifted = inUpperHalf ^ inLeftHalf; QTransform baseTransform = painter->transform(); for (int y = startPos.y(); y - tileHeight < rect.bottom(); y += tileHeight / 2) { QPoint columnItr = rowItr; for (int x = startPos.x(); x < rect.right(); x += tileWidth) { if (layer->contains(columnItr)) { const Cell &cell = layer->cellAt(columnItr); if (!cell.isEmpty()) { const QPixmap &img = cell.tile->image(); const QPoint offset = cell.tile->tileset()->tileOffset(); qreal m11 = 1; // Horizontal scaling factor qreal m12 = 0; // Vertical shearing factor qreal m21 = 0; // Horizontal shearing factor qreal m22 = 1; // Vertical scaling factor qreal dx = offset.x() + x; qreal dy = offset.y() + y - img.height(); if (cell.flippedAntiDiagonally) { // Use shearing to swap the X/Y axis m11 = 0; m12 = 1; m21 = 1; m22 = 0; // Compensate for the swap of image dimensions dy += img.height() - img.width(); } if (cell.flippedHorizontally) { m11 = -m11; m21 = -m21; dx += cell.flippedAntiDiagonally ? img.height() : img.width(); } if (cell.flippedVertically) { m12 = -m12; m22 = -m22; dy += cell.flippedAntiDiagonally ? img.width() : img.height(); } const QTransform transform(m11, m12, m21, m22, dx, dy); painter->setTransform(transform * baseTransform); painter->drawPixmap(0, 0, img); } } // Advance to the next column ++columnItr.rx(); --columnItr.ry(); } // Advance to the next row if (!shifted) { ++rowItr.rx(); startPos.rx() += tileWidth / 2; shifted = true; } else { ++rowItr.ry(); startPos.rx() -= tileWidth / 2; shifted = false; } } painter->setTransform(baseTransform); }
NodeCreationDialog::NodeCreationDialog(const QString& initialFilter, QWidget* parent) : QDialog(parent) , _imp( new NodeCreationDialogPrivate() ) { setWindowTitle( tr("Node Creation Tool") ); setWindowFlags(Qt::Window | Qt::CustomizeWindowHint); setObjectName( QString::fromUtf8("nodeCreationDialog") ); setAttribute(Qt::WA_DeleteOnClose, false); _imp->layout = new QVBoxLayout(this); _imp->layout->setContentsMargins(0, 0, 0, 0); CompleterLineEdit::PluginsNamesMap pluginsMap; QString initialFilterName; std::string stdInitialFilter = initialFilter.toStdString(); int i = 0; for (PluginsMap::iterator it = _imp->items.begin(); it != _imp->items.end(); ++it) { if ( it->second.empty() ) { continue; } if (it->second.size() == 1) { std::pair<QString, QString> idNamePair; Plugin* p = ( *it->second.begin() ); if ( !p->getIsUserCreatable() ) { continue; } idNamePair.second = p->generateUserFriendlyPluginID(); int indexOfBracket = idNamePair.second.lastIndexOf( QString::fromUtf8(" [") ); if (indexOfBracket != -1) { idNamePair.first = idNamePair.second.left(indexOfBracket); } int weight = getPluginWeight( p->getPluginID(), p->getMajorVersion() ); pluginsMap.insert( std::make_pair(weight, idNamePair) ); if (it->first == stdInitialFilter) { initialFilterName = idNamePair.first; } ++i; } else { QString bestMajorName; for (PluginMajorsOrdered::reverse_iterator it2 = it->second.rbegin(); it2 != it->second.rend(); ++it2) { if ( !(*it2)->getIsUserCreatable() ) { continue; } std::pair<QString, QString> idNamePair; if ( it2 == it->second.rbegin() ) { idNamePair.second = (*it2)->generateUserFriendlyPluginID(); bestMajorName = idNamePair.second; } else { idNamePair.second = (*it2)->generateUserFriendlyPluginIDMajorEncoded(); } int indexOfBracket = idNamePair.second.lastIndexOf( QString::fromUtf8(" [") ); if (indexOfBracket != -1) { idNamePair.first = idNamePair.second.left(indexOfBracket); } ++i; int weight = getPluginWeight( (*it2)->getPluginID(), (*it2)->getMajorVersion() ); pluginsMap.insert( std::make_pair(weight, idNamePair) ); } if (it->first == stdInitialFilter) { initialFilterName = bestMajorName; } } } _imp->textEdit = new CompleterLineEdit(pluginsMap, true, this); if ( !initialFilterName.isEmpty() ) { _imp->textEdit->setText(initialFilterName); } QPoint global = QCursor::pos(); QSize sizeH = sizeHint(); global.rx() -= sizeH.width() / 2; global.ry() -= sizeH.height() / 2; move( global.x(), global.y() ); _imp->layout->addWidget(_imp->textEdit); _imp->textEdit->setFocus(); _imp->textEdit->selectAll(); QTimer::singleShot( 20, _imp->textEdit, SLOT(showCompleter()) ); }
void IsometricRenderer::drawTileLayer(QPainter *painter, const TileLayer *layer, const QRectF &exposed) const { const int tileWidth = map()->tileWidth(); const int tileHeight = map()->tileHeight(); QRect rect = exposed.toAlignedRect(); if (rect.isNull()) rect = boundingRect(layer->bounds()); const QSize maxTileSize = layer->maxTileSize(); const int extraWidth = maxTileSize.width() - tileWidth; const int extraHeight = maxTileSize.height() - tileHeight; rect.adjust(-extraWidth, 0, 0, extraHeight); // Determine the tile and pixel coordinates to start at QPointF tilePos = pixelToTileCoords(rect.x(), rect.y()); QPoint rowItr = QPoint((int) std::floor(tilePos.x()), (int) std::floor(tilePos.y())); QPointF startPos = tileToPixelCoords(rowItr); startPos.rx() -= tileWidth / 2; startPos.ry() += tileHeight; // Compensate for the layer position rowItr -= QPoint(layer->x(), layer->y()); /* Determine in which half of the tile the top-left corner of the area we * need to draw is. If we're in the upper half, we need to start one row * up due to those tiles being visible as well. How we go up one row * depends on whether we're in the left or right half of the tile. */ const bool inUpperHalf = startPos.y() - rect.y() > tileHeight / 2; const bool inLeftHalf = rect.x() - startPos.x() < tileWidth / 2; if (inUpperHalf) { if (inLeftHalf) { --rowItr.rx(); startPos.rx() -= tileWidth / 2; } else { --rowItr.ry(); startPos.rx() += tileWidth / 2; } startPos.ry() -= tileHeight / 2; } // Determine whether the current row is shifted half a tile to the right bool shifted = inUpperHalf ^ inLeftHalf; for (int y = startPos.y(); y - tileHeight < rect.bottom(); y += tileHeight / 2) { QPoint columnItr = rowItr; for (int x = startPos.x(); x < rect.right(); x += tileWidth) { if (layer->contains(columnItr)) { if (const Tile *tile = layer->tileAt(columnItr)) { const QPixmap &img = tile->image(); painter->drawPixmap(x, y - img.height(), img); } } // Advance to the next column ++columnItr.rx(); --columnItr.ry(); } // Advance to the next row if (!shifted) { ++rowItr.rx(); startPos.rx() += tileWidth / 2; shifted = true; } else { ++rowItr.ry(); startPos.rx() -= tileWidth / 2; shifted = false; } } }
void Q3DockArea::moveDockWindow(Q3DockWindow *w, const QPoint &p, const QRect &r, bool swap) { invalidateFixedSizes(); int mse = -10; bool hasResizable = false; for (int i = 0; i < dockWindows.size(); ++i) { Q3DockWindow *dw = dockWindows.at(i); if (dw->isHidden()) continue; if (dw->isResizeEnabled()) hasResizable = true; if (orientation() != Qt::Horizontal) mse = qMax(qMax(dw->fixedExtent().width(), dw->width()), mse); else mse = qMax(qMax(dw->fixedExtent().height(), dw->height()), mse); } if (!hasResizable && w->isResizeEnabled()) { if (orientation() != Qt::Horizontal) mse = qMax(w->fixedExtent().width(), mse); else mse = qMax(w->fixedExtent().height(), mse); } Q3DockWindow *dockWindow = 0; int dockWindowIndex = findDockWindow(w); QList<Q3DockWindow *> lineStarts = layout->lineStarts(); QList<QRect> lines = layout->lineList(); bool wasAloneInLine = false; QPoint pos = mapFromGlobal(p); int line = lineOf(dockWindowIndex); QRect lr; if (line < lines.size()) lr = lines.at(line); if (dockWindowIndex != -1) { if (lineStarts.contains(w) && ((dockWindowIndex < dockWindows.count() - 1 && lineStarts.contains(dockWindows.at(dockWindowIndex + 1))) || dockWindowIndex == dockWindows.count() - 1)) wasAloneInLine = true; dockWindow = dockWindows.takeAt(dockWindowIndex); if (!wasAloneInLine) { // only do the pre-layout if the widget isn't the only one in its line if (lineStarts.contains(dockWindow) && dockWindowIndex < dockWindows.count()) dockWindows.at(dockWindowIndex)->setNewLine(true); layout->layoutItems(QRect(0, 0, width(), height()), true); } } else { dockWindow = w; bool vis = dockWindow->isVisible(); dockWindow->setParent(this); dockWindow->move(0, 0); if(vis) dockWindow->show(); if (swap) dockWindow->resize(dockWindow->height(), dockWindow->width()); w->installEventFilter(this); } lineStarts = layout->lineStarts(); lines = layout->lineList(); QRect rect = QRect(mapFromGlobal(r.topLeft()), r.size()); if (orientation() == Qt::Horizontal && QApplication::reverseLayout()) { rect = QRect(width() - rect.x() - rect.width(), rect.y(), rect.width(), rect.height()); pos.rx() = width() - pos.x(); } dockWindow->setOffset(point_pos(rect.topLeft(), orientation())); if (orientation() == Qt::Horizontal) { int offs = dockWindow->offset(); if (width() - offs < dockWindow->minimumWidth()) dockWindow->setOffset(width() - dockWindow->minimumWidth()); } else { int offs = dockWindow->offset(); if (height() - offs < dockWindow->minimumHeight()) dockWindow->setOffset(height() - dockWindow->minimumHeight()); } if (dockWindows.isEmpty()) { dockWindows.append(dockWindow); } else { int dockLine = -1; bool insertLine = false; int i = 0; QRect lineRect; // find the line which we touched with the mouse for (QList<QRect>::Iterator it = lines.begin(); it != lines.end(); ++it, ++i) { if (point_pos(pos, orientation(), true) >= point_pos((*it).topLeft(), orientation(), true) && point_pos(pos, orientation(), true) <= point_pos((*it).topLeft(), orientation(), true) + size_extent((*it).size(), orientation(), true)) { dockLine = i; lineRect = *it; break; } } if (dockLine == -1) { // outside the dock... insertLine = true; if (point_pos(pos, orientation(), true) < 0) // insert as first line dockLine = 0; else dockLine = (int)lines.count(); // insert after the last line ### size_t/int cast } else { // inside the dock (we have found a dockLine) if (point_pos(pos, orientation(), true) < point_pos(lineRect.topLeft(), orientation(), true) + 4) { // mouse was at the very beginning of the line insertLine = true; // insert a new line before that with the docking widget } else if (point_pos(pos, orientation(), true) > point_pos(lineRect.topLeft(), orientation(), true) + size_extent(lineRect.size(), orientation(), true) - 4) { // mouse was at the very and of the line insertLine = true; // insert a line after that with the docking widget dockLine++; } } if (!insertLine && wasAloneInLine && lr.contains(pos)) // if we are alone in a line and just moved in there, re-insert it insertLine = true; #if defined(QDOCKAREA_DEBUG) qDebug("insert in line %d, and insert that line: %d", dockLine, insertLine); qDebug(" (btw, we have %d lines)", lines.count()); #endif Q3DockWindow *dw = 0; if (dockLine >= (int)lines.count()) { // insert after last line dockWindows.append(dockWindow); dockWindow->setNewLine(true); #if defined(QDOCKAREA_DEBUG) qDebug("insert at the end"); #endif } else if (dockLine == 0 && insertLine) { // insert before first line dockWindows.insert(0, dockWindow); dockWindows.at(1)->setNewLine(true); #if defined(QDOCKAREA_DEBUG) qDebug("insert at the begin"); #endif } else { // insert somewhere in between // make sure each line start has a new line for (int i = 0; i < lineStarts.size(); ++i) { dw = lineStarts.at(i); dw->setNewLine(true); } // find the index of the first widget in the search line int searchLine = dockLine; #if defined(QDOCKAREA_DEBUG) qDebug("search line start of %d", searchLine); #endif Q3DockWindow *lsw = lineStarts.at(searchLine); int index = dockWindows.indexOf(lsw); if (index == -1) { // the linestart widget hasn't been found, try to find it harder if (lsw == w && dockWindowIndex <= dockWindows.count()) index = dockWindowIndex; else index = 0; } #if defined(QDOCKAREA_DEBUG) qDebug(" which starts at %d", index); #endif if (!insertLine) { // if we insert the docking widget in the existing line // find the index for the widget bool inc = true; bool firstTime = true; for (int i = index; i < dockWindows.size(); ++i) { dw = dockWindows.at(i); if (orientation() == Qt::Horizontal) dw->setFixedExtentWidth(-1); else dw->setFixedExtentHeight(-1); if (!firstTime && lineStarts.contains(dw)) // we are in the next line, so break break; if (point_pos(pos, orientation()) < point_pos(fix_pos(dw), orientation()) + size_extent(dw->size(), orientation()) / 2) { inc = false; } if (inc) index++; firstTime = false; } #if defined(QDOCKAREA_DEBUG) qDebug("insert at index: %d", index); #endif // if we insert it just before a widget which has a new line, transfer the newline to the docking widget // but not if we didn't only mave a widget in its line which was alone in the line before if (!(wasAloneInLine && lr.contains(pos)) && index >= 0 && index < dockWindows.count() && dockWindows.at(index)->newLine() && lineOf(index) == dockLine) { #if defined(QDOCKAREA_DEBUG) qDebug("get rid of the old newline and get me one"); #endif dockWindows.at(index)->setNewLine(false); dockWindow->setNewLine(true); } else if (wasAloneInLine && lr.contains(pos)) { dockWindow->setNewLine(true); } else { // if we are somewhere in a line, get rid of the newline dockWindow->setNewLine(false); } } else { // insert in a new line, so make sure the dock widget and the widget which will be after it have a newline #if defined(QDOCKAREA_DEBUG) qDebug("insert a new line"); #endif if (index < dockWindows.count()) { #if defined(QDOCKAREA_DEBUG) qDebug("give the widget at %d a newline", index); #endif Q3DockWindow* nldw = dockWindows.at(index); if (nldw) nldw->setNewLine(true); } #if defined(QDOCKAREA_DEBUG) qDebug("give me a newline"); #endif dockWindow->setNewLine(true); } // finally insert the widget dockWindows.insert(index, dockWindow); } } if (mse != -10 && w->isResizeEnabled()) { if (orientation() != Qt::Horizontal) w->setFixedExtentWidth(qMin(qMax(w->minimumWidth(), mse), w->sizeHint().width())); else w->setFixedExtentHeight(qMin(qMax(w->minimumHeight(), mse), w->sizeHint().height())); } updateLayout(); setSizePolicy(QSizePolicy(orientation() == Qt::Horizontal ? QSizePolicy::Expanding : QSizePolicy::Minimum, orientation() == Qt::Vertical ? QSizePolicy::Expanding : QSizePolicy::Minimum)); }
void IsometricRenderer::drawTileLayer(QPainter *painter, const TileLayer *layer, const QRectF &exposed) const { const int tileWidth = map()->tileWidth(); const int tileHeight = map()->tileHeight(); if (tileWidth <= 0 || tileHeight <= 1) return; QRect rect = exposed.toAlignedRect(); if (rect.isNull()) rect = boundingRect(layer->bounds()); QMargins drawMargins = layer->drawMargins(); drawMargins.setTop(drawMargins.top() - tileHeight); drawMargins.setRight(drawMargins.right() - tileWidth); rect.adjust(-drawMargins.right(), -drawMargins.bottom(), drawMargins.left(), drawMargins.top()); // Determine the tile and pixel coordinates to start at QPointF tilePos = screenToTileCoords(rect.x(), rect.y()); QPoint rowItr = QPoint((int) std::floor(tilePos.x()), (int) std::floor(tilePos.y())); QPointF startPos = tileToScreenCoords(rowItr); startPos.rx() -= tileWidth / 2; startPos.ry() += tileHeight; // Compensate for the layer position rowItr -= QPoint(layer->x(), layer->y()); /* Determine in which half of the tile the top-left corner of the area we * need to draw is. If we're in the upper half, we need to start one row * up due to those tiles being visible as well. How we go up one row * depends on whether we're in the left or right half of the tile. */ const bool inUpperHalf = startPos.y() - rect.y() > tileHeight / 2; const bool inLeftHalf = rect.x() - startPos.x() < tileWidth / 2; if (inUpperHalf) { if (inLeftHalf) { --rowItr.rx(); startPos.rx() -= tileWidth / 2; } else { --rowItr.ry(); startPos.rx() += tileWidth / 2; } startPos.ry() -= tileHeight / 2; } // Determine whether the current row is shifted half a tile to the right bool shifted = inUpperHalf ^ inLeftHalf; CellRenderer renderer(painter); for (int y = startPos.y(); y - tileHeight < rect.bottom(); y += tileHeight / 2) { QPoint columnItr = rowItr; for (int x = startPos.x(); x < rect.right(); x += tileWidth) { if (layer->contains(columnItr)) { const Cell &cell = layer->cellAt(columnItr); if (!cell.isEmpty()) { renderer.render(cell, QPointF(x, y), QSizeF(0, 0), CellRenderer::BottomLeft); } } // Advance to the next column ++columnItr.rx(); --columnItr.ry(); } // Advance to the next row if (!shifted) { ++rowItr.rx(); startPos.rx() += tileWidth / 2; shifted = true; } else { ++rowItr.ry(); startPos.rx() -= tileWidth / 2; shifted = false; } } }
void StaggeredRenderer::drawTileLayer(QPainter *painter, const TileLayer *layer, const QRectF &exposed) const { const int tileWidth = map()->tileWidth(); const int tileHeight = map()->tileHeight(); QRect rect = exposed.toAlignedRect(); if (rect.isNull()) rect = boundingRect(layer->bounds()); QMargins drawMargins = layer->drawMargins(); drawMargins.setRight(drawMargins.right() - tileWidth); rect.adjust(-drawMargins.right(), -drawMargins.bottom(), drawMargins.left(), drawMargins.top()); // Determine the tile and pixel coordinates to start at QPoint startTile = pixelToTileCoords(rect.x(), rect.y()).toPoint(); // Compensate for the layer position startTile -= layer->position(); QPoint startPos = tileToPixelCoords(startTile + layer->position()).toPoint(); /* Determine in which half of the tile the top-left corner of the area we * need to draw is. If we're in the upper half, we need to start one row * up due to those tiles being visible as well. How we go up one row * depends on whether we're in the left or right half of the tile. */ const bool inUpperHalf = startPos.y() - rect.y() > tileHeight / 2; const bool inLeftHalf = rect.x() - startPos.x() < tileWidth / 2; if (inUpperHalf) startTile.ry()--; if (inLeftHalf) startTile.rx()--; startTile.setX(qMax(0, startTile.x())); startTile.setY(qMax(0, startTile.y())); startPos = tileToPixelCoords(startTile + layer->position()).toPoint(); startPos.ry() += tileHeight; // Odd row shifting is applied in the rendering loop, so un-apply it here if ((startTile.y() + layer->y()) % 2) startPos.rx() -= tileWidth / 2; qDebug() << rect << startTile << startPos << layer->position(); QTransform baseTransform = painter->transform(); for (; startPos.y() < rect.bottom() && startTile.y() < layer->height(); startTile.ry()++) { QPoint rowTile = startTile; QPoint rowPos = startPos; if ((startTile.y() + layer->y()) % 2) rowPos.rx() += tileWidth / 2; for (; rowPos.x() < rect.right() && rowTile.x() < layer->width(); rowTile.rx()++) { const Cell &cell = layer->cellAt(rowTile); if (cell.isEmpty()) { rowPos.rx() += tileWidth; continue; } const QPixmap &img = cell.tile->image(); const QPoint offset = cell.tile->tileset()->tileOffset(); qreal m11 = 1; // Horizontal scaling factor qreal m12 = 0; // Vertical shearing factor qreal m21 = 0; // Horizontal shearing factor qreal m22 = 1; // Vertical scaling factor qreal dx = offset.x() + rowPos.x(); qreal dy = offset.y() + rowPos.y() - img.height(); if (cell.flippedAntiDiagonally) { // Use shearing to swap the X/Y axis m11 = 0; m12 = 1; m21 = 1; m22 = 0; // Compensate for the swap of image dimensions dy += img.height() - img.width(); } if (cell.flippedHorizontally) { m11 = -m11; m21 = -m21; dx += cell.flippedAntiDiagonally ? img.height() : img.width(); } if (cell.flippedVertically) { m12 = -m12; m22 = -m22; dy += cell.flippedAntiDiagonally ? img.width() : img.height(); } const QTransform transform(m11, m12, m21, m22, dx, dy); painter->setTransform(transform * baseTransform); painter->drawPixmap(0, 0, img); rowPos.rx() += tileWidth; } startPos.ry() += tileHeight / 2; } painter->setTransform(baseTransform); }
void TEWidget::mouseMoveEvent(QMouseEvent* ev) { // for auto-hiding the cursor, we need mouseTracking if (ev->modifiers() == Qt::NoButton ) return; if (actSel == 0) return; // don't extend selection while pasting if (ev->modifiers() & Qt::MidButton) return; //if ( !contentsRect().contains(ev->pos()) ) return; QPoint tL = contentsRect().topLeft(); int tLx = tL.x(); int tLy = tL.y(); int scroll = scrollbar->value(); // we're in the process of moving the mouse with the left button pressed // the mouse cursor will remain caught within the bounds of the text in // this widget. // Adjust position within text area bounds. See FIXME above. QPoint pos = ev->pos(); if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); // check if we produce a mouse move event by this if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); if ( pos.y() == tLy+bY+lines*font_h-1 ) { scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward } if ( pos.y() == tLy+bY ) { scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback } QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); QPoint ohere; bool swapping = FALSE; if ( word_selection_mode ) { // Extend to word boundaries int i; int selClass; bool left_not_right = ( here.y() < iPntSel.y() || here.y() == iPntSel.y() && here.x() < iPntSel.x() ); bool old_left_not_right = ( pntSel.y() < iPntSel.y() || pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); swapping = left_not_right != old_left_not_right; // Find left (left_not_right ? from here : from start) QPoint left = left_not_right ? here : iPntSel; i = loc(left.x(),left.y()); selClass = charClass(image[i].c); while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) { i--; left.rx()--; } // Find left (left_not_right ? from start : from here) QPoint right = left_not_right ? iPntSel : here; i = loc(right.x(),right.y()); selClass = charClass(image[i].c); while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) { i++; right.rx()++; } // Pick which is start (ohere) and which is extension (here) if ( left_not_right ) { here = left; ohere = right; } else { here = right; ohere = left; } } if (here == pntSel && scroll == scrollbar->value()) return; // not moved if ( word_selection_mode ) { if ( actSel < 2 || swapping ) { emit beginSelectionSignal( ohere.x(), ohere.y() ); } } else if ( actSel < 2 ) { emit beginSelectionSignal( pntSel.x(), pntSel.y() ); } actSel = 2; // within selection pntSel = here; emit extendSelectionSignal( here.x(), here.y() ); }
void CelestiaGlWidget::mouseMoveEvent(QMouseEvent* m) { int x = (int) m->x(); int y = (int) m->y(); int buttons = 0; if (m->buttons() & LeftButton) buttons |= CelestiaCore::LeftButton; if (m->buttons() & MidButton) buttons |= CelestiaCore::MiddleButton; if (m->buttons() & RightButton) buttons |= CelestiaCore::RightButton; if (m->modifiers() & ShiftModifier) buttons |= CelestiaCore::ShiftKey; if (m->modifiers() & ControlModifier) buttons |= CelestiaCore::ControlKey; #ifdef TARGET_OS_MAC // On the Mac, right dragging is be simulated with Option+left drag. // We may want to enable this on other platforms, though it's mostly only helpful // for users with single button mice. if (m->modifiers() & AltModifier) { buttons &= ~CelestiaCore::LeftButton; buttons |= CelestiaCore::RightButton; } #endif if ((m->buttons() & (LeftButton | RightButton)) != 0) { appCore->mouseMove(x - lastX, y - lastY, buttons); // Infinite mouse: allow the user to rotate and zoom continuously, i.e., // without being stopped when the pointer reaches the window borders. QPoint pt; pt.setX(lastX); pt.setY(lastY); pt = mapToGlobal(pt); // First mouse drag event. // Hide the cursor and set its position to the center of the window. if (cursorVisible) { // Hide the cursor. setCursor(QCursor(Qt::BlankCursor)); cursorVisible = false; // Save the cursor position. saveCursorPos = pt; // Compute the center point of the OpenGL Widget. QPoint center; center.setX(width() / 2); center.setY(height() / 2); // Set the cursor position to the center of the OpenGL Widget. x = center.rx() + (x - lastX); y = center.ry() + (y - lastY); lastX = (int) center.rx(); lastY = (int) center.ry(); center = mapToGlobal(center); QCursor::setPos(center); } else { if (x - lastX != 0 || y - lastY != 0) QCursor::setPos(pt); } } else { appCore->mouseMove(x, y); lastX = x; lastY = y; } }
void Field::openNeighbours(QPoint pos) { for(int y = 0; y < 3; y++) for (int x = 0; x < 3; ++x) { cells[y + pos.ry() - 1][x + pos.rx() - 1]->open(); } }
void QWidgetResizeHandler::mouseMoveEvent(QMouseEvent *e) { QPoint pos = widget->mapFromGlobal(e->globalPos()); if (!moveResizeMode && !buttonDown) { if (pos.y() <= range && pos.x() <= range) mode = TopLeft; else if (pos.y() >= widget->height()-range && pos.x() >= widget->width()-range) mode = BottomRight; else if (pos.y() >= widget->height()-range && pos.x() <= range) mode = BottomLeft; else if (pos.y() <= range && pos.x() >= widget->width()-range) mode = TopRight; else if (pos.y() <= range) mode = Top; else if (pos.y() >= widget->height()-range) mode = Bottom; else if (pos.x() <= range) mode = Left; else if ( pos.x() >= widget->width()-range) mode = Right; else if (widget->rect().contains(pos)) mode = Center; else mode = Nowhere; if (widget->isMinimized() || !isActive(Resize)) mode = Center; #ifndef QT_NO_CURSOR setMouseCursor(mode); #endif return; } if (mode == Center && !movingEnabled) return; if (widget->testAttribute(Qt::WA_WState_ConfigPending)) return; QPoint globalPos = (!widget->isWindow() && widget->parentWidget()) ? widget->parentWidget()->mapFromGlobal(e->globalPos()) : e->globalPos(); if (!widget->isWindow() && !widget->parentWidget()->rect().contains(globalPos)) { if (globalPos.x() < 0) globalPos.rx() = 0; if (globalPos.y() < 0) globalPos.ry() = 0; if (sizeprotect && globalPos.x() > widget->parentWidget()->width()) globalPos.rx() = widget->parentWidget()->width(); if (sizeprotect && globalPos.y() > widget->parentWidget()->height()) globalPos.ry() = widget->parentWidget()->height(); } QPoint p = globalPos + invertedMoveOffset; QPoint pp = globalPos - moveOffset; // Workaround for window managers which refuse to move a tool window partially offscreen. if (QGuiApplication::platformName() == QLatin1String("xcb")) { const QRect desktop = QApplication::desktop()->availableGeometry(widget); pp.rx() = qMax(pp.x(), desktop.left()); pp.ry() = qMax(pp.y(), desktop.top()); p.rx() = qMin(p.x(), desktop.right()); p.ry() = qMin(p.y(), desktop.bottom()); } QSize ms = qSmartMinSize(childWidget); int mw = ms.width(); int mh = ms.height(); if (childWidget != widget) { mw += 2 * fw; mh += 2 * fw + extrahei; } QSize maxsize(childWidget->maximumSize()); if (childWidget != widget) maxsize += QSize(2 * fw, 2 * fw + extrahei); QSize mpsize(widget->geometry().right() - pp.x() + 1, widget->geometry().bottom() - pp.y() + 1); mpsize = mpsize.expandedTo(widget->minimumSize()).expandedTo(QSize(mw, mh)) .boundedTo(maxsize); QPoint mp(widget->geometry().right() - mpsize.width() + 1, widget->geometry().bottom() - mpsize.height() + 1); QRect geom = widget->geometry(); switch (mode) { case TopLeft: geom = QRect(mp, widget->geometry().bottomRight()) ; break; case BottomRight: geom = QRect(widget->geometry().topLeft(), p) ; break; case BottomLeft: geom = QRect(QPoint(mp.x(), widget->geometry().y()), QPoint(widget->geometry().right(), p.y())) ; break; case TopRight: geom = QRect(QPoint(widget->geometry().x(), mp.y()), QPoint(p.x(), widget->geometry().bottom())) ; break; case Top: geom = QRect(QPoint(widget->geometry().left(), mp.y()), widget->geometry().bottomRight()) ; break; case Bottom: geom = QRect(widget->geometry().topLeft(), QPoint(widget->geometry().right(), p.y())) ; break; case Left: geom = QRect(QPoint(mp.x(), widget->geometry().top()), widget->geometry().bottomRight()) ; break; case Right: geom = QRect(widget->geometry().topLeft(), QPoint(p.x(), widget->geometry().bottom())) ; break; case Center: geom.moveTopLeft(pp); break; default: break; } geom = QRect(geom.topLeft(), geom.size().expandedTo(widget->minimumSize()) .expandedTo(QSize(mw, mh)) .boundedTo(maxsize)); if (geom != widget->geometry() && (widget->isWindow() || widget->parentWidget()->rect().intersects(geom))) { if (mode == Center) widget->move(geom.topLeft()); else widget->setGeometry(geom); } }
QGraphicsItem* GIFactory::createComponentGI( ComponentDescriptor* type) { qDebug() << "Generating Graphics item for" << type->text(); // collect all the information QString componentName = type->text(); QGraphicsItemGroup* parent = new QGraphicsItemGroup(); // create all the partial items and calculate sizes unsigned int inSection_minWidth = 0; unsigned int outSection_minWidth = 0; unsigned int portSection_lineHeight = 0; QList<PortEntry> inPorts = QList<PortEntry>(); QList<PortEntry> outPorts = QList<PortEntry>(); for (PortDescriptor * port : type->ports()) { PortEntry portEntry = PortEntry(port, parent); unsigned int width = portEntry.textGraphics()->boundingRect().width() + 2 * TEXT_PADDING; unsigned int height = portEntry.textGraphics()->boundingRect().height() + 2 * TEXT_PADDING; // adjust the line height, if needed if (height > portSection_lineHeight) { portSection_lineHeight = height; } switch (port->direction()) { case model::enums::PortDirection::IN : { inPorts.append(portEntry); if (width > inSection_minWidth) { inSection_minWidth = width; } } break; case model::enums::PortDirection::OUT : { outPorts.append(portEntry); if (width > outSection_minWidth) { outSection_minWidth = width; } } break; default: continue; // do not handle other types. } } std::sort(inPorts.begin(), inPorts.end()); std::sort(outPorts.begin(), outPorts.end()); unsigned int portSection_height = inPorts.count() > outPorts.count() ? inPorts.count() * portSection_lineHeight : outPorts.count() * portSection_lineHeight; QGraphicsTextItem* text_compName = new QGraphicsTextItem(componentName, parent); parent->addToGroup(text_compName); unsigned int nameSection_minWidth = text_compName->boundingRect().width() + 2 * TEXT_PADDING; unsigned int nameSection_height = text_compName->boundingRect().height() + 2 * TEXT_PADDING; // adjust the total width unsigned int totalWidth = 0; if (nameSection_minWidth > (inSection_minWidth + outSection_minWidth)) { totalWidth = nameSection_minWidth; if (inSection_minWidth > totalWidth / 2) { // extend outSection_minWidth outSection_minWidth = totalWidth - inSection_minWidth; } else if (outSection_minWidth > totalWidth / 2) { // extend inSection_minWidth inSection_minWidth = totalWidth - outSection_minWidth; } else { // stretch both to totalWidth / 2 inSection_minWidth = totalWidth / 2; outSection_minWidth = totalWidth / 2; } } else { // adjust nameSection_minWidth totalWidth = inSection_minWidth + outSection_minWidth; } // now actually place all the stuff QBrush nameSectionBrush = QBrush(Qt::lightGray, Qt::SolidPattern); QBrush portSectionBrush = QBrush(Qt::white, Qt::SolidPattern); QPen pen = QPen(Qt::black, Qt::SolidLine); QPoint currentPos = QPoint(0, 0); // draw the rectangles QGraphicsRectItem* nameSection = new QGraphicsRectItem( currentPos.x(), currentPos.y(), totalWidth, nameSection_height, parent); nameSection->setBrush(nameSectionBrush); nameSection->setPen(pen); nameSection->setZValue(-1); parent->addToGroup(nameSection); currentPos.ry() += nameSection_height; QGraphicsRectItem* inSection = new QGraphicsRectItem( currentPos.x(), currentPos.y(), inSection_minWidth, portSection_height, parent); inSection->setBrush(portSectionBrush); inSection->setPen(pen); inSection->setZValue(-1); parent->addToGroup(inSection); currentPos.rx() += inSection_minWidth; QGraphicsRectItem* outSection = new QGraphicsRectItem( currentPos.x(), currentPos.y(), outSection_minWidth, portSection_height, parent); outSection->setBrush(portSectionBrush); outSection->setPen(pen); outSection->setZValue(-1); parent->addToGroup(outSection); // place the texts and set the port positions in the port descriptor text_compName->setPos((totalWidth - text_compName->boundingRect().width()) / 2, /*0 + */ TEXT_PADDING); currentPos.setX(0); currentPos.setY(nameSection_height); for(PortEntry inIter : inPorts){ inIter.textGraphics()->setPos(currentPos.x() + TEXT_PADDING, currentPos.y() + TEXT_PADDING); currentPos.ry() += portSection_lineHeight / 2; QPoint portPos = QPoint(currentPos.x() - PORT_DIAMETER, currentPos.y()); inIter.descriptor()->setPosition(portPos); QGraphicsLineItem* lineToPort = new QGraphicsLineItem(QLineF(portPos, currentPos), parent); parent->addToGroup(lineToPort); currentPos.ry() += portSection_lineHeight / 2; } currentPos.setX(totalWidth); currentPos.setY(nameSection_height); for(PortEntry outIter : outPorts){ outIter.textGraphics()->setPos( currentPos.x() - TEXT_PADDING - outIter.textGraphics()->boundingRect().width(), currentPos.y() + TEXT_PADDING); currentPos.ry() += portSection_lineHeight / 2; QPoint portPos = QPoint(currentPos.x() + PORT_DIAMETER, currentPos.y()); outIter.descriptor()->setPosition(portPos); QGraphicsLineItem* lineToPort = new QGraphicsLineItem(QLineF(currentPos, portPos), parent); parent->addToGroup(lineToPort); currentPos.ry() += portSection_lineHeight / 2; } parent->setVisible(true); return parent; }
void QToolButtonPrivate::popupTimerDone() { Q_Q(QToolButton); popupTimer.stop(); if (!menuButtonDown && !down) return; menuButtonDown = true; QPointer<QMenu> actualMenu; bool mustDeleteActualMenu = false; if(menuAction) { actualMenu = menuAction->menu(); } else if (defaultAction && defaultAction->menu()) { actualMenu = defaultAction->menu(); } else { actualMenu = new QMenu(q); mustDeleteActualMenu = true; for(int i = 0; i < actions.size(); i++) actualMenu->addAction(actions.at(i)); } repeat = q->autoRepeat(); q->setAutoRepeat(false); bool horizontal = true; #if !defined(QT_NO_TOOLBAR) QToolBar *tb = qobject_cast<QToolBar*>(parent); if (tb && tb->orientation() == Qt::Vertical) horizontal = false; #endif QPoint p; QRect screen = QApplication::desktop()->availableGeometry(q); QSize sh = ((QToolButton*)(QMenu*)actualMenu)->receivers(SIGNAL(aboutToShow()))? QSize() : actualMenu->sizeHint(); QRect rect = q->rect(); if (horizontal) { if (q->isRightToLeft()) { if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) { p = q->mapToGlobal(rect.bottomRight()); } else { p = q->mapToGlobal(rect.topRight() - QPoint(0, sh.height())); } p.rx() -= sh.width(); } else { if (q->mapToGlobal(QPoint(0, rect.bottom())).y() + sh.height() <= screen.height()) { p = q->mapToGlobal(rect.bottomLeft()); } else { p = q->mapToGlobal(rect.topLeft() - QPoint(0, sh.height())); } } } else { if (q->isRightToLeft()) { if (q->mapToGlobal(QPoint(rect.left(), 0)).x() - sh.width() <= screen.x()) { p = q->mapToGlobal(rect.topRight()); } else { p = q->mapToGlobal(rect.topLeft()); p.rx() -= sh.width(); } } else { if (q->mapToGlobal(QPoint(rect.right(), 0)).x() + sh.width() <= screen.right()) { p = q->mapToGlobal(rect.topRight()); } else { p = q->mapToGlobal(rect.topLeft() - QPoint(sh.width(), 0)); } } } p.rx() = qMax(screen.left(), qMin(p.x(), screen.right() - sh.width())); p.ry() += 1; QPointer<QToolButton> that = q; actualMenu->setNoReplayFor(q); if (!mustDeleteActualMenu) //only if action are not in this widget QObject::connect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*))); QObject::connect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown())); actualMenu->d_func()->causedPopup.widget = q; actualMenu->d_func()->causedPopup.action = defaultAction; actionsCopy = q->actions(); //(the list of action may be modified in slots) actualMenu->exec(p); QObject::disconnect(actualMenu, SIGNAL(aboutToHide()), q, SLOT(_q_updateButtonDown())); if (mustDeleteActualMenu) delete actualMenu; else QObject::disconnect(actualMenu, SIGNAL(triggered(QAction*)), q, SLOT(_q_menuTriggered(QAction*))); if (!that) return; actionsCopy.clear(); if (repeat) q->setAutoRepeat(true); }
void SystemTopologyDrawing::paintTopology( QPainter &painter, bool optimizeScreen ) { initScale(); int dimIndex[ 3 ]; dimIndex[ 0 ] = -1; dimIndex[ 1 ] = -1; dimIndex[ 2 ] = -1; plane.setFoldingSeparator( data->getFoldingSeparators() ); //if the right mouse is pressed, then we must find the topology item that is selected; //the position of the selected item will be stored in dimIndex; //similarly, if the left mouse was pressed and released at the same position, we //will select the corresponding tree item, and thus need its id int selectedPlane = -1; if ( rightMousePressed || toSelect ) { // get selected plane index Tetragon polygon; polygon.push_back( QPointF( plane.getPoint( 0 )->getX(), plane.getPoint( 0 )->getY() ) ); polygon.push_back( QPointF( plane.getPoint( 1 )->getX(), plane.getPoint( 1 )->getY() ) ); polygon.push_back( QPointF( plane.getPoint( 2 )->getX(), plane.getPoint( 2 )->getY() ) ); polygon.push_back( QPointF( plane.getPoint( 3 )->getX(), plane.getPoint( 3 )->getY() ) ); if ( plane.isRising() ) // check from top to bottom, if user has clicked inside plane { for ( selectedPlane = 0; selectedPlane < ( int )data->getDim( ZZ ); selectedPlane++ ) { //painter.setPen(QPen(Qt::red, 7, Qt::SolidLine)); painter.drawPolygon(polygon); if ( polygon.containsPoint( lastPoint ) ) { break; } polygon.translate( 0, transform->getPlaneDistance() ); } } else // check from bottom to top { polygon.translate( 0, ( ( int )data->getDim( ZZ ) - 1 ) * transform->getPlaneDistance() ); for ( selectedPlane = data->getDim( ZZ ) - 1; selectedPlane >= 0; selectedPlane-- ) { //painter.setPen(QPen(Qt::red, 7, Qt::SolidLine)); painter.drawPolygon(polygon); if ( polygon.containsPoint( lastPoint ) ) { break; } polygon.translate( 0, -transform->getPlaneDistance() ); } } } dimIndex[ ZZ ] = selectedPlane; //if the planes are rising, then we paint the lowest plane first, //otherwise we start with the plane on the top int dummy1 = -1; int dummy2 = -1; if ( plane.isRising() ) { // since the plane is rising, we paint the lowest plane first plane.yScroll( ( double )( data->getDim( ZZ ) - 1 ) * transform->getPlaneDistance() ); //compute which items on planes are visible if the plane is partly //covered by another plane plane.computeVisibles( data, -transform->getPlaneDistance() ); //paint all planes for ( int i = data->getDim( ZZ ) - 1; i >= 0; i-- ) { bool toPaint = true; if ( optimizeScreen ) { //this is the region of this widget which is not covered by other //widgets; only planes in this widget must be painted QRect rect = visibleRegion().boundingRect(); //don't paint if whole plane is below the visible rectangle if ( ( int )plane.getPoint( 0 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 1 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 2 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 3 )->getY() > rect.y() + rect.height() ) { toPaint = false; } //also don't paint if plane is above the visible rectangle else if ( ( int )plane.getPoint( 0 )->getY() < rect.y() && ( int )plane.getPoint( 1 )->getY() < rect.y() && ( int )plane.getPoint( 2 )->getY() < rect.y() && ( int )plane.getPoint( 3 )->getY() < rect.y() ) { toPaint = false; } } // plane.paint method also calculated the index of the selected item if ( toPaint ) { plane.paint( data, i, painter, i > 0, ( i == selectedPlane && ( rightMousePressed || toSelect ) ? &lastPoint : NULL ), ( i == selectedPlane ? dimIndex[ XX ] : dummy1 ), ( i == selectedPlane ? dimIndex[ YY ] : dummy2 ) ); } //scroll the plane to represent the next plane above the //currently painted one if ( i > 0 ) { plane.yScroll( -transform->getPlaneDistance() ); } } } else { //compute which items on planes are visible if the plane is partly //covered by another plane plane.computeVisibles( data, transform->getPlaneDistance() ); //paint all planes; since the plane is not rising, we paint the //plane on the top first for ( unsigned i = 0; i < data->getDim( ZZ ); i++ ) { bool toPaint = true; if ( optimizeScreen ) { //this is the region of this widget which is not covered by other //widgets; only planes in this widget must be painted QRect rect = visibleRegion().boundingRect(); //don't paint if whole plane is below the visible rectangle if ( ( int )plane.getPoint( 0 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 1 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 2 )->getY() > rect.y() + rect.height() && ( int )plane.getPoint( 3 )->getY() > rect.y() + rect.height() ) { toPaint = false; } //also don't paint if plane is above the visible rectangle else if ( ( int )plane.getPoint( 0 )->getY() < rect.y() && ( int )plane.getPoint( 1 )->getY() < rect.y() && ( int )plane.getPoint( 2 )->getY() < rect.y() && ( int )plane.getPoint( 3 )->getY() < rect.y() ) { toPaint = false; } } if ( toPaint ) { plane.paint( data, i, painter, i < data->getDim( ZZ ) - 1, ( ( int )i == selectedPlane && ( rightMousePressed || toSelect ) ? &lastPoint : NULL ), ( ( int )i == selectedPlane ? dimIndex[ XX ] : dummy1 ), ( ( int )i == selectedPlane ? dimIndex[ YY ] : dummy2 ) ); } if ( i < data->getDim( ZZ ) - 1 ) { plane.yScroll( transform->getPlaneDistance() ); } } //scroll the plane to represent the next plane below the //currently painted one plane.yScroll( -( double )( data->getDim( ZZ ) - 1 ) * transform->getPlaneDistance() ); } QPen pen( Qt::black ); pen.setWidth( 0 ); painter.setPen( pen ); //if the left mouse button was pressed and released without moving //then we select the corresponding item if ( toSelect && dimIndex[ 0 ] != -1 && dimIndex[ 1 ] != -1 && dimIndex[ 2 ] != -1 ) { int systemId = data->getSystemId( dimIndex[ XX ], dimIndex[ YY ], dimIndex[ ZZ ] ); if ( systemId >= 0 ) { selectedSystemId = systemId; } else { selectedSystemId = -1; } } else { selectedSystemId = -1; } if ( rightMousePressed ) // show Tooltip { int x = dimIndex[ XX ]; int y = dimIndex[ YY ]; int z = dimIndex[ ZZ ]; QPoint pos = this->mapToGlobal( lastPoint ); pos.rx() += 5; pos.ry() += 5; info->showInfo( pos, data->getTooltipText( x, y, z ) ); } if ( data->hasInvalidDimensions() ) { painter.setOpacity( 0.7 ); painter.fillRect( this->rect(), Qt::gray ); } }
bool TestFramework::eventFilter(QObject* obj, QEvent* e) { if (test_running_) { // if (e == last_event_) return false; // last_event_ = e; bool stop = false; if (e->type() == QEvent::KeyPress) { QKeyEvent* ke = dynamic_cast<QKeyEvent*>(e); // pause macro if pause key is pressed if (ke->key() == Qt::Key_Pause) stop = true; else if (ke->key() == Qt::Key_X && ke->modifiers() == Qt::AltModifier) { // if a user presses Alt-X: quit immediately abortTest(); getMainControl()->quit(0); return true; } } else if (e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease) { // abort macro if user presses mouse button: if (!RTTI::isKindOf<MyMouseEvent>(*e) && e->spontaneous()) { stop = true; } } else { return false; } if (stop) { abortTest(); qApp->installEventFilter(this); return true; } return false; } // if test is paused and pause key is pressed->resume macro if (!recording_ && e->type() == QEvent::KeyPress && lines_.size() > 0) { QKeyEvent* ke = dynamic_cast<QKeyEvent*>(e); if (ke->key() == Qt::Key_Pause) { processEvent_(); timer_.reset(); timer_.start(); test_running_ = true; thread_.start(); return true; } return false; } if (!recording_) return false; if (!RTTI::isKindOf<QKeyEvent>(*e) && !RTTI::isKindOf<QMouseEvent>(*e) && !RTTI::isKindOf<QShortcutEvent>(*e)) { return false; } if (e->type() == QEvent::ShortcutOverride) return false; if (e->type() == QEvent::KeyRelease) return false; QMouseEvent* me = dynamic_cast<QMouseEvent*>(e); QKeyEvent* ke = dynamic_cast<QKeyEvent*>(e); QShortcutEvent* se = dynamic_cast<QShortcutEvent*>(e); if (ke != 0 && ke->type() == QEvent::KeyPress && ke->key() == Qt::Key_Pause) { stopTest(); return false; } /////////////////////////////////////////////////////// // uniquely identify the active widget: // walk up the QObject tree and collect all names of QWidgets /////////////////////////////////////////////////////// // take the sending object QObject* o = obj; QObject* parent = 0; x_ = y_ = 0; // for mouse events: take widget under the mouse cursor if (me != 0) { widget_ = qApp->widgetAt(me->globalPos()); if (widget_ == 0) return false; if (widget_->objectName() == "" && widget_->actions().size() == 0) { widget_ = dynamic_cast<QWidget*>(widget_->parent()); if (widget_ == 0 || widget_->objectName() == "") return false; } o = widget_; QPoint global = me->globalPos(); // if we can not get local coordinates: abort QPoint local = widget_->mapFromGlobal(global); if (local.x() < 0 || local.y() < 0 || local.x() >= widget_->width() || local.y() >= widget_->height()) { return false; } // for menus: take the position of the action under the cursor QMenu* menu = dynamic_cast<QMenu*>(o); if (menu) { QAction* action = menu->actionAt(local); if (action != 0) { o = action; parent = menu; QRect rect = menu->actionGeometry(action); local.rx() -= rect.x(); local.ry() -= rect.y(); if (rect.width() == 0 || rect.height() == 0) return false; x_ = local.x(); y_ = local.y(); } } if (x_ == 0 && y_ == 0) { // take the position as percent of the widget's actual size if (widget_->width() == 0 || widget_->height() == 0) return false; x_ = local.x(); y_ = local.y(); } } String names; while (o != 0) { String name = ascii(o->objectName()); if (name == "") { QWidget* widget = dynamic_cast<QWidget*>(o); if (widget != 0) { QList<QAction*> actions = widget->actions(); if (actions.size() == 1) { name = ascii((**actions.begin()).objectName()); } } } else { // if a parent has more childs with the same name: add a suffix with the number if (!parent) parent = o->parent(); if (parent != 0) { QList<QWidget*> childs = parent->findChildren<QWidget*>(name.c_str()); if (childs.size() > 1) { Position pos = 0; QList<QWidget*>::iterator wit = childs.begin(); for (; wit != childs.end(); wit++) { if (*wit == o) { name += "#"; name += String(pos); break; } pos++; } } } } if (name != "") names = name + "|" + names; o = o->parent(); } String event_string; event_string += String((int)e->type()) + "|"; event_string += String(getMainControl()->isBusy()) + "|"; if (me != 0) { if (me->button() == Qt::NoButton && !switch_move->isChecked() && me->type() == QEvent::MouseMove && widget_ == last_widget_) { return false; } last_widget_ = widget_; event_string += String((int)MOUSE) + "|"; event_string += String((int) me->modifiers()) + "|"; event_string += String((int) me->button()) + "|"; event_string += String((int) me->buttons()) + "|"; event_string += String(x_) + "|"; event_string += String(y_) + "|"; // prevent mouse move events with same position if (event_string == last_event_string_ && names == last_names_) { return false; } } else if (ke != 0) { // prevent accepting key events that are resend further up in the widget tree if (timer_.getClockTime() < 0.01) return false; int m = (int) ke->modifiers(); // sometimes Qt sends nonsense Key messages if (m > (int)(Qt::AltModifier | Qt::ControlModifier | Qt::ShiftModifier)) return false; event_string += String((int)KEY) + "|"; event_string += String(m); event_string += "|"; event_string += String(ke->key()) + "|"; } else if (se != 0) { event_string += String((int)SHORTCUT) + "|"; event_string += String(se->shortcutId()) + "|"; event_string += ascii(se->key().toString()) + "|"; } float time = timer_.getClockTime(); timer_.reset(); outfile_ << "I°" << time << "°" << names << "°" << event_string << std::endl; last_event_string_ = event_string; last_names_ = names; return false; }
void Q3TitleBar::mouseMoveEvent(QMouseEvent *e) { Q_D(Q3TitleBar); e->accept(); switch (d->buttonDown) { case QStyle::SC_None: if(autoRaise()) repaint(); break; case QStyle::SC_TitleBarSysMenu: break; case QStyle::SC_TitleBarShadeButton: case QStyle::SC_TitleBarUnshadeButton: case QStyle::SC_TitleBarNormalButton: case QStyle::SC_TitleBarMinButton: case QStyle::SC_TitleBarMaxButton: case QStyle::SC_TitleBarCloseButton: { QStyle::SubControl last_ctrl = d->buttonDown; QStyleOptionTitleBar opt = d->getStyleOption(); d->buttonDown = style()->hitTestComplexControl(QStyle::CC_TitleBar, &opt, e->pos(), this); if (d->buttonDown != last_ctrl) d->buttonDown = QStyle::SC_None; repaint(); d->buttonDown = last_ctrl; } break; case QStyle::SC_TitleBarLabel: if (d->buttonDown == QStyle::SC_TitleBarLabel && d->movable && d->pressed) { if ((d->moveOffset - mapToParent(e->pos())).manhattanLength() >= 4) { QPoint p = mapFromGlobal(e->globalPos()); QWidget *parent = d->window ? d->window->parentWidget() : 0; if(parent && parent->inherits("Q3WorkspaceChild")) { QWidget *workspace = parent->parentWidget(); p = workspace->mapFromGlobal(e->globalPos()); if (!workspace->rect().contains(p)) { if (p.x() < 0) p.rx() = 0; if (p.y() < 0) p.ry() = 0; if (p.x() > workspace->width()) p.rx() = workspace->width(); if (p.y() > workspace->height()) p.ry() = workspace->height(); } } QPoint pp = p - d->moveOffset; if (!parentWidget()->isMaximized()) parentWidget()->move(pp); } } else { QStyle::SubControl last_ctrl = d->buttonDown; d->buttonDown = QStyle::SC_None; if(d->buttonDown != last_ctrl) repaint(); } break; default: break; } }
void QWidgetResizeHandler::keyPressEvent(QKeyEvent * e) { if (!isMove() && !isResize()) return; bool is_control = e->modifiers() & Qt::ControlModifier; int delta = is_control?1:8; QPoint pos = QCursor::pos(); switch (e->key()) { case Qt::Key_Left: pos.rx() -= delta; if (pos.x() <= QApplication::desktop()->geometry().left()) { if (mode == TopLeft || mode == BottomLeft) { moveOffset.rx() += delta; invertedMoveOffset.rx() += delta; } else { moveOffset.rx() -= delta; invertedMoveOffset.rx() -= delta; } } if (isResize() && !resizeHorizontalDirectionFixed) { resizeHorizontalDirectionFixed = true; if (mode == BottomRight) mode = BottomLeft; else if (mode == TopRight) mode = TopLeft; #ifndef QT_NO_CURSOR setMouseCursor(mode); widget->grabMouse(widget->cursor()); #else widget->grabMouse(); #endif } break; case Qt::Key_Right: pos.rx() += delta; if (pos.x() >= QApplication::desktop()->geometry().right()) { if (mode == TopRight || mode == BottomRight) { moveOffset.rx() += delta; invertedMoveOffset.rx() += delta; } else { moveOffset.rx() -= delta; invertedMoveOffset.rx() -= delta; } } if (isResize() && !resizeHorizontalDirectionFixed) { resizeHorizontalDirectionFixed = true; if (mode == BottomLeft) mode = BottomRight; else if (mode == TopLeft) mode = TopRight; #ifndef QT_NO_CURSOR setMouseCursor(mode); widget->grabMouse(widget->cursor()); #else widget->grabMouse(); #endif } break; case Qt::Key_Up: pos.ry() -= delta; if (pos.y() <= QApplication::desktop()->geometry().top()) { if (mode == TopLeft || mode == TopRight) { moveOffset.ry() += delta; invertedMoveOffset.ry() += delta; } else { moveOffset.ry() -= delta; invertedMoveOffset.ry() -= delta; } } if (isResize() && !resizeVerticalDirectionFixed) { resizeVerticalDirectionFixed = true; if (mode == BottomLeft) mode = TopLeft; else if (mode == BottomRight) mode = TopRight; #ifndef QT_NO_CURSOR setMouseCursor(mode); widget->grabMouse(widget->cursor()); #else widget->grabMouse(); #endif } break; case Qt::Key_Down: pos.ry() += delta; if (pos.y() >= QApplication::desktop()->geometry().bottom()) { if (mode == BottomLeft || mode == BottomRight) { moveOffset.ry() += delta; invertedMoveOffset.ry() += delta; } else { moveOffset.ry() -= delta; invertedMoveOffset.ry() -= delta; } } if (isResize() && !resizeVerticalDirectionFixed) { resizeVerticalDirectionFixed = true; if (mode == TopLeft) mode = BottomLeft; else if (mode == TopRight) mode = BottomRight; #ifndef QT_NO_CURSOR setMouseCursor(mode); widget->grabMouse(widget->cursor()); #else widget->grabMouse(); #endif } break; case Qt::Key_Space: case Qt::Key_Return: case Qt::Key_Enter: case Qt::Key_Escape: moveResizeMode = false; widget->releaseMouse(); widget->releaseKeyboard(); buttonDown = false; break; default: return; } QCursor::setPos(pos); }
void DisplayTile::drawSignals(QPainter &painter) { float areaWeight[6] = {0,0,0,0,0,0}; float currentHalfTotal; QPoint arrowPoints[3]; QPoint start, end; QPen tilePen, arrowPen; QBrush arrowBrush; QVector<qreal> dashPattern; dashPattern << 2 << 5; arrowPen.setStyle(Qt::SolidLine); arrowBrush.setStyle(Qt::SolidPattern); tilePen.setWidth(this->size / 200); areaWeight[0] = area[0].size() / 2.0 + area[2].size() / 2.0; areaWeight[1] = area[5].size(); areaWeight[2] = area[1].size() / 2.0 + area[3].size() / 2.0; areaWeight[3] = area[0].size() / 2.0 + area[1].size() / 2.0; areaWeight[4] = area[4].size(); areaWeight[5] = area[2].size() / 2.0 + area[3].size() / 2.0; currentHalfTotal = areaWeight[0] + areaWeight[1] + areaWeight[2] + 1; areaWeight[0] /= currentHalfTotal; areaWeight[1] /= currentHalfTotal; areaWeight[2] /= currentHalfTotal; currentHalfTotal = areaWeight[3] + areaWeight[4] + areaWeight[5] + 1; areaWeight[3] /= currentHalfTotal; areaWeight[4] /= currentHalfTotal; areaWeight[5] /= currentHalfTotal; for(int i = 0; i < 6; i++) { if(area[i].empty()) continue; qSort(area[i]); float xInc; float yInc; switch(i) { case 0: xInc = areaWeight[0] * size / (area[i].size()); yInc = areaWeight[3] * size / (area[i].size()); start = end = QPoint(x,y); break; case 1: xInc = areaWeight[2] * size / (area[i].size()); yInc = areaWeight[3] * size / (area[i].size()); start = end = QPoint(x + size, y); xInc *= -1; break; case 2: xInc = areaWeight[0] * size / (area[i].size()); yInc = areaWeight[5] * size / (area[i].size()); start = end = QPoint(x, y + size); yInc *= -1; break; case 3: xInc = areaWeight[2] * size / (area[i].size()); yInc = areaWeight[5] * size / (area[i].size()); start = end = QPoint(x + size, y + size); xInc *= -1; yInc *= -1; break; case 4: xInc = 0; yInc = areaWeight[4] * size / (area[i].size()); start = QPoint(x, y + areaWeight[3] * size); end = start + QPoint(size, 0); break; case 5: xInc = areaWeight[1] * size / (area[i].size()); yInc = 0; start = QPoint(x + areaWeight[0] * size, y); end = start + QPoint(0, size); break; } for(QList<DisplaySignal>::iterator next = area[i].begin(); next != area[i].end(); next++) { tilePen.setColor((*next).color); arrowBrush.setColor((*next).color); arrowPen.setColor((*next).color); painter.setBrush(arrowBrush); if((*next).activation) { tilePen.setDashPattern(dashPattern); }else{ tilePen.setStyle(Qt::SolidLine); } painter.setPen(arrowPen); if(i < 4) { start.rx() += xInc; end.ry() += yInc; QPoint mid(start.x(), end.y()); if((*next).target % 2) { arrowPoints[0] = start; arrowPoints[1] = start + QPoint(3, yInc / abs(yInc) * 8); arrowPoints[2] = start + QPoint(-3, yInc / abs(yInc) * 8); painter.drawPolygon(arrowPoints, 3); }else{ arrowPoints[0] = end; arrowPoints[1] = end + QPoint(xInc / abs(xInc) * 8, 3); arrowPoints[2] = end + QPoint(xInc / abs(xInc) * 8, -3); painter.drawPolygon(arrowPoints, 3); } painter.setPen(tilePen); painter.drawLine(start, mid); painter.drawLine(mid, end); }else{ bool init = (*next).source == -1; const int rSize = 6; const int rSize2 = rSize / 2; start += QPoint(xInc, yInc); end += QPoint(xInc, yInc); QPoint realStart = start; QPoint realEnd = end; if((*next).target == 0) { if(init) { realStart.rx() += (areaWeight[0] + areaWeight[1] + areaWeight[2] / 2.0) * size; painter.drawRect(realStart.x() - rSize2, realStart.y() - rSize2, rSize, rSize); } arrowPoints[0] = end; arrowPoints[1] = end + QPoint(-8, 3); arrowPoints[2] = end + QPoint(-8, -3); }else if((*next).target == 1) { if(init) { realStart.ry() += (areaWeight[3] + areaWeight[4] + areaWeight[5] / 2.0) * size; painter.drawRect(realStart.x() - rSize2, realStart.y() - rSize2, rSize, rSize); } arrowPoints[0] = end; arrowPoints[1] = end + QPoint(3, -8); arrowPoints[2] = end + QPoint(-3, -8); }else if((*next).target == 2) { if(init) { realEnd.rx() -= (areaWeight[0] / 2.0 + areaWeight[1] + areaWeight[2]) * size; painter.drawRect(realEnd.x() - rSize2, realEnd.y() - rSize2, rSize, rSize); } arrowPoints[0] = start; arrowPoints[1] = start + QPoint(8, 3); arrowPoints[2] = start + QPoint(8, -3); }else if((*next).target == 3) { if(init) { realEnd.ry() -= (areaWeight[3] / 2.0 + areaWeight[4] + areaWeight[5]) * size; painter.drawRect(realEnd.x() - rSize2, realEnd.y() - rSize2, rSize, rSize); } arrowPoints[0] = start; arrowPoints[1] = start + QPoint(3, 8); arrowPoints[2] = start + QPoint(-3, 8); } painter.drawPolygon(arrowPoints, 3); painter.setPen(tilePen); painter.drawLine(realStart,realEnd); } } } }