void LogView::createHeader() { _headerScene->clear(); _hourScene->clear(); QSize size = headerSizeHint(); QLinearGradient grad(0, 0, 0, size.height()); int dark = 210; grad.setColorAt(1, QColor(dark, dark, dark)); grad.setColorAt(0.7, QColor(dark + 20, dark + 20, dark + 20)); grad.setColorAt(0, Qt::white); QBrush background(grad); QPen pen(QColor(220, 220, 220)); QSize sizeHint = _logScene->viewSizeHint(); _headerScene->addRect(0, 0, sizeHint.width() + verticalScrollBar()->width() + 200, size.height() + 1, pen, background)->setZValue(0); int columnSize = _logScene->dayWidth(); DateTime startDate = _logScene->startDate().addDays(-1); DateTime today; today.setHour(0); today.setMin(0); today.setSecs(0); for (int x = 0; x < _logScene->totalDays(); x++) { QPen textPen(Qt::black); QGraphicsSimpleTextItem* text = _headerScene->addSimpleText(startDate.addDays(1).toQDateTime().toString("dd-MMM"), QFont("Arial", 8)); text->setPos((x * columnSize + 2) + 50, 3); text->setVisible(true); // text->setPen(textPen); text->setZValue(1); if (startDate == today) { _todayPos = (x * columnSize + 2); } startDate = startDate.addDays(1); } _headerView.setMaximumHeight(headerSizeHint().height()); for (int x = 0; x < 24; x++) { _hourScene->addRect(0, x*BLOCKSIZE, 50, BLOCKSIZE, pen, background)->setZValue(0); std::stringstream ss; ss << x << ":00"; QGraphicsSimpleTextItem* text = _hourScene->addSimpleText(ss.str().c_str()); text->setPos(10, (x * BLOCKSIZE) + 10); text->setVisible(true); // text->setPen(textPen); text->setZValue(1); } _hourView.setScene(_hourScene); _hourView.setMaximumWidth(50); }
void GameArena::slotMapWinner(qint8 playerId, bool end) { QFont bigText; bigText.setPointSize(32); bigText.setWeight(QFont::Bold); QGraphicsSimpleTextItem* textOver = new QGraphicsSimpleTextItem(); if(playerId == -1) textOver->setText("DRAW GAME!"); else textOver->setText(QString("PLAYER ") + QString::number(playerId + 1) + QString(" WINS!")); textOver->setFont(bigText); textOver->setZValue(1.0); scene->addItem(textOver); QGraphicsSimpleTextItem* text2 = new QGraphicsSimpleTextItem(); text2->setText(textOver->text()); text2->setFont(bigText); text2->setZValue(0.9); text2->setX(text2->x() + 1); text2->setY(text2->y() + 1); text2->setBrush(QBrush(Qt::white)); scene->addItem(text2); }
void controlGraph::drawFixedPoints() { QHash<QString, fixedPoint>::iterator i; QHash<QString, bGraphicsEllipseItem*>::iterator ii; for (ii = elliseFixedPointHash.begin(); ii != elliseFixedPointHash.end(); ++ii)delete ii.value(); elliseFixedPointHash.clear(); for (i = fixedPoints->begin(); i != fixedPoints->end(); ++i) { bGraphicsEllipseItem *e = new bGraphicsEllipseItem(0); scene.addItem(e); e->setRect(1.0 * (i->panValue - rangeMinPan) * scene.width() / visibleRangePan - 15, scene.height() - 1.0 * (i->tiltValue - rangeMinPan) * scene.height() / visibleRangeTilt - 15 , 30, 30 ); e->setBrush(QBrush(QColor("#d3f9fe"))); if(i->timelapseMember == 1)e->setBrush(QBrush(QColor("#19c6ee"))); e->setZValue(1); QGraphicsSimpleTextItem *et = new QGraphicsSimpleTextItem(e); et->setPos(1.0 * (i->panValue - rangeMinTilt) * scene.width() / visibleRangePan - 20, scene.height() - 1.0 * (i->tiltValue - rangeMinTilt) * scene.height() / visibleRangeTilt - 30); et->setFont(QFont("Calibri", 14, QFont::Normal)); et->setText(i->name); et->setZValue(1); elliseFixedPointHash.insert(i.key(), e); } }
void TimeScene::drawTime(DateTime currentDay, DTime time, QModelIndex index, int groupLevel) { QSize size = sizeHint(index); int bordermargin = (size.height() * .1) / 2; QBrush b; QPen pen(QColor(0, 0, 150)); QBrush textBrush; if (groupLevel == 2) { b = QBrush(Qt::white); pen = QPen(QColor(0, 0, 150)); textBrush = QBrush(Qt::darkBlue); } if (groupLevel == 1) { b = QBrush(Qt::lightGray); pen = QPen(QColor(0, 0, 50)); textBrush = QBrush(Qt::blue); } if (groupLevel == 0) { b = QBrush(Qt::darkGray); pen = QPen(QColor(100, 100, 200)); textBrush = QBrush(Qt::white); } int daysToStart = _startDate.daysTo(currentDay); int x1 = daysToStart * _dayWidth; int y1 = _currentY + bordermargin; int x2 = x1 + _dayWidth; int y2 = _currentY + size.height() - bordermargin; // QGraphicsRectItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b); QRect rect(x1, y1, (x2 - x1), (y2 - y1)); GraphicsRectItem* item = new GraphicsRectItem(rect, index); this->addItem(item); item->setPen(pen); item->setBrush(b); item->setZValue(1); item->setAcceptHoverEvents(true); connect(item, SIGNAL(itemHoverEnter(QModelIndex)), this, SLOT(receiveItemHoverEnter(QModelIndex))); connect(item, SIGNAL(itemHoverLeave(QModelIndex)), this, SLOT(receiveItemHoverLeave(QModelIndex))); QFont font("Arial", 8); font.setBold((groupLevel <= 1)); font.setItalic((groupLevel == 0)); QGraphicsSimpleTextItem* text = addSimpleText(time.toQString(), font); text->setBrush(textBrush); text->setPos(x1 + 2, y1 + 1); text->setVisible(true); text->setZValue(1); }
void DivePlannerGraphics::pointInserted(const QModelIndex& parent, int start , int end) { DiveHandler *item = new DiveHandler (); scene()->addItem(item); handles << item; QGraphicsSimpleTextItem *gasChooseBtn = new QGraphicsSimpleTextItem(); scene()->addItem(gasChooseBtn); gasChooseBtn->setZValue(10); gasChooseBtn->setFlag(QGraphicsItem::ItemIgnoresTransformations); gases << gasChooseBtn; drawProfile(); }
void GraphViewer::onSceneMouseRelease(QGraphicsSceneMouseEvent *mouseEvent) { // need to put the connecting line on the background otherwise it is detected under the mouse _drawingEdge->setZValue(EDGE_LINE_Z); QGraphicsItem * item = _scene.itemAt(mouseEvent->scenePos(), QTransform()); if (qgraphicsitem_cast<QGraphicsEllipseItem*>(item) || qgraphicsitem_cast<QGraphicsSimpleTextItem*>(item)) { QGraphicsEllipseItem* vertex = qgraphicsitem_cast<QGraphicsEllipseItem*>(item->parentItem()); if (!vertex) vertex = qgraphicsitem_cast<QGraphicsEllipseItem*>(item); if (vertex) { double x = _drawingEdge->transform().dx(); double y = _drawingEdge->transform().dy(); _drawingEdge->setLine(0.0,0.0, vertex->scenePos().x()-x, vertex->scenePos().y()-y); _drawingEdge->setZValue(EDGE_LINE_Z); if (_drawingEdge->data(KEY_EDGE_VERTEX1) == vertex->data(KEY_EDGE_VERTEX1)) _scene.removeItem(_drawingEdge); else { int defaultWeight = 1; _drawingEdge->setData(KEY_EDGE_VERTEX2, vertex->data(KEY_VERTEX_ID)); _drawingEdge->setData(KEY_EDGE_WEIGHT, defaultWeight); // draw edge weight QGraphicsSimpleTextItem * edgeWeight = _scene.addSimpleText(QString("%1").arg(defaultWeight)); edgeWeight->setParentItem(_drawingEdge); edgeWeight->setBrush(Qt::blue); QLineF line = _drawingEdge->line(); edgeWeight->setTransform( QTransform::fromScale(0.005, 0.005) * QTransform::fromTranslate(line.x2()*0.5, line.y2()*0.5) ); edgeWeight->setZValue(EDGE_TEXT_Z); // add to graph edges _edges << _drawingEdge; } } } else { _scene.removeItem(_drawingEdge); } _isDrawingEdge=false; _drawingEdge=0; }
void Create(QGraphicsScene *scene, const GameGraphicsObjects *grobjs_, int x_, int y_, int z_order_, QString name_, int color_, int dir_, int64 amount) { grobjs = grobjs_; x = x_; y = y_; z_order = z_order_; name = name_; color = color_; dir = dir_; nLootAmount = amount; referenced = true; sprite = scene->addPixmap(grobjs->player_sprite[color][dir]); sprite->setOffset(x, y); sprite->setZValue(z_order); text = scene->addSimpleText(""); text->setZValue(1e9); UpdPos(); UpdText(); UpdColor(); }
/** Either increments or decrements a life. Checks for game over. @param choice Integer that determines whether life increments or decrements. */ void Game::life(int choice) { QString temp = ""; switch(choice) { case 0: lives--; gScene->removeItem(lAmount); temp = QString::number(lives); lAmount = new QGraphicsSimpleTextItem(temp); lAmount->setPos(70, 460); lAmount->setFont(font); lAmount->setZValue(2); gScene->addItem(lAmount); break; case 1: lives++; gScene->removeItem(lAmount); temp = QString::number(lives); lAmount = new QGraphicsSimpleTextItem(temp); lAmount->setPos(70, 460); lAmount->setFont(font); lAmount->setZValue(2); gScene->addItem(lAmount); break; } if(lives == 0) { QGraphicsSimpleTextItem *over = new QGraphicsSimpleTextItem("Game Over!"); over->setPos(100, 225); QFont *fonto = new QFont; fonto->setPixelSize(50); over->setFont(*fonto); over->setZValue(3); gScene->addItem(over); timer->stop(); overG = true; } }
void Gui::createLaserDistanceObjects() { // set colors colorHelpLine = Qt::gray; colorHelpLineText = Qt::gray; //-------------------------------------------------------------- // create the FRONT laser line distances with text //-------------------------------------------------------------- laserDistanceLineListFront = new QList <QGraphicsEllipseItem*>(); laserDistanceTextFront = new QList <QGraphicsSimpleTextItem*>(); // create and add twelve semi circles and text for (int i=0; i<LASERDISTANCECIRCLES; i++) { // create semi circles // position doesn't matter, because of moving circles in setLaserDistancePosition()! So we just take 0,0 here. QGraphicsEllipseItem *semiCircle = new QGraphicsEllipseItem(0, 0, LASERDISTANCEFIRSTCIRCLE + (i*LASERDISTANCEDISTANCE), LASERDISTANCEFIRSTCIRCLE + (i*LASERDISTANCEDISTANCE)); // create an (empty) text QGraphicsSimpleTextItem *text = new QGraphicsSimpleTextItem(); // set the start angle of the circle semiCircle->setStartAngle(180*16); // set the span angle of the circle semiCircle->setSpanAngle(180*16); // set semiCircle color semiCircle->setPen(QPen(colorHelpLine)); // set text color text->setBrush(QBrush(colorHelpLine)); // setting to the highest layer level semiCircle->setZValue(4); text->setZValue(4); // add semiCircle to QList laserDistanceLineListFront->append(semiCircle); laserDistanceTextFront->append(text); // add semiCircle to scene scene->addItem(semiCircle); // add text to scene scene->addItem(text); } //-------------------------------------------------------------- // create the REAR laser line distances with text //-------------------------------------------------------------- laserDistanceLineListRear = new QList <QGraphicsEllipseItem*>(); laserDistanceTextRear = new QList <QGraphicsSimpleTextItem*>(); // create and add twelve semi circles and text for (int i=0; i<LASERDISTANCECIRCLES; i++) { // create semi circles // position doesn't matter, because of moving circles in setLaserDistancePosition()! So we just take 0,0 here. QGraphicsEllipseItem *semiCircle = new QGraphicsEllipseItem(0, 0, LASERDISTANCEFIRSTCIRCLE + (i*LASERDISTANCEDISTANCE), LASERDISTANCEFIRSTCIRCLE + (i*LASERDISTANCEDISTANCE)); // create an (empty) text QGraphicsSimpleTextItem *text = new QGraphicsSimpleTextItem(); // set the start angle of the circle semiCircle->setStartAngle(0); // set the span angle of the circle semiCircle->setSpanAngle(180*16); // set semiCircle color semiCircle->setPen(QPen(colorHelpLine)); // set text color text->setBrush(QBrush(colorHelpLine)); // setting to the highest layer level semiCircle->setZValue(4); text->setZValue(4); // add semiCircle to QList laserDistanceLineListRear->append(semiCircle); laserDistanceTextRear->append(text); // add semiCircle to scene scene->addItem(semiCircle); // add text to scene scene->addItem(text); } }
MainWindow::MainWindow(AmViewerState *state) : _state(state) { _state->recon_tree = NULL; _state->amEvent = NULL; _state->show_dBm = false; _state->filtered = true; _state->sumpols = false; _state->resetSearch(); // couldn't hurt? setWindowTitle("AmViewer"); // creat dialogs _searchWindow = new SearchWindow(this,_state); _visWindow = new VisWindow(this,_state); _fovWindow = new FovWindow(this,_state); _filterWindow = NULL; _infoWindow = NULL; QWidget *centralWidget = new QWidget(); setCentralWidget(centralWidget); QVBoxLayout *bigLayout = new QVBoxLayout(centralWidget); // File menu QAction *quitMenu = new QAction("&Exit",this); quitMenu->setShortcut(tr("Ctrl+Q")); connect(quitMenu,SIGNAL(triggered()),qApp,SLOT(quit())); QAction *openMenu = new QAction("&Open ROOT file...",this); openMenu->setShortcut(tr("Ctrl+O")); connect(openMenu,SIGNAL(triggered()),this,SLOT(openFile())); _saveMenu = new QAction("&Save event candidates...",this); connect(_saveMenu,SIGNAL(triggered()),this,SLOT(saveFile())); QMenu *fileDrop; fileDrop = menuBar()->addMenu("&File"); fileDrop->addAction(openMenu); fileDrop->addAction(_saveMenu); fileDrop->addAction(quitMenu); _saveMenu->setEnabled(false); // View menu _unitsMenu = new QAction("&Display dBm",this); _unitsMenu->setCheckable(true); _unitsMenu->setChecked(false); connect(_unitsMenu,SIGNAL(triggered()),this,SLOT(applyUnits())); // Filter dialog _filterMenu = new QAction("&Filter Settings",this); connect(_filterMenu,SIGNAL(triggered()),this,SLOT(openFilter())); // Polarization checkbox _polMenu = new QAction("&Sum Polarizations",this); _polMenu->setCheckable(true); _polMenu->setChecked(false); _polMenu->setEnabled(false); connect(_polMenu,SIGNAL(triggered()),this,SLOT(applySumPol())); QMenu *viewDrop; viewDrop = menuBar()->addMenu("&View"); viewDrop->addAction(_unitsMenu); viewDrop->addAction(_polMenu); viewDrop->addAction(_filterMenu); _filterMenu->setEnabled(false); // Analysis menu QAction *infoMenu = new QAction("&Event Info",this); connect(infoMenu,SIGNAL(triggered()),this,SLOT(openInfo())); _analysisDrop = menuBar()->addMenu("&Analysis"); _analysisDrop->addAction(infoMenu); QAction *searchMenu = new QAction("&Search Parameters",this); connect(searchMenu,SIGNAL(triggered()),this,SLOT(openSearch())); _analysisDrop->addAction(searchMenu); _analysisDrop->setEnabled(false); QAction *visMenu = new QAction("&Event Visualization",this); connect(visMenu,SIGNAL(triggered()),this,SLOT(openVis())); _analysisDrop->addAction(visMenu); QAction*fovMenu = new QAction("&AMBER Field of View",this); connect(fovMenu,SIGNAL(triggered()),this,SLOT(openFov())); _analysisDrop->addAction(fovMenu); // Set up layout for event browser, pixel windows, graphs QHBoxLayout *hbox = new QHBoxLayout(); bigLayout->addLayout(hbox); // Event list stuff _eventList = new QTreeWidget(this); _eventList->setColumnCount(2); _eventList->setColumnHidden(1,true); //'true' valid in C++? QTreeWidgetItem *_source0 = new QTreeWidgetItem(_eventList); _source0->setText(0,"Source:0 (LTRIG)"); QTreeWidgetItem *_source1 = new QTreeWidgetItem(_eventList); _source1->setText(0,"Source:1 (PPS)"); QTreeWidgetItem *_source2 = new QTreeWidgetItem(_eventList); _source2->setText(0,"Source:2 (Auger)"); _eventList->setHeaderLabel("Events"); hbox->addWidget(_eventList); // Some gross stuff concerning the clickable horns _hornDisplay = new HornDisplay(this,1); CenterHorns *centerLegend = new CenterHorns("center",true); QGraphicsProxyWidget *centerLegendProxy = new QGraphicsProxyWidget(); centerLegendProxy->setWidget(centerLegend->widget); _hornDisplay->hornScene->addItem(centerLegendProxy); centerLegendProxy->rotate(45); centerLegendProxy->setPos(0,-50); centerLegendProxy->setZValue(0.0); AmHorn *ppsHorn[4]; int i; stringstream out; QToolButton *b; for(i=0; i<4; i++) { b = new QToolButton(); b->setFixedSize(25,25); out.str(""); out << (i+1); ppsHorn[i] = new AmHorn(b,"PPS" + out.str()); ppsHorn[i]->proxyWidget = new QGraphicsProxyWidget(); ppsHorn[i]->proxyWidget->setWidget(ppsHorn[i]->_button); _hornDisplay->hornScene->addItem(ppsHorn[i]->proxyWidget); ppsHorn[i]->proxyWidget->setPos(25*i-145,375); // probably stupid, delete //ppsHorn[i]->trigger_color = "blue"; //ppsHorn[i]->updateStyle(); //delete b; } QGraphicsSimpleTextItem *item; for(i=0; i<4; i++) { item = new QGraphicsSimpleTextItem(); _hornDisplay->hornScene->addItem(item); if(i==0) { item->setText("CH"); item->setPos(-7,-31); item->setZValue(1.0); } if(i==1) { item->setText("CV"); item->setPos(-7,5); item->setZValue(1.0); } if(i==2) { item->setText("KH"); item->setPos(-24,-15); item->setZValue(1.0); } if(i==3) { item->setText("KV"); item->setPos(12,-15); item->setZValue(1.0); } //delete item; } // CRUFT ALERT // THIS WHOLE NEXT LOOP IS HIGHLY SUSPECT, I DOUBT IT DOES ANYTHING QString qstr; for(i=0; i<16; i++) { out.str(""); out << (i+1); qstr = QString::fromStdString(out.str()); item = new QGraphicsSimpleTextItem(qstr); _hornDisplay->hornScene->addItem(item); if(i==0) item->setPos(-2.5,75.0); else if(i==1) item->setPos(-105.0,177.5); else if(i==2) item->setPos(-2.5,280.0); else if(i==3) item->setPos(102.5,177.5); else if(i==4) item->setPos(-70.0,55.0); else if(i==5) item->setPos(-95.0,80.0); else if(i==6) item->setPos(-120.0,105.0); else if(i==7) item->setPos(-125.0,250.0); else if(i==8) item->setPos(-100.0,275.5); else if(i==9) item->setPos(-75.0,300.0); else if(i==10) item->setPos(60.0,300.0); else if(i==11) item->setPos(85.0,275.0); else if(i==12) item->setPos(110.0,250.0); else if(i==13) item->setPos(120.0,110.0); else if(i==14) item->setPos(95.0,85.0); else if(i==15) item->setPos(70.0,60.0); } QVBoxLayout *evVbox = new QVBoxLayout(); hbox->addLayout(evVbox); QGridLayout *evInfoGrid = new QGridLayout(); evVbox->addLayout(evInfoGrid); _evIdLabel = new QLabel(""); _evSourceLabel = new QLabel(""); _evSecLabel = new QLabel(""); _evNsLabel = new QLabel(""); _evInfoLabel = new QLabel(""); evInfoGrid->addWidget(_evIdLabel,0,0); evInfoGrid->addWidget(_evSourceLabel,0,1); evInfoGrid->addWidget(_evSecLabel,1,0); evInfoGrid->addWidget(_evNsLabel,1,1); evInfoGrid->addWidget(_evInfoLabel,2,0); evVbox->addWidget(_hornDisplay); QVBoxLayout *pixelVbox = new QVBoxLayout(); hbox->addLayout(pixelVbox); for(i=0; i<4; i++) { pixelWindow[i] = new PixelWindow(this,i); pixelWindow[i]->setMinimumHeight(100); pixelWindow[i]->setMinimumWidth(300); pixelVbox->addWidget(pixelWindow[i]); } for(i=0; i<28; i++) { _hornDisplay->channel[i]->setHornClickFunction(this); connect(_hornDisplay->channel[i]->_button,SIGNAL(clicked()),_hornDisplay->channel[i],SLOT(hornClick())); } for(i=0; i<4; i++) { //ppsHorn[i]->setHornClickFunction(clickHornSetPixel); ppsHorn[i]->setHornClickFunction(this); connect(ppsHorn[i]->_button,SIGNAL(clicked()),ppsHorn[i],SLOT(hornClick())); } }
CalendarGraphicsItem::CalendarGraphicsItem(CalendarControl * cc, QGraphicsItem * parent) : QGraphicsRectItem(0.0, 0.0, __width, __height, parent) { _controller = cc; QDate today = QDate::currentDate(); QDate firstMonthDay = QDate(today.year(), today.month(), 1); QDate firstCalendarDay = firstMonthDay.addDays(firstMonthDay.dayOfWeek() * -1); if(firstMonthDay.dayOfWeek() < 2) firstCalendarDay = firstCalendarDay.addDays(-7); _selectedDay = today; QString prev = QObject::tr("<"); QString prevprev = QObject::tr("<<"); QString next = QObject::tr(">"); QString nextnext = QObject::tr(">>"); QGraphicsSimpleTextItem * textItem; QGraphicsRectItem * rectItem; rectItem = new QGraphicsRectItem(0.0, 0.0, __width, __titleHeight, this); rectItem->setBrush(blackFill); _items.insert("titleBackground", rectItem); textItem = new QGraphicsSimpleTextItem(today.toString("MMMM yyyy"), this); textItem->setFont(monthfont); textItem->setZValue(2); textItem->setBrush(whiteFill); QPointF ct = rectItem->boundingRect().center(); QRectF rt = textItem->boundingRect(); textItem->setPos(ct.x() - (rt.width() / 2), ct.y() - (rt.height() / 2)); _items.insert("title", textItem); qreal offset = 0.1 * __dpi; qreal nw = 0; GraphicsTextButtonItem * tbtnItem = 0; tbtnItem = new GraphicsTextButtonItem(prevprev, this); tbtnItem->setFont(navfont); tbtnItem->setZValue(3); tbtnItem->setBrush(Qt::lightGray); tbtnItem->setRolloverBrush(Qt::green); tbtnItem->scale(0.5, 1); tbtnItem->setReceiver(this); rt = tbtnItem->boundingRect(); tbtnItem->setPos(offset, ct.y() - (rt.height() / 2)); nw = rt.width(); _items.insert("fastrewind", tbtnItem); tbtnItem = new GraphicsTextButtonItem(nextnext, this); tbtnItem->setFont(navfont); tbtnItem->setZValue(3); tbtnItem->setBrush(Qt::lightGray); tbtnItem->setRolloverBrush(Qt::green); tbtnItem->scale(0.5, 1); tbtnItem->setReceiver(this); rt = tbtnItem->boundingRect(); tbtnItem->setPos(rectItem->boundingRect().right() - offset - (rt.width() / 2), ct.y() - (rt.height() / 2)); nw = qMax(nw, rt.width()) / 2; offset += (nw * 1.5); _items.insert("fastforward", tbtnItem); tbtnItem = new GraphicsTextButtonItem(prev, this); tbtnItem->setFont(navfont); tbtnItem->setZValue(3); tbtnItem->setBrush(Qt::lightGray); tbtnItem->setRolloverBrush(Qt::green); tbtnItem->scale(0.5, 1); tbtnItem->setReceiver(this); rt = tbtnItem->boundingRect(); tbtnItem->setPos(offset, ct.y() - (rt.height() / 2)); _items.insert("rewind", tbtnItem); tbtnItem = new GraphicsTextButtonItem(next, this); tbtnItem->setFont(navfont); tbtnItem->setZValue(3); tbtnItem->setBrush(Qt::lightGray); tbtnItem->setRolloverBrush(Qt::green); tbtnItem->scale(0.5, 1); tbtnItem->setReceiver(this); rt = tbtnItem->boundingRect(); tbtnItem->setPos(rectItem->boundingRect().right() - offset - (rt.width() / 2), ct.y() - (rt.height() / 2)); _items.insert("forward", tbtnItem); QDate date; qreal dayWidth = __width / 7.0; QApplication::setOverrideCursor(Qt::WaitCursor); for(int wday = 0; wday < 7; wday++) { for(int week = 0; week < 6; week++) { date = firstCalendarDay.addDays((7 * week) + wday); if(0 == week) { rectItem = new QGraphicsRectItem(wday * dayWidth, 0.5 * __dpi, dayWidth, 0.25 * __dpi, this); _items.insert(QString("weekday%1").arg(week), rectItem); textItem = new QGraphicsSimpleTextItem(date.toString("dddd"), this); textItem->setFont(wdayfont); textItem->setZValue(2); ct = rectItem->boundingRect().center(); rt = textItem->boundingRect(); textItem->setPos(ct.x() - (rt.width() / 2), ct.y() - (rt.height() / 2)); _items.insert(QString("weekday%1Text").arg(week), textItem); } QBrush fill; QBrush dayFill = blackFill; if(date == _selectedDay) fill = selectedFill; else if(date.month() != today.month()) { fill = nonMonthFill; dayFill = nonMonthDayFill; } else if(date == today) fill = todayFill; else if(date.dayOfWeek() > 5) fill = weekendFill; rectItem = new QGraphicsRectItem(wday * dayWidth, (0.75 + (1.25 * week)) * __dpi, dayWidth, 1.25 * __dpi, this); rectItem->setBrush(fill); _items.insert(QString("day%1").arg((7 * week) + wday), rectItem); rt = QRectF(rectItem->pos(), rectItem->boundingRect().size()); double offset = rt.width() / 3; textItem = new QGraphicsSimpleTextItem(QString::number(date.day()), this); textItem->setFont(dayfont); textItem->setZValue(2); textItem->setBrush(dayFill); textItem->setPos(rectItem->boundingRect().topLeft()); textItem->moveBy(5.0, 5.0); _items.insert(QString("day%1Number").arg((7 * week) + wday), textItem); rt = QRectF(textItem->pos(), textItem->boundingRect().size()); QString additionalText; if(_controller) additionalText = _controller->contents(date); textItem = new QGraphicsSimpleTextItem(additionalText, this); textItem->setFont(notesfont); textItem->setZValue(2); textItem->setBrush(dayFill); textItem->setPos(rt.left() + offset, rt.top() + (rt.height() * 1.5)); _items.insert(QString("day%1Text").arg((7 * week) + wday), textItem); } } QApplication::restoreOverrideCursor(); }
void TerrainProfileGraph::drawHoverCursor(const QPointF& position) { if (_hoverLine) { _scene->removeItem(_hoverLine); delete _hoverLine; _hoverLine = 0L; } if (_graphField.width() < 2 || _graphField.height() < 2) return; double xPos = position.x() < _graphField.x() ? _graphField.x() : (position.x() > _graphField.x() + _graphField.width() ? _graphField.x() + _graphField.width() : position.x()); QLineF vLine(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height()); QPointF* intersect = new QPointF; bool foundIntersect = false; for (int i=0; i < _graphLines.count(); i++) { if (vLine.intersect(_graphLines[i], intersect) == QLineF::BoundedIntersection) { foundIntersect = true; break; } } if (foundIntersect) { // Draw the upper line segment. Also serves as the parent item. _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, intersect->y() - 3); _hoverLine->setPen(_hoverPen); _hoverLine->setZValue(OVERLAY_Z); _scene->addItem(_hoverLine); // Draw the box around the intersect point QGraphicsRectItem* hoverBox = new QGraphicsRectItem(xPos - 3, intersect->y() - 3, 6, 6); hoverBox->setPen(_hoverPen); hoverBox->setBrush(Qt::NoBrush); hoverBox->setZValue(OVERLAY_Z); hoverBox->setParentItem(_hoverLine); // Draw the lower line segment QGraphicsLineItem* lowerLine = new QGraphicsLineItem(xPos, intersect->y() + 3, xPos, _graphField.y() + _graphField.height() + 5); lowerLine->setPen(_hoverPen); lowerLine->setZValue(OVERLAY_Z); lowerLine->setParentItem(_hoverLine); // Draw the text and background double y = (1.0 - ((intersect->y() - _graphField.y()) / _graphField.height())) * (_graphMaxY - _graphMinY) + _graphMinY; int textOffset = 10; QGraphicsSimpleTextItem* hoverText = new QGraphicsSimpleTextItem(QString::number(y) + tr("m")); hoverText->setBrush(QBrush(_axesColor)); hoverText->setFont(_graphFont); hoverText->setZValue(OVERLAY_Z); if (intersect->x() + textOffset + hoverText->boundingRect().width() < _graphField.x() + _graphField.width()) hoverText->setPos(intersect->x() + textOffset, intersect->y() - hoverText->boundingRect().height()); else hoverText->setPos(intersect->x() - textOffset - hoverText->boundingRect().width(), intersect->y() - hoverText->boundingRect().height()); QGraphicsRectItem* hoverTextBackground = new QGraphicsRectItem(hoverText->x() - 3, hoverText->y() - 1, hoverText->boundingRect().width() + 6, hoverText->boundingRect().height() + 1); hoverTextBackground->setPen(_axesPen); hoverTextBackground->setBrush(QBrush(_graphColor)); hoverTextBackground->setZValue(OVERLAY_Z); hoverTextBackground->setParentItem(_hoverLine); hoverText->setParentItem(_hoverLine); // Update callback if (_positionCallback.valid()) { double distanceFactor = ((xPos - _graphField.x()) / (double)_graphField.width()); osg::Vec3d worldStart, worldEnd; _calculator->getStart(ALTMODE_ABSOLUTE).toWorld(worldStart); _calculator->getEnd(ALTMODE_ABSOLUTE).toWorld(worldEnd); double worldX = (worldEnd.x() - worldStart.x()) * distanceFactor + worldStart.x(); double worldY = (worldEnd.y() - worldStart.y()) * distanceFactor + worldStart.y(); double worldZ = (worldEnd.z() - worldStart.z()) * distanceFactor + worldStart.z(); GeoPoint mapPos; mapPos.fromWorld(_calculator->getStart().getSRS(), osg::Vec3d(worldX, worldY, worldZ)); _positionCallback->updatePosition(mapPos.y(), mapPos.x(), hoverText->text().toStdString()); } } else { // No intersect found so just draw the full line at xPos _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height() + 5); _hoverLine->setPen(_hoverPen); _hoverLine->setZValue(OVERLAY_Z); _scene->addItem(_hoverLine); } // Draw distance text double x = ((xPos - _graphField.x()) / _graphField.width()) * _totalDistance; BoxedSimpleTextItem* distanceText = new BoxedSimpleTextItem(QString::number(x / 1000.0, 'f', 2) + tr("km"), _backgroundColor); distanceText->setBrush(QBrush(_axesColor)); distanceText->setFont(_graphFont); distanceText->setZValue(OVERLAY_Z); if(xPos - 2 - distanceText->boundingRect().width() > _graphField.x()) { distanceText->setPos(xPos - 2 - distanceText->boundingRect().width(), _graphField.y() + _graphField.height() + 2); } else { distanceText->setPos(xPos + 2, _graphField.y() + _graphField.height() + 2); } distanceText->setParentItem(_hoverLine); // Draw selection box drawSelectionBox(xPos); delete intersect; }
void TerrainProfileGraph::drawAxes(double yMin, double yMax, double yScale, double xMax, QRect &out_field) { QBrush axesBrush(_axesColor); // Create min/max text items QGraphicsSimpleTextItem* yMinText = new QGraphicsSimpleTextItem(QString::number(yMin)); yMinText->setBrush(axesBrush); yMinText->setFont(_graphFont); QGraphicsSimpleTextItem* yMaxText = new QGraphicsSimpleTextItem(QString::number(yMax)); yMaxText->setBrush(axesBrush); yMaxText->setFont(_graphFont); QGraphicsSimpleTextItem* xMaxText = new QGraphicsSimpleTextItem(QString::number(xMax)); xMaxText->setBrush(axesBrush); xMaxText->setFont(_graphFont); // Calculate positioning offsets and set out_field to actual graph bounds double fontHalfHeight = yMinText->boundingRect().height() / 2.0; int textSpacing = 8; int xOffset = (int)osg::maximum(yMinText->boundingRect().width(), yMaxText->boundingRect().width()) + textSpacing; int yOffset = (int)xMaxText->boundingRect().height() + textSpacing; int xAxisY = _graphHeight - yOffset; out_field.setCoords(xOffset, (int)fontHalfHeight, _graphWidth, xAxisY); // Draw background rectangle _scene->addRect(out_field, QPen(Qt::NoPen), QBrush(_fieldColor))->setZValue(FIELD_Z); // Add min/max text items to the scene yMinText->setPos(xOffset - textSpacing - yMinText->boundingRect().width(), xAxisY - fontHalfHeight); yMinText->setZValue(AXES_Z); _scene->addItem(yMinText); yMaxText->setPos(xOffset - textSpacing - yMaxText->boundingRect().width(), 0); yMaxText->setZValue(AXES_Z); _scene->addItem(yMaxText); xMaxText->setPos(_graphWidth - xMaxText->boundingRect().width(), _graphHeight - xMaxText->boundingRect().height()); xMaxText->setZValue(AXES_Z); _scene->addItem(xMaxText); // Draw the main axes and x-axis end cap _scene->addLine(xOffset, fontHalfHeight, xOffset, xAxisY + 5, _axesPen)->setZValue(AXES_Z); _scene->addLine(xOffset - 5, xAxisY, _graphWidth, xAxisY, _axesPen)->setZValue(AXES_Z); _scene->addLine(_graphWidth, xAxisY - 5, _graphWidth, xAxisY + 5, _axesPen)->setZValue(AXES_Z); // Draw horizontal graph lines double yGraphScale = (yScale / (yMax - yMin)) * out_field.height(); double graphLineY = xAxisY - yGraphScale; for (double y = yMin + yScale; y <= yMax; y += yScale) { _scene->addLine(xOffset - 5, graphLineY, _graphWidth, graphLineY, _axesPen)->setZValue(AXES_Z);; if (y != yMax) { QGraphicsSimpleTextItem* yText = new QGraphicsSimpleTextItem(QString::number(y)); yText->setBrush(axesBrush); yText->setFont(_graphFont); yText->setPos(xOffset - textSpacing - yText->boundingRect().width(), graphLineY - fontHalfHeight); yText->setZValue(AXES_Z); _scene->addItem(yText); } graphLineY -= yGraphScale; } }
void LogScene::getTaskItem(const QModelIndex &index) { Task* task = _model->task(index); Calendar* calendar = task->project()->projectDefaultCalendar(); int hoursInDay = calendar->endHour().hour() - calendar->startHour().hour(); std::vector<TaskLog*>* logs =task->logs(); double startHour = 0;//calendar->startHour().hour(); double endHour = 24;//calendar->endHour().hour() + 1; double minuteSize = (double)24*BLOCKSIZE / (double)((endHour - startHour) * 60); int red = 0; for (std::vector<TaskLog*>::iterator iter = logs->begin(); iter != logs->end(); iter++) { TaskLog* log = *iter; QSize size = sizeHint(index); int bordermargin = (size.height() * .4) / 2; int daysToStart = _startDate.daysTo(*log->start); double x1 = (double)daysToStart * (double)_dayWidth; DTime logStartTime = log->start->time(); double y1 = (double)(logStartTime.totalMinutes() - (startHour*60)) * minuteSize; double x2 = (daysToStart + 1) * (double)_dayWidth; DTime logEndTime = log->end->time(); if (log->end->getDay() != log->start->getDay()) { logEndTime = DTime(23, 59, 59); } double y2 = (double)(logEndTime.totalMinutes() - (startHour*60)) * minuteSize; QBrush b(task->taskColor());//QImage(":/img/task_bar.png"));//(QPixmap(":/img/task_bar.png")); red += 20; QColor penColor((task->taskColor().red() < 100) ? 0: (task->taskColor().red() - 100), (task->taskColor().green() < 100) ? 0: (task->taskColor().green() - 100), (task->taskColor().blue() < 100) ? 0: (task->taskColor().blue() - 100)); QPen pen(penColor); if (log->activeLog) { pen.setWidth(3); } QGraphicsItem* item = this->addRect(x1, y1, (x2 - x1), (y2 - y1), pen, b); item->setZValue(1); if ((y2 - y1) > 20) { QFont f("Arial", 8); f.setWeight(QFont::Light); QBrush brush(penColor); std::string description = *task->shortDescription(); int textY = y1 + 5; while (description.length() > 0) { std::string label; if (description.length() > 15) { label = description.substr(0, 15); description = description.substr(15); if ((label.at(label.length() - 1) != ' ') && (description.at(0) != ' ')) { int pos; if ((pos = label.rfind(' ')) != std::string::npos) { description = label.substr(pos) + description; label = label.substr(0, pos); } } } else { label = description; description = ""; } label = label.erase(label.find_last_not_of(" \n\r\t")+1); description = description.erase(description.find_last_not_of(" \n\r\t")+1); if ((textY + 20) < y2) { QGraphicsSimpleTextItem* text = this->addSimpleText(tr(label.c_str())); text->setPos(x1 + 10, textY); //text->rotate(90); text->setVisible(true); text->setBrush(brush); text->setFont(f); text->setZValue(2); textY += 15; } else { break; } } } _currentY += sizeHint(index).height(); } delete(logs); }
void GraphViewer::onSceneMousePress(QGraphicsSceneMouseEvent *mouseEvent) { if (_vertices.isEmpty()) _initialText->setVisible(false); if (_scene.items(QRectF( mouseEvent->scenePos().x() - VERTEX_SIZE*0.5, mouseEvent->scenePos().y() - VERTEX_SIZE*0.5, VERTEX_SIZE, VERTEX_SIZE) ).isEmpty()) { // Create new vertex QGraphicsEllipseItem * vertex = _scene.addEllipse( QRectF(-VERTEX_SIZE*0.5, -VERTEX_SIZE*0.5, VERTEX_SIZE, VERTEX_SIZE), QPen(Qt::black, 0), QBrush(Qt::white) ); vertex->setTransform( QTransform::fromTranslate(mouseEvent->scenePos().x(), mouseEvent->scenePos().y()) ); vertex->setZValue(VERTEX_CIRCLE_Z); _vertices << vertex; int id = _vertices.size()-1; vertex->setData(KEY_VERTEX_ID, id); QGraphicsSimpleTextItem * vertexId = _scene.addSimpleText(QString("%1").arg(id+1)); vertexId->setParentItem(vertex); vertexId->setTransform( QTransform::fromScale(0.005, 0.005) * QTransform::fromTranslate(-VERTEX_SIZE*( (id < 9) ? 0.18 : 0.28 ), -VERTEX_SIZE*0.35) ); vertexId->setZValue(VERTEX_TEXT_Z); } else { // Propose to draw new edge QGraphicsItem * item = _scene.itemAt(mouseEvent->scenePos(), QTransform()); if (qgraphicsitem_cast<QGraphicsEllipseItem*>(item) || qgraphicsitem_cast<QGraphicsSimpleTextItem*>(item)) { QGraphicsEllipseItem* vertex = qgraphicsitem_cast<QGraphicsEllipseItem*>(item->parentItem()); if (!vertex) vertex = qgraphicsitem_cast<QGraphicsEllipseItem*>(item); if (vertex) { _isDrawingEdge=true; _drawingEdge = _scene.addLine(0.0, 0.0, mouseEvent->scenePos().x()-vertex->scenePos().x(), mouseEvent->scenePos().y()-vertex->scenePos().y(), QPen(Qt::black, 0)); _drawingEdge->setTransform(QTransform::fromTranslate(vertex->scenePos().x(), vertex->scenePos().y())); _drawingEdge->setZValue(VERTEX_CIRCLE_Z); _drawingEdge->setData(KEY_EDGE_VERTEX1, vertex->data(KEY_VERTEX_ID)); } } } }