File indexing completed on 2024-12-22 04:40:14

0001 /*
0002     SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
0003     SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "scripting_rangesmodule.h"
0009 
0010 #include "appglobal.h"
0011 #include "application.h"
0012 #include "gui/treeview/lineswidget.h"
0013 #include "scripting/scripting_rangelist.h"
0014 #include "scripting/scripting_range.h"
0015 
0016 using namespace SubtitleComposer;
0017 
0018 Scripting::RangesModule::RangesModule(QObject *parent) :
0019     QObject(parent)
0020 {}
0021 
0022 QObject *
0023 Scripting::RangesModule::newRange(int firstIndex, int lastIndex)
0024 {
0025     if(firstIndex > lastIndex || firstIndex < 0 || lastIndex < 0)
0026         return 0;
0027     return new Scripting::Range(SubtitleComposer::Range(firstIndex, lastIndex), this);
0028 }
0029 
0030 QObject *
0031 Scripting::RangesModule::newLowerRange(int index)
0032 {
0033     return new Scripting::Range(SubtitleComposer::Range::lower(index), this);
0034 }
0035 
0036 QObject *
0037 Scripting::RangesModule::newUpperRange(int index)
0038 {
0039     return new Scripting::Range(SubtitleComposer::Range::upper(index), this);
0040 }
0041 
0042 QObject *
0043 Scripting::RangesModule::newUptoLastSelectedRange()
0044 {
0045     int index = app()->linesWidget()->lastSelectedIndex();
0046     return index < 0 ? 0 : new Scripting::Range(SubtitleComposer::Range::lower(index), this);
0047 }
0048 
0049 QObject *
0050 Scripting::RangesModule::newFromFirstSelectedRange()
0051 {
0052     int index = app()->linesWidget()->firstSelectedIndex();
0053     return index < 0 ? 0 : new Scripting::Range(SubtitleComposer::Range::upper(index), this);
0054 }
0055 
0056 QObject *
0057 Scripting::RangesModule::newEmptyRangeList()
0058 {
0059     return new Scripting::RangeList(SubtitleComposer::RangeList(), this);
0060 }
0061 
0062 QObject *
0063 Scripting::RangesModule::newSelectionRangeList()
0064 {
0065     return new Scripting::RangeList(app()->linesWidget()->selectionRanges(), this);
0066 }
0067 
0068