Ejemplo n.º 1
0
    public MyWidget(QWidget parent) : base(parent)
    {
        QPushButton quit = new QPushButton("Quit");

        Connect(quit,SIGNAL("clicked()"),qApp,SLOT("quit()"));

        LCDRange angle = new LCDRange();

        angle.SetRange(5,70);
        CannonField field = new CannonField();

        Connect(angle,SIGNAL("valueChanged(int)"),field,SLOT("setAngle(int)"));
        Connect(field,SIGNAL("angleChanged(int)"),angle,SLOT("setValue(int)"));

        QGridLayout gridLayout = new QGridLayout();

        gridLayout.AddWidget(quit,0,0);
        gridLayout.AddWidget(angle,1,0);
        gridLayout.AddWidget(field,1,1,2,1);
        gridLayout.SetColumnStretch(1,10);
        SetLayout(gridLayout);

        angle.SetValue(60);
        angle.SetFocus();
    }
Ejemplo n.º 2
0
        private void InitUI()
        {
            QGridLayout grid = new QGridLayout(this);

            QLabel labelName = new QLabel("Name", this);
            QLineEdit lineEdit = new QLineEdit(this);
            QTextEdit textEdit = new QTextEdit(this);
            QPushButton btnOk = new QPushButton("Ok", this);
            QPushButton btnCancel = new QPushButton("Cancel", this);

            /*
             * In our scenario, the grid will have totally four columns and three rows. We would add
             * and make the widgets to span in the grid as needed.
             */

            //Add Name label at row 1 - Column 1
            grid.AddWidget(labelName, 0, 0);

            //Add line Edit at row 1 - Column 2 with row span 1 and column span 4
            grid.AddWidget(lineEdit, 0, 1 , 1, 3);

            //Add textEdit at row2 - column 1 with row span 1 and column span 4
            grid.AddWidget(textEdit, 1, 0, 1, 4);

            //Add a stretch at row 3 - column 2 to make the btn move right
            grid.SetColumnStretch(1, 1);

            //Add Ok Btn at row 3 - Column 3
            grid.AddWidget(btnOk, 2, 2);

            //Add Cancel Btn at row 3 - Column 4
            grid.AddWidget(btnCancel, 2, 3);
        }
Ejemplo n.º 3
0
    public MyWidget(QWidget parent) : base(parent)
    {
        QPushButton quit = new QPushButton("&Quit");

        quit.Font = new QFont("Times", 18, (int)QFont.Weight.Bold);

        Connect(quit, SIGNAL("clicked()"), qApp, SLOT("quit()"));

        LCDRange angle = new LCDRange(null);

        angle.setRange(5,70);

        LCDRange force = new LCDRange(null);

        force.setRange(10,50);

        CannonField cannonField = new CannonField(null);

        Connect(angle,SIGNAL("valueChanged(int)"),
                cannonField,SLOT("setAngle(int)"));
        Connect(cannonField,SIGNAL("angleChanged(int)"),
                angle,SLOT("setValue(int)"));

        Connect(force,SIGNAL("valueChanged(int)"),
                cannonField,SLOT("setForce(int)"));
        Connect(cannonField,SIGNAL("forceChanged(int)"),
                force,SLOT("setValue(int)"));

        QPushButton shoot = new QPushButton("&Shoot");

        shoot.Font = new QFont("Times",18,(int)QFont.Weight.Bold);

        Connect(shoot,SIGNAL("clicked()"),cannonField,SLOT("shoot()"));

        QHBoxLayout topLayout = new QHBoxLayout();

        topLayout.AddWidget(shoot);
        topLayout.AddStretch(1);

        QVBoxLayout leftLayout = new QVBoxLayout();

        leftLayout.AddWidget(angle);
        leftLayout.AddWidget(force);

        QGridLayout gridLayout = new QGridLayout();

        gridLayout.AddWidget(quit,0,0);
        gridLayout.AddLayout(topLayout,0,1);
        gridLayout.AddLayout(leftLayout,1,0);
        gridLayout.AddWidget(cannonField,1,1,2,1);
        gridLayout.SetColumnStretch(1,10);
        SetLayout(gridLayout);

        angle.setValue(60);
        force.setValue(25);
        angle.SetFocus();
    }
Ejemplo n.º 4
0
        private void InitUI()
        {
            QGridLayout grid = new QGridLayout (this);

            QLabel nameLabel = new QLabel ("Name", this);
            QLineEdit nameEdit = new QLineEdit (this);
            QTextEdit textEdit = new QTextEdit (this);

            QPushButton okButton = new QPushButton ("Ok", this);
            QPushButton closeButton = new QPushButton ("Close", this);

            grid.AddWidget (nameLabel, 0, 0);
            grid.AddWidget (nameEdit, 0, 1, 1, 3);
            grid.AddWidget (textEdit, 1, 0, 2, 4);
            grid.SetColumnStretch (1, 1);
            grid.AddWidget (okButton, 4, 2);
            grid.AddWidget (closeButton, 4, 3);
        }
Ejemplo n.º 5
0
        private void InitUI()
        {
            QGridLayout grid = new QGridLayout(this);

            QLabel    nameLabel = new QLabel("Name", this);
            QLineEdit nameEdit  = new QLineEdit(this);
            QTextEdit textEdit  = new QTextEdit(this);

            QPushButton okButton    = new QPushButton("Ok", this);
            QPushButton closeButton = new QPushButton("Close", this);

            grid.AddWidget(nameLabel, 0, 0);
            grid.AddWidget(nameEdit, 0, 1, 1, 3);
            grid.AddWidget(textEdit, 1, 0, 2, 4);
            grid.SetColumnStretch(1, 1);
            grid.AddWidget(okButton, 4, 2);
            grid.AddWidget(closeButton, 4, 3);
        }
Ejemplo n.º 6
0
    public GameBoard(QWidget parent) : base(parent)
    {
        QPushButton quit = new QPushButton("&Quit");

        quit.Font = new QFont("Times", 18, (int)QFont.Weight.Bold);

        Connect(quit, SIGNAL("clicked()"), qApp, SLOT("quit()"));

        LCDRange angle = new LCDRange(Tr("ANGLE"));

        angle.setRange(5,70);

        LCDRange force = new LCDRange(Tr("FORCE"));

        force.setRange(10,50);

        cannonField = new CannonField();

        Connect(angle,SIGNAL("valueChanged(int)"),
                cannonField,SLOT("setAngle(int)"));
        Connect(cannonField,SIGNAL("angleChanged(int)"),
                angle,SLOT("setValue(int)"));

        Connect(force,SIGNAL("valueChanged(int)"),
                cannonField,SLOT("setForce(int)"));
        Connect(cannonField,SIGNAL("forceChanged(int)"),
                force,SLOT("setValue(int)"));

        Connect(cannonField,SIGNAL("hit()"),
                this,SLOT("hit()"));
        Connect(cannonField,SIGNAL("missed()"),
                this,SLOT("missed()"));

        QPushButton shoot = new QPushButton("&Shoot");

        shoot.Font = new QFont("Times",18,(int)QFont.Weight.Bold);

        Connect(shoot,SIGNAL("clicked()"),
                this,SLOT("fire()"));
        Connect(cannonField,SIGNAL("canShoot(bool)"),
                shoot,SLOT("setEnabled(bool)"));

        QPushButton restart = new QPushButton(Tr("&New Game"));

        restart.Font = new QFont("Times",18,(int)QFont.Weight.Bold);

        Connect(restart,SIGNAL("clicked()"),this,SLOT("newGame()"));

        hits = new QLCDNumber(2);
        hits.segmentStyle = QLCDNumber.SegmentStyle.Filled;

        shotsLeft = new QLCDNumber(2);
        shotsLeft.segmentStyle = QLCDNumber.SegmentStyle.Filled;

        QLabel hitsLabel      = new QLabel(Tr("HITS"));
        QLabel shotsLeftLabel = new QLabel(Tr("SHOTS LEFT"));

        QHBoxLayout topLayout = new QHBoxLayout();

        topLayout.AddWidget(shoot);
        topLayout.AddWidget(hits);
        topLayout.AddWidget(hitsLabel);
        topLayout.AddWidget(shotsLeft);
        topLayout.AddWidget(shotsLeftLabel);
        topLayout.AddStretch(1);
        topLayout.AddWidget(restart);

        QVBoxLayout leftLayout = new QVBoxLayout();

        leftLayout.AddWidget(angle);
        leftLayout.AddWidget(force);

        QGridLayout gridLayout = new QGridLayout();

        gridLayout.AddWidget(quit,0,0);
        gridLayout.AddLayout(topLayout,0,1);
        gridLayout.AddLayout(leftLayout,1,0);
        gridLayout.AddWidget(cannonField,1,1,2,1);
        gridLayout.SetColumnStretch(1,10);
        SetLayout(gridLayout);

        angle.setValue(60);
        force.setValue(25);
        angle.SetFocus();

        newGame();
    }
Ejemplo n.º 7
0
    public GameBoard(QWidget parent) : base(parent)
    {
        QPushButton quit = new QPushButton("&Quit");

        quit.Font = new QFont("Times", 18, (int)QFont.Weight.Bold);

        Connect(quit, SIGNAL("clicked()"), qApp, SLOT("quit()"));

        LCDRange angle = new LCDRange(Tr("ANGLE"));

        angle.SetRange(5,70);

        LCDRange force = new LCDRange(Tr("FORCE"));

        force.SetRange(10,50);

        QFrame cannonBox = new QFrame();

        cannonBox.SetFrameStyle((int)QFrame.Shape.WinPanel | (int)QFrame.Shadow.Sunken);

        cannonField = new CannonField();

        Connect(angle,SIGNAL("ValueChanged(int)"),
                cannonField,SLOT("SetAngle(int)"));
        Connect(cannonField,SIGNAL("AngleChanged(int)"),
                angle,SLOT("SetValue(int)"));

        Connect(force,SIGNAL("ValueChanged(int)"),
                cannonField,SLOT("SetForce(int)"));
        Connect(cannonField,SIGNAL("ForceChanged(int)"),
                force,SLOT("SetValue(int)"));

        Connect(cannonField,SIGNAL("Hit()"),
                this,SLOT("Hit()"));
        Connect(cannonField,SIGNAL("Missed()"),
                this,SLOT("Missed()"));

        QPushButton shoot = new QPushButton("&Shoot");

        shoot.Font = new QFont("Times",18,(int)QFont.Weight.Bold);

        Connect(shoot,SIGNAL("clicked()"),
                this,SLOT("Fire()"));
        Connect(cannonField,SIGNAL("CanShoot(bool)"),
                shoot,SLOT("setEnabled(bool)"));

        QPushButton restart = new QPushButton(Tr("&New Game"));

        restart.Font = new QFont("Times",18,(int)QFont.Weight.Bold);

        Connect(restart,SIGNAL("clicked()"),this,SLOT("NewGame()"));

        hits = new QLCDNumber(2);
        hits.segmentStyle = QLCDNumber.SegmentStyle.Filled;

        shotsLeft = new QLCDNumber(2);
        shotsLeft.segmentStyle = QLCDNumber.SegmentStyle.Filled;

        QLabel hitsLabel      = new QLabel(Tr("HITS"));
        QLabel shotsLeftLabel = new QLabel(Tr("SHOTS LEFT"));

        new QShortcut(Qt.Key.Key_Enter,this,SLOT("Fire()"));
        new QShortcut(Qt.Key.Key_Return,this,SLOT("Fire()"));
        new QShortcut((int)Qt.Modifier.CTRL + (int)Qt.Key.Key_Q,this,SLOT("close()"));

        QHBoxLayout topLayout = new QHBoxLayout();

        topLayout.AddWidget(shoot);
        topLayout.AddWidget(hits);
        topLayout.AddWidget(hitsLabel);
        topLayout.AddWidget(shotsLeft);
        topLayout.AddWidget(shotsLeftLabel);
        topLayout.AddStretch(1);
        topLayout.AddWidget(restart);

        QVBoxLayout leftLayout = new QVBoxLayout();

        leftLayout.AddWidget(angle);
        leftLayout.AddWidget(force);

        QVBoxLayout cannonLayout = new QVBoxLayout();

        cannonLayout.AddWidget(cannonField);
        cannonBox.SetLayout(cannonLayout);

        QGridLayout gridLayout = new QGridLayout();

        gridLayout.AddWidget(quit,0,0);
        gridLayout.AddLayout(topLayout,0,1);
        gridLayout.AddLayout(leftLayout,1,0);
        gridLayout.AddWidget(cannonBox,1,1,2,1);
        gridLayout.SetColumnStretch(1,10);
        SetLayout(gridLayout);

        angle.SetValue(60);
        force.SetValue(25);
        angle.SetFocus();

        NewGame();
    }