Example #1
0
TextDisplay::TextDisplay()
{
	text = new osgText::Text();
	textGeode = new osg::Geode();
	projectionMatrix = new osg::Projection;
	int x, y, width, height;
	((osgViewer::GraphicsWindow* )getViewer()->getCamera()->getGraphicsContext())->getWindowRectangle(x, y, width, height);
	projectionMatrix->setMatrix(osg::Matrix::ortho2D(x, windowWidth, y, windowHeight));
	viewMatrix = new osg::MatrixTransform;
	viewMatrix->setMatrix(osg::Matrix::identity());
	viewMatrix->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
	//root->addChild(projectionMatrix);
	addToSceneGraph(projectionMatrix);
	projectionMatrix->addChild(viewMatrix);
	viewMatrix->addChild(textGeode);
	textGeode->addDrawable(text);
	osg::StateSet* stateSet = new osg::StateSet();
	textGeode->setStateSet(stateSet);
	stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
	stateSet->setRenderBinDetails(11, "RenderBin");
	text->setAxisAlignment(osgText::Text::SCREEN);
	text->setPosition(osg::Vec3(0, height - 25, 0));
	text->setCharacterSize(25);
	text->setFont("fonts/arial.ttf");
	textGeode->setUpdateCallback(new TextGeodeCallback(this));
	setDefaultText();
}
Example #2
0
ChatbarTextEdit::ChatbarTextEdit(QWidget *p) : QTextEdit(p), iHistoryIndex(-1) {
	setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setMinimumHeight(0);
	connect(this, SIGNAL(textChanged()), SLOT(doResize()));

	bDefaultVisible = true;
	setDefaultText(tr("<center>Type chat message here</center>"));
}
Example #3
0
void PythonEditorWidget::buildWidget() {
    setWindowIcon(QIcon(":/icons/python.png"));
    QWidget* content = new QWidget(this);
    QVBoxLayout* verticalLayout = new QVBoxLayout(content);
    ////Create Buttons
    QHBoxLayout* horizontalLayout = new QHBoxLayout();
    QToolButton* runButton = new QToolButton(content);
    QToolButton* newButton = new QToolButton(content);
    QToolButton* openButton = new QToolButton(content);
    QToolButton* saveButton = new QToolButton(content);
    QToolButton* saveAsButton = new QToolButton(content);
    QPushButton* clearOutputButton = new QPushButton(content);
    runButton->setShortcut(QKeySequence(tr("F5")));
    runButton->setIcon(QIcon(":/icons/python.png"));
    runButton->setToolTip("Compile and run (F5)");
    newButton->setIcon(QIcon(":/icons/new.png"));
    newButton->setToolTip("New file (Ctrl+N)");
    openButton->setIcon(QIcon(":/icons/open.png"));
    openButton->setToolTip("Open Python script");
    saveButton->setIcon(QIcon(":/icons/save.png"));
    saveButton->setToolTip("Save (Ctrl+S)");
    saveAsButton->setIcon(QIcon(":/icons/saveas.png"));
    saveAsButton->setToolTip("Save as");
    clearOutputButton->setText("Clear Output");
   
    QFrame* line1 = new QFrame(content);
    line1->setFrameShape(QFrame::VLine);
    line1->setFrameShadow(QFrame::Sunken);
    QFrame* line2 = new QFrame(content);
    line2->setFrameShape(QFrame::VLine);
    line2->setFrameShadow(QFrame::Sunken);
    QFrame* line3 = new QFrame(content);
    line3->setFrameShape(QFrame::VLine);
    line3->setFrameShadow(QFrame::Sunken);
    horizontalLayout->addWidget(runButton);
    horizontalLayout->addWidget(line1);
    horizontalLayout->addWidget(newButton);
    horizontalLayout->addWidget(openButton);
    horizontalLayout->addWidget(saveButton);
    horizontalLayout->addWidget(saveAsButton);
    horizontalLayout->addWidget(line2);
    horizontalLayout->addWidget(clearOutputButton);
    horizontalLayout->addWidget(line3);
    QSpacerItem* horizontalSpacer =
        new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
    horizontalLayout->addItem(horizontalSpacer);
    // Done creating buttons
    QSplitter* splitter = new QSplitter(content);

    splitter->setOrientation(Qt::Vertical);
    pythonCode_ = new PythonTextEditor(content);
    pythonCode_->setObjectName("pythonEditor");
    pythonCode_->setUndoRedoEnabled(true);
    setDefaultText();
    pythonOutput_ = new QTextEdit(content);
    pythonOutput_->setObjectName("pythonConsole");
    pythonOutput_->setReadOnly(true);
    pythonOutput_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    syntaxHighligther_ =
        SyntaxHighligther::createSyntaxHighligther<Python>(pythonCode_->document());
    verticalLayout->addLayout(horizontalLayout);
    splitter->addWidget(pythonCode_);
    splitter->addWidget(pythonOutput_);
    splitter->setStretchFactor(0, 1);
    splitter->setStretchFactor(1, 0);
    splitter->setHandleWidth(2);
    // enable QSplitter:hover stylesheet 
    // QTBUG-13768 https://bugreports.qt.io/browse/QTBUG-13768
    splitter->handle(1)->setAttribute(Qt::WA_Hover);

    verticalLayout->addWidget(splitter);
    setWidget(content);
    connect(pythonCode_, SIGNAL(textChanged()), this, SLOT(onTextChange()));
    connect(runButton, SIGNAL(clicked()), this, SLOT(run()));
    connect(newButton, SIGNAL(clicked()), this, SLOT(setDefaultText()));
    connect(openButton, SIGNAL(clicked()), this, SLOT(open()));
    connect(saveButton, SIGNAL(clicked()), this, SLOT(save()));
    connect(saveAsButton, SIGNAL(clicked()), this, SLOT(saveAs()));
    connect(clearOutputButton, SIGNAL(clicked()), this, SLOT(clearOutput()));


    updateStyle();
    InviwoApplication::getPtr()->getSettingsByType<SystemSettings>()->pythonSyntax_.onChange(this, &PythonEditorWidget::updateStyle);
    InviwoApplication::getPtr()->getSettingsByType<SystemSettings>()->pyFontSize_.onChange(this, &PythonEditorWidget::updateStyle);
}
Example #4
0
void TextProperty::save()
{
	setDefaultText(mText);
	setModified(false);
}
ChatbarLineEdit::ChatbarLineEdit(QWidget *p) : QLineEdit(p) {
	bDefaultVisible = true;
	setDefaultText(tr("Type chat message here"));
}
PythonEditorWidget::PythonEditorWidget(InviwoMainWindow* ivwwin, InviwoApplication* app)
    : InviwoDockWidget(tr("Python Editor"), ivwwin)
    , settings_("Inviwo", "Inviwo")
    , infoTextColor_(153, 153, 153)
    , errorTextColor_(255, 107, 107)
    , runAction_(nullptr)
    , script_()
    , unsavedChanges_(false)
    , app_(app)
    , appendLog_(true)
{

    setObjectName("PythonEditor");
    settings_.beginGroup("PythonEditor");
    QString lastFile = settings_.value("lastScript", "").toString();
    appendLog_ = settings_.value("appendLog", appendLog_).toBool();
    settings_.endGroup();
    setVisible(false);
    setWindowIcon(QIcon(":/icons/python.png"));

    QMainWindow* mainWindow = new QMainWindow();
    mainWindow->setContextMenuPolicy(Qt::NoContextMenu);
    QToolBar* toolBar = new QToolBar();
    mainWindow->addToolBar(toolBar);
    toolBar->setFloatable(false);
    toolBar->setMovable(false);
    setWidget(mainWindow);

    {
        runAction_ = toolBar->addAction(QIcon(":/icons/python.png"), "Compile and Run");
        runAction_->setShortcut(QKeySequence(tr("F5")));
        runAction_->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        runAction_->setToolTip("Compile and Run Script");
        mainWindow->addAction(runAction_);
        connect(runAction_, &QAction::triggered, [this]() {run(); });
    }
    {
        auto action = toolBar->addAction(QIcon(":/icons/new.png"), tr("&New Script"));
        action->setShortcut(QKeySequence::New);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("New Script");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){setDefaultText();});
    }
    {
        auto action = toolBar->addAction(QIcon(":/icons/open.png"), tr("&Open Script"));
        action->setShortcut(QKeySequence::Open);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("Open Script");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){open();});
    }

    {
        auto action = toolBar->addAction(QIcon(":/icons/save.png"), tr("&Save Script"));
        action->setShortcut(QKeySequence::Save);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("Save Script");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){save();});
    }
    {
        auto action = toolBar->addAction(QIcon(":/icons/saveas.png"), tr("&Save Script As..."));
        action->setShortcut(QKeySequence::SaveAs);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("Save Script As...");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){saveAs();});
    }
    {
        QIcon icon;
        icon.addFile(":/icons/log-append.png", QSize(), QIcon::Normal, QIcon::On);
        icon.addFile(":/icons/log-clearonrun.png", QSize(), QIcon::Normal, QIcon::Off);

        QString str = (appendLog_ ? "Append Log" : "Clear Log on Run");
        auto action = toolBar->addAction(icon, str);
        action->setShortcut(Qt::ControlModifier + Qt::Key_E);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setCheckable(true);
        action->setChecked(appendLog_);
        action->setToolTip(appendLog_ ? "Append Log" : "Clear Log on Run");
        mainWindow->addAction(action);
        connect(action, &QAction::toggled, [this, action](bool toggle) { 
            appendLog_ = toggle; 
            // update tooltip and menu entry
            QString tglstr = (toggle ? "Append Log" : "Clear Log on Run");
            action->setText(tglstr);
            action->setToolTip(tglstr);
            // update settings
            settings_.beginGroup("PythonEditor");
            settings_.setValue("appendLog", appendLog_);
            settings_.endGroup();
        });
    }
    {
        auto action = toolBar->addAction(QIcon(":/icons/log-clear.png"), "Clear Log Output");
        action->setShortcut(Qt::ControlModifier + Qt::Key_E);
        action->setShortcutContext(Qt::WidgetWithChildrenShortcut);
        action->setToolTip("Clear Log Output");
        mainWindow->addAction(action);
        connect(action, &QAction::triggered, [this](){clearOutput();});
    }

    // Done creating buttons
    QSplitter* splitter = new QSplitter(nullptr);
    splitter->setOrientation(Qt::Vertical);
    pythonCode_ = new PythonTextEditor(nullptr);
    pythonCode_->setObjectName("pythonEditor");
    pythonCode_->setUndoRedoEnabled(true);
    setDefaultText();
    pythonOutput_ = new QTextEdit(nullptr);
    pythonOutput_->setObjectName("pythonConsole");
    pythonOutput_->setReadOnly(true);
    pythonOutput_->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    syntaxHighligther_ =
        SyntaxHighligther::createSyntaxHighligther<Python>(pythonCode_->document());

    splitter->addWidget(pythonCode_);
    splitter->addWidget(pythonOutput_);
    splitter->setStretchFactor(0, 1);
    splitter->setStretchFactor(1, 0);
    splitter->setHandleWidth(2);
    // enable QSplitter:hover stylesheet
    // QTBUG-13768 https://bugreports.qt.io/browse/QTBUG-13768
    splitter->handle(1)->setAttribute(Qt::WA_Hover);
    mainWindow->setCentralWidget(splitter);

    QObject::connect(pythonCode_, SIGNAL(textChanged()), this, SLOT(onTextChange()));
    // close this window before the main window is closed
    QObject::connect(ivwwin, &InviwoMainWindow::closingMainWindow, [this]() { delete this; });

    this->updateStyle();

    
    this->resize(500, 700);

    if (app_) {
        app_->getSettingsByType<SystemSettings>()->pythonSyntax_.onChange(
            this, &PythonEditorWidget::updateStyle);
        app_->getSettingsByType<SystemSettings>()->pyFontSize_.onChange(
            this, &PythonEditorWidget::updateStyle);
        app_->registerFileObserver(this);
    }
    unsavedChanges_ = false;

    if (lastFile.size() != 0) loadFile(lastFile.toLocal8Bit().constData(), false);

    setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    setFloating(true);
}