void State::refresh() { emit charsetUpdated(); emit charIndexUpdated(_charIndex); emit tileIndexUpdated(_tileIndex); emit tilePropertiesUpdated(); emit multicolorModeToggled(shouldBeDisplayedInMulticolor()); emit colorPropertiesUpdated(_selectedPen); }
void State::_setColorForPen(int pen, int color) { Q_ASSERT(pen >=0 && pen < PEN_MAX); Q_ASSERT(color >=0 && color < 16); if (_penColors[pen] != color) { bool oldvalue = shouldBeDisplayedInMulticolor(); _penColors[pen] = color; bool newvalue = shouldBeDisplayedInMulticolor(); emit colorPropertiesUpdated(pen); if (oldvalue != newvalue) emit multicolorModeToggled(newvalue); emit contentsChanged(); } }
void CharsetWidget::paintEvent(QPaintEvent *event) { QPainter painter; painter.begin(this); painter.fillRect(event->rect(), QWidget::palette().color(QWidget::backgroundRole())); painter.setBrush(QColor(0,0,0)); painter.setPen(Qt::NoPen); auto state = State::getInstance(); int end_x = 8; int pixel_size_x = _pixelSize.width(); int increment_x = 1; int bits_to_mask = 1; if (state->shouldBeDisplayedInMulticolor()) { end_x = 4; pixel_size_x = _pixelSize.width() * 2; increment_x = 2; bits_to_mask = 3; } QPen pen; pen.setColor({149,195,244,255}); if (hasFocus()) pen.setWidth(3); else pen.setWidth(1); pen.setStyle(Qt::PenStyle::SolidLine); for (int w=0; w<COLUMNS; w++) { for (int h=0; h<ROWS; h++) { int index = w + h * COLUMNS; quint8* charPtr = state->getCharAtIndex(index); for (int y=0; y<8; y++) { char letter = charPtr[y]; for (int x=0; x<end_x; x++) { // Warning: Don't use 'char'. Instead use 'unsigned char'. // 'char' doesn't work Ok with << and >> // only mask the bits are needed unsigned char mask = bits_to_mask << (((end_x-1)-x) * increment_x); unsigned char color = letter & mask; // now transform those bits into values from 0-3 since those are the // possible colors int bits_to_shift = (((end_x-1)-x) * increment_x); int color_pen = color >> bits_to_shift; if (!state->shouldBeDisplayedInMulticolor() && color_pen ) color_pen = State::PEN_FOREGROUND; painter.setBrush(Palette::getColorForPen(color_pen)); painter.drawRect((w*end_x+x) * pixel_size_x + OFFSET, (h*8+y) * _pixelSize.height() + OFFSET, pixel_size_x, _pixelSize.height()); } } painter.setPen(Qt::NoPen); } } if (_selecting) { pen.setColor({149,195,244,255}); painter.setPen(pen); painter.setBrush(QColor(149,195,244,64)); painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET, _cursorPos.y() * 8 * _pixelSize.height() + OFFSET, _selectingSize.width() * 8 * _pixelSize.width(), _selectingSize.height() * 8 * _pixelSize.height()); } else { pen.setColor({149,195,244,255}); painter.setPen(pen); painter.setBrush(QColor(128,0,0,0)); painter.drawRect(_cursorPos.x() * 8 * _pixelSize.width() + OFFSET, _cursorPos.y() * 8 * _pixelSize.height() + OFFSET, 8 * _pixelSize.width(), 8 * _pixelSize.height()); } paintFocus(painter); painter.end(); }