Debian Codegraph @

src/views/starview.h

raw
1 /*
2 This file is part of Icecream.
3
4 Copyright (c) 2003 Frerich Raabe <[email protected]>
5 Copyright (c) 2004 Cornelius Schumacher <[email protected]>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21 #ifndef ICEMON_STARVIEW_H
22 #define ICEMON_STARVIEW_H
23
24 #include "job.h"
25 #include "statusview.h"
26
27 #include <QGraphicsView>
28 #include <QResizeEvent>
29 #include <QLabel>
30 #include <QGraphicsEllipseItem>
31 #include <QDialog>
32
33 class HostInfo;
34 class StarView;
35
36 class QSlider;
37 class QLabel;
38 class QLineEdit;
39 class QCheckBox;
40 class QGraphicsView;
41
42 class StarViewConfigDialog
43 : public QDialog
44 {
45 Q_OBJECT
46
47 public:
48 explicit StarViewConfigDialog(QWidget *parent);
49
50 int nodesPerRing();
51 void setNodesPerRing(int nodes);
52
53 bool suppressDomainName() const;
54 void setSuppressDomainName(bool suppress);
55
56 void setMaxNodes(int);
57
58 QString archFilter();
59
60 protected slots:
61 void slotNodesPerRingChanged(int nodes);
62 void slotSuppressDomainName(bool);
63
64 signals:
65 void configChanged();
66
67 private:
68 QSlider *mNodesPerRingSlider;
69 QLabel *mNodesPerRingLabel;
70 QLineEdit *mArchFilterEdit;
71 QCheckBox *mSuppressDomainName;
72 };
73
74 class HostItem
75 : public QGraphicsItemGroup
76 {
77 public:
78 static const int HaloMargin = 4;
79 static const int PenDarkerFactor = 125;
80
81 enum { RttiHostItem = 1000 };
82
83 explicit HostItem(const QString &text);
84 HostItem(HostInfo *hostInfo, HostInfoManager *);
85 ~HostItem() override;
86
87 void init();
88
89 HostInfo *hostInfo() const { return mHostInfo; }
90
91 void setHostColor(const QColor &color);
92
93 void setIsActiveClient(bool active) { mIsActiveClient = active; }
94 bool isActiveClient() const { return mIsActiveClient; }
95
96 void setIsCompiling(bool compiling) { mIsCompiling = compiling; }
97 bool isCompiling() const { return mIsCompiling; }
98
99 void setStateItem(QGraphicsItem *item) { m_stateItem = item; }
100 QGraphicsItem *stateItem() { return m_stateItem; }
101
102 void setClient(unsigned int client) { m_client = client; }
103 unsigned int client() const { return m_client; }
104
105 QString hostName() const;
106 void updateName();
107 void setFixedText(const QString &text);
108
109 double centerPosX() const { return pos().x() + m_textItem->boundingRect().width() / 2; }
110 double centerPosY() const { return pos().y() + m_textItem->boundingRect().height() / 2; }
111
112 double relativeCenterPosX() const { return m_textItem->boundingRect().width() / 2; }
113 double relativeCenterPosY() const { return m_textItem->boundingRect().height() / 2; }
114
115 qreal baseXMargin() const { return (mBaseWidth - m_textItem->boundingRect().width()) / 2; }
116 qreal baseYMargin() const { return (mBaseHeight - m_textItem->boundingRect().height()) / 2; }
117
118 void setCenterPos(double x, double y);
119
120 void update(const Job &job);
121
122 protected:
123 void createJobHalo(const Job &);
124 void deleteJobHalo(const Job &job);
125 void updateHalos();
126
127 private:
128 HostInfo *mHostInfo;
129 HostInfoManager *mHostInfoManager;
130
131 bool mIsActiveClient;
132 bool mIsCompiling;
133
134 QGraphicsItem *m_stateItem;
135 QGraphicsTextItem *m_textItem;
136 QString m_fixedText;
137 unsigned int m_client;
138
139 qreal mBaseWidth;
140 qreal mBaseHeight;
141
142 QGraphicsEllipseItem *m_boxItem;
143
144 QMap<Job, QGraphicsEllipseItem *> m_jobHalos;
145
146 JobList m_jobs;
147 };
148
149 class StarViewGraphicsView
150 : public QGraphicsView
151 {
152 Q_OBJECT
153
154 public:
155 StarViewGraphicsView(QGraphicsScene *scene, StarView *starView, QWidget *parent = nullptr);
156
157 void arrangeItems();
158 void drawNodeStatus();
159
160 protected:
161 void resizeEvent(QResizeEvent *e) override;
162 bool event(QEvent *event) override;
163
164 private:
165 void arrangeHostItems();
166 void arrangeSchedulerItem();
167 void drawState(HostItem *node);
168
169 StarView *m_starView;
170 HostItem *m_schedulerItem;
171 };
172
173 class StarView
174 : public StatusView
175 {
176 Q_OBJECT
177
178 public:
179 explicit StarView(QObject *parent);
180 ~StarView() override;
181
182 void readSettings();
183 void writeSettings();
184
185 void update(const Job &job) override;
186 QWidget *widget() const override;
187
188 QString id() const override { return QStringLiteral("star"); }
189
190 QList<HostItem *> hostItems() const;
191 HostItem *findHostItem(unsigned int hostid) const;
192
193 void setMonitor(Monitor *monitor) override;
194
195 void checkNode(unsigned int hostid) override;
196 void removeNode(unsigned int hostid) override;
197 void updateSchedulerState(Monitor::SchedulerState state) override;
198 void configureView() override;
199
200 bool isConfigurable() override { return true; }
201
202 StarViewConfigDialog *configDialog() const;
203
204 /**
205 Return true if node should be shown and false if not.
206 */
207 bool filterArch(unsigned int hostid);
208 /**
209 Return true if node should be shown and false if not.
210 */
211 bool filterArch(HostInfo *);
212
213 protected slots:
214 void slotConfigChanged();
215
216 private:
217 void createKnownHosts();
218 HostItem *createHostItem(unsigned int hostid);
219
220 QGraphicsScene *m_canvas;
221 QScopedPointer<StarViewGraphicsView> m_widget;
222 StarViewConfigDialog *mConfigDialog;
223
224 QMap<unsigned int, HostItem *> m_hostItems;
225 QMap<unsigned int, HostItem *> mJobMap;
226 };
227
228 #endif
229 // vim:ts=4:sw=4:noet