Ejemplo n.º 1
0
/*! \brief display the context Menu
 */
void ExtendedTableWidget::contextMenuEvent(QContextMenuEvent * event)
{
    qDebug() << Q_FUNC_INFO << event;
    qDebug() << "   " << event->pos();
    QTableWidgetItem *item = itemAt(event->pos());
    QAction *action;
    if (item) {
        event->accept();
        QMenu contextMenu( this );
        if (m_editable) {
            action = contextMenu.addAction(tr("&Remove"), this, SLOT(remove()));
            action->setProperty("row", row(item));
        }
        if (m_re_number.exactMatch(item->text())) {
            action = contextMenu.addAction(tr("&Dial"), this, SLOT(dialNumber()));
            action->setProperty("number", item->text());

            QMenu *transferMenu = new QMenu(tr("Direct &Transfer"), &contextMenu);
            QMenu *indirectTransferMenu = new QMenu(tr("&Indirect Transfer"), &contextMenu);
            UserInfo *ui = b_engine->getXivoClientUser();
            if (ui) {
                foreach (const QString phone, ui->phonelist()) {
                    const PhoneInfo * pi = ui->getPhoneInfo( phone );
                    if (pi) {
                        QMapIterator<QString, QVariant> it( pi->comms() );
                        while(it.hasNext()) {
                            it.next();
                            QMap<QString, QVariant> call = it.value().toMap();
                            // Add the transfer entry with the callerid name and num
                            QString text;
                            if (call.contains("calleridname")) {
                                text.append( call["calleridname"].toString() );
                                text.append(" : ");
                            }
                            text.append(call["calleridnum"].toString() );

                            action = transferMenu->addAction(text, this, SLOT(dtransfer()));
                            action->setProperty("chan", call["peerchannel"]);
                            action->setProperty("number", item->text());

                            action = indirectTransferMenu->addAction(text, this, SLOT(itransfer()));
                            action->setProperty("chan", call["thischannel"]);
                            action->setProperty("number", item->text());
                        }
                    }
                }
            }
            if (!transferMenu->isEmpty()) {
                contextMenu.addMenu(transferMenu);
            }
            if (!indirectTransferMenu->isEmpty()) {
                contextMenu.addMenu(indirectTransferMenu);
            }
        } else if(item->text().contains("@")) { // this is an email address
Ejemplo n.º 2
0
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
    QMenu *menu = new QMenu(this);

    QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());

    if (!r.linkUrl().isEmpty()) {
        menu->addAction(tr("Open in New &Window"), this, SLOT(openLinkInNewWindow()));
        menu->addAction(tr("Open in New &Tab"), this, SLOT(openLinkInNewTab()));
        menu->addSeparator();
        menu->addAction(tr("Save Lin&k"), this, SLOT(downloadLinkToDisk()));
        menu->addAction(tr("&Bookmark This Link"), this, SLOT(bookmarkLink()))->setData(r.linkUrl().toString());
        menu->addSeparator();
        menu->addAction(tr("&Copy Link Location"), this, SLOT(copyLinkToClipboard()));
        if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled))
            menu->addAction(pageAction(QWebPage::InspectElement));
    }

    if (!r.imageUrl().isEmpty()) {
        if (!menu->isEmpty())
            menu->addSeparator();
        menu->addAction(tr("Open Image in New &Window"), this, SLOT(openImageInNewWindow()));
        menu->addAction(tr("Open Image in New &Tab"), this, SLOT(openImageInNewTab()));
        menu->addSeparator();
        menu->addAction(tr("&Save Image"), this, SLOT(downloadImageToDisk()));
        menu->addAction(tr("&Copy Image"), this, SLOT(copyImageToClipboard()));
        menu->addAction(tr("C&opy Image Location"), this, SLOT(copyImageLocationToClipboard()))->setData(r.imageUrl().toString());
    }

#ifdef WEBKIT_TRUNK // i.e. Qt 4.5, but not in Qt 4.5 yet
    if (menu->isEmpty())
        menu = page()->createStandardContextMenu();
#endif

    if (!menu->isEmpty()) {
        if (m_page->mainWindow()->menuBar()->isHidden()) {
            menu->addSeparator();
            menu->addAction(m_page->mainWindow()->showMenuBarAction());
        }

        menu->exec(mapToGlobal(event->pos()));
        delete menu;
        return;
    }
    delete menu;

    QWebView::contextMenuEvent(event);
}
Ejemplo n.º 3
0
bool QMenuProto::isEmpty() const
{
  QMenu *item = qscriptvalue_cast<QMenu*>(thisObject());
  if (item)
    return item->isEmpty();
  return false;
}
Ejemplo n.º 4
0
void BookmarksToolbar::aboutToShowFolderMenu()
{
    QMenu* menu = qobject_cast<QMenu*> (sender());
    if (!menu) {
        return;
    }

    menu->clear();
    QString folder = menu->title();

    QSqlQuery query;
    query.prepare("SELECT title, url, icon FROM bookmarks WHERE folder=?");
    query.addBindValue(folder);
    query.exec();
    while (query.next()) {
        QString title = query.value(0).toString();
        QUrl url = query.value(1).toUrl();
        QIcon icon = IconProvider::iconFromBase64(query.value(2).toByteArray());
        if (title.length() > 40) {
            title.truncate(40);
            title += "..";
        }

        Action* act = new Action(icon, title);
        act->setData(url);
        connect (act, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl()));
        connect (act, SIGNAL(middleClicked()), p_QupZilla, SLOT(loadActionUrlInNewTab()));
        menu->addAction(act);
    }

    if (menu->isEmpty()) {
        menu->addAction(tr("Empty"));
    }
}
Ejemplo n.º 5
0
void DatabaseListWidget::customContextMenu(const QPoint& point)
{
	QMenu menu;

	QListWidgetItem *item = m_view->itemAt(point);
	QAction *newConnect=0, *switchDb=0;
	if(item) {
		newConnect = menu.addAction(tr("New connection"));
		if(m_canswitch)
			switchDb = menu.addAction(tr("Switch database"));
	}

	if(!menu.isEmpty())
		menu.addSeparator();

	QAction *refreshAct = menu.addAction(tr("Refresh"));

	QAction *a = menu.exec(m_view->mapToGlobal(point));
	if(a!=0) {
		if(a==refreshAct)
			m_connection->getDbList();
		else if(a==newConnect)
			emit newConnection(item->text());
		else if(a==switchDb)
			m_connection->switchDatabase(item->text());
	}
}
bool CDiagramContextMenuHandler::triggerMenu(CDiagram *d, const QPoint &p)
{
    bool                        r = false;
    QMenu                       hostMenu;
    CDiagram::DiagramMode       mode;
    CDiagramContextMenu         *hostedMenu = NULL;
    QList<CDiagramContextMenu*> menus;

    mode = d->mode();
    if (m_menus.contains(mode))
        menus = m_menus[mode];

    if (menus.length() > 0)
    {
        for (int i = 0; i < menus.length(); ++i)
        {
            hostedMenu = menus.at(i);
            if (hostedMenu->support(d))
            {
                hostedMenu->reset(d);
                hostedMenu->apply(&hostMenu);
            }
        }

        if (!hostMenu.isEmpty())
        {
            hostMenu.exec(p);
            r = true;
        }
    }

    return r;
}
Ejemplo n.º 7
0
bool MLModel::popup( const QModelIndex & index, const QPoint &point, const QModelIndexList &list )
{
    current_selection = list;
    current_index = index;
    QMenu menu;
    if( index.isValid() )
    {
        menu.addAction( QIcon( ":/menu/play" ), qtr(I_POP_PLAY), this, SLOT( popupPlay() ) );
        menu.addAction( QIcon( ":/menu/stream" ),
                        qtr(I_POP_STREAM), this, SLOT( popupStream() ) );
        menu.addAction( qtr(I_POP_SAVE), this, SLOT( popupSave() ) );
        menu.addAction( QIcon( ":/menu/info" ), qtr(I_POP_INFO), this, SLOT( popupInfo() ) );
        menu.addSeparator();
    }


    QIcon addIcon( ":/buttons/playlist/playlist_add" );
    menu.addSeparator();
    //menu.addAction( addIcon, qtr(I_PL_ADDF), THEDP, SLOT( simpleMLAppendDialog()) );
    //menu.addAction( addIcon, qtr(I_PL_ADDDIR), THEDP, SLOT( MLAppendDir() ) );
    //menu.addAction( addIcon, qtr(I_OP_ADVOP), THEDP, SLOT( MLAppendDialog() ) );

    if( index.isValid() )
    {
        menu.addAction( QIcon( ":/buttons/playlist/playlist_remove" ),
                        qtr(I_POP_DEL), this, SLOT( popupDel() ) );
        menu.addSeparator();
    }
    if( !menu.isEmpty() )
    {
        menu.exec( point ); return true;
    }
    else return false;
}
Ejemplo n.º 8
0
void WebView::contextMenuEvent(QContextMenuEvent* event)
{
	if (isLoading_) return;
	QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
	QMenu *menu;

	if (!r.linkUrl().isEmpty()) {
		if (r.linkUrl().scheme() == "addnick") {
			event->ignore();
			return;
		}
		menu = URLObject::getInstance()->createPopupMenu(r.linkUrl().toEncoded());
		//menu->addAction(pageAction(QWebPage::CopyLinkToClipboard));
	} else {
		menu = new QMenu(this);
		if (!page()->selectedText().isEmpty()) {
			menu->addAction(pageAction(QWebPage::Copy));
		} else {
			if (!menu->isEmpty()) {
				menu->addSeparator();
			}
			menu->addAction(pageAction(QWebPage::SelectAll));
		}
		if (settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) {
			menu->addAction(pageAction(QWebPage::InspectElement));
		}
	}
	menu->addAction(pageAction(QWebPage::Reload));
	menu->exec(mapToGlobal(event->pos()));
	event->accept();
	delete menu;
}
Ejemplo n.º 9
0
void BookmarksToolbar::aboutToShowFolderMenu()
{
    QMenu* menu = qobject_cast<QMenu*> (sender());
    if (!menu) {
        return;
    }

    menu->clear();
    QString folder = menu->title();

    foreach (const Bookmark &b, m_bookmarksModel->folderBookmarks(folder)) {
        QString title = b.title;
        if (title.length() > 40) {
            title.truncate(40);
            title += "..";
        }

        Action* act = new Action(qIconProvider->iconFromImage(b.image), title);
        act->setData(b.url);
        connect(act, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl()));
        connect(act, SIGNAL(middleClicked()), p_QupZilla, SLOT(loadActionUrlInNewNotSelectedTab()));
        menu->addAction(act);
    }

    if (menu->isEmpty()) {
        menu->addAction(tr("Empty"))->setEnabled(false);
    }
}
Ejemplo n.º 10
0
void pTableWidget::showContextMenu(const QPoint &pos)
{
    QMenu *contextMenu = new QMenu(this);
    foreach(QAction *a, actions())
        contextMenu->addAction(a);

    if(!contextMenu->isEmpty())
        contextMenu->exec(viewport()->mapToGlobal(pos));
}
Ejemplo n.º 11
0
QMenu *MvdMainWindow::createPopupMenu()
{
    QMenu *menu = QMainWindow::createPopupMenu();

    menu->addSeparator();
    if (!menu->isEmpty() && !menu->actions().last()->isSeparator())
        menu->addSeparator();
    menu->addAction(d->mA_LockToolBars);
    return menu;
}
Ejemplo n.º 12
0
void QtMenu::updateMenuVisibility(QMenu& qMenu)
{
	auto children = qMenu.findChildren<QMenu*>(QString(), Qt::FindDirectChildrenOnly);
	for (auto& child : children)
	{
		updateMenuVisibility(*child);
	}

	qMenu.menuAction()->setVisible(!qMenu.isEmpty());
}
void GettingStartedWelcomePageWidget::updateExamples(const QString &examplePath,
                                                     const QString &demosPath,
                                                     const QString &sourcePath)
{

    QString demoXml = demosPath + "/qtdemo/xml/examples.xml";
    if (!QFile::exists(demoXml)) {
        demoXml = sourcePath + "/demos/qtdemo/xml/examples.xml";
        if (!QFile::exists(demoXml))
            return;
    }

    QMenuHash cppSubMenuHash;
    QMenuHash qmlSubMenuHash;

    const QString dropDownLabel = tr("Choose an Example...");
    QMenu *cppMenu = new QMenu(ui->cppExamplesButton);
    ui->cppExamplesButton->setMenu(cppMenu);
    QMenu *qmlMenu = new QMenu(ui->qmlExamplesButton);


    // let Creator's files take precedence
    QString localQmlExamplesXml =
            Core::ICore::instance()->resourcePath()+QLatin1String("/examplebrowser/qmlexamples.xml");

    QFile localDescriptions(localQmlExamplesXml);
    if (localDescriptions.open(QFile::ReadOnly)) {
        parseXmlFile(&localDescriptions, cppSubMenuHash, qmlSubMenuHash, examplePath, sourcePath);
    }

    QFile descriptions(demoXml);
    if (!descriptions.open(QFile::ReadOnly))
        return;

    ui->cppExamplesButton->setEnabled(true);
    ui->cppExamplesButton->setText(dropDownLabel);

    parseXmlFile(&descriptions, cppSubMenuHash, qmlSubMenuHash, examplePath, sourcePath);

    QList<QMenu*> cppSubMenus = cppSubMenuHash.values();
    qSort(cppSubMenus.begin(), cppSubMenus.end(), menuEntryCompare);
    QList<QMenu*> qmlSubMenus = qmlSubMenuHash.values();
    qSort(qmlSubMenus.begin(), qmlSubMenus.end(), menuEntryCompare);

    foreach (QMenu *menu, cppSubMenus)
        cppMenu->addMenu(menu);
    foreach (QMenu *menu, qmlSubMenus)
        qmlMenu->addMenu(menu);

    if (!qmlMenu->isEmpty()) {
        ui->qmlExamplesButton->setMenu(qmlMenu);
        ui->qmlExamplesButton->setEnabled(true);
        ui->qmlExamplesButton->setText(dropDownLabel);
    }
}
Ejemplo n.º 14
0
void QToasterBrowserLCD::contextMenuEvent(QContextMenuEvent * cme)
{
  if(mpCtxMenuProvider)
  {
    QMenu ctxMenu;
    QPoint globalPos = mapToGlobal(cme->pos());
    mpCtxMenuProvider->createMenu(ctxMenu);
    if(!ctxMenu.isEmpty())
      ctxMenu.exec(globalPos);
  }
}
Ejemplo n.º 15
0
void TaskTreeView::openContextMenu(TreeModel::Item *gItem,
                                   const QPoint &globalPos) {
  TaskTreeModel::Item *item = static_cast<TaskTreeModel::Item *>(gItem);
  TaskTreeModel *m          = static_cast<TaskTreeModel *>(model());
  // m->setSelected(item->createIndex());
  if (item->getDepth() == 1) {
    static QMenu globalMenu;
    if (globalMenu.isEmpty()) {
      const std::vector<QAction *> &actions = m_mainViewer->getActions();
      assert(!actions.empty());
      int i;
      for (i = 0; i < actions.size(); i++) {
        globalMenu.addAction(actions[i]);
        if (i == 1 || i == 3 || i == 6) globalMenu.addSeparator();
      }
    }
    globalMenu.exec(globalPos);
  } else if (item->getDepth() > 1) {
    static QMenu menu;
    if (menu.isEmpty()) {
      bool ret = true;
      QAction *action;
      action = new QAction(tr("Start"), this);
      ret =
          ret && connect(action, SIGNAL(triggered(bool)), m, SLOT(start(bool)));
      menu.addAction(action);
      action = new QAction(tr("Stop"), this);
      ret =
          ret && connect(action, SIGNAL(triggered(bool)), m, SLOT(stop(bool)));
      menu.addAction(action);
      action = new QAction(tr("Remove"), this);
      menu.addAction(action);
      ret = ret &&
            connect(action, SIGNAL(triggered(bool)), m, SLOT(remove(bool)));
      assert(ret);
    }
    menu.exec(globalPos);
  }
Ejemplo n.º 16
0
QMenu* WebContextMenuProxyQt::createContextMenu(const Vector<WebContextMenuItemData>& items)
{
    QMenu* menu = new QMenu;
    for (int i = 0; i < items.size(); ++i) {
        const WebContextMenuItemData& item = items.at(i);
        switch (item.type()) {
        case WebCore::CheckableActionType: /* fall through */
        case WebCore::ActionType: {
            QWKPage::WebAction action = webActionForContextMenuAction(item.action());
            QAction* qtAction = m_page->action(action);
            if (qtAction) {
                qtAction->setEnabled(item.enabled());
                qtAction->setChecked(item.checked());
                qtAction->setCheckable(item.type() == WebCore::CheckableActionType);

                menu->addAction(qtAction);
            }
            break;
        }
        case WebCore::SeparatorType:
            menu->addSeparator();
            break;
        case WebCore::SubmenuType:
            if (QMenu *subMenu = createContextMenu(item.submenu())) {
                subMenu->setTitle(item.title());
                menu->addAction(subMenu->menuAction());
            }

            break;
        }
    }

    // Do not show sub-menus with just disabled actions.
    if (menu->isEmpty()) {
        delete menu;
        return 0;
    }
    bool isAnyActionEnabled = false;
    QList<QAction *> actions = menu->actions();
    for (int i = 0; i < actions.count(); ++i) {
        if (actions.at(i)->isVisible())
            isAnyActionEnabled |= actions.at(i)->isEnabled();
    }
    if (!isAnyActionEnabled) {
        delete menu;
        return 0;
    }

    return menu;
}
Ejemplo n.º 17
0
void Speller::populateLanguagesMenu()
{
    QMenu* menu = qobject_cast<QMenu*>(sender());

    if (!menu || !menu->isEmpty()) {
        return;
    }

    const QList<Language> langs = availableLanguages();
    foreach(const Language & lang, langs) {
        QAction* act = menu->addAction(lang.name, this, SLOT(changeLanguage()));
        act->setCheckable(true);
        act->setChecked(m_language == lang);
        act->setData(QVariant::fromValue(lang));
    }
Ejemplo n.º 18
0
void ezQtPropertyContainerWidget::OnCustomElementContextMenu(const QPoint& pt)
{
  ezQtGroupBoxBase* pGroup = qobject_cast<ezQtGroupBoxBase*>(sender());
  Element* pElement =
      std::find_if(begin(m_Elements), end(m_Elements), [pGroup](const Element& elem) -> bool { return elem.m_pSubGroup == pGroup; });

  if (pElement)
  {
    QMenu m;
    pElement->m_pWidget->ExtendContextMenu(m);

    m_pGrid->ExtendContextMenu(m, pElement->m_pWidget->GetSelection(), pElement->m_pWidget->GetProperty());

    if (!m.isEmpty())
    {
      m.exec(pGroup->mapToGlobal(pt));
    }
  }
}
void CollocationsDialogController::sl_plusClicked() {
    if (task != NULL) {
        return;
    }
    QMenu m;
    AnnotationSettingsRegistry* asr = AppContext::getAnnotationsSettingsRegistry();
    foreach(const QString& name, allNames) {
        if (usedNames.contains(name)) {
            continue;
        }
        QColor c = asr->getAnnotationSettings(name)->color;
        QAction* a = m.addAction(GUIUtils::createSquareIcon(c, 10), name, this, SLOT(sl_addName()));
        assert(a->parent() == &m); Q_UNUSED(a);
    }
    if (m.isEmpty()) {
        m.addAction(tr("No annotations left"));
    }
    m.exec(QCursor::pos());
}
Ejemplo n.º 20
0
void SchemeItem::contextMenuEvent(QGraphicsSceneContextMenuEvent* Event)
{
	static QMenu Menu(tr("Actions"));
	static QList<QAction*> Actions =
	{
		new QAction(QIcon::fromTheme("object-rotate-left"), tr("Rotate left"), &Menu),
		new QAction(QIcon::fromTheme("object-rotate-right"), tr("Rotate right"), &Menu),
		new QAction(QIcon::fromTheme("network-wired"), tr("Connect"), &Menu),
		new QAction(QIcon::fromTheme("preferences-system"), tr("Edit"), &Menu),
		new QAction(QIcon::fromTheme("edit-delete"), tr("Remove"), &Menu)
	};

	if (Menu.isEmpty()) Menu.addActions(Actions);

	QAction* Action = Menu.exec(Event->screenPos());

	if (Action == Actions[0])
	{
		setRotation(rotation() - 90);
	}
	else if (Action == Actions[1])
	{
		setRotation(rotation() + 90);
	}
	else if (Action == Actions[2])
	{
		emit onConnectRequest(1);

		//int(Event->pos().y() > (boundingRect().height() / 2)));

		qDebug() << "connect request on" << int(Event->pos().y() > (boundingRect().height() / 2));
	}
	else if (Action == Actions[3])
	{
		TriggerEditAction();
	}
	else if (Action == Actions[4])
	{
		deleteLater();
	}
}
Ejemplo n.º 21
0
void WebView::contextMenuEvent(QContextMenuEvent* event)
{
	if (isLoading_) return;
#ifdef WEBENGINE
#if QT_VERSION >= QT_VERSION_CHECK(5,7,0)
	QWebEngineContextMenuData r = page()->contextMenuData();
#else
	struct CMData {
		QUrl linkUrl() { return QUrl(); } // just a stub. TODO invent something
	};
	CMData r;
#endif
#else
	QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());
#endif
	QMenu *menu;

	if (!r.linkUrl().isEmpty()) {
		if (r.linkUrl().scheme() == "addnick") {
			event->ignore();
			return;
		}
		menu = URLObject::getInstance()->createPopupMenu(r.linkUrl().toEncoded());
		//menu->addAction(pageAction(QWebPage::CopyLinkToClipboard));
	} else {
		menu = new QMenu(this);
		if (!page()->selectedText().isEmpty()) {
#ifdef WEBENGINE
			menu->addAction(pageAction(QWebEnginePage::Copy));
		} else {
			if (!menu->isEmpty()) {
				menu->addSeparator();
			}
			menu->addAction(pageAction(QWebEnginePage::SelectAll));
		}
		menu->addAction(pageAction(QWebEnginePage::InspectElement));
	}
	menu->addAction(pageAction(QWebEnginePage::Reload));
#else
			menu->addAction(pageAction(QWebPage::Copy));
		} else {
Ejemplo n.º 22
0
void ChatPanel::showContextMenu(const QPoint &pos)
{
    auto item = ui->treeWidget->itemAt(pos);
    auto root = ui->treeWidget->topLevelItem(0);
    if (!item || item == root)
        return;

    auto userName = item->text(0);

    auto userIp = item->data(0, Qt::UserRole + 1).toString();

    auto userFullName = QString("%1@%2").arg(userName).arg(userIp);

    QMenu menu;

    emit connectedUserContextMenuActivated(menu, userFullName);

    if (!menu.isEmpty()) {
        auto menuPos = ui->treeWidget->viewport()->mapToGlobal(pos);
        menu.exec(menuPos);
    }
}
Ejemplo n.º 23
0
void DataTreeView::showPopup(const QPoint & pos)
{
    DataTreeViewItem * item = 0 ;
    auto items = selectedItems ();
    if(items.count() == 0) 
        return;

    QMenu menu(this);
    QMenu addMenu(this);
    vector<Action*> actions;

    if(items.count() == 1)
    {
        item = static_cast<DataTreeViewItem*>(items.back());
        uint guid = item->getGuid();
        serialization::Node* pNode = m_pDataBase->getNode(guid);

        if(pNode == nullptr)
        {
            const phantom::data& d = m_pDataBase->getData(guid);
            reflection::Class* pClass = d.type()->asClass();
            const phantom::data& owner = m_pDataBase->getComponentDataOwner(d);
            if(owner.isNull())
            {
                // Data directly removed from a Node
                //menu.addAction(new RemoveDataAction(&menu, m_pDataBase->getNode(d), d));
            }
            else
            {
                // Data first removed from its owner
                o_assert(owner.type()->asClass());

            }

            // Display/Hide action
            /*if (d.type()->isKindOf(phantom::typeOf<physic::CollisionShape>()))
            {
            menu.addAction(new DisplayDataAction(&menu, d, this));
            menu.addAction(new HideDataAction(&menu, d, this));
            }*/
        }
        else
        {
            if(pNode->getState() == serialization::Node::e_Loaded)
            {
                addMenu.setTitle("add");
                addMenu.setIcon(QIcon("resources/icons/famfamfam/add.png"));
                menu.addMenu(&addMenu);
                Action* pAction = o_new(AddNodeAction)(this, pNode, m_AddNodeActionDelegate, this);
                addMenu.addAction(pAction);
                actions.push_back(pAction);
                if(pNode != m_pDataBase->rootNode()) 
                {
                    addMenu.addSeparator();
                    for(auto it = phantom::beginModules(); it != phantom::endModules(); ++it)
                    {
                        reflection::Module* pModule = it->second;
                        for(auto it = pModule->beginPackages(); it != pModule->endPackages(); ++it)
                        {
                            QMenu* packageMenu = new QMenu;
                            reflection::Package* pPackage = *it;
                            for(auto it = pPackage->beginSources(); it != pPackage->endSources(); ++it)
                            {
                                reflection::Source* pSource = *it;
                                for(auto it = pSource->beginElements(); it != pSource->endElements(); ++it)
                                {
                                    packageMenu->setTitle(pPackage->getName().c_str());
                                    reflection::Class* pClass = (*it)->asClass();
                                    if(pClass 
                                        AND pClass->isPublic()
                                        AND NOT(pClass->testModifiers(o_private_visibility)) 
                                        AND NOT(pClass->isAbstract())
                                        AND pClass->isDefaultConstructible()
                                        AND pClass->getSingleton() == nullptr)
                                    {
                                        Action* pAction = o_new(AddDataAction)(this, pNode, pClass, m_AddDataActionDelegate, packageMenu);
                                        packageMenu->addAction(pAction);
                                        actions.push_back(pAction);
                                    }
                                }
                            }
                            if(!packageMenu->isEmpty())
                            {
                                addMenu.addMenu(packageMenu);
                            }
                        }
                    }
                    menu.addSeparator();
                    if(pNode->getParentNode()) // If it's not the root node
                    {
                        Action* pAction = o_new(UnloadNodeAction)(this, pNode, m_UnloadNodeActionDelegate, &menu);
                        menu.addAction(pAction);
                        actions.push_back(pAction);
                    }
                }

            }
            else if(pNode->getState() == serialization::Node::e_Unloaded)
            {
                Action* pAction = o_new(LoadNodeAction)(this, pNode, m_LoadNodeActionDelegate, &menu);
                menu.addAction(pAction);
                actions.push_back(pAction);
                pAction = o_new(LoadNodeAction)(this, pNode, m_RecursiveLoadNodeActionDelegate, &menu);
                menu.addAction(pAction);
                actions.push_back(pAction);
            }
        }
    }
    {
        vector<uint> guids;
        for(auto it = items.begin(); it != items.end(); ++it)
        {
            guids.push_back(((DataTreeViewItem*)(*it))->getGuid());
        }
        RemoveDataAction* pRemoveDataAction = o_new(RemoveDataAction)(this, guids, m_RemoveDataActionDelegate, &menu) ;
        menu.addAction(pRemoveDataAction);
        actions.push_back(pRemoveDataAction);
    }
    if(NOT(menu.isEmpty()))
    {
        menu.exec(QCursor::pos());
    }
    for(auto it = actions.begin(); it != actions.end(); ++it)
    {
        o_dynamic_delete *it;
    }
}
Ejemplo n.º 24
0
void WebView::contextMenuEvent(QContextMenuEvent *event)
{
    QMenu *menu = new QMenu(this);

    QWebHitTestResult r = page()->mainFrame()->hitTestContent(event->pos());

    if (!r.linkUrl().isEmpty()) {
        QAction *newWindowAction = menu->addAction(tr("Open in New &Window"), this, SLOT(openActionUrlInNewWindow()));
        newWindowAction->setData(r.linkUrl());
        QAction *newTabAction = menu->addAction(tr("Open in New &Tab"), this, SLOT(openActionUrlInNewTab()));
        newTabAction->setData(r.linkUrl());
        menu->addSeparator();
        menu->addAction(tr("Save Lin&k"), this, SLOT(downloadLinkToDisk()));
        menu->addAction(tr("&Bookmark This Link"), this, SLOT(bookmarkLink()))->setData(r.linkUrl());
        menu->addSeparator();
        if (!page()->selectedText().isEmpty())
            menu->addAction(pageAction(QWebPage::Copy));
        menu->addAction(tr("&Copy Link Location"), this, SLOT(copyLinkToClipboard()));
    }

    if (!r.imageUrl().isEmpty()) {
        if (!menu->isEmpty())
            menu->addSeparator();
        QAction *newWindowAction = menu->addAction(tr("Open Image in New &Window"), this, SLOT(openActionUrlInNewWindow()));
        newWindowAction->setData(r.imageUrl());
        QAction *newTabAction = menu->addAction(tr("Open Image in New &Tab"), this, SLOT(openActionUrlInNewTab()));
        newTabAction->setData(r.imageUrl());
        menu->addSeparator();
        menu->addAction(tr("&Save Image"), this, SLOT(downloadImageToDisk()));
        menu->addAction(tr("&Copy Image"), this, SLOT(copyImageToClipboard()));
        menu->addAction(tr("C&opy Image Location"), this, SLOT(copyImageLocationToClipboard()))->setData(r.imageUrl().toString());
        menu->addSeparator();
        menu->addAction(tr("Block Image"), this, SLOT(blockImage()))->setData(r.imageUrl().toString());
    }

    if (!page()->selectedText().isEmpty()) {
        if (menu->isEmpty()) {
            menu->addAction(pageAction(QWebPage::Copy));
        } else {
            menu->addSeparator();
        }
        QMenu *searchMenu = menu->addMenu(tr("Search with..."));

        QList<QString> list = ToolbarSearch::openSearchManager()->allEnginesNames();
        for (int i = 0; i < list.count(); ++i) {
            QString name = list.at(i);
            OpenSearchEngine *engine = ToolbarSearch::openSearchManager()->engine(name);
            QAction *action = new OpenSearchEngineAction(engine, searchMenu);
            searchMenu->addAction(action);
            action->setData(name);
        }

        connect(searchMenu, SIGNAL(triggered(QAction *)), this, SLOT(searchRequested(QAction *)));
    }

    QWebElement element = r.element();
    if (!element.isNull()
        && element.tagName().toLower() == QLatin1String("input")
        && element.attribute(QLatin1String("type"), QLatin1String("text")) == QLatin1String("text")) {
        if (menu->isEmpty()) {
            menu->addAction(pageAction(QWebPage::Copy));
        } else {
            menu->addSeparator();
        }

        QVariant variant;
        variant.setValue(element);
        menu->addAction(tr("Add to the toolbar search"), this, SLOT(addSearchEngine()))->setData(variant);
    }

    if (menu->isEmpty()) {
        delete menu;
        menu = page()->createStandardContextMenu();
    } else {
        if (page()->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled))
            menu->addAction(pageAction(QWebPage::InspectElement));
    }

    if (!menu->isEmpty()) {
        if (BrowserMainWindow::parentWindow(tabWidget())->menuBar()->isHidden()) {
            menu->addSeparator();
            menu->addAction(BrowserMainWindow::parentWindow(tabWidget())->showMenuBarAction());
        }

        menu->exec(mapToGlobal(event->pos()));
        delete menu;
        return;
    }
    delete menu;

    QWebView::contextMenuEvent(event);
}
Ejemplo n.º 25
0
void dspCashReceipts::sHandleButtons(bool valid)
{      
  int menuItem = -1;
  QMenu * editMenu = new QMenu;
  QMenu * viewMenu = new QMenu;   

  _reverse->setVisible(!_applications->isChecked());

  if (valid && _arapply->id() > -1)
  {
    // Handle Edit Button
    // Cash Receipt
    if (_arapply->currentItem()->rawValue("voided").toBool())
    {
      _post->hide();
      _reverse->hide();
    }
    else if (!_arapply->currentItem()->rawValue("posted").toBool())
    {
      editMenu->insertItem(tr("Cash Receipt..."), this, SLOT(sEditCashrcpt()), 0);
      editMenu->setItemEnabled(menuItem, _privileges->check("MaintainCashReceipts"));
        
      _post->show();
      _reverse->setVisible(!_applications->isChecked());
      _reverse->setEnabled(false);
      _post->setEnabled(_privileges->check("PostCashReceipts"));
    }
    else
    {
      _post->show();
      _reverse->setVisible(!_applications->isChecked());
      _post->setEnabled(false);
      _reverse->setEnabled(_privileges->check("ReversePostedCashReceipt")
                           && _cashreceipts->isChecked()
                           && !_arapply->altId());
    } 
        
    if (_arapply->currentItem()->id("target") > -1)
    {
      editMenu->insertItem(tr("Receivable Item..."), this, SLOT(sEditAropen()), 0);
      editMenu->setItemEnabled(menuItem, _privileges->check("EditAROpenItem"));
    }
    
    // Handle View Button
    // Cash Receipt             
    viewMenu->insertItem(tr("Cash Receipt..."), this, SLOT(sViewCashrcpt()), 0);
    viewMenu->setItemEnabled(menuItem, _privileges->check("ViewCashReceipts") || _privileges->check("MaintainCashReceipts"));
   
    // Open Item
    if (_arapply->currentItem()->id("target") > -1)
    {
      viewMenu->insertItem(tr("Receivable Item..."), this, SLOT(sViewAropen()), 0);
      viewMenu->setItemEnabled(menuItem, _privileges->check("ViewAROpenItems") || _privileges->check("EditAROpenItem"));
    }   
    
    _edit->setMenu(editMenu);
    _edit->setEnabled(!editMenu->isEmpty());
    _view->setMenu(viewMenu);
    _view->setEnabled(!viewMenu->isEmpty());
  }
  else
  {
    _edit->setEnabled(false);
    _view->setEnabled(false);
    _post->setEnabled(false);
    _reverse->setEnabled(false);
  }
}
Ejemplo n.º 26
0
void KateProjectTreeViewContextMenu::exec(const QString &filename, const QPoint &pos, QWidget *parent)
{
    /**
     * create context menu
     */
    QMenu menu;

    QAction *copyAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy Filename"));

    /**
     * handle "open with"
     * find correct mimetype to query for possible applications
     */
    QMenu *openWithMenu = menu.addMenu(i18n("Open With"));
    QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename);
    KService::List offers = KMimeTypeTrader::self()->query(mimeType.name(), QStringLiteral("Application"));

    /**
     * for each one, insert a menu item...
     */
    for (KService::List::Iterator it = offers.begin(); it != offers.end(); ++it) {
        KService::Ptr service = *it;
        if (service->name() == QStringLiteral("Kate")) {
            continue;    // omit Kate
        }
        QAction *action = openWithMenu->addAction(QIcon::fromTheme(service->icon()), service->name());
        action->setData(service->entryPath());
    }

    /**
     * perhaps disable menu, if no entries!
     */
    openWithMenu->setEnabled(!openWithMenu->isEmpty());

    KMoreToolsMenuFactory menuFactory(QLatin1String("kate/addons/project/git-tools"));

    QMenu gitMenu; // must live as long as the maybe filled menu items should live

    if (isGit(filename)) {

        menuFactory.fillMenuFromGroupingNames(&gitMenu, { QLatin1String("git-clients-and-actions") },
                                                               QUrl::fromLocalFile(filename));

        menu.addSection(i18n("Git:"));
        Q_FOREACH(auto action, gitMenu.actions()) {
            menu.addAction(action);
        }
    }

    /**
     * run menu and handle the triggered action
     */
    if (QAction *action = menu.exec(pos)) {

        // handle apps
        if (copyAction == action) {
            QApplication::clipboard()->setText(filename);
        } else {
            // handle "open with"
            const QString openWith = action->data().toString();
            if (KService::Ptr app = KService::serviceByDesktopPath(openWith)) {
                QList<QUrl> list;
                list << QUrl::fromLocalFile(filename);
                KRun::runService(*app, list, parent);
            }
        }
    }
}
Ejemplo n.º 27
0
bool RunWdgView::event( QEvent *event )
{
    //> Force event's process
    switch(event->type())
    {
	case QEvent::Paint:
	    if(permView())	break;
	    //> Paint message about access denied
	    if(dynamic_cast<RunPageView*>(this))
	    {
		QPainter pnt(this);
		//>> Fill page and draw border
		pnt.fillRect(rect(),QBrush(QColor("black"),Qt::Dense4Pattern));
		pnt.setPen(QPen(QBrush(QColor("black")),1));
		pnt.drawRect(rect().adjusted(0,0,-1,-1));
		//>> Draw message
		QTextOption to;
		pnt.setPen(QColor("red"));
		to.setAlignment(Qt::AlignCenter);
		to.setWrapMode(QTextOption::WordWrap);
		if( rect().width() > 500 && rect().height() > 100 )
		{
		    QFont cfnt = pnt.font();
		    cfnt.setPointSize( 16 );
		    pnt.setFont( cfnt );
		}
		pnt.drawText(rect(),QString(_("Page: '%1'.\nView access is not permitted.")).arg(id().c_str()),to);
	    }
	    return true;
	case QEvent::MouseButtonRelease:
	    if(((QMouseEvent*)event)->button() == Qt::RightButton && !property("contextMenu").toString().isEmpty() &&
		property("active").toBool() && permCntr() && isVisible(mapFromGlobal(cursor().pos())))
	    {
		QAction *actTmp;
		QMenu popup;
		string sln;
		for(int off = 0; (sln=TSYS::strSepParse(property("contextMenu").toString().toAscii().data(),0,'\n',&off)).size(); )
		{
		    actTmp = new QAction(TSYS::strSepParse(sln,0,':').c_str(),this);
		    actTmp->setWhatsThis(TSYS::strSepParse(sln,1,':').c_str());
		    popup.addAction(actTmp);
		}
		if(!popup.isEmpty())
		{
		    actTmp = popup.exec(QCursor::pos());
		    if(actTmp && !actTmp->whatsThis().isEmpty()) attrSet("event","usr_"+actTmp->whatsThis().toStdString());
		    popup.clear();
		    return true;
		}
	    }
	    break;
	default: break;
    }

    //> Call to shape for event process
    if(WdgView::event(event) || (shape&&shape->event(this,event)))	return true;

    //> Key events process for send to model
    string mod_ev;
    map<string,string> attrs;
    if(property("active").toBool() && permCntr())
    switch(event->type())
    {
	case QEvent::Paint:	return true;
	case QEvent::KeyPress:
	    mod_ev = "key_pres";
	case QEvent::KeyRelease:
	    if(((QKeyEvent*)event)->key() == Qt::Key_Tab) { mod_ev = ""; break; }
	    if(mod_ev.empty()) mod_ev = "key_rels";
	    if(QApplication::keyboardModifiers()&Qt::ControlModifier)	mod_ev += "Ctrl";
	    if(QApplication::keyboardModifiers()&Qt::AltModifier)	mod_ev += "Alt";
	    if(QApplication::keyboardModifiers()&Qt::ShiftModifier)	mod_ev += "Shift";
	    if(((QKeyEvent*)event)->nativeScanCode())
		attrs["event"] = mod_ev+"SC#"+TSYS::int2str(((QKeyEvent*)event)->nativeScanCode(),TSYS::Hex);
	    switch(((QKeyEvent*)event)->key())
	    {
		case Qt::Key_Escape:	mod_ev+="Esc";		break;
		case Qt::Key_Backspace:	mod_ev+="BackSpace";	break;
		case Qt::Key_Return:	mod_ev+="Return";	break;
		case Qt::Key_Enter:	mod_ev+="Enter";	break;
		case Qt::Key_Insert:	mod_ev+="Insert";	break;
		case Qt::Key_Delete:	mod_ev+="Delete";	break;
		case Qt::Key_Pause:	mod_ev+="Pause";	break;
		case Qt::Key_Print:	mod_ev+="Print";	break;
		//case Qt::Key_SysReq:	mod_ev+="SysReq";	break;
		//case Qt::Key_Clear:	mod_ev+="Clear";	break;
		case Qt::Key_Home:	mod_ev+="Home";		break;
		case Qt::Key_End:	mod_ev+="End";		break;
		case Qt::Key_Left:	mod_ev+="Left";		break;
		case Qt::Key_Up:	mod_ev+="Up";		break;
		case Qt::Key_Right:	mod_ev+="Right";	break;
		case Qt::Key_Down:	mod_ev+="Down";		break;
		case Qt::Key_PageUp:	mod_ev+="PageUp";	break;
		case Qt::Key_PageDown:	mod_ev+="PageDown";	break;
		case Qt::Key_F1:	mod_ev+="F1";		break;
		case Qt::Key_F2:	mod_ev+="F2";		break;
		case Qt::Key_F3:	mod_ev+="F3";		break;
		case Qt::Key_F4:	mod_ev+="F4";		break;
		case Qt::Key_F5:	mod_ev+="F5";		break;
		case Qt::Key_F6:	mod_ev+="F6";		break;
		case Qt::Key_F7:	mod_ev+="F7";		break;
		case Qt::Key_F8:	mod_ev+="F8";		break;
		case Qt::Key_F9:	mod_ev+="F9";		break;
		case Qt::Key_F10:	mod_ev+="F10";		break;
		case Qt::Key_F11:	mod_ev+="F11";		break;
		case Qt::Key_F12:	mod_ev+="F12";		break;
		case Qt::Key_F13:	mod_ev+="F13";		break;
		case Qt::Key_F14:	mod_ev+="F14";		break;
		case Qt::Key_F15:	mod_ev+="F15";		break;
		case Qt::Key_F16:	mod_ev+="F16";		break;
		case Qt::Key_F17:	mod_ev+="F17";		break;
		case Qt::Key_F18:	mod_ev+="F18";		break;
		case Qt::Key_F19:	mod_ev+="F19";		break;
		case Qt::Key_F20:	mod_ev+="F20";		break;
		case Qt::Key_F21:	mod_ev+="F21";		break;
		case Qt::Key_F22:	mod_ev+="F22";		break;
		case Qt::Key_F23:	mod_ev+="F23";		break;
		case Qt::Key_F24:	mod_ev+="F24";		break;
		case Qt::Key_F25:	mod_ev+="F25";		break;
		case Qt::Key_F26:	mod_ev+="F26";		break;
		case Qt::Key_F27:	mod_ev+="F27";		break;
		case Qt::Key_F28:	mod_ev+="F28";		break;
		case Qt::Key_F29:	mod_ev+="F29";		break;
		case Qt::Key_F30:	mod_ev+="F30";		break;
		case Qt::Key_F31:	mod_ev+="F31";		break;
		case Qt::Key_F32:	mod_ev+="F32";		break;
		case Qt::Key_F33:	mod_ev+="F33";		break;
		case Qt::Key_F34:	mod_ev+="F34";		break;
		case Qt::Key_F35:	mod_ev+="F35";		break;
		case Qt::Key_Space:	mod_ev+="Space";	break;
		case Qt::Key_Apostrophe:mod_ev+="Apostrophe";	break;
		case Qt::Key_Asterisk:	mod_ev+="Asterisk";	break;
		case Qt::Key_Plus:	mod_ev+="Plus";		break;
		case Qt::Key_Comma:	mod_ev+="Comma";	break;
		case Qt::Key_Minus:	mod_ev+="Minus";	break;
		case Qt::Key_Period:	mod_ev+="Period";	break;
		case Qt::Key_Slash:	mod_ev+="Slash";	break;
		case Qt::Key_0:		mod_ev+="0";		break;
		case Qt::Key_1:		mod_ev+="1";		break;
		case Qt::Key_2:		mod_ev+="2";		break;
		case Qt::Key_3:		mod_ev+="3";		break;
		case Qt::Key_4:		mod_ev+="4";		break;
		case Qt::Key_5:		mod_ev+="5";		break;
		case Qt::Key_6:		mod_ev+="6";		break;
		case Qt::Key_7:		mod_ev+="7";		break;
		case Qt::Key_8:		mod_ev+="8";		break;
		case Qt::Key_9:		mod_ev+="9";		break;
		case Qt::Key_Semicolon:	mod_ev+="Semicolon";	break;
		case Qt::Key_Equal:	mod_ev+="Equal";	break;
		case Qt::Key_A:		mod_ev+="A";		break;
		case Qt::Key_B:		mod_ev+="B";		break;
		case Qt::Key_C:		mod_ev+="C";		break;
		case Qt::Key_D:		mod_ev+="D";		break;
		case Qt::Key_E:		mod_ev+="E";		break;
		case Qt::Key_F:		mod_ev+="F";		break;
		case Qt::Key_G:		mod_ev+="G";		break;
		case Qt::Key_H:		mod_ev+="H";		break;
		case Qt::Key_I:		mod_ev+="I";		break;
		case Qt::Key_J:		mod_ev+="J";		break;
		case Qt::Key_K:		mod_ev+="K";		break;
		case Qt::Key_L:		mod_ev+="L";		break;
		case Qt::Key_M:		mod_ev+="M";		break;
		case Qt::Key_N:		mod_ev+="N";		break;
		case Qt::Key_O:		mod_ev+="O";		break;
		case Qt::Key_P:		mod_ev+="P";		break;
		case Qt::Key_Q:		mod_ev+="Q";		break;
		case Qt::Key_R:		mod_ev+="R";		break;
		case Qt::Key_S:		mod_ev+="S";		break;
		case Qt::Key_T:		mod_ev+="T";		break;
		case Qt::Key_U:		mod_ev+="U";		break;
		case Qt::Key_V:		mod_ev+="V";		break;
		case Qt::Key_W:		mod_ev+="W";		break;
		case Qt::Key_X:		mod_ev+="X";		break;
		case Qt::Key_Y:		mod_ev+="Y";		break;
		case Qt::Key_Z:		mod_ev+="Z";		break;
		case Qt::Key_BracketLeft:	mod_ev+="BracketLeft";	break;
		case Qt::Key_Backslash:	mod_ev+="BackSlash";	break;
		case Qt::Key_BracketRight:	mod_ev+="BracketRight";	break;
		case Qt::Key_QuoteLeft:	mod_ev+="QuoteLeft";	break;
		default:
		    mod_ev += "#"+TSYS::int2str(((QKeyEvent*)event)->key(),TSYS::Hex);
		    break;
	    }
	    attrs["event"] += (attrs["event"].size()?"\n":"")+mod_ev;
	    attrsSet(attrs);
	    return true;
	case QEvent::MouseButtonPress:
	    mod_ev = "key_mousePres";
	case QEvent::MouseButtonRelease:
	    if(mod_ev.empty()) mod_ev = "key_mouseRels";
	    switch(((QMouseEvent*)event)->button())
	    {
		case Qt::LeftButton:	mod_ev += "Left";	break;
		case Qt::RightButton:	mod_ev += "Right";	break;
		case Qt::MidButton:	mod_ev += "Midle";	break;
		default: break;
	    }
	    if(isVisible(mapFromGlobal(cursor().pos())))
	    {
		if(event->type() == QEvent::MouseButtonPress && !hasFocus()) setFocus(Qt::MouseFocusReason);
		attrSet("event", mod_ev);
		return true;
	    }
	    break;
	case QEvent::MouseButtonDblClick:
	    if(!isVisible(mapFromGlobal(cursor().pos()))) break;
	    attrSet("event", "key_mouseDblClick");
	    return true;
	case QEvent::FocusIn:	attrs["focus"] = "1"; attrs["event"] = "ws_FocusIn"; attrsSet(attrs); return true;
	case QEvent::FocusOut:	attrs["focus"] = "0"; attrs["event"] = "ws_FocusOut"; attrsSet(attrs); return true;
	default: break;
    }

    //> Try put mouse event to next level widget into same container
    if(!qobject_cast<RunPageView*>(this) &&
	(event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::MouseButtonDblClick))
    {
	bool isOk = false;
	QPoint curp = parentWidget()->mapFromGlobal(cursor().pos());
	for(int i_c = parentWidget()->children().size()-1; i_c >= 0; i_c--)
	{
	    RunWdgView *curwdg = qobject_cast<RunWdgView*>(parentWidget()->children().at(i_c));
	    if(!curwdg) continue;
	    if(curwdg == this) isOk = true;
	    else if(isOk && curwdg->geometry().contains(curp))
	    {
		RunWdgView *wdg = curwdg;
		curp = wdg->mapFromGlobal(cursor().pos());
		for(int i_cr = wdg->children().size()-1; i_cr >= 0; i_cr--)
		{
		    curwdg = qobject_cast<RunWdgView*>(wdg->children().at(i_cr));
		    if(curwdg && curwdg->geometry().contains(curp))
		    {
			wdg = curwdg;
			i_cr = wdg->children().size();
			curp = wdg->mapFromGlobal(cursor().pos());
		    }
		}
		return QApplication::sendEvent(wdg, event);
	    }
	}
    }

    return QWidget::event(event);
}
Ejemplo n.º 28
0
void MainWindow::editorContextMenuRequested ( const QPoint & pos ) {
    QString guid = getCurrentNoteGuid();
    if (guid == "main")
        return;

    QWebHitTestResult element = ui->editor->page()->mainFrame()->hitTestContent(pos);

    if (element.isNull())
        return;

    QStringList classes = allClasses(element.element());
    if (classes.contains("pdfarea"))
        return;

    QMenu * menu = new QMenu(ui->editor);

    menu->addAction(ui->editor->pageAction(QWebPage::SelectAll));

    if (element.isContentSelected()) {

        if (!menu->isEmpty())
            menu->addSeparator();

        menu->addAction(ui->editor->pageAction(QWebPage::Copy));

        if (element.isContentEditable()) {
            menu->addAction(ui->editor->pageAction(QWebPage::Cut));
            menu->addAction(ui->editor->pageAction(QWebPage::Paste));
            menu->addSeparator();

            menu->addAction(ui->editor->pageAction(QWebPage::ToggleBold));
            menu->addAction(ui->editor->pageAction(QWebPage::ToggleItalic));
            menu->addAction(ui->editor->pageAction(QWebPage::ToggleUnderline));
        }
    }

    if(!element.imageUrl().isEmpty() && (element.imageUrl().scheme() != "qrc")) {

        if (!menu->isEmpty())
            menu->addSeparator();

        menu->addAction(ui->editor->pageAction(QWebPage::DownloadImageToDisk));
        menu->addAction(ui->editor->pageAction(QWebPage::CopyImageToClipboard));

        if (element.imageUrl().scheme() == "http" || element.imageUrl().scheme() == "https")
            menu->addAction(ui->editor->pageAction(QWebPage::CopyImageUrlToClipboard));

        QAction * openImage = new QAction(this);
        openImage->setText("Open Image");
        openImage->setObjectName("openImage");
        menu->addAction(openImage);

        if (JS("editMode").toBool()) {
            menu->addSeparator();

            QAction * deleteImage = new QAction(this);
            deleteImage->setText("Delete Image");
            deleteImage->setObjectName("deleteImage");
            deleteImage->setIcon(QIcon::fromTheme("edit-delete"));
            menu->addAction(deleteImage);

            if (element.imageUrl().scheme() != "resource") {
                QAction * saveLocally = new QAction(this);
                saveLocally->setText("Save Locally");
                saveLocally->setObjectName("saveLocally");
                menu->addAction(saveLocally);
            }
        }
    }

    if (!element.linkUrl().isEmpty()) {
        if (!menu->isEmpty())
            menu->addSeparator();

        menu->addAction(ui->editor->pageAction(QWebPage::CopyLinkToClipboard));

        if (element.isContentEditable()) {
            QAction * deleteURL = new QAction(this);
            deleteURL->setText("Remove Link");
            deleteURL->setObjectName("deleteURL");
            menu->addAction(deleteURL);
        }
    }

    if (element.isContentEditable() && !element.isContentSelected() && element.imageUrl().isEmpty()) {
        Speller *speller = Speller::GetInstance();
        if (speller->initialized()) {

            QHash<QString, QString> languages = speller->availableLanguages();
            if (!languages.isEmpty()) {

                if (!menu->isEmpty())
                    menu->addSeparator();                

                QAction* act = menu->addAction(tr("Check &Spelling"));
                act->setCheckable(true);
                act->setChecked(speller->isEnabled());
                connect(act, SIGNAL(triggered(bool)), speller, SLOT(setEnabled(bool)));

                if (speller->isEnabled()) {
                    QString word = JS(QString("getSpellingWord(%1,%2);").arg(pos.x()).arg(pos.y())).toString();
                    if (!word.isEmpty() && speller->isMisspelled(word)) {
                        QStringList wordsList = speller->suggest(word);

                        QFont boldFont = menu->font();
                        boldFont.setBold(true);

                        QActionGroup *suggestGroup = new QActionGroup(menu);

                        QString suggest;
                        foreach(suggest, wordsList) {
                            QAction* act = menu->addAction(suggest);
                            act->setFont(boldFont);
                            act->setData(suggest);
                            suggestGroup->addAction(act);
                        }
                        connect(suggestGroup, SIGNAL(triggered(QAction*)), this, SLOT(replaceWord(QAction*)));
                    }
Ejemplo n.º 29
0
void MouseGameInput::showGameContextMenu(StackModel *stackModel)
{
    this->contextMenu = new QMenu();

    ObjectCharacter *character = stackModel->refCharacter();
    QList<ObjectItem *> *items = stackModel->refItemList();
    ObjectTile *wall = stackModel->refWall();
    ObjectTile *floor = stackModel->refFloor();
    QList<ObjectSpecial *> *specials = stackModel->refSpecialList();

    if(character)
    {
        ObjectMenu *menu = new ObjectMenu(character, this->processor, this->contextMenu);

        if(character->getObjectID() == ObjectID::PLAYER &&
           this->gameModel->getPlayerID() == character->getSpawnID())
        {
            menu->setTitle(menu->title().append(tr(" (YOU)")));
        }

        this->contextMenu->addMenu(menu);
    }

    if(!items->isEmpty())
    {
        QMenu *itemMenu = new QMenu(tr("Items"), this->contextMenu);

        for(int i = 0; i < items->size(); ++i)
        {
            itemMenu->addMenu(new ObjectMenu(items->at(i), this->processor, itemMenu));
        }

        if(!itemMenu->isEmpty())
        {
            this->contextMenu->addMenu(itemMenu);
        }
    }

    if(wall)
    {
        this->contextMenu->addMenu(new ObjectMenu(wall, this->processor, this->contextMenu));
    }

    if(floor)
    {
        this->contextMenu->addMenu(new ObjectMenu(floor, this->processor, this->contextMenu));
    }

    if(!specials->isEmpty())
    {
        QMenu *specialMenu = new QMenu(tr("Specials"), this->contextMenu);

        for(int i = 0; i < specials->size(); ++i)
        {
            if(specials->at(i)->isVisibleInGame())
            {
                specialMenu->addMenu(new ObjectMenu(specials->at(i), this->processor, specialMenu));
            }
        }

        if(!specialMenu->isEmpty())
        {
            this->contextMenu->addMenu(specialMenu);
        }
    }

    if(character)
    {
        QAction *options = 0;
        QAction *endTurn = 0;

        if(character &&
           character->getObjectID() == ObjectID::PLAYER &&
           character->getSpawnID() == this->gameModel->getPlayerID())
        {
            endTurn = new QAction(tr("End Turn"), this->contextMenu);
            connect(endTurn, SIGNAL(triggered()), this, SLOT(endTurn()));
            options = new QAction(tr("Options"), this->contextMenu);
            connect(options, SIGNAL(triggered()), this, SLOT(showGameOptions()));
        }

        if(((this->gameModel->isYourTurn() && endTurn) || options) && !this->contextMenu->isEmpty())
        {
            this->contextMenu->addSeparator();
        }

        if(options)
        {
            this->contextMenu->addAction(options);
        }

        if(this->gameModel->isYourTurn() && endTurn)
        {
            this->contextMenu->addAction(endTurn);
        }
    }

    if(!this->contextMenu->isEmpty())
    {
        emit showContextMenu(stackModel);
    }

    return;
}