README.codestyle
1==========================
2 Killbots C++ Style Guide
3==========================
4
5*******************************************************************************
6 Indentation
7*******************************************************************************
8
9Structural indentation is done with tabs. Formatting is done with spaces. All
10code having the same nested depth has the same number of tabs. This separates
11meaning from presentation.
12
13Tabwidth is a matter of personal preference. If the above is followed source is
14tabwidth independent.
15
16Ensure your editor doesn't do automatic conversion from spaces to tabs, as this
17will break things.
18
19Labels (public, private, goto, case, etc.) do not get indented.
20
21Empty lines do not get indentation. In fact, no lines should have trailing
22whitespace.
23
24If a pair of parentheses span multiple lines, the closing parenthesis should be
25indented (with spaces) to appear in the same column as the opening parenthesis.
26
27Examples:
28-------------------------------------------------------------------------------
29bool Killbots::Engine::cellIsValid( const QPoint & cell ) const
30{
31____return ( 0 <= cell.x()
32____.........&& cell.x() < m_rules->columns()
33____.........&& 0 <= cell.y()
34____.........&& cell.y() < m_rules->rows()
35____.......);
36}
37-------------------------------------------------------------------------------
38namespace Killbots
39{
40____class RenderPrivate
41____{
42____public:
43________RenderPrivate()
44________..:.m_svgRenderer(),
45________....m_pixmapCache("killbots-cache"),
46________....m_cursors(),
47________....m_hasBeenLoaded( false )
48________{};
49-------------------------------------------------------------------------------
50____if ( m_rulesetChanged )
51____{
52________if ( ! m_engine->gameHasStarted() ||
53________.....KMessageBox::questionYesNo( this,
54________.................................i18n("A new ruleset has been selected, but there is already a game in progress."),
55________.................................i18n("Rule Set Changed"),
56________.................................KGuiItem( i18n("Continue Current Game") ),
57________.................................KGuiItem( i18n("Start a New Game") )
58________...............................) == KMessageBox::No
59________...)
60________{
61-------------------------------------------------------------------------------
62
63
64*******************************************************************************
65 Braces
66*******************************************************************************
67
68Opening and closing braces are always on a new line.
69
70For loop or conditional statements, braces can be omitted if the block is a
71single-line statement and the conditional fits on a single line. If braces are
72used in one block of an if-elseif-else statement, they should be used in the
73other blocks even if those blocks are a single line.
74
75Blocks never appear on the same line as the loop/conditional, even if braces
76aren't used.
77
78Empty blocks are represented on a single line as '{}'
79
80Examples:
81-------------------------------------------------------------------------------
82void Killbots::Engine::refreshSpriteMap()
83{
84 m_spriteMap.clear();
85 for (Sprite * bot : std::as_const(m_bots))
86 m_spriteMap.insert( bot->gridPos(), bot );
87 for (Sprite * junkheap : std::as_const(m_junkheaps))
88 m_spriteMap.insert( junkheap->gridPos(), junkheap );
89}
90-------------------------------------------------------------------------------
91if ( m_rules->pushableJunkheaps() != Ruleset::None && cellIsValid( nextCell ) )
92{
93 if ( spriteTypeAt( nextCell ) == NoSprite )
94 return true;
95 else if ( spriteTypeAt( nextCell ) == Junkheap )
96 return m_rules->pushableJunkheaps() == Ruleset::Many && canPushJunkheap( m_spriteMap.value( nextCell ), direction );
97 else
98 return m_rules->squaskKillsEnabled();
99}
100else
101{
102 return false;
103}
104-------------------------------------------------------------------------------
105while ( m_rulesetMap.contains( name ) )
106 name += '_';
107-------------------------------------------------------------------------------
108
109*******************************************************************************
110 Whitespace
111*******************************************************************************
112
113Lines should generally be kept to less than 100 characters, but don't make code
114uglier just to avoid width.
115
116Two empty lines should be used to separate function definitions.
117
118Within a block, empty lines may be used to break up unrelated lines, but never
119more than one.
120
121No space appears between the function name and the opening bracket.
122
123A single space appears between the loop/conditional statement name and the
124opening bracket.
125
126Padding spaces appear inside of all parentheses, unless the parentheses are
127empty or contain only a string literal.
128
129Binary operators are separated from their operands with a single space. Unary
130operators are not.
131
132Pointer and reference symbols have a space on either side.
133
134No padding spaces appear inside angle brackets when using template functions
135or classes.
136
137No space appears between a label and the following colon.
138
139No whitespace should appear inside Qt's SIGNAL and SLOT macros.
140
141
142*******************************************************************************
143 Indentifiers
144*******************************************************************************
145
146All identifiers should use camel case.
147
148Classnames and namespaces begin with uppercase letters. All other identifiers
149begin with lowercase letters.
150
151Class data members are prefixed with 'm_', unless they are public KConfigXT
152widgets, in which case, they are prefixed with 'kfcg_'.
153
154Indentifiers should favour descriptiveness over brevity. Single letter
155variables are acceptable only for iterators or coordinates.
156
157All indentifiers should use American English spelling. (Comments can be in your
158choice of English.)
159
160Examples:
161-------------------------------------------------------------------------------
162namespace Killbots
163{
164 class Ruleset;
165
166 class RulesetSelector : public QWidget
167 {
168 Q_OBJECT
169
170 public: // functions
171 explicit RulesetSelector( QWidget * parent = 0 );
172 virtual ~RulesetSelector();
173
174 public: // data members
175 KLineEdit * kcfg_Ruleset;
176
177 private: // functions
178 void findRulesets();
179
180 private Q_SLOTS:
181 void selectionChanged( QString rulesetName );
182
183 private: // data members
184 QListWidget * m_listWidget;
185 QLabel * m_author;
186 QLabel * m_authorContact;
187 QLabel * m_description;
188 QMap< QString, Ruleset * > m_rulesetMap;
189 };
190}
191-------------------------------------------------------------------------------
192
193
194*******************************************************************************
195 Comments
196*******************************************************************************
197
198Feel free to comment as much as possible.
199
200Comments should describe the purpose of logic or give background details not
201obvious from the code. Comments should not describe what the code is doing,
202unless the code is extremely dense (in which case the code should probably be
203rewritten/refactored anyway).
204
205Comments appear on the line before the code it is commenting on.
206
207Use '/**/' for comments longer than 3 lines.
208
209
210*******************************************************************************
211 Class Definitions
212*******************************************************************************
213
214Classes should be given simple names and placed inside the Killbots namespace
215instead of adding a prefix. (i.e. Killbots::MainWindow instead of
216KillbotsMainWindow)
217
218No inline function definitions in the header, even if they are a single
219statement. Same goes for constructors.
220
221Define destructors even if they're empty.
222
223Class definitions should be layed out in the following order.
224 public: // types
225 public: // functions
226 public Q_SLOTS:
227 public: // data members
228 Q_SIGNALS:
229 protected: // types
230 protected: // functions
231 protected Q_SLOTS:
232 protected: // data members
233 private: // types
234 private: // functions
235 private Q_SLOTS:
236 private: // data members
237
238
239*******************************************************************************
240 Includes
241*******************************************************************************
242
243Include guards are of the form NAMESPACE_CLASSNAME_H.
244
245Group includes in the following order with blank lines in between:
246 File's own header
247 Killbots headers
248 KDE headers
249 Qt headers
250
251Inside of groups, sort includes alphabetically.
252
253Use the "new" style includes with directory names where appropriate
254
255Forward declare whenever possible in headers.
256
257moc includes appear at the bottom of the source file.
258
259Examples:
260-------------------------------------------------------------------------------
261#ifndef KILLBOTS_RULESETSELECTOR_H
262#define KILLBOTS_RULESETSELECTOR_H
263
264class KLineEdit;
265
266#include <QtCore/QMap>
267class QLabel;
268class QListWidget;
269#include <QWidget>
270
271namespace Killbots
272{
273 class Ruleset;
274-------------------------------------------------------------------------------
275#include "rulesetselector.h"
276
277#include "ruleset.h"
278#include "settings.h"
279
280#include <KDE/KDebug>
281#include <KDE/KDialog>
282#include <KDE/KLineEdit>
283#include <KDE/KLocalizedString>
284#include <KDE/KStandardDirs>
285
286#include <QLabel>
287#include <QListWidget>
288-------------------------------------------------------------------------------
289
290
291*******************************************************************************
292 Miscellaneous
293*******************************************************************************
294
295It is generally preferred that functions have a single return statement, but
296multiple returns statements are exceptable if a single return would make the
297code more complicated.
298
299Use the "Q_UNUSED" macro on unused function parameters.
300
301Use "static_cast<>" instead of the C or C++ style type casts when casting
302pointers.
303
304When converting one type to another use C++ or constructor style casts. For
305example, use "int()" to convert floating types to integers.
306
307Make sure code passes all the English Breakfast Network checks.
README.translators
1Translating Keyboard Controls in Killbots
2
3To effectively use the keyboard to control Killbots. the movement keys must be
4assigned to a 3 by 3 grid of adjacent keys. In KDE 4.2, the basic directional
5controls were assigned to Q,W,E,A,S,D,Z,X,C,(the leftmost block of letter keys
6on a QWERTY keyboard). Special action keys were assigned to those just right
7of this block. The keys of the numeric keypad were added as an alternate set.
8
9It was quickly noticed that while the QWE... keys were convenient for those
10with American-style keyboards, they were of little to no use to those on other
11layouts where the keys might be spread about at random. Also most laptop users
12do not have numeric keypads, so for a large percentage of users neither set
13of default shortcuts were usable.
14
15As a result I'm asking you, the translators, to translate these keys to their
16physical equivalents on the localised keyboard layout. I realise that some
17locales might not have their own keyboard layout, while others might have
18more than one. In such cases, please choose the layout that is most commonly
19found on new keyboards sold in your locale. (Keep in mind that we are only
20discussing default key assignments. The user still has the option of
21reassigning the shortcuts manually in the Configure Shortcuts dialog.)
22
23The following are some example mappings (taken from Wikipedia):
24
25US-English French Greek Ukranian Hebrew
26
27QWERT AZERT ;ςΕΡΤ ЙЦУКЕ /'ארק
28ASDF QSDF ΑΣΔΦ ФІВА כגדש
29ZXCV WXCV ΖΧΨΩ ЯЧСМ הבסז
30
31
32
33
34
35