Пример #1
0
void BitcoinGUI::restoreWindowGeometry()
{
    QSettings settings;
    QPoint pos = settings.value("nWindowPos").toPoint();
    QSize size = settings.value("nWindowSize", QSize(850, 550)).toSize();
    if (!pos.x() && !pos.y())
    {
        QRect screen = QApplication::desktop()->screenGeometry();
        pos.setX((screen.width()-size.width())/2);
        pos.setY((screen.height()-size.height())/2);
    }
    resize(size);
    move(pos);
}
Пример #2
0
void RSSDetectionWidget::showAt(QWidget* parent)
{
  // Calculate sizes before showing
  layout()->invalidate();
  layout()->activate();

  QPoint p = parent->mapToGlobal(QPoint(0, 0));

  p.setX(p.x() + parent->width() - width());
  p.setY(p.y() + parent->height());
  move(p);

  QFrame::show();
}
Пример #3
0
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());
    }
}
void make_image_inserts::on_actionInsert_images_into_template_triggered() {
    QList<geom_angle *>::iterator insert_iter;
    geom_angle *this_insert;
    QImage tmp_img = template_image;
    QImage result(tmp_img.width(), tmp_img.height(), QImage::Format_ARGB32_Premultiplied);
    QPainter pt(&result);
    pt.drawImage(QPoint(0,0), tmp_img);
    pt.setBackgroundMode(Qt::TransparentMode);
    bool error = false;

    for (insert_iter = insert_geoms.begin(); insert_iter != insert_geoms.end(); ++insert_iter) {
        this_insert = *insert_iter;
        QList<QListWidgetItem *> current_selections(ui->listWidget->selectedItems());
        if (current_selections.isEmpty()) {
            QMessageBox select_an_insert;
            select_an_insert.setText("Please select an image to insert");
            select_an_insert.exec();
            error = true;
            break;
        } else {
            QListWidgetItem *current_item;
            double rotation = this_insert->rotation_degrees;
            QMatrix rm;
            rm.rotate(rotation);
            QPoint where;
            current_item = *current_selections.begin();
            QImage insert = insert_images[current_item->data(Qt::UserRole).toUInt()].transformed(rm, Qt::SmoothTransformation);
            QImage scaled_insert(this_insert->geom_size, QImage::Format_ARGB32_Premultiplied);

            scaled_insert.fill(qRgba(0,0,0,0));
            scaled_insert = insert.scaled(this_insert->geom_size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
            int inset_img_width = scaled_insert.width();
            int inset_img_height = scaled_insert.height();
            int geom_width = this_insert->geom_size.width();
            int geom_height = this_insert->geom_size.height();
            int center_x_offset = geom_width/2 - inset_img_width/2;
            int center_y_offset = geom_height/2 - inset_img_height/2;
            where = this_insert->geom_where;
            where.setX(where.x() + center_x_offset);
            where.setY(where.y() + center_y_offset);
            pt.drawImage(where, scaled_insert);
        } /* endif */
    } /* endfor */
    if (!error) {
        template_item->setPixmap(QPixmap::fromImage(result));
        copy_text_keys(result, template_image);
        result_image = result;
    } /* endif */
}
Пример #5
0
void Window::createCurveIcons()
{
    static const char* names[]= {
        "Linear",
        "InQuad", "OutQuad", "InOutQuad", "OutInQuad",
        "InCubic", "OutCubic", "InOutCubic", "OutInCubic",
        "InQuart", "OutQuart", "InOutQuart", "OutInQuart",
        "InQuint", "OutQuint", "InOutQuint", "OutInQuint",
        "InSine", "OutSine", "InOutSine", "OutInSine",
        "InExpo", "OutExpo", "InOutExpo", "OutInExpo",
        "InCirc", "OutCirc", "InOutCirc", "OutInCirc",
        "InElastic", "OutElastic", "InOutElastic", "OutInElastic",
        "InBack", "OutBack", "InOutBack", "OutInBack",
        "InBounce", "OutBounce", "InOutBounce", "OutInBounce",
        "InCurve", "OutCurve", "SineCurve", "CosineCurve"
        };

    QPixmap pix(m_iconSize);
    QPainter painter(&pix);
    QLinearGradient gradient(0,0, 0, m_iconSize.height());
    gradient.setColorAt(0.0, QColor(240, 240, 240));
    gradient.setColorAt(1.0, QColor(224, 224, 224));
    QBrush brush(gradient);
    for (int i = QtEasingCurve::Linear; i <= QtEasingCurve::CosineCurve; ++i) {
        painter.fillRect(QRect(QPoint(0, 0), m_iconSize), brush);
        QtEasingCurve curve((QtEasingCurve::Type)i);
        painter.setPen(QColor(0, 0, 255, 64));
        qreal xAxis = m_iconSize.height()/1.5;
        qreal yAxis = m_iconSize.width()/3;
        painter.drawLine(0, xAxis, m_iconSize.width(),  xAxis);
        painter.drawLine(yAxis, 0, yAxis, m_iconSize.height());
        painter.setPen(Qt::black);
        
        qreal curveScale = m_iconSize.height()/2;
        QPoint currentPos(yAxis, xAxis);
        
        for (qreal t = 0; t < 1.0; t+=1.0/curveScale) {
            QPoint to;
            to.setX(yAxis + curveScale * t);
            to.setY(xAxis - curveScale * curve.valueForStep(t));
            painter.drawLine(currentPos, to);
            currentPos = to;
        }
        QListWidgetItem *item = new QListWidgetItem();
        item->setIcon(QIcon(pix));
        item->setText(QLatin1String(names[i]));
        m_listWidget->addItem(item);
    }
}
Пример #6
0
void KBinaryClock::toggleCalendar()
{
	if (_calendar && !_disableCalendar) {
		// calls slotCalendarDeleted which does the cleanup for us
		_calendar->close();
		return;
	}
	if (_calendar || _disableCalendar){
		return;
	}
	_calendar = new DatePicker(this, QDateTime::currentDateTime().date());
	connect( _calendar, SIGNAL( destroyed() ), SLOT( slotCalendarDeleted() ));

	// some extra spacing is included if aligned on a desktop edge
	QPoint c = mapToGlobal(QPoint(0,0));

	int w = _calendar->sizeHint().width() + 28;
															// Added 28 px. to size poperly as said in API
	int h = _calendar->sizeHint().height();

	switch (position()) {
	case KPanelApplet::pLeft:	c.setX(c.x()+width()+2);	break;
	case KPanelApplet::pRight:	c.setX(c.x()-w-2);		break;
	case KPanelApplet::pTop:	c.setY(c.y()+height()+2);	break;
	case KPanelApplet::pBottom:	c.setY(c.y()-h-2);		break;
		}

		// make calendar fully visible
		QRect deskR = KGlobalSettings::desktopGeometry(QPoint(0,0));

		if (c.y()+h > deskR.bottom())	c.setY(deskR.bottom()-h-1);
		if (c.x()+w > deskR.right())				c.setX(deskR.right()-w-1);

		_calendar->move(c);
		_calendar->show();
}
Пример #7
0
QRect KstTopLevelView::newSize(const QRect& originalSize, const QRect& bounds, int direction, const QPoint& pos, bool maintainAspect) {
  QRect newSize;

  QPoint anchor_pt, move_pt;
  QPoint npos = pos;

  anchor_pt = move_pt = originalSize.center();

  npos.setX(QMAX(npos.x(), bounds.left()));
  npos.setX(QMIN(npos.x(), bounds.right()));
  npos.setY(QMIN(npos.y(), bounds.bottom()));
  npos.setY(QMAX(npos.y(), bounds.top()));

  if ((direction & UP) != 0) {
    move_pt.setY(originalSize.top());
    anchor_pt.setY(originalSize.bottom());
  } else if ((direction & DOWN) != 0) {
    move_pt.setY(originalSize.bottom());
    anchor_pt.setY(originalSize.top());
  }

  if ((direction & LEFT) != 0) {
    move_pt.setX(originalSize.left());
    anchor_pt.setX(originalSize.right());
  } else if ((direction & RIGHT) != 0) {
    move_pt.setX(originalSize.right());
    anchor_pt.setX(originalSize.left());
  }

  if ( ((direction & (UP|DOWN)) == 0) || ((direction & (LEFT|RIGHT)) == 0) ) { //resizing from edge.
    return KstGfxMouseHandlerUtils::resizeRectFromEdge(originalSize, anchor_pt, move_pt, npos, bounds, maintainAspect);
  } else { //resizing from corner.
    return KstGfxMouseHandlerUtils::resizeRectFromCorner(anchor_pt, move_pt, npos, bounds,maintainAspect);
  }

}
Пример #8
0
void Splash::append(const QString & msg) {

    QRegExp re("\\[([NS]?)([EO]?)\\](.*)");
    if(re.exactMatch(msg)) {
        m_timer->stop();
        m_label->setText(re.cap(3).replace(QRegExp("&gt "),">").replace(QRegExp("&lt "),"<").replace(QRegExp("&amp "),"&"));
        m_label->adjustSize();
        resize(m_label->size());

        QRect scr = QApplication::desktop()->screenGeometry(QCursor::pos());

        QPoint pt = scr.center();

        if(re.cap(1) == "S") {
            pt.setY(scr.height() - rect().height());
        } else if(re.cap(1) == "N") {
            pt.setY(0);
        } else {
            pt.setY(pt.y() - rect().height()/2);
        }

        if(re.cap(2) == "E") {
            pt.setX(scr.width() - rect().width());
        } else if(re.cap(2) == "O") {
            pt.setX(0);
        } else {
            pt.setX(pt.x() - rect().width()/2);
        }

        move(pt);
        show();
        repaint();

        m_timer->start(time,true);
    }
}
Пример #9
0
void VCWidget::move(QPoint p)
{
	// Grid settings
	if (_app->virtualConsole()->isGridEnabled())
	{
		p.setX(p.x() - (p.x() % _app->virtualConsole()->gridX()));
		p.setY(p.y() - (p.y() % _app->virtualConsole()->gridY()));
	}

	// Don't move beyond left or right
	if (p.x() < 0)
		p.setX(0);
	else if (p.x() + rect().width() > parentWidget()->width())
		p.setX(parentWidget()->width() - rect().width());

	// Don't move beyond top or bottom
	if (p.y() < 0)
		p.setY(0);
	else if (p.y() + rect().height() > parentWidget()->height())
		p.setY(parentWidget()->height() - rect().height());

	// Do the move
	QFrame::move(p);
}
Пример #10
0
void CGLWidget::wheelEvent(QWheelEvent *event)
{
	QPoint point = event->pos();

	int y = (-(cy + 0.0f) / (cy- 1.0f) * (point.y() + 0.0f) + (cy + 0.0f) / 2.0f);
	int x = ((cx + 0.0f) / (cx- 1.0f) * (point.x() + 0.0f) - (cx + 0.0f) / 2.0f);
	point.setY(y);
	point.setX(x);

	int delta = event->delta();

	INPUTMGR->OnMouseWheel( delta, point);

	updateGL();
}
Пример #11
0
void BalloonTip::move(QPoint pos)
{
    QWidget::move(pos);
    switch (my_arrowPos) {
    case BottomLeft:
        pos.setY(pos.y() - my_popupRect.height() - 60);
        break;
    case TopLeft:
        pos.setX(pos.x() - 30);
        break;
    case BottomRight:
        pos.setY(pos.y() - my_popupRect.height() - 60);
        break;
    case TopRight:
        pos.setX(pos.x() - my_popupRect.width() + 30);
        break;
    case LeftTop:
        pos.setX(pos.x() + 10);
        pos.setY(pos.y() - int(my_popupRect.height() * 0.63));
        break;
    }
    QWidget::move(pos);
    update();
}
Пример #12
0
/**
*Converts OpenGL Viewport coordinates to client coordinates
*@param x the viewport x-coordinate.
*@param y the viewport y-coordinate.
*@param point the client coordinates.
*/
void ThreeDWidget::GLToClient(double const &x, double const &y, QPoint &point)
{
    //
    //converts an opengl 2D vector to screen client coordinates
    //
    static double dx, dy, h2, w2;

    h2 = m_GLViewRect.height() /2.0;
    w2 = m_GLViewRect.width()  /2.0;

    dx = ( x + w2)/2.0;
    dy = (-y + h2)/2.0;

    if(w2>h2)
    {
        point.setX((int)(dx * (double)geometry().width()));
        point.setY((int)(dy * (double)geometry().width()));
    }
    else
    {
        point.setX((int)(dx * (double)geometry().height()));
        point.setY((int)(dy * (double)geometry().height()));
    }
}
Пример #13
0
QPolygon ControlRuler::mapItemToWidget(QPolygonF *poly)
{
//    double xscale = width() / m_pannedRect.width();
//    double yscale = height();

    QPolygon newpoly;
    QPoint newpoint;
    for (QPolygonF::iterator it = poly->begin(); it != poly->end(); ++it) {
        newpoint.setX(mapXToWidget((*it).x()));
        newpoint.setY(mapYToWidget((*it).y()));
        newpoly.push_back(newpoint);
    }

    return newpoly;
}
Пример #14
0
/**
 * Takes a string with komma seperated integer values.
 * These values are put into a QPoint object.
 * @param input     A string with to integer values komma seperated.
 * @return          A QPoint object containing these values. Or (-1,-1) if string was invalid.
 */
QPoint Battleships::getPointObject(const QString input)
{
    QStringList value = input.split(',');
    if (value.size() < 2) {
        return QPoint(-1, -1);
    }
    QPoint point;
    bool ok;
    int x = value[0].toInt(&ok);
    point.setX( (ok) ? x : -1 ) ;
    int y = value[1].toInt(&ok);
    point.setY( (ok) ? y : -1 );

    return point;
}
Пример #15
0
QPoint RotationDaemon::getOrientationInformation()
{
    QPoint p;

    // rewind
    m_accelerometer.seek(0);

    QByteArray bytes = m_accelerometer.readAll();
    QList<QByteArray> tokens = bytes.split(' ');

    p.setX(tokens[0].toInt());
    p.setY(tokens[1].toInt());

    return p;
}
void ImageCanvasWidget::mouseMoveEvent(QMouseEvent *event) {
  QPoint pos = event->pos();
  if (!rect().contains(event->pos())) {
    pos.setX(qMin(rect().right() - 1, qMax(rect().left(), pos.x())));
    pos.setY(qMin(rect().bottom() - 1, qMax(rect().top(), pos.y())));
  }

  QRect current_cursor = options_cache_->PosToGrid(pos);
  if (anchor_down_) {
    options_cache_->set_tile_selection(current_cursor.united(anchor_));
  } else {
    options_cache_->MoveSelection(current_cursor.center());
  }
  update();
}
Пример #17
0
bool lineIntersect(
  qreal a1, qreal b1, qreal c1,
  qreal a2, qreal b2, qreal c2,
  QPoint &intersect)
{
  qreal det = a1*b2 - a2*b1;
  if (fabs(det) < 1e-6) {
    return false;
  } else {
    qreal dinv = 1.0/det;
    intersect.setX((b1*c2 - b2*c1)*dinv);
    intersect.setY((a2*c1 - a1*c2)*dinv);
    return true;
  }
}
void JulyButtonMenu::displayMenuClicked()
{
    resize(minimumSizeHint());
    QPoint pointToShow;
    if(widgetUnderButton==0)pointToShow=QCursor::pos();
    else
    {
    if(position==Left)
        pointToShow=parentButton->geometry().bottomLeft();
    else
    {
        pointToShow=parentButton->geometry().bottomRight();
        pointToShow.setX(pointToShow.x()-this->width());
    }

    pointToShow=widgetUnderButton->mapToGlobal(pointToShow);
    exec(pointToShow);return;
    if(pointToShow.x()<parentWindow->geometry().x())pointToShow.setX(parentWindow->geometry().x());
    if(pointToShow.y()<parentWindow->geometry().y())pointToShow.setY(parentWindow->geometry().y());
    if(pointToShow.x()>parentWindow->geometry().right()-this->width())pointToShow.setX(parentWindow->geometry().right()-this->width());
    if(pointToShow.y()>parentWindow->geometry().bottom()-this->height())pointToShow.setY(parentWindow->geometry().bottom()-this->height());
    }
    exec(pointToShow);
}
Пример #19
0
void MyQComboBox::showPopup()
{
    QRect desk = popupGeometry(QApplication::desktop()->screenNumber(this));
    QPoint popupPoint = mapToGlobal(QPoint(0, 0));
    const int dateFrameHeight = _menu->sizeHint().height();
    if (popupPoint.y() + height() + dateFrameHeight > desk.bottom()) {
        popupPoint.setY(popupPoint.y() - dateFrameHeight);
     } else {
      popupPoint.setY(popupPoint.y() + height());
      }

     const int dateFrameWidth = _menu->sizeHint().width();
      if (popupPoint.x() + dateFrameWidth > desk.right()) {
        popupPoint.setX(desk.right() - dateFrameWidth);
      }

      if (popupPoint.x() < desk.left()) {
        popupPoint.setX(desk.left());
        }
      if (popupPoint.y() < desk.top()) {
        popupPoint.setY(desk.top());
        }
    _menu->popup(popupPoint);
}
Пример #20
0
void ContextMenu::popup(const QPoint &p) {
	QPoint w = p - QPoint(st::dropdownPadding.left(), st::dropdownPadding.top());
	QRect r = QDesktopWidget().screenGeometry(p);
	if (w.x() + width() - st::dropdownPadding.right() > r.x() + r.width()) {
		w.setX(r.x() + r.width() - width() + st::dropdownPadding.right());
	}
	if (w.y() + height() - st::dropdownPadding.bottom() > r.y() + r.height()) {
		w.setY(p.y() - height() + st::dropdownPadding.bottom());
	}
	if (w.y() < r.y()) {
		w.setY(r.y());
	}
	move(w);
	showStart();
}
Пример #21
0
void ProfilePictureWindow::mouseMoveEvent(QMouseEvent *event)
{
    if (origin != QPoint(-1,-1))
    {

        QPoint newPos = rubberBand->pos() + (event->globalPos() - origin);

        if (newPos.x() < screenPhotoRect.left())
            newPos.setX(screenPhotoRect.left());

        if (newPos.y() < screenPhotoRect.top())
            newPos.setY(screenPhotoRect.top());

        if (newPos.x() + rubberBandRect.width() > screenPhotoRect.right())
            newPos.setX(screenPhotoRect.right() - rubberBandRect.width());

        if (newPos.y() + rubberBandRect.height() > screenPhotoRect.bottom())
            newPos.setY(screenPhotoRect.bottom() - rubberBandRect.height());

        rubberBandRect.moveTo(newPos);
        rubberBand->setGeometry(rubberBandRect);
        origin = event->globalPos();
    }
}
Пример #22
0
void BarFrame::mouseMoveEvent(QMouseEvent *event)
{
	if (!moving) return;
	QPoint dpos = event->pos() - mousePos;
	QWidget* p = dynamic_cast<QWidget*>(QFrame::parent());
	QPoint targetPos = p->pos() + dpos;
	
	// Prevent the title bar from being dragged to an unreachable position.
	StelMainWindow& mainWindow = StelMainWindow::getInstance();
	int leftBoundX = 10 - width();
	int rightBoundX = mainWindow.width() - 10;
	if (targetPos.x() < leftBoundX)
		targetPos.setX(leftBoundX);
	else if (targetPos.x() > rightBoundX)
		targetPos.setX(rightBoundX);
	
	int lowerBoundY = mainWindow.height() - height();
	if (targetPos.y() < 0)
		targetPos.setY(0);
	else if (targetPos.y() > lowerBoundY)
		targetPos.setY(lowerBoundY);
	
	p->move(targetPos);
}
Пример #23
0
void UTableRecycleBin::showContextMenu(QPoint p)
{
    if(visibleContextMenu)
    {
        QMenu menu(this);
        menu.addAction(actionDeleteItem);
        menu.addAction(actionRestoreItem);

        p.setX(p.x() + 18);
        p.setY(p.y() + 22);
        menu.exec(this->mapToGlobal(p));

        visibleContextMenu = false;
    }
}
Пример #24
0
void QWindowsContext::handleContextMenuEvent(QWindow *window, const MSG &msg)
{
    bool mouseTriggered = false;
    QPoint globalPos;
    QPoint pos;
    if (msg.lParam != (int)0xffffffff) {
        mouseTriggered = true;
        globalPos.setX(msg.pt.x);
        globalPos.setY(msg.pt.y);
        pos = QWindowsGeometryHint::mapFromGlobal(msg.hwnd, globalPos);
    }

    QWindowSystemInterface::handleContextMenuEvent(window, mouseTriggered, pos, globalPos,
                                                   QWindowsKeyMapper::queryKeyboardModifiers());
}
Пример #25
0
void Smb4KToolTip::show(const QPoint &pos)
{
  // Get the geometry of the screen where the cursor is
  const QRect screenRect = QApplication::desktop()->screenGeometry(pos);
  
  // Adjust the size
  adjustSize();

  // The position where the tooltip is to be shown
  QPoint tooltipPos;  
  
  // Correct the position of the tooltip, so that it is completely 
  // shown.
  if (pos.x() + width() + 5 >= screenRect.x() + screenRect.width())
  {
    tooltipPos.setX(pos.x() - width() - 5);
  }
  else
  {
    tooltipPos.setX(pos.x() + 5);
  }
  
  if (pos.y() + height() + 5 >= screenRect.y() + screenRect.height())
  {
    tooltipPos.setY(pos.y() - height() - 5);
  }
  else
  {
    tooltipPos.setY(pos.y() + 5);
  }

  move(tooltipPos);
  setVisible(true);
  
  QTimer::singleShot(10000, this, SLOT(slotHideToolTip()));
}
Пример #26
0
void widget::on_toolButton_open_clicked()
{
 //   setExistingDirectory();
    QPoint pos = this->pos();
    QPoint btnPos = ui->toolButton_open->pos();
    pos += btnPos;

    QPoint movPos;
    movPos.setX(0);
    movPos.setY(ui->toolButton_open->height()-10);
    pos += movPos;

    openFileMenu->popup(pos);

}
Пример #27
0
void CannonField::mouseMoveEvent(QMouseEvent *event)
{
	if (!barrelPressed)
		return;

	QPoint pos = event->pos();
	
	if (pos.x() <= 0)
		pos.setX(1);
	if (pos.y() >= height())
		pos.setY(height() - 1);

	double rad = atan(((double)rect().bottom() - pos.y()) / pos.x());
	setAngle(qRound(rad * 180 / 3.14159265));
}
Пример #28
0
void restoreWindowGeometry(const QString& strSetting, const QSize& defaultSize, QWidget *parent)
{
    QSettings settings;
    QPoint pos = settings.value(strSetting + "Pos").toPoint();
    QSize size = settings.value(strSetting + "Size", defaultSize).toSize();

    if (!pos.x() && !pos.y()) {
        QRect screen = QApplication::desktop()->screenGeometry();
        pos.setX((screen.width() - size.width()) / 2);
        pos.setY((screen.height() - size.height()) / 2);
    }

    parent->resize(size);
    parent->move(pos);
}
Пример #29
0
void OrthographicWidget::mouseMoveEvent(QMouseEvent *event) {
    int convertedY = height()-event->y();

    QVector2D delta(last_click_pos.x()-event->x(),
                    last_click_pos.y()-convertedY);

    QVector2D cpoly_world = mousePressToWorld(create_polytope_pos);
    QVector2D cpoly_world_snapped(i_grid_.RoundToNearestMinor(cpoly_world.x()),
                                  i_grid_.RoundToNearestMinor(cpoly_world.y()));

    QVector2D cur_world = mousePressToWorld(event->pos());
    QVector2D cur_world_snapped(i_grid_.RoundToNearestMinor(cur_world.x()),
                                i_grid_.RoundToNearestMinor(cur_world.y()));

    if (event->buttons() & Qt::LeftButton) {
        switch (ConfigManager::get().input_state()) {
        case InputState::CREATE_POLYTOPE:
            if (ConfigManager::get().snap_to_grid()) {
                if (cur_world_snapped.x() != cpoly_world_snapped.x() &&
                    cur_world_snapped.y() != cpoly_world_snapped.y()) {
                    emit BeginCreatePolytope(cpoly_world_snapped,
                                             cur_world_snapped);
                    ConfigManager::get().set_input_state(InputState::UPDATE_POLYTOPE);
                }
            } else {

            }
            break;
        case InputState::UPDATE_POLYTOPE:
            if (ConfigManager::get().snap_to_grid()) {
                emit UpdateNewPolytope(cur_world_snapped);
            } else {

            }
            break;
        default:
            break;
        }
    }

    if (event->buttons() & Qt::MiddleButton) {
        i_grid_.Translate(delta);
    }

    last_click_pos.setX(event->x());
    last_click_pos.setY(convertedY);
    QCoreApplication::processEvents();
}
Пример #30
0
/**
 * Override to support zooming in and out using the mouse wheel.
 */
void MapView::wheelEvent(QWheelEvent *event)
{
    auto *hBar = static_cast<FlexibleScrollBar*>(horizontalScrollBar());
    auto *vBar = static_cast<FlexibleScrollBar*>(verticalScrollBar());

    bool wheelZoomsByDefault = Preferences::instance()->wheelZoomsByDefault();
    bool control = event->modifiers() & Qt::ControlModifier;

    if ((wheelZoomsByDefault != control) && event->orientation() == Qt::Vertical) {
        // No automatic anchoring since we'll do it manually
        setTransformationAnchor(QGraphicsView::NoAnchor);

        mZoomable->handleWheelDelta(event->delta());
        adjustCenterFromMousePosition(mLastMousePos);

        // Restore the centering anchor
        setTransformationAnchor(QGraphicsView::AnchorViewCenter);
        return;
    }

    // By default, the scroll area forwards the wheel events to the scroll
    // bars, which apply their bounds. This custom wheel handling is here to
    // override the bounds checking.
    //
    // This also disables QGraphicsSceneWheelEvent, but Tiled does not rely
    // on that event.
    QPoint pixels = event->pixelDelta();

    if (pixels.isNull()) {
        QPointF steps = event->angleDelta() / 8.0 / 15.0;
        int lines = QApplication::wheelScrollLines();
        pixels.setX(int(steps.x() * lines * hBar->singleStep()));
        pixels.setY(int(steps.y() * lines * vBar->singleStep()));
    } else {
        pixels = Utils::dpiScaled(pixels);
    }

    if (!pixels.isNull()) {
        int horizontalValue = hBar->value() + (isRightToLeft() ? pixels.x() : -pixels.x());
        int verticalValue = vBar->value() - pixels.y();
        hBar->forceSetValue(horizontalValue);
        vBar->forceSetValue(verticalValue);

        // When scrolling the mouse does not move, but the view below it does.
        // This affects the mouse scene position, which needs to be updated.
        mLastMouseScenePos = mapToScene(viewport()->mapFromGlobal(mLastMousePos));
    }
}