示例#1
0
TEST(LuaUIOperationsTest, Rotate) {
	QApplication app(argc, argv);
	LuaInterface luaInterface;
	auto L = luaInterface.luaState();

	luaInterface.hideUI(true);
	luaInterface.initLua();

	auto mdiArea = LuaIntf::Lua::getGlobal<QMdiArea*>(L, "mdiArea");

	if(mdiArea->subWindowList().count() == 0) {
		LuaIntf::LuaRef(L, "new_file")();
	}

	mdiArea->setActiveSubWindow(mdiArea->subWindowList().at(0));

	auto mdiChild = dynamic_cast<CadMdiChild*>(mdiArea->activeSubWindow()->widget());
	auto storageManager = mdiChild->storageManager();
	auto documentCanvas = mdiChild->viewer()->documentCanvas();

	lc::entity::Line_CSPtr createdEntity;
	std::vector<lc::entity::CADEntity_CSPtr> entities;

	entities = storageManager->entityContainer().asVector();

	for(auto entity : entities) {
		storageManager->removeEntity(entity);
	}

	EXPECT_EQ(0, storageManager->entityContainer().asVector().size());



	LuaIntf::LuaRef(L, "create_line")();
	LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
	LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 100));

	EXPECT_EQ(1, storageManager->entityContainer().asVector().size()) << "Line was not created";



	documentCanvas->makeSelection(0, 0, 100, 100, false, false);
	documentCanvas->closeSelection();

	EXPECT_EQ(1, mdiChild->selection().size()) << "Entity not selected";



	LuaIntf::LuaRef(L, "rotate_selected_entities")();
	LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 0));
	LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(0, 100));
	LuaIntf::LuaRef(L, "event.trigger")("point", lc::geo::Coordinate(100, 0));

	entities = storageManager->entityContainer().asVector();
	createdEntity = std::dynamic_pointer_cast<const lc::entity::Line>(entities.at(0));

	EXPECT_EQ(lc::geo::Coordinate(0, 0), createdEntity->start());
	EXPECT_EQ(lc::geo::Coordinate(100, -100), createdEntity->end());
}
示例#2
0
void CWindowStack::activateNextSubWindow()
{
    if (subWindowList.count()>1)
    {
        int index=activeIndex+1;
        if (index>=subWindowList.count()) index=0;
        setActiveSubWindow(subWindowList[index]);
    }
}
示例#3
0
void CWindowStack::activatePreviousSubWindow()
{
    if (subWindowList.count()>1)
    {
        int index=activeIndex-1;
        if (index<0) index=subWindowList.count()-1;
        setActiveSubWindow(subWindowList[index]);
    }
}
示例#4
0
QWidget* CWindowStack::addSubWindow(QWidget *sw)
{
    subWindowList.append(sw);
    this->layout()->addWidget(sw);
    sw->setVisible(false);
    sw->disconnect();
    sw->setEnabled(false);
    setActiveSubWindow(sw);
    return sw;
}
示例#5
0
//TODO: debug, this seems circular, maybe not necessary
void CodeArea::selectRevision(Revision *r)
{
    QMdiSubWindow *sub = subWindowMap[r];

    //if we closed the window and it is invisible, make it visible
    if ( sub && !sub->isVisible() )
    {
        sub->show(); sub->widget()->show();
    }

    setActiveSubWindow( sub );
}
示例#6
0
void CWindowStack::removeSubWindow(QWidget *sw)
{
    int index=subWindowList.indexOf(sw);
    if (index>-1)
    {
        sw->disconnect();
        subWindowList.removeAt(index);
        delete sw;
        activeIndex=-1;
    }
    if (subWindowList.count()) setActiveSubWindow(subWindowList.first());
    emit subWindowActivated(0);
}
示例#7
0
QWidget* CWindowStack::closeSubWindow(QWidget *sw)
{
    if (subWindowList.count()<2) return sw;
    int index=subWindowList.indexOf(sw);
    if (index>-1)
    {
        if (!sw->close()) return sw;
        sw->disconnect();
        subWindowList.removeAt(index);
        delete sw;
        activeIndex=-1;
        if (subWindowList.count()) return setActiveSubWindow(subWindowList.first());
        emit subWindowActivated(0);
        return 0;
    }
    return sw;
}
示例#8
0
void CodeArea::addCodeWindow(Revision *r, QString fileText, int cursorPos = 0)
{
    //setup the widget
    CodeEdit *edit = new CodeEdit(this);
    edit->setPlainText( fileText );
    edit->rev = r;

    //set highlighter no matter what language, dirty hack
    SuperWordHighlighter *wh =
            new SuperWordHighlighter(edit->document());

    //setup the subwindow
    QMdiSubWindow *subWindow = addSubWindow( edit );
    subWindow->showMaximized();
    subWindow->setWindowTitle( edit->rev->getBufferName() );

    //don't delete windows when closed
    subWindow->setAttribute(Qt::WA_DeleteOnClose, false);

    //add to subwindow maps
    subWindowMap[r] = subWindow;
    subWindowMap2[subWindow] = r;

    //save the position, so that it may be restored
    if ( cursorPos > 0 )
    {
        QTextCursor cursor = edit->textCursor();
        cursor.setPosition( cursorPos );
        edit->setTextCursor( cursor );
    }

    notifyNewRevision(r);

    //listen changes
    edit->listenChanges();

    //edit->focusWidget();
    setActiveSubWindow( subWindow );

    //listen to zoom changes
    connect( this, SIGNAL(updateZoom(int)), edit, SLOT(onZoomChanged(int)) );

}
//-----------------------------------------------------------------------------------------
bool GenericTextEditor::displayText(QString docName, QString text, QString extension, QString optionalData)
{
    // If there is no extra extension passed, then try to find the matching one based on the doc name
    ITextEditorCodecFactory* codecFactory;
    if(extension == "")    
        codecFactory = GenericTextEditor::findMatchingCodecFactory(docName);
    else
        codecFactory = GenericTextEditor::findMatchingCodecFactory(extension);

    if(codecFactory == 0)
        return false;

    GenericTextEditorDocument* document = 0;
    if(!isDocAlreadyShowing(docName, document) || isAllowDoubleDisplay())
    {
        document = new GenericTextEditorDocument(this);
        ITextEditorCodec* codec = codecFactory->create(document, docName);
        document->setCodec(codec);
        document->displayText(docName, text, optionalData);
        QMdiSubWindow *window = addSubWindow(document);
        window->setWindowIcon(QIcon(codec->getDocumentIcon()));
        document->showMaximized();
        QTabBar* tabBar = findChildren<QTabBar*>().at(0);
        tabBar->setTabToolTip(findChildren<QMdiSubWindow*>().size() - 1, docName);    
    }
    else
    {
        document->getCodec()->setOptionalData(optionalData);
        document->getCodec()->onDisplayRequest();
        setActiveSubWindow(qobject_cast<QMdiSubWindow*>(document->window()));
        document->setFocus(Qt::ActiveWindowFocusReason);
    }

    moveToForeground();

    connect(document, SIGNAL(textChanged()), document, SLOT(documentWasModified()));
    mActSave->setEnabled(false);

    return true;
}
//-----------------------------------------------------------------------------------------
bool GenericTextEditor::displayTextFromFile(QString filePath, QString optionalData)
{
    ITextEditorCodecFactory* codecFactory = GenericTextEditor::findMatchingCodecFactory(filePath);

    if(codecFactory == 0)
       return false;    
    
    GenericTextEditorDocument* document = 0;
    if(!isPathAlreadyShowing(filePath, document) || isAllowDoubleDisplay())
    {
        document = new GenericTextEditorDocument(this);
        ITextEditorCodec* codec = codecFactory->create(document, filePath);
        document->setCodec(codec);
        document->displayTextFromFile(QFile(filePath).fileName(), filePath, optionalData);
        QMdiSubWindow *window = addSubWindow(document);
        window->setWindowIcon(QIcon(codec->getDocumentIcon()));
        document->showMaximized();
        QTabBar* tabBar = findChildren<QTabBar*>().at(0);
        tabBar->setTabToolTip(findChildren<QMdiSubWindow*>().size() - 1, QFile(filePath).fileName());   
    }
    else
    {
        document->getCodec()->setOptionalData(optionalData);
        document->getCodec()->onDisplayRequest();
        setActiveSubWindow(qobject_cast<QMdiSubWindow*>(document->window()));
        document->setFocus(Qt::ActiveWindowFocusReason);
    }

    moveToForeground();   

    connect(document, SIGNAL(textChanged()), document, SLOT(documentWasModified()));
    
    mActSave->setEnabled(false);

    return true;
}
void PalettePreviewMdiArea::setInactiveState()
{
    setActiveSubWindow(0);
    mDemoWidget->setEnabled(true);
}
void PalettePreviewMdiArea::setDisabledState()
{
    setActiveSubWindow(mDemoWidget);
    mDemoWidget->setEnabled(false);
}