// Unzoom and go to the init position
void StelMovementMgr::autoZoomOut(float moveDuration, bool full)
{
	moveDuration /= movementsSpeedFactor;

	if (objectMgr->getWasSelected() && !full)
	{
		// If the selected object has satellites, unzoom to satellites view
		// unless specified otherwise
		float satfov = objectMgr->getSelectedObject()[0]->getSatellitesFov(core);

		if (satfov>0.0 && currentFov<=satfov*0.9)
		{
			zoomTo(satfov, moveDuration);
			return;
		}

		// If the selected object is part of a Planet subsystem (other than sun),
		// unzoom to subsystem view
		satfov = objectMgr->getSelectedObject()[0]->getParentSatellitesFov((core));
		if (satfov>0.0 && currentFov<=satfov*0.9)
		{
			zoomTo(satfov, moveDuration);
			return;
		}
	}

	zoomTo(initFov, moveDuration);
	if (flagAutoZoomOutResetsDirection)
	{
		moveToJ2000(core->altAzToJ2000(getInitViewingDirection(), StelCore::RefractionOff), moveDuration, -1);
		setFlagTracking(false);
		setFlagLockEquPos(false);
	}
}
Exemple #2
0
void QEditor::setText( const QString& text )
{
//    setTextFormat( Q3TextEdit::PlainText );

    Q3TextEdit::setText(text);
    // hack to maintain font point size
    zoomTo(pointSize()-1);
    zoomTo(pointSize()+1);

    refresh();
}
void SonicPiScintilla::zoomFontOut() {
  int zoom = property("zoom").toInt();
  zoom--;
  if (zoom < -10) zoom = -10;
  setProperty("zoom", QVariant(zoom));
  zoomTo(zoom);
}
void CurvesView::wheelEvent(QGraphicsSceneWheelEvent * event){
    if(event->modifiers().testFlag(Qt::ShiftModifier)){ // zoom only when SHIFT key pressed
        if(!zoomStarted){
            zoomCenter = event->scenePos();
            qDebug() << "Zoom center" << zoomCenter;
            zoomStarted = true;
        }
        if (event->delta() == 0) {
            event->ignore();
            return;
        }
        zoomFactor += (event->delta()>0)?0.05:-0.05;
        zoomTo(zoomFactor);
        /*
        if(zoomFactor<0.1){
            zoomFactor = 0.1;
        }else if(zoomFactor > 20){
            zoomFactor = 20;
        }
        */
        // qDebug() << "Zoom factor: " << zoomFactor;
        //qreal sc = pow(1.25, numSteps); // I use scale factor 1.25
        emit zoomChanged(QPointF(zoomFactor,zoomFactor), zoomCenter);

        event->accept();

    }else{
        zoomStarted = false;
        event->ignore();
    }

}
Exemple #5
0
void QcWaveform::mouseMoveEvent( QMouseEvent *ev )
{
  if( !ev->buttons() ) return;

  if( _dragAction == Navigate ) {
    Qt::KeyboardModifiers mods = ev->modifiers();
    if( mods & Qt::ShiftModifier ) {
      double factor = pow( 2, (ev->pos().y() - _dragPoint.y()) * 0.008 );
      // zoom to the initial zoom times the factor based on distance from initial position
      zoomTo( _dragData2 * factor );
    }
    // scroll to the clicked frame minus the current mouse position in frames
    // _fpp has been adjusted by zooming
    scrollTo( _dragData - (ev->pos().x() * _fpp) );
  }
  else if( _dragAction == Select ) {
    sf_count_t frame = qBound( 0, ev->pos().x(), width() ) * _fpp + _beg;
    setSelection( _curSel, _dragFrame, frame );
    update();
    Q_EMIT( action() );
  }
  else if( _dragAction == MoveSelection ) {
    double dpos = ev->pos().x() - _dragPoint.x();
    Selection &s = _selections[_curSel];
    s.start = _dragFrame + (dpos * _fpp);
    s.start = qBound( _rangeBeg, s.start, _rangeEnd - s.size );
    update();
    Q_EMIT( action() );
  }
  else if( _dragAction == MoveCursor ) {
    _cursorPos = qBound( 0, ev->pos().x(), width() ) * _fpp + _beg;
    update();
    Q_EMIT( metaAction() );
  }
}
Exemple #6
0
void GLWidget::zoomToTooth()
{
    if (isTooth)
        waitForToothSelection = true;
    else
        zoomTo(1);
}
void SonicPiScintilla::zoomFontIn() {
  int zoom = property("zoom").toInt();
  zoom++;
  if (zoom > 20) zoom = 20;
  setProperty("zoom", QVariant(zoom));
  zoomTo(zoom);
}
Exemple #8
0
MapView::MapView(QWidget *parent) : QGraphicsView(parent)
{
    outlinePen.setBrush(Qt::white);
    setInteractable(true);

    //NYI: limit maximum number of current downloads to 2 as specified in the CycleMap tileserver terms,
    // this would severely degrade download performance, though. Maybe keep limit at ~5?
    requestLimit = 5;
    maxReqStackSize = 30;
    networkManager = new QNetworkAccessManager(this);

    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    setScene(new QGraphicsScene(this)); //no delete necessary, parent set
    setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);

    lastTileUpdate = QTime(0,0);
    currentTime = new QTime(QTime::currentTime());

    //tile size: 256px x 256px, in coordinates: 2*PI x 2*PI
    scale(128/PI,128/PI); //default zoom == 0
    setSceneRect(-PI, -PI, 2*PI, 2*PI);

    mapSources.insert(OCM,{OCM,"OpenCycleMap", "http://tile.opencyclemap.org/cycle/", 0, 17});
    mapSources.insert(Mapnik,{Mapnik,"OpenStreetMap Mapnik", "http://tile.openstreetmap.org/", 0,18});
    mapSources.insert(None,{None,"None","",0,20});

    MapSource = {None, "None", "", 0 , 20};
    currentZoom = 0; zoomTo(MapSource.minzoom);

    connectSignalsAndSlots();
}
// private
void kpMainWindow::enableViewMenuDocumentActions (bool enable)
{
    m_viewMenuDocumentActionsEnabled = enable;


    m_actionActualSize->setEnabled (enable);
    /*m_actionFitToPage->setEnabled (enable);
    m_actionFitToWidth->setEnabled (enable);
    m_actionFitToHeight->setEnabled (enable);*/

    m_actionZoomIn->setEnabled (enable);
    m_actionZoomOut->setEnabled (enable);

    m_actionZoom->setEnabled (enable);

    actionShowGridUpdate ();

    m_actionShowThumbnail->setEnabled (enable);
    enableThumbnailOptionActions (enable);


    // TODO: for the time being, assume that we start at zoom 100%
    //       with no grid

    // This function is only called when a new document is created
    // or an existing document is closed.  So the following will
    // always be correct:

    zoomTo (100);
}
// private slot
void kpMainWindow::slotFitToHeight ()
{
    if (!m_scrollView || !m_document)
        return;

    // doc_height * zoom / 100 <= view_height &&
    // 1 <= zoom <= 3200

    zoomTo (QMIN (3200, QMAX (1, m_scrollView->visibleHeight () * 100 / m_document->height ())));
}
// private slot
void kpMainWindow::slotFitToWidth ()
{
    if (!m_scrollView || !m_document)
        return;

    // doc_width * zoom / 100 <= view_width &&
    // 1 <= zoom <= 3200

    zoomTo (QMIN (3200, QMAX (1, m_scrollView->visibleWidth () * 100 / m_document->width ())));
}
Exemple #12
0
bool RGraphicsView::zoomToSelection() {
    RDocument* document = getDocument();
    if (document == NULL) {
        return false;
    }
    RBox selectionBox = document->getSelectionBox();
    if (selectionBox.isValid() && (selectionBox.getWidth()>RS::PointTolerance || selectionBox.getHeight()>RS::PointTolerance)) {
        zoomTo(selectionBox, getMargin());
        return true;
    }
    return false;
}
// Go and zoom to the selected object. (Action linked to key, default "/")
void StelMovementMgr::autoZoomIn(float moveDuration, bool allowManualZoom)
{
	if (!objectMgr->getWasSelected())
		return;

	moveDuration /= movementsSpeedFactor;

	float manualMoveDuration;
	if (!getFlagTracking())
	{
		setFlagTracking(true); // includes a call to moveToObject(), but without zooming=1!
		moveToObject(objectMgr->getSelectedObject()[0], moveDuration, ZoomIn);
		manualMoveDuration = moveDuration;
	}
	else
	{
		// faster zoom in manual zoom mode once object is centered
		manualMoveDuration = moveDuration*.66f;
	}

	if( allowManualZoom && flagManualZoom )
	{
		// if manual zoom mode, user can zoom in incrementally
		float newfov = currentFov*0.5f;
		zoomTo(newfov, manualMoveDuration);
	}
	else
	{
		float satfov = objectMgr->getSelectedObject()[0]->getSatellitesFov(core);

		if (satfov>0.0 && currentFov*0.9>satfov)
			zoomTo(satfov, moveDuration);
		else
		{
			float closefov = objectMgr->getSelectedObject()[0]->getCloseViewFov(core);
			if (currentFov>closefov)
				zoomTo(closefov, moveDuration);
		}
	}
}
Exemple #14
0
//------------------------------------------------------------------------------
void ptImageView::receiveImage(uint, TThumbPtr AImage8) {
  FFilenameCurrent = FFilenameNext;
  FFilenameNext.clear();

  FImage = AImage8;

  if (FZoomMode == ptZoomMode_Fit)
    zoomFit(false);
  else
    zoomTo(FZoomFactor, true);

  FStatusOverlay->stop();
}
bool StelMovementMgr::handlePinch(qreal scale, bool started)
{
#ifdef Q_OS_WIN
	if (flagEnableMouseNavigation == false)
		return true;
#endif

	static double previousFov = 0;
	if (started)
		previousFov = getAimFov();
	if (scale>0)
		zoomTo(previousFov/scale, 0);
	return true;
}
Exemple #16
0
void MapView::setMapSource(sourceName source)
{
    //get new map source struct
    osmMapSource newSource = mapSource(source);

    //check if map source changed, if it did not, abort
    if (newSource.id == MapSource.id) return;

    emit mapSourceChanged(newSource.minzoom, newSource.maxzoom);

    //remove all tiles, resize tilemanager
    if (MapSource.id != None) {
    for (int z = MapSource.minzoom; z <= MapSource.maxzoom; ++z) removeTiles(z);
    delete[] tiles;
    }
    if (newSource.id != None) tiles = new QList<OSMTile*>[newSource.maxzoom+1];

    MapSource = newSource;

    if (currentZoom > MapSource.maxzoom) zoomTo(MapSource.maxzoom);
    else if (currentZoom < MapSource.minzoom) zoomTo(MapSource.minzoom);
    else getTilesInView();
}
Exemple #17
0
void Palapeli::PieceHolder::initializeZooming()
{
	// Allow space for a distant view of at most (maxGrid * maxGrid) pieces
	// in a piece holder when the view is at minimum size. More that number
	// of pieces can be teleported in, but the holder window will have to be
	// resized or scrolled for the user to see them, even in distant view.

	qDebug() << "ENTERED PieceHolder::initializeZooming() for" << name();
	qreal scale = qMin(transform().m11(), transform().m22());
	scale = scale * (minGrid / maxGrid);
	// Calculate the zooming range and return the close-up scale's level.
	int level = calculateZoomRange(scale, false);
	zoomTo(level);
	centerOn(sceneRect().center());
}
//
// Mouse left button up event.
//
void CChartViewer::OnLButtonUp(UINT nFlags, CPoint point) 
{
	mouse_state=true;
	if (m_isPlotAreaMouseDown)
	{
		// Release the mouse capture.
		ReleaseCapture();
		m_isPlotAreaMouseDown = false;
		setRectVisible(false);
		bool hasUpdate = false;

		switch (m_mouseUsage)
		{
		case Chart::MouseUsageZoomIn :
			if (canZoomIn(m_zoomDirection))
			{
				if (isDrag(m_zoomDirection, point))
					// Zoom to the drag selection rectangle.
					hasUpdate = zoomTo(m_zoomDirection, 
						m_plotAreaMouseDownXPos, m_plotAreaMouseDownYPos, point.x, point.y);
				else
					// User just click on a point. Zoom-in around the mouse cursor position.
					hasUpdate = zoomAt(m_zoomDirection, point.x, point.y, m_zoomInRatio);
			}
			break;
		case Chart::MouseUsageZoomOut:
			// Zoom out around the mouse cursor position.
			if (canZoomOut(m_zoomDirection))
				hasUpdate = zoomAt(m_zoomDirection, point.x, point.y, m_zoomOutRatio);
			break;
		default :
			if (m_isDragScrolling)
				// Drag to scroll. We can update the image map now as scrolling has finished.
				updateViewPort(false, true);
			else
				// Is not zooming or scrolling, so is just a normal click event.
				GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED), (LPARAM)m_hWnd);
			break;
		}

		m_isDragScrolling = false;
		if (hasUpdate)
			// View port has changed - update it.
			updateViewPort(true, true);
	}
	
	CStatic::OnLButtonUp(nFlags, point);
}
Exemple #19
0
/*!
    \qmlmethod bool WebView::heuristicZoom(int clickX, int clickY, real maxzoom)

    Finds a zoom that:
    \list
    \li shows a whole item
    \li includes (\a clickX, \a clickY)
    \li fits into the preferredWidth and preferredHeight
    \li zooms by no more than \a maxZoom
    \li is more than 10% above the current zoom
    \endlist

    If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise,
    no signal is emitted and returns false.
*/
bool QDeclarativeWebView::heuristicZoom(int clickX, int clickY, qreal maxZoom)
{
    if (contentsScale() >= maxZoom / scale())
        return false;
    qreal ozf = contentsScale();
    QRect showArea = elementAreaAt(clickX, clickY, d->preferredwidth / maxZoom, d->preferredheight / maxZoom);
    qreal z = qMin(qreal(d->preferredwidth) / showArea.width(), qreal(d->preferredheight) / showArea.height());
    if (z > maxZoom / scale())
        z = maxZoom / scale();
    if (z / ozf > 1.2) {
        QRectF r(showArea.left() * z, showArea.top() * z, showArea.width() * z, showArea.height() * z);
        emit zoomTo(z, r.x() + r.width() / 2, r.y() + r.height() / 2);
        return true;
    }
    return false;
}
//! Handle mouse wheel events.
void StelMovementMgr::handleMouseWheel(QWheelEvent* event)
{
	if (flagEnableMouseNavigation==false)
		return;

	// Manage only vertical wheel event
	if (event->orientation() != Qt::Vertical)
		return;
  
	const float numSteps = event->delta() / 120.f;
	const float zoomFactor = std::exp(-mouseZoomSpeed * numSteps / 60.f);
	const float zoomDuration = 0.2f * qAbs(numSteps);
	zoomTo(getAimFov() * zoomFactor, zoomDuration);

	event->accept();
}
Exemple #21
0
void QScintillaWidget::keyPressEvent(QKeyEvent *pEvent)
{
    // Let people know that a key has been pressed

    bool handled = false;

    emit keyPressed(pEvent, handled);

    // Carry on as normal, if the event wasn't handled

    if (handled) {
        // Accept the event

        pEvent->accept();
    } else {
        // Reset the font size, if needed

        if (   !(pEvent->modifiers() & Qt::ShiftModifier)
            &&  (pEvent->modifiers() & Qt::ControlModifier)
            && !(pEvent->modifiers() & Qt::AltModifier)
            && !(pEvent->modifiers() & Qt::MetaModifier)) {
            if (pEvent->key() == Qt::Key_0) {
                zoomTo(0);

                // Accept the event

                pEvent->accept();
            } else if (pEvent->key() == Qt::Key_Equal) {
                zoomIn();

                // Accept the event

                pEvent->accept();
            } else {
                // Default handling of the event

                QsciScintilla::keyPressEvent(pEvent);
            }
        } else {
            // Default handling of the event

            QsciScintilla::keyPressEvent(pEvent);
        }
    }
}
Exemple #22
0
void RGraphicsView::autoZoom(int margin, bool ignoreEmpty) {
    RDocument* document = getDocument();
    if (document == NULL) {
        return;
    }
    RBox bb = document->getBoundingBox(true, ignoreEmpty);

    // TODO: optional:
    bb.growXY(
        RUnit::convert(
            document->getMaxLineweight()/100.0/2,
            RS::Millimeter,
            document->getUnit()
        )
    );

    zoomTo(bb, (margin!=-1 ? margin : getMargin()));
}
Exemple #23
0
LRESULT CImgAreaWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    if ((!drawing) || (toolsModel.GetActiveTool() == TOOL_COLOR))
    {
        SetCapture();
        drawing = TRUE;
        startPaintingR(imageModel.GetDC(), GET_X_LPARAM(lParam) * 1000 / toolsModel.GetZoom(), GET_Y_LPARAM(lParam) * 1000 / toolsModel.GetZoom(),
                       paletteModel.GetFgColor(), paletteModel.GetBgColor());
    }
    else
    {
        SendMessage(WM_RBUTTONUP, wParam, lParam);
        imageModel.Undo();
    }
    Invalidate(FALSE);
    if ((toolsModel.GetActiveTool() == TOOL_ZOOM) && (toolsModel.GetZoom() > 125))
        zoomTo(toolsModel.GetZoom() / 2, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
    return 0;
}
Exemple #24
0
void GLWidget::mousePressEvent(QMouseEvent *event)
{
    if (!waitForToothSelection)
    {
        prevPos = event->pos();
        if (event->button() == Qt::LeftButton)
            lbut = true;

        if (event->button() == Qt::RightButton)
            rbut = true;
    } else
    {
        if (event->button() == Qt::LeftButton)
        {
            if (toothSelected != 0)
                zoomTo(toothSelected);

            waitForToothSelection = false;
        }
    }
}
ReportManager::ReportManager(KMainWindow* m, QWidgetStack* v,
                             KListView* b, KListViewSearchLine* s) :
    mainWindow(m), reportStack(v), browser(b), searchLine(s)
{
    loadingProject = false;

    /* Hide the 2nd column. It contains the report ID that is of no interest
     * to the user. */
    browser->setColumnWidthMode(1, QListView::Manual);
    browser->hideColumn(1);

    // Setup zoom toolbar actions.
    zoomSelector = new KSelectAction
        (i18n("Zoom"), "viewmag", 0, this, SLOT(zoomTo()),
         m->actionCollection(), "zoom_to");
    zoomSelector->setEditable(false);
    zoomSelector->setComboWidth(170);
#if KDE_IS_VERSION(3,4,89)
    zoomSelector->setMaxComboViewCount(15);
#endif

}
Exemple #26
0
//------------------------------------------------------------------------------
void ptImageView::resizeTimerExpired() {
  zoomTo(FZoomFactor, false);
}
Exemple #27
0
LRESULT CALLBACK
SettingsWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_VSCROLL:
            zoomTo(125 << SendMessage(hTrackbarZoom, TBM_GETPOS, 0, 0), 0, 0);
            break;
        case WM_PAINT:
        {
            HDC hdc = GetDC(hwnd);
            RECT rect1 = { 0, 0, 42, 66 };
            RECT rect2 = { 0, 70, 42, 136 };

            DefWindowProc(hwnd, message, wParam, lParam);

            DrawEdge(hdc, &rect1, BDR_SUNKENOUTER, (activeTool == TOOL_ZOOM) ? BF_RECT : BF_RECT | BF_MIDDLE);
            DrawEdge(hdc, &rect2, (activeTool >= TOOL_RECT) ? BDR_SUNKENOUTER : 0, BF_RECT | BF_MIDDLE);
            switch (activeTool)
            {
                case TOOL_FREESEL:
                case TOOL_RECTSEL:
                case TOOL_TEXT:
                {
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                    Rectangle(hdc, 2, transpBg * 31 + 2, 41, transpBg * 31 + 33);
                    DeleteObject(SelectObject(hdc, oldPen));
                    DrawIconEx(hdc, 1, 2, hNontranspIcon, 40, 30, 0, NULL, DI_NORMAL);
                    DrawIconEx(hdc, 1, 33, hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
                    break;
                }
                case TOOL_RUBBER:
                {
                    int i;
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    for(i = 0; i < 4; i++)
                    {
                        if (rubberRadius == i + 2)
                        {
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                            Rectangle(hdc, 14, i * 15 + 2, 29, i * 15 + 17);
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
                        }
                        else
                            SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
                        Rectangle(hdc, 19 - i, i * 14 + 7, 24 + i, i * 16 + 12);
                    }
                    DeleteObject(SelectObject(hdc, oldPen));
                    break;
                }
                case TOOL_BRUSH:
                {
                    int i;
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                    Rectangle(hdc, brushStyle % 3 * 13 + 2, brushStyle / 3 * 15 + 2, brushStyle % 3 * 13 + 15,
                              brushStyle / 3 * 15 + 17);
                    DeleteObject(SelectObject(hdc, oldPen));
                    for(i = 0; i < 12; i++)
                        Brush(hdc, i % 3 * 13 + 7, i / 3 * 15 + 8, i % 3 * 13 + 7, i / 3 * 15 + 8,
                              GetSysColor((i == brushStyle) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), i);
                    break;
                }
                case TOOL_AIRBRUSH:
                {
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                    switch (airBrushWidth)
                    {
                        case 5:
                            Rectangle(hdc, 2, 2, 21, 31);
                            break;
                        case 8:
                            Rectangle(hdc, 20, 2, 41, 31);
                            break;
                        case 3:
                            Rectangle(hdc, 2, 30, 16, 61);
                            break;
                        case 12:
                            Rectangle(hdc, 15, 30, 41, 61);
                            break;
                    }
                    Airbrush(hdc, 10, 15,
                             GetSysColor((airBrushWidth == 5) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 5);
                    Airbrush(hdc, 30, 15,
                             GetSysColor((airBrushWidth == 8) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 8);
                    Airbrush(hdc, 8, 45,
                             GetSysColor((airBrushWidth == 3) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 3);
                    Airbrush(hdc, 27, 45,
                             GetSysColor((airBrushWidth == 12) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 12);
                    DeleteObject(SelectObject(hdc, oldPen));
                    break;
                }
                case TOOL_LINE:
                case TOOL_BEZIER:
                {
                    int i;
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    for(i = 0; i < 5; i++)
                    {
                        if (lineWidth == i + 1)
                        {
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                            Rectangle(hdc, 2, i * 12 + 2, 41, i * 12 + 14);
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
                        }
                        else
                            SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
                        Rectangle(hdc, 5, i * 12 + 6, 38, i * 12 + 8 + i);
                    }
                    DeleteObject(SelectObject(hdc, oldPen));
                    break;
                }
                case TOOL_RECT:
                case TOOL_SHAPE:
                case TOOL_ELLIPSE:
                case TOOL_RRECT:
                {
                    int i;
                    HPEN oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
                    for(i = 0; i < 3; i++)
                    {
                        if (shapeStyle == i)
                        {
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                            Rectangle(hdc, 2, i * 20 + 2, 41, i * 20 + 22);
                        }
                    }
                    Rect(hdc, 5, 6, 37, 16,
                         GetSysColor((shapeStyle == 0) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT),
                         GetSysColor(COLOR_APPWORKSPACE), 1, 0);
                    Rect(hdc, 5, 26, 37, 36,
                         GetSysColor((shapeStyle == 1) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT),
                         GetSysColor(COLOR_APPWORKSPACE), 1, 1);
                    Rect(hdc, 5, 46, 37, 56, GetSysColor(COLOR_APPWORKSPACE), GetSysColor(COLOR_APPWORKSPACE),
                         1, 1);
                    for(i = 0; i < 5; i++)
                    {
                        if (lineWidth == i + 1)
                        {
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHT));
                            Rectangle(hdc, 2, i * 12 + 72, 41, i * 12 + 84);
                            SelectObject(hdc, GetSysColorBrush(COLOR_HIGHLIGHTTEXT));
                        }
                        else
                            SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
                        Rectangle(hdc, 5, i * 12 + 76, 38, i * 12 + 78 + i);
                    }
                    DeleteObject(SelectObject(hdc, oldPen));
                    break;
                }
            }
            ReleaseDC(hwnd, hdc);
            break;
        }
        case WM_LBUTTONDOWN:
        {
            int x = GET_X_LPARAM(lParam);
            int y = GET_Y_LPARAM(lParam);
            switch (activeTool)
            {
                case TOOL_FREESEL:
                case TOOL_RECTSEL:
                case TOOL_TEXT:
                    if ((y > 1) && (y < 64))
                    {
                        transpBg = (y - 2) / 31;
                        InvalidateRect(hwnd, NULL, TRUE);

                        ForceRefreshSelectionContents();
                    }
                    break;
                case TOOL_RUBBER:
                    if ((y > 1) && (y < 62))
                    {
                        rubberRadius = (y - 2) / 15 + 2;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
                case TOOL_BRUSH:
                    if ((x > 1) && (x < 40) && (y > 1)
                        && (y < 62))
                    {
                        brushStyle = (y - 2) / 15 * 3 + (x - 2) / 13;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
                case TOOL_AIRBRUSH:
                    if (y < 62)
                    {
                        if (y < 30)
                        {
                            if (x < 20)
                                airBrushWidth = 5;
                            else
                                airBrushWidth = 8;
                        }
                        else
                        {
                            if (x < 15)
                                airBrushWidth = 3;
                            else
                                airBrushWidth = 12;
                        }
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
                case TOOL_LINE:
                case TOOL_BEZIER:
                    if (y <= 62)
                    {
                        lineWidth = (y - 2) / 12 + 1;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
                case TOOL_RECT:
                case TOOL_SHAPE:
                case TOOL_ELLIPSE:
                case TOOL_RRECT:
                    if (y <= 60)
                    {
                        shapeStyle = (y - 2) / 20;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    if ((y >= 70) && (y <= 132))
                    {
                        lineWidth = (y - 72) / 12 + 1;
                        InvalidateRect(hwnd, NULL, TRUE);
                    }
                    break;
            }
            break;
        }

        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}
Exemple #28
0
void QcWaveform::setXZoom( double seconds )
{
  // NOTE We have limited _rangeDur to 1 minimum.
  double frac = seconds * sfInfo.samplerate / _rangeDur;
  zoomTo( frac );
}
Exemple #29
0
void QcWaveform::zoomBy( double factor )
{
  zoomTo( zoom() * factor );
}
Exemple #30
0
LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    switch (LOWORD(wParam))
    {
        case IDM_HELPINFO:
        {
            HICON paintIcon = LoadIcon(hProgInstance, MAKEINTRESOURCE(IDI_APPICON));
            TCHAR infotitle[100];
            TCHAR infotext[200];
            LoadString(hProgInstance, IDS_INFOTITLE, infotitle, SIZEOF(infotitle));
            LoadString(hProgInstance, IDS_INFOTEXT, infotext, SIZEOF(infotext));
            ShellAbout(m_hWnd, infotitle, infotext, paintIcon);
            DeleteObject(paintIcon);
            break;
        }
        case IDM_HELPHELPTOPICS:
            HtmlHelp(m_hWnd, _T("help\\Paint.chm"), 0, 0);
            break;
        case IDM_FILEEXIT:
            SendMessage(WM_CLOSE, wParam, lParam);
            break;
        case IDM_FILENEW:
        {
            BOOL reset = TRUE;
            if (!imageModel.IsImageSaved())
            {
                TCHAR programname[20];
                TCHAR saveprompttext[100];
                TCHAR temptext[500];
                LoadString(hProgInstance, IDS_PROGRAMNAME, programname, SIZEOF(programname));
                LoadString(hProgInstance, IDS_SAVEPROMPTTEXT, saveprompttext, SIZEOF(saveprompttext));
                _stprintf(temptext, saveprompttext, filename);
                switch (MessageBox(temptext, programname, MB_YESNOCANCEL | MB_ICONQUESTION))
                {
                    case IDNO:
                        imageModel.imageSaved = TRUE; //TODO: move to ImageModel
                        break;
                    case IDYES:
                        saveImage(FALSE);
                        break;
                    case IDCANCEL:
                        reset = FALSE;
                        break;
                }
            }
            if (reset && imageModel.IsImageSaved()) //TODO: move to ImageModel
            {
                imageModel.Clear();
                imageModel.ClearHistory();
            }
            break;
        }
        case IDM_FILEOPEN:
            if (GetOpenFileName(&ofn) != 0)
            {
                HBITMAP bmNew = NULL;
                LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
                if (bmNew != NULL)
                {
                    UpdateApplicationProperties(bmNew, ofn.lpstrFileTitle, ofn.lpstrFileTitle);
                }
            }
            break;
        case IDM_FILESAVE:
            saveImage(TRUE);
            break;
        case IDM_FILESAVEAS:
            saveImage(FALSE);
            break;
        case IDM_FILEPAGESETUP:
            // DUMMY: Shows the dialog only, no functionality
            PAGESETUPDLG psd;
            ZeroMemory(&psd, sizeof(psd));
            psd.lStructSize = sizeof(psd);
            psd.hwndOwner = m_hWnd;
            PageSetupDlg(&psd);
            break;
        case IDM_FILEPRINT:
            // TODO: Test whether it actually works
            PRINTDLG pd;
            ZeroMemory(&pd, sizeof(pd));
            pd.lStructSize = sizeof(pd);
            pd.hwndOwner = m_hWnd;
            pd.hDevMode = NULL;  // freed by user
            pd.hDevNames = NULL;  // freed by user
            pd.Flags = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
            pd.nCopies = 1;
            pd.nFromPage = 0xffff;
            pd.nToPage = 0xffff;
            pd.nMinPage = 1;
            pd.nMaxPage = 0xffff;
            if (PrintDlg(&pd) == TRUE)
            {
                BitBlt(pd.hDC, 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), imageModel.GetDC(), 0, 0, SRCCOPY);
                DeleteDC(pd.hDC);
            }
            if (pd.hDevMode)
                GlobalFree(pd.hDevMode);
            if (pd.hDevNames)
                GlobalFree(pd.hDevNames);
            break;
        case IDM_FILEASWALLPAPERPLANE:
            RegistrySettings::SetWallpaper(filepathname, 1, 1);
            break;
        case IDM_FILEASWALLPAPERCENTERED:
            RegistrySettings::SetWallpaper(filepathname, 1, 0);
            break;
        case IDM_FILEASWALLPAPERSTRETCHED:
            RegistrySettings::SetWallpaper(filepathname, 2, 0);
            break;
        case IDM_EDITUNDO:
            imageModel.Undo();
            imageArea.Invalidate(FALSE);
            break;
        case IDM_EDITREDO:
            imageModel.Redo();
            imageArea.Invalidate(FALSE);
            break;
        case IDM_EDITCOPY:
            OpenClipboard();
            EmptyClipboard();
            SetClipboardData(CF_BITMAP, CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
            CloseClipboard();
            break;
        case IDM_EDITCUT:
            /* Copy */
            SendMessage(WM_COMMAND, IDM_EDITCOPY, 0);
            /* Delete selection */
            SendMessage(WM_COMMAND, IDM_EDITDELETESELECTION, 0);
            break;
        case IDM_EDITPASTE:
            OpenClipboard();
            if (GetClipboardData(CF_BITMAP) != NULL)
            {
                InsertSelectionFromHBITMAP((HBITMAP) GetClipboardData(CF_BITMAP), m_hWnd);
            }
            CloseClipboard();
            break;
        case IDM_EDITDELETESELECTION:
        {
            /* remove selection window and already painted content using undo */
            imageModel.Undo();
            break;
        }
        case IDM_EDITSELECTALL:
        {
            HWND hToolbar = FindWindowEx(toolBoxContainer.m_hWnd, NULL, TOOLBARCLASSNAME, NULL);
            SendMessage(hToolbar, TB_CHECKBUTTON, ID_RECTSEL, MAKELPARAM(TRUE, 0));
            toolBoxContainer.SendMessage(WM_COMMAND, ID_RECTSEL);
            //TODO: do this properly
            startPaintingL(imageModel.GetDC(), 0, 0, paletteModel.GetFgColor(), paletteModel.GetBgColor());
            whilePaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
            endPaintingL(imageModel.GetDC(), imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetFgColor(), paletteModel.GetBgColor());
            break;
        }
        case IDM_EDITCOPYTO:
            if (GetSaveFileName(&ofn) != 0)
                SaveDIBToFile(selectionModel.GetBitmap(), ofn.lpstrFile, imageModel.GetDC(), NULL, NULL, fileHPPM, fileVPPM);
            break;
        case IDM_EDITPASTEFROM:
            if (GetOpenFileName(&ofn) != 0)
            {
                HBITMAP bmNew = NULL;
                LoadDIBFromFile(&bmNew, ofn.lpstrFile, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
                if (bmNew != NULL)
                {
                    InsertSelectionFromHBITMAP(bmNew, m_hWnd);
                    DeleteObject(bmNew);
                }
            }
            break;
        case IDM_COLORSEDITPALETTE:
            if (ChooseColor(&choosecolor))
                paletteModel.SetFgColor(choosecolor.rgbResult);
            break;
        case IDM_COLORSMODERNPALETTE:
            paletteModel.SelectPalette(1);
            break;
        case IDM_COLORSOLDPALETTE:
            paletteModel.SelectPalette(2);
            break;
        case IDM_IMAGEINVERTCOLORS:
        {
            imageModel.InvertColors();
            break;
        }
        case IDM_IMAGEDELETEIMAGE:
            imageModel.CopyPrevious();
            Rect(imageModel.GetDC(), 0, 0, imageModel.GetWidth(), imageModel.GetHeight(), paletteModel.GetBgColor(), paletteModel.GetBgColor(), 0, TRUE);
            imageArea.Invalidate(FALSE);
            break;
        case IDM_IMAGEROTATEMIRROR:
            switch (mirrorRotateDlg())
            {
                case 1: /* flip horizontally */
                    if (selectionWindow.IsWindowVisible())
                        selectionModel.FlipHorizontally();
                    else
                        imageModel.FlipHorizontally();
                    break;
                case 2: /* flip vertically */
                    if (selectionWindow.IsWindowVisible())
                        selectionModel.FlipVertically();
                    else
                        imageModel.FlipVertically();
                    break;
                case 3: /* rotate 90 degrees */
                    break;
                case 4: /* rotate 180 degrees */
                    if (selectionWindow.IsWindowVisible())
                        selectionModel.RotateNTimes90Degrees(2);
                    else
                        imageModel.RotateNTimes90Degrees(2);
                    break;
                case 5: /* rotate 270 degrees */
                    break;
            }
            break;
        case IDM_IMAGEATTRIBUTES:
        {
            if (attributesDlg())
            {
                imageModel.Crop(widthSetInDlg, heightSetInDlg, 0, 0);
            }
            break;
        }
        case IDM_IMAGESTRETCHSKEW:
        {
            if (changeSizeDlg())
            {
                imageModel.StretchSkew(stretchSkew.percentage.x, stretchSkew.percentage.y,
                                       stretchSkew.angle.x, stretchSkew.angle.y);
            }
            break;
        }
        case IDM_IMAGEDRAWOPAQUE:
            toolsModel.SetBackgroundTransparent(!toolsModel.IsBackgroundTransparent());
            break;
        case IDM_IMAGECROP:
            imageModel.Insert((HBITMAP) CopyImage(selectionModel.GetBitmap(), IMAGE_BITMAP, 0, 0, LR_COPYRETURNORG));
            break;

        case IDM_VIEWTOOLBOX:
            toolBoxContainer.ShowWindow(toolBoxContainer.IsWindowVisible() ? SW_HIDE : SW_SHOW);
            alignChildrenToMainWindow();
            break;
        case IDM_VIEWCOLORPALETTE:
            paletteWindow.ShowWindow(paletteWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);
            alignChildrenToMainWindow();
            break;
        case IDM_VIEWSTATUSBAR:
            ::ShowWindow(hStatusBar, ::IsWindowVisible(hStatusBar) ? SW_HIDE : SW_SHOW);
            alignChildrenToMainWindow();
            break;
        case IDM_FORMATICONBAR:
            textEditWindow.ShowWindow(textEditWindow.IsWindowVisible() ? SW_HIDE : SW_SHOW);

        case IDM_VIEWSHOWGRID:
            showGrid = !showGrid;
            imageArea.Invalidate(FALSE);
            break;
        case IDM_VIEWSHOWMINIATURE:
            showMiniature = !showMiniature;
            miniature.ShowWindow(showMiniature ? SW_SHOW : SW_HIDE);
            break;

        case IDM_VIEWZOOM125:
            zoomTo(125, 0, 0);
            break;
        case IDM_VIEWZOOM25:
            zoomTo(250, 0, 0);
            break;
        case IDM_VIEWZOOM50:
            zoomTo(500, 0, 0);
            break;
        case IDM_VIEWZOOM100:
            zoomTo(1000, 0, 0);
            break;
        case IDM_VIEWZOOM200:
            zoomTo(2000, 0, 0);
            break;
        case IDM_VIEWZOOM400:
            zoomTo(4000, 0, 0);
            break;
        case IDM_VIEWZOOM800:
            zoomTo(8000, 0, 0);
            break;

        case IDM_VIEWFULLSCREEN:
            fullscreenWindow.ShowWindow(SW_SHOW);
            ShowWindow(SW_HIDE);
            break;
    }
    return 0;
}