void CMcLogo::OnPaint() { CPaintDC dc(this); // device context for painting CRect Client; GetClientRect(&Client); dc.SetBoundsRect(Client,DCB_SET); CRgn reg; reg.CreateRectRgnIndirect(Client); dc.SelectClipRgn(®); // CRect rendRect(CPoint((Client.Width()-227)/2,0),CSize(227,36)), // rectLeft(0,0,(Client.Width()-227)/2,36), // rectRight((Client.Width()-227)/2+227,0,Client.Width(),36); CRect rendRect(CPoint(0, 0), CSize(227,36)), rectRight(227, 0, Client.Width(), 36); //dc.FillSolidRect(rectLeft,m_BkgColor); dc.FillSolidRect(rectRight, m_BkgColor); if(m_Image.m_pPict) m_Image.Render(&dc, rendRect, rendRect); else dc.FillSolidRect(rendRect, m_BkgColor); }
void MoveDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &) const { QStyleOptionViewItem button = option; QRect rect = option.rect; QRect rectLeft(rect.x() + rect.width()/4 - 8, rect.y() + rect.height()/2 - 5, 30, 15); QRect rectRight(rect.x() + rect.width()*3/4 -8, rect.y() + rect.height()/2 - 5 , 30, 15); QPoint pointUp, pointDown; pointUp.setX(rect.x() + rect.width()/4 - 8); pointUp.setY(rect.y() + rect.height()/2 + 5); pointDown.setX(rect.x() + rect.width()*3/4 -8); pointDown.setY(rect.y() + rect.height()/2 + 5); painter->save(); painter->setPen(leftColor); //QColor(108, 162, 234) (254, 107, 107) painter->drawText(pointUp, leftText); painter->save(); painter->setPen(rightColor); painter->drawText(pointDown, rightText); painter->restore(); // this->drawDisplay(painter, button, rectBu, _text); this->drawFocus(painter, button, rectLeft); this->drawFocus(painter, button, rectRight); painter->restore(); }
static void textEditPaint(struct OzUIWidget *widget) { struct Rect rect, cursorRect; struct OzUITextEdit *textEdit; struct Point p1, p2; int dx, dy; textEdit = (struct OzUITextEdit*)widget->d; initRect(&rect, 0, 0, widget->rect.w, widget->rect.h); //initRect(&tlc.rect, 0, 0, 100000, 100000); OzUIWidgetDrawRectangle(widget, &rect, &blackLS, &whiteFS); if (textEdit && textEdit->layout) { copyRect(&cursorRect, &textEdit->layout->charLayout[textEdit->cursorPos].rect); cursorRect.w = textEdit->fontSize/2; dx = dy = 0; if (rectLeft(&cursorRect) < rectLeft(&rect)) dx = rectLeft(&rect) - rectLeft(&cursorRect); if (rectRight(&cursorRect) > rectRight(&rect)) dx = rectRight(&rect) - rectRight(&cursorRect); if (rectTop(&cursorRect) < rectTop(&rect)) dy = rectTop(&rect) - rectTop(&cursorRect); if (rectBottom(&cursorRect) > rectBottom(&rect)) dy = rectBottom(&rect) - rectBottom(&cursorRect); OzUITextLayoutTransform(textEdit->layout, dx, dy); translateRect(&cursorRect, dx, dy); OzUIWidgetDrawTextLayout(widget, &tlc, &blackLS, textEdit->layout); if (widget->window->focusWidget == widget) { p1.x = rectLeft(&cursorRect); p1.y = rectBottom(&cursorRect); p2.x = rectRight(&cursorRect); p2.y = rectBottom(&cursorRect); OzUIWidgetDrawLine(widget, &p1, &p2, &blackLS); } } }
void SetInfoDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem button = option; QRect rect = option.rect; QRect rectAdd(rect.left() + rect.width()/2 - 15, rect.top() + rect.height()/2 - 5, 30, 15); QRect rectLeft(rect.x() + rect.width()/4 - 8, rect.y() + rect.height()/2 - 5, 30, 15); QRect rectRight(rect.x() + rect.width()*3/4 -8, rect.y() + rect.height()/2 - 5 , 30, 15); if(index.row() != rows){ QPoint pointUp, pointDown; pointUp.setX(rect.x() + rect.width()/4 - 8); pointUp.setY(rect.y() + rect.height()/2 + 5); pointDown.setX(rect.x() + rect.width()*3/4 -8); pointDown.setY(rect.y() + rect.height()/2 + 5); painter->save(); painter->setPen(QColor(108, 162, 234)); //QColor(108, 162, 234) (254, 107, 107) painter->drawText(pointUp, "修改"); painter->save(); painter->setPen(QColor(254, 107, 107)); painter->drawText(pointDown, "删除"); painter->restore(); // this->drawDisplay(painter, button, rectBu, _text); this->drawFocus(painter, button, rectLeft); this->drawFocus(painter, button, rectRight); painter->restore(); } if(index.row() == rows){ QPoint point; point.setX(rect.left()+ rect.width()/2 - 12); point.setY(rect.top() + rect.height()/2 + 5); painter->save(); painter->setPen(QColor(108, 162, 234));// (QColor(254, 107, 107)); //(254, 107, 107) button.displayAlignment = Qt::AlignCenter; painter->drawText(point, "添加"); this->drawFocus(painter, button, rectAdd); painter->restore(); } }
bool SetInfoDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { QRect rect = option.rect; QRect rectLeft(rect.x() + rect.width()/4 - 8, rect.y() + rect.height()/2 - 5 , 30, 15); QRect rectRight(rect.x() + rect.width()*3/4 -8, rect.y() + rect.height()/2 - 5 , 30, 15); QRect rectAdd(rect.left() + rect.width()/2 - 15, rect.top() + rect.height()/2 - 5, 30, 15); if (event->type() == QEvent::MouseMove) { // QMouseEvent* e =(QMouseEvent*)event; } if (event->type() == QEvent::MouseButtonRelease) { QMouseEvent* e =(QMouseEvent*)event; int row = index.row(); if(row != rows){ if (rectLeft.contains(e->x(), e->y())) { emit left(row); return true; }else if(rectRight.contains(e->x(), e->y())){ emit right(row); return true; } } if(row == rows){ if(rectAdd.contains(e->x(), e->y())){ emit currentRow(row); return true; } } } return false; }