diff --git a/src/qballoontip.cpp b/src/qballoontip.cpp index 1ec676a..2817a0e 100644 --- a/src/qballoontip.cpp +++ b/src/qballoontip.cpp @@ -66,12 +66,12 @@ QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title, } // Add drop shadow effect - QGraphicsDropShadowEffect *shadowEffect = - new QGraphicsDropShadowEffect(this); - shadowEffect->setBlurRadius(200); - shadowEffect->setColor(QColor(0, 0, 0, 80)); - shadowEffect->setOffset(0, 5); - setGraphicsEffect(shadowEffect); + // QGraphicsDropShadowEffect *shadowEffect = + // new QGraphicsDropShadowEffect(this); + // shadowEffect->setBlurRadius(200); + // shadowEffect->setColor(QColor(0, 0, 0, 80)); + // shadowEffect->setOffset(0, 5); + // setGraphicsEffect(shadowEffect); // QLabel *titleLabel = new QLabel; // titleLabel->installEventFilter(this); @@ -121,102 +121,103 @@ QBalloonTip::QBalloonTip(const QIcon &icon, const QString &title, QBalloonTip::~QBalloonTip() { theSolitaryBalloonTip = nullptr; } -void QBalloonTip::paintEvent(QPaintEvent *) +void QBalloonTip::paintEvent(QPaintEvent *ev) { QPainter painter(this); painter.drawPixmap(rect(), pixmap); + QWidget::paintEvent(ev); } void QBalloonTip::resizeEvent(QResizeEvent *ev) { QWidget::resizeEvent(ev); } void QBalloonTip::balloon(const QPoint &pos, int msecs, bool showArrow) { - this->showArrow = showArrow; - QScreen *screen = QGuiApplication::screenAt(pos); - if (!screen) - screen = QGuiApplication::primaryScreen(); - QRect screenRect = screen->geometry(); - QSize sh = sizeHint(); - const int border = 1; - const int ah = 18, aw = 18, rc = 7; - bool arrowAtTop = (pos.y() + sh.height() + ah < screenRect.height()); + // this->showArrow = showArrow; + // QScreen *screen = QGuiApplication::screenAt(pos); + // if (!screen) + // screen = QGuiApplication::primaryScreen(); + // QRect screenRect = screen->geometry(); + // QSize sh = sizeHint(); + // const int border = 1; + // const int ah = 18, aw = 18, rc = 7; + // bool arrowAtTop = (pos.y() + sh.height() + ah < screenRect.height()); - setContentsMargins(border + 3, border + (arrowAtTop ? ah : 0) + 2, - border + 3, border + (arrowAtTop ? 0 : ah) + 2); - updateGeometry(); - sh = sizeHint(); + // setContentsMargins(border + 3, border + (arrowAtTop ? ah : 0) + 2, + // border + 3, border + (arrowAtTop ? 0 : ah) + 2); + // updateGeometry(); + // sh = sizeHint(); - // Center the balloon relative to the pos point (button center) - int balloonX = pos.x() - sh.width() / 2; + // // Center the balloon relative to the pos point (button center) + // int balloonX = pos.x() - sh.width() / 2; - // Calculate arrow offset from left edge of balloon to center it - int ao = sh.width() / 2 - aw / 2; // Center the arrow on the balloon + // // Calculate arrow offset from left edge of balloon to center it + // int ao = sh.width() / 2 - aw / 2; // Center the arrow on the balloon - int ml, mr, mt, mb; - QSize sz = sizeHint(); - if (!arrowAtTop) { - ml = mt = 0; - mr = sz.width() - 1; - mb = sz.height() - ah - 1; - } else { - ml = 0; - mt = ah; - mr = sz.width() - 1; - mb = sz.height() - 1; - } + // int ml, mr, mt, mb; + // QSize sz = sizeHint(); + // if (!arrowAtTop) { + // ml = mt = 0; + // mr = sz.width() - 1; + // mb = sz.height() - ah - 1; + // } else { + // ml = 0; + // mt = ah; + // mr = sz.width() - 1; + // mb = sz.height() - 1; + // } - QPainterPath path; - path.moveTo(ml + rc, mt); - if (arrowAtTop) { - if (showArrow) { - path.lineTo(ml + ao, mt); - path.lineTo(ml + ao + aw / 2, mt - ah); - path.lineTo(ml + ao + aw, mt); - } - move(qBound(screenRect.left() + 2, balloonX, - screenRect.right() - sh.width() - 2), - pos.y()); - } - path.lineTo(mr - rc, mt); - path.arcTo(QRect(mr - rc * 2, mt, rc * 2, rc * 2), 90, -90); - path.lineTo(mr, mb - rc); - path.arcTo(QRect(mr - rc * 2, mb - rc * 2, rc * 2, rc * 2), 0, -90); - if (!arrowAtTop) { - if (showArrow) { - path.lineTo(mr - ao - aw, mb); - path.lineTo(mr - ao - aw / 2, mb + ah); - path.lineTo(mr - ao, mb); - } - move(qBound(screenRect.left() + 2, balloonX, - screenRect.right() - sh.width() - 2), - pos.y() - sh.height()); - } - path.lineTo(ml + rc, mb); - path.arcTo(QRect(ml, mb - rc * 2, rc * 2, rc * 2), -90, -90); - path.lineTo(ml, mt + rc); - path.arcTo(QRect(ml, mt, rc * 2, rc * 2), 180, -90); + // QPainterPath path; + // path.moveTo(ml + rc, mt); + // if (arrowAtTop) { + // if (showArrow) { + // path.lineTo(ml + ao, mt); + // path.lineTo(ml + ao + aw / 2, mt - ah); + // path.lineTo(ml + ao + aw, mt); + // } + // move(qBound(screenRect.left() + 2, balloonX, + // screenRect.right() - sh.width() - 2), + // pos.y()); + // } + // path.lineTo(mr - rc, mt); + // path.arcTo(QRect(mr - rc * 2, mt, rc * 2, rc * 2), 90, -90); + // path.lineTo(mr, mb - rc); + // path.arcTo(QRect(mr - rc * 2, mb - rc * 2, rc * 2, rc * 2), 0, -90); + // if (!arrowAtTop) { + // if (showArrow) { + // path.lineTo(mr - ao - aw, mb); + // path.lineTo(mr - ao - aw / 2, mb + ah); + // path.lineTo(mr - ao, mb); + // } + // move(qBound(screenRect.left() + 2, balloonX, + // screenRect.right() - sh.width() - 2), + // pos.y() - sh.height()); + // } + // path.lineTo(ml + rc, mb); + // path.arcTo(QRect(ml, mb - rc * 2, rc * 2, rc * 2), -90, -90); + // path.lineTo(ml, mt + rc); + // path.arcTo(QRect(ml, mt, rc * 2, rc * 2), 180, -90); - // Set the mask - QBitmap bitmap = QBitmap(sizeHint()); - bitmap.fill(Qt::color0); - QPainter painter1(&bitmap); - painter1.setPen(QPen(Qt::color1, border)); - painter1.setBrush(QBrush(Qt::color1)); - painter1.drawPath(path); - setMask(bitmap); + // // Set the mask + // QBitmap bitmap = QBitmap(sizeHint()); + // bitmap.fill(Qt::color0); + // QPainter painter1(&bitmap); + // painter1.setPen(QPen(Qt::color1, border)); + // painter1.setBrush(QBrush(Qt::color1)); + // painter1.drawPath(path); + // setMask(bitmap); - // Draw the border with background color - pixmap = QPixmap(sz); - pixmap.fill(Qt::transparent); - QPainter painter2(&pixmap); - painter2.setRenderHint(QPainter::Antialiasing); - bool isDark = isDarkMode(); - QColor lightColor = qApp->palette().color(QPalette::Light); - QColor darkColor = qApp->palette().color(QPalette::Dark); - QColor bgColor = isDark ? lightColor : darkColor; - painter2.setPen(QPen(bgColor.darker(160), border)); - painter2.setBrush(bgColor); - painter2.drawPath(path); + // // Draw the border with background color + // pixmap = QPixmap(sz); + // pixmap.fill(Qt::transparent); + // QPainter painter2(&pixmap); + // painter2.setRenderHint(QPainter::Antialiasing); + // bool isDark = isDarkMode(); + // QColor lightColor = qApp->palette().color(QPalette::Light); + // QColor darkColor = qApp->palette().color(QPalette::Dark); + // QColor bgColor = isDark ? lightColor : darkColor; + // painter2.setPen(QPen(bgColor.darker(160), border)); + // painter2.setBrush(bgColor); + // painter2.drawPath(path); if (msecs > 0) timer.start(msecs, this); @@ -224,8 +225,8 @@ void QBalloonTip::balloon(const QPoint &pos, int msecs, bool showArrow) // Install event filter to detect clicks outside qApp->installEventFilter(this); - // Set initial scale and opacity for animation - setWindowOpacity(0.0); + // // Set initial scale and opacity for animation + // setWindowOpacity(0.0); // Store the transform origin point (center of the widget) QPoint center = rect().center(); @@ -249,15 +250,15 @@ void QBalloonTip::balloon(const QPoint &pos, int msecs, bool showArrow) scaleAnim->setStartValue(startGeometry); scaleAnim->setEndValue(finalGeometry); - QPropertyAnimation *opacityAnim = - new QPropertyAnimation(this, "windowOpacity"); - opacityAnim->setDuration(200); - opacityAnim->setStartValue(0.0); - opacityAnim->setEndValue(1.0); - opacityAnim->setEasingCurve(QEasingCurve::OutCubic); + // QPropertyAnimation *opacityAnim = + // new QPropertyAnimation(this, "windowOpacity"); + // opacityAnim->setDuration(200); + // opacityAnim->setStartValue(0.0); + // opacityAnim->setEndValue(1.0); + // opacityAnim->setEasingCurve(QEasingCurve::OutCubic); - scaleAnim->start(QAbstractAnimation::DeleteWhenStopped); - opacityAnim->start(QAbstractAnimation::DeleteWhenStopped); + // scaleAnim->start(QAbstractAnimation::DeleteWhenStopped); + // opacityAnim->start(QAbstractAnimation::DeleteWhenStopped); } void QBalloonTip::mousePressEvent(QMouseEvent *e)