gamedialog.cpp 6.89 KB
Newer Older
1
/*******************************************************************************
Ian Wadham's avatar
Ian Wadham committed
2
  Copyright 2008 Ian Wadham <iandw.au@gmail.com>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*******************************************************************************/

#include "gamedialog.h"
Andrius Štikonas's avatar
Andrius Štikonas committed
20
#include <KConfigGroup>
Laurent Montel's avatar
Laurent Montel committed
21
#include <KLocalizedString>
22

Andrius Štikonas's avatar
Andrius Štikonas committed
23
#include <QDialogButtonBox>
24
#include <QFrame>
Andrius Štikonas's avatar
Andrius Štikonas committed
25 26 27
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
28 29 30 31 32 33

/******************************************************************************/
/*****************    DIALOG BOX TO SELECT A GAME AND LEVEL   *****************/
/******************************************************************************/

GameDialog::GameDialog (bool changePuzzle, int optionTemp [], QWidget * parent)
Andrius Štikonas's avatar
Andrius Štikonas committed
34
                : QDialog (parent)
35 36 37 38 39 40
{
    myParent                 = parent;
    myChangePuzzle           = changePuzzle;
    opt                      = optionTemp;

    QWidget * dad	     = new QWidget (this);
Andrius Štikonas's avatar
Andrius Štikonas committed
41 42 43 44 45 46 47 48 49 50 51
    QVBoxLayout *mainLayout = new QVBoxLayout(dad);
    mainLayout->addWidget(dad);
    setLayout(mainLayout);
    setWindowTitle (i18n ("Rubik's Cube Options"));
    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel|QDialogButtonBox::Help);
    QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
    okButton->setDefault(true);
    okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
    connect(buttonBox, &QDialogButtonBox::accepted, this, &GameDialog::accept);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &GameDialog::reject);
    buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

    QHBoxLayout * cubeDimensions = new QHBoxLayout();
    mainLayout->addLayout (cubeDimensions);

    QHBoxLayout * difficulty = new QHBoxLayout();
    mainLayout->addLayout (difficulty);

    if (changePuzzle) {
	// Lay out spin boxes for the cube dimensions.
	dimL     = new QLabel (i18n("Cube dimensions:"));
	cubeDimensions->addWidget (dimL);

	dimX     = new QSpinBox ();
	dimY     = new QSpinBox ();
	dimZ     = new QSpinBox ();
	dimX->setRange (1, 6);
	dimY->setRange (1, 6);
	dimZ->setRange (1, 6);
	cubeDimensions->addWidget (dimX);
	cubeDimensions->addWidget (dimY);
	cubeDimensions->addWidget (dimZ);

	shuffleL = new QLabel (i18n("Moves per shuffle (difficulty):"));
	shuffleN = new QSpinBox ();
	shuffleN->setRange (0, 50);
	difficulty->addWidget (shuffleL);
	difficulty->addWidget (shuffleN);
    }
    else {
	dimL     = new QLabel (i18n("Cube dimensions: %1x%2x%3",
			optionTemp [optXDim],
			optionTemp [optYDim],
			optionTemp [optZDim]));
	cubeDimensions->addWidget (dimL);

	shuffleL = new QLabel (i18n("Moves per shuffle (difficulty): %1",
			optionTemp [optShuffleMoves]));
	difficulty->addWidget (shuffleL);

	QHBoxLayout * msg = new QHBoxLayout();
	mainLayout->addLayout (msg);
	QLabel * msgL = new QLabel (i18n(
			"<i>Please use <nobr>'Choose Puzzle Type->Make Your "
			"Own...'</nobr> to set the above options.</i>"));
Laurent Montel's avatar
Laurent Montel committed
96
        msgL->setWordWrap(true);
97 98 99 100
        msg->addWidget (msgL);
    }

    QFont f  = dimL->font();
101
    f.setBold (true);
102 103 104 105 106 107 108 109 110 111
    dimL->setFont (f);
    shuffleL->setFont (f);

    // Add a horizontal line as a separator.
    QFrame * separator = new QFrame (dad);
    separator->setFrameShape  (QFrame::HLine);
    separator->setFrameShadow (QFrame::Sunken);
    mainLayout->addWidget (separator);

    // Lay out the remaining options.
Laurent Montel's avatar
Laurent Montel committed
112
    shuffleA = new QCheckBox (i18n("Watch shuffling in progress?"), dad);
113 114
    mainLayout->addWidget (shuffleA);

Laurent Montel's avatar
Laurent Montel committed
115
    movesA   = new QCheckBox (i18n("Watch your moves in progress?"), dad);
116 117 118 119 120 121 122 123 124 125 126 127 128 129
    mainLayout->addWidget (movesA);

    QHBoxLayout * speed = new QHBoxLayout();
    mainLayout->addLayout (speed);

    speedL   = new QLabel (i18n("Speed of moves:"));
    speedN   = new QSpinBox ();
    speedN->setRange (1, 15);
    speed->addWidget (speedL);
    speed->addWidget (speedN);

    QHBoxLayout * bevel = new QHBoxLayout();
    mainLayout->addLayout (bevel);

Albert Astals Cid's avatar
Albert Astals Cid committed
130
    // xgettext: no-c-format
131 132 133 134 135 136 137
    bevelL   = new QLabel (i18n("% of bevel on edges of cubies:"));
    bevelN   = new QSpinBox ();
    bevelN->setRange (4, 30);
    bevelN->setSingleStep (2);
    bevel->addWidget (bevelL);
    bevel->addWidget (bevelN);

Andrius Štikonas's avatar
Andrius Štikonas committed
138 139
    mainLayout->addWidget(buttonBox);

140 141 142 143 144 145 146 147 148 149 150 151 152 153
    // Set the option-widgets to the current values of the options.
    if (changePuzzle) {
	dimX->setValue (optionTemp [optXDim]);
	dimY->setValue (optionTemp [optYDim]);
	dimZ->setValue (optionTemp [optZDim]);

	shuffleN->setValue   (optionTemp [optShuffleMoves]);
    }
    shuffleA->setChecked ((bool) optionTemp [optViewShuffle]);
    movesA->setChecked   ((bool) optionTemp [optViewMoves]);
    speedN->setValue     (optionTemp [optMoveSpeed]);

    bevelN->setValue     (optionTemp [optBevel]);

Andrius Štikonas's avatar
Andrius Štikonas committed
154 155
    connect(okButton, &QPushButton::clicked, this, &GameDialog::slotOk);
    connect(buttonBox->button(QDialogButtonBox::Help), &QPushButton::clicked, this, &GameDialog::slotHelp);
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
}


GameDialog::~GameDialog()
{
}


void GameDialog::slotOk ()
{
    // Pass back the latest option values.
    if (myChangePuzzle) {
	// We are making a new cube.
	opt [optXDim]         = dimX->value();
	opt [optYDim]         = dimY->value();
	opt [optZDim]         = dimZ->value();

	opt [optShuffleMoves] = shuffleN->value();
    }

    opt [optViewShuffle]  = (int) shuffleA->isChecked();
    opt [optViewMoves]    = (int) movesA->isChecked();
    opt [optMoveSpeed]    = speedN->value();

    opt [optBevel]        = bevelN->value();
}


void GameDialog::slotHelp ()
{
    // Help for "Rubik's Cube Options" dialog box.
    QString s = i18n(
	"You can choose any size of cube (or brick) up to 6x6x6, but only "
	"one side can have dimension 1 (otherwise the puzzle becomes trivial). "
	" The easiest puzzle is 2x2x1 and 3x3x1 is a good warmup for the "
	"original Rubik's Cube, which is 3x3x3.  "
	"Simple puzzles have 2 to 5 shuffling moves, a difficult 3x3x3 puzzle "
	"has 10 to 20 --- or you can choose zero shuffling then shuffle the "
	"cube yourself, maybe for a friend to solve.\n"
	"The other options determine whether you can watch the shuffling "
	"and/or your own moves and how fast the animation goes.  The bevel "
	"option affects the appearance of the small cubes.  Try setting "
	"it to 30 and you'll see what we mean.");

    KMessageBox::information (myParent, s, i18n("HELP: Rubik's Cube Options"));
}

203