1 /* 2 SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar> 3 SPDX-FileCopyrightText: 2010-2020 Mladen Milinkovic <max@smoothware.net> 4 5 SPDX-License-Identifier: GPL-2.0-or-later 6 */ 7 8 #ifndef LINESWIDGET_H 9 #define LINESWIDGET_H 10 11 #include "core/subtitle.h" 12 #include "gui/treeview/linesmodel.h" 13 #include "gui/treeview/treeview.h" 14 15 #include <QPen> 16 17 namespace SubtitleComposer { 18 class LinesItemDelegate; 19 20 class LinesWidget : public TreeView 21 { 22 Q_OBJECT 23 24 public: 25 explicit LinesWidget(QWidget *parent); 26 virtual ~LinesWidget(); 27 28 bool showingContextMenu(); 29 30 SubtitleLine * currentLine() const; 31 int currentLineIndex() const; 32 33 int firstSelectedIndex() const; 34 int lastSelectedIndex() const; 35 bool selectionHasMultipleRanges() const; 36 RangeList selectionRanges() const; 37 RangeList targetRanges(int target) const; 38 model()39 inline LinesModel * model() const { return static_cast<LinesModel *>(TreeView::model()); } scrollFollowsModel()40 inline bool scrollFollowsModel() const { return m_scrollFollowsModel; } 41 isEditing()42 inline bool isEditing() { return m_inlineEditor != nullptr; } 43 44 void loadConfig(); 45 void saveConfig(); 46 47 bool eventFilter(QObject *object, QEvent *event) override; 48 49 public slots: 50 void setSubtitle(Subtitle *subtitle = 0); 51 void setTranslationMode(bool enabled); 52 53 void setCurrentLine(SubtitleLine *line, bool clearSelection = true); 54 void setPlayingLine(SubtitleLine *line); 55 56 void editCurrentLineInPlace(bool primaryText = true); 57 58 signals: 59 void currentLineChanged(SubtitleLine *line); 60 void lineDoubleClicked(SubtitleLine *line); 61 62 protected slots: 63 void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint) override; 64 65 private: 66 void contextMenuEvent(QContextMenuEvent *e) override; 67 void mouseDoubleClickEvent(QMouseEvent *e) override; 68 69 static void drawHorizontalDotLine(QPainter *painter, int x1, int x2, int y); 70 static void drawVerticalDotLine(QPainter *painter, int x, int y1, int y2); 71 void updateHeader(); 72 73 void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 74 75 private slots: 76 void onCurrentRowChanged(); 77 78 private: 79 bool m_scrollFollowsModel; 80 bool m_translationMode; 81 bool m_showingContextMenu; 82 QPen m_gridPen; 83 84 LinesItemDelegate *m_itemsDelegate; 85 QWidget *m_inlineEditor; 86 87 friend class LinesWidgetScrollToModelDetacher; 88 friend class LinesModel; 89 friend class LinesItemDelegate; 90 }; 91 92 class LinesWidgetScrollToModelDetacher 93 { 94 public: LinesWidgetScrollToModelDetacher(LinesWidget & w)95 inline LinesWidgetScrollToModelDetacher(LinesWidget &w) : m_linesWidget(w) { m_linesWidget.m_scrollFollowsModel = false; } ~LinesWidgetScrollToModelDetacher()96 inline ~LinesWidgetScrollToModelDetacher() { m_linesWidget.m_scrollFollowsModel = true; } 97 98 private: 99 LinesWidget &m_linesWidget; 100 }; 101 } 102 #endif 103