Skip to content

Commit 098ef8d

Browse files
committed
Add color when dropping file
1 parent 60b0a62 commit 098ef8d

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

Desktop/components/JASP/Widgets/MainWindow.qml

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,58 @@ Window
8787
return (a + n) % n;
8888
}
8989

90-
DropArea
91-
{
92-
id: drop
93-
enabled: true
94-
anchors.fill: parent
95-
onDropped: (drop) => mainWindow.openURLFile(drop.text)
96-
}
97-
9890
Item
9991
{
10092
anchors.fill: parent
10193

10294
Rectangle
10395
{
96+
id: warningRect
10497
z: 1
105-
visible: mainWindow.hadFatalError
106-
color: jaspTheme.red
98+
color: mainWindow.hadFatalError ? jaspTheme.red : "transparent"
10799
opacity: 0.75
108100
anchors.fill: parent
101+
102+
DropArea
103+
{
104+
enabled: true
105+
anchors.fill: parent
106+
onDropped: (drop) =>
107+
{
108+
if (mainWindow.openURLFile(drop.text))
109+
drop.accepted = true
110+
parent.state = ""
111+
}
112+
113+
onExited: parent.state = ""
114+
onEntered: (drag) =>
115+
{
116+
if (drag.hasText)
117+
parent.state = "active"
118+
}
119+
}
120+
121+
states: [
122+
State {
123+
name: "active"
124+
PropertyChanges {
125+
warningRect {
126+
color: jaspTheme.blueLighter
127+
}
128+
}
129+
}
130+
]
131+
132+
transitions: [
133+
Transition {
134+
from: ""
135+
to: "active"
136+
reversible: true
137+
ColorAnimation { properties: "color"; duration: 150; easing.type: Easing.InOutQuad }
138+
}
139+
]
140+
141+
109142
}
110143

111144
Shortcut { onActivated: mainWindow.showEnginesWindow(); sequences: ["Ctrl+Alt+Shift+E"]; context: Qt.ApplicationShortcut; }

Desktop/mainwindow.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,13 @@ void MainWindow::showLogFolder() const
852852
openFolderExternally(AppDirs::logDir());
853853
}
854854

855-
void MainWindow::openURLFile(QString fileURLPath)
855+
bool MainWindow::openURLFile(QString fileURLPath)
856856
{
857857
QUrl fileUrl = fileURLPath.startsWith("file:") ? QUrl(fileURLPath) : QUrl::fromLocalFile(fileURLPath);
858858
if (!fileUrl.isLocalFile())
859859
{
860860
MessageForwarder::showWarning(tr("Open file"), tr("Cannot access file %1").arg(fileURLPath));
861-
return;
861+
return false;
862862
}
863863

864864
QString filePath = fileUrl.toLocalFile();
@@ -867,15 +867,15 @@ void MainWindow::openURLFile(QString fileURLPath)
867867
if (!fileInfo.exists())
868868
{
869869
MessageForwarder::showWarning(tr("Open file"), tr("File %1 is not found.").arg(filePath));
870-
return;
870+
return false;
871871
}
872872

873873
Utils::FileType fileType = Utils::getTypeFromFileName(fq(filePath));
874874

875875
if (fileType == Utils::FileType::empty || fileType == Utils::FileType::unknown || fileType == Utils::FileType::html || fileType == Utils::FileType::pdf)
876876
{
877877
MessageForwarder::showWarning(tr("Open file"), tr("JASP does not support this file type %1.").arg(filePath));
878-
return;
878+
return false;
879879
}
880880

881881
if (_package->hasDataSet() && fileType != Utils::FileType::jasp)
@@ -886,6 +886,8 @@ void MainWindow::openURLFile(QString fileURLPath)
886886
}
887887
else
888888
open(filePath);
889+
890+
return true;
889891
}
890892

891893
void MainWindow::open(const QString & mainFilePath, const QString & inputDataFile, const QString & outputFile, bool keepJASPOpen)

Desktop/mainwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public slots:
171171
void zoomResetKeyPressed();
172172
void undo();
173173
void redo();
174-
void openURLFile(QString fileURLPath);
174+
bool openURLFile(QString fileURLPath);
175175

176176
QObject * loadQmlData(QString data, QUrl url);
177177

0 commit comments

Comments
 (0)