mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Dropping a file onto a main window now opens that file.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@1861 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -526,6 +526,38 @@ QString QETApp::symbolicPath(const QString &real_path) {
|
|||||||
return(chemin);
|
return(chemin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@return the list of file extensions QElectroTech is able to open and
|
||||||
|
supposed to handle. Note they are provided with no leading point.
|
||||||
|
*/
|
||||||
|
QStringList QETApp::handledFileExtensions() {
|
||||||
|
static QStringList ext;
|
||||||
|
if (!ext.count()) {
|
||||||
|
ext << "qet";
|
||||||
|
ext << "elmt";
|
||||||
|
ext << QString(TITLEBLOCKS_FILE_EXTENSION).remove(QRegExp("^\."));
|
||||||
|
}
|
||||||
|
return(ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param an URLs list
|
||||||
|
@return the list of filepaths QElectroTech is able to open.
|
||||||
|
*/
|
||||||
|
QStringList QETApp::handledFiles(const QList<QUrl> &urls) {
|
||||||
|
QList<QString> filepaths;
|
||||||
|
foreach (QUrl url, urls) {
|
||||||
|
if (!url.isLocalFile()) continue;
|
||||||
|
QString local_path = url.toLocalFile();
|
||||||
|
QFileInfo local_path_info(local_path);
|
||||||
|
QString local_path_ext = local_path_info.completeSuffix();
|
||||||
|
if (handledFileExtensions().contains(local_path_ext)) {
|
||||||
|
filepaths << local_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(filepaths);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param filepath Un chemin de fichier
|
@param filepath Un chemin de fichier
|
||||||
Note : si filepath est une chaine vide, cette methode retourne 0.
|
Note : si filepath est une chaine vide, cette methode retourne 0.
|
||||||
|
|||||||
@@ -95,6 +95,8 @@ class QETApp : public QETSingleApplication {
|
|||||||
static QString languagesPath();
|
static QString languagesPath();
|
||||||
static QString realPath(const QString &);
|
static QString realPath(const QString &);
|
||||||
static QString symbolicPath(const QString &);
|
static QString symbolicPath(const QString &);
|
||||||
|
static QStringList handledFileExtensions();
|
||||||
|
static QStringList handledFiles(const QList<QUrl> &);
|
||||||
static RecentFiles *projectsRecentFiles();
|
static RecentFiles *projectsRecentFiles();
|
||||||
static RecentFiles *elementsRecentFiles();
|
static RecentFiles *elementsRecentFiles();
|
||||||
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
|
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ QETMainWindow::QETMainWindow(QWidget *widget, Qt::WindowFlags flags) :
|
|||||||
{
|
{
|
||||||
initCommonActions();
|
initCommonActions();
|
||||||
initCommonMenus();
|
initCommonMenus();
|
||||||
|
|
||||||
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,3 +164,31 @@ bool QETMainWindow::event(QEvent *e) {
|
|||||||
*/
|
*/
|
||||||
void QETMainWindow::firstActivation(QEvent *) {
|
void QETMainWindow::firstActivation(QEvent *) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Accept or refuse drag'n drop events depending on the dropped mime type;
|
||||||
|
especially, accepts only URLs to local files that we could open.
|
||||||
|
@param e le QDragEnterEvent correspondant au drag'n drop tente
|
||||||
|
*/
|
||||||
|
void QETMainWindow::dragEnterEvent(QDragEnterEvent *e) {
|
||||||
|
if (e -> mimeData() -> hasUrls()) {
|
||||||
|
if (QETApp::handledFiles(e -> mimeData() -> urls()).count()) {
|
||||||
|
e -> acceptProposedAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Handle drops accepted on main windows; more specifically, open dropped files
|
||||||
|
as long as they are handled by QElectrotech.
|
||||||
|
@param e the QDropEvent describing the current drag'n drop
|
||||||
|
*/
|
||||||
|
void QETMainWindow::dropEvent(QDropEvent *e) {
|
||||||
|
if (e -> mimeData() -> hasUrls()) {
|
||||||
|
QStringList filepaths = QETApp::handledFiles(e -> mimeData() -> urls());
|
||||||
|
if (filepaths.count()) {
|
||||||
|
QETApp::instance() -> openFiles(QETArguments(filepaths));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ class QETMainWindow : public QMainWindow {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool event(QEvent *);
|
virtual bool event(QEvent *);
|
||||||
|
virtual void dragEnterEvent(QDragEnterEvent *e);
|
||||||
|
virtual void dropEvent(QDropEvent *e);
|
||||||
virtual void firstActivation(QEvent *);
|
virtual void firstActivation(QEvent *);
|
||||||
|
|
||||||
// slots
|
// slots
|
||||||
|
|||||||
Reference in New Issue
Block a user