22 #include <QtGui/QApplication>
23 #include <QtGui/QImage>
24 #include <QtGui/QFont>
25 #include <QtGui/QFontMetrics>
26 #include <QtGui/QPainter>
30 #include <KGlobalSettings>
35 #define SINCOS_H_IMPLEMENTATION (1)
48 const int fmh = QFontMetrics(QFont()).height();
49 const int fmhD4 = fmh / 4;
55 delete [] m_signature;
60 delete [] m_signature;
63 m_visibleDepth = Config::defaultRingDepth;
69 QApplication::setOverrideCursor(Qt::WaitCursor);
73 delete [] m_signature;
74 Builder builder(
this, tree, refresh);
85 QApplication::restoreOverrideCursor();
88 void RadialMap::Map::setRingBreadth()
92 m_ringBreadth = (height() - MAP_2MARGIN) / (2 * m_visibleDepth + 4);
107 #define cw rect.width()
108 #define ch rect.height()
112 uint size = ((
cw <
ch) ?
cw :
ch) - MAP_2MARGIN;
124 m_rect.setRect(0,0,size,size);
126 m_pixmap = QPixmap(m_rect.size());
131 if (m_signature != NULL)
148 void RadialMap::Map::colorise()
152 double contrast = (double)Config::contrast / (
double)100;
153 int h, s1, s2, v1, v2;
155 QColor kdeColour[2] = { KGlobalSettings::inactiveTitleColor(), KGlobalSettings::activeTitleColor() };
157 double deltaRed = (double)(kdeColour[0].red() - kdeColour[1].red()) / 2880;
158 double deltaGreen = (double)(kdeColour[0].green() - kdeColour[1].green()) / 2880;
159 double deltaBlue = (double)(kdeColour[0].blue() - kdeColour[1].blue()) / 2880;
161 for (uint i = 0; i <= m_visibleDepth; ++i, darkness += 0.04)
163 for (
Iterator<Segment> it = m_signature[i].iterator(); it != m_signature[i].end(); ++it)
166 if ((*it)->file()->name() == QLatin1String(
"Used")) {
167 cb = QApplication::palette().highlight().color();
168 cb.getHsv(&h, &s1, &v1);
173 v2 = v1 - int(contrast * v1);
174 s2 = s1 + int(contrast * (255 - s1));
176 cb.setHsv(h, s1, v1);
177 cp.setHsv(h, s2, v2);
185 (*it)->setPalette(cp, cb);
189 switch (Config::scheme)
196 int a = (*it)->start();
198 if (a > 2880) a = 2880 - (a - 2880);
200 h = (int)(deltaRed * a) + kdeColour[1].red();
201 s1 = (int)(deltaGreen * a) + kdeColour[1].green();
202 v1 = (int)(deltaBlue * a) + kdeColour[1].blue();
204 cb.setRgb(h, s1, v1);
205 cb.getHsv(&h, &s1, &v1);
212 cb.setHsv(180, 0,
int(255.0 * contrast));
213 (*it)->setPalette(cp, cb);
217 h = int((*it)->start() / 16);
219 v1 = (int)(255.0 / darkness);
222 v2 = v1 - int(contrast * v1);
223 s2 = s1 + int(contrast * (255 - s1));
225 if (s1 < 80) s1 = 80;
229 cb.setHsv(h, s2, (v2 < 90) ? 90 : v2);
230 cp.setHsv(h, 17, v1);
232 else if (!(*it)->file()->isFolder())
234 cb.setHsv(h, 17, v1);
235 cp.setHsv(h, 17, v2);
239 cb.setHsv(h, s1, v1);
240 cp.setHsv(h, s2, v2);
243 (*it)->setPalette(cp, cb);
259 void RadialMap::Map::paint(
bool antialias)
261 KColorScheme scheme(QPalette::Active, KColorScheme::View);
266 rect.adjust(5, 5, -5, -5);
267 m_pixmap.fill(scheme.background().color());
275 if (m_pixmap.isNull())
278 if (!paint.begin(&m_pixmap)) {
279 kWarning() <<
"Failed to initialize painting, returning...";
283 if (antialias && Config::antialias) {
284 paint.translate(0.7, 0.7);
285 paint.setRenderHint(QPainter::Antialiasing);
288 int step = m_ringBreadth;
293 excess = rect.width() % m_ringBreadth;
298 for (
int x = m_visibleDepth; x >= 0; --x)
300 int width = rect.width() / 2;
302 uint a_max = int(acos((
double)width /
double((width + 5))) * (180*16 /
M_PI));
309 paint.setPen((*it)->pen());
311 if ((*it)->hasHiddenChildren())
315 QPoint pos, cpos = rect.center();
316 uint a[3] = { (*it)->start(), (*it)->length(), 0 };
318 a[2] = a[0] + (a[1] / 2);
322 a[0] = a[2] - a_max / 2;
327 for (
int i = 0, radius = width; i < 3; ++i)
329 double ra =
M_PI/(180*16) * a[i], sinra, cosra;
333 sincos(ra, &sinra, &cosra);
334 pos.rx() = cpos.x() +
static_cast<int>(cosra * radius);
335 pos.ry() = cpos.y() -
static_cast<int>(sinra * radius);
336 pts.setPoint(i, pos);
339 paint.setBrush((*it)->pen());
340 paint.drawPolygon(pts);
343 paint.setBrush((*it)->brush());
344 paint.drawPie(rect, (*it)->start(), (*it)->length());
346 if ((*it)->hasHiddenChildren())
350 QPen pen = paint.pen();
356 rect2.adjust(width, width, -width, -width);
357 paint.drawArc(rect2, (*it)->start(), (*it)->length());
368 rect.adjust(step, step, -step, -step);
373 paint.setPen(scheme.foreground().color());
374 paint.setBrush(scheme.background().color());
375 paint.drawEllipse(rect);
376 paint.drawText(rect, Qt::AlignCenter, m_centerText);
378 m_innerRadius = rect.width() / 2;
QString humanReadableSize() const
bool resize(const QRect &)
http QObject const QList< QVariant > m_summary(0)
void make(const Folder *, bool=false)
#define DEFAULT_RING_DEPTH
void sincos(double angleRadians, double *Sin, double *Cos)