JKQtExtras
a library of useful Qt widgets and tools
jkqtespecialtoolbutton.h
1 /*
2  Copyright (c) 2008-2020 Jan W. Krieger (<jan@jkrieger.de>)
3 
4  This software is free software: you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License (LGPL) as
6  published by the Free Software Foundation, either version 2.1 of the License,
7  or (at your option) any later version.
8 
9  This program 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
12  GNU Lesser General Public License (LGPL) for more details.
13 
14  You should have received a copy of the GNU Lesser General Public License
15  (LGPL) along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef JKQTESPECIALTOOLBUTTON_H
19 #define JKQTESPECIALTOOLBUTTON_H
20 #include <QToolBar>
21 #include <QToolButton>
22 #include <QLineEdit>
23 #include <QUrl>
24 #include <QString>
25 #include <QDesktopServices>
26 #include <QFileDialog>
27 #include <QFileInfo>
28 #include <iostream>
29 #include "jkqtextras_imexport.h"
30 
31 
32 
33 
34 /** \brief specialized QToolButton which takes the contents of its buddy as webpage adress (URL) and opens
35  * it in the system's standard application
36  * \ingroup JKQtExtrasWidgetsButtons
37  *
38  * \image html JKQTEURLOpenToolButton.png
39  *
40  * Usage example:
41  *
42  * \snippet jkqtextras_test/testmainwindow.cpp Example: JKQTEURLOpenToolButton
43  */
44 class JKQTEXTRAS_LIB_EXPORT JKQTEURLOpenToolButton : public QToolButton {
45  Q_OBJECT
46  public:
47  /** Default constructor */
48  JKQTEURLOpenToolButton(QWidget* parent=nullptr);
49  /** Default destructor */
51 
52  /** \brief buddy associated with this button */
53  const QLineEdit* buddy() const;
54  /** \brief buddy associated with this button */
55  QLineEdit* buddy() ;
56  /** \brief set the buddy widget, which provides the contents */
57  void setBuddy(QLineEdit* b);
58  protected slots:
59  /** \brief opens the contents of the buddy() as URL
60  *
61  * This internally calls \c QDesktopServices::openUrl(QUrl(buddyContents,QUrl::TolerantMode));
62  */
64  private:
65  QLineEdit* m_buddy;
66 };
67 
68 
69 /** \brief specialized QToolButton which allows to select a file and saves its path in the buddy
70  * \ingroup JKQtExtrasWidgetsButtons
71  *
72  * \image html JKQTEFileSelectToolButton.png
73  *
74  * Usage example:
75  *
76  * \snippet jkqtextras_test/testmainwindow.cpp Example: JKQTEFileSelectToolButton
77  */
79  Q_OBJECT
80 public:
81  /** Default constructor */
82  JKQTEFileSelectToolButton(QWidget* parent=nullptr);
83  /** Default destructor */
85 
86  /** \brief buddy associated with this button */
87  const QLineEdit* buddy() const;
88  /** \brief buddy associated with this button */
89  QLineEdit* buddy() ;
90  /** \brief set the buddy widget, which provides the contents */
91  void setBuddy(QLineEdit* b);
92  /** \brief returns a basedir in which files are searched for execution, if this is empty the current directory is used */
93  QString getBaseDir() const;
94  /** \brief returns the title label of the file select dialog*/
95  QString getDialogTitle() const;
96  /** \brief returns the file filter of the file select dialog*/
97  QString getDialogFilter() const;
98 public slots:
99  /** \brief sets the file filter of the file select dialog*/
100  void setDialogFilter(const QString &b);
101  /** \brief sets the title label of the file select dialog*/
102  void setDialogTitle(const QString& b);
103  /** \brief set a basedir in which files are searched for execution, if this is empty the current directory is used */
104  void setBaseDir(const QString& b);
105 protected slots:
107 private:
108  QLineEdit* m_buddy;
109  QString m_baseDir;
110  QString m_dlgTitle;
111  QString m_dlgFilter;
112 };
113 
114 
115 /** \brief specialized QToolButton which allows to select a directory and saves its path in the buddy
116  * \ingroup JKQtExtrasWidgetsButtons
117  *
118  * \image html JKQTEDirectorySelectToolButton.png
119  *
120  * Usage example:
121  *
122  * \snippet jkqtextras_test/testmainwindow.cpp Example: JKQTEDirectorySelectToolButton
123  */
125  Q_OBJECT
126 public:
127  /** Default constructor */
128  JKQTEDirectorySelectToolButton(QWidget* parent=nullptr);
129  /** Default destructor */
131 
132  /** \brief buddy associated with this button */
133  const QLineEdit* buddy() const;
134  /** \brief buddy associated with this button */
135  QLineEdit* buddy() ;
136  /** \brief set the buddy widget, which provides the contents */
137  void setBuddy(QLineEdit* b);
138  /** \brief returns a basedir in which files are searched for execution, if this is empty the current directory is used */
139  QString getBaseDir() const;
140  /** \brief returns the title label of the file select dialog*/
141  QString getDialogTitle() const;
142 public slots:
143  /** \brief sets the file filter of the file select dialog*/
144  void setDialogFilter(const QString &b);
145  /** \brief set a basedir in which files are searched for execution, if this is empty the current directory is used */
146  void setBaseDir(const QString& b);
147 protected slots:
149 private:
150  QLineEdit* m_buddy;
151  QString m_baseDir;
152  QString m_dlgTitle;
153  QString m_dlgFilter;
154 };
155 
156 
157 /** \brief specialized QToolButton which allows to open the file referenced by the buddy edit
158  * \ingroup JKQtExtrasWidgetsButtons
159  *
160  * \image html JKQTEFileExecuteToolButton.png
161  *
162  * Usage example:
163  *
164  * \snippet jkqtextras_test/testmainwindow.cpp Example: JKQTEFileExecuteToolButton
165  */
167  Q_OBJECT
168  public:
169  /** Default constructor */
170  JKQTEFileExecuteToolButton(QWidget* parent=nullptr);
171  /** Default destructor */
173  /** \brief buddy associated with this button */
174  const QLineEdit* buddy() const;
175  /** \brief buddy associated with this button */
176  QLineEdit* buddy();
177  /** \brief returns a basedir in which files are searched for execution, if this is empty the current directory is used */
178  QString getBaseDir() const;
179  public slots:
180  /** \brief set the buddy widget, which provides the contents */
181  void setBuddy(QLineEdit* b);
182  /** \brief set a basedir in which files are searched for execution, if this is empty the current directory is used */
183  void setBaseDir(const QString& b);
184  protected slots:
185  /** \brief executes the contents of the buddy()
186  *
187  * This internally calls \c QDesktopServices::openUrl(QUrl("file:///"+buddyContents,QUrl::TolerantMode));
188  *
189  * \see setBaseDir()
190  */
192 
193  private:
194  QLineEdit* m_buddy;
195  QString m_baseDir;
196 };
197 
198 #endif // JKQTESPECIALTOOLBUTTON_H
JKQTEFileSelectToolButton
specialized QToolButton which allows to select a file and saves its path in the buddy
Definition: jkqtespecialtoolbutton.h:78
JKQTEFileSelectToolButton::getDialogTitle
QString getDialogTitle() const
returns the title label of the file select dialog
JKQTEFileSelectToolButton::setBaseDir
void setBaseDir(const QString &b)
set a basedir in which files are searched for execution, if this is empty the current directory is us...
JKQTEFileExecuteToolButton::buddy
const QLineEdit * buddy() const
buddy associated with this button
JKQTEURLOpenToolButton::openBuddyContents
void openBuddyContents()
opens the contents of the buddy() as URL
JKQTEDirectorySelectToolButton::setDialogFilter
void setDialogFilter(const QString &b)
sets the file filter of the file select dialog
JKQTEDirectorySelectToolButton::getBaseDir
QString getBaseDir() const
returns a basedir in which files are searched for execution, if this is empty the current directory i...
JKQTEDirectorySelectToolButton::m_dlgFilter
QString m_dlgFilter
Definition: jkqtespecialtoolbutton.h:153
JKQTEDirectorySelectToolButton::buddy
QLineEdit * buddy()
buddy associated with this button
JKQTEURLOpenToolButton::~JKQTEURLOpenToolButton
virtual ~JKQTEURLOpenToolButton()
JKQTEDirectorySelectToolButton::m_buddy
QLineEdit * m_buddy
Definition: jkqtespecialtoolbutton.h:150
JKQTEFileSelectToolButton::setDialogFilter
void setDialogFilter(const QString &b)
sets the file filter of the file select dialog
JKQTEFileExecuteToolButton::JKQTEFileExecuteToolButton
JKQTEFileExecuteToolButton(QWidget *parent=nullptr)
JKQTEFileExecuteToolButton::openBuddyContents
void openBuddyContents()
executes the contents of the buddy()
JKQTEFileSelectToolButton::m_dlgFilter
QString m_dlgFilter
Definition: jkqtespecialtoolbutton.h:111
JKQTEFileExecuteToolButton::setBaseDir
void setBaseDir(const QString &b)
set a basedir in which files are searched for execution, if this is empty the current directory is us...
JKQTEDirectorySelectToolButton::JKQTEDirectorySelectToolButton
JKQTEDirectorySelectToolButton(QWidget *parent=nullptr)
JKQTEDirectorySelectToolButton::buddy
const QLineEdit * buddy() const
buddy associated with this button
JKQTEFileSelectToolButton::getBaseDir
QString getBaseDir() const
returns a basedir in which files are searched for execution, if this is empty the current directory i...
JKQTEFileSelectToolButton::buddy
QLineEdit * buddy()
buddy associated with this button
JKQTEURLOpenToolButton::buddy
QLineEdit * buddy()
buddy associated with this button
JKQTEFileSelectToolButton::m_dlgTitle
QString m_dlgTitle
Definition: jkqtespecialtoolbutton.h:110
JKQTEXTRAS_LIB_EXPORT
#define JKQTEXTRAS_LIB_EXPORT
Definition: jkqtextras_imexport.h:95
JKQTEFileExecuteToolButton::m_baseDir
QString m_baseDir
Definition: jkqtespecialtoolbutton.h:195
JKQTEFileSelectToolButton::m_baseDir
QString m_baseDir
Definition: jkqtespecialtoolbutton.h:109
JKQTEFileSelectToolButton::~JKQTEFileSelectToolButton
virtual ~JKQTEFileSelectToolButton()
JKQTEDirectorySelectToolButton::getDialogTitle
QString getDialogTitle() const
returns the title label of the file select dialog
JKQTEDirectorySelectToolButton::~JKQTEDirectorySelectToolButton
virtual ~JKQTEDirectorySelectToolButton()
JKQTEDirectorySelectToolButton::m_dlgTitle
QString m_dlgTitle
Definition: jkqtespecialtoolbutton.h:152
JKQTEDirectorySelectToolButton
specialized QToolButton which allows to select a directory and saves its path in the buddy
Definition: jkqtespecialtoolbutton.h:124
JKQTEURLOpenToolButton::m_buddy
QLineEdit * m_buddy
Definition: jkqtespecialtoolbutton.h:65
JKQTEFileExecuteToolButton::getBaseDir
QString getBaseDir() const
returns a basedir in which files are searched for execution, if this is empty the current directory i...
JKQTEFileSelectToolButton::getDialogFilter
QString getDialogFilter() const
returns the file filter of the file select dialog
JKQTEFileSelectToolButton::buddy
const QLineEdit * buddy() const
buddy associated with this button
JKQTEURLOpenToolButton
specialized QToolButton which takes the contents of its buddy as webpage adress (URL) and opens it in...
Definition: jkqtespecialtoolbutton.h:44
JKQTEURLOpenToolButton::buddy
const QLineEdit * buddy() const
buddy associated with this button
JKQTEFileExecuteToolButton::m_buddy
QLineEdit * m_buddy
Definition: jkqtespecialtoolbutton.h:194
JKQTEDirectorySelectToolButton::setBaseDir
void setBaseDir(const QString &b)
set a basedir in which files are searched for execution, if this is empty the current directory is us...
JKQTEFileExecuteToolButton::~JKQTEFileExecuteToolButton
virtual ~JKQTEFileExecuteToolButton()
JKQTEDirectorySelectToolButton::openBuddyContents
void openBuddyContents()
JKQTEFileSelectToolButton::m_buddy
QLineEdit * m_buddy
Definition: jkqtespecialtoolbutton.h:108
JKQTEFileExecuteToolButton::buddy
QLineEdit * buddy()
buddy associated with this button
JKQTEFileExecuteToolButton::setBuddy
void setBuddy(QLineEdit *b)
set the buddy widget, which provides the contents
JKQTEDirectorySelectToolButton::m_baseDir
QString m_baseDir
Definition: jkqtespecialtoolbutton.h:151
JKQTEFileExecuteToolButton
specialized QToolButton which allows to open the file referenced by the buddy edit
Definition: jkqtespecialtoolbutton.h:166
JKQTEFileSelectToolButton::setBuddy
void setBuddy(QLineEdit *b)
set the buddy widget, which provides the contents
JKQTEFileSelectToolButton::setDialogTitle
void setDialogTitle(const QString &b)
sets the title label of the file select dialog
JKQTEURLOpenToolButton::setBuddy
void setBuddy(QLineEdit *b)
set the buddy widget, which provides the contents
JKQTEURLOpenToolButton::JKQTEURLOpenToolButton
JKQTEURLOpenToolButton(QWidget *parent=nullptr)
JKQTEFileSelectToolButton::openBuddyContents
void openBuddyContents()
JKQTEFileSelectToolButton::JKQTEFileSelectToolButton
JKQTEFileSelectToolButton(QWidget *parent=nullptr)
JKQTEDirectorySelectToolButton::setBuddy
void setBuddy(QLineEdit *b)
set the buddy widget, which provides the contents