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;
}
示例#2
0
qreal AsemanDevices::lcdDpiY() const
{
    if( QGuiApplication::screens().isEmpty() )
        return 0;

    QScreen *scr = QGuiApplication::screens().first();
    return scr->physicalDotsPerInchY();
}
示例#3
0
qreal AsemanDevices::lcdPhysicalHeight() const
{
    if( QGuiApplication::screens().isEmpty() )
        return 0;

    QScreen *scr = QGuiApplication::screens().first();
    return (qreal)scr->size().height()/scr->physicalDotsPerInchY();
}
示例#4
0
文件: qwidget_qpa.cpp 项目: cedrus/qt
int QWidget::metric(PaintDeviceMetric m) const
{
    Q_D(const QWidget);

    QScreen *screen = 0;
    if (QWidget *topLevel = window())
        if (QWindow *topLevelWindow = topLevel->windowHandle()) {
            QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(topLevelWindow);
            if (platformScreen)
                screen = platformScreen->screen();
        }
    if (!screen && QGuiApplication::primaryScreen())
        screen = QGuiApplication::primaryScreen();

    if (!screen) {
        if (m == PdmDpiX || m == PdmDpiY)
              return 72;
        return QPaintDevice::metric(m);
    }
    int val;
    if (m == PdmWidth) {
        val = data->crect.width();
    } else if (m == PdmWidthMM) {
        val = data->crect.width() * screen->physicalSize().width() / screen->geometry().width();
    } else if (m == PdmHeight) {
        val = data->crect.height();
    } else if (m == PdmHeightMM) {
        val = data->crect.height() * screen->physicalSize().height() / screen->geometry().height();
    } else if (m == PdmDepth) {
        return screen->depth();
    } else if (m == PdmDpiX) {
        if (d->extra && d->extra->customDpiX)
            return d->extra->customDpiX;
        else if (d->parent)
            return static_cast<QWidget *>(d->parent)->metric(m);
        return qRound(screen->logicalDotsPerInchX());
    } else if (m == PdmDpiY) {
        if (d->extra && d->extra->customDpiY)
            return d->extra->customDpiY;
        else if (d->parent)
            return static_cast<QWidget *>(d->parent)->metric(m);
        return qRound(screen->logicalDotsPerInchY());
    } else if (m == PdmPhysicalDpiX) {
        return qRound(screen->physicalDotsPerInchX());
    } else if (m == PdmPhysicalDpiY) {
        return qRound(screen->physicalDotsPerInchY());
    } else if (m == PdmDevicePixelRatio) {
        return screen->devicePixelRatio();
    } else {
        val = QPaintDevice::metric(m);// XXX
    }
    return val;
}
/*!
  \internal
 */
int QPaintDeviceWindow::metric(PaintDeviceMetric metric) const
{
    QScreen *screen = this->screen();
    if (!screen && QGuiApplication::primaryScreen())
        screen = QGuiApplication::primaryScreen();

    switch (metric) {
    case PdmWidth:
        return width();
    case PdmWidthMM:
        if (screen)
            return width() * screen->physicalSize().width() / screen->geometry().width();
        break;
    case PdmHeight:
        return height();
    case PdmHeightMM:
        if (screen)
            return height() * screen->physicalSize().height() / screen->geometry().height();
        break;
    case PdmDpiX:
        if (screen)
            return qRound(screen->logicalDotsPerInchX());
        break;
    case PdmDpiY:
        if (screen)
            return qRound(screen->logicalDotsPerInchY());
        break;
    case PdmPhysicalDpiX:
        if (screen)
            return qRound(screen->physicalDotsPerInchX());
        break;
    case PdmPhysicalDpiY:
        if (screen)
            return qRound(screen->physicalDotsPerInchY());
        break;
    case PdmDevicePixelRatio:
        if (screen)
            return screen->devicePixelRatio();
        break;
    default:
        break;
    }

    return QPaintDevice::metric(metric);
}
示例#6
0
int BtStyle::pixelsPerMillimeterY() {
    QScreen* screen = QGuiApplication::screens().at(0);
    int dpm = screen->physicalDotsPerInchY() / millimeterPerInch;
    return dpm;
}