- 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: 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

View File

@ -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 \

View File

@ -9,25 +9,25 @@ IconsManager::IconsManager(QObject *parent) : QObject(parent)
mBreakpoint = std::make_shared<QPixmap>(":/icons/images/editor/breakpoint.png");
mActiveBreakpoint = std::make_shared<QPixmap>(":/icons/images/editor/currentline.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;
}
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;
}

View File

@ -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;

View File

@ -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()
{

View File

@ -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;

View File

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

View File

@ -9,6 +9,7 @@
#include "platform.h"
#include "projecttemplate.h"
#include "systemconsts.h"
#include "iconsmanager.h"
#include <QDir>
#include <QFileDialog>
@ -16,6 +17,7 @@
#include <QMessageBox>
#include <QTextCodec>
#include <QMessageBox>
#include <QFileIconProvider>
#include "settings.h"
#include <QDebug>
@ -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<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;
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;

View File

@ -15,6 +15,7 @@
SettingsWidget::SettingsWidget(const QString &name, const QString &group, QWidget *parent):
QWidget(parent),
mSettingsChanged(false),
mName(name),
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