1 /************************************************************************
2 **
3 **  Copyright (C) 2012 John Schember <john@nachtimwald.com>
4 **  Copyright (C) 2012 Dave Heiland
5 **  Copyright (C) 2012 Grant Drake
6 **
7 **  This file is part of Sigil.
8 **
9 **  Sigil is free software: you can redistribute it and/or modify
10 **  it under the terms of the GNU General Public License as published by
11 **  the Free Software Foundation, either version 3 of the License, or
12 **  (at your option) any later version.
13 **
14 **  Sigil is distributed in the hope that it will be useful,
15 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 **  GNU General Public License for more details.
18 **
19 **  You should have received a copy of the GNU General Public License
20 **  along with Sigil.  If not, see <http://www.gnu.org/licenses/>.
21 **
22 *************************************************************************/
23 
24 #pragma once
25 #ifndef CLIPEDITOR_H
26 #define CLIPEDITOR_H
27 
28 #include <QtWidgets/QDialog>
29 #include <QtGui/QStandardItemModel>
30 #include <QtCore/QSharedPointer>
31 #include <QPointer>
32 
33 #include "Misc/SettingsStore.h"
34 #include "MiscEditors/ClipEditorModel.h"
35 #include "MiscEditors/ClipEditorTreeView.h"
36 #include "BookManipulation/Book.h"
37 
38 #include "ui_ClipEditor.h"
39 
40 /**
41  * The editor used to create and modify saved clip entries
42  */
43 class ClipEditor : public QDialog
44 {
45     Q_OBJECT
46 
47 public:
48     ClipEditor(QWidget *parent);
49     void ForceClose();
50     void SetBook(QSharedPointer <Book> book);
51 
52 public slots:
53     QStandardItem *AddEntry(bool is_group = false, ClipEditorModel::clipEntry *clip_entry = NULL, bool insert_after = true);
54 
55 signals:
56     void PasteSelectedClipRequest(QList<ClipEditorModel::clipEntry *> clip_entries);
57     void ShowStatusMessageRequest(const QString &message);
58     void ClipsUpdated();
59 
60 protected:
61     bool eventFilter(QObject *obj, QEvent *ev);
62 
63 protected slots:
64     void reject();
65     void showEvent(QShowEvent *event);
66 
67 private slots:
68     QStandardItem *AddGroup();
69     void Edit();
70     void Cut();
71     bool Copy();
72     void Paste();
73     void Delete();
74     void Import();
75     void Reload();
76     void Export();
77     void ExportAll();
78     void CollapseAll();
79     void ExpandAll();
80     void AutoFill();
81 
82     void Apply();
83     bool Save();
84 
85     void MoveUp();
86     void MoveDown();
87     void MoveLeft();
88     void MoveRight();
89 
90     void PasteIntoDocument();
91 
92     void FilterEditTextChangedSlot(const QString &text);
93 
94     void OpenContextMenu(const QPoint &point);
95 
96     void SettingsFileModelUpdated();
97 
98     void ModelItemDropped(const QModelIndex &index);
99 
100 private:
101     bool MaybeSaveDialogSaysProceed(bool is_forced);
102     void MoveVertical(bool move_down);
103     void MoveHorizontal(bool move_left);
104 
105     void ExportItems(QList<QStandardItem *> items);
106 
107     void SetupClipEditorTree();
108 
109     int SelectedRowsCount();
110     QList<ClipEditorModel::clipEntry *> GetSelectedEntries();
111 
112     QList<QStandardItem *> GetSelectedItems();
113 
114     bool ItemsAreUnique(QList<QStandardItem *> items);
115 
116     bool SaveData(QList<ClipEditorModel::clipEntry *> entries = QList<ClipEditorModel::clipEntry *>() , QString filename = QString());
117 
118     bool FilterEntries(const QString &text, QStandardItem *item = NULL);
119     bool SelectFirstVisibleNonGroup(QStandardItem *item);
120 
121     void ReadSettings();
122     void WriteSettings();
123 
124     void CreateContextMenuActions();
125     void SetupContextMenu(const QPoint &point);
126 
127     void ConnectSignalsSlots();
128 
129     QAction *m_AddEntry;
130     QAction *m_AddGroup;
131     QAction *m_Edit;
132     QAction *m_Cut;
133     QAction *m_Copy;
134     QAction *m_Paste;
135     QAction *m_Delete;
136     QAction *m_Import;
137     QAction *m_Reload;
138     QAction *m_Export;
139     QAction *m_ExportAll;
140     QAction *m_CollapseAll;
141     QAction *m_ExpandAll;
142     QAction *m_AutoFill;
143 
144     ClipEditorModel *m_ClipEditorModel;
145 
146     QSharedPointer<Book> m_Book;
147 
148     QString m_LastFolderOpen;
149 
150     QPointer<QMenu> m_ContextMenu;
151 
152     QList<ClipEditorModel::clipEntry *> m_SavedClipEntries;
153 
154     Ui::ClipEditor ui;
155 };
156 
157 #endif // CLIPEDITOR_H
158 
159