Пример #1
0
void IconView::contextMenuEvent( QContextMenuEvent* event )
{
    QModelIndex index = indexAt( event->pos() );
    if ( !index.isValid() || m_selectionModel->selectedIndexes().isEmpty() ) {
        QMenu* menu = new QMenu;
        menu->addAction( m_actionCollection.action( "new_menu" ) );
        menu->addSeparator();
        menu->addAction( m_actionCollection.action( "undo" ) );
        menu->addAction( m_actionCollection.action( "paste" ) );
        menu->addSeparator();
        menu->addAction( m_actionCollection.action( "refresh" ) );
        menu->addSeparator();
        menu->addAction( m_actionCollection.action( "wallpaper" ) );
        if ( event->reason() == QContextMenuEvent::Keyboard )
            menu->exec( QPoint( 0, 0 ) );
        else
            menu->exec( event->pos() );
        delete menu;
        return;
    }

    KFileItemList items;
    foreach ( const QModelIndex &index, m_selectionModel->selectedIndexes() ) {
        KFileItem item = m_model->itemForIndex( m_proxyModel->mapToSource( index ) );
        if ( !item.isNull() )
            items.append( item );
    }

    QAction* pasteTo = m_actionCollection.action( "pasteto" );
    if ( pasteTo ) {
        pasteTo->setEnabled( m_actionCollection.action( "paste" )->isEnabled() );
        pasteTo->setText( m_actionCollection.action( "paste" )->text() );
    }

    QList<QAction*> editActions;
    editActions.append( m_actionCollection.action( "rename" ) );
    editActions.append( m_actionCollection.action( "trash" ) );
    KConfigGroup configGroup( KGlobal::config(), "KDE" );
    bool showDeleteCommand = configGroup.readEntry( "ShowDeleteCommand", false );
    if ( showDeleteCommand )
        editActions.append( m_actionCollection.action( "del" ) );
    KParts::BrowserExtension::ActionGroupMap actionGroups;
    actionGroups.insert( "editactions", editActions );
    KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::ShowProperties;
    flags |= KParts::BrowserExtension::ShowUrlOperations;
    KonqPopupMenu* contextMenu = new KonqPopupMenu( items, KUrl(QDir::homePath()), m_actionCollection, m_newMenu,
                                                    KonqPopupMenu::ShowNewWindow, flags,
                                                    QApplication::desktop(),
                                                    KBookmarkManager::userBookmarksManager(),
                                                    actionGroups );
    contextMenu->exec( event->pos() );
    delete contextMenu;
}
Пример #2
0
PopupMenuGUIClient::PopupMenuGUIClient( const KService::List &embeddingServices,
                                        KParts::BrowserExtension::ActionGroupMap& actionGroups,
                                        QAction* showMenuBar, QAction* stopFullScreen )
    : m_actionCollection(this),
      m_embeddingServices(embeddingServices)
{
    QList<QAction *> topActions;
    if (showMenuBar) {
        topActions.append(showMenuBar);
        KAction* separator = new KAction(&m_actionCollection);
        separator->setSeparator(true);
        topActions.append(separator);
    }

    if (stopFullScreen) {
        topActions.append(stopFullScreen);
        KAction* separator = new KAction(&m_actionCollection);
        separator->setSeparator(true);
        topActions.append(separator);
    }

    if (!embeddingServices.isEmpty()) {
        QList<QAction *> previewActions;
        if (embeddingServices.count() == 1) {
            KService::Ptr service = embeddingServices.first();
            QAction* act = addEmbeddingService( 0, i18n( "Preview &in %1", service->name() ), service );
            previewActions.append(act);
        } else if (embeddingServices.count() > 1) {
            KService::List::ConstIterator it = embeddingServices.begin();
            const KService::List::ConstIterator end = embeddingServices.end();
            int idx = 0;
            for (; it != end; ++it, ++idx ) {
                QAction* act = addEmbeddingService( idx, (*it)->name(), *it );
                previewActions.append(act);
            }
        }
        actionGroups.insert("preview", previewActions);
    }
    actionGroups.insert("topactions", topActions);
}
Пример #3
0
void WebView::editableContentActionPopupMenu(KParts::BrowserExtension::ActionGroupMap& partGroupMap)
{
    QList<QAction*> editableContentActions;

    KActionMenu* menu = new KActionMenu(i18nc("Text direction", "Direction"), this);
    QActionGroup* group = new QActionGroup(this);
    group->setExclusive(true);

    QAction *action = m_actionCollection->addAction(QL1S("text-direction-default"),  m_part->browserExtension(), SLOT(slotTextDirectionChanged()));
    action->setText(i18n("Default"));
    action->setCheckable(true);
    action->setData(QWebPage::SetTextDirectionDefault);
    action->setEnabled(pageAction(QWebPage::SetTextDirectionDefault)->isEnabled());
    action->setCheckable(pageAction(QWebPage::SetTextDirectionDefault)->isChecked());
    action->setActionGroup(group);
    menu->addAction(action);

    action = m_actionCollection->addAction(QL1S("text-direction-left-to-right"),  m_part->browserExtension(), SLOT(slotTextDirectionChanged()));
    action->setText(i18n("Left to right"));
    action->setCheckable(true);
    action->setData(QWebPage::SetTextDirectionLeftToRight);
    action->setEnabled(pageAction(QWebPage::SetTextDirectionLeftToRight)->isEnabled());
    action->setChecked(pageAction(QWebPage::SetTextDirectionLeftToRight)->isChecked());
    action->setActionGroup(group);
    menu->addAction(action);

    action = m_actionCollection->addAction(QL1S("text-direction-right-to-left"),  m_part->browserExtension(), SLOT(slotTextDirectionChanged()));
    action->setText(i18n("Right to left"));
    action->setCheckable(true);
    action->setData(QWebPage::SetTextDirectionRightToLeft);
    action->setEnabled(pageAction(QWebPage::SetTextDirectionRightToLeft)->isEnabled());
    action->setChecked(pageAction(QWebPage::SetTextDirectionRightToLeft)->isChecked());
    action->setActionGroup(group);
    menu->addAction(action);

    editableContentActions.append(menu);

    action = new QAction(m_actionCollection);
    action->setSeparator(true);
    editableContentActions.append(action);

    action = m_actionCollection->addAction(KStandardAction::Copy, QL1S("copy"),  m_part->browserExtension(), SLOT(copy()));
    action->setEnabled(pageAction(QWebPage::Copy)->isEnabled());
    editableContentActions.append(action);

    action = m_actionCollection->addAction(KStandardAction::Cut, QL1S("cut"),  m_part->browserExtension(), SLOT(cut()));
    action->setEnabled(pageAction(QWebPage::Cut)->isEnabled());
    editableContentActions.append(action);

    action = m_actionCollection->addAction(KStandardAction::Paste, QL1S("paste"),  m_part->browserExtension(), SLOT(paste()));
    action->setEnabled(pageAction(QWebPage::Paste)->isEnabled());
    editableContentActions.append(action);

    action = new QAction(m_actionCollection);
    action->setSeparator(true);
    editableContentActions.append(action);

    const bool hasContent = (!m_result.element().evaluateJavaScript(QL1S("this.value")).toString().isEmpty());
    action = m_actionCollection->addAction(KStandardAction::SelectAll, QL1S("selectall"),  m_part->browserExtension(), SLOT(slotSelectAll()));
    action->setEnabled((pageAction(QWebPage::SelectAll)->isEnabled() && hasContent));
    editableContentActions.append(action);

    if (showSpellCheckAction(m_result.element())) {
        action = new QAction(m_actionCollection);
        action->setSeparator(true);
        editableContentActions.append(action);
        action = m_actionCollection->addAction(KStandardAction::Spelling, QL1S("spelling"), m_part->browserExtension(), SLOT(slotCheckSpelling()));
        action->setText(i18n("Check Spelling..."));
        action->setEnabled(hasContent);
        editableContentActions.append(action);

        const bool hasSelection = (hasContent && m_result.isContentSelected());
        action = m_actionCollection->addAction(KStandardAction::Spelling, QL1S("spellcheckSelection"), m_part->browserExtension(), SLOT(slotSpellCheckSelection()));
        action->setText(i18n("Spellcheck selection..."));
        action->setEnabled(hasSelection);
        editableContentActions.append(action);
    }

    if (settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled)) {
        if (!m_webInspector) {
            m_webInspector = new QWebInspector;
            m_webInspector->setPage(page());
            connect(page(), SIGNAL(destroyed()), m_webInspector, SLOT(deleteLater()));
        }
        action = new QAction(m_actionCollection);
        action->setSeparator(true);
        editableContentActions.append(action);
        editableContentActions.append(pageAction(QWebPage::InspectElement));
    }

    partGroupMap.insert("editactions" , editableContentActions);
}
Пример #4
0
void PopupView::showContextMenu(QWidget *widget, const QPoint &screenPos, const QList<QModelIndex> &indexes)
{
    Q_UNUSED(widget)
    // contextMenuRequest is only called from the icon view, which is created in init()
    // which mean m_model should always be initialized
    Q_ASSERT(m_model);

    if (indexes.isEmpty()) {
        return;
    }

    if (m_actionCollection.isEmpty()) {
        createActions();
    }

    KFileItemList items;
    bool hasRemoteFiles = false;
    bool isTrashLink = false;

    foreach (const QModelIndex &index, m_selectionModel->selectedIndexes()) {
        KFileItem item = m_model->itemForIndex(index);
        if (!item.isNull()) {
            hasRemoteFiles |= item.localPath().isEmpty();
            items.append(item);
        }
    }

    // Check if we're showing the menu for the trash link
    if (items.count() == 1 && items.at(0).isDesktopFile()) {
        KDesktopFile file(items.at(0).localPath());
        if (file.readType() == "Link" && file.readUrl() == "trash:/") {
            isTrashLink = true;
        }
    }

    QAction *pasteTo = m_actionCollection.action("pasteto");
    if (pasteTo) {
        if (QAction *paste = m_actionCollection.action("paste")) {
            pasteTo->setEnabled(paste->isEnabled());
            pasteTo->setText(paste->text());
        }
    }

    QList<QAction*> editActions;
    editActions.append(m_actionCollection.action("rename"));

    KConfigGroup configGroup(KGlobal::config(), "KDE");
    bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false);

    // Don't add the "Move to Trash" action if we're showing the menu for the trash link
    if (!isTrashLink) {
        if (!hasRemoteFiles) {
            editActions.append(m_actionCollection.action("trash"));
        } else {
            showDeleteCommand = true;
        }
    }
    if (showDeleteCommand) {
        editActions.append(m_actionCollection.action("del"));
    }

    KParts::BrowserExtension::ActionGroupMap actionGroups;
    actionGroups.insert("editactions", editActions);

    KParts::BrowserExtension::PopupFlags flags = KParts::BrowserExtension::ShowProperties;
    flags |= KParts::BrowserExtension::ShowUrlOperations;

    // m_newMenu can be NULL here but KonqPopupMenu does handle this.
    KonqPopupMenu *contextMenu = new KonqPopupMenu(items, m_url, m_actionCollection, m_newMenu,
                                                   KonqPopupMenu::ShowNewWindow, flags,
                                                   QApplication::desktop(),
                                                   KBookmarkManager::userBookmarksManager(),
                                                   actionGroups);

    connect(contextMenu->fileItemActions(), SIGNAL(openWithDialogAboutToBeShown()), this, SLOT(openWithDialogAboutToShow()));

    m_showingMenu = true;
    contextMenu->exec(screenPos);
    delete contextMenu;
    m_showingMenu = false;

    if (pasteTo) {
        pasteTo->setEnabled(false);
    }

    if (m_delayedClose) {
        m_delayedClose = false;
        closeThisAndParentPopup();
    }
}