public LCDRange(QWidget parent) : base(parent) { QLCDNumber lcd = new QLCDNumber( 2, this ); lcd.segmentStyle = QLCDNumber.SegmentStyle.Filled; QSlider slider = new QSlider( Orientation.Horizontal, this ); slider.SetRange( 0, 99 ); slider.Value = 0; Connect( slider, SIGNAL("valueChanged(int)"), lcd, SLOT("display(int)") ); QVBoxLayout layout = new QVBoxLayout(); layout.AddWidget(lcd); layout.AddWidget(slider); SetLayout(layout); }
public MyWidget(QWidget parent) : base(parent) { QPushButton quit = new QPushButton(Tr("Quit")); quit.Font = new QFont("Times", 18, (int) QFont.Weight.Bold); QLCDNumber lcd = new QLCDNumber(2); lcd.segmentStyle = QLCDNumber.SegmentStyle.Filled; QSlider slider = new QSlider(Qt.Orientation.Horizontal); slider.SetRange(0, 99); slider.Value = 0; Connect(quit, SIGNAL("clicked()"), qApp, SLOT("quit()")); Connect(slider, SIGNAL("valueChanged(int)"), lcd, SLOT("display(int)")); QVBoxLayout layout = new QVBoxLayout(); layout.AddWidget(quit); layout.AddWidget(lcd); layout.AddWidget(slider); SetLayout(layout); }
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(); }
private void Init() { QLCDNumber lcd = new QLCDNumber(2); lcd.segmentStyle = QLCDNumber.SegmentStyle.Filled; slider = new QSlider(Qt.Orientation.Horizontal); slider.SetRange(0, 99); slider.Value = 0; label = new QLabel(); label.Alignment = (int) (Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop); label.SetSizePolicy(QSizePolicy.Policy.Preferred, QSizePolicy.Policy.Fixed); Connect(slider, SIGNAL("valueChanged(int)"), lcd, SLOT("display(int)")); Connect(slider, SIGNAL("valueChanged(int)"), this, SIGNAL("ValueChanged(int)")); QVBoxLayout layout = new QVBoxLayout(); layout.AddWidget(lcd); layout.AddWidget(slider); layout.AddWidget(label); SetLayout(layout); SetFocusProxy(slider); }
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(); }