File indexing completed on 2024-03-24 04:07:47
0001 /* 0002 SPDX-FileCopyrightText: 2008 Ian Wadham <iandw.au@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "gamedialog.h" 0008 #include <KLocalizedString> 0009 #include <KMessageBox> 0010 0011 #include <QDialogButtonBox> 0012 #include <QFrame> 0013 #include <QPushButton> 0014 #include <QVBoxLayout> 0015 0016 /******************************************************************************/ 0017 /***************** DIALOG BOX TO SELECT A GAME AND LEVEL *****************/ 0018 /******************************************************************************/ 0019 0020 GameDialog::GameDialog (bool changePuzzle, int optionTemp [], QWidget * parent) 0021 : QDialog (parent) 0022 { 0023 myParent = parent; 0024 myChangePuzzle = changePuzzle; 0025 opt = optionTemp; 0026 0027 QWidget * dad = new QWidget (this); 0028 QVBoxLayout *mainLayout = new QVBoxLayout(dad); 0029 mainLayout->addWidget(dad); 0030 setLayout(mainLayout); 0031 setWindowTitle (i18nc("@title:window", "Rubik's Cube Options")); 0032 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Help); 0033 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0034 okButton->setDefault(true); 0035 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0036 connect(buttonBox, &QDialogButtonBox::accepted, this, &GameDialog::accept); 0037 connect(buttonBox, &QDialogButtonBox::rejected, this, &GameDialog::reject); 0038 buttonBox->button(QDialogButtonBox::Ok)->setDefault(true); 0039 0040 QHBoxLayout * cubeDimensions = new QHBoxLayout(); 0041 mainLayout->addLayout (cubeDimensions); 0042 0043 QHBoxLayout * difficulty = new QHBoxLayout(); 0044 mainLayout->addLayout (difficulty); 0045 0046 if (changePuzzle) { 0047 // Lay out spin boxes for the cube dimensions. 0048 dimL = new QLabel (i18n("Cube dimensions:")); 0049 cubeDimensions->addWidget (dimL); 0050 0051 dimX = new QSpinBox (); 0052 dimY = new QSpinBox (); 0053 dimZ = new QSpinBox (); 0054 dimX->setRange (1, 6); 0055 dimY->setRange (1, 6); 0056 dimZ->setRange (1, 6); 0057 cubeDimensions->addWidget (dimX); 0058 cubeDimensions->addWidget (dimY); 0059 cubeDimensions->addWidget (dimZ); 0060 0061 shuffleL = new QLabel (i18n("Moves per shuffle (difficulty):")); 0062 shuffleN = new QSpinBox (); 0063 shuffleN->setRange (0, 50); 0064 difficulty->addWidget (shuffleL); 0065 difficulty->addWidget (shuffleN); 0066 } 0067 else { 0068 dimL = new QLabel (i18n("Cube dimensions: %1x%2x%3", 0069 optionTemp [optXDim], 0070 optionTemp [optYDim], 0071 optionTemp [optZDim])); 0072 cubeDimensions->addWidget (dimL); 0073 0074 shuffleL = new QLabel (i18n("Moves per shuffle (difficulty): %1", 0075 optionTemp [optShuffleMoves])); 0076 difficulty->addWidget (shuffleL); 0077 0078 QHBoxLayout * msg = new QHBoxLayout(); 0079 mainLayout->addLayout (msg); 0080 QLabel * msgL = new QLabel (i18n( 0081 "<i>Please use <nobr>'Choose Puzzle Type->Make Your " 0082 "Own...'</nobr> to set the above options.</i>")); 0083 msgL->setWordWrap(true); 0084 msg->addWidget (msgL); 0085 } 0086 0087 QFont f = dimL->font(); 0088 f.setBold (true); 0089 dimL->setFont (f); 0090 shuffleL->setFont (f); 0091 0092 // Add a horizontal line as a separator. 0093 QFrame * separator = new QFrame (dad); 0094 separator->setFrameShape (QFrame::HLine); 0095 separator->setFrameShadow (QFrame::Sunken); 0096 mainLayout->addWidget (separator); 0097 0098 // Lay out the remaining options. 0099 shuffleA = new QCheckBox (i18n("Watch shuffling in progress?"), dad); 0100 mainLayout->addWidget (shuffleA); 0101 0102 movesA = new QCheckBox (i18n("Watch your moves in progress?"), dad); 0103 mainLayout->addWidget (movesA); 0104 0105 QHBoxLayout * speed = new QHBoxLayout(); 0106 mainLayout->addLayout (speed); 0107 0108 speedL = new QLabel (i18n("Speed of moves:")); 0109 speedN = new QSpinBox (); 0110 speedN->setRange (1, 15); 0111 speed->addWidget (speedL); 0112 speed->addWidget (speedN); 0113 0114 QHBoxLayout * bevel = new QHBoxLayout(); 0115 mainLayout->addLayout (bevel); 0116 0117 // xgettext: no-c-format 0118 bevelL = new QLabel (i18n("% of bevel on edges of cubies:")); 0119 bevelN = new QSpinBox (); 0120 bevelN->setRange (4, 30); 0121 bevelN->setSingleStep (2); 0122 bevel->addWidget (bevelL); 0123 bevel->addWidget (bevelN); 0124 0125 mainLayout->addWidget(buttonBox); 0126 0127 // Set the option-widgets to the current values of the options. 0128 if (changePuzzle) { 0129 dimX->setValue (optionTemp [optXDim]); 0130 dimY->setValue (optionTemp [optYDim]); 0131 dimZ->setValue (optionTemp [optZDim]); 0132 0133 shuffleN->setValue (optionTemp [optShuffleMoves]); 0134 } 0135 shuffleA->setChecked ((bool) optionTemp [optViewShuffle]); 0136 movesA->setChecked ((bool) optionTemp [optViewMoves]); 0137 speedN->setValue (optionTemp [optMoveSpeed]); 0138 0139 bevelN->setValue (optionTemp [optBevel]); 0140 0141 connect(okButton, &QPushButton::clicked, this, &GameDialog::slotOk); 0142 connect(buttonBox->button(QDialogButtonBox::Help), &QPushButton::clicked, this, &GameDialog::slotHelp); 0143 } 0144 0145 0146 GameDialog::~GameDialog() 0147 { 0148 } 0149 0150 0151 void GameDialog::slotOk () 0152 { 0153 // Pass back the latest option values. 0154 if (myChangePuzzle) { 0155 // We are making a new cube. 0156 opt [optXDim] = dimX->value(); 0157 opt [optYDim] = dimY->value(); 0158 opt [optZDim] = dimZ->value(); 0159 0160 opt [optShuffleMoves] = shuffleN->value(); 0161 } 0162 0163 opt [optViewShuffle] = (int) shuffleA->isChecked(); 0164 opt [optViewMoves] = (int) movesA->isChecked(); 0165 opt [optMoveSpeed] = speedN->value(); 0166 0167 opt [optBevel] = bevelN->value(); 0168 } 0169 0170 0171 void GameDialog::slotHelp () 0172 { 0173 // Help for "Rubik's Cube Options" dialog box. 0174 QString s = i18n( 0175 "You can choose any size of cube (or brick) up to 6x6x6, but only " 0176 "one side can have dimension 1 (otherwise the puzzle becomes trivial). " 0177 " The easiest puzzle is 2x2x1 and 3x3x1 is a good warmup for the " 0178 "original Rubik's Cube, which is 3x3x3. " 0179 "Simple puzzles have 2 to 5 shuffling moves, a difficult 3x3x3 puzzle " 0180 "has 10 to 20 --- or you can choose zero shuffling then shuffle the " 0181 "cube yourself, maybe for a friend to solve.\n" 0182 "The other options determine whether you can watch the shuffling " 0183 "and/or your own moves and how fast the animation goes. The bevel " 0184 "option affects the appearance of the small cubes. Try setting " 0185 "it to 30 and you'll see what we mean."); 0186 0187 KMessageBox::information (myParent, s, i18n("HELP: Rubik's Cube Options")); 0188 } 0189 0190