Changeset View
Changeset View
Standalone View
Standalone View
kcalc_bitset.cpp
Show All 21 Lines | |||||
22 | #include "kcalc_bitset.h" | 22 | #include "kcalc_bitset.h" | ||
23 | #include "bitbutton.h" | 23 | #include "bitbutton.h" | ||
24 | 24 | | |||
25 | #include <QButtonGroup> | 25 | #include <QButtonGroup> | ||
26 | #include <QGridLayout> | 26 | #include <QGridLayout> | ||
27 | #include <QHBoxLayout> | 27 | #include <QHBoxLayout> | ||
28 | #include <QLabel> | 28 | #include <QLabel> | ||
29 | #include <QPainter> | 29 | #include <QPainter> | ||
30 | #include <klocalizedstring.h> | ||||
30 | 31 | | |||
31 | 32 | | |||
32 | 33 | | |||
33 | // TODO: I think it would actually be appropriate to use a std::bitset<64> | 34 | // TODO: I think it would actually be appropriate to use a std::bitset<64> | ||
34 | // for the internal representation of this class perhaps | 35 | // for the internal representation of this class perhaps | ||
35 | // the only real caveat is the conversion to/from quint64 | 36 | // the only real caveat is the conversion to/from quint64 | ||
36 | 37 | | |||
37 | //------------------------------------------------------------------------------ | 38 | //------------------------------------------------------------------------------ | ||
38 | // Name: paintEvent | 39 | // Name: paintEvent | ||
39 | // Desc: draws the button | 40 | // Desc: draws the button | ||
40 | //------------------------------------------------------------------------------ | 41 | //------------------------------------------------------------------------------ | ||
41 | void BitButton::paintEvent(QPaintEvent *) { | 42 | void BitButton::paintEvent(QPaintEvent *) { | ||
42 | 43 | | |||
44 | uint8_t alpha = 0x60; | ||||
43 | QPainter painter(this); | 45 | QPainter painter(this); | ||
44 | QPen pen(palette().text(), 2); | 46 | QPen pen(palette().text(), 1); | ||
45 | pen.setJoinStyle(Qt::MiterJoin); | 47 | pen.setJoinStyle(Qt::MiterJoin); | ||
46 | painter.setPen(pen); | 48 | painter.setPen(pen); | ||
47 | 49 | | |||
48 | if (on_) { | 50 | if (on_) { | ||
49 | painter.setBrush(palette().text()); | 51 | painter.setBrush(palette().text()); | ||
52 | alpha = 0xB0; | ||||
50 | } else { | 53 | } else { | ||
51 | painter.setBrush(palette().base()); | 54 | painter.setBrush(palette().base()); | ||
52 | } | 55 | } | ||
53 | 56 | | |||
57 | if (over_) { | ||||
58 | painter.setBrush(QColor(palette().text().color().red(), | ||||
59 | palette().text().color().green(), | ||||
60 | palette().text().color().blue(), | ||||
61 | alpha)); | ||||
62 | } | ||||
63 | | ||||
54 | painter.drawRect(rect().adjusted(1, 1, -1, -1)); | 64 | painter.drawRect(rect().adjusted(1, 1, -1, -1)); | ||
55 | } | 65 | } | ||
56 | 66 | | |||
57 | //------------------------------------------------------------------------------ | 67 | //------------------------------------------------------------------------------ | ||
58 | // Name: KCalcBitset | 68 | // Name: KCalcBitset | ||
59 | // Desc: constructor | 69 | // Desc: constructor | ||
60 | //------------------------------------------------------------------------------ | 70 | //------------------------------------------------------------------------------ | ||
61 | KCalcBitset::KCalcBitset(QWidget *parent) : QFrame(parent), bit_button_group_(new QButtonGroup(this)), value_(0) { | 71 | KCalcBitset::KCalcBitset(QWidget *parent) : QFrame(parent), bit_button_group_(new QButtonGroup(this)), value_(0) { | ||
Show All 20 Lines | 91 | for (int cols = 0; cols < 4; cols++) { | |||
82 | // two rows of four words | 92 | // two rows of four words | ||
83 | QHBoxLayout *const wordlayout = new QHBoxLayout(); | 93 | QHBoxLayout *const wordlayout = new QHBoxLayout(); | ||
84 | wordlayout->setContentsMargins(2, 2, 2, 2); | 94 | wordlayout->setContentsMargins(2, 2, 2, 2); | ||
85 | wordlayout->setSpacing(2); | 95 | wordlayout->setSpacing(2); | ||
86 | layout->addLayout(wordlayout, rows, cols); | 96 | layout->addLayout(wordlayout, rows, cols); | ||
87 | 97 | | |||
88 | for (int bit = 0; bit < 8; bit++) { | 98 | for (int bit = 0; bit < 8; bit++) { | ||
89 | BitButton *const tmpBitButton = new BitButton(this); | 99 | BitButton *const tmpBitButton = new BitButton(this); | ||
100 | tmpBitButton->setToolTip(i18n("Bit %1", bitCounter)); | ||||
aacid: we don't use tr but i18n, this should be i18n("Bit %1", bitCounter) | |||||
90 | wordlayout->addWidget(tmpBitButton); | 101 | wordlayout->addWidget(tmpBitButton); | ||
91 | bit_button_group_->addButton(tmpBitButton, bitCounter); | 102 | bit_button_group_->addButton(tmpBitButton, bitCounter); | ||
92 | bitCounter--; | 103 | bitCounter--; | ||
93 | } | 104 | } | ||
94 | 105 | | |||
95 | // label word | 106 | // label word | ||
96 | QLabel *label = new QLabel(this); | 107 | QLabel *label = new QLabel(this); | ||
97 | label->setText(QString::number(bitCounter + 1)); | 108 | label->setText(QString::number(bitCounter + 1)); | ||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |
we don't use tr but i18n, this should be i18n("Bit %1", bitCounter)