]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincontroller.h
Drag & drop fixes for all views: assure that a consistent pixmap for the drag object...
[dolphin.git] / src / dolphincontroller.h
index a7f227306d958ee1a7e0cca7abcb36fa21fdff88..e08e9e49031acf958b2873152efd2be5b03a0845 100644 (file)
 #include <QtCore/QObject>
 #include <libdolphin_export.h>
 
+class DolphinView;
 class KUrl;
 class QBrush;
-class QModelIndex;
 class QPoint;
 class QRect;
 class QWidget;
 
+// TODO: get rid of all the state duplications in the controller and allow read access
+// to the Dolphin view for all view implementations
+
 /**
- * @brief Allows to control Dolphin views and to react on state changes.
+ * @brief Acts as mediator between the abstract Dolphin view and the view
+ *        implementations.
  *
- * One instance of a DolphinController can be assigned to a variable number of
- * Dolphin views (DolphinIconsView, DolphinDetailsView) by passing it in
- * the constructor:
+ * The abstract Dolphin view (see DolphinView) represents the parent of the controller.
+ * The controller is passed to the current view implementation
+ * (see DolphinIconsView, DolphinDetailsView and DolphinColumnView)
+ * by passing it in the constructor:
  *
  * \code
- * DolphinController* controller = new DolphinController(parent);
- * DolphinDetailsView* detailsView = new DolphinDetailsView(parent, controller);
- * DolphinIconsView* iconsView = new DolphinIconsView(parent, controller);
+ * DolphinController* controller = new DolphinController(dolphinView);
+ * QAbstractItemView* view = new DolphinIconsView(parent, controller);
  * \endcode
  *
- * The Dolphin view assures that the controller gets informed about selection changes,
- * when an item should be triggered and a lot more. The controller emits the corresponding signals
- * so that the receiver may react on those changes.
+ * The communication of the view implementations to the abstract view is done by:
+ * - triggerContextMenuRequest()
+ * - requestActivation()
+ * - triggerUrlChangeRequest()
+ * - indicateDroppedUrls()
+ * - indicateSortingChange()
+ * - indicateSortOrderChanged()
+ * - setZoomInPossible()
+ * - setZoomOutPossible()
+ * - triggerItem()
+ * - emitItemEntered()
+ * - emitViewportEntered()
+ *
+ * The communication of the abstract view to the view implementations is done by:
+ * - setUrl()
+ * - setShowHiddenFiles()
+ * - setShowPreview()
+ * - indicateActivationChange()
+ * - triggerZoomIn()
+ * - triggerZoomOut()
  */
 class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
 {
     Q_OBJECT
 
 public:
-    explicit DolphinController(QObject* parent);
+    explicit DolphinController(DolphinView* dolphinView);
     virtual ~DolphinController();
 
-    /** Sets the URL to \a url and emits the signal urlChanged(). */
+    /**
+     * Allows read access for the the view implementation to the abstract
+     * Dolphin view.
+     */
+    const DolphinView* dolphinView() const;
+
+    /**
+     * Sets the URL to \a url and emits the signal urlChanged() if
+     * \a url is different for the current URL. This method should
+     * be invoked by the abstract Dolphin view whenever the current
+     * URL has been changed.
+     */
     void setUrl(const KUrl& url);
-    inline const KUrl& url() const;
+    const KUrl& url() const;
 
+    /**
+     * Allows a view implementation to request an URL change to \a url.
+     * The signal requestUrlChange() is emitted and the abstract Dolphin view
+     * will assure that the URL of the Dolphin Controller will be updated
+     * later. Invoking this method makes only sense if the view implementation
+     * shows a hierarchy of URLs and allows to change the URL within
+     * the view (e. g. this is the case in the column view).
+     */
+    void triggerUrlChangeRequest(const KUrl& url);
+
+    /**
+     * Requests a context menu for the position \a pos. This method
+     * should be invoked by the view implementation when a context
+     * menu should be opened. The abstract Dolphin view itself
+     * takes care itself to get the selected items depending from
+     * \a pos.
+     */
     void triggerContextMenuRequest(const QPoint& pos);
 
-    void triggerActivation();
+    /**
+     * Requests an activation of the view and emits the signal
+     * activated(). This method should be invoked by the view implementation
+     * if e. g. a mouse click on the view has been done.
+     * After the activation has been changed, the view implementation
+     * might listen to the activationChanged() signal.
+     */
+    void requestActivation();
 
+    /**
+     * Indicates that URLs are dropped above a destination. This method
+     * should be invoked by the view implementation. The abstract Dolphin view
+     * will start the corresponding action (copy, move, link).
+     * @param urls      URLs that are dropped above a destination.
+     * @param destPath  Path of the destination.
+     * @param destItem  Destination item (can be null, see KFileItem::isNull()).
+     */
     void indicateDroppedUrls(const KUrl::List& urls,
                              const KUrl& destPath,
-                             const QModelIndex& destIndex,
-                             QWidget* source);
+                             const KFileItem& destItem);
 
+    /**
+     * Informs the abstract Dolphin view about a sorting change done inside
+     * the view implementation. This method should be invoked by the view
+     * implementation (e. g. the details view uses this method in combination
+     * with the details header).
+     */
     void indicateSortingChange(DolphinView::Sorting sorting);
 
+    /**
+     * Informs the abstract Dolphin view about a sort order change done inside
+     * the view implementation. This method should be invoked by the view
+     * implementation (e. g. the details view uses this method in combination
+     * with the details header).
+     */
     void indicateSortOrderChange(Qt::SortOrder order);
 
-    void setShowPreview(bool show);
-    inline bool showPreview() const;
+    /**
+     * Informs the abstract Dolphin view about an additional information change
+     * done inside the view implementation. This method should be invoked by the
+     * view implementation (e. g. the details view uses this method in combination
+     * with the details header).
+     */
+    void indicateAdditionalInfoChange(const KFileItemDelegate::InformationList& info);
 
-    void setShowAdditionalInfo(bool show);
-    inline bool showAdditionalInfo() const;
+    /**
+     * Informs the view implementation about a change of the activation
+     * state and is invoked by the abstract Dolphin view. The signal
+     * activationChanged() is emitted.
+     */
+    void indicateActivationChange(bool active);
 
+    /**
+     * Tells the view implementation to zoom in by emitting the signal zoomIn()
+     * and is invoked by the abstract Dolphin view.
+     */
     void triggerZoomIn();
-    inline void setZoomInPossible(bool possible);
-    inline bool isZoomInPossible() const;
 
+    /**
+     * Is invoked by the view implementation to indicate whether a zooming in
+     * is possible. The abstract Dolphin view updates the corresponding menu
+     * action depending on this state.
+     */
+    void setZoomInPossible(bool possible);
+    bool isZoomInPossible() const;
+
+    /**
+     * Tells the view implementation to zoom out by emitting the signal zoomOut()
+     * and is invoked by the abstract Dolphin view.
+     */
     void triggerZoomOut();
-    inline void setZoomOutPossible(bool possible);
-    inline bool isZoomOutPossible() const;
 
-    // TODO: remove this method when the issue #160611 is solved in Qt 4.4
-    static void drawHoverIndication(QWidget* widget,
-                                    const QRect& bounds,
-                                    const QBrush& brush);
+    /**
+     * Is invoked by the view implementation to indicate whether a zooming out
+     * is possible. The abstract Dolphin view updates the corresponding menu
+     * action depending on this state.
+     */
+    void setZoomOutPossible(bool possible);
+    bool isZoomOutPossible() const;
 
 public slots:
     /**
      * Emits the signal itemTriggered(). The method should be invoked by the
      * controller parent whenever the user has triggered an item. */
-    void triggerItem(const QModelIndex& index);
+    void triggerItem(const KFileItem& item);
 
     /**
      * Emits the signal itemEntered(). The method should be invoked by
      * the controller parent whenever the mouse cursor is above an item.
      */
-    void emitItemEntered(const QModelIndex& index);
+    void emitItemEntered(const KFileItem& item);
 
     /**
      * Emits the signal viewportEntered(). The method should be invoked by
@@ -119,7 +218,14 @@ signals:
     void urlChanged(const KUrl& url);
 
     /**
-     * Is emitted if a context menu should be opened.
+     * Is emitted if the view implementation requests a changing of the current
+     * URL to \a url (see triggerUrlChangeRequest()).
+     */
+    void requestUrlChange(const KUrl& url);
+
+    /**
+     * Is emitted if a context menu should be opened (see triggerContextMenuRequest()).
+     * The abstract Dolphin view connects to this signal and will open the context menu.
      * @param pos       Position relative to the view widget where the
      *                  context menu should be opened. It is recommended
      *                  to get the corresponding model index from
@@ -129,102 +235,119 @@ signals:
 
     /**
      * Is emitted if the view has been activated by e. g. a mouse click.
+     * The abstract Dolphin view connects to this signal to know the
+     * destination view for the menu actions.
      */
     void activated();
 
     /**
      * Is emitted if the URLs \a urls have been dropped to the destination
      * path \a destPath. If the URLs have been dropped above an item of
-     * the destination path, the item is indicated by \a destIndex.
-     * \a source indicates the widget where the dragging has been started from.
+     * the destination path, the item is indicated by \a destItem
+     * (can be null, see KFileItem::isNull()).
      */
     void urlsDropped(const KUrl::List& urls,
                      const KUrl& destPath,
-                     const QModelIndex& destIndex,
-                     QWidget* source);
+                     const KFileItem& destItem);
 
-    /** Is emitted if the sorting has been changed to \a sorting. */
+    /**
+     * Is emitted if the sorting has been changed to \a sorting by
+     * the view implementation (see indicateSortingChanged().
+     * The abstract Dolphin view connects to
+     * this signal to update its menu action.
+     */
     void sortingChanged(DolphinView::Sorting sorting);
 
-    /** Is emitted if the sort order has been changed to \a sort order. */
+    /**
+     * Is emitted if the sort order has been changed to \a order
+     * by the view implementation (see indicateSortOrderChanged().
+     * The abstract Dolphin view connects
+     * to this signal to update its menu actions.
+     */
     void sortOrderChanged(Qt::SortOrder order);
 
     /**
-     * Is emitted if the state for showing previews has been
-     * changed to \a show.
+     * Is emitted if the additional info has been changed to \a info
+     * by the view implementation. The abstract Dolphin view connects
+     * to this signal to update its menu actions.
      */
-    void showPreviewChanged(bool show);
+    void additionalInfoChanged(const KFileItemDelegate::InformationList& info);
 
     /**
-     * Is emitted if the state for showing additional info has been
-     * changed to \a show.
+     * Is emitted if the activation state has been changed to \a active
+     * by the abstract Dolphin view.
+     * The view implementation might connect to this signal if custom
+     * updates are required in this case.
      */
-    void showAdditionalInfoChanged(bool show);
+    void activationChanged(bool active);
 
     /**
-     * Is emitted if the item with the index \a index should be triggered.
-     * Usually triggering on a directory opens the directory, triggering
-     * on a file opens the corresponding application.
-     * Emitted with an invalid \a index when clicking on the viewport itself.
+     * Is emitted if the item \a item should be triggered. The abstract
+     * Dolphin view connects to this signal. If the item represents a directory,
+     * the directory is opened. On a file the corresponding application is opened.
+     * The item is null (see KFileItem::isNull()), when clicking on the viewport itself.
      */
-    void itemTriggered(const QModelIndex& index);
+    void itemTriggered(const KFileItem& item);
 
     /**
      * Is emitted if the mouse cursor has entered the item
-     * given by \a index.
+     * given by \a index (see emitItemEntered()).
+     * The abstract Dolphin view connects to this signal.
      */
-    void itemEntered(const QModelIndex& index);
+    void itemEntered(const KFileItem& item);
 
     /**
      * Is emitted if the mouse cursor has entered
-     * the viewport. */
+     * the viewport (see emitViewportEntered().
+     * The abstract Dolphin view connects to this signal.
+     */
     void viewportEntered();
 
-    /** Is emitted if the view should zoom in. */
+    /**
+     * Is emitted if the view should zoom in. The view implementation
+     * must connect to this signal if it supports zooming.
+     */
     void zoomIn();
 
-    /** Is emitted if the view should zoom out. */
+    /**
+     * Is emitted if the view should zoom out. The view implementation
+     * must connect to this signal if it supports zooming.
+     */
     void zoomOut();
 
 private:
-    bool m_showPreview;
-    bool m_showAdditionalInfo;
     bool m_zoomInPossible;
     bool m_zoomOutPossible;
     KUrl m_url;
+    DolphinView* m_dolphinView;
 };
 
-const KUrl& DolphinController::url() const
-{
-    return m_url;
-}
-
-bool DolphinController::showPreview() const
+inline const DolphinView* DolphinController::dolphinView() const
 {
-    return m_showPreview;
+    return m_dolphinView;
 }
 
-bool DolphinController::showAdditionalInfo() const
+inline const KUrl& DolphinController::url() const
 {
-    return m_showAdditionalInfo;
+    return m_url;
 }
 
-void DolphinController::setZoomInPossible(bool possible)
+inline void DolphinController::setZoomInPossible(bool possible)
 {
     m_zoomInPossible = possible;
 }
 
-bool DolphinController::isZoomInPossible() const
+inline bool DolphinController::isZoomInPossible() const
 {
     return m_zoomInPossible;
 }
 
-void DolphinController::setZoomOutPossible(bool possible)
+inline void DolphinController::setZoomOutPossible(bool possible)
 {
     m_zoomOutPossible = possible;
 }
 
-bool DolphinController::isZoomOutPossible() const
+inline bool DolphinController::isZoomOutPossible() const
 {
     return m_zoomOutPossible;
 }