1 /* 2 * This file Copyright (C) 2014-2015 Mnemosyne LLC 3 * 4 * It may be used under the GNU GPL versions 2 or 3 5 * or any future license endorsed by Mnemosyne LLC. 6 * 7 */ 8 9 #pragma once 10 11 #include <QToolButton> 12 13 class PathButton : public QToolButton 14 { 15 Q_OBJECT 16 17 public: 18 enum Mode 19 { 20 DirectoryMode, 21 FileMode 22 }; 23 24 public: 25 PathButton(QWidget* parent = nullptr); 26 27 void setMode(Mode mode); 28 void setTitle(QString const& title); 29 void setNameFilter(QString const& nameFilter); 30 31 void setPath(QString const& path); 32 QString const& path() const; 33 34 // QWidget 35 QSize sizeHint() const override; 36 37 signals: 38 void pathChanged(QString const& path); 39 40 protected: 41 // QWidget 42 void paintEvent(QPaintEvent* event) override; 43 44 private: 45 void updateAppearance(); 46 47 bool isDirMode() const; 48 QString effectiveTitle() const; 49 50 private slots: 51 void onClicked(); 52 void onFileSelected(QString const& path); 53 54 private: 55 Mode myMode; 56 QString myTitle; 57 QString myNameFilter; 58 QString myPath; 59 }; 60