BalloonMsg::BalloonMsg(void *param, const QString &_text, QStringList &btn, QWidget *parent, const QRect *rcParent, bool bModal, bool bAutoHide, unsigned bwidth, const QString &box_msg, bool *bChecked) : QDialog(parent, "ballon", bModal, (bAutoHide ? WType_Popup : WType_TopLevel | WStyle_StaysOnTop) | WStyle_Customize | WStyle_NoBorderEx | WStyle_Tool | WDestructiveClose | WX11BypassWM) { m_param = param; m_parent = parent; m_width = bwidth; m_bAutoHide = bAutoHide; m_bYes = false; m_bChecked = bChecked; bool bTailDown = true; setPalette(QToolTip::palette()); text = _text; QFrame *frm = new QFrame(this); frm->setPalette(palette()); QVBoxLayout *vlay = new QVBoxLayout(frm); vlay->setMargin(0); m_check = NULL; if (!box_msg.isEmpty()){ m_check = new QCheckBox(box_msg, frm); vlay->addWidget(m_check); if (m_bChecked) m_check->setChecked(*m_bChecked); } QHBoxLayout *lay = new QHBoxLayout(vlay); lay->setSpacing(5); lay->addStretch(); unsigned id = 0; bool bFirst = true; for (QStringList::Iterator it = btn.begin(); it != btn.end(); ++it, id++){ BalloonButton *b = new BalloonButton(*it, frm, id); connect(b, SIGNAL(action(int)), this, SLOT(action(int))); lay->addWidget(b); if (bFirst){ b->setDefault(true); bFirst = false; } } setButtonsPict(this); lay->addStretch(); int wndWidth = frm->minimumSizeHint().width(); int hButton = frm->minimumSizeHint().height(); int txtWidth = bwidth; QRect rc; if (rcParent){ rc = *rcParent; }else{ QPoint p = parent->mapToGlobal(parent->rect().topLeft()); rc = QRect(p.x(), p.y(), parent->width(), parent->height()); } if (rc.width() > txtWidth) txtWidth = rc.width(); QSimpleRichText richText(_text, font(), "", QStyleSheet::defaultSheet(), QMimeSourceFactory::defaultFactory(), -1, Qt::blue, false); richText.setWidth(wndWidth); richText.adjustSize(); QSize s(richText.widthUsed(), richText.height()); QSize sMin = frm->minimumSizeHint(); if (s.width() < sMin.width()) s.setWidth(sMin.width()); int BALLOON_SHADOW = BALLOON_SHADOW_DEF; #ifdef WIN32 /* FIXME */ /* if ((GetClassLong(winId(), GCL_STYLE) & CS_DROPSHADOW) && style().inherits("QWindowsXPStyle")) BALLOON_SHADOW = 0; */ #endif resize(s.width() + BALLOON_R * 2 + BALLOON_SHADOW, s.height() + BALLOON_R * 2 + BALLOON_TAIL + BALLOON_SHADOW + hButton + BALLOON_MARGIN); mask = QBitmap(width(), height()); int w = width() - BALLOON_SHADOW; int tailX = w / 2; int posX = rc.left() + rc.width() / 2 + BALLOON_TAIL_WIDTH - tailX; if (posX <= 0) posX = 1; QRect rcScreen = screenGeometry(); if (posX + width() >= rcScreen.width()) posX = rcScreen.width() - 1 - width(); int tx = posX + tailX - BALLOON_TAIL_WIDTH; if (tx < rc.left()) tx = rc.left(); if (tx > rc.left() + rc.width()) tx = rc.left() + rc.width(); tailX = tx + BALLOON_TAIL_WIDTH - posX; if (tailX < BALLOON_R) tailX = BALLOON_R; if (tailX > width() - BALLOON_R - BALLOON_TAIL_WIDTH) tailX = width() - BALLOON_R - BALLOON_TAIL_WIDTH; if (rc.top() <= height() + 2){ bTailDown = false; move(posX, rc.top() + rc.height() + 1); }else{ move(posX, rc.top() - height() - 1); } int pos = 0; int h = height() - BALLOON_SHADOW - BALLOON_TAIL; if (!bTailDown) pos += BALLOON_TAIL; textRect.setRect(BALLOON_R, pos + BALLOON_R, w - BALLOON_R * 2, h); frm->resize(s.width(), hButton); frm->move(BALLOON_R, pos + h - BALLOON_R - hButton); QPainter p; p.begin(&mask); #ifdef WIN32 QColor bg(255, 255, 255); QColor fg(0, 0, 0); #else QColor bg(0, 0, 0); QColor fg(255, 255, 255); #endif p.fillRect(0, 0, width(), height(), bg); p.fillRect(0, pos + BALLOON_R, w, h - BALLOON_R * 2, fg); p.fillRect(BALLOON_R, pos, w - BALLOON_R * 2, h, fg); p.fillRect(BALLOON_SHADOW, pos + BALLOON_R + BALLOON_SHADOW, w, h - BALLOON_R * 2, fg); p.fillRect(BALLOON_R + BALLOON_SHADOW, pos + BALLOON_SHADOW, w - BALLOON_R * 2, h, fg); p.setBrush(fg); p.drawEllipse(0, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(0, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(BALLOON_SHADOW, pos + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2 + BALLOON_SHADOW, pos + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2 + BALLOON_SHADOW, pos + h - BALLOON_R * 2 + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(BALLOON_SHADOW, pos + h - BALLOON_R * 2 + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); QPointArray arr(3); arr.setPoint(0, tailX, bTailDown ? h : pos); arr.setPoint(1, tailX + BALLOON_TAIL_WIDTH, bTailDown ? h : pos); arr.setPoint(2, tailX - BALLOON_TAIL_WIDTH, bTailDown ? height() - BALLOON_SHADOW : 0); p.drawPolygon(arr); arr.setPoint(0, tailX + BALLOON_SHADOW, (bTailDown ? h : pos) + BALLOON_SHADOW); arr.setPoint(1, tailX + BALLOON_TAIL_WIDTH + BALLOON_SHADOW, (bTailDown ? h : pos) + BALLOON_SHADOW); arr.setPoint(2, tailX - BALLOON_TAIL_WIDTH + BALLOON_SHADOW, bTailDown ? height() : BALLOON_SHADOW); p.drawPolygon(arr); p.end(); setMask(mask); qApp->syncX(); QPixmap pict = QPixmap::grabWindow(QApplication::desktop()->winId(), x(), y(), width(), height()); intensity(pict, -0.50f); p.begin(&pict); p.setBrush(colorGroup().background()); p.drawEllipse(0, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(0, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); arr.setPoint(0, tailX, bTailDown ? h - 1 : pos + 1); arr.setPoint(1, tailX + BALLOON_TAIL_WIDTH, bTailDown ? h - 1 : pos + 1); arr.setPoint(2, tailX - BALLOON_TAIL_WIDTH, bTailDown ? height() - BALLOON_SHADOW : 0); p.drawPolygon(arr); p.fillRect(0, pos + BALLOON_R, w, h - BALLOON_R * 2, colorGroup().background()); p.fillRect(BALLOON_R, pos, w - BALLOON_R * 2, h, colorGroup().background()); p.drawLine(0, pos + BALLOON_R, 0, pos + h - BALLOON_R); p.drawLine(w - 1, pos + BALLOON_R, w - 1, pos + h - BALLOON_R); if (bTailDown){ p.drawLine(BALLOON_R, 0, w - BALLOON_R, 0); p.drawLine(BALLOON_R, h - 1, tailX, h - 1); p.drawLine(tailX + BALLOON_TAIL_WIDTH, h - 1, w - BALLOON_R, h - 1); }else{ p.drawLine(BALLOON_R, pos + h - 1, w - BALLOON_R, pos + h - 1); p.drawLine(BALLOON_R, pos, tailX, pos); p.drawLine(tailX + BALLOON_TAIL_WIDTH, pos, w - BALLOON_R, pos); } p.end(); setBackgroundPixmap(pict); setAutoMask(true); if (!bAutoHide) setFocusPolicy(NoFocus); QWidget *top = NULL; if (parent) top = parent->topLevelWidget(); if (top){ raiseWindow(top); top->installEventFilter(this); } }
const QRect QDesktopWidget::availableGeometry(int screen) const { Q_D(const QDesktopWidget); if (qt_desktopwidget_workarea_dirty) { // the workareas are dirty, invalidate them for (int i = 0; i < d->screenCount; ++i) d->workareas[i] = QRect(); qt_desktopwidget_workarea_dirty = false; } if (screen < 0 || screen >= d->screenCount) screen = d->defaultScreen; if (d->workareas[screen].isValid()) return d->workareas[screen]; if (X11->isSupportedByWM(ATOM(_NET_WORKAREA))) { int x11Screen = isVirtualDesktop() ? DefaultScreen(X11->display) : screen; Atom ret; int format, e; unsigned char *data = 0; unsigned long nitems, after; e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(x11Screen), ATOM(_NET_WORKAREA), 0, 4, False, XA_CARDINAL, &ret, &format, &nitems, &after, &data); QRect workArea; if (e == Success && ret == XA_CARDINAL && format == 32 && nitems == 4) { long *workarea = (long *) data; workArea = QRect(workarea[0], workarea[1], workarea[2], workarea[3]); } else { workArea = screenGeometry(screen); } if (isVirtualDesktop()) { // intersect the workarea (which spawns all Xinerama screens) with the rect for the // requested screen workArea &= screenGeometry(screen); } d->workareas[screen] = workArea; if (data) XFree(data); } else { d->workareas[screen] = screenGeometry(screen); } return d->workareas[screen]; }
void TextTip::configure(const QPoint &pos, QWidget *w) { if (helpId().isEmpty()) setText(m_text); else setText(QString::fromLatin1("<table><tr><td valign=middle>%1</td><td> " "<img src=\":/utils/tooltip/images/f1.png\"></td>" "</tr></table>").arg(m_text)); // Make it look good with the default ToolTip font on Mac, which has a small descent. QFontMetrics fm(font()); int extraHeight = 0; if (fm.descent() == 2 && fm.ascent() >= 11) ++extraHeight; // Try to find a nice width without unnecessary wrapping. setWordWrap(false); int tipWidth = sizeHint().width(); const int screenWidth = screenGeometry(pos, w).width(); const int maxDesiredWidth = int(screenWidth * .5); if (tipWidth > maxDesiredWidth) { setWordWrap(true); tipWidth = sizeHint().width(); // If the width is still too large (maybe due to some extremely long word which prevents // wrapping), the tip is truncated according to the screen. if (tipWidth > screenWidth) tipWidth = screenWidth - 10; } resize(tipWidth, heightForWidth(tipWidth) + extraHeight); }
/// Content rectangle (position) inside the screen QRect Tuning::contentGeometry() const { QRect _screenRect(screenGeometry()); int _w = session_.screenSetup().subScreenWidth(screen()); QRect _contentRect(_w * subScreenIndex(),0,_w,_screenRect.height()); return _contentRect; }
void TextTip::configure(const QPoint &pos, QWidget *w) { const QString &text = static_cast<const TextContent &>(content()).text(); setText(text); // Make it look good with the default ToolTip font on Mac, which has a small descent. QFontMetrics fm(font()); int extraHeight = 0; if (fm.descent() == 2 && fm.ascent() >= 11) ++extraHeight; // Try to find a nice width without unnecessary wrapping. setWordWrap(false); int tipWidth = sizeHint().width(); const int screenWidth = screenGeometry(pos, w).width(); const int maxDesiredWidth = int(screenWidth * .5); if (tipWidth > maxDesiredWidth) { setWordWrap(true); tipWidth = sizeHint().width(); // If the width is still too large (maybe due to some extremely long word which prevents // wrapping), the tip is truncated according to the screen. if (tipWidth > screenWidth) tipWidth = screenWidth - 10; } resize(tipWidth, heightForWidth(tipWidth) + extraHeight); }
void TipLabel::show(const QRect &tipRect, bool bState) { setAlignment( WordBreak | AlignCenter ); QRect rc = screenGeometry(); QSize s = sizeHint(); int h = heightForWidth(s.width()); resize(s.width(), h ); int x = tipRect.left() + tipRect.width() / 2 - width(); if (x < 0) x = tipRect.left() + tipRect.width() / 2; if (x + width() > rc.width() - 2) x = rc.width() - 2 - width(); int y; if (bState){ y = tipRect.top() - 4 - height(); if (y < 0) bState = false; } if (!bState) y = tipRect.top() + tipRect.height() + 4; if (y + height() > rc.height()) y = tipRect.top() - 4 - height(); if (y < 0) y = tipRect.top() + tipRect.height() + 4; move(x, y); QLabel::show(); }
const QRect QDesktopWidget::availableGeometry(int screen) const { Q_D(const QDesktopWidget); if (qt_desktopwidget_workarea_dirty) { // the workareas are dirty, invalidate them for (int i = 0; i < d->screenCount; ++i) d->workareas[i] = QRect(); qt_desktopwidget_workarea_dirty = false; } if (screen < 0 || screen >= d->screenCount) screen = d->defaultScreen; if (d->workareas[screen].isValid()) return d->workareas[screen]; if ((d->screenCount == 1 || !isVirtualDesktop()) && X11->isSupportedByWM(ATOM(_NET_WORKAREA))) { Atom ret; int format, e; unsigned char *data = 0; unsigned long nitems, after; e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(screen), ATOM(_NET_WORKAREA), 0, 4, False, XA_CARDINAL, &ret, &format, &nitems, &after, &data); if (e == Success && ret == XA_CARDINAL && format == 32 && nitems == 4) { long *workarea = (long *) data; d->workareas[screen].setRect(workarea[0], workarea[1], workarea[2], workarea[3]); } else { d->workareas[screen] = screenGeometry(screen); } if (data) XFree(data); } else { d->workareas[screen] = screenGeometry(screen); } return d->workareas[screen]; }
QT_BEGIN_NAMESPACE const QRect QDesktopWidget::screenGeometry(const QWidget *widget) const { if (!widget) { qWarning("QDesktopWidget::screenGeometry(): Attempt " "to get the screen geometry of a null widget"); return QRect(); } QRect rect = QWidgetPrivate::screenGeometry(widget); if (rect.isNull()) return screenGeometry(screenNumber(widget)); else return rect; }
QT_BEGIN_NAMESPACE QMinimalEglWindow::QMinimalEglWindow(QWindow *w) : QPlatformWindow(w) { static int serialNo = 0; m_winid = ++serialNo; #ifdef QEGL_EXTRA_DEBUG qWarning("QEglWindow %p: %p 0x%x\n", this, w, uint(m_winid)); #endif QRect screenGeometry(screen()->availableGeometry()); if (w->geometry() != screenGeometry) { QWindowSystemInterface::handleGeometryChange(w, screenGeometry); } }
/// Write tuning to stream void Tuning::toStream(QDataStream& _os) const { PropertyMap _map; _map("color",color_) ("projector",projector_) ("warpGrid",warpGrid_) ("blendMask",blendMask_) ("outputDisabled",outputDisabled_) ("overlapOpacity",overlapOpacity_) ("colorCorrection",colorCorrection_) ("patches",patches_) ; _map("screenGeometry", screenGeometry()); _map("contentGeometry", contentGeometry()); _map("subScreenIndex", subScreenIndex_); _os << _map; }
QPixmap Plugin::GetPixmap () const { switch (Dialog_->GetMode ()) { case ShooterDialog::Mode::LCWindowOverlay: return QPixmap::grabWindow (Proxy_->GetMainWindow ()->winId ()); case ShooterDialog::Mode::LCWindow: return QPixmap::grabWidget (Proxy_->GetMainWindow ()); case ShooterDialog::Mode::CurrentScreen: { auto desk = qApp->desktop (); auto screen = desk->screen (desk->screenNumber (QCursor::pos ())); auto geom = desk->screenGeometry (QCursor::pos ()); return QPixmap::grabWindow (screen->winId (), geom.x (), geom.y (), geom.width (), geom.height ()); } case ShooterDialog::Mode::WholeDesktop: return QPixmap::grabWindow (qApp->desktop ()->winId ()); } }
void OSDWidget::showOSD(const QString &str, OSDUserData *data) { setFont(FontEdit::str2font(data->Font.ptr, baseFont)); QPainter p(this); p.setFont(font()); unsigned nScreen = data->Screen.value; unsigned nScreens = screens(); if (nScreen >= nScreens) nScreen = 0; QRect rcScreen = screenGeometry(nScreen); rcScreen = QRect(0, 0, rcScreen.width() - SHADOW_OFFS - XOSD_MARGIN * 2 - data->Offset.value, rcScreen.height() - SHADOW_OFFS - XOSD_MARGIN * 2 - data->Offset.value); QRect rc = p.boundingRect(rcScreen, AlignLeft | AlignTop | WordBreak, str); p.end(); int x = rcScreen.left(); int y = rcScreen.top(); int w = rc.width() + 1; int h = rc.height() + 1; if (data->Shadow.bValue){ w += SHADOW_OFFS; h += SHADOW_OFFS; } if (data->Background.bValue){ w += XOSD_MARGIN * 2; h += XOSD_MARGIN * 2; } resize(QSize(w, h)); switch (data->Position.value){ case 1: move(x + data->Offset.value, y + data->Offset.value); break; case 2: move(x + rcScreen.width() - data->Offset.value - w, y + rcScreen.height() - data->Offset.value - h); break; case 3: move(x + rcScreen.width() - data->Offset.value - w, y + data->Offset.value); break; case 4: move(x + (rcScreen.width() - w) / 2, y + rcScreen.height() - data->Offset.value - h); break; case 5: move(x + (rcScreen.width() - w) / 2, y + data->Offset.value); break; case 6: move(x + (rcScreen.width() - w) / 2, y + (rcScreen.height() - h) /2); break; default: move(x + data->Offset.value, y + rcScreen.height() - data->Offset.value - h); } if (!data->Background.bValue || data->Shadow.bValue){ QBitmap mask(w, h); p.begin(&mask); #ifdef WIN32 QColor bg(255, 255, 255); QColor fg(0, 0, 0); #else QColor bg(0, 0, 0); QColor fg(255, 255, 255); #endif p.fillRect(0, 0, w, h, bg); if (data->Background.bValue){ p.fillRect(0, 0, w - SHADOW_OFFS, h - SHADOW_OFFS, fg); p.fillRect(SHADOW_OFFS, SHADOW_OFFS, w - SHADOW_OFFS, h - SHADOW_OFFS, fg); }else{ p.setPen(fg); p.setFont(font()); if (data->Shadow.bValue){ rc = QRect(SHADOW_OFFS, SHADOW_OFFS, w - SHADOW_OFFS, h - SHADOW_OFFS); p.drawText(rc, AlignLeft | AlignTop | WordBreak, str); rc = QRect(0, 0, w - SHADOW_OFFS, h - SHADOW_OFFS); p.drawText(rc, AlignLeft | AlignTop | WordBreak, str); }else{ rc = QRect(0, 0, w, h); p.drawText(rc, AlignLeft | AlignTop | WordBreak, str); } } p.end(); setMask(mask); } qApp->syncX(); QPixmap pict = QPixmap::grabWindow(QApplication::desktop()->winId(), this->x(), this->y(), width(), height()); intensity(pict, -0.50f); p.begin(&pict); rc = QRect(0, 0, w, h); if (data->Background.bValue){ if (data->Shadow.bValue){ w -= SHADOW_OFFS; h -= SHADOW_OFFS; rc = QRect(0, 0, w, h); } QBrush bg(data->BgColor.value); p.fillRect(rc, bg); #if QT_VERSION < 300 style().drawPopupPanel(&p, 0, 0, w, h, colorGroup(), 2, &bg); #else style().drawPrimitive(QStyle::PE_PanelPopup, &p, rc, colorGroup()); #endif rc = QRect(XOSD_MARGIN, XOSD_MARGIN, w - XOSD_MARGIN * 2, h - XOSD_MARGIN * 2); } p.setFont(font()); p.setPen(QColor(data->Color.value)); p.drawText(rc, AlignLeft | AlignTop | WordBreak, str); p.end(); bgPict = pict; QWidget::show(); raise(); }
void OSDWidget::showOSD(const QString &str, OSDUserData *data) { if (isScreenSaverActive()){ hide(); return; } setFont(FontEdit::str2font(data->Font.ptr, baseFont)); QPainter p(this); p.setFont(font()); unsigned nScreen = data->Screen.value; unsigned nScreens = screens(); if (nScreen >= nScreens) nScreen = 0; QRect rcScreen = screenGeometry(nScreen); rcScreen = QRect(0, 0, rcScreen.width() - SHADOW_OFFS - XOSD_MARGIN * 2 - data->Offset.value, rcScreen.height() - SHADOW_OFFS - XOSD_MARGIN * 2 - data->Offset.value); QRect rc = p.boundingRect(rcScreen, AlignLeft | AlignTop | WordBreak, str); p.end(); if (data->EnableMessageShowContent.bValue && data->ContentLines.value){ QFontMetrics fm(font()); int maxHeight = fm.height() * (data->ContentLines.value + 1); if (rc.height() > maxHeight) rc.setHeight(maxHeight); } int x = rcScreen.left(); int y = rcScreen.top(); int w = rc.width() + 1; int h = rc.height() + 1; int text_y = 0; if (data->Background.bValue){ w += XOSD_MARGIN * 2; h += XOSD_MARGIN * 2; if (m_button == NULL){ m_button = new QPushButton("", this); m_button->setPixmap(QPixmap((const char **)close_h_xpm)); connect(m_button, SIGNAL(clicked()), this, SLOT(slotCloseClick())); } QSize s = m_button->sizeHint(); m_button->resize(s.height() - 4, s.height() - 4); m_button->move(w - m_button->width() - 3, 2); text_y = m_button->height() + 4; h += text_y; m_button->show(); }else{ if (m_button){ delete m_button; m_button = NULL; } } if (data->Shadow.bValue){ w += SHADOW_OFFS; h += SHADOW_OFFS; } resize(QSize(w, h)); switch (data->Position.value){ case 1: move(x + data->Offset.value, y + data->Offset.value); break; case 2: move(x + rcScreen.width() - data->Offset.value - w, y + rcScreen.height() - data->Offset.value - h); break; case 3: move(x + rcScreen.width() - data->Offset.value - w, y + data->Offset.value); break; case 4: move(x + (rcScreen.width() - w) / 2, y + rcScreen.height() - data->Offset.value - h); break; case 5: move(x + (rcScreen.width() - w) / 2, y + data->Offset.value); break; case 6: move(x + (rcScreen.width() - w) / 2, y + (rcScreen.height() - h) /2); break; default: move(x + data->Offset.value, y + rcScreen.height() - data->Offset.value - h); } if (!data->Background.bValue || data->Shadow.bValue){ QBitmap mask(w, h); p.begin(&mask); #ifdef WIN32 QColor bg(255, 255, 255); QColor fg(0, 0, 0); #else QColor bg(0, 0, 0); QColor fg(255, 255, 255); #endif p.fillRect(0, 0, w, h, bg); if (data->Background.bValue){ p.fillRect(0, 0, w - SHADOW_OFFS, h - SHADOW_OFFS, fg); p.fillRect(SHADOW_OFFS, SHADOW_OFFS, w - SHADOW_OFFS, h - SHADOW_OFFS, fg); }else{ p.setPen(fg); p.setFont(font()); if (data->Shadow.bValue){ rc = QRect(SHADOW_OFFS, SHADOW_OFFS, w - SHADOW_OFFS, h - SHADOW_OFFS); p.drawText(rc, AlignLeft | AlignTop | WordBreak, str); rc = QRect(0, 0, w - SHADOW_OFFS, h - SHADOW_OFFS); p.drawText(rc, AlignLeft | AlignTop | WordBreak, str); }else{ rc = QRect(0, 0, w, h); p.drawText(rc, AlignLeft | AlignTop | WordBreak, str); } } p.end(); setMask(mask); } qApp->syncX(); QPixmap pict = QPixmap::grabWindow(QApplication::desktop()->winId(), this->x(), this->y(), width(), height()); intensity(pict, -0.50f); p.begin(&pict); rc = QRect(0, 0, w, h); if (data->Background.bValue){ if (data->Shadow.bValue){ w -= SHADOW_OFFS; h -= SHADOW_OFFS; rc = QRect(0, 0, w, h); } QBrush bg(data->BgColor.value); p.fillRect(rc, bg); #if COMPAT_QT_VERSION < 0x030000 style().drawPopupPanel(&p, 0, 0, w, h, colorGroup(), 2, &bg); #else style().drawPrimitive(QStyle::PE_PanelPopup, &p, rc, colorGroup()); #endif rc = QRect(XOSD_MARGIN, XOSD_MARGIN, w - XOSD_MARGIN * 2, h - XOSD_MARGIN * 2); } p.setFont(font()); p.setPen(QColor(data->Color.value)); rc.setTop(text_y); p.drawText(rc, AlignLeft | AlignTop | WordBreak, str); p.end(); bgPict = pict; QWidget::show(); raise(); }
void TipLabel::show(const QRect &tipRect, bool _bState) { int prevH = 0; int x = 0; int y = 0; unsigned totalH = 0; QStringList l; vector<unsigned> heights; QRect rc = screenGeometry(); for (unsigned nDiv = 0;; nDiv++){ bool bState = _bState; QString text = m_text; if (nDiv){ text = "<table><tr><td>"; unsigned hPart = totalH / (nDiv + 1); unsigned h = 0; unsigned i = 0; QString part; for (QStringList::Iterator it = l.begin(); it != l.end(); ++it, i++){ string s; s = (*it).local8Bit(); log(L_DEBUG, "%u %u (%u %u):\n%s", i, heights[i], h, hPart, s.c_str()); if (!part.isEmpty()){ if (heights[i] >= hPart){ log(L_DEBUG, "Div---"); text += part; text += "</td><td>"; part = ""; h = 0; }else{ part += "<hr>"; } } part += *it; h += heights[i]; if (h >= hPart){ log(L_DEBUG, "DDD"); text += part; text += "</td><td>"; part = ""; h = 0; } } text += part; text += "</td></tr></table>"; } QSimpleRichText richText(text, font(), "", QStyleSheet::defaultSheet(), QMimeSourceFactory::defaultFactory(), -1, Qt::blue, false); richText.adjustSize(); QSize s(richText.widthUsed() + 8, richText.height() + 8); resize(s.width(), s.height()); x = tipRect.left() + tipRect.width() / 2 - width(); if (x < 0) x = tipRect.left() + tipRect.width() / 2; if (x + width() > rc.width() - 2) x = rc.width() - 2 - width(); y = 0; if (bState){ y = tipRect.top() - 4 - height(); if (y < 0) bState = false; } if (!bState) y = tipRect.top() + tipRect.height() + 4; if (y + height() > rc.height()) y = tipRect.top() - 4 - height(); if (y < 0) y = tipRect.top() + tipRect.height() + 4; if ((y + s.height() < rc.height()) || (prevH == s.height())){ m_text = text; break; } prevH = s.height(); if (totalH == 0){ totalH = prevH; l = QStringList::split("<hr>", m_text); unsigned i = 0; for (QStringList::Iterator it = l.begin(); it != l.end(); ++it, i++){ QSimpleRichText richText(*it, font(), "", QStyleSheet::defaultSheet(), QMimeSourceFactory::defaultFactory(), -1, Qt::blue, false); richText.adjustSize(); heights.push_back(richText.height() + 8); log(L_DEBUG, "H[%u]=%u", i, richText.height() + 8); } } } move(x, y); QLabel::show(); }
BalloonMsg::BalloonMsg(void *param, const QString &_text, QStringList &btn, QWidget *parent, const QRect *rcParent, bool bModal, bool bAutoHide) : QDialog(parent, "ballon", bModal, (bAutoHide ? WType_Popup : WType_TopLevel | WStyle_StaysOnTop) | WStyle_Customize | WStyle_NoBorderEx | WStyle_Tool | WDestructiveClose | WX11BypassWM) { m_param = param; m_parent = parent; m_bAutoHide = bAutoHide; m_bYes = false; bool bTailDown = true; setPalette(QToolTip::palette()); text = _text; int hButton = 0; QFrame *frm = new QFrame(this); frm->setPalette(palette()); QHBoxLayout *lay = new QHBoxLayout(frm); lay->setSpacing(5); lay->addStretch(); unsigned id = 0; bool bFirst = true; for (QStringList::Iterator it = btn.begin(); it != btn.end(); ++it, id++){ BalloonButton *b = new BalloonButton(*it, frm, id); connect(b, SIGNAL(action(int)), this, SLOT(action(int))); lay->addWidget(b); if (bFirst){ b->setDefault(true); bFirst = false; } hButton = b->height(); } setButtonsPict(this); lay->addStretch(); int wndWidth = frm->minimumSizeHint().width(); int txtWidth = BALLOON_WIDTH; QRect rc; if (rcParent){ rc = *rcParent; }else{ QPoint p = parent->mapToGlobal(parent->rect().topLeft()); rc = QRect(p.x(), p.y(), parent->width(), parent->height()); } if (rc.width() > txtWidth) txtWidth = rc.width(); QPainter p(this); QRect rcText = p.boundingRect(0, 0, QMAX(wndWidth, txtWidth), 1000, AlignLeft | AlignTop | WordBreak, _text); if (rcText.width() < wndWidth) rcText.setWidth(wndWidth); resize(rcText.width() + BALLOON_R * 2 + BALLOON_SHADOW, rcText.height() + BALLOON_R * 2 + BALLOON_TAIL + BALLOON_SHADOW + hButton + BALLOON_MARGIN); p.end(); mask = QBitmap(width(), height()); int w = width() - BALLOON_SHADOW; int tailX = w / 2; int posX = rc.left() + rc.width() / 2 + BALLOON_TAIL_WIDTH - tailX; if (posX <= 0) posX = 1; QRect rcScreen = screenGeometry(); if (posX + width() >= rcScreen.width()) posX = rcScreen.width() - 1 - width(); int tx = posX + tailX - BALLOON_TAIL_WIDTH; if (tx < rc.left()) tx = rc.left(); if (tx > rc.left() + rc.width()) tx = rc.left() + rc.width(); tailX = tx + BALLOON_TAIL_WIDTH - posX; if (tailX < BALLOON_R) tailX = BALLOON_R; if (tailX > width() - BALLOON_R - BALLOON_TAIL_WIDTH) tailX = width() - BALLOON_R - BALLOON_TAIL_WIDTH; if (rc.top() <= height() + 2){ bTailDown = false; move(posX, rc.top() + rc.height() + 1); }else{ move(posX, rc.top() - height() - 1); } int pos = 0; int h = height() - BALLOON_SHADOW - BALLOON_TAIL; if (!bTailDown) pos += BALLOON_TAIL; textRect.setRect(BALLOON_R, pos + BALLOON_R, w - BALLOON_R * 2, h); frm->resize(rcText.width(), hButton); frm->move(BALLOON_R, pos + h - BALLOON_R - hButton); p.begin(&mask); #ifdef WIN32 QColor bg(255, 255, 255); QColor fg(0, 0, 0); #else QColor bg(0, 0, 0); QColor fg(255, 255, 255); #endif p.fillRect(0, 0, width(), height(), bg); p.fillRect(0, pos + BALLOON_R, w, h - BALLOON_R * 2, fg); p.fillRect(BALLOON_R, pos, w - BALLOON_R * 2, h, fg); p.fillRect(BALLOON_SHADOW, pos + BALLOON_R + BALLOON_SHADOW, w, h - BALLOON_R * 2, fg); p.fillRect(BALLOON_R + BALLOON_SHADOW, pos + BALLOON_SHADOW, w - BALLOON_R * 2, h, fg); p.setBrush(fg); p.drawEllipse(0, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(0, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(BALLOON_SHADOW, pos + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2 + BALLOON_SHADOW, pos + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2 + BALLOON_SHADOW, pos + h - BALLOON_R * 2 + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(BALLOON_SHADOW, pos + h - BALLOON_R * 2 + BALLOON_SHADOW, BALLOON_R * 2, BALLOON_R * 2); QPointArray arr(3); arr.setPoint(0, tailX, bTailDown ? h : pos); arr.setPoint(1, tailX + BALLOON_TAIL_WIDTH, bTailDown ? h : pos); arr.setPoint(2, tailX - BALLOON_TAIL_WIDTH, bTailDown ? height() - BALLOON_SHADOW : 0); p.drawPolygon(arr); arr.setPoint(0, tailX + BALLOON_SHADOW, (bTailDown ? h : pos) + BALLOON_SHADOW); arr.setPoint(1, tailX + BALLOON_TAIL_WIDTH + BALLOON_SHADOW, (bTailDown ? h : pos) + BALLOON_SHADOW); arr.setPoint(2, tailX - BALLOON_TAIL_WIDTH + BALLOON_SHADOW, bTailDown ? height() : BALLOON_SHADOW); p.drawPolygon(arr); p.end(); setMask(mask); qApp->syncX(); QPixmap pict = QPixmap::grabWindow(QApplication::desktop()->winId(), x(), y(), width(), height()); intensity(pict, -0.50f); p.begin(&pict); p.setBrush(colorGroup().background()); p.drawEllipse(0, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(w - BALLOON_R * 2, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); p.drawEllipse(0, pos + h - BALLOON_R * 2, BALLOON_R * 2, BALLOON_R * 2); arr.setPoint(0, tailX, bTailDown ? h - 1 : pos + 1); arr.setPoint(1, tailX + BALLOON_TAIL_WIDTH, bTailDown ? h - 1 : pos + 1); arr.setPoint(2, tailX - BALLOON_TAIL_WIDTH, bTailDown ? height() - BALLOON_SHADOW : 0); p.drawPolygon(arr); p.fillRect(0, pos + BALLOON_R, w, h - BALLOON_R * 2, colorGroup().background()); p.fillRect(BALLOON_R, pos, w - BALLOON_R * 2, h, colorGroup().background()); p.drawLine(0, pos + BALLOON_R, 0, pos + h - BALLOON_R); p.drawLine(w - 1, pos + BALLOON_R, w - 1, pos + h - BALLOON_R); if (bTailDown){ p.drawLine(BALLOON_R, 0, w - BALLOON_R, 0); p.drawLine(BALLOON_R, h - 1, tailX, h - 1); p.drawLine(tailX + BALLOON_TAIL_WIDTH, h - 1, w - BALLOON_R, h - 1); }else{ p.drawLine(BALLOON_R, pos + h - 1, w - BALLOON_R, pos + h - 1); p.drawLine(BALLOON_R, pos, tailX, pos); p.drawLine(tailX + BALLOON_TAIL_WIDTH, pos, w - BALLOON_R, pos); } p.end(); setBackgroundPixmap(pict); setAutoMask(true); if (!bAutoHide) setFocusPolicy(NoFocus); QWidget *top = NULL; if (parent) top = parent->topLevelWidget(); if (top){ raiseWindow(top); top->installEventFilter(this); } }