1 /*
2  * Copyright (C) 2016  Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  */
19 
20 #ifndef FM_PATHBAR_H
21 #define FM_PATHBAR_H
22 
23 #include "libfmqtglobals.h"
24 #include <QWidget>
25 #include "core/filepath.h"
26 
27 class QToolButton;
28 class QScrollArea;
29 class QPushButton;
30 class QHBoxLayout;
31 
32 namespace Fm {
33 
34 class PathEdit;
35 class PathButton;
36 
37 class LIBFM_QT_API PathBar: public QWidget {
38     Q_OBJECT
39 public:
40     explicit PathBar(QWidget* parent = nullptr);
41 
path()42     const Fm::FilePath& path() {
43         return currentPath_;
44     }
45 
46     void setPath(Fm::FilePath path);
47 
48 Q_SIGNALS:
49     void chdir(const Fm::FilePath& path);
50     void middleClickChdir(const Fm::FilePath& path);
51     void editingFinished();
52 
53 public Q_SLOTS:
54     void openEditor();
55     void closeEditor();
56     void copyPath();
57 
58 private Q_SLOTS:
59   void onButtonToggled(bool checked);
60   void onScrollButtonClicked();
61   void onReturnPressed();
62   void setArrowEnabledState(int value);
63   void setScrollButtonVisibility();
64   void ensureToggledVisible();
65 
66 protected:
67     void resizeEvent(QResizeEvent* event) override;
68     void wheelEvent(QWheelEvent* event) override;
69     void mousePressEvent(QMouseEvent* event) override;
70     void contextMenuEvent(QContextMenuEvent* event) override;
71 
72 private:
73     void updateScrollButtonVisibility();
74     Fm::FilePath pathForButton(PathButton* btn);
75 
76 private:
77     QToolButton* scrollToStart_;
78     QToolButton* scrollToEnd_;
79     QScrollArea* scrollArea_;
80     QWidget* buttonsWidget_;
81     QHBoxLayout* buttonsLayout_;
82     PathEdit* tempPathEdit_;
83 
84     Fm::FilePath currentPath_;   // currently active path
85     PathButton* toggledBtn_;
86 };
87 
88 } // namespace Fm
89 
90 #endif // FM_PATHBAR_H
91