#include <bookdelegate.h>
Inheritance diagram for BookDelegate:


Definition at line 34 of file bookdelegate.h.
Public Member Functions | |
| BookDelegate (QObject *parent) | |
| void | paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| QSize | sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const |
| bool | editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) |
| QWidget * | createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const |
Private Attributes | |
| QPixmap | star |
| BookDelegate::BookDelegate | ( | QObject * | parent | ) |
Definition at line 28 of file bookdelegate.cpp.
00029 : QSqlRelationalDelegate(parent), star(QPixmap(":images/star.png")) 00030 { 00031 }
| void BookDelegate::paint | ( | QPainter * | painter, | |
| const QStyleOptionViewItem & | option, | |||
| const QModelIndex & | index | |||
| ) | const |
Definition at line 33 of file bookdelegate.cpp.
References QRect::adjust(), QRect::adjusted(), QRect::bottomLeft(), QRect::bottomRight(), QPalette::color(), QAbstractItemModel::data(), QPalette::Disabled, Qt::DisplayRole, QPainter::drawLine(), QPainter::drawPixmap(), QPainter::fillRect(), QPixmap::height(), height, QRect::height(), QPalette::Highlight, i, index, QPalette::Mid, QPalette::Normal, QStyleOption::palette, QPainter::pen(), QStyleOption::rect, QPainter::setPen(), star, QStyleOption::state, QStyle::State_Enabled, QStyle::State_Selected, QVariant::toInt(), QRect::topRight(), QPixmap::width(), width, QRect::x(), x, QRect::y(), and y.
00035 { 00036 if (index.column() != 5) { 00037 QStyleOptionViewItem opt = option; 00038 opt.rect.adjust(0, 0, -1, -1); // since we draw the grid ourselves 00039 QSqlRelationalDelegate::paint(painter, opt, index); 00040 } else { 00041 const QAbstractItemModel *model = index.model(); 00042 QPalette::ColorGroup cg = option.state & QStyle::State_Enabled 00043 ? QPalette::Normal : QPalette::Disabled; 00044 if (option.state & QStyle::State_Selected) 00045 painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); 00046 00047 int rating = model->data(index, Qt::DisplayRole).toInt(); 00048 int width = star.width(); 00049 int height = star.height(); 00050 int x = option.rect.x(); 00051 int y = option.rect.y() + (option.rect.height() / 2) - (height / 2); 00052 for (int i = 0; i < rating; ++i) { 00053 painter->drawPixmap(x, y, star); 00054 x += width; 00055 } 00056 drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves 00057 } 00058 00059 QPen pen = painter->pen(); 00060 painter->setPen(option.palette.color(QPalette::Mid)); 00061 painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); 00062 painter->drawLine(option.rect.topRight(), option.rect.bottomRight()); 00063 painter->setPen(pen); 00064 }
Here is the call graph for this function:

| QSize BookDelegate::sizeHint | ( | const QStyleOptionViewItem & | option, | |
| const QModelIndex & | index | |||
| ) | const |
Definition at line 66 of file bookdelegate.cpp.
References QPixmap::height(), index, star, and QPixmap::width().
00068 { 00069 if (index.column() == 5) 00070 return QSize(5 * star.width(), star.height()) + QSize(1, 1); 00071 00072 return QSqlRelationalDelegate::sizeHint(option, index) + QSize(1, 1); // since we draw the grid ourselves 00073 }
Here is the call graph for this function:

| bool BookDelegate::editorEvent | ( | QEvent * | event, | |
| QAbstractItemModel * | model, | |||
| const QStyleOptionViewItem & | option, | |||
| const QModelIndex & | index | |||
| ) |
Definition at line 75 of file bookdelegate.cpp.
References index, QEvent::MouseButtonPress, QTest::mouseEvent(), QStyleOption::rect, QAbstractItemModel::setData(), star, QPixmap::width(), and QRect::x().
00078 { 00079 if (index.column() != 5) 00080 return QSqlRelationalDelegate::editorEvent(event, model, option, index); 00081 00082 QMouseEvent *mouseEvent; 00083 int stars; 00084 00085 switch (event->type()) { 00086 case QEvent::MouseButtonPress: 00087 mouseEvent = static_cast<QMouseEvent*>(event); 00088 stars = qBound(0, int(0.7 + qreal(mouseEvent->pos().x() 00089 - option.rect.x()) / star.width()), 5); 00090 model->setData(index, QVariant(stars)); 00091 break; 00092 default: 00093 break; 00094 } 00095 00096 return true; 00097 }
Here is the call graph for this function:

| QWidget * BookDelegate::createEditor | ( | QWidget * | parent, | |
| const QStyleOptionViewItem & | option, | |||
| const QModelIndex & | index | |||
| ) | const |
Definition at line 99 of file bookdelegate.cpp.
References index, QAbstractSpinBox::setFrame(), QSpinBox::setMaximum(), and QSpinBox::setMinimum().
00101 { 00102 if (index.column() != 4) 00103 return QSqlRelationalDelegate::createEditor(parent, option, index); 00104 00105 // for editing the year, return a spinbox with a range from -1000 to 2100. 00106 QSpinBox *sb = new QSpinBox(parent); 00107 sb->setFrame(false); 00108 sb->setMaximum(2100); 00109 sb->setMinimum(-1000); 00110 00111 return sb; 00112 }
Here is the call graph for this function:

QPixmap BookDelegate::star [private] |
1.5.1