| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2002-2003 Andi Peredri * |
| 3 | * [email protected] * |
| 4 | * Copyright (C) 2004-2005 Artur Wiebe |
| 5 | * [email protected] |
| 6 | * * |
| 7 | * This program is free software; you can redistribute it and/or modify * |
| 8 | * it under the terms of the GNU General Public License as published by * |
| 9 | * the Free Software Foundation; either version 2 of the License, or * |
| 10 | * (at your option) any later version. * |
| 11 | * * |
| 12 | * This program is distributed in the hope that it will be useful, * |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 | * GNU General Public License for more details. * |
| 16 | * * |
| 17 | * You should have received a copy of the GNU General Public License * |
| 18 | * along with this program; if not, write to the * |
| 19 | * Free Software Foundation, Inc., * |
| 20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 21 | ***************************************************************************/ |
| 22 | |
| 23 | #include <QPainter> |
| 24 | #include <QMouseEvent> |
| 25 | #include <QDebug> |
| 26 | |
| 27 | #include "theme.h"cxx . . $ `<file>/src/theme.h`/ |
| 28 | #include "field.h"cxx . . $ `<file>/src/field.h`/ |
| 29 | #include "common.h"cxx . . $ `<file>/src/common.h`/ |
| 30 | #include "checkers.h"cxx . . $ `<file>/src/checkers.h`/ |
| 31 | |
| 32 | |
| 33 | Fieldcxx . . $ Field#::Fieldcxx . . $ Field#Field(3f47e595a91bc133).(QObjectcxx . . $ QObject#* parent,int i) |
| 34 | : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent) |
| 35 | { |
| 36 | pixmapcxx . . $ Field#pixmap. = new QPixmapcxx . . $ QPixmap#QPixmap(3e454b8ccf442868).(128, 128); |
| 37 | pixmap_validcxx . . $ Field#pixmap_valid. = false; |
| 38 | |
| 39 | m_numbercxx . . $ Field#m_number.=i; |
| 40 | |
| 41 | show_framecxx . . $ Field#show_frame. = false; |
| 42 | |
| 43 | m_show_labelcxx . . $ Field#m_show_label. = true; |
| 44 | |
| 45 | setup_modecxx . . $ Field#setup_mode. = false; |
| 46 | |
| 47 | m_pattern_idcxx . . $ Field#m_pattern_id. = 0; |
| 48 | m_checker_idcxx . . $ Field#m_checker_id. = FREEcxx . . $ `src/checkers.h:35:9`!; |
| 49 | } |
| 50 | |
| 51 | Fieldcxx . . $ Field#::~cxx . . $ Field#`~Field`(ced63f7c635d850d).Fieldcxx . . $ Field#() { |
| 52 | if (pixmapcxx . . $ Field#pixmap.) { |
| 53 | delete pixmapcxx . . $ Field#pixmap.; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | void Fieldcxx . . $ Field#::beginSetupcxx . . $ Field#beginSetup(49f6e7a06ebc5aa8).() { |
| 58 | Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:861:13`!(! setup_mode); |
| 59 | //qInfo("beginSetup(%d)", m_number); |
| 60 | setup_modecxx . . $ Field#setup_mode. = true; |
| 61 | } |
| 62 | |
| 63 | void Fieldcxx . . $ Field#::endSetupcxx . . $ Field#endSetup(49f6e7a06ebc5aa8).() { |
| 64 | Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:861:13`!(setup_mode); |
| 65 | //qInfo("endSetup(%d)", m_number); |
| 66 | |
| 67 | setup_modecxx . . $ Field#setup_mode. = false; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /* |
| 72 | void Field::paintEvent(QPaintEvent*) |
| 73 | { |
| 74 | QPainter p(this); |
| 75 | |
| 76 | draw(); |
| 77 | Q_ASSERT(pixmap_valid); |
| 78 | p.drawPixmap(0, 0, *pixmap); |
| 79 | |
| 80 | p.end(); |
| 81 | } |
| 82 | */ |
| 83 | |
| 84 | |
| 85 | /* |
| 86 | void Field::mousePressEvent(QMouseEvent* me) |
| 87 | { |
| 88 | if(me->button() != Qt::LeftButton) |
| 89 | return; |
| 90 | emit click(m_number); |
| 91 | } |
| 92 | */ |
| 93 | |
| 94 | void Fieldcxx . . $ Field#::invalidatecxx . . $ Field#invalidate(49f6e7a06ebc5aa8).() { |
| 95 | pixmap_validcxx . . $ Field#pixmap_valid. = false; |
| 96 | } |
| 97 | |
| 98 | void Fieldcxx . . $ Field#::drawcxx . . $ Field#draw(49f6e7a06ebc5aa8).() |
| 99 | { |
| 100 | if (pixmap_validcxx . . $ Field#pixmap_valid.) { |
| 101 | return; |
| 102 | } |
| 103 | /*if (pixmap) { |
| 104 | delete pixmap; |
| 105 | }*/ |
| 106 | /*QSize mySize = size(); |
| 107 | if (mySize.height() == 0 || mySize.width() == 0) { |
| 108 | return; |
| 109 | }*/ |
| 110 | //qInfo("Draw: %d x %d", mySize.width(), mySize.height()); |
| 111 | //pixmap = new QPixmap(128, 128); |
| 112 | |
| 113 | pixmapcxx . . $ Field#pixmap.->fillcxx . . $ QPixmap#fill(129a55e114526ad3).(Qtcxx . . $ QColor#QColor(408ec4d5924bfb00).::whitecxx . . $ Qt/white.); |
| 114 | QPaintercxx . . $ QPainter# paintcxx . . $ QPainter#QPainter(49f6e7a06ebc5aa8).; |
| 115 | paint.begincxx . . $ QPainter#begin(3d42010d693361d5).(pixmapcxx . . $ Field#pixmap.); |
| 116 | //paint.setFont(font()); |
| 117 | |
| 118 | if (m_pattern_idcxx . . $ Field#m_pattern_id.) { |
| 119 | QPixmapcxx . . $ QPixmap#& pattern = m_themecxx . . $ Field#m_theme.->getPatterncxx . . $ Theme#getPattern(d87f11e1b39fe07).(m_pattern_idcxx . . $ Field#m_pattern_id.); |
| 120 | if (! pattern.isNullcxx . . $ QPixmap#isNull(50ce9a9e25b4a850).()) { |
| 121 | paint.drawPixmapcxx . . $ QPainter#drawPixmap(c906314a67120896).(0, 0, pattern); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // notation |
| 126 | paint.setPencxx . . $ QPainter#setPen(129a55e114526ad3).(Qtcxx . . $ QColor#QColor(408ec4d5924bfb00).::whitecxx . . $ Qt/white.); |
| 127 | QRectcxx . . $ QRect# not_rect = paint.boundingRectcxx . . $ QPainter#boundingRect(e4dbe49932017af9).(2, 2, 0, 0, Qtcxx . . $ Qt/::AlignLeftcxx . . $ Qt/AlignLeft., m_labelcxx . . $ Field#m_label.); |
| 128 | QPixmapcxx . . $ QPixmap#& checker = m_themecxx . . $ Field#m_theme.->getCheckercxx . . $ Theme#getChecker(4ba5b81937b338e1).(m_checker_idcxx . . $ Field#m_checker_id., m_bottom_is_whitecxx . . $ Field#m_bottom_is_white.); |
| 129 | if (m_show_abovecxx . . $ Field#m_show_above.) { |
| 130 | if (! checker.isNullcxx . . $ QPixmap#isNull(50ce9a9e25b4a850).()) |
| 131 | paint.drawPixmapcxx . . $ QPainter#drawPixmap(c906314a67120896).(0, 0, checker); |
| 132 | if (m_show_labelcxx . . $ Field#m_show_label.) { |
| 133 | paint.fillRectcxx . . $ QPainter#fillRect(26a0210a6d40746b).(not_rect, Qtcxx . . $ Qt/::blackcxx . . $ Qt/black.); |
| 134 | paint.drawTextcxx . . $ QPainter#drawText(5e6899f7fbe08e9d).(not_rect, Qtcxx . . $ Qt/::AlignTopcxx . . $ Qt/AlignTop.|cxx . . $ Qt/`operator|`(6ff00bf3a2570bcb).Qtcxx . . $ Qt/::AlignLeftcxx . . $ Qt/AlignLeft., m_labelcxx . . $ Field#m_label.); |
| 135 | } |
| 136 | } else { |
| 137 | if (m_show_labelcxx . . $ Field#m_show_label.) |
| 138 | paint.drawTextcxx . . $ QPainter#drawText(5e6899f7fbe08e9d).(not_rect, Qtcxx . . $ Qt/::AlignTopcxx . . $ Qt/AlignTop.|cxx . . $ Qt/`operator|`(6ff00bf3a2570bcb).Qtcxx . . $ Qt/::AlignLeftcxx . . $ Qt/AlignLeft., m_labelcxx . . $ Field#m_label.); |
| 139 | if (! checker.isNullcxx . . $ QPixmap#isNull(50ce9a9e25b4a850).()) |
| 140 | paint.drawPixmapcxx . . $ QPainter#drawPixmap(c906314a67120896).(0, 0, checker); |
| 141 | } |
| 142 | |
| 143 | if (show_framecxx . . $ Field#show_frame.) { |
| 144 | QPixmapcxx . . $ QPixmap#& frame = m_themecxx . . $ Field#m_theme.->getFramecxx . . $ Theme#getFrame(249fa7b9f2945cb1).(); |
| 145 | paint.drawPixmapcxx . . $ QPainter#drawPixmap(c906314a67120896).(0, 0, frame); |
| 146 | } |
| 147 | |
| 148 | paint.endcxx . . $ QPainter#end(c9857a73d68e59ba).(); |
| 149 | //update(); |
| 150 | pixmap_validcxx . . $ Field#pixmap_valid. = true; |
| 151 | } |
| 152 | |
| 153 | void Fieldcxx . . $ Field#::drawcxx . . $ Field#draw(34758fb9d6aa1963).(QPaintercxx . . $ QPainter#& painter, QRectcxx . . $ QRect# rect) { |
| 154 | m_rectcxx . . $ Field#m_rect. =cxx . . $ QRect#`operator=`(7cfd2b8ed4e6a4e). rect; |
| 155 | drawcxx . . $ Field#draw(49f6e7a06ebc5aa8).(); |
| 156 | Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:861:13`!(pixmap_valid); |
| 157 | painter.drawPixmapcxx . . $ QPainter#drawPixmap(c906314a67120896).(rect.xcxx . . $ QRect#x(ea6fe5115c70a13f).(), rect.ycxx . . $ QRect#y(ea6fe5115c70a13f).(), *pixmapcxx . . $ Field#pixmap.); |
| 158 | } |
| 159 | |
| 160 | const QRectcxx . . $ QRect#& Fieldcxx . . $ Field#::rectcxx . . $ Field#rect(f4023511c62cad66).() const { |
| 161 | return m_rectcxx . . $ Field#m_rect.; |
| 162 | } |
| 163 | |
| 164 | void Fieldcxx . . $ Field#::showFramecxx . . $ Field#showFrame(b45ddcbc8423892c).(bool b) |
| 165 | { |
| 166 | if(show_framecxx . . $ Field#show_frame. != b) { |
| 167 | show_framecxx . . $ Field#show_frame. = b; |
| 168 | invalidatecxx . . $ Field#invalidate(49f6e7a06ebc5aa8).(); |
| 169 | drawcxx . . $ Field#draw(49f6e7a06ebc5aa8).(); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | void Fieldcxx . . $ Field#::setPatterncxx . . $ Field#setPattern(d4f767463ce0a6b3).(int i) |
| 174 | { |
| 175 | if (i != m_pattern_idcxx . . $ Field#m_pattern_id.) { |
| 176 | m_pattern_idcxx . . $ Field#m_pattern_id. = i; |
| 177 | invalidatecxx . . $ Field#invalidate(49f6e7a06ebc5aa8).(); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | void Fieldcxx . . $ Field#::setThemecxx . . $ Field#setTheme(99b847e279ae44f4).(Themecxx . . $ Theme#* theme) { |
| 182 | Q_ASSERTcxx . . $ `<external>/15045578679651060896/qglobal.h:861:13`!(theme); |
| 183 | m_themecxx . . $ Field#m_theme. = theme; |
| 184 | invalidatecxx . . $ Field#invalidate(49f6e7a06ebc5aa8).(); |
| 185 | drawcxx . . $ Field#draw(49f6e7a06ebc5aa8).(); |
| 186 | } |
| 187 | |
| 188 | void Fieldcxx . . $ Field#::setcxx . . $ Field#set(918ebd27a9ddbad3).(int item, bool bottom_is_white) { |
| 189 | if (m_checker_idcxx . . $ Field#m_checker_id. != item || m_bottom_is_whitecxx . . $ Field#m_bottom_is_white. != bottom_is_white) { |
| 190 | m_checker_idcxx . . $ Field#m_checker_id. = item; |
| 191 | m_bottom_is_whitecxx . . $ Field#m_bottom_is_white. = bottom_is_white; |
| 192 | invalidatecxx . . $ Field#invalidate(49f6e7a06ebc5aa8).(); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void Fieldcxx . . $ Field#::setLabelcxx . . $ Field#setLabel(3520e46b33348bf6).(const QStringcxx . . $ QString#& str) |
| 197 | { |
| 198 | if(m_labelcxx . . $ Field#m_label.!=cxx . . $ `operator!=`(5bc2975d2d751687).str) { |
| 199 | m_labelcxx . . $ Field#m_label.=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).str; |
| 200 | invalidatecxx . . $ Field#invalidate(49f6e7a06ebc5aa8).(); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | |
| 205 | void Fieldcxx . . $ Field#::showLabelcxx . . $ Field#showLabel(b0b38cda41d4ede4).(bool s, bool a) |
| 206 | { |
| 207 | if(s!=m_show_labelcxx . . $ Field#m_show_label. || a!=m_show_abovecxx . . $ Field#m_show_above.) { |
| 208 | m_show_abovecxx . . $ Field#m_show_above. = a; |
| 209 | m_show_labelcxx . . $ Field#m_show_label. = s; |
| 210 | invalidatecxx . . $ Field#invalidate(49f6e7a06ebc5aa8).(); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | QSize Field::sizeHint() const { |
| 216 | if (! m_theme) { |
| 217 | return QSize(); |
| 218 | } else { |
| 219 | return QSize(m_theme->getFieldWidth(), m_theme->getFieldHeight()); |
| 220 | } |
| 221 | } |
| 222 | */ |
| 223 | |
| 224 | /* |
| 225 | void Field::resizeEvent(QResizeEvent* e) { |
| 226 | invalidate(); |
| 227 | if (e->size().width() == 0 || e->size().height() == 0) { |
| 228 | return; |
| 229 | } |
| 230 | draw(); |
| 231 | } |
| 232 | */ |
| 233 |