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;
}
Exemple #2
0
    void ScreenModel::initScreens(bool first) {
        // Clear
        d->geometry = QRect();
        d->primary = 0;
        d->screens.clear();

#ifndef USE_QT5
        // set role names
        QHash<int, QByteArray> roleNames;
        roleNames[NameRole] = "name";
        roleNames[GeometryRole] = "geometry";
        // set role names
        setRoleNames(roleNames);
#endif

#if 0
        // fake model for testing
        d->geometry = QRect(0, 0, 1920, 1080);
        d->primary = 1;
        d->screens << ScreenPtr { new Screen { "First", QRect(0, 0, 300, 300) } }
                   << ScreenPtr { new Screen { "Second", QRect(300, 0, 1320, 742) } }
                   << ScreenPtr { new Screen { "Third", QRect(1620, 0, 300, 300) } };
        return;
#endif

#ifdef USE_QT5
        QList<QScreen *> screens = QGuiApplication::screens();
        for (int i = 0; i < screens.size(); ++i) {
            QScreen *screen = screens.at(i);
            // add to the screens list
            d->screens << ScreenPtr { new Screen { QString("Screen %1").arg(i + 1), screen->geometry() } };
            // extend available geometry
            d->geometry = d->geometry.united(screen->geometry());
            // check if primary
            if (screen == QGuiApplication::primaryScreen())
                d->primary = i;

            if (first) {
                // Recive screen updates
                connect(screen, SIGNAL(geometryChanged(const QRect &)), this, SLOT(onScreenChanged()));
            }
        }
#else
        // set primary screen
        d->primary = QApplication::desktop()->primaryScreen();
        // get screen count
        int screenCount = QApplication::desktop()->screenCount();

        for (int i = 0; i < screenCount; ++i) {
            QRect geometry = QApplication::desktop()->screenGeometry(i);
            // add to the screens list
            d->screens << ScreenPtr { new Screen { QString("Screen %1").arg(i + 1), geometry } };
            // extend available geometry
            d->geometry = d->geometry.united(geometry);
        }
#endif
        emit screensChanged();
    }
Exemple #3
0
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;
}
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;
}
Exemple #5
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();
}
Exemple #6
0
void App::show()
{
    QScreen *currScreen = screen();
    QRect rect(0, 0, 800, 600);
    rect.moveTopLeft(currScreen->geometry().topLeft());
    setGeometry(rect);
    showMaximized();
}
/*!
  \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);
}
Exemple #8
0
    void ScreenModel::initScreens(bool first) {
        // Clear
        beginResetModel();
        d->geometry = QRect();
        d->primary = 0;
        d->screens.clear();

#if 0
        // fake model for testing
        d->geometry = QRect(0, 0, 1920, 1080);
        d->primary = 1;
        d->screens << ScreenPtr { new Screen { "First", QRect(0, 0, 300, 300) } }
                   << ScreenPtr { new Screen { "Second", QRect(300, 0, 1320, 742) } }
                   << ScreenPtr { new Screen { "Third", QRect(1620, 0, 300, 300) } };
        return;
#endif

        QScreen *primaryScreen = QGuiApplication::primaryScreen();
        QList<QScreen *> screens = QGuiApplication::screens();
        for (int i = 0; i < screens.size(); ++i) {
            QScreen *screen = screens.at(i);
            // heuristic to detect clone mode, in that case only consider the primary screen
            if (screen->virtualGeometry() == primaryScreen->geometry() && screen != primaryScreen)
                continue;
            // add to the screens list
            d->screens << ScreenPtr { new Screen { QStringLiteral("Screen %1").arg(i + 1), screen->geometry() } };
            // extend available geometry
            d->geometry = d->geometry.united(screen->geometry());
            // check if primary
            if (screen == QGuiApplication::primaryScreen())
                d->primary = i;

            if (first) {
                // Recive screen updates
                connect(screen, SIGNAL(geometryChanged(const QRect &)), this, SLOT(onScreenChanged()));
            }
        }
        endResetModel();

        emit primaryChanged();
    }
void MainWindow::savePosition(Qt::WindowState state) {
	if (state == Qt::WindowActive) state = windowHandle()->windowState();
	if (state == Qt::WindowMinimized || !positionInited()) return;

	auto savedPosition = cWindowPos();
	auto realPosition = savedPosition;

	if (state == Qt::WindowMaximized) {
		realPosition.maximized = 1;
	} else {
		auto r = geometry();
		realPosition.x = r.x();
		realPosition.y = r.y();
		realPosition.w = r.width() - (_rightColumn ? _rightColumn->width() : 0);
		realPosition.h = r.height();
		realPosition.maximized = 0;
		realPosition.moncrc = 0;
	}
	DEBUG_LOG(("Window Pos: Saving position: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));

	auto centerX = realPosition.x + realPosition.w / 2;
	auto centerY = realPosition.y + realPosition.h / 2;
	int minDelta = 0;
	QScreen *chosen = nullptr;
	auto screens = QGuiApplication::screens();
	for (auto screen : QGuiApplication::screens()) {
		auto delta = (screen->geometry().center() - QPoint(centerX, centerY)).manhattanLength();
		if (!chosen || delta < minDelta) {
			minDelta = delta;
			chosen = screen;
		}
	}
	if (chosen) {
		auto screenGeometry = chosen->geometry();
		DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4").arg(screenGeometry.x()).arg(screenGeometry.y()).arg(screenGeometry.width()).arg(screenGeometry.height()));
		realPosition.x -= screenGeometry.x();
		realPosition.y -= screenGeometry.y();
		realPosition.moncrc = screenNameChecksum(chosen->name());
	}

	if (realPosition.w >= st::windowMinWidth && realPosition.h >= st::windowMinHeight) {
		if (realPosition.x != savedPosition.x
			|| realPosition.y != savedPosition.y
			|| realPosition.w != savedPosition.w
			|| realPosition.h != savedPosition.h
			|| realPosition.moncrc != savedPosition.moncrc
			|| realPosition.maximized != savedPosition.maximized) {
			DEBUG_LOG(("Window Pos: Writing: %1, %2, %3, %4 (maximized %5)").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h).arg(Logs::b(realPosition.maximized)));
			cSetWindowPos(realPosition);
			Local::writeSettings();
		}
	}
}
Exemple #10
0
bool OGGameEngine::initialize()
{
    qApp->installEventFilter(this);

    m_window.reset(new OGWindow(m_game));

    QScreen* screen = getPrimaryScreen();
    int x = (screen->geometry().width() - getWidth()) / 2.0f;
    int y = (screen->geometry().height() - getHeight()) / 2.0f;
    m_window->setGeometry(x, y, getWidth(), getHeight());
    m_window->setFixedSize(getWidth(), getHeight());

    if (m_fullscreen)
    {
        //initialize video mode
#ifdef Q_OS_WIN32
        m_isVideoModeSupported = OGVideoMode::testVideoMode(getWidth()
                                , getHeight());

        if (m_isVideoModeSupported)
        {
            OGVideoMode::setVideoMode(getWidth(), getHeight());

            m_window->showFullScreen();
        }
        else { logWarn("Video mode not supported"); }
#else
        m_window->show();
#endif // Q_OS_WIN32
    }
    else
    {
        m_window->show();
    }

    connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(gameExit()));

    return true;
}
QPixmap ScreenCaptureProvider::requestPixmap(const QString &/*id*/, QSize * /*size*/, const QSize& /*requestedSize*/)
{
	QScreen *screen = QGuiApplication::primaryScreen();
	if (screen)
	{
		QPixmap screenShotPixmap = screen->grabWindow(0);
		qDebug() << screen->geometry();
		setLastPixmap(screenShotPixmap);

		return screenShotPixmap;
	}

	return QPixmap();
}
Exemple #12
0
bool OGGameEngine::initialize()
{
    QScreen* screen = QGuiApplication::primaryScreen();
    window_ = new OGWindow(pGame_);

    // Set fixed size of window
    window_->setMaximumSize(QSize(getWidth(), getHeight()));
    window_->setMinimumSize(QSize(getWidth(), getHeight()));

    // Center window on screen
    int x = qRound((screen->geometry().width() - getWidth()) / 2.0f);
    int y = qRound((screen->geometry().height() - getHeight()) / 2.0f);
    window_->setGeometry(x, y, getWidth(), getHeight());

    if (fullscreen_)
    {
        //initialize video mode
#ifdef Q_OS_WIN32
        isVideoModeSupported_ = OGVideoMode::testVideoMode(getWidth()
                                , getHeight());

        if (isVideoModeSupported_)
        {
            OGVideoMode::setVideoMode(getWidth(), getHeight());

            window_->showFullScreen();
        }
        else { logWarn("Video mode not supported"); }
#else
        window_->show();
#endif // Q_OS_WIN32
    }
    else { window_->show(); }

    return true;
}
Exemple #13
0
void GetScreenInfoFromNativeWindow(QWindow* window, blink::WebScreenInfo* results)
{
    QScreen* screen = window->screen();

    blink::WebScreenInfo r;
    r.deviceScaleFactor = screen->devicePixelRatio();
    r.depthPerComponent = 8;
    r.depth = screen->depth();
    r.isMonochrome = (r.depth == 1);

    QRect screenGeometry = screen->geometry();
    r.rect = blink::WebRect(screenGeometry.x(), screenGeometry.y(), screenGeometry.width(), screenGeometry.height());
    QRect available = screen->availableGeometry();
    r.availableRect = blink::WebRect(available.x(), available.y(), available.width(), available.height());
    *results = r;
}
Exemple #14
0
int main(int argc, char** argv)
{
    try {
        QApplication app(argc, argv);

        GeneratorWindow myWindow;

        QScreen* screen = app.primaryScreen();
        QRect rec = screen->geometry();
        myWindow.resize(rec.size().width(), rec.size().height() - 100);
        myWindow.show();

        return app.exec();
    } catch (std::exception& e) {
        std::cout << e.what() << std::endl;
    }
    return -1;
}
Exemple #15
0
void PsMainWindow::psSavePosition(Qt::WindowState state) {
    if (state == Qt::WindowActive) state = windowHandle()->windowState();
	if (state == Qt::WindowMinimized || !posInited) return;

	TWindowPos pos(cWindowPos()), curPos = pos;

	if (state == Qt::WindowMaximized) {
		curPos.maximized = 1;
	} else {
		QRect r(geometry());
		curPos.x = r.x();
		curPos.y = r.y();
		curPos.w = r.width();
		curPos.h = r.height();
		curPos.maximized = 0;
	}

	int px = curPos.x + curPos.w / 2, py = curPos.y + curPos.h / 2, d = 0;
	QScreen *chosen = 0;
	QList<QScreen*> screens = App::app()->screens();
	for (QList<QScreen*>::const_iterator i = screens.cbegin(), e = screens.cend(); i != e; ++i) {
		int dx = (*i)->geometry().x() + (*i)->geometry().width() / 2 - px; if (dx < 0) dx = -dx;
		int dy = (*i)->geometry().y() + (*i)->geometry().height() / 2 - py; if (dy < 0) dy = -dy;
		if (!chosen || dx + dy < d) {
			d = dx + dy;
			chosen = *i;
		}
	}
	if (chosen) {
		curPos.x -= chosen->geometry().x();
		curPos.y -= chosen->geometry().y();
		QByteArray name = chosen->name().toUtf8();
		curPos.moncrc = hashCrc32(name.constData(), name.size());
	}

	if (curPos.w >= st::wndMinWidth && curPos.h >= st::wndMinHeight) {
		if (curPos.x != pos.x || curPos.y != pos.y || curPos.w != pos.w || curPos.h != pos.h || curPos.moncrc != pos.moncrc || curPos.maximized != pos.maximized) {
			cSetWindowPos(curPos);
			Local::writeSettings();
		}
    }
}
Exemple #16
0
void MainWindow::trayAction(QSystemTrayIcon::ActivationReason reason) {

	if(variables->verbose)
		LOG << CURDATE << "trayAction()" << NL;

	if(reason == QSystemTrayIcon::Trigger) {

		if(!variables->hiddenToTrayIcon) {
			variables->geometryWhenHiding = this->geometry();
			if(variables->verbose)
				LOG << CURDATE << "trayAction(): Hiding to tray" << NL;
			this->hide();
		} else {

			if(variables->verbose)
				LOG << CURDATE << "trayAction(): Updating screenshots" << NL;

			// Get screenshots
			for(int i = 0; i < QGuiApplication::screens().count(); ++i) {
				QScreen *screen = QGuiApplication::screens().at(i);
				QRect r = screen->geometry();
				QPixmap pix = screen->grabWindow(0,r.x(),r.y(),r.width(),r.height());
				if(!pix.save(QDir::tempPath() + QString("/photoqt_screenshot_%1.jpg").arg(i)))
					LOG << CURDATE << "ERROR: Unable to update screenshot for screen #" << i << NL;
			}

			if(variables->verbose)
				LOG << CURDATE << "trayAction(): SHowing window" << NL;

			updateWindowGeometry();

			if(variables->currentDir == "")
				QMetaObject::invokeMethod(object, "openFile");
		}

	}

}
QtWaylandMotorcarCompositor *QtWaylandMotorcarCompositor::create(int argc, char** argv, motorcar::Scene *scene)
{
    // 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 = new QGuiApplication(argc, argv);
    QScreen *screen = NULL;



    //screen = QGuiApplication::primaryScreen();
    screen = QGuiApplication::screens().back();

    QRect screenGeometry = screen->geometry();


    QSurfaceFormat format;
//    std::cout << "color buffer size: " << format.redBufferSize() << std::endl;
//    format.setRedBufferSize(8);
//    format.setGreenBufferSize(8);
//    format.setBlueBufferSize(8);
//    format.setAlphaBufferSize(8);
    format.setDepthBufferSize(8);
    format.setStencilBufferSize(8);
    format.setSwapInterval(1);
    format.setStencilBufferSize(8);

    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 = new QOpenGLWindow(format, geom);
    return  new QtWaylandMotorcarCompositor(window, app, scene);
}
Screen2::Screen2(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Screen2),
    airTime()
{
    ui->setupUi(this);
    QScreen* screen;
    if(QApplication::screens().size() > 1){
      screen = QApplication::screens().at(1);
    } else {
       screen = QApplication::screens().at(0);
    }
    QRect screenres = screen->geometry();
    this->move(QPoint(screenres.x(), screenres.y()));
    this->resize(screenres.width(), screenres.height());

    QPalette palette = this->palette();
    palette.setColor(this->backgroundRole(), Qt::black);
    this->setPalette(palette);

//    QPalette pText = ui->label_height->palette();
//    palette.setColor(ui->label_height->foregroundRole(), Qt::white);
//    ui->label_height->setPalette(pText);
//    ui->label_state->setPalette(pText);
//    ui->label_time->setPalette(pText);

    mCompassGauge = new QcGaugeWidget;

    QcLabelItem *w = mCompassGauge->addLabel(60);
    w->setText("W");
    w->setAngle(0);
    w->setColor(Qt::black);

    QcLabelItem *n = mCompassGauge->addLabel(60);
    n->setText("N");
    n->setAngle(90);
    n->setColor(Qt::black);

    QcLabelItem *e = mCompassGauge->addLabel(60);
    e->setText("E");
    e->setAngle(180);
    e->setColor(Qt::black);

    QcLabelItem *s = mCompassGauge->addLabel(60);
    s->setText("S");
    s->setAngle(270);
    s->setColor(Qt::black);

    QcDegreesItem *deg = mCompassGauge->addDegrees(50);
    deg->setStep(5);
    deg->setMaxDegree(360);
    deg->setMinDegree(0);
    deg->setColor(Qt::black);

    lab = mCompassGauge->addLabel(75);

    mShipNeedle = mCompassGauge->addNeedle(55);
    mShipNeedle->setNeedle(QcNeedleItem::AttitudeMeterNeedle);
    mShipNeedle->setValueRange(-360,360);
    mShipNeedle->setMaxDegree(360);
    mShipNeedle->setMinDegree(-360);
    mShipNeedle->setColor(Qt::green);

    mHeadingNeedle = mCompassGauge->addNeedle(45);
    mHeadingNeedle->setNeedle(QcNeedleItem::DiamonNeedle);
    mHeadingNeedle->setValueRange(0,360);
    mHeadingNeedle->setMaxDegree(360);
    mHeadingNeedle->setMinDegree(0);
    mHeadingNeedle->setColor(Qt::red);

    ui->compassLayout->addWidget(mCompassGauge);


    time = new QTime;
    timer = new QTimer;
    connect(timer, SIGNAL(timeout()), this, SLOT(updateTime()));
    timer->start(1000);

    hr = 0;
    min = 0;
    sec = 0;
    oldmsec = 0;
    timerOn = false;
    airTime.setHMS(hr, min, sec);
}
Exemple #19
0
// Remote controlling
void MainWindow::remoteAction(QString cmd) {

	if(variables->verbose)
		LOG << CURDATE << "remoteAction(): " << cmd.toStdString() << NL;

	if(cmd == "open") {

		if(variables->verbose)
			LOG << CURDATE << "remoteAction(): Open file" << NL;
		if(!this->isVisible()) {
			// Get screenshots
			for(int i = 0; i < QGuiApplication::screens().count(); ++i) {
				QScreen *screen = QGuiApplication::screens().at(i);
				QRect r = screen->geometry();
				QPixmap pix = screen->grabWindow(0,r.x(),r.y(),r.width(),r.height());
				pix.save(QDir::tempPath() + QString("/photoqt_screenshot_%1.jpg").arg(i));
			}
			updateWindowGeometry();
			this->raise();
			this->requestActivate();
		}

		QMetaObject::invokeMethod(object, "openFile");

	} else if(cmd == "nothumbs") {

		if(variables->verbose)
			LOG << CURDATE << "remoteAction(): Disable thumbnails" << NL;
		settingsPermanent->thumbnailDisable = true;
		settingsPermanent->thumbnailDisableChanged(settingsPermanent->thumbnailDisable);

	} else if(cmd == "thumbs") {

		if(variables->verbose)
			LOG << CURDATE << "remoteAction(): Enable thumbnails" << NL;
		settingsPermanent->thumbnailDisable = true;
		settingsPermanent->thumbnailDisableChanged(settingsPermanent->thumbnailDisable);

	} else if(cmd == "hide" || (cmd == "toggle" && this->isVisible())) {

		if(variables->verbose)
			LOG << CURDATE << "remoteAction(): Hiding" << NL;
		if(settingsPermanent->trayicon != 1) {
			settingsPermanent->trayicon = 1;
			settingsPermanent->trayiconChanged(settingsPermanent->trayicon);
		}
		QMetaObject::invokeMethod(object, "hideOpenFile");
		this->hide();

	} else if(cmd.startsWith("show") || (cmd == "toggle" && !this->isVisible())) {

		if(variables->verbose)
			LOG << CURDATE << "remoteAction(): Showing" << NL;

		// The same code can be found at the end of main.cpp
		if(!this->isVisible()) {
			// Get screenshots
			for(int i = 0; i < QGuiApplication::screens().count(); ++i) {
				QScreen *screen = QGuiApplication::screens().at(i);
				QRect r = screen->geometry();
				QPixmap pix = screen->grabWindow(0,r.x(),r.y(),r.width(),r.height());
				pix.save(QDir::tempPath() + QString("/photoqt_screenshot_%1.jpg").arg(i));
			}
			updateWindowGeometry();
		}
		this->raise();
		this->requestActivate();

		if(variables->currentDir == "" && cmd != "show_noopen")
			QMetaObject::invokeMethod(object, "openFile");

	} else if(cmd.startsWith("::file::")) {

		if(variables->verbose)
			LOG << CURDATE << "remoteAction(): Opening passed-on file" << NL;
		QMetaObject::invokeMethod(object, "hideOpenFile");
		handleOpenFileEvent(cmd.remove(0,8));

	}


}
DraftScoreWindow::DraftScoreWindow(QWidget *parent, QRect rect, QSize sizeCard, int screenIndex) :
    QMainWindow(parent, Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint)
{
    scoreWidth = sizeCard.width()*0.8;

    QList<QScreen *> screens = QGuiApplication::screens();
    QScreen *screen = screens[screenIndex];
    if (!screen) return;

    QRect rectScreen = screen->geometry();
    resize(rect.width()+2*MARGIN-(sizeCard.width()-scoreWidth),
           rect.height()+2*MARGIN-(sizeCard.height()-scoreWidth));
    move(rectScreen.x() + rect.x() - MARGIN + (sizeCard.width()-scoreWidth)/2,
         rectScreen.y() + rect.y() - MARGIN + 2.6*sizeCard.height());


    QWidget *centralWidget = new QWidget(this);
    QFont font("Belwe Bd BT");
    font.setPointSize(scoreWidth/3);

    QVBoxLayout *verLayout = new QVBoxLayout(centralWidget);
    QHBoxLayout *horLayoutScores = new QHBoxLayout();
    QHBoxLayout *horLayoutSynergies = new QHBoxLayout();
    verLayout->addLayout(horLayoutScores);
    verLayout->addLayout(horLayoutSynergies);

    for(int i=0; i<3; i++)
    {
        scoresPushButton[i] = new ScoreButton(centralWidget, i);
        scoresPushButton[i]->setMinimumHeight(0);
        scoresPushButton[i]->setMaximumHeight(0);
        scoresPushButton[i]->setMinimumWidth(scoreWidth);
        scoresPushButton[i]->setFont(font);

        horLayoutScores->addWidget(scoresPushButton[i]);
        if(i<2)    horLayoutScores->addStretch();

        connect(scoresPushButton[i], SIGNAL(enter(int)),
                this, SLOT(showSynergies(int)));
        connect(scoresPushButton[i], SIGNAL(leave(int)),
                this, SLOT(hideSynergies(int)));


        QVBoxLayout *verLayoutSynergy = new QVBoxLayout();
        synergiesListWidget[i] = new QListWidget(centralWidget);
        synergiesListWidget[i]->setMinimumHeight(0);
        synergiesListWidget[i]->setMaximumHeight(0);
        synergiesListWidget[i]->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        synergiesListWidget[i]->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        synergiesListWidget[i]->setIconSize(CARD_SIZE);
        synergiesListWidget[i]->setFrameShape(QFrame::NoFrame);
        synergiesListWidget[i]->setStyleSheet("background-color: transparent;");
        verLayoutSynergy->addWidget(synergiesListWidget[i]);
        verLayoutSynergy->addStretch();
        horLayoutSynergies->addLayout(verLayoutSynergy);
        if(i<2)    horLayoutSynergies->addStretch();
    }

    maxSynergyHeight = rectScreen.y() + rectScreen.height() - this->y() - 2*MARGIN - 2*scoreWidth; //Extra scoreWidth
    setCentralWidget(centralWidget);
    setAttribute(Qt::WA_TranslucentBackground, true);
}
OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor,
		QString title, ProjectorType type_)
	: OBSQTDisplay                 (widget,
	                                Qt::Window),
	  source                       (source_),
	  removedSignal                (obs_source_get_signal_handler(source),
	                                "remove", OBSSourceRemoved, this)
{
	projectorTitle = std::move(title);
	savedMonitor   = monitor;
	isWindow       = savedMonitor < 0;
	type           = type_;

	if (isWindow) {
		setWindowIcon(QIcon::fromTheme("obs",
				QIcon(":/res/images/obs.png")));

		UpdateProjectorTitle(projectorTitle);
		windowedProjectors.push_back(this);

		resize(480, 270);
	} else {
		setWindowFlags(Qt::FramelessWindowHint |
				Qt::X11BypassWindowManagerHint);

		QScreen *screen = QGuiApplication::screens()[savedMonitor];
		setGeometry(screen->geometry());

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

	SetAlwaysOnTop(this, config_get_bool(GetGlobalConfig(),
			"BasicWindow", "ProjectorAlwaysOnTop"));

	setAttribute(Qt::WA_DeleteOnClose, true);

	//disable application quit when last window closed
	setAttribute(Qt::WA_QuitOnClose, false);

	installEventFilter(CreateShortcutFilter());

	auto addDrawCallback = [this] ()
	{
		bool isMultiview = type == ProjectorType::Multiview;
		obs_display_add_draw_callback(GetDisplay(),
				isMultiview ? OBSRenderMultiview : OBSRender,
				this);
		obs_display_set_background_color(GetDisplay(), 0x000000);
	};

	connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback);

	bool hideCursor = config_get_bool(GetGlobalConfig(),
			"BasicWindow", "HideProjectorCursor");
	if (hideCursor && !isWindow) {
		QPixmap empty(16, 16);
		empty.fill(Qt::transparent);
		setCursor(QCursor(empty));
	}

	if (type == ProjectorType::Multiview) {
		obs_enter_graphics();

		// All essential action should be placed inside this area
		gs_render_start(true);
		gs_vertex2f(actionSafePercentage, actionSafePercentage);
		gs_vertex2f(actionSafePercentage, 1 - actionSafePercentage);
		gs_vertex2f(1 - actionSafePercentage, 1 - actionSafePercentage);
		gs_vertex2f(1 - actionSafePercentage, actionSafePercentage);
		gs_vertex2f(actionSafePercentage, actionSafePercentage);
		actionSafeMargin = gs_render_save();

		// All graphics should be placed inside this area
		gs_render_start(true);
		gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage);
		gs_vertex2f(graphicsSafePercentage, 1 - graphicsSafePercentage);
		gs_vertex2f(1 - graphicsSafePercentage,
				1 - graphicsSafePercentage);
		gs_vertex2f(1 - graphicsSafePercentage, graphicsSafePercentage);
		gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage);
		graphicsSafeMargin = gs_render_save();

		// 4:3 safe area for widescreen
		gs_render_start(true);
		gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage);
		gs_vertex2f(1 - fourByThreeSafePercentage,
				graphicsSafePercentage);
		gs_vertex2f(1 - fourByThreeSafePercentage, 1 -
				graphicsSafePercentage);
		gs_vertex2f(fourByThreeSafePercentage,
				1 - graphicsSafePercentage);
		gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage);
		fourByThreeSafeMargin = gs_render_save();

		gs_render_start(true);
		gs_vertex2f(0.0f, 0.5f);
		gs_vertex2f(lineLength, 0.5f);
		leftLine = gs_render_save();

		gs_render_start(true);
		gs_vertex2f(0.5f, 0.0f);
		gs_vertex2f(0.5f, lineLength);
		topLine = gs_render_save();

		gs_render_start(true);
		gs_vertex2f(1.0f, 0.5f);
		gs_vertex2f(1 - lineLength, 0.5f);
		rightLine = gs_render_save();
		obs_leave_graphics();

		solid = obs_get_base_effect(OBS_EFFECT_SOLID);
		color = gs_effect_get_param_by_name(solid, "color");

		UpdateMultiview();

		multiviewProjectors.push_back(this);
	}

	App()->IncrementSleepInhibition();

	if (source)
		obs_source_inc_showing(source);

	ready = true;

	show();

	// We need it here to allow keyboard input in X11 to listen to Escape
	if (!isWindow)
		activateWindow();
}
Exemple #22
0
GUI::GUI() {
    mStreamingMode = STREAMING_MODE_STORE_ALL_FRAMES;
    QScreen* screen = QGuiApplication::primaryScreen();
    menuWidth = screen->geometry().width()*(1.0f/6.0f);
    mPipelineWidget = nullptr;
    mStreamer = ImageFileStreamer::New();

    QVBoxLayout* viewLayout = new QVBoxLayout;


    View* view = createView();
    view->set2DMode();
    view->setBackgroundColor(Color::Black());
    setWidth(screen->geometry().width());
    setHeight(screen->geometry().height());
    enableMaximized();
    setTitle("FAST - Viewer");
    viewLayout->addWidget(view);

    menuLayout = new QVBoxLayout;
    menuLayout->setAlignment(Qt::AlignTop);

    // Logo
    QImage* image = new QImage;
    image->load((Config::getDocumentationPath() + "images/FAST_logo_square.png").c_str());
    QLabel* logo = new QLabel;
    logo->setPixmap(QPixmap::fromImage(image->scaled(menuWidth, ((float)menuWidth/image->width())*image->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)));
    logo->adjustSize();
    menuLayout->addWidget(logo);

    // Title label
    QLabel* title = new QLabel;
    title->setText("Viewer");
	QFont font;
	font.setPixelSize(24 * getScalingFactor());
	font.setWeight(QFont::Bold);
	title->setFont(font);
	title->setAlignment(Qt::AlignCenter);
    menuLayout->addWidget(title);

    // Quit button
    QPushButton* quitButton = new QPushButton;
    quitButton->setText("Quit (q)");
    quitButton->setStyleSheet("QPushButton { background-color: red; color: white; }");
    quitButton->setFixedWidth(menuWidth);
    menuLayout->addWidget(quitButton);

    // Connect the clicked signal of the quit button to the stop method for the window
    QObject::connect(quitButton, &QPushButton::clicked, std::bind(&Window::stop, this));

    QLabel* inputListLabel = new QLabel;
    //inputListLabel->setFixedHeight(24);
    inputListLabel->setText("Input data");
    inputListLabel->setStyleSheet("QLabel { font-weight: bold; }");
    menuLayout->addWidget(inputListLabel);

    mList = new QListWidget;
    mList->setFixedWidth(menuWidth);
    mList->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    mList->setFixedHeight(200);
    mList->setSelectionMode(QAbstractItemView::ExtendedSelection); // Allow multiple items to be selected
    QObject::connect(mList, &QListWidget::itemSelectionChanged, std::bind(&GUI::selectInputData, this));
    menuLayout->addWidget(mList);

    QPushButton* addButton = new QPushButton;
    addButton->setText("Add input data");
    addButton->setFixedWidth(menuWidth);
    QObject::connect(addButton, &QPushButton::clicked, std::bind(&GUI::addInputData, this));
    menuLayout->addWidget(addButton);

    QLabel* selectPipelineLabel = new QLabel;
    selectPipelineLabel->setText("Active pipeline");
    selectPipelineLabel->setStyleSheet("QLabel { font-weight: bold; }");
    //selectPipelineLabel->setFixedHeight(24);
    menuLayout->addWidget(selectPipelineLabel);

    mSelectPipeline = new QComboBox;
    mSelectPipeline->setFixedWidth(menuWidth);
    mPipelines = getAvailablePipelines();
    int index = 0;
    int counter = 0;
    for(auto pipeline : mPipelines) {
        mSelectPipeline->addItem((pipeline.getName() + " (" + pipeline.getDescription() + ")").c_str());
        if(pipeline.getName() == "Image renderer") {
            index = counter;
        }
        ++counter;
    }
    mSelectPipeline->setCurrentIndex(index);

    menuLayout->addWidget(mSelectPipeline);
    QObject::connect(mSelectPipeline, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), std::bind(&GUI::selectPipeline, this));

    QPushButton* refreshPipeline = new QPushButton;
    refreshPipeline->setText("Refresh pipeline");
    refreshPipeline->setStyleSheet("QPushButton { background-color: blue; color: white; }");
    refreshPipeline->setFixedWidth(menuWidth);
    QObject::connect(refreshPipeline, &QPushButton::clicked, std::bind(&GUI::selectPipeline, this));
    menuLayout->addWidget(refreshPipeline);

    QPushButton* editPipeline = new QPushButton;
    editPipeline->setText("Edit pipeline");
    editPipeline->setStyleSheet("QPushButton { background-color: blue; color: white; }");
    editPipeline->setFixedWidth(menuWidth);
    QObject::connect(editPipeline, &QPushButton::clicked, std::bind(&GUI::editPipeline, this));
    menuLayout->addWidget(editPipeline);

    QPushButton* newPipeline = new QPushButton;
    newPipeline->setText("New pipeline");
    newPipeline->setStyleSheet("QPushButton { background-color: blue; color: white; }");
    newPipeline->setFixedWidth(menuWidth);
    QObject::connect(newPipeline, &QPushButton::clicked, std::bind(&GUI::newPipeline, this));
    menuLayout->addWidget(newPipeline);

    // Playback
    QHBoxLayout* playbackLayout = new QHBoxLayout;

    mPlayPauseButton = new QPushButton;
    mPlayPauseButton->setText("Play");
    mPlayPauseButton->setStyleSheet("QPushButton { background-color: green; color: white; }");
    //mPlayPauseButton->setFixedHeight(100);
    QObject::connect(mPlayPauseButton, &QPushButton::clicked, std::bind(&GUI::playPause, this));
    playbackLayout->addWidget(mPlayPauseButton);

    mTimestepSlider = new QSlider(Qt::Horizontal);
    // Improve style of slider
    mTimestepSlider->setStyleSheet("QSlider:horizontal { min-height: 50px; } QSlider::groove:horizontal {\n"
                                           "    border: 1px solid #999999;\n"
                                           "    height: 10px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */\n"
                                           "    background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);\n"
                                           "    margin: 2px 0;\n"
                                           "}\n"
                                           "\n"
                                           "QSlider::handle:horizontal {\n"
                                           "    background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #81BEF7, stop:1 #2E9AFE);\n"
                                           "    border: 1px solid #5c5c5c;\n"
                                           "    width: 18px;\n"
                                           "    height: 25px;\n"
                                           "    margin: -10px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */\n"
                                           "    border-radius: 3px;\n"
                                           "}");
    playbackLayout->addWidget(mTimestepSlider);
    mTimestepSlider->setTickPosition(QSlider::NoTicks);
    mTimestepSlider->setRange(0, 1234);
    mTimestepSlider->setPageStep(1);
    mTimestepSlider->setSingleStep(1);
    mTimestepSlider->setStyle(new MyStyle(mTimestepSlider->style())); // Fixes issues with direct jump with slider
    QObject::connect(mTimestepSlider, &QSlider::sliderMoved, std::bind(&GUI::setTimestep, this));
    QObject::connect(mTimestepSlider, &QSlider::sliderPressed, std::bind(&GUI::setTimestep, this));

    viewLayout->addLayout(playbackLayout);

    // Add menu and view to main layout
    QHBoxLayout* layout = new QHBoxLayout;
    layout->addLayout(menuLayout);
    layout->addLayout(viewLayout);

    mWidget->setLayout(layout);
	std::cout << "Finished viewer setup" << std::endl;

}
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;
}
void QWaylandWindow::setWindowState(Qt::WindowState state)
{
    if (state == Qt::WindowFullScreen || state == Qt::WindowMaximized) {
        QScreen *screen = window()->screen();

        QRect geometry = screen->mapBetween(window()->windowOrientation(), screen->primaryOrientation(), screen->geometry());
        setGeometry(geometry);

        QWindowSystemInterface::handleGeometryChange(window(), geometry);
    }
}