| 1 | /* | 
|---|---|
| 2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) | 
| 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 3 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 | #include "editorstabwidget.h" | 
| 18 | |
| 19 | #include <QDragEnterEvent> | 
| 20 | #include <QDropEvent> | 
| 21 | #include <QMimeData> | 
| 22 | #include "../editor.h" | 
| 23 | #include "../editorlist.h" | 
| 24 | #include "../mainwindow.h" | 
| 25 | |
| 26 | EditorsTabWidget::EditorsTabWidget(QWidget* parent):QTabWidget(parent) | 
| 27 | { | 
| 28 | setAcceptDrops(true); | 
| 29 | } | 
| 30 | |
| 31 | void EditorsTabWidget::dropEvent(QDropEvent *event) | 
| 32 | { | 
| 33 | if (event->mimeData()->hasUrls()) { | 
| 34 | QStringList files; | 
| 35 | foreach(const QUrl& url, event->mimeData()->urls()){ | 
| 36 | if (!url.isLocalFile()) | 
| 37 | continue; | 
| 38 | QString file = url.toLocalFile(); | 
| 39 | files.append(file); | 
| 40 | } | 
| 41 | pMainWindow->openFiles(files); | 
| 42 | } | 
| 43 | } | 
| 44 | |
| 45 | void EditorsTabWidget::dragEnterEvent(QDragEnterEvent *event) | 
| 46 | { | 
| 47 | if (event->mimeData()->hasUrls()){ | 
| 48 | event->acceptProposedAction(); | 
| 49 | } | 
| 50 | } | 
| 51 | |
| 52 | void EditorsTabWidget::mousePressEvent(QMouseEvent *event) | 
| 53 | { | 
| 54 | if (event->buttons() == Qt::MiddleButton) { | 
| 55 | int idx = this->tabBar()->tabAt(event->pos()); | 
| 56 | if (idx>=0) | 
| 57 | emit middleButtonClicked(idx); | 
| 58 | } | 
| 59 | QTabWidget::mousePressEvent(event); | 
| 60 | } | 
| 61 | 
