void ColorsIcon::mousePressEvent(QGraphicsSceneMouseEvent* e) { // Get first cell float divider = boundingRect().width() * 0.5; // Match mouse if(e->pos().x() < divider) { pickColor(QPalette::Foreground); } else { pickColor(QPalette::Background); } }
ColorPickerItem::ColorPickerItem(QObject* parent) : QObject(parent) { connect(this, SIGNAL(pickColor()), &m_selector, SLOT(startSelection())); connect(&m_selector, SIGNAL(colorPicked(QColor)), SIGNAL(colorPicked(QColor))); connect(&m_selector, SIGNAL(cancelled()), SIGNAL(cancelled())); }
//-------------------------------------------------------------- void ofApp::setColorsToSend(){ /* * three different examples/demoModes that set/generate a color * the colorPicker is actually quite usefull! */ switch (demoMode) { case 0: //use the colorPicker pickColor(mouseX, mouseY); break; case 1: //static green! red = 255; green = 255; blue = 0; break; case 2: //something a bit more dynamic frames = ++frames % 360; //static const float DegRadFactor = PI / 180.0f; float radR = ofDegToRad(frames); float radG = ofDegToRad(frames + 120); float radB = ofDegToRad(frames + 240); float intensity = 255; red = ( cosf( radR ) + 1.0f ) * intensity / 2; green = ( sinf( radG ) + 1.0f ) * intensity / 2; blue = ( sinf( radB ) + 1.0f ) * intensity / 2; break; } }
void MainWindow2::makeColorWheelConnections() { ColorBox* pColorBox = static_cast<ColorBox*>(m_pColorWheelWidget->widget()); Q_ASSERT( pColorBox ); connect( pColorBox, SIGNAL(colorChanged(QColor)), editor->colorManager(), SLOT(pickColor(QColor))); connect( editor->colorManager(), SIGNAL(colorChanged(QColor)), pColorBox, SLOT(setColor(QColor))); }
Dart Topo3PrimalRender<PFP>::picking(MAP& map, int x, int y) { pushColors(); setDartsIdColor(map); Dart d = pickColor(x,y); popColors(); return d; }
ColorButton::ColorButton(QWidget* parent, bool allowAlpha) : QPushButton(parent), _alpha(allowAlpha) { // Pick color on click (use queued connection so that any on_*_clicked() events can be processed first) connect(this, SIGNAL(clicked()), this, SLOT(pickColor()), Qt::QueuedConnection); setAutoDefault(false); setDefault(false); updateImage(); }
void ColorWheel::mousePressEvent(QMouseEvent *event) { QPoint lastPos = event->pos(); if (m_squareRegion.contains(lastPos)) { m_isInWheel = false; m_isInSquare = true; QColor color = pickColor(lastPos); svChanged(color); } else if (m_wheelRegion.contains(lastPos)) { m_isInWheel = true; m_isInSquare = false; QColor color = pickColor(lastPos); hueChanged(color.hue()); } }
//returns 1 if this is a new cursor; 0 otherwise int moveRemoteCursor(char *msg) { char *ip = (char*)malloc(sizeof(char)*20); char *tempstring = (char*)malloc(sizeof(char)*20); char *posstring = (char*)malloc(sizeof(char)*10); char *anchorstring = (char*)malloc(sizeof(char)*10); int size=strlen(msg); int pos; int anchor; int ipsize = strchr(msg,'|') - msg; strncpy(ip,msg,ipsize); ip[ipsize]='\0'; strcpy(tempstring,msg+ipsize+1); int possize = strchr(tempstring,'|') - tempstring; strncpy(posstring,tempstring,possize); posstring[possize]='\0'; strcpy(anchorstring,tempstring+possize+1); anchorstring[size-possize-ipsize-2]='\0'; pos=atoi(posstring); anchor=atoi(anchorstring); int found=0; int i; for(i=0;i<cursorIPs.size();i++) { if(cursorIPs.at(i)==QString(ip)) { found=1; if(pos==-1){ cursorIPs.removeAt(i); cursorHighlights.removeAt(i); } else { cursorHighlights[i].cursor.setPosition(pos,QTextCursor::MoveAnchor); if(pos==anchor){ cursorHighlights[i].cursor.setPosition(pos+1,QTextCursor::KeepAnchor); } else { cursorHighlights[i].cursor.setPosition(anchor,QTextCursor::KeepAnchor); } } } } if(!found) { //add a new client QTextEdit::ExtraSelection highlight; highlight.cursor = editor->textCursor(); highlight.cursor.setPosition(pos,QTextCursor::MoveAnchor); highlight.cursor.setPosition(pos+1,QTextCursor::KeepAnchor); highlight.format = editor->currentCharFormat(); highlight.format.setBackground(pickColor(ip)); cursorIPs.append(ip); cursorHighlights.append(highlight); } editor->setExtraSelections(cursorHighlights); return(!found); }
void ColorWheel::mousePressEvent(QMouseEvent *event) { QPoint lastPos = event->pos(); if (mSquareRect.contains(lastPos)) { mIsInWheel = false; mIsInSquare = true; QColor color = pickColor(lastPos); saturationChanged(color.saturation()); valueChanged(color.value()); } else if (mWheelRect.contains(lastPos)) { mIsInWheel = true; mIsInSquare = false; QColor color = pickColor(lastPos); hueChanged(color.hue()); } }
void Canvas::mouseMoveEvent(QMouseEvent *event) { if ((event->buttons() & Qt::LeftButton)){ if(inPicker){ pickColor(event->pos()); }else{ if(drawing){ drawLineTo(event->pos()); lastPoint = event->pos(); } } } }
void StaticImageColorSource::updateColor() { QImage displayImage(image); drawCursor(displayImage); imageLabel->setPixmap(QPixmap::fromImage(displayImage)); pickColor(image); //Pass the color on emit colorChanged(lastColor); }
void ColorWheel::mouseMoveEvent(QMouseEvent* event) { QPoint lastPos = event->pos(); if ( event->buttons() == Qt::NoButton ) { return; } if (m_isInSquare) { QRect rect = m_squareRegion.boundingRect(); if ( lastPos.x() < rect.topLeft().x() ) { lastPos.setX( rect.topLeft().x() ); } else if ( lastPos.x() > rect.bottomRight().x() ) { lastPos.setX( rect.bottomRight().x() ); } if ( lastPos.y() < rect.topLeft().y() ) { lastPos.setY( rect.topLeft().y() ); } else if ( lastPos.y() > rect.bottomRight().y() ) { lastPos.setY( rect.bottomRight().y() ); } QColor color = pickColor(lastPos); svChanged(color); } else if (m_wheelRegion.contains(lastPos) && m_isInWheel) { QColor color = pickColor(lastPos); hueChanged(color.hue()); } }
void Canvas::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton) { if(inPicker){ pickColor(event->pos()); onColorPicker(false); }else{ if(drawing){ drawing = false; updateCursor(brush_->width()); } } } }
void MainWindow2::makeColorPaletteConnections() { connect(m_pColorPalette, SIGNAL(colorChanged(QColor)), editor->colorManager(), SLOT(pickColor(QColor))); connect(m_pColorPalette, SIGNAL(colorNumberChanged(int)), editor->colorManager(), SLOT(pickColorNumber(int))); connect(editor->colorManager(), SIGNAL(colorChanged(QColor)), m_pColorPalette, SLOT(setColor(QColor))); connect(editor->colorManager(), SIGNAL(colorNumberChanged(int)), m_pColorPalette, SLOT(selectColorNumber(int))); }
void ColorWheel::mouseMoveEvent(QMouseEvent* event) { QPoint lastPos = event->pos(); if (event->buttons() == Qt::NoButton) { return; } if (mIsInSquare) { if (lastPos.x() < mSquareRect.topLeft().x()) { lastPos.setX(mSquareRect.topLeft().x()); } else if (lastPos.x() > mSquareRect.bottomRight().x()) { lastPos.setX(mSquareRect.bottomRight().x()); } if (lastPos.y() < mSquareRect.topLeft().y()) { lastPos.setY(mSquareRect.topLeft().y()); } else if (lastPos.y() > mSquareRect.bottomRight().y()) { lastPos.setY(mSquareRect.bottomRight().y()); } QColor color = pickColor(lastPos); saturationChanged(color.saturation()); valueChanged(color.value()); } else if (mWheelRect.contains(lastPos) && mIsInWheel) { QColor color = pickColor(lastPos); hueChanged(color.hue()); } }
int Tiled::Internal::ColorButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QToolButton::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: colorChanged((*reinterpret_cast< const QColor(*)>(_a[1]))); break; case 1: pickColor(); break; default: ; } _id -= 2; } return _id; }
bool PointShopApp::MouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) { if (mMouseMode == MM_Pick_Rectangle || mMouseMode == MM_Pick_Cycle) { mPickTool.MouseReleased(arg.state.X.abs, arg.state.Y.abs); std::vector<int> pickIndex; mPickTool.GetPickPointsetIndex(pickIndex); MagicMath::Vector3 pickColor(1 - mDefaultColor[0], 1 - mDefaultColor[1], 1 - mDefaultColor[2]); for (std::vector<int>::iterator piIter = pickIndex.begin(); piIter != pickIndex.end(); ++piIter) { mPickIndexSet.insert(*piIter); mpPointSet->GetPoint(*piIter)->SetColor(pickColor); } UpdatePointSetRendering(); } return true; }
void ImageViewer::mousePressEvent(QMouseEvent *event) { if (!m_image) return; m_pos = event->pos() * getDevPixRatio(); m_pressedMousePos = TPoint(m_pos.x(), m_pos.y()); m_mouseButton = event->button(); m_draggingZoomSelection = false; if (m_mouseButton != Qt::LeftButton) { event->ignore(); return; } if (m_visualSettings.m_defineLoadbox && m_flipbook) m_dragType = getDragType( m_pressedMousePos, convert(getImgToWidgetAffine() * convert(m_flipbook->getLoadbox()))); else if (m_visualSettings.m_doCompare) { if (fabs(m_pos.x() - width() * m_compareSettings.m_compareX) < 20) { m_compareSettings.m_dragCompareX = true; m_compareSettings.m_dragCompareY = false; m_compareSettings.m_compareY = ImagePainter::DefaultCompareValue; update(); } else if (fabs((height() - m_pos.y()) - height() * m_compareSettings.m_compareY) < 20) { m_compareSettings.m_dragCompareY = true; m_compareSettings.m_dragCompareX = false; m_compareSettings.m_compareX = ImagePainter::DefaultCompareValue; update(); } else m_compareSettings.m_dragCompareX = m_compareSettings.m_dragCompareY = false; } // pick color and throw it to the style editor if (m_isHistogramEnable && m_histogramPopup->isVisible() && !m_isColorModel && !(event->modifiers() & Qt::ControlModifier)) // if ctrl button is // pressed, which means // rectangular pick { update(); pickColor(event, true); } event->ignore(); }
WidgetChatInput::WidgetChatInput(QWidget *parent, bool isIRC) : QMainWindow(parent), ui(new Ui::WidgetChatInput) { ui->setupUi(this); bIsIRC = isIRC; textEditInput = new WidgetReturnEmitTextEdit(this); connect(textEditInput, SIGNAL(cursorPositionChanged()), this, SLOT(updateToolbar())); ui->horizontalLayoutInput->addWidget(textEditInput); checkBoxSendOnEnter = new QCheckBox(tr("Send On Enter"), this); checkBoxSendOnEnter->setChecked(true); connect(checkBoxSendOnEnter, SIGNAL(toggled(bool)), textEditInput, SLOT(setEmitsReturn(bool))); connect(textEditInput, SIGNAL(returnPressed()), ui->toolButtonSend, SLOT(click())); connect(textEditInput, SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(onTextFormatChange(QTextCharFormat))); toolButtonSmilies = new QToolButton(); toolButtonSmilies->setPopupMode(QToolButton::InstantPopup); toolButtonSmilies->setToolTip(tr("Smilies")); toolButtonSmilies->setIcon(QIcon(":/Resource/Smileys/0.png")); widgetSmileyList = new WidgetSmileyList(this); toolButtonSmilies->setMenu(widgetSmileyList); toolButtonPickColor = new QToolButton(this); toolButtonPickColor->setStyleSheet(QString("QToolButton { background-color: %1; border-style: outset; border-width: 2px; border-radius: 6px; border-color: lightgrey; }").arg(textEditInput->textColor().name())); toolButtonPickColor->setToolTip(tr("Font Color")); connect(toolButtonPickColor, SIGNAL(clicked()), this, SLOT(pickColor())); toolButtonPrivateMessage = new QToolButton(this); toolButtonPrivateMessage->setText(tr("New Private Message")); toolButtonPrivateMessage->setToolTip(tr("New Private Message")); toolButtonPrivateMessage->setIcon(QIcon(":/Resource/Chat/Chat.png")); ui->toolBarTextTools->insertWidget(ui->actionBold, toolButtonPickColor); ui->toolBarTextTools->addSeparator(); ui->toolBarTextTools->addWidget(toolButtonSmilies); ui->toolBarTextTools->addWidget(checkBoxSendOnEnter); ui->actionBold->setChecked(textEditInput->fontWeight() == QFont::Bold); ui->actionItalic->setChecked(textEditInput->fontItalic()); ui->actionUnderline->setChecked(textEditInput->fontUnderline()); ui->toolBarTextTools->addWidget(toolButtonPrivateMessage); toolButtonPrivateMessage->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); connect(ui->actionItalic, SIGNAL(toggled(bool)), textEditInput, SLOT(setFontItalic(bool))); connect(ui->actionUnderline, SIGNAL(toggled(bool)), textEditInput, SLOT(setFontUnderline(bool))); connect(toolButtonPrivateMessage, SIGNAL(clicked()), this, SLOT(addPrivateMessage())); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , m_update_pending(false), m_animating(false) , m_fgColor(255, 255, 255), m_bgColor(0, 0, 0) { m_oglviewer = new OGLViewer; ui.setupUi(this); ui.ogl_layout->addWidget(m_oglviewer); //setWindowTitle(tr("OpenGL Qt Template")); m_oglviewer->setFocusPolicy(Qt::StrongFocus); connect(ui.clear_button, SIGNAL(clicked()), m_oglviewer, SLOT(clearVertex())); connect(ui.curve_type, SIGNAL(currentIndexChanged(int)), m_oglviewer, SLOT(changeCurveType(int))); connect(ui.degree_val, SIGNAL(valueChanged(int)), m_oglviewer, SLOT(setDegree(int))); connect(ui.seg_val, SIGNAL(valueChanged(int)), m_oglviewer, SLOT(setSegment(int))); connect(ui.actionOpen, SIGNAL(triggered()), this, SLOT(readPoints())); connect(ui.actionSave, SIGNAL(triggered()), this, SLOT(savePoints())); connect(ui.actionExport, SIGNAL(triggered()), this, SLOT(exportSVG())); signalMapper = new QSignalMapper(this); connect(signalMapper, SIGNAL(mapped(int)), m_oglviewer, SLOT(changeOperation(int))); signalMapper->setMapping(ui.actionInsert, 0); signalMapper->setMapping(ui.actionMove, 1); connect(ui.actionInsert, SIGNAL(triggered()), signalMapper, SLOT(map())); connect(ui.actionMove, SIGNAL(triggered()), signalMapper, SLOT(map())); connect(ui.intersection_button, SIGNAL(clicked()), m_oglviewer, SLOT(findIntersections())); connect(ui.disp_ctrl_pts, SIGNAL(toggled(bool)), m_oglviewer, SLOT(setDispCtrlPts(bool))); connect(ui.disp_curves, SIGNAL(toggled(bool)), m_oglviewer, SLOT(setDispCurves(bool))); connect(ui.disp_intersections, SIGNAL(toggled(bool)), m_oglviewer, SLOT(setDispIntersections(bool))); ui.foreground_color->setStyleSheet("QPushButton { background-color : #FFFFFF;}"); ui.background_color->setStyleSheet("QPushButton { background-color : #000000;}"); connect(ui.foreground_color, SIGNAL(clicked()), this, SLOT(pickColor())); }
ColorButton::ColorButton(QWidget *parent) : QPushButton(parent), color(QColor(255, 255, 255)) { connect(this, SIGNAL(clicked()), this, SLOT(pickColor())); updateImage(); }
void USDVMP::draw(FnKat::ViewerModifierInput& input) { TF_DEBUG(KATANA_DEBUG_VMP_USD).Msg("%s @ %p : %s\n", TF_FUNC_NAME().c_str(), this, _prim.GetPath().GetString().c_str()); // Render if (_stage) { // Get draw options needed for styling. bool isSelected = input.getDrawOption("selected"); bool drawPoints = input.getDrawOption("fillPoints"); bool drawWireframe = input.getDrawOption("fillWireframe"); bool drawSmooth = input.getDrawOption("shadingSmooth"); bool isPicking = input.getDrawOption("isPicking"); // Clear out override color _params.overrideColor[3] = 0.0f; // Determine the approrpiate draw mode based on the styling options. if ( drawSmooth ) { if (_GetProxyOverlayMode() == _tokens->wireframe) { _params.drawMode = UsdImagingGL::DRAW_WIREFRAME_ON_SURFACE; } else { _params.drawMode = UsdImagingGL::DRAW_SHADED_SMOOTH; } } if ( drawWireframe ) { _params.drawMode = UsdImagingGL::DRAW_WIREFRAME; } if ( drawPoints ) { // TODO: support draw points _params.drawMode = UsdImagingGL::DRAW_POINTS; } // If this gprim is selected setup drawmode and selection color. if ( isSelected ) { _params.drawMode = UsdImagingGL::DRAW_GEOM_SMOOTH; _params.overrideColor = GfVec4f(0.0f, 1.0f, 1.0f, 1.0f); glColor4fv(_params.overrideColor.GetArray()); } if (isPicking) { if(input.getDrawOption("hasPickColor") == 1) { GfVec4f pickColor(0, 0, 0, 1); pickColor[0] = input.getDrawOptionFloat("pickColorR"); pickColor[1] = input.getDrawOptionFloat("pickColorG"); pickColor[2] = input.getDrawOptionFloat("pickColorB"); _params.overrideColor = pickColor; } else { // Most horrible hack in the world :( // Katana does it's picking by setting a shader // that takes a pick id and renders geometry with // the color representation of that id. // Unfortunately if we are using Hydra, we need to // use our own shaders. To get around this, we are // using specific knowledge of the katana pick shader // to extract the pick id and set our own override color // based on this id. This is basically emulating what the // katana shader is doing. GLint program = -1; glGetIntegerv(GL_CURRENT_PROGRAM, &program); TF_VERIFY(program != -1); GLint kat_PickIdLoc = glGetUniformLocation(program, "kat_PickId"); if (TF_VERIFY(kat_PickIdLoc != -1)) { GLint kat_PickId; glGetUniformiv(program, kat_PickIdLoc, &kat_PickId); // Simulate pick id with color _params.overrideColor = GfVec4f( ((float)((kat_PickId >> 0 ) & 0xff)) / 255.0f, ((float)((kat_PickId >> 8 ) & 0xff)) / 255.0f, ((float)((kat_PickId >> 16 ) & 0xff)) / 255.0f, 1.0f); } } // Using DRAW_GEOM_ONLY will disable lighting and make // sure we are rendering a solid color _params.drawMode = UsdImagingGL::DRAW_GEOM_ONLY; } // Save and restore shader settings around render call // because hydra does not restore shader state. GLint oldProgram = -1; glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgram); if (TF_VERIFY(_renderer)) { _renderer->SetCameraStateFromOpenGL(); glPushAttrib(GL_LIGHTING_BIT | GL_ENABLE_BIT); if (_GetProxyOverlayMode() == _tokens->ghosted) { glEnable(GL_LIGHT0); float f = 0.1; float params[4] = { f, 0.0, f, 1.0 }; glLightfv(GL_LIGHT0, GL_AMBIENT, params); } _renderer->SetLightingStateFromOpenGL(); glPopAttrib(); // The multi-threaded Usd Op may be loading or unloading models on // the stage we need, so we grab the global lock in reader mode // before rendering. boost::shared_lock<boost::upgrade_mutex> readerLock(UsdKatanaGetStageLock()); _renderer->Render(_prim, _params); } // Restore old shader glUseProgram(oldProgram); }
int main(int argc, char *argv[]) { mandel_Pars pars; int i, j, x, y, k, nofslices, level, thread_status; int xoff,yoff; long double reEnd,imEnd,reCenter,imCenter; pthread_t *thread_workers; printf("\n"); printf("This program starts by drawing the default Mandelbrot region\n"); printf("When done, you can click with the mouse on an area of interest\n"); printf("and the program will automatically zoom around this point\n"); printf("\n"); printf("Press enter to continue\n"); getchar(); pars.reSteps = WinW; /* never changes */ pars.imSteps = WinH; /* never changes */ /* default mandelbrot region */ pars.reBeg = (long double) -2.0; reEnd = (long double) 1.0; pars.imBeg = (long double) -1.5; imEnd = (long double) 1.5; pars.reInc = (reEnd - pars.reBeg) / pars.reSteps; pars.imInc = (imEnd - pars.imBeg) / pars.imSteps; printf("enter max iterations (50): "); scanf("%d",&maxIterations); printf("enter no of slices: "); scanf("%d",&nofslices); /* adjust slices to divide win height */ while (WinH % nofslices != 0) { nofslices++;} /* allocate slice parameter and result arrays */ slices = (mandel_Pars *) malloc(sizeof(mandel_Pars)*nofslices); res = (int *) malloc(sizeof(int)*pars.reSteps*pars.imSteps); //workers init thread_workers = (pthread_t*)malloc(sizeof(pthread_t)*nofslices); work_status=(int *)malloc(sizeof(int)*nofslices); for(i=0;i<nofslices;i++)work_status[i]=-1; for(i=0;i<nofslices;i++){ thread_status=pthread_create(&thread_workers[i], NULL, workers, (void*)(intptr_t)i); if(thread_status){ perror("Fail create thread\n"); exit(1); } } /* open window for drawing results */ openDisplay(); openWin(argv[0], WinW, WinH); level = 1; while (1) { clearWin(); mandel_Slice(&pars,nofslices,slices); for(i=0;i<nofslices;i++)work_status[i]=0; i=0; y=0; while(i<nofslices){ for(k=0;work_status[k]!=1;k++)if((k+1)==nofslices)k=-1; for(i++, work_status[k]=2, j=0;j<slices[k].imSteps;j++,y++){ for(x=0;x<slices[k].reSteps;x++){ setColor(pickColor(res[y*slices[k].reSteps+x],maxIterations)); drawPoint(x, y); } } printf("thread no. %d finish draw\n", k); } /* get next focus/zoom point */ getMouseCoords(&x,&y); xoff = x; yoff = WinH-y; /* adjust region and zoom factor */ reCenter = pars.reBeg + xoff*pars.reInc; imCenter = pars.imBeg + yoff*pars.imInc; pars.reInc = pars.reInc*ZoomStepFactor; pars.imInc = pars.imInc*ZoomStepFactor; pars.reBeg = reCenter - (WinW/2)*pars.reInc; pars.imBeg = imCenter - (WinH/2)*pars.imInc; maxIterations = maxIterations*ZoomIterationFactor; level++; } /* never reach this point; for cosmetic reasons */ free(work_status); free(thread_workers); free(slices); free(res); closeWin(); closeDisplay(); }
/*! If middle button is pressed pan the image. Update current mouse position. */ void ImageViewer::mouseMoveEvent(QMouseEvent *event) { if (!m_image) return; QPoint curQPos = event->pos() * getDevPixRatio(); TPoint curPos = TPoint(curQPos.x(), curQPos.y()); if (m_visualSettings.m_defineLoadbox && m_flipbook) { if (m_mouseButton == Qt::LeftButton) updateLoadbox(curPos); else if (m_mouseButton == Qt::MidButton) panQt(curQPos - m_pos); else updateCursor(curPos); update(); event->ignore(); m_pos = curQPos; return; } // setting the cursors if (!m_isColorModel) { // when the histogram window is opened, switch to the RGB picker tool if (m_isHistogramEnable && m_histogramPopup->isVisible()) setToolCursor(this, ToolCursor::PickerRGB); else setCursor(Qt::ArrowCursor); } if (m_visualSettings.m_doCompare && m_mouseButton == Qt::NoButton) { if (fabs(curPos.x - width() * m_compareSettings.m_compareX) < 20) setToolCursor(this, ToolCursor::ScaleHCursor); else if (fabs((height() - curPos.y) - height() * m_compareSettings.m_compareY) < 20) setToolCursor(this, ToolCursor::ScaleVCursor); } if (m_compareSettings.m_dragCompareX || m_compareSettings.m_dragCompareY) dragCompare(curQPos - m_pos); else if (m_mouseButton == Qt::MidButton) panQt(curQPos - m_pos); m_pos = curQPos; // pick the color if the histogram popup is opened if (m_isHistogramEnable && m_histogramPopup->isVisible() && !m_isColorModel) { // Rect Pick if (m_mouseButton == Qt::LeftButton && (event->modifiers() & Qt::ControlModifier)) { if (!m_rectRGBPick && !m_visualSettings.m_defineLoadbox && (abs(m_pos.x() - m_pressedMousePos.x) > 10 || abs(m_pos.y() - m_pressedMousePos.y) > 10) && !(m_compareSettings.m_dragCompareX || m_compareSettings.m_dragCompareY) && m_flipbook) m_rectRGBPick = true; if (m_rectRGBPick) { update(); rectPickColor(); } } update(); pickColor(event); return; } if (m_mouseButton == Qt::LeftButton && !m_isColorModel && (event->modifiers() & Qt::AltModifier)) { if (!m_draggingZoomSelection && !m_visualSettings.m_defineLoadbox && (abs(m_pos.x() - m_pressedMousePos.x) > 10 || abs(m_pos.y() - m_pressedMousePos.y) > 10) && !(m_compareSettings.m_dragCompareX || m_compareSettings.m_dragCompareY) && m_flipbook) m_draggingZoomSelection = true; if (m_draggingZoomSelection) update(); } else m_draggingZoomSelection = false; if (m_isColorModel && m_mouseButton == Qt::LeftButton) { event->ignore(); } }
int main(int argc, char *argv[]) { mandelPars pars; int i,k,x,y,level,*res,check; int xoff,yoff, thrCheck; long double reStep,imStep; Toolbox **Tool; pthread_t *thrP; printf("\n"); printf("This program starts by drawing the default Mandelbrot region\n"); printf("When done, you can click with the mouse on an area of interest\n"); printf("and the program will zoom at this point\n"); printf("\n"); printf("Press enter to continue\n"); getchar(); pars.rePixels = WinW; /* never changes */ pars.imPixels = WinH; /* never changes */ /* default mandelbrot region */ pars.reBeg = (long double) -2.0; pars.reEnd = (long double) 1.0; pars.imBeg = (long double) -1.5; pars.imEnd = (long double) 1.5; reStep = (pars.reEnd - pars.reBeg) / pars.rePixels; imStep = (pars.imEnd - pars.imBeg) / pars.imPixels; printf("enter max iterations (50): "); scanf("%d",&pars.maxIterations); printf("enter no of slices: "); scanf("%d",&pars.slices); /* adjust slices to divide win height */ while (WinH % pars.slices != 0) { pars.slices++;} /* allocate result and ready arrays */ res = (int *) malloc(sizeof(int)*pars.rePixels*pars.imPixels); /* open window for drawing results */ openDisplay(); openWin(argv[0], WinW, WinH); level = 1; if (NULL== (Tool=(Toolbox**)malloc(sizeof(Toolbox)*pars.slices))){ perror ("Memory Error"); } for (i=0; i<pars.slices; i++){ if (NULL== (Tool[i]=(Toolbox*)malloc(sizeof(Toolbox)*pars.slices))){ perror ("Memory Error"); } if (NULL==(Tool[i]->mand=(mandelPars*)malloc(sizeof(mandelPars)))){ perror ("Memory error"); } Tool[i]->mand=&pars; if (NULL==(Tool[i]->res=(int*)malloc(sizeof(int)))){ perror ("Memory error"); } Tool[i]->res= res; Tool[i]->count=i; Tool[i]->rd=-1; if (NULL== (thrP=(pthread_t*)malloc(sizeof(pthread_t)*pars.slices))){ perror ("Memory Error"); } thrCheck = pthread_create( &thrP[i], NULL,calcMandel , (void *)Tool[i]); if(thrCheck) { fprintf(stderr,"Error - pthread_create() return code: %d\n",thrCheck); exit(EXIT_FAILURE); } } while (1) { clearWin(); printf("computing for level %d:\n",level); printf("reBeg=%Lf reEnd=%Lf reStep=%Lf\n",pars.reBeg,pars.reEnd,reStep); printf("imBeg=%Lf imEnd=%Lf imStep=%Lf\n",pars.imBeg,pars.imEnd,imStep); printf("maxIterations=%d\n",pars.maxIterations); for (i=0; i<pars.slices; i++) { Tool[i]->level=&level; Tool[i]->rd=0; } /* busywait (and draw results) until all slices done */ k=0; while (k!=pars.slices) { for (i=0; i<pars.slices; i++) { while (Tool[i]->rd!=1){ if (0!=(check= sched_yield())){ perror ("Thread"); } } for (y=i*(pars.imPixels/pars.slices); y<(i+1)*(pars.imPixels/pars.slices); y++) { for (x=0; x<pars.rePixels; x++) { setColor(pickColor(res[y*pars.rePixels+x],pars.maxIterations)); drawPoint(x,y); } } k++; Tool[i]->rd=2; } } /* get next focus/zoom point */ getMouseCoords(&x,&y); xoff = WinW/2 - x; yoff = WinH/2 - (WinH-y); /* adjust focus */ pars.reBeg = pars.reBeg - xoff*reStep; pars.reEnd = pars.reBeg + reStep*pars.rePixels; pars.imBeg = pars.imBeg - yoff*reStep; pars.imEnd = pars.imBeg + reStep*pars.imPixels; /* zoom in */ reStep = reStep*ZoomStepFactor; imStep = imStep*ZoomStepFactor; pars.reBeg = pars.reBeg + (pars.reEnd-pars.reBeg)/2 - reStep*pars.rePixels/2; pars.reEnd = pars.reBeg+reStep*pars.rePixels; pars.imBeg = pars.imBeg + (pars.imEnd-pars.imBeg)/2 - imStep*pars.imPixels/2; pars.imEnd = pars.imBeg+imStep*pars.imPixels; pars.maxIterations = pars.maxIterations*ZoomIterationFactor; level++; } /* never reach this point; for cosmetic reasons */ free(res); closeWin(); closeDisplay(); }
lineDialog::lineDialog( QWidget* parent, const char* name, bool modal, WFlags fl ) : QDialog( parent, name, modal, fl ) { if ( !name ) setName( "lineDialog" ); setCaption( tr( "QtiPlot - Line options" ) ); tw = new QTabWidget( this, "tw" ); options = new QWidget( tw, "options" ); GroupBox1 = new QButtonGroup( 2,QGroupBox::Horizontal, QString::null,options,"GroupBox1" ); new QLabel(tr( "Color" ), GroupBox1, "TextLabel1",0); colorBox = new ColorButton(GroupBox1); new QLabel(tr( "Line type" ),GroupBox1, "TextLabel1_2_2",0 ); styleBox = new QComboBox( FALSE, GroupBox1, "styleBox" ); styleBox->insertItem("_____"); styleBox->insertItem("- - -"); styleBox->insertItem("....."); styleBox->insertItem("_._._"); styleBox->insertItem("_.._.."); new QLabel(tr( "Line width" ),GroupBox1, "TextLabel1_2",0 ); widthBox = new QComboBox( FALSE, GroupBox1, "widthBox" ); widthBox->insertItem( tr( "1" ) ); widthBox->insertItem( tr( "2" ) ); widthBox->insertItem( tr( "3" ) ); widthBox->insertItem( tr( "4" ) ); widthBox->insertItem( tr( "5" ) ); widthBox->setEditable (TRUE); widthBox->setCurrentItem(0); startBox = new QCheckBox(GroupBox1, "startBox" ); startBox->setText( tr( "Arrow at &start" ) ); endBox = new QCheckBox(GroupBox1, "endBox" ); endBox->setText( tr( "Arrow at &end" ) ); endBox->setChecked(TRUE); QHBoxLayout* hl1 = new QHBoxLayout(options,5,5, "hl1"); hl1->addWidget(GroupBox1); tw->insertTab(options, tr( "Opti&ons" ) ); head = new QWidget( tw, "head" ); QButtonGroup *GroupBox4 = new QButtonGroup( 2,QGroupBox::Horizontal,tr(""),head,"GroupBox4" ); new QLabel(tr( "Length" ), GroupBox4, "TextLabel111",0); boxHeadLength = new QSpinBox( 0,100,1,GroupBox4, "boxHeadLength" ); new QLabel(tr( "Angle" ),GroupBox4, "TextLabel1112",0 ); boxHeadAngle = new QSpinBox(0,85,5,GroupBox4, "boxHeadAngle" ); filledBox = new QCheckBox(GroupBox4, "filledBox" ); filledBox->setText( tr( "&Filled" ) ); QHBoxLayout* hl3 = new QHBoxLayout(head,5,5, "hl3"); hl3->addWidget(GroupBox4); tw->insertTab(head, tr( "Arrow &Head" ) ); geometry = new QWidget( tw, "geometry" ); QButtonGroup *GroupBox2 = new QButtonGroup( 2,QGroupBox::Horizontal,tr("Start Point"),geometry,"GroupBox2" ); new QLabel(tr( "X" ), GroupBox2, "TextLabel11",0); xStartBox = new QSpinBox( 0,10000,1,GroupBox2, "xstart" ); new QLabel(tr( "Y" ),GroupBox2, "TextLabel111",0 ); yStartBox = new QSpinBox(0,10000,1,GroupBox2, "ystart" ); QButtonGroup *GroupBox3 = new QButtonGroup( 2,QGroupBox::Horizontal,tr("End Point"),geometry,"GroupBox3" ); new QLabel(tr( "X" ), GroupBox3, "TextLabel11",0); xEndBox = new QSpinBox(0,10000,1,GroupBox3, "xstart" ); new QLabel(tr( "Y" ),GroupBox3, "TextLabel111",0 ); yEndBox = new QSpinBox(0,10000,1,GroupBox3, "ystart" ); QHBoxLayout* hl2 = new QHBoxLayout(geometry,5,5, "hl2"); hl2->addWidget(GroupBox2); hl2->addWidget(GroupBox3); tw->insertTab(geometry, tr( "&Geometry" ) ); GroupBox2 = new QButtonGroup(3,QGroupBox::Horizontal, QString::null,this,"GroupBox2" ); GroupBox2->setLineWidth (0); btnOk = new QPushButton(GroupBox2, "btnOk" ); btnOk->setText( tr( "&Ok" ) ); btnApply = new QPushButton(GroupBox2, "btnApply" ); btnApply->setText( tr( "&Apply" ) ); btnCancel = new QPushButton(GroupBox2, "btnCancel" ); btnCancel->setText( tr( "&Cancel" ) ); QVBoxLayout* hlayout = new QVBoxLayout(this,5,5, "hlayout"); hlayout->addWidget(tw); hlayout->addWidget(GroupBox2); connect( colorBox, SIGNAL( clicked() ), this, SLOT(pickColor() ) ); connect( btnOk, SIGNAL( clicked() ), this, SLOT(accept() ) ); connect( btnApply, SIGNAL( clicked() ), this, SLOT(apply() ) ); connect( btnCancel, SIGNAL( clicked() ), this, SLOT(close() ) ); }
void SyntaxHighlighter::colorize(QString text) { Row *currentRow; TextField *field = NULL; enum {IDLE, MULTI_COMMENT, SPACES, WORD, GLOBAL_INCLUDE_FILE, COMMENT1,COMMENT, STRING, ESCAPED_CHAR, INC_STRING } state = IDLE; char c = '\n'; char prevC = ' '; char prevPrevC = ' '; bool isEscaped = false; reset(); currentRow = new Row; m_rows.push_back(currentRow); for(int i = 0;i < text.size();i++) { c = text[i].toLatin1(); // Was the last character an escape? if(prevC == '\\' && prevPrevC != '\\') isEscaped = true; else isEscaped = false; prevPrevC = prevC; prevC = c; switch(state) { case IDLE: { if(c == '/') { state = COMMENT1; field = new TextField; field->m_type = TextField::WORD; field->m_color = Qt::white; currentRow->appendField(field); field->m_text = c; } else if(c == ' ' || c == '\t') { state = SPACES; field = new TextField; field->m_type = TextField::SPACES; field->m_color = Qt::white; currentRow->appendField(field); field->m_text = c; } else if(c == '\'') { state = ESCAPED_CHAR; field = new TextField; field->m_type = TextField::STRING; currentRow->appendField(field); field->m_text = c; } else if(c == '"') { state = STRING; field = new TextField; if(currentRow->isCppRow) field->m_type = TextField::INC_STRING; else field->m_type = TextField::STRING; currentRow->appendField(field); field->m_text = c; } else if(c == '<' && currentRow->isCppRow) { // Is it a include string? bool isIncString = false; TextField *lastField = currentRow->getLastNonSpaceField(); if(lastField) { if(lastField->m_text == "include") isIncString = true; } // Add the field field = new TextField; field->m_text = c; if(isIncString) { state = INC_STRING; field->m_type = TextField::INC_STRING; } else { field->m_type = TextField::WORD; field->m_color = Qt::white; } currentRow->appendField(field); } else if(c == '#') { // Only spaces before the '#' at the line? bool onlySpaces = true; for(int j = 0;onlySpaces == true && j < currentRow->m_fields.size();j++) { if(currentRow->m_fields[j]->m_type != TextField::SPACES && currentRow->m_fields[j]->m_type != TextField::COMMENT) { onlySpaces = false; } } currentRow->isCppRow = onlySpaces ? true : false; // Create a new field structure field = new TextField; if(currentRow->isCppRow) field->m_type = TextField::CPP_KEYWORD; else field->m_type = TextField::WORD; field->m_color = Qt::white; currentRow->appendField(field); field->m_text = c; } else if(isSpecialChar(c)) { field = new TextField; field->m_type = TextField::WORD; field->m_color = Qt::white; currentRow->appendField(field); field->m_text = c; } else if(c == '\n') { currentRow = new Row; m_rows.push_back(currentRow); state = IDLE; } else { state = WORD; field = new TextField; if(QChar(c).isDigit()) field->m_type = TextField::NUMBER; else field->m_type = TextField::WORD; field->m_color = Qt::white; currentRow->appendField(field); field->m_text = c; } };break; case COMMENT1: { if(c == '*') { field->m_text += c; field->m_type = TextField::COMMENT; field->m_color = Qt::green; state = MULTI_COMMENT; } else if(c == '/') { field->m_text += c; field->m_type = TextField::COMMENT; field->m_color = Qt::green; state = COMMENT; } else { i--; state = IDLE; } };break; case MULTI_COMMENT: { if(c == '\n') { currentRow = new Row; m_rows.push_back(currentRow); field = new TextField; field->m_type = TextField::COMMENT; currentRow->appendField(field); } else if(text[i-1].toLatin1() == '*' && c == '/') { field->m_text += c; state = IDLE; } else { field->m_text += c; } };break; case COMMENT: { if(c == '\n') { i--; state = IDLE; } else field->m_text += c; };break; case SPACES: { if(c == ' ' || c == '\t') { field->m_text += c; } else { i--; field = NULL; state = IDLE; } };break; case GLOBAL_INCLUDE_FILE: { if(!isEscaped && c == '\n') { state = IDLE; } else { field->m_text += c; if(c == '>') { state = IDLE; } } };break; case ESCAPED_CHAR: { field->m_text += c; if(!isEscaped && c == '\'') { field = NULL; state = IDLE; } };break; case INC_STRING: { if(!isEscaped && c == '\n') { i--; field = NULL; state = IDLE; } else { field->m_text += c; if(!isEscaped && c == '>') { field = NULL; state = IDLE; } } };break; case STRING: { field->m_text += c; if(!isEscaped && c == '"') { field = NULL; state = IDLE; } };break; case WORD: { if(isSpecialChar(c) || c == ' ' || c == '\t' || c == '\n') { i--; if(currentRow->isCppRow) { if(isCppKeyword(field->m_text)) field->m_type = TextField::CPP_KEYWORD; } else { if(isKeyword(field->m_text)) field->m_type = TextField::KEYWORD; } field = NULL; state = IDLE; } else { field->m_text += c; } };break; } } for(int r = 0;r < m_rows.size();r++) { Row *currentRow = m_rows[r]; for(int j = 0;j < currentRow->m_fields.size();j++) { TextField* currentField = currentRow->m_fields[j]; pickColor(currentField); } } }