1 /*************************************************************************** 2 * Copyright (C) 2004-2018 by Thomas Fischer <fischer@unix-ag.uni-kl.de> * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (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 General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, see <https://www.gnu.org/licenses/>. * 16 ***************************************************************************/ 17 #ifndef KBIBTEX_GUI_FIELDLISTEDIT_H 18 #define KBIBTEX_GUI_FIELDLISTEDIT_H 19 20 #include <QWidget> 21 #include <QSet> 22 23 #include <KSharedConfig> 24 25 #include "kbibtex.h" 26 #include "value.h" 27 28 class QCheckBox; 29 class QDropEvent; 30 class QDragEnterEvent; 31 class QSignalMapper; 32 class QPushButton; 33 34 class KJob; 35 class KJob; 36 37 class Element; 38 class FieldLineEdit; 39 40 /** 41 * @author Thomas Fischer <fischer@unix-ag.uni-kl.de> 42 */ 43 class FieldListEdit : public QWidget 44 { 45 Q_OBJECT 46 47 public: 48 FieldListEdit(KBibTeX::TypeFlag preferredTypeFlag, KBibTeX::TypeFlags typeFlags, QWidget *parent = nullptr); 49 ~FieldListEdit() override; 50 51 virtual bool reset(const Value &value); 52 virtual bool apply(Value &value) const; 53 virtual bool validate(QWidget **widgetWithIssue, QString &message) const; 54 55 void clear(); 56 virtual void setReadOnly(bool isReadOnly); 57 virtual void setFile(const File *file); 58 virtual void setElement(const Element *element); 59 virtual void setFieldKey(const QString &fieldKey); 60 virtual void setCompletionItems(const QStringList &items); 61 62 signals: 63 void modified(); 64 65 protected: 66 /// Add a new field line edit to this list 67 /// Allows to get overwritten by descentants of this class 68 virtual FieldLineEdit *addFieldLineEdit(); 69 void addButton(QPushButton *button); 70 void lineAdd(Value *value); 71 void dragEnterEvent(QDragEnterEvent *event) override; 72 void dropEvent(QDropEvent *) override; 73 74 const Element *m_element; 75 76 private slots: 77 void lineAdd(); 78 void lineRemove(QWidget *widget); 79 void lineGoDown(QWidget *widget); 80 void lineGoUp(QWidget *widget); 81 82 protected: 83 class FieldListEditProtected; 84 FieldListEditProtected *d; 85 }; 86 87 88 /** 89 @author Thomas Fischer 90 */ 91 class PersonListEdit : public FieldListEdit 92 { 93 Q_OBJECT 94 95 public: 96 PersonListEdit(KBibTeX::TypeFlag preferredTypeFlag, KBibTeX::TypeFlags typeFlags, QWidget *parent = nullptr); 97 98 bool reset(const Value &value) override; 99 bool apply(Value &value) const override; 100 101 void setReadOnly(bool isReadOnly) override; 102 103 private slots: 104 void slotAddNamesFromClipboard(); 105 106 private: 107 QCheckBox *m_checkBoxOthers; 108 QPushButton *m_buttonAddNamesFromClipboard; 109 }; 110 111 112 /** 113 @author Thomas Fischer 114 */ 115 class UrlListEdit : public FieldListEdit 116 { 117 Q_OBJECT 118 119 public: 120 explicit UrlListEdit(QWidget *parent = nullptr); 121 122 void setReadOnly(bool isReadOnly) override; 123 124 static QString askRelativeOrStaticFilename(QWidget *parent, const QString &filename, const QUrl &baseUrl); 125 126 /// Own function as QUrl's isLocalFile is not reliable 127 static bool urlIsLocal(const QUrl &url); 128 129 protected: 130 FieldLineEdit *addFieldLineEdit() override; 131 132 private slots: 133 void slotAddReference(); 134 void slotAddReferenceFromClipboard(); 135 /// Slot for events where the "save locally" button is triggered 136 void slotSaveLocally(QWidget *widget); 137 void downloadFinished(KJob *); 138 /// Catch events where the line edit's text change 139 void textChanged(QWidget *widget); 140 141 private: 142 QPushButton *m_buttonAddFile; 143 QSignalMapper *m_signalMapperSaveLocallyButtonClicked; 144 QSignalMapper *m_signalMapperFieldLineEditTextChanged; 145 146 void addReference(const QUrl &url); 147 }; 148 149 150 /** 151 @author Thomas Fischer 152 */ 153 class KeywordListEdit : public FieldListEdit 154 { 155 Q_OBJECT 156 157 public: 158 static const QString keyGlobalKeywordList; 159 160 explicit KeywordListEdit(QWidget *parent = nullptr); 161 162 void setReadOnly(bool isReadOnly) override; 163 void setFile(const File *file) override; 164 void setCompletionItems(const QStringList &items) override; 165 166 private slots: 167 void slotAddKeywordsFromList(); 168 void slotAddKeywordsFromClipboard(); 169 170 private: 171 KSharedConfigPtr m_config; 172 const QString m_configGroupName; 173 QPushButton *m_buttonAddKeywordsFromList, *m_buttonAddKeywordsFromClipboard; 174 QSet<QString> m_keywordsFromFile; 175 }; 176 177 #endif // KBIBTEX_GUI_FIELDLISTEDIT_H 178