File indexing completed on 2024-04-14 15:05:37

0001 /***************************************************************************
0002     smb4knetworkbrowser  -  The network browser widget of Smb4K.
0003                              -------------------
0004     begin                : Mo Jan 8 2007
0005     copyright            : (C) 2007-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 SMB4KNETWORKBROWSER_H
0027 #define SMB4KNETWORKBROWSER_H
0028 
0029 // Qt includes
0030 #include <QTreeWidget>
0031 
0032 // forward declarations
0033 class Smb4KNetworkBrowserItem;
0034 class Smb4KToolTip;
0035 
0036 /**
0037  * This is the network neighborhood browser widget.
0038  * 
0039  * @author Alexander Reinholdt <alexander.reinholdt@kdemail.net>
0040  */
0041 
0042 class Smb4KNetworkBrowser : public QTreeWidget
0043 {
0044   Q_OBJECT
0045 
0046   public:
0047     /**
0048      * The constructor
0049      *
0050      * @param parent        The parent widget
0051      */
0052     explicit Smb4KNetworkBrowser(QWidget *parent = 0);
0053 
0054     /**
0055      * The destructor
0056      */
0057     ~Smb4KNetworkBrowser();
0058 
0059     /**
0060      * Enumeration for the columns in the list view.
0061      */
0062     enum Columns{ Network = 0,
0063                   Type = 1,
0064                   IP = 2,
0065                   Comment = 3 };
0066 
0067     /**
0068      * This function returns TRUE if the mouse is inside the network
0069      * browser widget and FALSE otherwise.
0070      *
0071      * @returns TRUE if the mouse is inside the widget.
0072      */
0073     bool mouseInsideWidget() { return m_mouse_inside; }
0074 
0075   signals:
0076     /**
0077      * This signal is emitted when a tool tip is about to be shown.
0078      * 
0079      * @param item          The network browser item
0080      */
0081     void aboutToShowToolTip(Smb4KNetworkBrowserItem *item);
0082     
0083     /**
0084      * This signal is emitted when a tool tip is about to be hidden.
0085      * 
0086      * @param item          The network browser item
0087      */
0088     void aboutToHideToolTip(Smb4KNetworkBrowserItem *item);
0089 
0090   protected:
0091     /**
0092      * Reimplemented from QWidget.
0093      */
0094     bool event(QEvent *e) override;
0095 
0096     /**
0097      * Reimplemented from QWidget. This function keeps track of the
0098      * mouse position and handles the tool tips.
0099      *
0100      * @param e             The mouse event
0101      */
0102     void mouseMoveEvent(QMouseEvent *e) override;
0103 
0104     /**
0105      * Reimplemented from QWidget. This function emits the signal
0106      * mouseOutside().
0107      *
0108      * @param e             The event object
0109      */
0110     void leaveEvent(QEvent *e) override;
0111 
0112     /**
0113      * Reimplemented from QWidget. This function emits the signal
0114      * mouseInside().
0115      *
0116      * @param e             The event object
0117      */
0118     void enterEvent(QEvent *e) override;
0119 
0120     /**
0121      * Reimplemented from QAbstractItemView. This function handles
0122      * mouse press events.
0123      *
0124      * @param e             The mouse event object
0125      */
0126     void mousePressEvent(QMouseEvent *e) override;
0127 
0128     /**
0129      * Reimplemented from QAbstractItemView. This function is used
0130      * to stop the auto selection.
0131      *
0132      * @param e             The focus event
0133      */
0134     void focusOutEvent(QFocusEvent *e) override;
0135 
0136     /**
0137      * Reimplemented from QWidget. This function is used to handle
0138      * the tooltip.
0139      *
0140      * @param e             The wheel event
0141      */
0142     void wheelEvent(QWheelEvent *e) override;
0143 
0144   protected slots:
0145    /**
0146      * This slot is used to change the cursor over an item if appropriate.
0147      *
0148      * @param item          The item that was entered.
0149      *
0150      * @param column        The column where the item was entered.
0151      */
0152     void slotItemEntered(QTreeWidgetItem *item, int column);
0153 
0154     /**
0155      * This slot is invoked when the viewport is entered. It is used
0156      * to hide the tool tip if needed.
0157      */
0158     void slotViewportEntered();
0159 
0160     /**
0161      * This slot is called when the user activated an item. It is used
0162      * to open the item if it is expandable.
0163      * @param item          The item that has been activated.
0164      * @param column        The column where the item was activated.
0165      */
0166     void slotItemActivated(QTreeWidgetItem *item, int column);
0167 
0168     /**
0169      * Take care that only shares are selected when the user marks multiple
0170      * shares.
0171      */    
0172     void slotItemSelectionChanged();
0173 
0174   private:
0175     /**
0176      * The item for that a tool tip is shown
0177      */
0178     Smb4KNetworkBrowserItem *m_tooltip_item;
0179     
0180     /**
0181      * Mouse inside the widget?
0182      */
0183     bool m_mouse_inside;
0184 };
0185 
0186 #endif