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() ); }
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); this->setWindowState(this->windowState() ^ Qt::WindowFullScreen); QGraphicsView *view = ui->graphicsView; view->setScene(&scene); view->setWindowFlags (Qt::FramelessWindowHint); view->setAlignment(Qt::AlignLeft | Qt::AlignTop); view->setRenderHint(QPainter::Antialiasing); view->setMaximumSize(size()); view->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); view->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); view->setCacheMode(QGraphicsView::CacheBackground); QGMenu *menu = new QGMenu(view->rect()); //menu->setOpacity(0); scene.addItem(menu); int size = 152 + 16; for (int i = 0; i < 20 ;i++) { int r = i / 5; int c = i % 5; QGTile *tile = new QGTile; scene.addItem(tile); tile->moveBy(c * size, r * size); tile->installSceneEventFilter(menu); } menu->setZValue(100); // QGraphicsItem *ball = new QGraphicsEllipseItem(0, 0, 20, 20); // QTimeLine *timer = new QTimeLine(5000); // timer->setFrameRange(0, 100); // QGraphicsItemAnimation *animation = new QGraphicsItemAnimation; // animation->setItem(ball); // animation->setTimeLine(timer); // for (int i = 0; i < 200; ++i) // animation->setPosAt(i / 200.0, QPointF(i, i)); // scene.addItem(ball); // timer->start(); }
void MainWindowController::addArrow(int x, int y, int arrow) { int index = (y*view->getGridW())+x; int count = 0; //Count to the subsquare number for( int i = 0; i< index; i++) { count+= view->getSquareContainer()[i].count(); } QGraphicsView* v = (* (view->getSquareView()) )[count]; SquareScene* s = (* (view->getSquareScene()) )[count]; s->addPath(view->getArrows()[arrow]); switch(arrow) { case Grid::horiz: v->setAlignment(Qt::AlignLeft); break; case Grid::vert: v->setAlignment(Qt::AlignTop); break; } v->repaint(); }
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); }
void PieceAppearanceWidget::setupUI() { QLayout * lay = new QGridLayout( this ); lay->setSpacing(0); lay->setContentsMargins(0,0,0,0); QGraphicsView * v = this->impl->gv = //new QGraphicsView( impl->gs.scene() ) new QBoardView( impl->gs ) ; v->setTransformationAnchor(QGraphicsView::NoAnchor); #if 0 v->setAlignment(Qt::AlignLeft | Qt::AlignTop); v->setInteractive(true); // required to get mouse events to the children v->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); v->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); v->setDragMode(QGraphicsView::RubberBandDrag); v->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); #endif v->setBackgroundBrush(QColor("#abb8fb")); v->viewport()->setObjectName( "PieceAppearanceWidget"); lay->addWidget( v ); QStringList tip; tip << "<html><body>These widgets are appearance templates for game pieces.\n" << "Edit them by right-clicking them.\n" << "Select a template by left-clicking it. " << "QBoard will use the selected template as the default look\n" << "for newly-added pieces which are loaded from image files.\n" << "This list will be saved automatically when QBoard exits,\n" << "and loaded when QBoard starts up.</body></html>" ; impl->gv->setToolTip( tip.join("") ); }
int test_1_shape_ ( Main_Form *b ) { QTextStream std_out ( stdout ); QTextStream std_in ( stdin ); QTransform transform ( 1, 0, 0, 0, -1, 0, 0, 0, 1 ); transform.scale ( 0.5, 0.5 ); QGraphicsView* grView = b->graphicsView; grView->setAlignment ( 0 ); //Qt::AlignLeft | Qt::AlignTop grView->setTransform ( transform ); QGraphicsScene *grScene = new QGraphicsScene; grView->setScene ( grScene ); grView->setTransform ( transform ); grView->setRenderHints ( QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing ); int i = 1000; forma_l * a = new forma_l; forma *form = a->get_m_forma(); QList<shapes*>* sh_list = form->get_m_shapes(); sh_list->clear(); shape_e* she_0 = new shape_e(); sh_list->append ( she_0 ); shape_7* sh7_0 = new shape_7 ( 450 ); sh_list->append ( sh7_0 ); shape_56* sh56_0 = new shape_56 ( true ); sh_list->append ( sh56_0 ); shape_b* shb_0 = new shape_b ( 220, -30, -120, -1 ); sh_list->append ( shb_0 ); shape_* sh_0 = new shape_; sh_0->set_length ( 14 ); sh_0->set_sixtant ( 0 ); sh_list->append ( sh_0 ); shape_34* sh34_0 = new shape_34; sh34_0->set_scale_up ( true ); sh34_0->set_scale_factor ( 4 ); sh_list->append ( sh34_0 ); shape_12* sh12_0 = new shape_12 ( false ); sh_list->append ( sh12_0 ); shape_* sh_1 = new shape_; sh_1->set_length ( 14 ); sh_1->set_sixtant ( 4 ); sh_list->append ( sh_1 ); shape_12* sh12_1 = new shape_12 ( true ); sh_list->append ( sh12_1 ); shape_89* sh89_0 = new shape_89; sh89_0->set_xy ( 0, 20, 20 ); sh89_0->append ( -20, 20 ); sh89_0->append ( -20, -20 ); sh89_0->append ( 20, -20 ); sh_list->append ( sh89_0 ); shape_56* sh56_1 = new shape_56 ( false ); sh_list->append ( sh56_1 ); shape_a* sha_0 = new shape_a; sha_0->set_radius ( 120 ); sha_0->set_start ( 0 ); sha_0->set_number ( -1 ); sh_list->append ( sha_0 ); shape_cd* shcd_0 = new shape_cd; shcd_0->set_xy_c ( 0, 20, 20, 127 ); shcd_0->append ( -20, 20, 127 ); shcd_0->append ( -20, -20, 127 ); shcd_0->append ( 20, -20, 127 ); sh_list->append ( shcd_0 ); draw_vars dr; stack st; a->draw ( dr, st, *grScene ); { draw_point p_center ( 0.0, 0.0 ); draw_point p_radius ( 3.5, 3.5 ); grScene->addEllipse ( p_center.x - p_radius.x / 2., p_center.y - p_radius.y / 2., p_radius.x, p_radius.y, QPen ( Qt::red ) ); } std_out << a->out() << endl; forma_l *bb = new forma_l; *bb = *a; std_out << endl; std_out << endl; std_out << bb->out() << endl; delete bb; }
void JobViewServer::setupUi() { // Paar allgemeine Parameter setBackgroundHints(DefaultBackground); setHasConfigurationInterface(true); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); resize(400, 80); // Rahmen, der das Hauptlayout enthält Plasma::Frame* frame = new Plasma::Frame(); frame->setFrameShadow(Plasma::Frame::Sunken); QGraphicsLinearLayout* fullSpaceLayout = new QGraphicsLinearLayout(); fullSpaceLayout->setContentsMargins(0,0,0,0); setLayout(fullSpaceLayout); fullSpaceLayout->addItem(frame); QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(); layout->setContentsMargins(0,0,0,0); frame->setLayout(layout); // Icon mit History und Queue Indicator iconWidget = new Plasma::IconWidget(); iconWidget->setPreferredWidth(25); iconWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); iconWidget->setIcon(KIcon("arrow-down")); layout->addItem(iconWidget); // Layout mit Progressbars meterContainer = new Plasma::Label(); meterContainer->nativeWidget()->setWordWrap(true); meterLayout = new QGraphicsLinearLayout(); meterContainer->setLayout(meterLayout); layout->addItem(meterContainer); // Popup erzeugen popup = new Plasma::Dialog(); QVBoxLayout* popupLayout = new QVBoxLayout(); popupLayout->setContentsMargins(0,0,0,0); popup->setLayout(popupLayout); popup->setWindowFlags(Qt::Popup); popup->resize(400, 300); // GraphicsView und GraphicsScene erzeugen QGraphicsScene* popupScene = new QGraphicsScene(); QGraphicsView* popupView = new QGraphicsView(); popupView->setScene(popupScene); popupView->setFrameStyle(QFrame::NoFrame); popupView->setStyleSheet("background-color: transparent;"); popupView->setAlignment(Qt::AlignHCenter | Qt::AlignTop); popupView->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); popupView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); popupLayout->addWidget(popupView); // Container mit dem GridLayout zur Scene hinzufügen jobViewContainer = new QGraphicsWidget(); jobViewLayout = new QGraphicsLinearLayout(Qt::Vertical); jobViewLayout->setContentsMargins(5,5,5,5); jobViewContainer->setLayout(jobViewLayout); popupScene->addItem(jobViewContainer); // Überschrift-/Nachrichtenbereich popupHeadline = new Plasma::Label(); popupHeadline->nativeWidget()->setAlignment(Qt::AlignCenter); jobViewLayout->addItem(popupHeadline); QObject::connect(iconWidget, SIGNAL(clicked()), this, SLOT(showPopup())); }
MainWindow::MainWindow() : QMainWindow() { //CSS codes... this->setStyleSheet("background-color:gray;"); // // add drop down menus QMenu* fileMenu = menuBar()->addMenu( "&File" ); //QMenu* editMenu = menuBar()->addMenu( "&Edit" ); //QMenu* viewMenu = menuBar()->addMenu( "&View" ); //menuBar()->addMenu( "&Simulate" ); //menuBar()->addMenu( "&Help" ); // create file menu options //QAction* newAction = fileMenu->addAction( "&New", this, SLOT(fileNew()) ); //QAction* saveAction = fileMenu->addAction( "&Save As...", this, SLOT(fileSaveAs()) ); //QAction* openAction = fileMenu->addAction( "&Open ...", this, SLOT(fileOpen()) ); //fileMenu->addSeparator(); //QAction* previewAction = fileMenu->addAction( "Print pre&view...", this, SLOT(filePrintPreview()) ); //QAction* printAction = fileMenu->addAction( "&Print...", this, SLOT(filePrint()) ); //fileMenu->addSeparator(); fileMenu->addAction( "&Quit", this, SLOT(close()) ); //newAction->setShortcut( QKeySequence::New ); //saveAction->setShortcut( QKeySequence::Save ); //openAction->setShortcut( QKeySequence::Open ); //printAction->setShortcut( QKeySequence::Print ); // create undo stack and associated menu actions m_undoStack = new QUndoStack( this ); m_undoView = 0; //viewMenu->addAction( "Undo stack", this, SLOT(showUndoStack()) ); QAction* undoAction = m_undoStack->createUndoAction( this ); QAction* redoAction = m_undoStack->createRedoAction( this ); undoAction->setShortcut( QKeySequence::Undo ); redoAction->setShortcut( QKeySequence::Redo ); //editMenu->addAction( undoAction ); //editMenu->addAction( redoAction ); // create toolbar, set icon size, and add actions //QToolBar* toolBar = addToolBar( "Standard" ); QStyle* style = this->style(); QSize size = style->standardIcon(QStyle::SP_DesktopIcon).actualSize( QSize(99,99) ); //toolBar->setIconSize( size ); //newAction->setIcon( style->standardIcon(QStyle::SP_DesktopIcon) ); //openAction->setIcon( style->standardIcon(QStyle::SP_DialogOpenButton) ); //saveAction->setIcon( style->standardIcon(QStyle::SP_DialogSaveButton) ); //previewAction->setIcon( style->standardIcon(QStyle::SP_FileDialogContentsView) ); //printAction->setIcon( style->standardIcon(QStyle::SP_ComputerIcon) ); //undoAction->setIcon( style->standardIcon(QStyle::SP_ArrowBack) ); //redoAction->setIcon( style->standardIcon(QStyle::SP_ArrowForward) ); //toolBar->addAction( newAction ); //toolBar->addAction( openAction ); //toolBar->addAction( saveAction ); //toolBar->addSeparator(); //toolBar->addAction( previewAction ); //toolBar->addAction( printAction ); //toolBar->addSeparator(); //toolBar->addAction( undoAction ); //toolBar->addAction( redoAction ); // create scene and central widget view of scene m_scene = new Scene( m_undoStack ); QGraphicsView* view = new QGraphicsView( m_scene ); view->setAlignment( Qt::AlignLeft | Qt::AlignTop ); view->setFrameStyle( 0 ); setCentralWidget( view ); // connect message signal from scene to showMessage slot connect( m_scene, SIGNAL(message(QString)), this, SLOT(showMessage(QString)) ); // add status bar message statusBar()->showMessage("You are now attempting in vain to evade several murderous asteroids. Survive if possible. "); //sets window size by default setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT); }