File indexing completed on 2024-04-21 15:42:57

0001 /***************************************************************************
0002     This is the shares view of Smb4K.
0003                              -------------------
0004     begin                : Mo Dez 4 2006
0005     copyright            : (C) 2006-2019 by Alexander Reinholdt
0006     email                : alexander.reinholdt@kdemail.net
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *   This program is free software; you can redistribute it and/or modify  *
0011  *   it under the terms of the GNU General Public License as published by  *
0012  *   the Free Software Foundation; either version 2 of the License, or     *
0013  *   (at your option) any later version.                                   *
0014  *                                                                         *
0015  *   This program is distributed in the hope that it will be useful, but   *
0016  *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
0017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
0018  *   General Public License for more details.                              *
0019  *                                                                         *
0020  *   You should have received a copy of the GNU General Public License     *
0021  *   along with this program; if not, write to the                         *
0022  *   Free Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston,*
0023  *   MA 02110-1335, USA                                                    *
0024  ***************************************************************************/
0025 
0026 #ifndef SMB4KSHARESVIEW_H
0027 #define SMB4KSHARESVIEW_H
0028 
0029 // Qt includes
0030 #include <QTimer>
0031 #include <QMimeData>
0032 #include <QListWidget>
0033 
0034 // forward declarations
0035 class Smb4KSharesViewItem;
0036 class Smb4KToolTip;
0037 
0038 
0039 /**
0040  * This widget class provides the shares view of Smb4K.
0041  *
0042  * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0043  */
0044 
0045 class Smb4KSharesView : public QListWidget
0046 {
0047   Q_OBJECT
0048 
0049   public:
0050     /**
0051      * The constructor.
0052      *
0053      * @param parent        The parent widget
0054      */
0055     explicit Smb4KSharesView(QWidget *parent = 0);
0056 
0057     /**
0058      * The destructor.
0059      */
0060     ~Smb4KSharesView();
0061     
0062     /**
0063      * Set the view mode.
0064      * 
0065      * @param mode          The view mode
0066      * @param iconSize      The size of the icons
0067      */
0068     void setViewMode(ViewMode mode, int iconSize);
0069 
0070   signals:
0071     /**
0072      * This signal is emitted when something has been dropped onto
0073      * @p item and the drop event was accepted.
0074      *
0075      * @param item          The item on which something has been dropped.
0076      *
0077      * @param e             The drop event.
0078      */
0079     void acceptedDropEvent(Smb4KSharesViewItem *item, QDropEvent *e);
0080     
0081     /**
0082      * This signal is emitted when a tool tip is about to be shown.
0083      * 
0084      * @param item          The shares list view item
0085      */
0086     void aboutToShowToolTip(Smb4KSharesViewItem *item);
0087     
0088     /**
0089      * This signal is emitted when a tool tip is about to be hidden.
0090      * 
0091      * @param item          The shares list view item
0092      */
0093     void aboutToHideToolTip(Smb4KSharesViewItem *item);
0094 
0095   protected:
0096     /**
0097      * Reimplemented from QListWidget.
0098      */
0099     bool event(QEvent *e) override;
0100 
0101     /**
0102      * Reimplemented from QWidget. This function emits the signal
0103      * mouseOutside().
0104      *
0105      * @param e             The event object
0106      */
0107     void leaveEvent(QEvent *e) override;
0108 
0109     /**
0110      * Reimplemented from QWidget. This function emits the signal
0111      * mouseInside().
0112      *
0113      * @param e             The event object
0114      */
0115     void enterEvent(QEvent *e) override;
0116 
0117     /**
0118      * Reimplemented from QAbstractItemView. This function handles
0119      * mouse press events.
0120      *
0121      * @param e             The mouse event object
0122      */
0123     void mousePressEvent(QMouseEvent *e) override;
0124 
0125     /**
0126      * Reimplemented from QAbstractItemView. This function is used
0127      * to stop the auto selection.
0128      *
0129      * @param e             The focus event
0130      */
0131     void focusOutEvent(QFocusEvent *e) override;
0132 
0133     /**
0134      * Reimplemented from QWidget. This function is used to handle
0135      * the tooltip.
0136      *
0137      * @param e             The wheel event
0138      */
0139     void wheelEvent(QWheelEvent *e) override;
0140 
0141     /**
0142      * Reimplemented to allow dragging and dropping.
0143      *
0144      * @param e             The drag event
0145      */
0146     virtual void dragEnterEvent(QDragEnterEvent *e) override;
0147 
0148     /**
0149      * Reimplemented to allow dragging and dropping.
0150      *
0151      * @param e             The drag move event
0152      */
0153     void dragMoveEvent(QDragMoveEvent *e) override;
0154 
0155     /**
0156      * Reimplemented to allow dragging and dropping.
0157      *
0158      * @param e             The drop event
0159      */
0160     void dropEvent(QDropEvent *e) override;
0161 
0162     /**
0163      * Reimplemented to allow only the copy drop action.
0164      */
0165     Qt::DropActions supportedDropActions() const override;
0166 
0167     /**
0168      * Reimplemented to allow dragging.
0169      */
0170     QMimeData *mimeData(const QList<QListWidgetItem *> list) const override;
0171 
0172     /**
0173      * Reimplemented to allow dragging.
0174      */
0175     void startDrag(Qt::DropActions supported) override;
0176 
0177   protected slots:
0178     /**
0179      * This slot is invoked when an item in the shares view has been entered.
0180      * It is used to display the tool tips.
0181      *
0182      * @param item            The item that is under the mouse.
0183      */
0184     void slotItemEntered(QListWidgetItem *item);
0185 
0186     /**
0187      * This slot is invoked when the viewport is entered. It is used
0188      * to hide the tool tip if needed.
0189      */
0190     void slotViewportEntered();
0191 
0192   private:
0193     /**
0194      * The item for that a tool tip is shown
0195      */
0196     Smb4KSharesViewItem *m_tooltipItem;
0197 
0198     /**
0199      * Is the mouse inside the widget?
0200      */
0201     bool m_mouseInside;
0202 };
0203 
0204 #endif