void draw_graph(QGraphicsView& v, int px, int py, int x, int y, int& max_y, const QPen& pen) { REQUIRE(v.scene()); if(y > max_y) max_y = y; auto s = v.scene(); s->addLine(px, -py, x, -y, pen); v.fitInView(x-GRAPH_WIDTH,-int(max_y),GRAPH_WIDTH, max_y+2); }
void QSWindow::closeFile(){ QGraphicsView *view = ui->tabWidget->currentWidget()->findChild <QGraphicsView *>(QString(),Qt::FindDirectChildrenOnly); //current view if(view->scene() == 0){ ui->statusBar->showMessage("no current file to delete!"); //// return; //// } //// QSScene* qs = (QSScene*)view->scene();//current scene //// delete qs; //// qDebug()<<"after delete:"<<view->children().size();//index starts from 4 (3 default children) //// if(view->findChild<QSScene*>(QString(),Qt::FindDirectChildrenOnly) != 0)//auto switch to another file if possible //// emit ((QSScene*)view->findChild<QSScene*>(QString(),Qt::FindDirectChildrenOnly))->Opened()->triggered(); //// }
void MainWindow::closeEvent(QCloseEvent *e){ saveSettings(); bool clean = true; for(int i = 0; i < ui->tabWidget->count(); i++){ QGraphicsView* view = qobject_cast<QGraphicsView*>(ui->tabWidget->widget(i)); Q_ASSERT(view); if(view){ PetriNetScene* scene = qobject_cast<PetriNetScene*>(view->scene()); Q_ASSERT(scene); if(scene) clean &= scene->undoStack()->isClean(); } } if(!clean){ QMessageBox::StandardButtons retval; retval = QMessageBox::question(this, tr("You have unsaved changed"), tr("Do you wish to discard unsaved changes?"), QMessageBox::Cancel | QMessageBox::Discard, QMessageBox::Cancel); if(retval == QMessageBox::Cancel){ e->ignore(); return; } } // Accept if state was clean or changes were discarded e->accept(); }
Dashboard::Dashboard(QWidget *parent) : QMainWindow(parent) , d_ptr(new DashboardPrivate(this)) { setWindowTitle("Maliit Keyboard Viewer"); resize(854, 480); QGraphicsView *v = new QGraphicsView; v->setScene(new QGraphicsScene(v)); v->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); v->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setCentralWidget(v); v->show(); QWidget *w = 0; d_ptr->proxy_widget = v->scene()->addWidget(w = new QWidget); d_ptr->proxy_widget->setTransformOriginPoint(d_ptr->proxy_widget->geometry().center()); w->resize(size()); QVBoxLayout *vbox = d_ptr->vbox; w->setLayout(vbox); QSpacerItem *top_spacer = d_ptr->top; vbox->addItem(top_spacer); QWidget *buttons = d_ptr->buttons; buttons->show(); vbox->addWidget(buttons); QHBoxLayout *hbox = new QHBoxLayout; buttons->setLayout(hbox); QPushButton *show = new QPushButton("Show virtual keyboard"); connect(show, SIGNAL(clicked()), this, SLOT(onShow())); hbox->addWidget(show); show->show(); QPushButton *orientation_changed = new QPushButton("Change orientation"); connect(orientation_changed, SIGNAL(clicked()), this, SLOT(onOrientationChangeClicked())); hbox->addWidget(orientation_changed); orientation_changed->show(); QPushButton *close = new QPushButton("Close application"); connect(close, SIGNAL(clicked()), qApp, SLOT(quit())); hbox->addWidget(close); close->show(); QTextEdit *te = d_ptr->text_entry; vbox->addWidget(te); te->show(); te->setFocus(); QSpacerItem *bottom_spacer = d_ptr->bottom; vbox->addItem(bottom_spacer); onShow(); }
void MiniViewContainer::setView(QGraphicsView * view) { QGraphicsView * oldView = m_miniView->view(); if (oldView == view) return; if (oldView != NULL) { disconnect(oldView->horizontalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateFrame())); disconnect(oldView->verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(updateFrame())); disconnect(oldView->scene(), SIGNAL(sceneRectChanged(QRectF)), this, SLOT(updateFrame())); disconnect(oldView, SIGNAL(resizeSignal()), this, SLOT(updateFrame())); disconnect(m_frame, SIGNAL(scrollChangeSignal(double, double)), oldView, SLOT(navigatorScrollChange(double, double))); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QGraphicsView w; assert(!w.scene()); w.setScene(new QGraphicsScene); assert(w.scene()); { TrianglePolygonItem * const item = new TrianglePolygonItem; item->setPos(-150.0,-150.0); w.scene()->addItem(item); } { TrianglePolygonItem * const item = new TrianglePolygonItem; item->setBrush(QBrush(QColor(0,0,0))); item->setPos(150.0,-150.0); w.scene()->addItem(item); } { TriangleGraphicsItem * const item = new TriangleGraphicsItem; item->setPos(-150.0, 150.0); w.scene()->addItem(item); } { TriangleGraphicsItem * const item = new TriangleGraphicsItem; item->SetMyBrush(QBrush(QColor(0,0,0))); item->setPos(150.0, 150.0); w.scene()->addItem(item); } w.show(); return a.exec(); }
/*------------------------------------------------------------------------------ | main +-----------------------------------------------------------------------------*/ int main(int argc, char** argv) { qputenv("QT_QPA_EGLFS_FORCE888", "1"); QApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true); QApplication a(argc, argv); const QStringList args = a.arguments(); if (args.size() < 2) { log_err("Video ID is missing."); return 1; } const QString videoId = args.at(1); log_info("Starting playback of video ID %s...", qPrintable(videoId)); POC_Bridge bridge(videoId); QGraphicsWebView* webItem = new QGraphicsWebView; webItem->page()->mainFrame()->addToJavaScriptWindowObject("bridge", &bridge); QOpenGLWidget* glViewport = new QOpenGLWidget; QGraphicsView* view = new QGraphicsView; view->setFrameShape(QFrame::NoFrame); view->setRenderHints(QPainter::Antialiasing); view->setScene(new QGraphicsScene); view->setViewport(glViewport); view->showFullScreen(); view->scene()->setBackgroundBrush(QBrush(Qt::red)); view->scene()->setSceneRect(QRectF(0, 0, 1920, 1080)); view->scene()->addItem(webItem); webItem->setUrl(QUrl("qrc:/player.html")); webItem->setMinimumSize(1920, 1080); return a.exec(); }
bool TabChild::RecvCreateWidget(const MagicWindowHandle& parentWidget) { nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebNav); if (!baseWindow) { NS_ERROR("mWebNav doesn't QI to nsIBaseWindow"); return true; } #ifdef MOZ_WIDGET_GTK2 GtkWidget* win = gtk_window_new(GTK_WINDOW_TOPLEVEL); #elif defined(MOZ_WIDGET_QT) QGraphicsView *view = new QGraphicsView(new QGraphicsScene()); NS_ENSURE_TRUE(view, false); QGraphicsWidget *win = new QGraphicsWidget(); NS_ENSURE_TRUE(win, false); view->scene()->addItem(win); #elif defined(XP_WIN) HWND win = parentWidget; #elif defined(ANDROID) // Fake pointer to make baseWindow->InitWindow work // The android widget code is mostly disabled in the child process // so it won't choke on this void *win = (void *)0x1234; #elif defined(XP_MACOSX) # warning IMPLEMENT ME #else #error You lose! #endif #if !defined(XP_MACOSX) baseWindow->InitWindow(win, 0, 0, 0, 0, 0); baseWindow->Create(); baseWindow->SetVisibility(PR_TRUE); #endif // IPC uses a WebBrowser object for which DNS prefetching is turned off // by default. But here we really want it, so enable it explicitly nsCOMPtr<nsIWebBrowserSetup> webBrowserSetup = do_QueryInterface(baseWindow); if (webBrowserSetup) { webBrowserSetup->SetProperty(nsIWebBrowserSetup::SETUP_ALLOW_DNS_PREFETCH, PR_TRUE); } else { NS_WARNING("baseWindow doesn't QI to nsIWebBrowserSetup, skipping " "DNS prefetching enable step."); } return InitTabChildGlobal(); }
MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { // create a scene with items, // use the view to show the scene QGraphicsScene *scene = new QGraphicsScene(); QGraphicsView *gv = new QGraphicsView(this); gv->setScene(scene); if (gv->scene()) { printf("renc: scene is not null.\n"); // these two lines are at scene origin pos. scene->addLine(0, 0, 100, 0, QPen(Qt::red)); scene->addLine(0, 0, 0, 100, QPen(Qt::green)); /*QGraphicsRectItem *rect = */ scene->addRect(QRectF(0,0,50,50), QPen(Qt::red), QBrush(Qt::green)); // svg image QGraphicsSvgItem *svgItem = new QGraphicsSvgItem(svgFile2); scene->addItem((svgItem)); svgItem->setPos(400, 0); bool rValid1 = svgItem->renderer()->isValid(); printf("--%d--\n", rValid1); // QWidget to scene QPushButton *btn = new QPushButton("button 1");// at (0,0) by default. QGraphicsProxyWidget *btnWidget = scene->addWidget(btn); btnWidget->setPos(0, 400); // { SvgPushButton *btn2 = new SvgPushButton(svgFile1); QGraphicsProxyWidget *btnWidget2 = scene->addWidget(btn2); btnWidget2->setPos(400, 400); } } else printf("renc: scene is null.\n"); //setCentralWidget(gv); setWindowTitle("Demo: graphics view");//QMainWindow setStyleSheet("background-color: rgb(100,120,50);"); }
/** Close document-tab */ void MainWindow::on_tabWidget_tabCloseRequested(int index){ QGraphicsView* view = qobject_cast<QGraphicsView*>(ui->tabWidget->widget(index)); if(view){ PetriNetScene* scene = qobject_cast<PetriNetScene*>(view->scene()); Q_ASSERT(scene != NULL); if(!scene->undoStack()->isClean()){ QMessageBox::StandardButtons retval; retval = QMessageBox::question(this, tr("You have unsaved changed"), tr("Do you wish to discard unsaved changes?"), QMessageBox::Cancel | QMessageBox::Discard, QMessageBox::Cancel); if(retval == QMessageBox::Cancel) return; } ui->tabWidget->removeTab(index); view->deleteLater(); } }
void TimeGraphContainer::redraw() { //redraw it all: QGraphicsView * v; GraphScene * gs; for (int i=0;i<list.size();i++) { v=list.at(i); gs=(GraphScene *)v->scene(); gs->updateArea(); //v->fitInView ( 0,-10,3,20); v->fitInView ( (double)time_widget->getTimeControl()->getVisibleRange()->getMin() , (double)gs->sceneRect().y(), (double)time_widget->getTimeControl()->getVisibleRange()->getLength(), (double)gs->sceneRect().height(), //20, Qt::IgnoreAspectRatio ); qDebug("fit %f, %f, %f, %f\n",(double)time_widget->getTimeControl()->getVisibleRange()->getMin() , (double)gs->sceneRect().y(), (double)time_widget->getTimeControl()->getVisibleRange()->getLength(), (double)gs->sceneRect().height()); } }
void showAnCalChrRes::updColSenHoriz(){ //Accumulate values in each color //.. QGraphicsView *tmpCanvas = ui->canvasCroped; tmpCanvas->scene()->clear(); QImage tmpImg( "./tmpImages/tmpCropped.ppm" ); int Red[tmpImg.width()];memset(Red,'\0',tmpImg.width()); int Green[tmpImg.width()];memset(Green,'\0',tmpImg.width()); int Blue[tmpImg.width()];memset(Blue,'\0',tmpImg.width()); int r, c, maxR, maxG, maxB, xR, xG, xB; maxR = 0; maxG = 0; maxB = 0; xR = 0; xG = 0; xB = 0; QRgb pixel; for(c=0;c<tmpImg.width();c++){ Red[c] = 0; Green[c] = 0; Blue[c] = 0; for(r=0;r<tmpImg.height();r++){ if(!tmpImg.valid(QPoint(c,r))){ qDebug() << "Invalid r: " << r << "c: "<<c; qDebug() << "tmpImg.width(): " << tmpImg.width(); qDebug() << "tmpImg.height(): " << tmpImg.height(); return (void)NULL; close(); } pixel = tmpImg.pixel(QPoint(c,r)); Red[c] += qRed(pixel); Green[c] += qGreen(pixel); Blue[c] += qBlue(pixel); } Red[c] = round((float)Red[c]/tmpImg.height()); Green[c] = round((float)Green[c]/tmpImg.height()); Blue[c] = round((float)Blue[c]/tmpImg.height()); if( Red[c] > maxR ){ maxR = Red[c]; xR = c; } if( Green[c] > maxG ){ maxG = Green[c]; xG = c; } if( Blue[c] > maxB ){ maxB = Blue[c]; xB = c; } //qDebug() << "xR: " << xR << "xG: " << xG << "xB: " << xB; } int maxRGB = (maxR>maxG)?maxR:maxG; maxRGB = (maxB>maxRGB)?maxB:maxRGB; float upLimit = (float)tmpImg.height() * 0.7; //qDebug() << "c" << c << "maxR:"<<maxR<<" maxG:"<<maxG<<" maxB:"<<maxB; //qDebug() << "c" << c << "xR:"<<xR<<" xG:"<<xG<<" xB:"<<xB; //qDebug() << "tmpImg.width(): " << tmpImg.width(); //qDebug() << "tmpImg.height(): " << tmpImg.height(); //Draw camera's sensitivities //.. int tmpPoint1, tmpPoint2, tmpHeight; tmpHeight = tmpImg.height(); for(c=1;c<tmpImg.width();c++){ if( ui->chbRed->isChecked() ){ tmpPoint1 = ((float)Red[c-1]/((float)maxRGB)) * upLimit; tmpPoint2 = ((float)Red[c]/((float)maxRGB)) * upLimit; tmpPoint1 = tmpHeight - tmpPoint1; tmpPoint2 = tmpHeight - tmpPoint2; tmpCanvas->scene()->addLine( c, tmpPoint1, c+1, tmpPoint2, QPen(QColor("#FF0000")) ); } if( ui->chbGreen->isChecked() ){ tmpPoint1 = ((float)Green[c-1]/((float)maxRGB)) * upLimit; tmpPoint2 = ((float)Green[c]/((float)maxRGB)) * upLimit; tmpPoint1 = tmpHeight - tmpPoint1; tmpPoint2 = tmpHeight - tmpPoint2; tmpCanvas->scene()->addLine( c, tmpPoint1, c+1, tmpPoint2, QPen(QColor("#00FF00")) ); } if( ui->chbBlue->isChecked() ){ tmpPoint1 = ((float)Blue[c-1]/((float)maxRGB)) * upLimit; tmpPoint2 = ((float)Blue[c]/((float)maxRGB)) * upLimit; tmpPoint1 = tmpHeight - tmpPoint1; tmpPoint2 = tmpHeight - tmpPoint2; tmpCanvas->scene()->addLine( c, tmpPoint1, c+1, tmpPoint2, QPen(QColor("#0000FF")) ); } } //Draw RGB peaks //.. addLine2CanvasInPos(true,xR,Qt::red); globalRedLine = globalTmpLine; addLine2CanvasInPos(true,xG,Qt::green); globalGreenLine = globalTmpLine; addLine2CanvasInPos(true,xB,Qt::blue); globalBlueLine = globalTmpLine; globalRedLine->parameters.orientation = _VERTICAL; globalGreenLine->parameters.orientation = _VERTICAL; globalBlueLine->parameters.orientation = _VERTICAL; /* QPoint p1,p2; p1.setX(0); p1.setY(0); p2.setX(0); p2.setY(tmpImg.height()); customLine *redPeak = new customLine(p1,p2,QPen(Qt::red)); customLine *greenPeak = new customLine(p1,p2,QPen(Qt::green)); customLine *bluePeak = new customLine(p1,p2,QPen(Qt::blue)); redPeak->setX(xR); greenPeak->setX(xG); bluePeak->setX(xB); if(ui->chbRedLine->isChecked()){ tmpCanvas->scene()->addItem(redPeak); } if(ui->chbGreenLine->isChecked()){ tmpCanvas->scene()->addItem(greenPeak); } if(ui->chbBlueLine->isChecked()){ tmpCanvas->scene()->addItem(bluePeak); } globalRedLine = redPeak; globalGreenLine = greenPeak; globalBlueLine = bluePeak; */ }
// FIXME: better to qupdate(scene()) and then repaint the viewport widget? SEXP qt_qupdate_QGraphicsView(SEXP rself) { QGraphicsView *view = unwrapQObject(rself, QGraphicsView); view->scene()->update(); view->viewport()->repaint(); return rself; }
void init_scene(QGraphicsView& v) { auto s = new QGraphicsScene; v.setScene(s); ENSURE(v.scene()); }
void MInputContext::setFocusWidget(QWidget *focused) { QObject *focusedObject = focused; QGraphicsItem *focusItem = 0; qDebug() << "MInputContext" << "in" << __PRETTY_FUNCTION__ << focused; QInputContext::setFocusWidget(focused); // get detailed focus information from inside qgraphicsview QGraphicsView *graphicsView = qobject_cast<QGraphicsView *>(focusWidget()); if (graphicsView && graphicsView->scene()) { focusItem = graphicsView->scene()->focusItem(); if (focusItem) { focusedObject = dynamic_cast<QObject *>(focusItem); } } const QMap<QString, QVariant> stateInformation = getStateInformation(); if (focused) { // for non-null focus widgets, we'll have this context activated if (!active) { imServer->activateContext(); active = true; #ifdef HAVE_MEEGOTOUCH // Notify whatever application's orientation is currently. notifyOrientationChanged(currOrientation); #endif } imServer->updateWidgetInformation(stateInformation, true); // check if copyable text is selected Qt::InputMethodQuery query = Qt::ImCurrentSelection; QVariant queryResult = focused->inputMethodQuery(query); if (queryResult.isValid()) { copyAvailable = !queryResult.toString().isEmpty(); } if (focusItem) { copyAllowed = !(focusItem->inputMethodHints() & Qt::ImhHiddenText); } else { copyAllowed = !(focused->inputMethodHints() & Qt::ImhHiddenText); } pasteAvailable = !QApplication::clipboard()->text().isEmpty(); connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(handleClipboardDataChange()), Qt::UniqueConnection); } else { copyAvailable = false; copyAllowed = false; imServer->updateWidgetInformation(stateInformation, true); disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, 0); } // show or hide Copy/Paste button on input method server notifyCopyPasteState(); if (inputPanelState == InputPanelShowPending && focused) { imServer->showInputMethod(); inputPanelState = InputPanelShown; } if (connectedObject) { connectedObject->disconnect(this); connectedObject = 0; } if (focusedObject && focusedObject->metaObject()) { if (focusedObject->metaObject()->indexOfSignal("copyAvailable(bool)") != -1) { // for MTextEdit connect(focusedObject, SIGNAL(copyAvailable(bool)), this, SLOT(handleCopyAvailabilityChange(bool))); connectedObject = focusedObject; } else if (focusedObject->metaObject()->indexOfSignal("selectedTextChanged()") != -1) {