aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/DnDTabBar.h65
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/MainUI.cpp26
-rw-r--r--src-qt5/desktop-utils/lumina-textedit/MainUI.h5
3 files changed, 76 insertions, 20 deletions
diff --git a/src-qt5/desktop-utils/lumina-textedit/DnDTabBar.h b/src-qt5/desktop-utils/lumina-textedit/DnDTabBar.h
index b5150b84..f415d6c5 100644
--- a/src-qt5/desktop-utils/lumina-textedit/DnDTabBar.h
+++ b/src-qt5/desktop-utils/lumina-textedit/DnDTabBar.h
@@ -21,25 +21,27 @@
class DnDTabBar : public QTabBar{
Q_OBJECT
signals:
- /*void DetachTab(int); //
- void DroppedIn(QString); //The "whatsThis()" field on some other DnDTabBar tab
- void DraggedOut(QString); //The "whatsThis()" field on *this* DnDTabBar tab*/
+ void DetachTab(int); //
+ void DroppedIn(QStringList); //The full path of some file(s)
+ void DraggedOut(int, Qt::DropAction); //The tab number dragged/accepted by another app, and which action was accepted
private:
- //QMenu *tabMenu;
- //int selTab;
+ QMenu *tabMenu;
+ int selTab;
+ bool dragging;
private slots:
- /*void slotDetachTab(){
- qDebug() << "Detach Tab:" << selTab;
+ void slotDetachTab(){
+ //qDebug() << "Detach Tab:" << selTab;
if(selTab>=0){ emit DetachTab(selTab); }
- }*/
+ }
public:
DnDTabBar(QWidget *parent) : QTabBar(parent){
- //this->setAcceptDrops(true);
- //selTab = -1;
- //tabMenu = new QMenu(this);
- //tabMenu->addAction(tr("Detach Tab"), this, SLOT(slotDetachTab()) );
+ this->setAcceptDrops(true);
+ selTab = -1;
+ tabMenu = new QMenu(this);
+ tabMenu->addAction(tr("Detach Tab"), this, SLOT(slotDetachTab()) );
+ dragging = false;
}
~DnDTabBar(){
@@ -48,7 +50,7 @@ public:
protected:
- /*virtual void mousePressEvent(QMouseEvent *ev){
+ virtual void mousePressEvent(QMouseEvent *ev){
if(ev->button() == Qt::RightButton){
int tab = this->tabAt(ev->pos());
if(tab>=0){
@@ -63,8 +65,10 @@ protected:
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setUrls(QList<QUrl>() << QUrl::fromLocalFile(this->tabWhatsThis(tab)));
+ //qDebug() << "Start Drag:" << this->tabWhatsThis(tab);
drag->setMimeData(mimeData);
- Qt::DropAction dropAction = drag->exec();
+ Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
+ this->emit DraggedOut(tab, dropAction);
}else{
QTabBar::mousePressEvent(ev);
}
@@ -73,13 +77,36 @@ protected:
}
}
- virtual void mouseReleaseEvent(QMouseEvent *ev){
-
+ virtual void dragEnterEvent(QDragEnterEvent *ev){
+ //qDebug() << "Got Drag Enter Event:" << ev->mimeData()->hasUrls();
+ if(ev->mimeData()->hasUrls() && ev->source()!=this){
+ ev->acceptProposedAction();
+ }
}
- virtual void mouseMoveEvent(QMouseEvent *ev){
+ virtual void dragMoveEvent(QDragMoveEvent *ev){
+ //qDebug() << "Got Drag Move Event:" << ev->mimeData()->hasUrls();
+ if(ev->mimeData()->hasUrls() && ev->source()!=this){
+ ev->accept();
+ }
+ }
- }*/
+ virtual void dropEvent(QDropEvent *ev){
+ //qDebug() << "Got Drop Event:" << ev->mimeData()->hasUrls();
+ if(ev->mimeData()->hasUrls() && ev->source()!=this){
+ QStringList files;
+ for(int i=0; i<ev->mimeData()->urls().length(); i++){
+ QString path = ev->mimeData()->urls().at(i).toLocalFile();
+ if(QFile::exists(path)){ files << path; }
+ }
+ //qDebug() << "[DROP] URLS:" << ev->mimeData()->urls() << "Files:" << files;
+ if(!files.isEmpty() && (ev->proposedAction()==Qt::CopyAction || ev->proposedAction()==Qt::MoveAction)){
+ ev->setDropAction(Qt::MoveAction);
+ ev->accept();
+ this->emit DroppedIn(files);
+ }
+ }
+ }
};
class DnDTabWidget : public QTabWidget{
@@ -90,6 +117,8 @@ public:
DnDTabWidget(QWidget *parent) : QTabWidget(parent){
TB = new DnDTabBar(this);
this->setTabBar(TB);
+ this->setTabsClosable(true);
+ this->setMovable(true);
}
~DnDTabWidget(){}
diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp
index 1dbc4c1f..a44e16bb 100644
--- a/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp
+++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.cpp
@@ -85,6 +85,9 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){
connect(ui->menuSyntax_Highlighting, SIGNAL(triggered(QAction*)), this, SLOT(UpdateHighlighting(QAction*)) );
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged()) );
connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(tabClosed(int)) );
+ connect(tabWidget->dndTabBar(), SIGNAL(DetachTab(int)), this, SLOT(tabDetached(int)) );
+ connect(tabWidget->dndTabBar(), SIGNAL(DroppedIn(QStringList)), this, SLOT(LoadArguments(QStringList)) );
+ connect(tabWidget->dndTabBar(), SIGNAL(DraggedOut(int, Qt::DropAction)), this, SLOT(tabDraggedOut(int, Qt::DropAction)) );
connect(ui->actionLine_Numbers, SIGNAL(toggled(bool)), this, SLOT(showLineNumbers(bool)) );
connect(ui->actionWrap_Lines, SIGNAL(toggled(bool)), this, SLOT(wrapLines(bool)) );
connect(ui->actionShow_Popups, SIGNAL(toggled(bool)), this, SLOT(showPopupWarnings(bool)) );
@@ -101,6 +104,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){
connect(colorDLG, SIGNAL(colorsChanged()), this, SLOT(UpdateHighlighting()) );
connect(fontbox, SIGNAL(currentFontChanged(const QFont&)), this, SLOT(fontChanged(const QFont&)) );
connect(fontSizes, SIGNAL(valueChanged(int)), this, SLOT(changeFontSize(int)));
+
updateIcons();
//Now load the initial size of the window
QSize lastSize = settings->value("lastSize",QSize()).toSize();
@@ -318,6 +322,7 @@ void MainUI::updateTab(QString file){
//qDebug() << "Update Tab:" << file << cur << changes;
tabWidget->setTabText(index,(changes ? "*" : "") + file.section("/",-1));
tabWidget->setTabToolTip(index, file);
+ tabWidget->setTabWhatsThis(index, file); //needed for drag/drop functionality
ui->actionSave_File->setEnabled(changes);
this->setWindowTitle( (changes ? "*" : "") + file.section("/",-2) );
}
@@ -345,6 +350,27 @@ void MainUI::tabClosed(int tab){
edit->deleteLater();
}
+void MainUI::tabDetached(int tab){
+ PlainTextEditor *edit = static_cast<PlainTextEditor*>(tabWidget->widget(tab));
+ if(edit==0){ return; } //should never happen
+ if(edit->hasChange() && ui->actionShow_Popups->isChecked() ){
+ //Verify if the user wants to lose any unsaved changes
+ if(QMessageBox::Yes != QMessageBox::question(this, tr("Lose Unsaved Changes?"), QString(tr("This file has unsaved changes.\nDo you want to close it anyway?\n\n%1")).arg(edit->currentFile()), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){ return; }
+ }
+ //Launch this file with a new LTE process
+ QProcess::startDetached("lumina-textedit \""+edit->currentFile()+"\"");
+ tabWidget->removeTab(tab);
+ edit->deleteLater();
+}
+
+void MainUI::tabDraggedOut(int tab, Qt::DropAction act){
+ qDebug() << "Tab Dragged Out:" << tab << act;
+ if(act == Qt::MoveAction){
+ tabClosed(tab);
+ if(tabWidget->count()==0){ this->close(); } //merging two windows together?
+ }
+}
+
//Find/Replace functions
void MainUI::closeFindReplace(){
ui->groupReplace->setVisible(false);
diff --git a/src-qt5/desktop-utils/lumina-textedit/MainUI.h b/src-qt5/desktop-utils/lumina-textedit/MainUI.h
index e3e4c9fc..845a4a19 100644
--- a/src-qt5/desktop-utils/lumina-textedit/MainUI.h
+++ b/src-qt5/desktop-utils/lumina-textedit/MainUI.h
@@ -28,9 +28,8 @@ public:
MainUI();
~MainUI();
- void LoadArguments(QStringList args); //CLI arguments
-
public slots:
+ void LoadArguments(QStringList args); //CLI arguments
void updateIcons();
private:
@@ -69,6 +68,8 @@ private slots:
void updateTab(QString);
void tabChanged();
void tabClosed(int);
+ void tabDetached(int);
+ void tabDraggedOut(int, Qt::DropAction);
//Find/Replace functions
void closeFindReplace();
bgstack15