From 9937ef50c3be0ec76ba42f15231133901974ab43 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Sat, 23 Oct 2021 23:10:34 +0800 Subject: [PATCH] - enhancement: icons in project view - fix: sometimes option widget will show confirm dialog even not changed - enhancement: only editor area will receive file drop events --- NEWS.md | 3 + RedPandaIDE/RedPandaIDE.pro | 2 + RedPandaIDE/iconsmanager.cpp | 15 +++-- RedPandaIDE/iconsmanager.h | 11 ++-- RedPandaIDE/mainwindow.cpp | 57 +++++++++---------- RedPandaIDE/mainwindow.h | 9 +-- RedPandaIDE/mainwindow.ui | 21 ++++++- RedPandaIDE/project.cpp | 31 +++++++++- RedPandaIDE/project.h | 5 ++ RedPandaIDE/settingsdialog/settingswidget.cpp | 1 + RedPandaIDE/widgets/editorstabwidget.cpp | 41 +++++++++++++ RedPandaIDE/widgets/editorstabwidget.h | 21 +++++++ 12 files changed, 171 insertions(+), 46 deletions(-) create mode 100644 RedPandaIDE/widgets/editorstabwidget.cpp create mode 100644 RedPandaIDE/widgets/editorstabwidget.h diff --git a/NEWS.md b/NEWS.md index 88a8579a..3dfdf846 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,9 @@ Version 0.7.2 - fix: issue count not correctly displayed when syntax check/compile finished - fix: function declaration's parameters not correctly parsed, if it have a definition which have different parameter names - fix: file path seperator used in the app is not unified, and cause errors somtimes. + - enhancement: icons in project view + - fix: sometimes option widget will show confirm dialog even not changed + - enhancement: only editor area will receive file drop events Version 0.7.1 - fix: can't add bookmark at a breakpoint line diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 48df120f..31a2daf9 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -113,6 +113,7 @@ SOURCES += \ widgets/consolewidget.cpp \ widgets/custommakefileinfodialog.cpp \ widgets/darkfusionstyle.cpp \ + widgets/editorstabwidget.cpp \ widgets/filepropertiesdialog.cpp \ widgets/functiontooltipwidget.cpp \ widgets/headercompletionpopup.cpp \ @@ -227,6 +228,7 @@ HEADERS += \ widgets/consolewidget.h \ widgets/custommakefileinfodialog.h \ widgets/darkfusionstyle.h \ + widgets/editorstabwidget.h \ widgets/filepropertiesdialog.h \ widgets/functiontooltipwidget.h \ widgets/headercompletionpopup.h \ diff --git a/RedPandaIDE/iconsmanager.cpp b/RedPandaIDE/iconsmanager.cpp index 52f4f8bb..000c1a18 100644 --- a/RedPandaIDE/iconsmanager.cpp +++ b/RedPandaIDE/iconsmanager.cpp @@ -9,25 +9,25 @@ IconsManager::IconsManager(QObject *parent) : QObject(parent) mBreakpoint = std::make_shared(":/icons/images/editor/breakpoint.png"); mActiveBreakpoint = std::make_shared(":/icons/images/editor/currentline.png"); mBookmark = std::make_shared(":/icons/images/editor/bookmark.png"); - + mFolder = std::make_shared(":/icons/images/newlook24/090-explorer.png"); } -PIcon IconsManager::syntaxError() const +const PIcon &IconsManager::syntaxError() const { return mSyntaxError; } -PIcon IconsManager::syntaxWarning() const +const PIcon &IconsManager::syntaxWarning() const { return mSyntaxWarning; } -PIcon IconsManager::breakpoint() const +const PIcon &IconsManager::breakpoint() const { return mBreakpoint; } -PIcon IconsManager::activeBreakpoint() const +const PIcon &IconsManager::activeBreakpoint() const { return mActiveBreakpoint; } @@ -36,3 +36,8 @@ const PIcon &IconsManager::bookmark() const { return mBookmark; } + +const PIcon &IconsManager::folder() const +{ + return mFolder; +} diff --git a/RedPandaIDE/iconsmanager.h b/RedPandaIDE/iconsmanager.h index 5a84f44c..b807957c 100644 --- a/RedPandaIDE/iconsmanager.h +++ b/RedPandaIDE/iconsmanager.h @@ -12,16 +12,18 @@ class IconsManager : public QObject public: explicit IconsManager(QObject *parent = nullptr); - PIcon syntaxError() const; + const PIcon &syntaxError() const; - PIcon syntaxWarning() const; + const PIcon &syntaxWarning() const; - PIcon breakpoint() const; + const PIcon &breakpoint() const; - PIcon activeBreakpoint() const; + const PIcon &activeBreakpoint() const; const PIcon &bookmark() const; + const PIcon &folder() const; + signals: private: PIcon mSyntaxError; @@ -29,6 +31,7 @@ private: PIcon mBreakpoint; PIcon mActiveBreakpoint; PIcon mBookmark; + PIcon mFolder; }; extern IconsManager* pIconsManager; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 69483b94..070df811 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -72,7 +72,6 @@ MainWindow::MainWindow(QWidget *parent) ui->splitterEditorPanel, ui->EditorPanel); mProject = nullptr; - setAcceptDrops(true); setupActions(); ui->EditorTabsRight->setVisible(false); @@ -815,7 +814,7 @@ void MainWindow::openFiles(const QStringList &files) mEditorList->endUpdate(); } -void MainWindow::openFile(const QString &filename) +void MainWindow::openFile(const QString &filename, QTabWidget* page) { Editor* editor = mEditorList->getOpenedEditorByFilename(filename); if (editor!=nullptr) { @@ -825,7 +824,7 @@ void MainWindow::openFile(const QString &filename) try { pSettings->history().removeFile(filename); editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT, - false,false); + false, false, page); editor->activate(); this->updateForEncodingInfo(); } catch (FileError e) { @@ -2955,33 +2954,33 @@ void MainWindow::showEvent(QShowEvent *) } } -void MainWindow::dragEnterEvent(QDragEnterEvent *event) -{ - if (event->mimeData()->hasUrls()){ - event->acceptProposedAction(); - } -} +//void MainWindow::dragEnterEvent(QDragEnterEvent *event) +//{ +// if (event->mimeData()->hasUrls()){ +// event->acceptProposedAction(); +// } +//} -void MainWindow::dropEvent(QDropEvent *event) -{ - if (event->mimeData()->hasUrls()) { - foreach(const QUrl& url, event->mimeData()->urls()){ - if (!url.isLocalFile()) - continue; - QString file = url.toLocalFile(); - if (getFileType(file)==FileType::Project) { - openProject(file); - return; - } - } - foreach(const QUrl& url, event->mimeData()->urls()){ - if (!url.isLocalFile()) - continue; - QString file = url.toLocalFile(); - openFile(file); - } - } -} +//void MainWindow::dropEvent(QDropEvent *event) +//{ +// if (event->mimeData()->hasUrls()) { +// foreach(const QUrl& url, event->mimeData()->urls()){ +// if (!url.isLocalFile()) +// continue; +// QString file = url.toLocalFile(); +// if (getFileType(file)==FileType::Project) { +// openProject(file); +// return; +// } +// } +// foreach(const QUrl& url, event->mimeData()->urls()){ +// if (!url.isLocalFile()) +// continue; +// QString file = url.toLocalFile(); +// openFile(file); +// } +// } +//} void MainWindow::on_actionSave_triggered() { diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index b34e34e3..5c3bcaa2 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -141,6 +141,9 @@ public: const PBookmarkModel &bookmarkModel() const; + void openFile(const QString& filename, QTabWidget* page=nullptr); + void openProject(const QString& filename); + public slots: void onCompileLog(const QString& msg); void onCompileIssue(PCompileIssue issue); @@ -173,8 +176,6 @@ private: void prepareProjectForCompile(); void closeProject(bool refreshEditor); void updateProjectView(); - void openFile(const QString& filename); - void openProject(const QString& filename); CompileTarget getCompileTarget(); bool debugInferiorhasBreakpoint(); void setupActions(); @@ -536,8 +537,8 @@ private: protected: void closeEvent(QCloseEvent *event) override; void showEvent(QShowEvent* event) override; - void dragEnterEvent(QDragEnterEvent *event) override; - void dropEvent(QDropEvent *event) override; +// void dragEnterEvent(QDragEnterEvent *event) override; +// void dropEvent(QDropEvent *event) override; }; extern MainWindow* pMainWindow; diff --git a/RedPandaIDE/mainwindow.ui b/RedPandaIDE/mainwindow.ui index 85c43ccf..97f331be 100644 --- a/RedPandaIDE/mainwindow.ui +++ b/RedPandaIDE/mainwindow.ui @@ -85,7 +85,7 @@ QTabWidget::West - 3 + 0 true @@ -116,6 +116,15 @@ QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked + + true + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + QAbstractItemView::ExtendedSelection @@ -288,7 +297,7 @@ 1 - + 0 @@ -308,7 +317,7 @@ true - + true @@ -2017,6 +2026,12 @@
widgets/qconsole.h
1 + + EditorsTabWidget + QTabWidget +
widgets/editorstabwidget.h
+ 1 +
diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index c3736303..b028af53 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -9,6 +9,7 @@ #include "platform.h" #include "projecttemplate.h" #include "systemconsts.h" +#include "iconsmanager.h" #include #include @@ -16,6 +17,7 @@ #include #include #include +#include #include "settings.h" #include @@ -1813,6 +1815,16 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const return QVariant(); if (role == Qt::DisplayRole || role==Qt::EditRole) { return p->text; + } else if (role == Qt::DecorationRole) { + QFileIconProvider provider; + if (p->unitIndex>=0) { + return provider.icon(mProject->units()[p->unitIndex]->fileName()); + } else { + QIcon icon = provider.icon(QFileIconProvider::Folder); + if (icon.isNull()) + return *(pIconsManager->folder()); + return icon; + } } return QVariant(); } @@ -1826,7 +1838,10 @@ Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const return Qt::NoItemFlags; if (p==mProject->node().get()) return Qt::ItemIsEnabled; - return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable; + Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled; + if (p->unitIndex<0) + flags.setFlag(Qt::ItemIsDropEnabled); + return flags; } bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int role) @@ -1922,3 +1937,17 @@ bool ProjectModel::setData(const QModelIndex &index, const QVariant &value, int } return false; } + +bool ProjectModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const +{ + if (action != Qt::MoveAction) + return false; + QModelIndex idx = index(row,column,parent); + if (!idx.isValid()) + return false; + FolderNode* p = static_cast(idx.internalPointer()); + PFolderNode node = mProject->pointerToNode(p); + if (node->unitIndex>=0) + return false; + return true; +} diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index e83bb8d2..dbca4ed4 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -96,6 +96,11 @@ public: QVariant data(const QModelIndex &index, int role) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; + + + // QAbstractItemModel interface +public: + bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override; }; class ProjectTemplate; diff --git a/RedPandaIDE/settingsdialog/settingswidget.cpp b/RedPandaIDE/settingsdialog/settingswidget.cpp index 1375594d..04ca5ad7 100644 --- a/RedPandaIDE/settingsdialog/settingswidget.cpp +++ b/RedPandaIDE/settingsdialog/settingswidget.cpp @@ -15,6 +15,7 @@ SettingsWidget::SettingsWidget(const QString &name, const QString &group, QWidget *parent): QWidget(parent), + mSettingsChanged(false), mName(name), mGroup(group) { diff --git a/RedPandaIDE/widgets/editorstabwidget.cpp b/RedPandaIDE/widgets/editorstabwidget.cpp new file mode 100644 index 00000000..7476cd63 --- /dev/null +++ b/RedPandaIDE/widgets/editorstabwidget.cpp @@ -0,0 +1,41 @@ +#include "editorstabwidget.h" + +#include +#include +#include +#include "../editor.h" +#include "../editorlist.h" +#include "../mainwindow.h" + +EditorsTabWidget::EditorsTabWidget(QWidget* parent):QTabWidget(parent) +{ + setAcceptDrops(true); +} + +void EditorsTabWidget::dropEvent(QDropEvent *event) +{ + if (event->mimeData()->hasUrls()) { + foreach(const QUrl& url, event->mimeData()->urls()){ + if (!url.isLocalFile()) + continue; + QString file = url.toLocalFile(); + if (getFileType(file)==FileType::Project) { + pMainWindow->openProject(file); + return; + } + } + foreach(const QUrl& url, event->mimeData()->urls()){ + if (!url.isLocalFile()) + continue; + QString file = url.toLocalFile(); + pMainWindow->openFile(file,this); + } + } +} + +void EditorsTabWidget::dragEnterEvent(QDragEnterEvent *event) +{ + if (event->mimeData()->hasUrls()){ + event->acceptProposedAction(); + } +} diff --git a/RedPandaIDE/widgets/editorstabwidget.h b/RedPandaIDE/widgets/editorstabwidget.h new file mode 100644 index 00000000..9e5bf19d --- /dev/null +++ b/RedPandaIDE/widgets/editorstabwidget.h @@ -0,0 +1,21 @@ +#ifndef EDITORSTABWIDGET_H +#define EDITORSTABWIDGET_H + +#include + +class QDragEnterEvent; +class QDropEvent; + +class EditorsTabWidget : public QTabWidget +{ + Q_OBJECT +public: + explicit EditorsTabWidget(QWidget* parent=nullptr); + + // QWidget interface +protected: + void dropEvent(QDropEvent *event) override; + void dragEnterEvent(QDragEnterEvent *event) override; +}; + +#endif // EDITORSTABWIDGET_H