forked from Geonkick-Synthesizer/geonkick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPathListModel.cpp
95 lines (85 loc) · 3.22 KB
/
PathListModel.cpp
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
/**
* File name: PathListModel.cpp
* Project: Redkite (A small GUI toolkit)
*
* Copyright (C) 2020 Iurie Nistor
*
* This file is part of Redkite.
*
* Redkite 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
*/
#include "PathListModel.h"
#include "DesktopPaths.h"
PathListModel::PathListModel(RkObject *parent)
: RkModel(parent)
{
DesktopPaths desktopPaths;
pathList.emplace_back(desktopPaths.getHomePath());
pathList.emplace_back(desktopPaths.getDesktopPath());
pathList.emplace_back(desktopPaths.getDownloadsPath());
auto drives = desktopPaths.getDrivesList();
for (auto d: drives)
pathList.emplace_back(d);
stringFont.setWeight(RkFont::Weight::Bold);
stringFont.setSize(12);
}
void PathListModel::setHomeDirectory(const std::string &path)
{
if (!pathList.empty())
pathList[0] = path;
else
pathList.push_back(path);
action modelChanged();
}
RkVariant PathListModel::itemData(size_t index, int dataType) const
{
if (index > itemsNumber() - 1)
return RkVariant();
if (static_cast<RkModelItem::DataType>(dataType) == RkModelItem::DataType::String) {
if (index == 0)
return "Home";
else if (pathList[index].has_filename())
return pathList[index].filename().string();
else
return pathList[index].root_name().string();
} else if (static_cast<RkModelItem::DataType>(dataType) == RkModelItem::DataType::Size) {
return RkSize(0, 18);
} else if (static_cast<RkModelItem::DataType>(dataType) == RkModelItem::DataType::Font) {
return stringFont;
} else if (static_cast<RkModelItem::DataType>(dataType) == RkModelItem::DataType::Color) {
return RkColor(150, 150, 150);
} else if (static_cast<PathListDataType>(dataType) == PathListDataType::Path) {
return pathList[index].string();
}
return RkVariant();
}
size_t PathListModel::itemsNumber() const
{
return pathList.size();
}
int PathListModel::itemSpan() const
{
return 20;
}
void PathListModel::addPath(const std::filesystem::path &path)
{
auto it = std::find(pathList.begin(), pathList.end(), path);
if (it != pathList.end()) {
if (pathList.size() > 8)
pathList.erase(pathList.begin() + 3);
pathList.push_back(path);
action modelChanged();
}
}