void LLWebPage::javaScriptAlert(QWebFrame* frame, const QString& msg) { Q_UNUSED(frame); QMessageBox *msgBox = new QMessageBox; msgBox->setWindowTitle(tr("JavaScript Alert - %1").arg(mainFrame()->url().host())); msgBox->setText(msg); msgBox->addButton(QMessageBox::Ok); QGraphicsProxyWidget *proxy = webView->scene()->addWidget(msgBox); proxy->setWindowFlags(Qt::Window); // this makes the item a panel (and will make it get a window 'frame') proxy->setPanelModality(QGraphicsItem::SceneModal); proxy->setPos((webView->boundingRect().width() - msgBox->sizeHint().width())/2, (webView->boundingRect().height() - msgBox->sizeHint().height())/2); proxy->setActive(true); // make it the active item connect(msgBox, SIGNAL(finished(int)), proxy, SLOT(deleteLater())); msgBox->show(); webView->scene()->setFocusItem(proxy); }
void OverlayEditorScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) { QGraphicsScene::contextMenuEvent(e); if (e->isAccepted()) return; if (! e->widget()) return; QGraphicsPixmapItem *item = childAt(e->scenePos()); QMenu qm(e->widget()); QMenu *qmLayout = qm.addMenu(tr("Layout preset")); QAction *qaLayoutLargeAvatar = qmLayout->addAction(tr("Large square avatar")); QAction *qaLayoutText = qmLayout->addAction(tr("Avatar and Name")); QMenu *qmTrans = qm.addMenu(tr("User Opacity")); QActionGroup *qagUser = new QActionGroup(&qm); QAction *userOpacity[8]; for (int i=0;i<8;++i) { qreal o = (i + 1) / 8.0; userOpacity[i] = new QAction(tr("%1%").arg(o * 100.0f, 0, 'f', 1), qagUser); userOpacity[i]->setCheckable(true); userOpacity[i]->setData(o); if (qFuzzyCompare(qgiGroup->opacity(), o)) userOpacity[i]->setChecked(true); qmTrans->addAction(userOpacity[i]); } QAction *color = NULL; QAction *fontAction = NULL; QAction *objectOpacity[8]; for (int i=0;i<8;++i) objectOpacity[i] = NULL; QAction *boxpen[4] = { NULL, NULL, NULL, NULL}; QAction *boxpad[4] = { NULL, NULL, NULL, NULL}; QAction *boxpencolor = NULL; QAction *boxfillcolor = NULL; QAction *align[6]; for (int i=0;i<6;++i) align[i] = NULL; if (item) { qm.addSeparator(); QMenu *qmObjTrans = qm.addMenu(tr("Object Opacity")); QActionGroup *qagObject = new QActionGroup(&qm); for (int i=0;i<8;++i) { qreal o = i + 1 / 8.0; objectOpacity[i] = new QAction(tr("%1%").arg(o * 100.0f, 0, 'f', 1), qagObject); objectOpacity[i]->setCheckable(true); objectOpacity[i]->setData(o); if (qFuzzyCompare(item->opacity(), o)) objectOpacity[i]->setChecked(true); qmObjTrans->addAction(objectOpacity[i]); } QMenu *qmObjAlign = qm.addMenu(tr("Alignment")); Qt::Alignment a; if (item == qgpiAvatar) a = os.qaAvatar; else if (item == qgpiChannel) a = os.qaChannel; else if (item == qgpiMuted) a = os.qaMutedDeafened; else a = os.qaUserName; align[0] = qmObjAlign->addAction(tr("Left")); align[0]->setCheckable(true); align[0]->setData(Qt::AlignLeft); if (a & Qt::AlignLeft) align[0]->setChecked(true); align[1] = qmObjAlign->addAction(tr("Center")); align[1]->setCheckable(true); align[1]->setData(Qt::AlignHCenter); if (a & Qt::AlignHCenter) align[1]->setChecked(true); align[2] = qmObjAlign->addAction(tr("Right")); align[2]->setCheckable(true); align[2]->setData(Qt::AlignRight); if (a & Qt::AlignRight) align[2]->setChecked(true); qmObjAlign->addSeparator(); align[3] = qmObjAlign->addAction(tr("Top")); align[3]->setCheckable(true); align[3]->setData(Qt::AlignTop); if (a & Qt::AlignTop) align[3]->setChecked(true); align[4] = qmObjAlign->addAction(tr("Center")); align[4]->setCheckable(true); align[4]->setData(Qt::AlignVCenter); if (a & Qt::AlignVCenter) align[4]->setChecked(true); align[5] = qmObjAlign->addAction(tr("Bottom")); align[5]->setCheckable(true); align[5]->setData(Qt::AlignBottom); if (a & Qt::AlignBottom) align[5]->setChecked(true); if ((item != qgpiAvatar) && (item != qgpiMuted)) { color = qm.addAction(tr("Color...")); fontAction = qm.addAction(tr("Font...")); } } if (qgpiBox->isVisible()) { qm.addSeparator(); QMenu *qmBox = qm.addMenu(tr("Bounding box")); QMenu *qmPen = qmBox->addMenu(tr("Pen width")); QMenu *qmPad = qmBox->addMenu(tr("Padding")); boxpencolor = qmBox->addAction(tr("Pen color")); boxfillcolor = qmBox->addAction(tr("Fill color")); QActionGroup *qagPen = new QActionGroup(qmPen); QActionGroup *qagPad = new QActionGroup(qmPad); for (int i=0;i<4;++i) { qreal v = (i) ? powf(2.0f, static_cast<float>(-10 + i)) : 0.0f; boxpen[i] = new QAction(QString::number(i), qagPen); boxpen[i]->setData(v); boxpen[i]->setCheckable(true); if (qFuzzyCompare(os.fBoxPenWidth, v)) boxpen[i]->setChecked(true); qmPen->addAction(boxpen[i]); boxpad[i] = new QAction(QString::number(i), qagPad); boxpad[i]->setData(v); boxpad[i]->setCheckable(true); if (qFuzzyCompare(os.fBoxPad, v)) boxpad[i]->setChecked(true); qmPad->addAction(boxpad[i]); } } QAction *act = qm.exec(e->screenPos()); if (! act) return; for (int i=0;i<8;++i) { if (userOpacity[i] == act) { float o = static_cast<float>(act->data().toReal()); os.fUser[tsColor] = o; qgiGroup->setOpacity(o); } } for (int i=0;i<8;++i) { if (objectOpacity[i] == act) { qreal o = act->data().toReal(); if (item == qgpiMuted) os.fMutedDeafened = o; else if (item == qgpiAvatar) os.fAvatar = o; else if (item == qgpiChannel) os.fChannel = o; else if (item == qgpiName) os.fUserName = o; item->setOpacity(o); } } for (int i=0;i<4;++i) { if (boxpen[i] == act) { os.fBoxPenWidth = act->data().toReal(); moveBox(); } else if (boxpad[i] == act) { os.fBoxPad = act->data().toReal(); moveBox(); } } for (int i=0;i<6;++i) { if (align[i] == act) { Qt::Alignment *aptr; if (item == qgpiAvatar) aptr = & os.qaAvatar; else if (item == qgpiChannel) aptr = & os.qaChannel; else if (item == qgpiMuted) aptr = & os.qaMutedDeafened; else aptr = & os.qaUserName; Qt::Alignment a = static_cast<Qt::Alignment>(act->data().toInt()); if (a & Qt::AlignHorizontal_Mask) { *aptr = (*aptr & ~Qt::AlignHorizontal_Mask) | a; } else { *aptr = (*aptr & ~Qt::AlignVertical_Mask) | a; } updateSelected(); } } if (act == boxpencolor) { QColor qc = QColorDialog::getColor(os.qcBoxPen, e->widget(), tr("Pick pen color"), QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel); if (! qc.isValid()) return; os.qcBoxPen = qc; moveBox(); } else if (act == boxfillcolor) { QColor qc = QColorDialog::getColor(os.qcBoxFill, e->widget(), tr("Pick fill color"), QColorDialog::DontUseNativeDialog | QColorDialog::ShowAlphaChannel); if (! qc.isValid()) return; os.qcBoxFill = qc; moveBox(); } else if (act == color) { QColor *col = NULL; if (item == qgpiChannel) col = & os.qcChannel; else if (item == qgpiName) col = & os.qcUserName[tsColor]; if (! col) return; QColor qc = QColorDialog::getColor(*col, e->widget(), tr("Pick color"), QColorDialog::DontUseNativeDialog); if (! qc.isValid()) return; qc.setAlpha(255); if (qc == *col) return; *col = qc; updateSelected(); } else if (act == fontAction) { QFont *fontptr = (item == qgpiChannel) ? &os.qfChannel : &os.qfUserName; qgpiSelected = NULL; qgriSelected->hide(); // QFontDialog doesn't really like graphics view. At all. QFontDialog qfd; qfd.setOptions(QFontDialog::DontUseNativeDialog); qfd.setCurrentFont(*fontptr); qfd.setWindowTitle(tr("Pick font")); int ret; if (g.ocIntercept) { QGraphicsProxyWidget *qgpw = new QGraphicsProxyWidget(NULL, Qt::Window); qgpw->setWidget(&qfd); addItem(qgpw); qgpw->setZValue(3.0f); qgpw->setPanelModality(QGraphicsItem::PanelModal); qgpw->setPos(- qgpw->boundingRect().width() / 2.0f, - qgpw->boundingRect().height() / 2.0f); qgpw->show(); ret = qfd.exec(); qgpw->hide(); qgpw->setWidget(NULL); delete qgpw; } else { Qt::WindowFlags wf = g.mw->windowFlags(); if (wf.testFlag(Qt::WindowStaysOnTopHint)) qfd.setWindowFlags(qfd.windowFlags() | Qt::WindowStaysOnTopHint); ret = qfd.exec(); } if (! ret) return; *fontptr = qfd.selectedFont(); resync(); } else if (act == qaLayoutLargeAvatar) { os.setPreset(OverlaySettings::LargeSquareAvatar); resync(); } else if (act == qaLayoutText) { os.setPreset(OverlaySettings::AvatarAndName); resync(); } }