1#include <AGitServerItemList.h>
2
3#include <GitServerCache.h>
4#include <IssueItem.h>
5#include <ClickableFrame.h>
6#include <IRestApi.h>
7
8#include <QVBoxLayout>
9#include <QLabel>
10#include <QPushButton>
11#include <QScrollArea>
12#include <QTimer>
13#include <QSpinBox>
14#include <QToolButton>
15
16using namespace GitServer;
17
18AGitServerItemList::AGitServerItemList(const QSharedPointer<GitServerCache> &gitServerCache, QWidget *parent)
19 : QFrame(parent)
20 , mGitServerCache(gitServerCache)
21 , mHeaderTitle(new QLabel())
22 , mArrow(new QLabel())
23{
24 mHeaderTitle->setObjectName("HeaderTitle");
25
26 const auto headerFrame = new ClickableFrame();
27 headerFrame->setObjectName("IssuesHeaderFrame");
28 connect(headerFrame, &ClickableFrame::clicked, this, &AGitServerItemList::onHeaderClicked);
29
30 mArrow->setPixmap(QIcon(":/icons/remove").pixmap(QSize(15, 15)));
31
32 const auto headerLayout = new QHBoxLayout(headerFrame);
33 headerLayout->setContentsMargins(QMargins());
34 headerLayout->setSpacing(0);
35 headerLayout->addWidget(mHeaderTitle);
36 headerLayout->addStretch();
37 headerLayout->addWidget(mArrow);
38
39 mIssuesLayout = new QVBoxLayout();
40
41 const auto issuesLayout = new QVBoxLayout(this);
42 issuesLayout->setContentsMargins(QMargins());
43 issuesLayout->setSpacing(0);
44 issuesLayout->setAlignment(Qt::AlignTop);
45 issuesLayout->addWidget(headerFrame);
46 issuesLayout->addLayout(mIssuesLayout);
47
48 const auto timer = new QTimer();
49 connect(timer, &QTimer::timeout, this, &AGitServerItemList::loadData);
50 timer->start(900000);
51}
52
53void AGitServerItemList::loadData()
54{
55 loadPage();
56}
57
58void AGitServerItemList::createContent(QVector<IssueItem *> items)
59{
60 delete mIssuesWidget;
61 delete mScrollArea;
62
63 const auto issuesLayout = new QVBoxLayout();
64 issuesLayout->setAlignment(Qt::AlignTop | Qt::AlignVCenter);
65 issuesLayout->setContentsMargins(QMargins());
66 issuesLayout->setSpacing(0);
67
68 for (auto item : items)
69 {
70 issuesLayout->addWidget(item);
71
72 const auto separator = new QFrame();
73 separator->setObjectName("separator");
74 issuesLayout->addWidget(separator);
75 }
76
77 issuesLayout->addStretch();
78
79 mIssuesWidget = new QFrame();
80 mIssuesWidget->setLayout(issuesLayout);
81 mIssuesWidget->setObjectName("IssuesWidget");
82
83 mScrollArea = new QScrollArea();
84 mScrollArea->setWidget(mIssuesWidget);
85 mScrollArea->setWidgetResizable(true);
86 mScrollArea->setObjectName("IssuesScroll");
87 mScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
88
89 mIssuesLayout->addWidget(mScrollArea);
90
91 const auto icon = QIcon(mScrollArea->isVisible() ? QString(":/icons/add") : QString(":/icons/remove"));
92 mArrow->setPixmap(icon.pixmap(QSize(15, 15)));
93
94 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
95}
96
97void AGitServerItemList::onHeaderClicked()
98{
99 if (mScrollArea)
100 {
101 const auto issuesVisible = mScrollArea->isVisible();
102
103 mScrollArea->setWidgetResizable(issuesVisible);
104
105 const auto icon = QIcon(issuesVisible ? QString(":/icons/add") : QString(":/icons/remove"));
106 mArrow->setPixmap(icon.pixmap(QSize(15, 15)));
107 mScrollArea->setVisible(!issuesVisible);
108
109 /*
110 GitQlientSettings settings;
111 settings.setLocalValue(mGit->getGitQlientSettingsDir(),
112 QString("IssuesWidgetHeader/%1").arg(static_cast<int>(mConfig), !tagsAreVisible);
113 */
114
115 if (issuesVisible)
116 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
117 else
118 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
119 }
120}
121
122void AGitServerItemList::loadPage(int)
123{
124 /*
125 if (page == -1)
126 {
127 if (mConfig == Config::Issues)
128 mApi->requestIssues();
129 else
130 mApi->requestPullRequests();
131 }
132 else
133 {
134 if (mConfig == Config::Issues)
135 mApi->requestIssues(page);
136 else
137 mApi->requestPullRequests(page);
138 }
139*/
140}
141