[qet] [1861] Dropping a file onto a main window now opens that file. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 1861
Author: xavier
Date: 2012-05-24 19:27:15 +0200 (Thu, 24 May 2012)
Log Message:
-----------
Dropping a file onto a main window now opens that file.
Modified Paths:
--------------
trunk/sources/qetapp.cpp
trunk/sources/qetapp.h
trunk/sources/qetmainwindow.cpp
trunk/sources/qetmainwindow.h
Modified: trunk/sources/qetapp.cpp
===================================================================
--- trunk/sources/qetapp.cpp 2012-05-20 16:42:45 UTC (rev 1860)
+++ trunk/sources/qetapp.cpp 2012-05-24 17:27:15 UTC (rev 1861)
@@ -527,6 +527,38 @@
}
/**
+ @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
Note : si filepath est une chaine vide, cette methode retourne 0.
@return le QETDiagramEditor editant le fichier filepath, ou 0 si ce fichier
Modified: trunk/sources/qetapp.h
===================================================================
--- trunk/sources/qetapp.h 2012-05-20 16:42:45 UTC (rev 1860)
+++ trunk/sources/qetapp.h 2012-05-24 17:27:15 UTC (rev 1861)
@@ -95,6 +95,8 @@
static QString languagesPath();
static QString realPath(const QString &);
static QString symbolicPath(const QString &);
+ static QStringList handledFileExtensions();
+ static QStringList handledFiles(const QList<QUrl> &);
static RecentFiles *projectsRecentFiles();
static RecentFiles *elementsRecentFiles();
#ifdef QET_ALLOW_OVERRIDE_CED_OPTION
Modified: trunk/sources/qetmainwindow.cpp
===================================================================
--- trunk/sources/qetmainwindow.cpp 2012-05-20 16:42:45 UTC (rev 1860)
+++ trunk/sources/qetmainwindow.cpp 2012-05-24 17:27:15 UTC (rev 1861)
@@ -29,6 +29,8 @@
{
initCommonActions();
initCommonMenus();
+
+ setAcceptDrops(true);
}
/**
@@ -162,3 +164,31 @@
*/
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));
+ }
+ }
+}
Modified: trunk/sources/qetmainwindow.h
===================================================================
--- trunk/sources/qetmainwindow.h 2012-05-20 16:42:45 UTC (rev 1860)
+++ trunk/sources/qetmainwindow.h 2012-05-24 17:27:15 UTC (rev 1861)
@@ -40,6 +40,8 @@
protected:
virtual bool event(QEvent *);
+ virtual void dragEnterEvent(QDragEnterEvent *e);
+ virtual void dropEvent(QDropEvent *e);
virtual void firstActivation(QEvent *);
// slots