Exemple #1
1
//TODO - learn about DPI and point sizes and others; now is purely written by trial and error
int Utils::estimateQToolButtonSize() {
    const int MIN_SIZE = 15; //under 15 pixel should be an error
    const int PIXEL_FROM_FONT_SCALE = 2;
    const float POINT_FROM_FONT_SCALE = 3;
    const float SCREEN_RATIO_SCALE = 0.4;
    const int DEFAULT_SIZE = 35;
    QFont font;
    float defaultFontSize = font.pixelSize() * PIXEL_FROM_FONT_SCALE;
    //increasingly desperate computations:
    if (defaultFontSize <= MIN_SIZE) {
        defaultFontSize = font.pointSize() * POINT_FROM_FONT_SCALE;
        printf("%s - warning, trying QFont.pointSize():%f\n", __func__, defaultFontSize);
    }
    if (defaultFontSize <= MIN_SIZE) {
        QScreen* screen = QGuiApplication::primaryScreen();
        float auxFontSize = SCREEN_RATIO_SCALE * screen->geometry().width();
        defaultFontSize = auxFontSize;
        printf("%s - warning, screen geometry:%f\n", __func__, defaultFontSize);
    }
    if (defaultFontSize <= MIN_SIZE) {
        defaultFontSize = DEFAULT_SIZE;
        printf("%s - warning, will assume dumb size:%f\n", __func__, defaultFontSize);
    }

    return defaultFontSize;
}
void ScreenSelector::grabColor()
{
    m_selectionRect = m_selectionRect.normalized();
    QDesktopWidget* desktop = QApplication::desktop();
    int screenNum = desktop->screenNumber(m_selectionRect.topLeft());
    QScreen* screen = QGuiApplication::screens()[screenNum];
    QPixmap screenGrab = screen->grabWindow(desktop->winId(),
        m_selectionRect.x(), m_selectionRect.y(), m_selectionRect.width(), m_selectionRect.height());
    QImage image = screenGrab.toImage();
    int numPixel = image.width() * image.height();
    int sumR = 0;
    int sumG = 0;
    int sumB = 0;

    for (int x = 0; x < image.width(); ++x) {
        for (int y = 0; y < image.height(); ++y) {
            QColor color = image.pixel(x, y);
            sumR += color.red();
            sumG += color.green();
            sumB += color.blue();
        }
    }

    QColor avgColor(sumR / numPixel, sumG / numPixel, sumB / numPixel);
    emit colorPicked(avgColor);
}
Exemple #3
0
/*!
    Destroys the screen.
 */
QScreen::~QScreen()
{
    if (!qApp)
        return;

    // Allow clients to manage windows that are affected by the screen going
    // away, before we fall back to moving them to the primary screen.
    emit qApp->screenRemoved(this);

    if (QGuiApplication::closingDown())
        return;

    QScreen *primaryScreen = QGuiApplication::primaryScreen();
    if (this == primaryScreen)
        return;

    bool movingFromVirtualSibling = primaryScreen && primaryScreen->handle()->virtualSiblings().contains(handle());

    // Move any leftover windows to the primary screen
    const auto allWindows = QGuiApplication::allWindows();
    for (QWindow *window : allWindows) {
        if (!window->isTopLevel() || window->screen() != this)
            continue;

        const bool wasVisible = window->isVisible();
        window->setScreen(primaryScreen);

        // Re-show window if moved from a virtual sibling screen. Otherwise
        // leave it up to the application developer to show the window.
        if (movingFromVirtualSibling)
            window->setVisible(wasVisible);
    }
}
bool ReticleHandler::eventFilter(QObject *, QEvent *event)
{
	static bool show = true;
	switch (event->type()) {
	case QEvent::TouchBegin:
		show = true;
		break;
	case QEvent::TouchUpdate:
		show = false;
		break;
	case QEvent::TouchCancel:
		show = false;
		break;
	case QEvent::TouchEnd:
		{
			if (show) {
				QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
				const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first();
				QPointF fpoint = touchPoint.pos();
				int x = static_cast<int>(fpoint.x());
				int y = static_cast<int>(fpoint.y());

				QScreen *primaryScreen = QGuiApplication::primaryScreen();
				QTransform lOrientationTranform = primaryScreen->transformBetween(primaryScreen->orientation(), primaryScreen->primaryOrientation(), primaryScreen->geometry()).inverted();

				emit reticleEvent(lOrientationTranform.map(QPoint(x,y)));
			};
			show = false;
		}
		break;
	}
	return false;
}
/*!
    Returns the width of the display in pixels.

    \sa screenHeight(), screenDepth()
*/
int QDirectPainter::screenWidth()
{
    QScreen *screen = getPrimaryScreen();
    if (!screen)
        return 0;
    return screen->deviceWidth();
}
KReportDesignerSectionScene::KReportDesignerSectionScene(qreal w, qreal h, KReportDesigner *rd)
        : QGraphicsScene(0, 0, w, h, rd)
{
    m_rd = rd;
    m_minorSteps = 0;

    QScreen *srn = QApplication::screens().at(0);

    m_dpiX = srn->logicalDotsPerInchX();
    m_dpiY = srn->logicalDotsPerInchY();

    if (m_unit.type() != m_rd->pageUnit().type()) {
        m_unit = m_rd->pageUnit();
        if (m_unit.type() == KReportUnit::Cicero ||
            m_unit.type() == KReportUnit::Pica ||
            m_unit.type() == KReportUnit::Millimeter) {
            m_majorX = POINT_TO_INCH(m_unit.fromUserValue(10)) * m_dpiX;
            m_majorY = POINT_TO_INCH(m_unit.fromUserValue(10)) * m_dpiY;
        } else if (m_unit.type() == KReportUnit::Point) {
            m_majorX = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiX;
            m_majorY = POINT_TO_INCH(m_unit.fromUserValue(100)) * m_dpiY;
        } else {
            m_majorX = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiX;
            m_majorY = POINT_TO_INCH(m_unit.fromUserValue(1)) * m_dpiY;
        }
    }
}
QT_BEGIN_NAMESPACE

#ifndef QT_NO_WIDGETS
#define Application QApplication
#else
#define Application QGuiApplication
#endif

int main(int argc, char *argv[])
{
    Application app(argc, argv);
    QScreen* sc = app.primaryScreen();
    if(sc){
        sc->setOrientationUpdateMask(Qt::LandscapeOrientation
                             | Qt::PortraitOrientation
                             | Qt::InvertedLandscapeOrientation
                             | Qt::InvertedPortraitOrientation);
    }
    QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
    QObject *topLevel = engine.rootObjects().value(0);
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    if ( !window ) {
        qWarning("Error: Your root item has to be a Window.");
        return -1;
    }
    window->showFullScreen();
    return app.exec();
}
ResizeAwareQuickWidget::ResizeAwareQuickWidget(QWidget *parent)
    : QQuickWidget(parent),
      theButtonHeight(theButtonHeightPix),
      theButtonIconSize(theButtonIconPix),
      theWorldWidthInMeters(1.0),
      theWorldHeightInMeters(1.0),
      thePixPerMeter(100),
      theGameViewPtr(nullptr)
{
    // Enable objects in the QML world to see our properties.
    rootContext()->setContextProperty(QStringLiteral("ResizeInfo"), this);

    // TODO/FIXME: Does this belong here???
    qmlRegisterType<ViewItem>("TBEView", 1, 0, "ViewItem");
    qmlRegisterType<ViewResizeRotateMoveUndo>("TBEView", 1, 0, "ViewResizeRotateMoveUndo");
    qmlRegisterType<ViewWorldItem>("TBEView", 1, 0, "ViewWorldItem");
    qmlRegisterType<GameQControls>("TBEView", 1, 0, "GameQControls");

    // Pre-calculate the handle sizes, they normally won't change during play...
    QScreen* myQScreenPtr = QApplication::primaryScreen();
    assert (myQScreenPtr != nullptr);
    theHandleHeight = theHandleSizeMM / 25.4 * myQScreenPtr->physicalDotsPerInchX();
    if (theHandleHeight < theHandleMinPix)
        theHandleHeight = theHandleMinPix;
    theHandleWidth = theHandleSizeMM / 25.4 * myQScreenPtr->physicalDotsPerInchY();
    if (theHandleWidth < theHandleMinPix)
        theHandleWidth = theHandleMinPix;
}
Exemple #9
0
UIWindow::UIWindow(QWindow *window) :
	QPlatformWindow(window),
	position_includes_frame(false),
	visible(false),
	pending_geometry_change_on_show(true),
	z_level(0.0),
	opacity_level(1.0)
{
	PROFILE_FUNCTION

	QRect geom(window->geometry());
	QScreen *screen = window->screen();
	QRect screenGeom(screen->availableGeometry());
	int x = screenGeom.x() + screenGeom.width()/2. - geom.width()/2.;
	int y = screenGeom.y() + screenGeom.height()/2. - geom.height()/2.;
	geom.setX(x);
	geom.setY(y);
	
	setGeometry(geom);
	setWindowFlags(window->flags());
	setWindowState(window->windowState());

	QWindowSystemInterface::flushWindowSystemEvents();

	static WId counter = 0;
	win_id = ++counter;

	raise();
	mIsDecorationUpdateNeeded = true;
	checkDecorations();
}
static inline QSize devS()
{
    QScreen *screen = getPrimaryScreen();
    if (!screen)
        return QSize();
    return QSize(screen->deviceWidth(), screen->deviceHeight());
}
Exemple #11
0
DBThread::DBThread()
 : database(new osmscout::Database(databaseParameter)),
/*
DBThread::DBThread(const SettingsRef& settings)
 : settings(settings),
   painter(NULL),
   database(new osmscout::Database(databaseParameter)),
*/
   locationService(new osmscout::LocationService(database)),
   mapService(new osmscout::MapService(database)),
   painter(NULL),
   iconDirectory(),
   currentImage(NULL),
   currentLat(0.0),
   currentLon(0.0),
   currentAngle(0.0),
   currentMagnification(0),
   finishedImage(NULL),
   finishedLat(0.0),
   finishedLon(0.0),
   finishedMagnification(0),
   currentRenderRequest(),
   doRender(false),
   renderBreaker(new QBreaker()),
   renderBreakerRef(renderBreaker)
{
    QScreen *srn = QApplication::screens().at(0);

    dpi = (double)srn->physicalDotsPerInch();
}
static inline QSize screenS()
{
    QScreen *screen = getPrimaryScreen();
    if (!screen)
        return QSize();
    return QSize(screen->width(), screen->height());
}
Exemple #13
0
qreal Theme::GetDPI() const
{
    QScreen *srn = QApplication::screens().at(0);
    qreal dotsPerInch = (qreal)srn->physicalDotsPerInch();

    return dotsPerInch;
}
WormEngine::WormEngine(QObject *parent) :
    QObject(parent)
{
    QScreen* screen = QGuiApplication::primaryScreen();
    m_pagewidth = screen->size().width();
    m_pageheight = screen->size().height();

    m_isPaused = true;
    m_gameOver = false;
    m_finish = false;
    m_theend = false;
    m_pauseMenu = false;
    bodyr = m_pagewidth/13.5;

    for (int i = 0; i < 6; i++) {
        WormBody *wormBody = new WormBody((m_pagewidth/3.375)+i*(m_pagewidth/10.8), m_pageheight/2.4);
        m_wormBody.append(wormBody);
    }

    m_updater.setInterval(50);
    connect(&m_updater, SIGNAL(timeout()), this, SLOT(update()));
    m_updater.start();
    lowPx = m_pagewidth/20;
    highPx = m_pagewidth/1.04;
    lowPy = m_pageheight/48;
    highPy = m_pageheight/1.3;
    m_apples = 0;
    distCounter = 0;
    newFoodPos();
}
Exemple #15
0
int QWidget::metric(PaintDeviceMetric m) const
{
    Q_D(const QWidget);

    int val;
    if (m == PdmWidth) {
        val = data->crect.width();
    } else if (m == PdmWidthMM) {
        const QScreen *screen = d->getScreen();
        val = data->crect.width() * screen->physicalWidth() / screen->width();
    } else if (m == PdmHeight) {
        val = data->crect.height();
    } else if (m == PdmHeightMM) {
        const QScreen *screen = d->getScreen();
        val = data->crect.height() * screen->physicalHeight() / screen->height();
    } else if (m == PdmDepth) {
        return qwsDisplay()->depth();
    } else if (m == PdmDpiX || m == PdmPhysicalDpiX) {
        if (d->extra && d->extra->customDpiX)
            return d->extra->customDpiX;
        else if (d->parent)
            return static_cast<QWidget *>(d->parent)->metric(m);
        const QScreen *screen = d->getScreen();
        return qRound(screen->width() / double(screen->physicalWidth() / 25.4));
    } else if (m == PdmDpiY || m == PdmPhysicalDpiY) {
        if (d->extra && d->extra->customDpiY)
            return d->extra->customDpiY;
        else if (d->parent)
            return static_cast<QWidget *>(d->parent)->metric(m);
        const QScreen *screen = d->getScreen();
        return qRound(screen->height() / double(screen->physicalHeight() / 25.4));
    } else if (m == PdmNumColors) {
        QScreen *screen = d->getScreen();
        int ret = screen->colorCount();
        if (!ret) {
            const int depth = qwsDisplay()->depth();
            switch (depth) {
            case 1:
                ret = 2;
                break;
            case 8:
                ret = 256;
                break;
            case 16:
                ret = 65536;
                break;
            case 24:
                ret = 16777216;
                break;
            case 32:
                ret = 2147483647;
                break;
            }
        }
        return ret;
    } else {
        val = QPaintDevice::metric(m);// XXX
    }
    return val;
}
Exemple #16
0
void ColorPicker::updatePosition()
{
    QPoint pos = QCursor::pos();
    QScreen *screen = findScreenAt(pos);
    if (!screen) {
        qWarning() << "Could not find a screen containing" << pos;
        return;
    }
    QRect desktopRect = screen->geometry();

    QPoint newPos;
    if (pos.x() + GRAB_SIZE + width() < desktopRect.width()) {
        newPos.setX(pos.x() + GRAB_SIZE);
    } else {
        newPos.setX(pos.x() - GRAB_SIZE - width());
    }
    if (pos.y() + GRAB_SIZE + height() < desktopRect.height()) {
        newPos.setY(pos.y() + GRAB_SIZE);
    } else {
        newPos.setY(pos.y() - GRAB_SIZE - height());
    }

    move(newPos);

    WId wid = QApplication::desktop()->winId();
    mPixmap = screen->grabWindow(wid, pos.x() - GRAB_SIZE / 2, pos.y() - GRAB_SIZE / 2, GRAB_SIZE, GRAB_SIZE);
    update();
}
/*!
    Returns the height of the display in pixels.

    \sa screenWidth(), screenDepth()
*/
int QDirectPainter::screenHeight()
{
    QScreen *screen = getPrimaryScreen();
    if (!screen)
        return 0;
    return screen->deviceHeight();
}
Exemple #18
0
void run()
{
    TMPROF_BLOCK();

    int argc = 1;
    char* argv[] = { "" };
    QGuiApplication app(argc, argv);

    QScreen *screen = QGuiApplication::primaryScreen();
    QRect screenGeometry = screen->availableGeometry();
    QPoint center = QPoint(screenGeometry.center().x(), screenGeometry.top() + 80);
    QSize windowSize(400, 320);
    int delta = 40;

    QList<QWindow *> windows;
    xqtgl::window *windowA = new xqtgl::window(&init,&step,&draw,&fini);
    windowA->setGeometry(QRect(center, windowSize).translated(-windowSize.width() - delta / 2, 0));
    windowA->setTitle(QStringLiteral("Window"));
    windowA->setVisible(true);
    windows.prepend(windowA);

    app.exec();

    qDeleteAll(windows);

}
void QQuickWebEngineViewPrivate::setDevicePixelRatio(qreal devicePixelRatio)
{
    Q_Q(QQuickWebEngineView);
    this->devicePixelRatio = devicePixelRatio;
    QScreen *screen = q->window() ? q->window()->screen() : QGuiApplication::primaryScreen();
    m_dpiScale = devicePixelRatio / screen->devicePixelRatio();
}
void MainWindow::setThumbnail(int i) {
    QLabel *screenshotLabel;

    if (thumbnails[i] == NULL) {
        screenshotLabel = new QLabel;
        screenshotLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        screenshotLabel->setAlignment(Qt::AlignCenter);
        screenshotLabel->setMinimumSize(240, 160);

        layout->addWidget(screenshotLabel, i / 3, i % 3);
        thumbnails[i] = screenshotLabel;
    }
    else {
        screenshotLabel = thumbnails[i];
    }

    QScreen *srn = QApplication::screens().at(0);
    QPixmap workspacePixmap = srn->grabWindow(QApplication::desktop()->winId());

    screenshotLabel->setPixmap(
        workspacePixmap.scaled(
            screenshotLabel->size(),
            Qt::KeepAspectRatio,
            Qt::SmoothTransformation
        )
    );
}
Exemple #21
0
int main(int argc, char *argv[])
{
    // Enable the following to have touch events generated from mouse events.
    // Very handy for testing touch event delivery without a real touch device.
    // QGuiApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true);

    QGuiApplication app(argc, argv);
    QScreen *screen = QGuiApplication::primaryScreen();
    QRect screenGeometry = screen->availableGeometry();

    QSurfaceFormat format;
    format.setDepthBufferSize(16);

    QRect geom = screenGeometry;
    if (QCoreApplication::arguments().contains(QLatin1String("-nofullscreen")))
        geom = QRect(screenGeometry.width() / 4, screenGeometry.height() / 4,
                     screenGeometry.width() / 2, screenGeometry.height() / 2);

    QOpenGLWindow window(format, geom);
    QWindowCompositor compositor(&window);

    window.show();

    return app.exec();
}
void OBSProjector::Init(int monitor, bool window, QString title)
{
	QScreen *screen = QGuiApplication::screens()[monitor];

	if (!window)
		setGeometry(screen->geometry());

	bool alwaysOnTop = config_get_bool(GetGlobalConfig(),
			"BasicWindow", "ProjectorAlwaysOnTop");
	if (alwaysOnTop && !window)
		SetAlwaysOnTop(this, true);

	if (window)
		setWindowTitle(title);

	show();

	if (source)
		obs_source_inc_showing(source);

	if (!window) {
		QAction *action = new QAction(this);
		action->setShortcut(Qt::Key_Escape);
		addAction(action);
		connect(action, SIGNAL(triggered()), this,
				SLOT(EscapeTriggered()));
	}

	savedMonitor = monitor;
	isWindow = window;
}
/*!
    Returns the length (in bytes) of each scanline of the framebuffer.

    \sa frameBuffer()
*/
int QDirectPainter::linestep()
{
    QScreen *screen = getPrimaryScreen();
    if (!screen)
        return 0;
    return screen->linestep();
}
void BleWindowsCaptureSource::run()
{
    // TODO make could select screen
    // QGuiApplication::screens();
    while (!m_stop) {
        QElapsedTimer elapsedTimer;
        elapsedTimer.start();

        QScreen *screen = QGuiApplication::primaryScreen();

        if (screen) {
            QPixmap pixmap = screen->grabWindow(m_wid, m_x, m_y, m_width, m_height);
#if 1
            // TODO to draw cursor to image
            QRect desktopRect = QRect(QPoint(0, 0), screen->size());
            if (desktopRect.contains(QCursor::pos())) {
                drawCursor(&pixmap);
            }
#endif
            QImage image = pixmap.toImage();

            m_modifyMutex.lock();           // Start lock

            BleImage be;
            be.width = image.width();
            be.height = image.height();

            int imageSize = be.width * be.height * 3;
            be.data = new char[imageSize];

            IplImage *oriImage = cvCreateImageHeader(cvSize(image.width(), image.height()), IPL_DEPTH_8U, 4);
            cvSetData(oriImage, image.bits(), image.bytesPerLine());

            IplImage *dstImage = cvCreateImageHeader(cvSize(image.width(), image.height()), IPL_DEPTH_8U, 3);
            cvSetData(dstImage, be.data, be.width * 3);

            cvCvtColor(oriImage, dstImage, CV_BGRA2BGR);

            be.dataSize = imageSize;
            be.format = BleImage_Format_BGR24;

            m_image = be;

            cvReleaseImageHeader(&oriImage);
            cvReleaseImageHeader(&dstImage);

            m_modifyMutex.unlock();        // End unlock
        }

        int elapsedMs = elapsedTimer.elapsed();
        int needSleepMs = m_interval - elapsedMs;
        if (needSleepMs < 0) {
            needSleepMs = 0;
        }
        msleep(needSleepMs);
    }

    log_trace("BleWindowsCaptureSource exit normally.");
}
Exemple #25
0
void App::show()
{
    QScreen *currScreen = screen();
    QRect rect(0, 0, 800, 600);
    rect.moveTopLeft(currScreen->geometry().topLeft());
    setGeometry(rect);
    showMaximized();
}
Exemple #26
0
 InternalTextItem(QGraphicsItem * parent) : QGraphicsTextItem(parent) {
     // calculate the scale for the text item - this is the same
     // calculation as in GraphicsSheet::GraphicsSheet, so this should
     // be located in some common convenience method
     QScreen *srn = QApplication::screens().at(0);
     qreal scale = 25.4 / srn->logicalDotsPerInchY();
     setScale(scale);
 }
Exemple #27
0
qreal AsemanDevices::lcdDpiY() const
{
    if( QGuiApplication::screens().isEmpty() )
        return 0;

    QScreen *scr = QGuiApplication::screens().first();
    return scr->physicalDotsPerInchY();
}
Exemple #28
0
QSize AsemanDevices::screenSize() const
{
    if( QGuiApplication::screens().isEmpty() )
        return QSize();

    QScreen *scr = QGuiApplication::screens().first();
    return scr->size();
}
Exemple #29
0
qreal AsemanDevices::lcdPhysicalHeight() const
{
    if( QGuiApplication::screens().isEmpty() )
        return 0;

    QScreen *scr = QGuiApplication::screens().first();
    return (qreal)scr->size().height()/scr->physicalDotsPerInchY();
}
/*!
    Returns a pointer to the beginning of the display memory.

    Note that it is the application's responsibility to limit itself
    to modifying only the reserved region.

    Do not use this pointer if the current screen has subscreens,
    query the screen driver instead: A pointer to the current screen
    driver can always be retrieved using the static
    QScreen::instance() function. Then use QScreen's \l
    {QScreen::}{subScreenIndexAt()} and \l {QScreen::}{subScreens()}
    functions to access the correct subscreen, and the subscreen's \l
    {QScreen::}{base()} function to retrieve a pointer to the
    framebuffer.

    \sa requestedRegion(), allocatedRegion(), linestep()
*/
uchar* QDirectPainter::frameBuffer()
{
    QScreen *screen = getPrimaryScreen();
    if (!screen)
        return 0;
    return screen->base();
}