Ejemplo n.º 1
0
 void paint(QPainter *painter, const QStyleOptionViewItem &option,
     const QModelIndex &index) const
 {
     if (index.column() == 1) {
         bool paintRed = currentHandler()->registerAt(index.row()).changed;
         QPen oldPen = painter->pen();
         if (paintRed)
             painter->setPen(QColor(200, 0, 0));
         // FIXME: performance? this changes only on real font changes.
         QFontMetrics fm(option.font);
         int charWidth = fm.width(QLatin1Char('x'));
         for (int i = '1'; i <= '9'; ++i)
             charWidth = qMax(charWidth, fm.width(QLatin1Char(i)));
         for (int i = 'a'; i <= 'f'; ++i)
             charWidth = qMax(charWidth, fm.width(QLatin1Char(i)));
         QString str = index.data(Qt::DisplayRole).toString();
         int x = option.rect.x();
         for (int i = 0; i < str.size(); ++i) {
             QRect r = option.rect;
             r.setX(x);
             r.setWidth(charWidth);
             x += charWidth;
             painter->drawText(r, Qt::AlignHCenter, QString(str.at(i)));
         }
         if (paintRed)
             painter->setPen(oldPen);
     } else {
         QItemDelegate::paint(painter, option, index);
     }
 }
Ejemplo n.º 2
0
 void setModelData(QWidget *editor, QAbstractItemModel *,
     const QModelIndex &index) const
 {
     if (index.column() != 1)
         return;
     IntegerWatchLineEdit *lineEdit = qobject_cast<IntegerWatchLineEdit*>(editor);
     QTC_ASSERT(lineEdit, return);
     const int base = currentHandler()->numberBase();
     QString value = lineEdit->text();
     if (base == 16 && !value.startsWith(QLatin1String("0x")))
         value.insert(0, QLatin1String("0x"));
     currentEngine()->setRegisterValue(index.row(), value);
 }