bool QDesignerDockWidget::inMainWindow() const
{
    QMainWindow *mw = findMainWindow();
    if (mw && !mw->centralWidget()->layout()) {
        if (mw == parentWidget())
            return true;
        if (mw->centralWidget() == parentWidget())
            return true;
    }
    return false;
}
void UIMachineViewFullscreen::sltPerformGuestResize(const QSize &toSize)
{
    if (m_bIsGuestAutoresizeEnabled && uisession()->isGuestSupportsGraphics())
    {
        /* Get machine window: */
        QMainWindow *pMachineWindow = machineWindowWrapper() && machineWindowWrapper()->machineWindow() ?
                                      qobject_cast<QMainWindow*>(machineWindowWrapper()->machineWindow()) : 0;

        /* If this slot is invoked directly then use the passed size otherwise get
         * the available size for the guest display. We assume here that centralWidget()
         * contains this view only and gives it all available space: */
        QSize newSize(toSize.isValid() ? toSize : pMachineWindow ? pMachineWindow->centralWidget()->size() : QSize());
        AssertMsg(newSize.isValid(), ("Size should be valid!\n"));

        /* Do not send the same hints as we already have: */
        if ((newSize.width() == storedConsoleSize().width()) && (newSize.height() == storedConsoleSize().height()))
            return;

        /* We only actually send the hint if either an explicit new size was given
         * (e.g. if the request was triggered directly by a console resize event) or
         * if no explicit size was specified but a resize is flagged as being needed
         * (e.g. the autoresize was just enabled and the console was resized while it was disabled). */
        if (toSize.isValid() || m_fShouldWeDoResize)
        {
            /* Remember the new size: */
            storeConsoleSize(newSize.width(), newSize.height());

            /* Send new size-hint to the guest: */
            session().GetConsole().GetDisplay().SetVideoModeHint(newSize.width(), newSize.height(), 0, screenId());
        }

        /* We had requested resize now, rejecting other accident requests: */
        m_fShouldWeDoResize = false;
    }
}
Exemplo n.º 3
0
QWidget* QMainWindowProto::centralWidget () const
{
  QMainWindow *item = qscriptvalue_cast<QMainWindow*>(thisObject());
  if (item)
    return item->centralWidget();
  return 0;
}
Exemplo n.º 4
0
int main(int argc, char * argv[])
{
    QApplication app(argc, argv);

    ResourceManager resourceManager;
    resourceManager.addLoader(new QtTextureLoader());
    resourceManager.addStorer(new QtTextureStorer());

    // Initialize plugin manager
    PluginManager::init(QCoreApplication::applicationFilePath().toStdString());

    // Load example plugins
    PluginManager pluginManager;
#ifdef NDEBUG
    pluginManager.addPath("plugins");
#else
    pluginManager.addPath("plugins/debug");
#endif
    pluginManager.scan("painters");

    // Choose a painter
	std::string name = (argc > 1) ? argv[1] : "CubeScape";
    std::cout << "Trying to create painter '" << name << "'\n";

    gloperate::Painter * painter = nullptr;
    Plugin * plugin = pluginManager.plugin(name);

	if (!plugin)
	{
		globjects::fatal() << "Plugin '" << name << "' not found. Listing plugins found:";
		pluginManager.printPlugins();

		return 1;
	}

	painter = plugin->createPainter(resourceManager);

    // Create OpenGL window
    QSurfaceFormat format;
    format.setVersion(3, 2);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setDepthBufferSize(24);

	QtOpenGLWindow * window = new QtOpenGLWindow(resourceManager, format);
	window->setPainter(painter);

	QRect rect = QApplication::desktop()->screenGeometry(); // used to center the mainwindow on desktop

    // Create main window
    QMainWindow mainWindow;
	mainWindow.setGeometry((rect.width() - 1280) / 2, (rect.height() - 720) / 2, 1280, 720);
    mainWindow.setCentralWidget(QWidget::createWindowContainer(window));
    mainWindow.centralWidget()->setFocusPolicy(Qt::StrongFocus);

    mainWindow.show();

    return app.exec();
}
NativeRenderDialog::NativeRenderDialog(Document *aDoc, const CoordBox& aCoordBox, QWidget *parent)
    :QObject(parent), theDoc(aDoc), theOrigBox(aCoordBox)
{
    thePrinter = new QPrinter();
    thePrinter->setDocName(aDoc->title());

    mapview = new MapView(NULL);
    mapview->setDocument(theDoc);

    preview = new QPrintPreviewDialog( thePrinter, parent );
    QMainWindow* mw = preview->findChild<QMainWindow*>();
    prtW = dynamic_cast<QPrintPreviewWidget*>(mw->centralWidget());

    QWidget* myWidget = new QWidget(preview);
    ui.setupUi(myWidget);
    ui.verticalLayout->addWidget(prtW);
    mw->setCentralWidget(myWidget);

    /* Set the DPI validator to accept positive values only.  */
    dpiValidator = new QIntValidator( ui.fieldDpi );
    dpiValidator->setBottom( 0 );
    ui.fieldDpi->setValidator( dpiValidator );

    /* Set the UI parameters first, before we tie in the updatePreview signal/slot. */
    setBoundingBox(aCoordBox);
    setOptions(M_PREFS->getRenderOptions());

    /* Tie in the updatePreview slot to the UI. */
    connect(ui.cbShowNodes, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.cbShowRelations, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.cbShowGrid, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.cbShowScale, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.cbShowUnstyled, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.sbMinLat, SIGNAL(valueChanged(double)), prtW, SLOT(updatePreview()));
    connect(ui.sbMaxLat, SIGNAL(valueChanged(double)), prtW, SLOT(updatePreview()));
    connect(ui.sbMinLon, SIGNAL(valueChanged(double)), prtW, SLOT(updatePreview()));
    connect(ui.sbMaxLon, SIGNAL(valueChanged(double)), prtW, SLOT(updatePreview()));

    connect(ui.btExportPDF, SIGNAL(clicked()), SLOT(exportPDF()));
    connect(ui.btExportSVG, SIGNAL(clicked()), SLOT(exportSVG()));
    connect(ui.btExportRaster, SIGNAL(clicked()), SLOT(exportRaster()));

    connect( preview, &QPrintPreviewDialog::paintRequested,
             this,    &NativeRenderDialog::renderPreview );
}
bool WidgetEditorTool::handleDragEnterMoveEvent(QWidget *widget, QWidget * /*managedWidget*/, QDragMoveEvent *e, bool isEnter)
{
    const QDesignerMimeData *mimeData = qobject_cast<const QDesignerMimeData *>(e->mimeData());
    if (!mimeData)
        return false;

    if (!m_formWindow->hasFeature(QDesignerFormWindowInterface::EditFeature)) {
        e->ignore();
        return true;
    }

    if (isEnter)
        detectDockDrag(mimeData);


    QPoint globalPos = QPoint(0, 0);
    if (m_specialDockDrag) {
        m_lastDropTarget = 0;
        QMainWindow *mw = qobject_cast<QMainWindow*>(m_formWindow->mainContainer());
        if (mw)
            m_lastDropTarget = mw->centralWidget();
    } else {
        // If custom widgets have acceptDrops=true, the event occurs for them
        const QPoint formPos = widget != m_formWindow ? widget->mapTo(m_formWindow, e->pos()) : e->pos();
        globalPos = m_formWindow->mapToGlobal(formPos);
        const FormWindowBase::WidgetUnderMouseMode wum = mimeData->items().size() == 1 ? FormWindowBase::FindSingleSelectionDropTarget : FormWindowBase::FindMultiSelectionDropTarget;
        QWidget *dropTarget = m_formWindow->widgetUnderMouse(formPos, wum);
        if (m_lastDropTarget && dropTarget != m_lastDropTarget)
            m_formWindow->highlightWidget(m_lastDropTarget, m_lastDropTarget->mapFromGlobal(globalPos), FormWindow::Restore);
        m_lastDropTarget = dropTarget;
    }

    if (m_lastDropTarget)
        m_formWindow->highlightWidget(m_lastDropTarget, m_lastDropTarget->mapFromGlobal(globalPos), FormWindow::Highlight);

    if (isEnter || m_lastDropTarget)
        mimeData->acceptEvent(e);
    else
        e->ignore();
    return true;
}
Exemplo n.º 7
0
void
CQSplitterArea::
updateLayout()
{
  QMainWindow *mw = palette()->mgr()->window();

  if (mw)
    handle_->setParent(mw);

  handle_->setVisible(mw && palette_->isVisible() && isResizable() && ! isFloating());

  if (handle_->isVisible()) {
    QWidget *cw = mw->centralWidget();

//std::cerr << "CW: " << cw->x() << " " << cw->y() << " " << cw->width() << " " << cw->height() << std::endl;

    int hs = (isVerticalDockArea() ? handle_->width() : handle_->height());

    if      (dockArea() == Qt::LeftDockWidgetArea) {
      handle_->move  (cw->x() - hs, cw->y());
      handle_->resize(hs, height());
    }
    else if (dockArea() == Qt::RightDockWidgetArea) {
      handle_->move  (cw->x() + cw->width(), cw->y());
      handle_->resize(hs, height());
    }
    else if (dockArea() == Qt::TopDockWidgetArea) {
      handle_->move  (0, cw->y() - hs);
      handle_->resize(width(), hs);
    }
    else if (dockArea() == Qt::BottomDockWidgetArea) {
      handle_->move  (0, cw->y() + cw->height());
      handle_->resize(width(), hs);
    }

    handle_->raise();
  }

  splitter_->move(0, 0);
  splitter_->resize(width(), height());
}
Exemplo n.º 8
0
NativeRenderDialog::NativeRenderDialog(Document *aDoc, const CoordBox& aCoordBox, QWidget *parent)
    :QObject(parent), theDoc(aDoc), theOrigBox(aCoordBox)
{
    thePrinter = new QPrinter();
    thePrinter->setDocName(aDoc->title());

    mapview = new MapView(NULL);
    mapview->setDocument(theDoc);

    preview = new QPrintPreviewDialog( thePrinter, parent );
    QMainWindow* mw = preview->findChild<QMainWindow*>();
    prtW = dynamic_cast<QPrintPreviewWidget*>(mw->centralWidget());

    QWidget* myWidget = new QWidget(preview);
    ui.setupUi(myWidget);
    ui.verticalLayout->addWidget(prtW);
    mw->setCentralWidget(myWidget);

    connect(ui.cbShowNodes, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.cbShowRelations, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.cbShowGrid, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.cbShowScale, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.cbShowUnstyled, SIGNAL(toggled(bool)), prtW, SLOT(updatePreview()));
    connect(ui.sbMinLat, SIGNAL(valueChanged(double)), prtW, SLOT(updatePreview()));
    connect(ui.sbMaxLat, SIGNAL(valueChanged(double)), prtW, SLOT(updatePreview()));
    connect(ui.sbMinLon, SIGNAL(valueChanged(double)), prtW, SLOT(updatePreview()));
    connect(ui.sbMaxLon, SIGNAL(valueChanged(double)), prtW, SLOT(updatePreview()));

    connect(ui.btExportPDF, SIGNAL(clicked()), SLOT(exportPDF()));
    connect(ui.btExportSVG, SIGNAL(clicked()), SLOT(exportSVG()));
    connect(ui.btExportRaster, SIGNAL(clicked()), SLOT(exportRaster()));

    connect( preview, SIGNAL(paintRequested(QPrinter*)), SLOT(print(QPrinter*)) );
    setBoundingBox(aCoordBox);
    setOptions(M_PREFS->getRenderOptions());
}
Exemplo n.º 9
0
int main(int argc, char * argv[])
{
    // Read command line options
    cppassist::ArgumentParser argumentParser;
    argumentParser.parse(argc, argv);

    const auto contextString = argumentParser.value("--context");

    // Create gloperate environment
    Environment environment;
    environment.setupScripting();

    // Configure and load plugins
    environment.componentManager()->addPluginPath(
        gloperate::pluginPath(), cppexpose::PluginPathType::Internal
    );
    environment.componentManager()->scanPlugins();

    // Initialize Qt application
    gloperate_qt::Application app(&environment, argc, argv);

    // Create render window
    auto window = cppassist::make_unique<RenderWindow>(&environment);

    // Specify desired context format
    gloperate::GLContextFormat format;
    format.setVersion(3, 2);
    format.setProfile(gloperate::GLContextFormat::Profile::Core);
    format.setForwardCompatible(true);

    if (!contextString.empty())
    {
        if (!format.initializeFromString(contextString))
        {
            return 1;
        }
    }

    window->setContextFormat(format);

    auto windowRaw = window.get();
    window->createContext();
    window->canvas()->loadRenderStage("ShapeDemo");

    // Create main window
    QMainWindow mainWindow;
    mainWindow.setWindowTitle("gloperate viewer");
    mainWindow.resize(1280, 720);
    mainWindow.setCentralWidget(QWidget::createWindowContainer(window.release())); // pass ownership to Qt
    mainWindow.centralWidget()->setFocusPolicy(Qt::StrongFocus);
    mainWindow.show();

    // Create script console
    auto scriptPrompt = cppassist::make_unique<ScriptPromptWidget>(&mainWindow);
    scriptPrompt->setSyntaxHighlighter(cppassist::make_unique<ECMA26251SyntaxHighlighter>());
    scriptPrompt->setCompleter(cppassist::make_unique<ECMA26251Completer>());
    scriptPrompt->setFrameShape(QFrame::NoFrame);

    auto scriptPromptRaw = scriptPrompt.get();
    QObject::connect(scriptPrompt.get(), &ScriptPromptWidget::evaluate,
        [&environment, scriptPromptRaw] (const QString & cmd)
        {
            // Execute script code
            std::string code = cmd.toStdString();
            cppexpose::Variant res = environment.executeScript(code);

            // Output result
            scriptPromptRaw->print(QString::fromStdString(res.value<std::string>()));
        }
    );

    // Create dock window for scripting console
    auto scriptPromptDockWidget = cppassist::make_unique<QDockWidget>("Script Prompt");
    scriptPromptDockWidget->setWidget(scriptPrompt.release());
    scriptPromptDockWidget->setObjectName("ScriptPromptWidget");
    mainWindow.addDockWidget(Qt::DockWidgetArea::BottomDockWidgetArea, scriptPromptDockWidget.release());

    // Initialize context, print context info
    windowRaw->context()->use();
//  windowRaw->context()->setSwapInterval(Context::SwapInterval::VerticalSyncronization);
    cppassist::info() << std::endl
        << "OpenGL Version:  " << GLContextUtils::version() << std::endl
        << "OpenGL Profile:  " << GLContextUtils::profile() << std::endl
        << "OpenGL Vendor:   " << GLContextUtils::vendor() << std::endl
        << "OpenGL Renderer: " << GLContextUtils::renderer() << std::endl;
    windowRaw->context()->release();

    // Run main loop
    return app.exec();
}
Exemplo n.º 10
0
int main(int argc, char * argv[])
{
    QApplication app(argc, argv);

    ResourceManager resourceManager;
    resourceManager.addLoader(new QtTextureLoader());
    resourceManager.addStorer(new QtTextureStorer());

    PluginManager pluginManager;
    pluginManager.addSearchPath(QCoreApplication::applicationDirPath().toStdString());
    pluginManager.addSearchPath(QCoreApplication::applicationDirPath().toStdString() + "/plugins");
#ifdef NDEBUG
    pluginManager.scan("painters");
#else
    pluginManager.scan("paintersd");
#endif

    // Choose a painter
    std::unique_ptr<gloperate::Painter> painter(nullptr);

    std::string name = (argc > 1) ? argv[1] : "PostprocessingPipeline";

    Plugin * plugin = pluginManager.plugin(name);
    if (!plugin)
    {
        globjects::fatal() << "Plugin '" << name << "' not found. Listing plugins found:";
        pluginManager.printPlugins();

        return 1;
    }

    AbstractPainterPlugin * painterPlugin = dynamic_cast<AbstractPainterPlugin *>(plugin);
    if (!painterPlugin)
    {
        globjects::fatal() << "Plugin '" << name << "' is not a painter plugin.";

        return 1;
    }

    painter.reset(painterPlugin->createPainter(resourceManager));

    // Create Event Provider
    QtKeyEventProvider * keyProvider = new QtKeyEventProvider();
    QtMouseEventProvider * mouseProvider = new QtMouseEventProvider();
    QtWheelEventProvider * wheelProvider = new QtWheelEventProvider();

    // Create OpenGL window
    QSurfaceFormat format;
    format.setVersion(3, 2);
    format.setProfile(QSurfaceFormat::CoreProfile);
    format.setDepthBufferSize(16);

    QtOpenGLWindow * window = new QtOpenGLWindow(resourceManager, format);
    window->setPainter(painter.get());
    window->installEventFilter(keyProvider);
    window->installEventFilter(mouseProvider);
    window->installEventFilter(wheelProvider);

    // Create Mapping
    QtViewerMapping * mapping = new QtViewerMapping(window);
    mapping->setPainter(painter.get());
    mapping->addProvider(keyProvider);
    mapping->addProvider(mouseProvider);
    mapping->addProvider(wheelProvider);


    QRect rect = QApplication::desktop()->screenGeometry(); // used to center the mainwindow on desktop

    // Create main window
    QMainWindow mainWindow;
    mainWindow.setGeometry((rect.width() - 1280) / 2, (rect.height() - 720) / 2, 1280, 720);
    mainWindow.setCentralWidget(QWidget::createWindowContainer(window));
    mainWindow.centralWidget()->setFocusPolicy(Qt::StrongFocus);

    mainWindow.show();

    return app.exec();
}
Exemplo n.º 11
0
int main(int argc, char** argv) {
    LogCentral::init();
    LogCentral::getPtr()->registerLogger(new ConsoleLogger());

    std::string appName = "Inviwo v" + IVW_VERSION + " - QtApp";
    InviwoApplicationQt inviwoApp(appName, inviwo::filesystem::findBasePath(), argc, argv, false);
    inviwoApp.setAttribute(Qt::AA_NativeWindows);

    // Initialize all modules
    inviwoApp.initialize(&inviwo::registerAllModules);

    // Continue initialization of default context
    Canvas* sharedCanvas = RenderContext::getPtr()->getDefaultRenderContext();
    if (sharedCanvas) {
        sharedCanvas->initialize();
        sharedCanvas->activate();
    }

    // Set canvas as central widget
    QMainWindow mainWin;

    // Load workspace
    inviwoApp.getProcessorNetwork()->lock();
    const CommandLineParser* cmdparser = inviwoApp.getCommandLineParser();
    std::string workspace;

    if (cmdparser->getLoadWorkspaceFromArg())
        workspace = cmdparser->getWorkspacePath();
    else
#ifdef REG_INVIWOBASEGLMODULE
        workspace =
        inviwoApp.getPath(InviwoApplication::PATH_WORKSPACES, "/boron.inv");
#else
        workspace = "";
#endif

    try
    {
        if (!workspace.empty()) {
            IvwDeserializer xmlDeserializer(workspace);
            inviwoApp.getProcessorNetwork()->deserialize(xmlDeserializer);
            std::vector<Processor*> processors = inviwoApp.getProcessorNetwork()->getProcessors();

            for (auto processor : processors) {
                processor->invalidate(INVALID_RESOURCES);

                if (auto processorWidget =
                    ProcessorWidgetFactory::getPtr()->create(processor).release()) {
                    processorWidget->setProcessor(processor);
                    processorWidget->initialize();
                    processorWidget->setVisible(processorWidget->ProcessorWidget::isVisible());
                    processor->setProcessorWidget(processorWidget);

                    if (!mainWin.centralWidget()) {
                        mainWin.setCentralWidget(dynamic_cast<QWidget*>(processorWidget));
                    }
                }
            }
        }
    }
    catch (const AbortException& exception) {
        util::log(exception.getContext(),
            "Unable to load network " + workspace + " due to " + exception.getMessage(),
            LogLevel::Error);
        return 1;
    }
    catch (const IgnoreException& exception) {
        util::log(exception.getContext(),
            "Incomplete network loading " + workspace + " due to " + exception.getMessage(),
            LogLevel::Error);
        return 1;
    }
    catch (const ticpp::Exception& exception) {
        LogErrorCustom("qtminimum", "Unable to load network " + workspace + " due to deserialization error: " + exception.what());
        return 1;
    }

    inviwoApp.getProcessorNetwork()->setModified(true);
    inviwoApp.getProcessorNetwork()->unlock();

    if (cmdparser->getCaptureAfterStartup()) {
        std::string path = cmdparser->getOutputPath();

        if (path.empty()) path = inviwoApp.getPath(InviwoApplication::PATH_IMAGES);

        util::saveAllCanvases(inviwoApp.getProcessorNetwork(), path, cmdparser->getSnapshotName());
    }

    if (sharedCanvas)
        mainWin.resize(sharedCanvas->getScreenDimensions().x, sharedCanvas->getScreenDimensions().y);
    
    mainWin.show();

    if (cmdparser->getQuitApplicationAfterStartup()) {
        inviwoApp.closeInviwoApplication();
        inviwoApp.quit();
        return 0;
    }

    return inviwoApp.exec();
}