- 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
This commit is contained in:
royqh1979 2021-10-23 23:10:34 +08:00
parent aebcce0b05
commit 9937ef50c3
12 changed files with 171 additions and 46 deletions

View File

@ -3,6 +3,9 @@ Version 0.7.2
- fix: issue count not correctly displayed when syntax check/compile finished - 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: 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. - 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 Version 0.7.1
- fix: can't add bookmark at a breakpoint line - fix: can't add bookmark at a breakpoint line

View File

@ -113,6 +113,7 @@ SOURCES += \
widgets/consolewidget.cpp \ widgets/consolewidget.cpp \
widgets/custommakefileinfodialog.cpp \ widgets/custommakefileinfodialog.cpp \
widgets/darkfusionstyle.cpp \ widgets/darkfusionstyle.cpp \
widgets/editorstabwidget.cpp \
widgets/filepropertiesdialog.cpp \ widgets/filepropertiesdialog.cpp \
widgets/functiontooltipwidget.cpp \ widgets/functiontooltipwidget.cpp \
widgets/headercompletionpopup.cpp \ widgets/headercompletionpopup.cpp \
@ -227,6 +228,7 @@ HEADERS += \
widgets/consolewidget.h \ widgets/consolewidget.h \
widgets/custommakefileinfodialog.h \ widgets/custommakefileinfodialog.h \
widgets/darkfusionstyle.h \ widgets/darkfusionstyle.h \
widgets/editorstabwidget.h \
widgets/filepropertiesdialog.h \ widgets/filepropertiesdialog.h \
widgets/functiontooltipwidget.h \ widgets/functiontooltipwidget.h \
widgets/headercompletionpopup.h \ widgets/headercompletionpopup.h \

View File

@ -9,25 +9,25 @@ IconsManager::IconsManager(QObject *parent) : QObject(parent)
mBreakpoint = std::make_shared<QPixmap>(":/icons/images/editor/breakpoint.png"); mBreakpoint = std::make_shared<QPixmap>(":/icons/images/editor/breakpoint.png");
mActiveBreakpoint = std::make_shared<QPixmap>(":/icons/images/editor/currentline.png"); mActiveBreakpoint = std::make_shared<QPixmap>(":/icons/images/editor/currentline.png");
mBookmark = std::make_shared<QPixmap>(":/icons/images/editor/bookmark.png"); mBookmark = std::make_shared<QPixmap>(":/icons/images/editor/bookmark.png");
mFolder = std::make_shared<QPixmap>(":/icons/images/newlook24/090-explorer.png");
} }
PIcon IconsManager::syntaxError() const const PIcon &IconsManager::syntaxError() const
{ {
return mSyntaxError; return mSyntaxError;
} }
PIcon IconsManager::syntaxWarning() const const PIcon &IconsManager::syntaxWarning() const
{ {
return mSyntaxWarning; return mSyntaxWarning;
} }
PIcon IconsManager::breakpoint() const const PIcon &IconsManager::breakpoint() const
{ {
return mBreakpoint; return mBreakpoint;
} }
PIcon IconsManager::activeBreakpoint() const const PIcon &IconsManager::activeBreakpoint() const
{ {
return mActiveBreakpoint; return mActiveBreakpoint;
} }
@ -36,3 +36,8 @@ const PIcon &IconsManager::bookmark() const
{ {
return mBookmark; return mBookmark;
} }
const PIcon &IconsManager::folder() const
{
return mFolder;
}

View File

@ -12,16 +12,18 @@ class IconsManager : public QObject
public: public:
explicit IconsManager(QObject *parent = nullptr); 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 &bookmark() const;
const PIcon &folder() const;
signals: signals:
private: private:
PIcon mSyntaxError; PIcon mSyntaxError;
@ -29,6 +31,7 @@ private:
PIcon mBreakpoint; PIcon mBreakpoint;
PIcon mActiveBreakpoint; PIcon mActiveBreakpoint;
PIcon mBookmark; PIcon mBookmark;
PIcon mFolder;
}; };
extern IconsManager* pIconsManager; extern IconsManager* pIconsManager;

View File

@ -72,7 +72,6 @@ MainWindow::MainWindow(QWidget *parent)
ui->splitterEditorPanel, ui->splitterEditorPanel,
ui->EditorPanel); ui->EditorPanel);
mProject = nullptr; mProject = nullptr;
setAcceptDrops(true);
setupActions(); setupActions();
ui->EditorTabsRight->setVisible(false); ui->EditorTabsRight->setVisible(false);
@ -815,7 +814,7 @@ void MainWindow::openFiles(const QStringList &files)
mEditorList->endUpdate(); mEditorList->endUpdate();
} }
void MainWindow::openFile(const QString &filename) void MainWindow::openFile(const QString &filename, QTabWidget* page)
{ {
Editor* editor = mEditorList->getOpenedEditorByFilename(filename); Editor* editor = mEditorList->getOpenedEditorByFilename(filename);
if (editor!=nullptr) { if (editor!=nullptr) {
@ -825,7 +824,7 @@ void MainWindow::openFile(const QString &filename)
try { try {
pSettings->history().removeFile(filename); pSettings->history().removeFile(filename);
editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT, editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT,
false,false); false, false, page);
editor->activate(); editor->activate();
this->updateForEncodingInfo(); this->updateForEncodingInfo();
} catch (FileError e) { } catch (FileError e) {
@ -2955,33 +2954,33 @@ void MainWindow::showEvent(QShowEvent *)
} }
} }
void MainWindow::dragEnterEvent(QDragEnterEvent *event) //void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{ //{
if (event->mimeData()->hasUrls()){ // if (event->mimeData()->hasUrls()){
event->acceptProposedAction(); // event->acceptProposedAction();
} // }
} //}
void MainWindow::dropEvent(QDropEvent *event) //void MainWindow::dropEvent(QDropEvent *event)
{ //{
if (event->mimeData()->hasUrls()) { // if (event->mimeData()->hasUrls()) {
foreach(const QUrl& url, event->mimeData()->urls()){ // foreach(const QUrl& url, event->mimeData()->urls()){
if (!url.isLocalFile()) // if (!url.isLocalFile())
continue; // continue;
QString file = url.toLocalFile(); // QString file = url.toLocalFile();
if (getFileType(file)==FileType::Project) { // if (getFileType(file)==FileType::Project) {
openProject(file); // openProject(file);
return; // return;
} // }
} // }
foreach(const QUrl& url, event->mimeData()->urls()){ // foreach(const QUrl& url, event->mimeData()->urls()){
if (!url.isLocalFile()) // if (!url.isLocalFile())
continue; // continue;
QString file = url.toLocalFile(); // QString file = url.toLocalFile();
openFile(file); // openFile(file);
} // }
} // }
} //}
void MainWindow::on_actionSave_triggered() void MainWindow::on_actionSave_triggered()
{ {

View File

@ -141,6 +141,9 @@ public:
const PBookmarkModel &bookmarkModel() const; const PBookmarkModel &bookmarkModel() const;
void openFile(const QString& filename, QTabWidget* page=nullptr);
void openProject(const QString& filename);
public slots: public slots:
void onCompileLog(const QString& msg); void onCompileLog(const QString& msg);
void onCompileIssue(PCompileIssue issue); void onCompileIssue(PCompileIssue issue);
@ -173,8 +176,6 @@ private:
void prepareProjectForCompile(); void prepareProjectForCompile();
void closeProject(bool refreshEditor); void closeProject(bool refreshEditor);
void updateProjectView(); void updateProjectView();
void openFile(const QString& filename);
void openProject(const QString& filename);
CompileTarget getCompileTarget(); CompileTarget getCompileTarget();
bool debugInferiorhasBreakpoint(); bool debugInferiorhasBreakpoint();
void setupActions(); void setupActions();
@ -536,8 +537,8 @@ private:
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
void showEvent(QShowEvent* event) override; void showEvent(QShowEvent* event) override;
void dragEnterEvent(QDragEnterEvent *event) override; // void dragEnterEvent(QDragEnterEvent *event) override;
void dropEvent(QDropEvent *event) override; // void dropEvent(QDropEvent *event) override;
}; };
extern MainWindow* pMainWindow; extern MainWindow* pMainWindow;

View File

@ -85,7 +85,7 @@
<enum>QTabWidget::West</enum> <enum>QTabWidget::West</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>3</number> <number>0</number>
</property> </property>
<property name="usesScrollButtons"> <property name="usesScrollButtons">
<bool>true</bool> <bool>true</bool>
@ -116,6 +116,15 @@
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set> <set>QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked</set>
</property> </property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum> <enum>QAbstractItemView::ExtendedSelection</enum>
</property> </property>
@ -288,7 +297,7 @@
<property name="handleWidth"> <property name="handleWidth">
<number>1</number> <number>1</number>
</property> </property>
<widget class="QTabWidget" name="EditorTabsLeft"> <widget class="EditorsTabWidget" name="EditorTabsLeft">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Expanding"> <sizepolicy hsizetype="Ignored" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -308,7 +317,7 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
<widget class="QTabWidget" name="EditorTabsRight"> <widget class="EditorsTabWidget" name="EditorTabsRight">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -2017,6 +2026,12 @@
<header location="global">widgets/qconsole.h</header> <header location="global">widgets/qconsole.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>EditorsTabWidget</class>
<extends>QTabWidget</extends>
<header location="global">widgets/editorstabwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="icons.qrc"/> <include location="icons.qrc"/>

View File

@ -9,6 +9,7 @@
#include "platform.h" #include "platform.h"
#include "projecttemplate.h" #include "projecttemplate.h"
#include "systemconsts.h" #include "systemconsts.h"
#include "iconsmanager.h"
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
@ -16,6 +17,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QTextCodec> #include <QTextCodec>
#include <QMessageBox> #include <QMessageBox>
#include <QFileIconProvider>
#include "settings.h" #include "settings.h"
#include <QDebug> #include <QDebug>
@ -1813,6 +1815,16 @@ QVariant ProjectModel::data(const QModelIndex &index, int role) const
return QVariant(); return QVariant();
if (role == Qt::DisplayRole || role==Qt::EditRole) { if (role == Qt::DisplayRole || role==Qt::EditRole) {
return p->text; 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(); return QVariant();
} }
@ -1826,7 +1838,10 @@ Qt::ItemFlags ProjectModel::flags(const QModelIndex &index) const
return Qt::NoItemFlags; return Qt::NoItemFlags;
if (p==mProject->node().get()) if (p==mProject->node().get())
return Qt::ItemIsEnabled; 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) 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; 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<FolderNode*>(idx.internalPointer());
PFolderNode node = mProject->pointerToNode(p);
if (node->unitIndex>=0)
return false;
return true;
}

View File

@ -96,6 +96,11 @@ public:
QVariant data(const QModelIndex &index, int role) const override; QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override; Qt::ItemFlags flags(const QModelIndex &index) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) 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; class ProjectTemplate;

View File

@ -15,6 +15,7 @@
SettingsWidget::SettingsWidget(const QString &name, const QString &group, QWidget *parent): SettingsWidget::SettingsWidget(const QString &name, const QString &group, QWidget *parent):
QWidget(parent), QWidget(parent),
mSettingsChanged(false),
mName(name), mName(name),
mGroup(group) mGroup(group)
{ {

View File

@ -0,0 +1,41 @@
#include "editorstabwidget.h"
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QMimeData>
#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();
}
}

View File

@ -0,0 +1,21 @@
#ifndef EDITORSTABWIDGET_H
#define EDITORSTABWIDGET_H
#include <QTabWidget>
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