bool PYInfoPad::drawCheckBox(QPainter *painter, const QRectF &HeaderRect, qreal initY, int CateIndex) { // draw check box QPointF HeaderCheckBoxTopLeft(SIW_LEFT_SPACE,HeaderRect.center().y() - (qreal)SIW_BOX_WIDTH/2); QPointF HeaderCheckBoxBottomRight(SIW_LEFT_SPACE + SIW_BOX_WIDTH,HeaderRect.center().y() + (qreal)SIW_BOX_WIDTH/2); QRectF HeaderCheckBox(HeaderCheckBoxTopLeft,HeaderCheckBoxBottomRight); m_CategoryInfoVec.at(CateIndex)->SetRect(HeaderCheckBox); painter->save(); painter->setRenderHints(QPainter::Antialiasing,false); painter->setPen(SIW_BOX_PEN_COLOR); QLinearGradient BoxGradient(HeaderCheckBox.topLeft(),HeaderCheckBox.bottomLeft()); BoxGradient.setColorAt(0.0,SIW_BOX_START_COLOR); BoxGradient.setColorAt(1.0,SIW_BOX_END_COLOR); painter->setBrush(BoxGradient); painter->drawRect(HeaderCheckBox); painter->restore(); qreal textStartX = HeaderCheckBoxBottomRight.x(); // if icon is visible the draw category icon if( m_bIconVisible && m_CategoryInfoVec.at(CateIndex)->IsIconVisible() && !m_CategoryInfoVec.at(CateIndex)->GetIcon().isNull() ) { textStartX += SIW_EXTRA_SPACE * 2 + SIW_ICON_SIZE.width(); QPointF iconTopLeft(HeaderCheckBoxBottomRight.x() + SIW_EXTRA_SPACE, initY + SIW_EXTRA_SPACE); QPixmap pixmap = m_CategoryInfoVec.at(CateIndex)->GetIcon().pixmap(SIW_ICON_SIZE); painter->drawPixmap(iconTopLeft,pixmap); } // draw catogory text QPointF CategoryTextPot(textStartX + SIW_BOX_TEXT_SPACE,HeaderCheckBoxBottomRight.y()); painter->setPen(SIW_CATEGORY_COLOR); painter->save(); QFont CategoryFont; CategoryFont.setBold(true); painter->setFont(CategoryFont); painter->drawText(CategoryTextPot,m_CategoryInfoVec.at(CateIndex)->GetCaption()); painter->restore(); // draw horizontal handle QPointF CheckBoxLeftPot(HeaderCheckBox.topLeft().x() + SIW_BOX_WIDTH_EXTRA,HeaderCheckBox.center().y()); QPointF CheckBoxRightPot(HeaderCheckBox.topRight().x() - SIW_BOX_WIDTH_EXTRA,HeaderCheckBox.center().y()); painter->drawLine(CheckBoxLeftPot,CheckBoxRightPot); // draw vertical handle if(!m_CategoryInfoVec.at(CateIndex)->IsExpand() || m_CategoryInfoVec.at(CateIndex)->GetData().count() == 0) { QPointF CheckBoxTopPot(HeaderCheckBox.center().x(),qreal(HeaderCheckBox.center().y() - SIW_BOX_HALF_WIDTH)); QPointF CheckBoxBottomPot(HeaderCheckBox.center().x(),qreal(HeaderCheckBox.center().y() + SIW_BOX_HALF_WIDTH + 2)); painter->drawLine(CheckBoxTopPot,CheckBoxBottomPot); return false; } return true; }
/****************************************************************************** * Paint one value in one of the columns in the list view. */ void AlarmListViewItem::paintCell(QPainter *painter, const QColorGroup &cg, int column, int width, int /*align*/) { const AlarmListView *listView = alarmListView(); int margin = listView->itemMargin(); QRect box(margin, margin, width - margin * 2, height() - margin * 2); // area within which to draw bool selected = isSelected(); QColor bgColour = selected ? cg.highlight() : cg.base(); QColor fgColour = selected ? cg.highlightedText() : !event().enabled() ? Preferences::disabledColour() : event().expired() ? Preferences::expiredColour() : cg.text(); painter->setPen(fgColour); painter->fillRect(0, 0, width, height(), bgColour); if(column == listView->column(AlarmListView::TIME_COLUMN)) { int i = -1; QString str = text(column); if(mTimeHourPos >= 0) { // Need to pad out spacing to align times without leading zeroes i = str.find(" ~"); if(i >= 0) { if(mDigitWidth < 0) mDigitWidth = painter->fontMetrics().width("0"); QString date = str.left(i + 1); int w = painter->fontMetrics().width(date) + mDigitWidth; painter->drawText(box, AlignVCenter, date); box.setLeft(box.left() + w); painter->drawText(box, AlignVCenter, str.mid(i + 2)); } } if(i < 0) painter->drawText(box, AlignVCenter, str); } else if(column == listView->column(AlarmListView::TIME_TO_COLUMN)) painter->drawText(box, AlignVCenter | AlignRight, text(column)); else if(column == listView->column(AlarmListView::REPEAT_COLUMN)) painter->drawText(box, AlignVCenter | AlignHCenter, text(column)); else if(column == listView->column(AlarmListView::COLOUR_COLUMN)) { // Paint the cell the colour of the alarm message if(event().action() == KAEvent::MESSAGE || event().action() == KAEvent::FILE) painter->fillRect(box, event().bgColour()); } else if(column == listView->column(AlarmListView::TYPE_COLUMN)) { // Display the alarm type icon, horizontally and vertically centred in the cell QPixmap *pixmap = eventIcon(); QRect pixmapRect = pixmap->rect(); int diff = box.height() - pixmap->height(); if(diff < 0) { pixmapRect.setTop(-diff / 2); pixmapRect.setHeight(box.height()); } QPoint iconTopLeft(box.left() + (box.width() - pixmapRect.width()) / 2, box.top() + (diff > 0 ? diff / 2 : 0)); painter->drawPixmap(iconTopLeft, *pixmap, pixmapRect); } else if(column == listView->column(AlarmListView::MESSAGE_COLUMN)) { if(!selected && listView->drawMessageInColour()) { painter->fillRect(box, event().bgColour()); painter->setBackgroundColor(event().bgColour()); // painter->setPen(event().fgColour()); } QString txt = text(column); painter->drawText(box, AlignVCenter, txt); mMessageColWidth = listView->fontMetrics().boundingRect(txt).width(); } }