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); } }
void QSAEditor::doObjectCompletion() { QTextCursor cursor = textCursor(); cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor); QString objectName = cursor.selectedText(); if (objectName.endsWith(QLatin1Char('-'))) objectName.chop(1); objectName = objectName.simplified(); QString object = resolveFullyQualifiedValue(objectName, parseAssignments(functionCode())); bool assumedStatic = false; QSCompletionObject o; if(objectName == object) { QSObject stobj = env()->globalObject().get(object); if(stobj.isValid() && stobj.objectType()->valueType() == TypeClass) { #if defined ( QSA_COMPLETION_DEBUG ) printf(" -> assuming static\n"); #endif o = stobj; assumedStatic = true; } } if(o.type == QSCompletionObject::TNull) { o = queryObject(object); } #if defined ( QSA_COMPLETION_DEBUG ) printf(" -> type is: %d\n", o.type); #endif o.resolve(); if (o.isNull()) return; QVector<CompletionEntry> res; QSObject nullObject; switch (o.type) { case QSCompletionObject::TQSObject: #if defined ( QSA_COMPLETION_DEBUG ) printf(" -> objectType is: %s\n", o.qsobj.objectType()->name().latin1()); #endif if(o.qsobj.objectType()->name() == QString::fromLatin1("FactoryObject")){ QSObject sinst = ( (QSFactoryObjectProxy*) o.qsobj.objectType() )->staticInstance(); if(!sinst.isValid()) return; QSWrapperShared *shared = (QSWrapperShared*) sinst.shVal(); completeQObject( shared->objects, object, res ); break; } completeQSObject(o.qsobj, res, !assumedStatic); break; case QSCompletionObject::TQMetaObject: completeQMetaObject(o.meta, object, res, IncludeSuperClass, nullObject); break; case QSCompletionObject::TQObject: completeQObject(o.qobj, object, res); break; case QSCompletionObject::TNull: break; } if (!res.isEmpty()) { QFrame *f = new QFrame(0, Qt::Popup); f->setAttribute(Qt::WA_DeleteOnClose); QWidget *box = new CompletionBox(this, res); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(box); layout->setMargin(0); f->setLayout(layout); f->move(mapToGlobal(cursorRect().bottomLeft())); f->show(); box->setFocus(); } }
BalloonMsg::BalloonMsg(const QString &_text, const QRect &rc, QStringList &btn, QWidget *parent, bool bModal, bool bAutoHide) : QDialog(parent, "ballon", bModal, (bAutoHide ? WType_Popup : WType_TopLevel | WStyle_StaysOnTop) | WStyle_Customize | WStyle_NoBorderEx | WStyle_Tool | WDestructiveClose | WX11BypassWM) { m_bAutoHide = bAutoHide; 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, SIGNAL(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; 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; if (posX + width() >= QApplication::desktop()->width()) posX = QApplication::desktop()->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); }