forked from Geonkick-Synthesizer/geonkick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_dialog.h
147 lines (133 loc) · 5.03 KB
/
file_dialog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* File name: file_dialog.h
* Project: Geonkick (A kick synthesizer)
*
* Copyright (C) 2019 Iurie Nistor
*
* This file is part of Geonkick.
*
* GeonKick is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef GEONKICK_FILE_DIALOG_H
#define GEONKICK_FILE_DIALOG_H
#include "geonkick_widget.h"
class RkLineEdit;
class RkPaintEvent;
class RkMouseEvent;
class RkCloseEvent;
class GeonkickButton;
class RkLabel;
class GeonkickSlider;
class PathListModel;
class RkList;
class FilesView: public GeonkickWidget {
public:
explicit FilesView(GeonkickWidget *parent);
std::string selectedFile() const;
std::string getCurrentPath() const;
void setCurrentPath(const std::string &path);
RK_DECL_ACT(openFile, openFile(const std::string &fileName),
RK_ARG_TYPE(const std::string &), RK_ARG_VAL(fileName));
RK_DECL_ACT(currentPathChanged, currentPathChanged(const std::string &pathName),
RK_ARG_TYPE(const std::string &), RK_ARG_VAL(pathName));
RK_DECL_ACT(fileSelected,
fileSelected(const std::string &file),
RK_ARG_TYPE(const std::string&),
RK_ARG_VAL(file));
RK_DECL_ACT(currentFileChanged,
currentFileChanged(const std::string &file),
RK_ARG_TYPE(const std::string&),
RK_ARG_VAL(file));
void setFilters(const std::vector<std::string> &filters);
protected:
void createScrollBar();
void showScrollBar(bool b);
void paintWidget(RkPaintEvent *event) override;
void mouseButtonPressEvent(RkMouseEvent *event) override;
void mouseDoubleClickEvent(RkMouseEvent *event) override;
void mouseMoveEvent(RkMouseEvent *event) override;
void keyPressEvent(RkKeyEvent *event) override;
void loadCurrentDirectory();
int getLine(int x, int y) const;
void onLineUp();
void onLineDown();
void openSelectedFile();
void scrollBarChanged(int val);
void updateScrollBar();
std::string getSelectedFile() const;
private:
std::vector<std::filesystem::path> filesList;
int selectedFileIndex;
int hightlightLine;
int offsetIndex;
std::filesystem::path currentPath;
int lineHeight;
int lineSacing;
decltype(filesList.size()) visibleLines;
GeonkickButton *topScrollBarButton;
GeonkickButton *bottomScrollBarButton;
int scrollBarWidth;
GeonkickSlider *scrollBar;
bool isScrollBarVisible;
std::vector<std::string> fileFilters;
};
class FileDialog: public GeonkickWidget {
public:
enum class Type: int {
Save,
Open,
Browse
};
enum class AcceptStatus: int {
Cancel,
Accept
};
explicit FileDialog(GeonkickWidget *parent,
FileDialog::Type type = FileDialog::Type::Open,
const std::string& title = std::string());
RK_DECL_ACT(selectedFile,
selectedFile(const std::string &file),
RK_ARG_TYPE(const std::string&),
RK_ARG_VAL(file));
RK_DECL_ACT(currentFileChanged,
currentFileChanged(const std::string &file),
RK_ARG_TYPE(const std::string&),
RK_ARG_VAL(file));
RK_DECL_ACT(directoryChanged,
directoryChanged(const std::string &path),
RK_ARG_TYPE(const std::string&),
RK_ARG_VAL(path));
std::string currentDirectory() const;
void setCurrentDirectoy(const std::string &path);
std::string filePath() const;
AcceptStatus acceptStatus() const;
void setFilters(const std::vector<std::string> &filters);
void setHomeDirectory(const std::string &path);
protected:
void onAccept();
void onCancel();
void onPathChanged(const std::string &pathName);
void closeEvent(RkCloseEvent *event) final;
private:
RkLineEdit *fileNameEdit;
Type dialogType;
FilesView *filesView;
RkLabel *pathLabel;
std::string pathSelected;
AcceptStatus status;
PathListModel* shortcutDirectoriesModel;
RkList *shortcutDirectoriesView;
};
#endif // GEONKICK_FILE_DIALOG_H