]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontextmenu.h
Fix selection rect after porting from QFontMetrics::width()
[dolphin.git] / src / dolphincontextmenu.h
index ac165eef90f5dd4cf083738960cdc21aa6f91559..3f36895ec0b62a09cc19e5ec390c8e089fd80576 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
+ *   Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com>             *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
 #ifndef DOLPHINCONTEXTMENU_H
 #define DOLPHINCONTEXTMENU_H
 
-#include <kdesktopfileactions.h>
-#include <kfileitem.h>
-#include <kservice.h>
-#include <kurl.h>
+#include <KFileCopyToMenu>
+#include <KFileItem>
 
-#include <QObject>
+#include <QMenu>
+#include <QUrl>
 
-#include <QVector>
-
-class KMenu;
-class KFileItem;
 class QAction;
 class DolphinMainWindow;
+class KFileItemActions;
+class KFileItemListProperties;
+class DolphinRemoveAction;
 
 /**
  * @brief Represents the context menu which appears when doing a right
@@ -46,29 +44,51 @@ class DolphinMainWindow;
  * - 'Actions':   Contains all actions which can be applied to the
  *                given item.
  */
-class DolphinContextMenu : public QObject
+class DolphinContextMenu : public QMenu
 {
     Q_OBJECT
 
 public:
+    enum Command
+    {
+        None,
+        OpenParentFolder,
+        OpenParentFolderInNewWindow,
+        OpenParentFolderInNewTab
+    };
+
     /**
      * @parent        Pointer to the main window the context menu
      *                belongs to.
+     * @pos           Position in screen coordinates.
      * @fileInfo      Pointer to the file item the context menu
      *                is applied. If 0 is passed, the context menu
      *                is above the viewport.
      * @baseUrl       Base URL of the viewport where the context menu
      *                should be opened.
-     * @viewType      On which view type is the context menu shown.
      */
     DolphinContextMenu(DolphinMainWindow* parent,
-                       KFileItem* fileInfo,
-                       const KUrl& baseUrl);
+                       const QPoint& pos,
+                       const KFileItem& fileInfo,
+                       const QUrl& baseUrl);
+
+    ~DolphinContextMenu() override;
+
+    void setCustomActions(const QList<QAction*>& actions);
 
-    virtual ~DolphinContextMenu();
+    /**
+     * Opens the context menu model and returns the requested
+     * command, that should be triggered by the caller. If
+     * Command::None has been returned, either the context-menu
+     * had been closed without executing an action or an
+     * already available action from the main-window has been
+     * executed.
+     */
+    Command open();
 
-    /** Opens the context menu modal. */
-    void open();
+protected:
+    void keyPressEvent(QKeyEvent *ev) override;
+    void keyReleaseEvent(QKeyEvent *ev) override;
 
 private:
     void openTrashContextMenu();
@@ -76,37 +96,40 @@ private:
     void openItemContextMenu();
     void openViewportContextMenu();
 
-    void insertDefaultItemActions(KMenu* popup);
+    void insertDefaultItemActions(const KFileItemListProperties&);
+
+    /**
+     * Adds the "Show menubar" action to the menu if the
+     * menubar is hidden.
+     */
+    void addShowMenuBarAction();
+
+    bool placeExists(const QUrl& url) const;
+
+    QAction* createPasteAction();
+
+    KFileItemListProperties& selectedItemsProperties() const;
+
+    /**
+     * Returns the file item for m_baseUrl.
+     */
+    KFileItem baseFileItem();
 
     /**
-     * Inserts the 'Open With...' submenu to \a popup.
-     * @param popup          Menu where the 'Open With...' sub menu should
-     *                       be added.
-     * @param openWithVector Output parameter which contains all 'Open with...'
-     *                       services.
-     * @return               Identifier of the first 'Open With...' entry.
-     *                       All succeeding identifiers have an increased value of 1
-     *                       to the predecessor.
+     * Adds "Open With" actions
      */
-    QList<QAction*> insertOpenWithItems(KMenu* popup,
-                                        QVector<KService::Ptr>& openWithVector);
+    void addOpenWithActions(KFileItemActions& fileItemActions);
 
     /**
-     * Inserts the 'Actions...' submenu to \a popup.
-     * @param popup          Menu where the 'Actions...' sub menu should
-     *                       be added.
-     * @param openWithVector Output parameter which contains all 'Actions...'
-     *                       services.
+     * Adds actions that are provided by a KVersionControlPlugin.
      */
-    QList<QAction*> insertActionItems(KMenu* popup,
-                                      QVector<KDesktopFileActions::Service>& actionsVector);
+    void addVersionControlPluginActions();
 
     /**
-     * Returns true, if 'menu' contains already
-     * an entry with the name 'entryName'.
+     * Adds custom actions e.g. like the "[x] Expandable Folders"-action
+     * provided in the details view.
      */
-    bool containsEntry(const KMenu* menu,
-                       const QString& entryName) const;
+    void addCustomActions();
 
 private:
     struct Entry
@@ -123,15 +146,31 @@ private:
     {
         NoContext = 0,
         ItemContext = 1,
-        TrashContext = 2
+        TrashContext = 2,
+        TimelineContext = 4,
+        SearchContext = 8,
     };
 
+    QPoint m_pos;
     DolphinMainWindow* m_mainWindow;
-    KFileItem* m_fileInfo;
-    KUrl m_baseUrl;
+
+    KFileItem m_fileInfo;
+
+    QUrl m_baseUrl;
+    KFileItem* m_baseFileItem;  /// File item for m_baseUrl
+
     KFileItemList m_selectedItems;
-    KUrl::List m_selectedUrls;
+    mutable KFileItemListProperties* m_selectedItemsProperties;
+
     int m_context;
+    KFileCopyToMenu m_copyToMenu;
+    QList<QAction*> m_customActions;
+
+    Command m_command;
+
+    DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete'
+    void addDirectoryItemContextMenu(KFileItemActions &fileItemActions);
+
 };
 
 #endif