File indexing completed on 2024-04-28 17:06:04
0001 /* 0002 SPDX-FileCopyrightText: 2000 Shie Erlich <krusader@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2000 Rafi Yanai <krusader@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef KCMDLINE_H 0010 #define KCMDLINE_H 0011 0012 // QtGui 0013 #include <QKeyEvent> 0014 // QtWidgets 0015 #include <QLabel> 0016 #include <QLayout> 0017 #include <QToolButton> 0018 #include <QWidget> 0019 0020 #include <KCompletion/KLineEdit> 0021 #include <KIOWidgets/KShellCompletion> 0022 0023 #include "../GUI/krhistorycombobox.h" 0024 #include "../UserAction/kractionbase.h" 0025 0026 class KCMDModeButton; 0027 0028 class CmdLineCombo : public KrHistoryComboBox 0029 { 0030 Q_OBJECT 0031 public: 0032 explicit CmdLineCombo(QWidget *parent); 0033 0034 bool eventFilter(QObject *watched, QEvent *e) override; 0035 0036 QString path() 0037 { 0038 return _path; 0039 } 0040 void setPath(QString path); 0041 0042 signals: 0043 void returnToPanel(); 0044 0045 protected slots: 0046 void doLayout(); 0047 0048 protected: 0049 void resizeEvent(QResizeEvent *e) override; 0050 void keyPressEvent(QKeyEvent *e) override; 0051 0052 void updateLineEditGeometry(); 0053 0054 QLabel *_pathLabel; 0055 QString _path; 0056 bool _handlingLineEditResize; 0057 }; 0058 0059 class KCMDLine : public QWidget, KrActionBase 0060 { 0061 Q_OBJECT 0062 public: 0063 explicit KCMDLine(QWidget *parent = nullptr); 0064 ~KCMDLine() override; 0065 void setCurrent(const QString &path); 0066 // virtual methods from KrActionBase 0067 void setText(const QString &text); 0068 QString command() const override; 0069 ExecType execType() const override; 0070 QString startpath() const override; 0071 QString user() const override; 0072 QString text() const override; 0073 bool acceptURLs() const override; 0074 bool confirmExecution() const override; 0075 bool doSubstitution() const override; 0076 0077 signals: 0078 void signalRun(); 0079 0080 public slots: 0081 void slotReturnFocus(); // returns keyboard focus to panel 0082 void slotRun(); 0083 void addPlaceholder(); 0084 void addText(const QString &text) 0085 { 0086 cmdLine->lineEdit()->setText(cmdLine->lineEdit()->text() + text); 0087 } 0088 void popup() 0089 { 0090 cmdLine->showPopup(); 0091 } 0092 0093 protected: 0094 void focusInEvent(QFocusEvent *) override 0095 { 0096 cmdLine->setFocus(); 0097 } 0098 0099 void calcLabelSize(); 0100 0101 private: 0102 CmdLineCombo *cmdLine; 0103 KCMDModeButton *terminal; 0104 QToolButton *buttonAddPlaceholder; 0105 KShellCompletion completion; 0106 }; 0107 0108 #endif