File: GNUDoQBoxWidget.H

package info (click to toggle)
gnudoq 0.94-2.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 2,696 kB
  • ctags: 232
  • sloc: cpp: 2,695; makefile: 6
file content (201 lines) | stat: -rw-r--r-- 5,542 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
/*
 *  This file is part of GNUDoQ, Copyright (C) 2005-2006 Luc Vo Van
 *
 *   GNUDoQ 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, or (at your option) any
 *   later version.
 *
 *   GNUDoQ 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 GNUDoQ; see the file COPYING.  If not, write to
 *   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *   Boston, MA 02111-1307, USA.
 *
 *   Class          :   Number widget
 *   Author         :   Luc Vo Van
 *   Original Date  :   September 2005
 *
 **/

#ifndef GNUDOQBOXWIDGET_H
#define GNUDOQBOXWIDGET_H

#include <QWidget>
#include <QColor>
#include <QPainterPath>

/**
 * Number input widget. 81 instances of these widgets are used to form the
 * grid. Clicking them changes their values, they can be editable by the
 * player or not (depending on their editable() propery), can be marked
 * erroneous, etc.
 *
 * This widget is also called a 'box'.
 */
class GNUDoQBoxWidget : public QWidget
{
    Q_OBJECT

public:
    /**
     * Class constructor. Each GNUDoQBoxWidget must belong to a group,
     * which is one of the 9 3x3 zones of the grid. The numbers are
     * as follows:
     *
     * 012
     * 345
     * 678
     *
     * @param iGroup Group number to which this box belongs
     * @param parent Parent widget
     */
    GNUDoQBoxWidget(int iGroup,QWidget *parent = 0);
    /**
     * Returns the value of this box.
     *
     * @see setValue(const int)
     * @return the value of this box, 0 if no value is displayed
     */
    int value() { return m_iValue; }

    /*
     * Returns a value indicating wether or not this box is marked erroneous.
     *
     * @see setErroneous(const bool)
     * @return true if the box is erroneous, false otherwise
     */
    bool erroneous() { return m_bErroneous; }

    /**
     * Returns a value indicating wether or not this box is editable by the
     * player.
     *
     * @see setEditable(const bool)
     * @return true if the box is editable, false otherwise
     */
    bool editable() { return m_bEditable; }

    /**
     * Returns a value indicating wether or not this box's value was
     * determined by the GNUDoku solver (after the player presses the
     * 'Solve' button)
     *
     * @see setCpusolved(const bool)
     * @return true if the box's value was determined by the GNUDoku
     *         solver, false otherwise
     */
    bool cpusolved() { return m_bCpusolved; }

public slots:
    /**
     * Sets the value of this box.
     *
     * @param iValue value to give this box (0 if no value is to be displayed)
     * @see value()
     */
    void setValue(const int iValue);

    /**
     * Sets a value indicating if the box contains an erroneous value.
     * 
     * @param bErroneous true to set the box to erroneous, false otherwise
     * @see erroneous()
     */
    void setErroneous(const bool bErroneous);

    /**
     * Sets a value indicating wether or not the box's value can be edited
     * by the player.
     * 
     * @param bEditable true to make the box player editable, false otherwise
     * @see editable()
     */
    void setEditable(const bool bEditable);

    /**
     * Sets a value indicating wether or not the box's value was determined
     * by the GNUDoku solver.
     *
     * @param bCpuSolved true if the value was determined by the GNUDoku solver
     *        false otherwise (value set by the player)
     * @see cpusolved()
     */
    void setCpusolved(const bool bCpusolved);

signals:
    /**
     * Emitted whenever the value of this box changes
     *
     * @see setValue(const int)
     */
    void valueChanged();

protected:
    /**
     * Draws the box
     * @param event QPaintEvent
     */
    void paintEvent(QPaintEvent *event);

    /**
     * Reacts to keypresses: numbers set values, backspace/del removes
     * the current value (sets it to 0).
     *
     * @param event QKeyEvent
     * @see setValue(const int)
     */
    void keyPressEvent(QKeyEvent *event);

    /**
     * Reacts to clicks, left click increases the value, right click
     * decreases, middle click remove the current value (sets it to 0)
     *
     * @param event QMouseEvent
     * @see setValue(const int)
     */
    void mousePressEvent(QMouseEvent *event);

    /**
     * Reacts to mouse wheel events. Rolling up increases the value, rolling
     * down decreases it.
     *
     * @param event QWheelEvent
     * @see setValue(const int)
     */
    void wheelEvent(QWheelEvent * event);

    /**
     * Sets m_bHovered to true, to highlight the box when hovered by the
     * mouse cursor.
     *
     * @param event QEvent
     */
    void enterEvent(QEvent *event);

    /**
     * Sets m_bHovered to false, to dehighlight the box when not hovered by
     * the mouse cursor anymore.
     *
     * @param event QEvent
     */    
    void leaveEvent(QEvent *event);

private:
    // Properties value holders
    int m_iValue;
    int m_iGroup;
    bool m_bHovered;
    bool m_bErroneous;
    bool m_bEditable;
    bool m_bCpusolved;

    // Colors for each group (3x3 zones)
    static const QColor groupColor[];
};

#endif