Exemplo n.º 1
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()));
    }
}
Exemplo n.º 2
0
void Keyswitch::mousePressEvent(QMouseEvent *event)
{
	if (xkbConf->status==DONT_USE_XKB ||xkbConf->status==ONLY_INDICATION)
		return;
	if (event->button() == Qt::LeftButton) {
		setNextGroupe();
	}
	if (event->button() == Qt::RightButton) {
		QPoint p = mapToGlobal(QPoint(0, 0));
		QSize s(contextMenu->sizeHint());
		p.setY(p.y()-s.height());
		contextMenu->exec(p);
	}

}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
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;
  }
}
Exemplo n.º 6
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();
    }
}
Exemplo n.º 7
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();
}
Exemplo n.º 8
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);
}
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();
}
Exemplo n.º 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();
}
Exemplo n.º 11
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);
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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()));
}
Exemplo n.º 14
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();
}
Exemplo n.º 15
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;
    }
}
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);
}
Exemplo n.º 17
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);
}
Exemplo n.º 18
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));
    }
}
Exemplo n.º 19
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();
}
Exemplo n.º 20
0
void RegisteredUsersDialogItemDelegate::paint(QPainter * p, const QStyleOptionViewItem & option, const QModelIndex & index) const
{

	RegisteredUsersDialogItemBase * item = static_cast<RegisteredUsersDialogItemBase *>(index.internalPointer());

	if(item->type() == RegisteredUsersDialogItemBase::Group)
	{
		//groups
		QStyledItemDelegate::paint(p, option, index);
	}
	else
	{
		QStyleOptionViewItem opt = option;
		initStyleOption(&opt, index);

		if(opt.state & QStyle::State_Selected)
			QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, p);

		RegisteredUsersDialogItem * it = (RegisteredUsersDialogItem *)item;

		if(index.column() == 0)
		{
			QPoint pt = opt.rect.topLeft();
			pt.setX(pt.x() + LVI_BORDER);
			pt.setY(pt.y() + LVI_BORDER);

			p->drawPixmap(pt, *(g_pIconManager->getBigIcon(KVI_BIGICON_REGUSERS)));
			QRect cliprect = QRect(QPoint(0, 0), QSize(opt.rect.width() - (LVI_ICON_SIZE + LVI_SPACING + LVI_BORDER), opt.rect.height()));
			p->save();

			p->translate(opt.rect.x() + LVI_ICON_SIZE + LVI_SPACING, opt.rect.y());
			it->m_pText.drawContents(p, cliprect);
			p->restore();
		}
		else
		{
			if(it->user())
			{
				if(!it->user()->getProperty("notify").isEmpty())
					p->drawPixmap(opt.rect.topLeft().x() + LVI_BORDER, opt.rect.topLeft().y() + LVI_BORDER, *(g_pIconManager->getSmallIcon(KviIconManager::NotifyOnLine)));
				else
					p->drawPixmap(opt.rect.topLeft().x() + LVI_BORDER, opt.rect.topLeft().y() + LVI_BORDER, *(g_pIconManager->getSmallIcon(KviIconManager::NotifyOffLine)));
				if(it->user()->ignoreEnabled())
					p->drawPixmap(opt.rect.topLeft().x() + LVI_BORDER, opt.rect.topLeft().y() + 2 * LVI_BORDER + 16, *(g_pIconManager->getSmallIcon(KviIconManager::Ignore)));
			}
		}
	}
}
Exemplo n.º 21
0
void TerrainBrush::updateBrush(QPoint cursorPos, const QVector<QPoint> *list)
{
    // get the current tile layer
    TileLayer *currentLayer = currentTileLayer();
    Q_ASSERT(currentLayer);

    int layerWidth = currentLayer->width();
    int layerHeight = currentLayer->height();
    int numTiles = layerWidth * layerHeight;
    int paintCorner = 0;

    // if we are in vertex paint mode, the bottom right corner on the map will appear as an invalid tile offset...
    if (mBrushMode == PaintVertex) {
        if (cursorPos.x() == layerWidth) {
            cursorPos.setX(cursorPos.x() - 1);
            paintCorner |= 1;
        }
        if (cursorPos.y() == layerHeight) {
            cursorPos.setY(cursorPos.y() - 1);
            paintCorner |= 2;
        }
    }

    // if the cursor is outside of the map, bail out
    if (!currentLayer->bounds().contains(cursorPos))
        return;

    // TODO: this seems like a problem... there's nothing to say that 2 adjacent tiles are from the same tileset, or have any relation to eachother...
    Tileset *terrainTileset = mTerrain ? mTerrain->tileset() : NULL;

    // allocate a buffer to build the terrain tilemap (TODO: this could be retained per layer to save regular allocation)
    Tile **newTerrain = new Tile*[numTiles];

    // allocate a buffer of flags for each tile that may be considered (TODO: this could be retained per layer to save regular allocation)
    char *checked = new char[numTiles];
    memset(checked, 0, numTiles);

    // create a consideration list, and push the start points
    QList<QPoint> transitionList;
    int initialTiles = 0;

    if (list) {
        // if we were supplied a list of start points
        foreach (const QPoint &p, *list) {
            transitionList.push_back(p);
            ++initialTiles;
        }
    } else {
void SpectralMeterView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	Q_UNUSED(option);
	Q_UNUSED(widget);

        // re-draw the background pixmap
        if (bgPixmap.width() != int(m_boundingRect.width()) || bgPixmap.height() != int(m_boundingRect.height())) {
                update_background();
        }

	
	painter->drawPixmap(0, 0, bgPixmap);

	// draw the bars
	if (m_spectrum.size()) {
		QRect rect;
		painter->setClipRegion(m_rect);
		painter->setBrush(m_brushFg);
		painter->setPen(Qt::NoPen);

		int spc = 0;
		if (num_bands < 64) spc = 1;

		// draw the freq bands
		for (uint i = 0; i < (uint)m_spectrum.size(); ++i) {
			if (m_bands.at(i+1) < lower_db) {
				continue;
			}

			rect.setTopLeft(QPoint((int)freq2xpos(m_bands.at(i)) + spc, (int)db2ypos(m_spectrum.at(i))));
			rect.setBottomRight(QPoint((int)freq2xpos(m_bands.at(i+1)) - spc, (int)db2ypos(DB_FLOOR)));
			painter->drawRect(rect);
		}

		// draw the average line if requested
		if (show_average) {
			painter->setPen(m_penAvgCurve);
			QPoint pt;
			QPoint po((int)m_map_idx2xpos.at(0), (int)db2ypos(m_avg_db.at(0)));
			for (uint i = 0; i < (uint)m_avg_db.size(); ++i) {
				pt.setX((int)m_map_idx2xpos.at(i));
				pt.setY((int)db2ypos(m_avg_db.at(i)));
				painter->drawLine(po, pt);
				po = pt;
			}
		}
	}
}
Exemplo n.º 23
0
void KMapScene::updateTargetCoordinates() {
	if(targetRing == -1){
		return;	
	}
	QPoint toP;
	QPoint ball ( cellCenterX[targetRing][targetCell] , cellCenterY[targetRing][targetCell] );
	
	targetBall->setRect(ball.x() - 5, ball.y() - 5, 10, 10);
	//targetBall->setRect(toGrid(0) - 5, toGrid(1) - 5, 10, 10);
	float angle = targetOrient;
	int newX = -KMath::toCartesianY ( 10, angle );
	int newY = -KMath::toCartesianX ( 10, angle );
	toP.setX ( ball.x() + newX);
	toP.setY (ball.y() + newY );
	targetLine->setLine (ball.x(), ball.y(), toP.x(), toP.y() );
}
Exemplo n.º 24
0
bool
PolygonElement::processChildNode(QDomElement& e)
{
    QString tag = e.tagName();

    if (tag == "point") {
	QPoint point;
	point.setX(getInt(e, "x", 0));
	point.setY(getInt(e, "y", 0));
	points.push_back(point);
    } else {
	return ReportElement::processChildNode(e);
    }

    return true;
}
Exemplo n.º 25
0
QList<QPoint> PathCorrector::correctPath(QList<QPoint> const &path)
{
	QList<QPoint> newPath;
	if (path.isEmpty())
		return newPath;
	QPoint previousPoint = path[0];
	for (int i = 1; i < path.size(); i++) {
		QPoint currentPoint = path[i];
		qreal speed = (currentPoint - previousPoint).manhattanLength();
		qreal b = sense * (1 - 1 / exp(speedKoef * speed));
		previousPoint.setX((int) (b * currentPoint.x() + (1 - b) * previousPoint.x()));
		previousPoint.setY((int) (b * currentPoint.y() + (1 - b) * previousPoint.y()));
		newPath.push_back(previousPoint);
	}
	return newPath;
}
Exemplo n.º 26
0
void LocationBar::contextMenuEvent(QContextMenuEvent* event)
{
    if (!m_pasteAndGoAction) {
        m_pasteAndGoAction = new QAction(QIcon::fromTheme("edit-paste"), tr("Paste And &Go"), this);
        m_pasteAndGoAction->setShortcut(QKeySequence("Ctrl+Shift+V"));
        connect(m_pasteAndGoAction, SIGNAL(triggered()), this, SLOT(pasteAndGo()));
    }

    QMenu* menu = createContextMenu(m_pasteAndGoAction);
    menu->setAttribute(Qt::WA_DeleteOnClose);

    // Prevent choosing first option with double rightclick
    QPoint pos = event->globalPos();
    pos.setY(pos.y() + 1);
    menu->popup(pos);
}
Exemplo n.º 27
0
QPoint LayoutSquare::calculateCenterPnt( QSize fromSize, QSize itemSize ) const
{
	QPoint centerPoint;

	if ( ( fromSize.width() - fromSize.width() / 2.0 - itemSize.width() / 2.0 ) > 0.0 )
	{
		centerPoint.setX( fromSize.width() - fromSize.width() / 2.0 - itemSize.width() / 2.0 );
	}

	if ( ( fromSize.height() - fromSize.height() / 2.0 - itemSize.height() / 2.0 ) > 0.0 )
	{
		centerPoint.setY( fromSize.height() - fromSize.height() / 2.0 - itemSize.height() / 2.0 );
	}

	return centerPoint;
}
Exemplo n.º 28
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;

    QDesktopWidget desktop;
    QRect rect = desktop.availableGeometry(desktop.primaryScreen());
    QPoint center = rect.center();
    center.setX(center.x() - w.width()/2);
    center.setY(center.y() - w.height()/2);

    w.move(center);
    w.show();

    return a.exec();
}
Exemplo n.º 29
0
help::help(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::help)
{
    ui->setupUi(this);

    // Перемещение в центр экрана
    QPoint center = QApplication::desktop()->availableGeometry().center();
    QPoint corner = QApplication::desktop()->availableGeometry().topLeft();
    center.setX(center.x() - this->width() / 2);
    center.setY(center.y() - this->height() / 2);
    if(center.x() <= corner.x() || center.y() <= corner.y())
        this->move(corner);
    else
        this->move(center);
}
Exemplo n.º 30
0
void FastMenu::onlySecond()
{
    bool foundOk = true;
    KScreen::OutputList outputs = mConfig->outputs();
    for (const KScreen::OutputPtr &output : outputs)
    {
        if( !output->isConnected() )
            continue;
        QPoint pos = output->pos();
        pos.setX(0);
        pos.setY(0);
        output->setPos(pos);
        output->setEnabled(!foundOk);
        foundOk = false;
    }
}