summaryrefslogtreecommitdiffstats
path: root/kmines/frame.cpp
blob: 7c712383e7c6ac9882337db2b4fa0a5ad2393933 (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
144
145
/*
 * 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 *tqparent)
    : TQFrame(tqparent, "field"), _button(0)
{
    setFrameStyle( TQFrame::Box | TQFrame::Raised );
	setLineWidth(2);
	setMidLineWidth(2);
}

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

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

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

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

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

    if ( type==FlagPixmap ) {
        p.setWindow(0, 0, 16, 16);
        p.setPen( (tqmask ? 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 (!tqmask) p.setPen(black);
        p.setBrush( (tqmask ? 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, (tqmask ? color1 : Settings::color(Settings::EnumType::explosion)));
	TQPen pen(tqmask ? color1 : black, 1);
	p.setPen(pen);
	p.setBrush(tqmask ? 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, (tqmask ? color1 : white));
	if ( type==ErrorPixmap ) {
		if (!tqmask) {
			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 tqmask) const
{
    initPixmap(pix, tqmask);
    TQPainter p(&pix);
    p.setWindow(0, 0, 16, 16);
    p.setPen( TQPen(tqmask ? 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(),
                    tqcolorGroup(),  pressed, 2,
                    &tqcolorGroup().brush(TQColorGroup::Background));
    if (hasFocus) {
        painter.translate(p.x(), p.y());
        TQRect fbr = tqstyle().subRect(TQStyle::SR_PushButtonFocusRect, &_button);
        tqstyle().tqdrawPrimitive(TQStyle::PE_FocusRect, &painter, fbr,
                              tqcolorGroup(), 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));
    tqstyle().drawItem(&painter, r, AlignCenter, tqcolorGroup(), true, pixmap,
                     text, -1, &color);
    if ( advised!=-1 )
        tqstyle().drawItem(&painter, r, AlignCenter, tqcolorGroup(), true,
                         &_advised[advised], TQString());
}