summaryrefslogtreecommitdiffstats
path: root/kmines/frame.cpp
blob: 6c9446c24b3d8e8dfb3ffe143fe2b987651a940d (plain)
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
/*
 * Copyright (c) 2002 Nicolas HADACEK (hadacek@kde.org)
 *
 * 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 "frame.h"

#include <tqpainter.h>
#include <tqbitmap.h>
#include <tqstyle.h>
#include <tqdrawutil.h>

#include "settings.h"


FieldFrame::FieldFrame(TQWidget *parent)
    : TQFrame(parent, "field"), _button(0)
{
    setFrameStyle( TQFrame::Box | TQFrame::Raised );
	setLineWidth(2);
	setMidLineWidth(2);
}

void FieldFrame::adjustSize()
{
    setFixedSize(sizeHint());
    _button.resize(Settings::caseSize(), Settings::caseSize());

    TQBitmap mask;
    for (uint i=0; i<Nb_Pixmap_Types; i++) {
        drawPixmap(mask, (PixmapType)i, true);
        drawPixmap(_pixmaps[i], (PixmapType)i, false);
        _pixmaps[i].setMask(mask);
    }
    for (uint i=0; i<Nb_Advised; i++) {
        drawAdvised(mask, i, true);
        drawAdvised(_advised[i], i, false);
        _advised[i].setMask(mask);
    }

    TQFont f = font();
    f.setPointSize(QMAX(1, Settings::caseSize()-6));
    f.setBold(true);
    setFont(f);
}

void FieldFrame::initPixmap(TQPixmap &pix, bool mask) const
{
    pix.resize(Settings::caseSize(), Settings::caseSize());
    if (mask) pix.fill(color0);
}

void FieldFrame::drawPixmap(TQPixmap &pix, PixmapType type, bool mask) const
{
    initPixmap(pix, mask);
    TQPainter p(&pix);

    if ( type==FlagPixmap ) {
        p.setWindow(0, 0, 16, 16);
        p.setPen( (mask ? color1 : black) );
        p.drawLine(6, 13, 14, 13);
        p.drawLine(8, 12, 12, 12);
        p.drawLine(9, 11, 11, 11);
        p.drawLine(10, 2, 10, 10);
        if (!mask) p.setPen(black);
        p.setBrush( (mask ? color1 : Settings::color(Settings::EnumType::flag)) );
        p.drawRect(4, 3, 6, 5);
        return;
    }

    p.setWindow(0, 0, 20, 20);
	if ( type==ExplodedPixmap )
		p.fillRect(2, 2, 16, 16, (mask ? color1 : Settings::color(Settings::EnumType::explosion)));
	TQPen pen(mask ? color1 : black, 1);
	p.setPen(pen);
	p.setBrush(mask ? color1 : black);
	p.drawLine(10,3,10,18);
	p.drawLine(3,10,18,10);
	p.drawLine(5, 5, 16, 16);
	p.drawLine(5, 15, 15, 5);
	p.drawEllipse(5, 5, 11, 11);
	p.fillRect(8, 8, 2, 2, (mask ? color1 : white));
	if ( type==ErrorPixmap ) {
		if (!mask) {
			pen.setColor(Settings::color(Settings::EnumType::error));
			p.setPen(pen);
		}
		p.drawLine(3, 3, 17, 17);
		p.drawLine(4, 3, 17, 16);
		p.drawLine(3, 4, 16, 17);
		p.drawLine(3, 17, 17, 3);
		p.drawLine(3, 16, 16, 3);
		p.drawLine(4, 17, 17, 4);
	}
}

void FieldFrame::drawAdvised(TQPixmap &pix, uint i, bool mask) const
{
    initPixmap(pix, mask);
    TQPainter p(&pix);
    p.setWindow(0, 0, 16, 16);
    p.setPen( TQPen(mask ? color1 : Settings::mineColor(i), 2) );
    p.drawRect(3, 3, 11, 11);
}

void FieldFrame::drawBox(TQPainter &painter, const TQPoint &p,
                      bool pressed, PixmapType type, const TQString &text,
                      uint nbMines, int advised,
                      bool hasFocus) const
{
    qDrawShadePanel(&painter, p.x(), p.y(), _button.width(), _button.height(),
                    colorGroup(),  pressed, 2,
                    &colorGroup().brush(TQColorGroup::Background));
    if (hasFocus) {
        painter.translate(p.x(), p.y());
        TQRect fbr = style().subRect(TQStyle::SR_PushButtonFocusRect, &_button);
        style().drawPrimitive(TQStyle::PE_FocusRect, &painter, fbr,
                              colorGroup(), TQStyle::Style_Enabled);
        painter.resetXForm();
    }

	TQRect r(p, _button.size());
    const TQPixmap *pixmap = (type==NoPixmap ? 0 : &_pixmaps[type]);
    TQColor color = (nbMines==0 ? black : Settings::mineColor(nbMines-1));
    style().drawItem(&painter, r, AlignCenter, colorGroup(), true, pixmap,
                     text, -1, &color);
    if ( advised!=-1 )
        style().drawItem(&painter, r, AlignCenter, colorGroup(), true,
                         &_advised[advised], TQString::null);
}