10
10
11
11
// BinaryView
12
12
13
- const int CELL_HEIGHT = 26 ;
13
+ const int CELL_HEIGHT = 36 ;
14
14
15
15
inline int get_bit_index (const QModelIndex &index, bool little_endian) {
16
16
return index .row () * 8 + (little_endian ? 7 - index .column () : index .column ());
@@ -24,14 +24,13 @@ BinaryView::BinaryView(QWidget *parent) : QTableView(parent) {
24
24
horizontalHeader ()->setSectionResizeMode (QHeaderView::Stretch);
25
25
verticalHeader ()->setSectionsClickable (false );
26
26
verticalHeader ()->setSectionResizeMode (QHeaderView::Fixed );
27
+ verticalHeader ()->setDefaultSectionSize (CELL_HEIGHT);
27
28
horizontalHeader ()->hide ();
28
- setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
29
- setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
30
- setSizeAdjustPolicy (QAbstractScrollArea::AdjustToContents);
31
29
setFrameShape (QFrame::NoFrame);
32
30
setShowGrid (false );
33
- setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Minimum);
34
31
setMouseTracking (true );
32
+ setSizeAdjustPolicy (QAbstractScrollArea::AdjustToContents);
33
+ setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Fixed );
35
34
}
36
35
37
36
void BinaryView::highlight (const Signal *sig) {
@@ -57,7 +56,7 @@ void BinaryView::setSelection(const QRect &rect, QItemSelectionModel::SelectionF
57
56
}
58
57
59
58
void BinaryView::mousePressEvent (QMouseEvent *event) {
60
- delegate->setSelectionColor ( style ()-> standardPalette ().color (QPalette::Active, QPalette::Highlight));
59
+ delegate->selection_color = ( palette ().color (QPalette::Active, QPalette::Highlight));
61
60
if (auto index = indexAt (event->pos ()); index .isValid () && index .column () != 8 ) {
62
61
anchor_index = index ;
63
62
auto item = (const BinaryViewModel::Item *)anchor_index.internalPointer ();
@@ -66,7 +65,7 @@ void BinaryView::mousePressEvent(QMouseEvent *event) {
66
65
if (bit_idx == s->lsb || bit_idx == s->msb ) {
67
66
anchor_index = model->bitIndex (bit_idx == s->lsb ? s->msb : s->lsb , true );
68
67
resize_sig = s;
69
- delegate->setSelectionColor ( item->bg_color ) ;
68
+ delegate->selection_color = item->bg_color ;
70
69
break ;
71
70
}
72
71
}
@@ -79,8 +78,7 @@ void BinaryView::highlightPosition(const QPoint &pos) {
79
78
auto item = (BinaryViewModel::Item *)index .internalPointer ();
80
79
const Signal *sig = item->sigs .isEmpty () ? nullptr : item->sigs .back ();
81
80
highlight (sig);
82
- sig ? QToolTip::showText (pos, sig->name .c_str (), this , rect ())
83
- : QToolTip::hideText ();
81
+ QToolTip::showText (pos, sig ? sig->name .c_str () : " " , this , rect ());
84
82
}
85
83
}
86
84
@@ -214,7 +212,7 @@ QVariant BinaryViewModel::headerData(int section, Qt::Orientation orientation, i
214
212
if (orientation == Qt::Vertical) {
215
213
switch (role) {
216
214
case Qt::DisplayRole: return section;
217
- case Qt::SizeHintRole: return QSize (30 , CELL_HEIGHT );
215
+ case Qt::SizeHintRole: return QSize (30 , 0 );
218
216
case Qt::TextAlignmentRole: return Qt::AlignCenter;
219
217
}
220
218
}
@@ -224,16 +222,9 @@ QVariant BinaryViewModel::headerData(int section, Qt::Orientation orientation, i
224
222
// BinaryItemDelegate
225
223
226
224
BinaryItemDelegate::BinaryItemDelegate (QObject *parent) : QStyledItemDelegate(parent) {
227
- // cache fonts and color
228
- small_font.setPointSize (6 );
225
+ small_font.setPixelSize (8 );
229
226
hex_font = QFontDatabase::systemFont (QFontDatabase::FixedFont);
230
227
hex_font.setBold (true );
231
- selection_color = QApplication::style ()->standardPalette ().color (QPalette::Active, QPalette::Highlight);
232
- }
233
-
234
- QSize BinaryItemDelegate::sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const {
235
- QSize sz = QStyledItemDelegate::sizeHint (option, index );
236
- return {sz.width (), CELL_HEIGHT};
237
228
}
238
229
239
230
void BinaryItemDelegate::paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
@@ -245,19 +236,16 @@ void BinaryItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
245
236
painter->setFont (hex_font);
246
237
} else if (option.state & QStyle::State_Selected) {
247
238
painter->fillRect (option.rect , selection_color);
248
- painter->setPen (QApplication::style ()-> standardPalette () .color (QPalette::BrightText));
239
+ painter->setPen (option. palette .color (QPalette::BrightText));
249
240
} else if (!item->sigs .isEmpty () && (!bin_view->selectionModel ()->hasSelection () || !item->sigs .contains (bin_view->resize_sig ))) {
250
241
painter->fillRect (option.rect , item->bg_color );
251
- painter->setPen (item->sigs .contains (bin_view->hovered_sig )
252
- ? QApplication::style ()->standardPalette ().color (QPalette::BrightText)
253
- : Qt::black);
242
+ painter->setPen (item->sigs .contains (bin_view->hovered_sig ) ? option.palette .color (QPalette::BrightText) : Qt::black);
254
243
}
255
244
256
245
painter->drawText (option.rect , Qt::AlignCenter, item->val );
257
246
if (item->is_msb || item->is_lsb ) {
258
247
painter->setFont (small_font);
259
248
painter->drawText (option.rect , Qt::AlignHCenter | Qt::AlignBottom, item->is_msb ? " MSB" : " LSB" );
260
249
}
261
-
262
250
painter->restore ();
263
251
}
0 commit comments