Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
2145ce73
Commit
2145ce73
authored
Mar 07, 2013
by
Sebastian Eichelbaum
Browse files
[ADD
#253
] drag and drop support for filename properties
parent
1e98860b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
1 deletion
+66
-1
src/qt4gui/controlPanel/WPropertyFilenameWidget.cpp
src/qt4gui/controlPanel/WPropertyFilenameWidget.cpp
+50
-1
src/qt4gui/controlPanel/WPropertyFilenameWidget.h
src/qt4gui/controlPanel/WPropertyFilenameWidget.h
+16
-0
No files found.
src/qt4gui/controlPanel/WPropertyFilenameWidget.cpp
View file @
2145ce73
...
...
@@ -25,7 +25,6 @@
#include <cmath>
#include <string>
#include <QtGui/QFileDialog>
#include "core/common/WLogger.h"
...
...
@@ -58,6 +57,9 @@ WPropertyFilenameWidget::WPropertyFilenameWidget( WPropFilename property, QGridL
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
// accept drag and drop
setAcceptDrops
(
true
);
// set the initial values
update
();
...
...
@@ -112,3 +114,50 @@ void WPropertyFilenameWidget::buttonReleased()
m_button
.
setText
(
QString
::
fromStdString
(
m_fnProperty
->
get
().
filename
().
string
()
)
);
}
void
WPropertyFilenameWidget
::
dragEnterEvent
(
QDragEnterEvent
*
event
)
{
if
(
event
->
mimeData
()
->
hasUrls
()
&&
(
event
->
mimeData
()
->
urls
().
size
()
==
1
)
)
{
// accept only a single url to a local file
QUrl
url
=
*
(
event
->
mimeData
()
->
urls
().
begin
()
);
QString
path
=
url
.
toLocalFile
();
QFileInfo
info
(
path
);
bool
shouldBeDir
=
(
m_fnProperty
->
countConstraint
(
PC_ISDIRECTORY
)
!=
0
);
bool
shouldExist
=
(
m_fnProperty
->
countConstraint
(
PC_PATHEXISTS
)
!=
0
);
// needs to be a directory?
bool
accept
=
(
shouldBeDir
&&
info
.
isDir
()
)
||
!
shouldBeDir
;
accept
&=
(
shouldExist
&&
info
.
exists
()
)
||
!
shouldExist
;
event
->
setAccepted
(
accept
);
}
}
void
WPropertyFilenameWidget
::
dropEvent
(
QDropEvent
*
event
)
{
if
(
event
->
mimeData
()
->
hasUrls
()
&&
(
event
->
mimeData
()
->
urls
().
size
()
==
1
)
)
{
// accept only a single url to a local file
QUrl
url
=
*
(
event
->
mimeData
()
->
urls
().
begin
()
);
QString
path
=
url
.
toLocalFile
();
QFileInfo
info
(
path
);
bool
shouldBeDir
=
(
m_fnProperty
->
countConstraint
(
PC_ISDIRECTORY
)
!=
0
);
bool
shouldExist
=
(
m_fnProperty
->
countConstraint
(
PC_PATHEXISTS
)
!=
0
);
// needs to be a directory?
bool
accept
=
(
shouldBeDir
&&
info
.
isDir
()
)
||
!
shouldBeDir
;
accept
&=
(
shouldExist
&&
info
.
exists
()
)
||
!
shouldExist
;
// use new path/filename
// convert it back to a filename property
invalidate
(
!
m_fnProperty
->
set
(
boost
::
filesystem
::
path
(
path
.
toStdString
()
)
)
);
// NOTE: set automatically checks the validity of the value
// set button
m_button
.
setText
(
QString
::
fromStdString
(
m_fnProperty
->
get
().
filename
().
string
()
)
);
}
}
src/qt4gui/controlPanel/WPropertyFilenameWidget.h
View file @
2145ce73
...
...
@@ -29,6 +29,10 @@
#include <QtGui/QPushButton>
#include <QtGui/QHBoxLayout>
#include <QtCore/QMimeData>
#include <QtCore/QUrl>
#include <QtGui/QDragEnterEvent>
#include <QtGui/QDropEvent>
#include "../guiElements/WScaleLabel.h"
...
...
@@ -86,6 +90,18 @@ protected:
*/
QHBoxLayout
m_infoLayout
;
/**
* Reimplemented to accept color drops
* \param event the handled event
*/
virtual
void
dragEnterEvent
(
QDragEnterEvent
*
event
);
/**
* Reimplemented to accept color drops
* \param event the handled event
*/
virtual
void
dropEvent
(
QDropEvent
*
event
);
private:
public
slots
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment