void QGraphicsWidgetPrivate::windowFrameHoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); Q_Q(QGraphicsWidget); if (hasDecoration()) { // ### restore the cursor, don't override it #ifndef QT_NO_CURSOR q->unsetCursor(); #endif ensureWindowData(); bool needsUpdate = false; if (windowData->hoveredSubControl == QStyle::SC_TitleBarCloseButton || windowData->buttonMouseOver) needsUpdate = true; // update the hover state (of buttons etc...) windowData->hoveredSubControl = QStyle::SC_None; windowData->buttonMouseOver = false; windowData->buttonRect = QRect(); if (needsUpdate) q->update(windowData->buttonRect); } }
//___________________________________________________ void Button::paint( QPainter& painter ) { QPalette palette( _client.palette() ); palette.setCurrentColorGroup( isActive() ? QPalette::Active : QPalette::Inactive); if( _client.compositingActive() && !( _client.isMaximized() || _type == ButtonItemClose || _type == ButtonItemMenu ) ) { painter.translate( 0, -1 ); } // translate buttons down if window maximized if( _client.isMaximized() ) painter.translate( 0, 1 ); // base button color QColor base; if( _type == ButtonItemClose && _forceInactive ) base = _client.backgroundPalette( this, palette ).window().color(); else if( _type == ButtonItemClose ) base = palette.window().color(); else base = palette.button().color(); // text color QColor color = (_type == ButtonItemClose && _forceInactive ) ? buttonDetailColor( _client.backgroundPalette( this, palette ) ): buttonDetailColor( palette ); // decide decoration color QColor glow; if( isAnimated() || (_status&Hovered) ) { glow = isCloseButton() ? _helper.viewNegativeTextBrush().brush(palette).color(): _helper.viewHoverBrush().brush(palette).color(); if( isAnimated() ) { color = KColorUtils::mix( color, glow, glowIntensity() ); glow = _helper.alphaColor( glow, glowIntensity() ); } else if( _status&Hovered ) color = glow; } if( hasDecoration() ) { // scale qreal scale( (21.0*_client.buttonSize())/22.0 ); // pressed state const bool pressed( (_status&Pressed) || ( _type == ButtonSticky && _client.isOnAllDesktops() ) || ( _type == ButtonAbove && _client.keepAbove() ) || ( _type == ButtonBelow && _client.keepBelow() ) ); // draw button shape painter.drawPixmap(0, 0, _helper.windecoButton( base, glow, pressed, scale ) ); } // Icon // for menu button the application icon is used if( isMenuButton() ) { int iconScale( 0 ); switch( _client.buttonSize() ) { case Configuration::ButtonSmall: iconScale = 13; break; default: case Configuration::ButtonDefault: iconScale = 16; break; case Configuration::ButtonLarge: iconScale = 20; break; case Configuration::ButtonVeryLarge: iconScale = 24; break; case Configuration::ButtonHuge: iconScale = 35; break; } const QPixmap& pixmap( _client.icon().pixmap( iconScale ) ); const double offset = 0.5*(width()-pixmap.width() ); painter.drawPixmap(offset, offset-1, pixmap ); } else { painter.setRenderHints(QPainter::Antialiasing); qreal width( 1.2 ); // contrast painter.setBrush(Qt::NoBrush); painter.setPen(QPen( _helper.calcLightColor( base ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); drawIcon(&painter); // main painter.translate(0,-1.5); painter.setBrush(Qt::NoBrush); painter.setPen(QPen(color, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); drawIcon(&painter); } }
void QGraphicsWidgetPrivate::windowFrameHoverMoveEvent(QGraphicsSceneHoverEvent *event) { Q_Q(QGraphicsWidget); if (!hasDecoration()) return; ensureWindowData(); if (q->rect().contains(event->pos())) { if (windowData->buttonMouseOver || windowData->hoveredSubControl != QStyle::SC_None) windowFrameHoverLeaveEvent(event); return; } bool wasMouseOver = windowData->buttonMouseOver; QRect oldButtonRect = windowData->buttonRect; windowData->buttonRect = QRect(); windowData->buttonMouseOver = false; QPointF pos = event->pos(); QStyleOptionTitleBar bar; // make sure that the coordinates (rect and pos) we send to the style are positive. if (windowFrameMargins) { pos.rx() += windowFrameMargins[Left]; pos.ry() += windowFrameMargins[Top]; } initStyleOptionTitleBar(&bar); bar.rect = q->windowFrameRect().toRect(); bar.rect.moveTo(0,0); bar.rect.setHeight(int(titleBarHeight(bar))); Qt::CursorShape cursorShape = Qt::ArrowCursor; bool needsSetCursorCall = true; switch (q->windowFrameSectionAt(event->pos())) { case Qt::TopLeftSection: case Qt::BottomRightSection: cursorShape = Qt::SizeFDiagCursor; break; case Qt::TopRightSection: case Qt::BottomLeftSection: cursorShape = Qt::SizeBDiagCursor; break; case Qt::LeftSection: case Qt::RightSection: cursorShape = Qt::SizeHorCursor; break; case Qt::TopSection: case Qt::BottomSection: cursorShape = Qt::SizeVerCursor; break; case Qt::TitleBarArea: windowData->buttonRect = q->style()->subControlRect( QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarCloseButton, 0); #ifdef Q_WS_MAC // On mac we should hover if we are in the 'area' of the buttons windowData->buttonRect |= q->style()->subControlRect( QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMinButton, 0); windowData->buttonRect |= q->style()->subControlRect( QStyle::CC_TitleBar, &bar, QStyle::SC_TitleBarMaxButton, 0); #endif if (windowData->buttonRect.contains(pos.toPoint())) windowData->buttonMouseOver = true; event->ignore(); break; default: needsSetCursorCall = false; event->ignore(); } #ifndef QT_NO_CURSOR if (needsSetCursorCall) q->setCursor(cursorShape); #endif // update buttons if we hover over them windowData->hoveredSubControl = q->style()->hitTestComplexControl(QStyle::CC_TitleBar, &bar, pos.toPoint(), 0); if (windowData->hoveredSubControl != QStyle::SC_TitleBarCloseButton) windowData->hoveredSubControl = QStyle::SC_TitleBarLabel; if (windowData->buttonMouseOver != wasMouseOver) { if (!oldButtonRect.isNull()) q->update(QRectF(oldButtonRect).translated(q->windowFrameRect().topLeft())); if (!windowData->buttonRect.isNull()) q->update(QRectF(windowData->buttonRect).translated(q->windowFrameRect().topLeft())); } }