| 233 | } |
| 234 | |
| 235 | QRect TaskDelegate::paintFixButton(QPainter *painter, const QStyleOptionViewItem &option, |
| 236 | const QModelIndex &index) const |
| 237 | { |
| 238 | auto btnRect = fixButtonRect(option.rect); |
| 239 | if (!option.state.testFlag(QStyle::State_MouseOver)) |
| 240 | return btnRect; |
| 241 | |
| 242 | QPoint mousePos = view->mapFromGlobal(QCursor::pos()); |
| 243 | if (btnRect.contains(mousePos)) { |
| 244 | if (QApplication::mouseButtons() & Qt::LeftButton) { |
| 245 | QColor bgColor(255, 255, 255, qRound(255 * 0.15)); |
| 246 | painter->save(); |
| 247 | painter->setPen(Qt::NoPen); |
| 248 | painter->setBrush(bgColor); |
| 249 | painter->drawRoundedRect(btnRect, 6, 6); |
| 250 | painter->restore(); |
| 251 | } else if (option.state.testFlag(QStyle::State_MouseOver)) { |
| 252 | QColor bgColor(0, 0, 0, qRound(255 * 0.08)); |
| 253 | if (option.state.testFlag(QStyle::State_Selected)) { |
| 254 | bgColor.setRgba(qRgba(255, 255, 255, qRound(255 * 0.2))); |
| 255 | } else if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType) { |
| 256 | bgColor.setRgba(qRgba(255, 255, 255, qRound(255 * 0.08))); |
| 257 | } |
| 258 | painter->save(); |
| 259 | painter->setPen(Qt::NoPen); |
| 260 | painter->setBrush(bgColor); |
| 261 | painter->drawRoundedRect(btnRect, 6, 6); |
| 262 | painter->restore(); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | QIcon::Mode iconMode = QIcon::Normal; |
| 267 | if (!(option.state.testFlag(QStyle::State_Enabled))) |
| 268 | iconMode = QIcon::Disabled; |
| 269 | if (option.state.testFlag(QStyle::State_Selected)) |
| 270 | iconMode = QIcon::Selected; |
| 271 | |
| 272 | auto icon = QIcon::fromTheme("uc_repair"); |
| 273 | auto px = icon.pixmap({ kTaskIconSize, kTaskIconSize }, iconMode); |
| 274 | px.setDevicePixelRatio(qApp->devicePixelRatio()); |
| 275 | qreal x = btnRect.x(); |
| 276 | qreal y = btnRect.y(); |
| 277 | qreal w = px.width() / px.devicePixelRatio(); |
| 278 | qreal h = px.height() / px.devicePixelRatio(); |
| 279 | y += (btnRect.size().height() - h) / 2.0; |
| 280 | x += (btnRect.size().width() - w) / 2.0; |
| 281 | |
| 282 | painter->drawPixmap(qRound(x), qRound(y), px); |
| 283 | return btnRect; |
| 284 | } |
| 285 | |
| 286 | QRect TaskDelegate::iconRect(const QRect &itemRect) const |
| 287 | { |