Beispiel #1
0
GenericCodeEditor::GenericCodeEditor( Document *doc, QWidget *parent ):
    QPlainTextEdit( parent ),
    mDoc(doc),
    mEditorBoxIsActive(false),
    mLastCursorBlock(-1)
{
    Q_ASSERT(mDoc != 0);

    setFrameShape(QFrame::NoFrame);

    viewport()->setAttribute( Qt::WA_MacNoClickThrough, true );

    mLineIndicator = new LineIndicator(this);
    mLineIndicator->move( contentsRect().topLeft() );

    mOverlay = new QGraphicsScene(this);

    QPalette overlayPalette;
    overlayPalette.setBrush(QPalette::Base, Qt::NoBrush);

    QGraphicsView *overlayView = new QGraphicsView(mOverlay, this);
    overlayView->setFrameShape( QFrame::NoFrame );
    overlayView->setPalette(overlayPalette);
    overlayView->setFocusPolicy( Qt::NoFocus );
    overlayView->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    overlayView->setSceneRect(QRectF(0,0,1,1));
    overlayView->setAlignment(Qt::AlignLeft | Qt::AlignTop);

    mOverlayWidget = overlayView;

    mOverlayAnimator = new OverlayAnimator(this, mOverlay);

    connect( mDoc, SIGNAL(defaultFontChanged()), this, SLOT(onDocumentFontChanged()) );

    connect( this, SIGNAL(blockCountChanged(int)),
             mLineIndicator, SLOT(setLineCount(int)) );

    connect( mLineIndicator, SIGNAL( widthChanged() ),
             this, SLOT( updateLayout() ) );

    connect( this, SIGNAL(updateRequest(QRect,int)),
             this, SLOT(updateLineIndicator(QRect,int)) );

    connect( this, SIGNAL(selectionChanged()),
             mLineIndicator, SLOT(update()) );
    connect(this, SIGNAL(selectionChanged()), this, SLOT(updateDocLastSelection()));
    connect( this, SIGNAL(cursorPositionChanged()),
             this, SLOT(onCursorPositionChanged()) );

    connect( Main::instance(), SIGNAL(applySettingsRequest(Settings::Manager*)),
             this, SLOT(applySettings(Settings::Manager*)) );

    QTextDocument *tdoc = doc->textDocument();
    QPlainTextEdit::setDocument(tdoc);
    onDocumentFontChanged();
    doc->setLastActiveEditor(this);

    applySettings( Main::settings() );
}
Beispiel #2
0
GenericCodeEditor::GenericCodeEditor( Document *doc, QWidget *parent ):
    QPlainTextEdit( parent ),
    mDoc(doc)
{
    Q_ASSERT(mDoc != 0);

    setFrameShape( QFrame::NoFrame );

    mLineIndicator = new LineIndicator(this);
    mLineIndicator->move( contentsRect().topLeft() );

    mOverlay = new QGraphicsScene(this);

    QGraphicsView *overlayView = new QGraphicsView(mOverlay, this);
    overlayView->setFrameShape( QFrame::NoFrame );
    overlayView->setBackgroundBrush( Qt::NoBrush );
    overlayView->setStyleSheet("background: transparent");
    overlayView->setFocusPolicy( Qt::NoFocus );
    overlayView->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    overlayView->setSceneRect(QRectF(0,0,1,1));
    overlayView->setAlignment(Qt::AlignLeft | Qt::AlignTop);

    mOverlayWidget = overlayView;

    connect( mDoc, SIGNAL(defaultFontChanged()), this, SLOT(onDocumentFontChanged()) );

    connect( this, SIGNAL(blockCountChanged(int)),
             mLineIndicator, SLOT(setLineCount(int)) );

    connect( mLineIndicator, SIGNAL( widthChanged() ),
             this, SLOT( updateLayout() ) );

    connect( this, SIGNAL(updateRequest(QRect,int)),
             this, SLOT(updateLineIndicator(QRect,int)) );

    connect( this, SIGNAL(selectionChanged()),
             mLineIndicator, SLOT(update()) );

    connect( Main::instance(), SIGNAL(applySettingsRequest(Settings::Manager*)),
             this, SLOT(applySettings(Settings::Manager*)) );

    QTextDocument *tdoc = doc->textDocument();
    QPlainTextEdit::setDocument(tdoc);
    onDocumentFontChanged();
    mLineIndicator->setLineCount(blockCount());

    applySettings( Main::settings() );
}
/**
  Add a square to the grid
 * @brief MainWindow::addSquare
 * @param definition
 * @param i
 * @param j
 * @param arrowIndex
 */
void MainWindowController::addSquare(int definition, int x, int y) {
    int index = (y*view->getGridW())+x;
    view->getSquareContainer()[index].setSizeConstraint(QLayout::SetFixedSize);
    int defNum = -1;
    if(definition != 0)
        defNum = this->counter;
    SquareScene* scene = new SquareScene(defNum, x, y);
    QGraphicsView* gview = new QGraphicsView(scene);


    gview->setFixedSize(50,50);
    gview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    gview->setFocusPolicy(Qt::ClickFocus);
    gview->setAlignment(Qt::AlignLeft | Qt::AlignTop);

    if(definition >= 1) {
        addDefinitionSquare(gview, scene);
    }
    else {
        //Make connections for standardSquare
        connect(scene, SIGNAL(clicked(SquareScene*)), this, SLOT(slotClickStdSquare(SquareScene*)));
        connect(scene, SIGNAL(letterkeypress(SquareScene*,QString)), this, SLOT(slotLetterKeyPress(SquareScene*,QString)) );
        connect(scene, SIGNAL(delkeypress(SquareScene*)), this, SLOT(slotDelKeyPress(SquareScene*)) );
        connect(scene, SIGNAL(leftClicked(SquareScene*,QPoint)), this, SLOT(slotLeftClickStd(SquareScene*,QPoint)));

    }
    view->getSquareContainer()[index].addWidget(gview);
    if(definition == 2) {
        SquareScene* scene2 = new SquareScene(this->counter,x ,y, true);
        QGraphicsView* gview2 = new QGraphicsView(scene2);
        gview->setFixedSize(50,25);
        gview2->setFixedSize(50,25);
        gview2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        gview2->setAlignment(Qt::AlignLeft | Qt::AlignTop);
        gview2->setFocusPolicy(Qt::ClickFocus);
        addDefinitionSquare(gview2, scene2);
        view->getSquareContainer()[index].addWidget(gview2);
        ( *(view->getSquareView()) ).push_back(gview2);
        ( *(view->getSquareScene()) ).push_back(scene2);
    }
    view->getSquareView()->push_back(gview);
    view->getSquareScene()->push_back(scene);

    view->getUi()->gameLayout->addLayout(&(view->getSquareContainer())[index], y, x);

}