-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.cpp
More file actions
184 lines (163 loc) · 6.45 KB
/
Copy pathtasks.cpp
File metadata and controls
184 lines (163 loc) · 6.45 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "tasks.hpp"
#include "game.hpp"
#include "base/taskload.hpp"
#include "extra/help.hpp"
#include "wids/taskOverlay.hpp"
#include "wids/renameOverl.hpp"
#include "wids/confirm.hpp"
#include "font.hpp"
#include <QBoxLayout>
TaskView::TaskView() {
tlay = new QGridLayout(this);
tlay->setContentsMargins(0, 0, 0, 0);
auto mtlay = new QVBoxLayout();
mtlay->setContentsMargins(9, 9, 9, 9);
mtlay->setSpacing(0);
tlay->addLayout(mtlay, 0, 0);
{auto* labl = new QLabel("Tasks", this);
labl->setContentsMargins(4,4,4,8);
labl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
labl->setAlignment(Qt::AlignCenter);
mtlay->addWidget(labl);}
{auto tskscrl = new QScrollArea(this);
tskscrl->setFrameShape(QFrame::NoFrame);
tskscrl->setProperty("bg", true);
tskscrl->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
tskscrl->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
tskscrl->verticalScrollBar()->setAttribute(Qt::WA_TransparentForMouseEvents, true);
tskscrl->verticalScrollBar()->setFocusPolicy(Qt::NoFocus);
tdrag = new DragScroll(tskscrl->viewport(), tskscrl->verticalScrollBar());
auto* tcont = new QWidget(this);
tcont->setObjectName("transpbg");
tbbllay = new QVBoxLayout(tcont);
tbbllay->setSpacing(8);
tbbllay->setAlignment(Qt::AlignTop);
tskscrl->setWidget(tcont);
tskscrl->setWidgetResizable(true);
mtlay->addWidget(tskscrl);}
mtlay->addSpacing(8);
{QFrame* line = new QFrame();
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Raised);
mtlay->addWidget(line);}
mtlay->addSpacing(8);
auto topsect = new QHBoxLayout();
auto addBtn = [&](QString asset){
auto btn = new QPushButton();
btn->setProperty("fancy", true);
btn->setIcon(QIcon(asset));
btn->setIconSize(QSize(48, 44));
btn->setMinimumHeight(56);
return btn;
};
auto titlay = new QHBoxLayout();
titlay->addStretch();
todaybtn = new QPushButton("Today", this);
todaybtn->setProperty("fancy", true);
todaybtn->setProperty("optbtn", true);
todaybtn->setProperty("current", isTodayCat());
resizeFont(todaybtn, 1.2);
QObject::connect(todaybtn, &QPushButton::clicked, [this](){
if (isTodayCat()) showNoCat();
else showToday();
redoTasks();
});
titlay->addWidget(todaybtn);
titlay->addStretch();
{auto* labl = new QLabel("Categories", this);
resizeFont(labl, 1.2);
labl->setContentsMargins(4,8,4,8);
labl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
labl->setAlignment(Qt::AlignCenter);
titlay->addWidget(labl);}
titlay->addStretch();
mtlay->addLayout(titlay);
{scrl = new QScrollArea(this);
scrl->setFrameShape(QFrame::NoFrame);
scrl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
scrl->setProperty("bg", true);
scrl->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrl->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrl->horizontalScrollBar()->setAttribute(Qt::WA_TransparentForMouseEvents, true);
scrl->horizontalScrollBar()->setFocusPolicy(Qt::NoFocus);
tcatdrag = new DragScroll(scrl->viewport(), scrl->horizontalScrollBar());
auto* catcont = new QWidget(this);
catcont->setObjectName("transpbg");
tcatlay = new FlowLayout(catcont);
tcatlay->vertical(2);
scrl->setWidget(catcont);
scrl->setWidgetResizable(true);
mtlay->addWidget(scrl);}
mtlay->addSpacing(8);
auto bot = new QHBoxLayout();
bot->setSpacing(8);
{auto bk = addBtn(":/assets/UI/back.svg");
bk->setProperty("backbtn", true);
connect(bk, &QPushButton::clicked, this, [=](){ MG->toMain(); });
bot->addWidget(bk);}
{auto plus = addBtn(":/assets/UI/plus.svg");
plus->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
connect(plus, &QPushButton::clicked, this, [this](){
overlay = new RenameOverlay("New category", "", [this](QString s){
newCategory(this, s.trimmed());
redoTasks();
});
tlay->addWidget(overlay, 0, 0);
});
bot->addWidget(plus);}
{auto rnam = addBtn(":/assets/UI/rename.svg");
rnam->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
connect(rnam, &QPushButton::clicked, this, [this](){
if (isTodayCat()) {
confirm(this, "Cannot rename the today category!", Conf_OK);
return;
}
QString cur = getCurrent();
overlay = new RenameOverlay("Rename category '" + cur + "'", cur, [this](QString s){
if (renameCategory(this, s.trimmed())) redoTasks();
});
tlay->addWidget(overlay, 0, 0);
});
bot->addWidget(rnam);}
{auto bin = addBtn(":/assets/UI/bin.svg");
bin->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
connect(bin, &QPushButton::clicked, this, [this](){
if (isTodayCat()) {
confirm(this, "Cannot delete the today category!", Conf_OK);
return;
}
if (deleteCategory(this)) redoTasks();
});
bot->addWidget(bin);}
{auto help = addBtn(":/assets/UI/help.svg");
help->setProperty("backbtn", true);
connect(help, &QPushButton::clicked, this, [this](){
confirm(this, TASK_HELP, Conf_OK, true);
});
bot->addWidget(help);}
mtlay->addLayout(bot);
redoTasks();
}
void TaskView::redoTasks() {
todaybtn->setProperty("current", isTodayCat());
todaybtn->style()->unpolish(todaybtn);
todaybtn->style()->polish(todaybtn);
todaybtn->update();
auto redo = [this](){ redoTasks(); };
setTasksLay(tbbllay, [=](std::shared_ptr<Task> t, bool upd){
overlay = new TaskOverlay(t, redo, this);
tlay->addWidget(overlay, 0, 0);
if (upd) redoTasks();
}, redo, this);
setTasksCatsLay(tcatlay, redo, this);
tcatdrag->installOn(tcatlay);
tdrag->installOn(tbbllay);
tcatlay->activate();
scrl->widget()->setMinimumWidth(tcatlay->lastSize().width() + 8);
QTimer::singleShot(0, [this](){
const int w = scrl->viewport()->width();
const int h = tcatlay->heightForWidth(w);
scrl->setFixedHeight(h);
});
if (overlay) overlay->raise();
}