BibleTime
csearchanalysislegenditem.cpp
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
14 
15 #include <QBrush>
16 #include <QFont>
17 #include <QPainter>
18 #include <QPoint>
19 #include <QRect>
20 #include <QRectF>
21 #include <vector>
22 #include "../../../backend/cswordmodulesearch.h"
23 #include "../../../backend/drivers/cswordmoduleinfo.h"
24 #include "csearchanalysisscene.h"
25 
26 
27 namespace Search {
28 
29 const int ITEM_TEXT_SIZE = 8;
30 
31 const int LEGEND_INNER_BORDER = 5;
32 const int LEGEND_DELTAY = 4;
33 
34 
35 void CSearchAnalysisLegendItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) {
36  painter->save();
37 
38  //the outer rectangle
39  #define S(...) static_cast<int>(__VA_ARGS__)
40  QPoint p1(S(rect().x()), S(rect().y()));
41  QPoint p2(S(rect().x() + rect().width()), S(rect().y() + rect().height()));
42  QRect r(p1, p2);
43  r = r.normalized();
44  painter->drawRect(r);
45 
46  QFont f = painter->font();
47  f.setPointSize(ITEM_TEXT_SIZE);
48  painter->setFont(f);
49 
50  // for (unsigned int index=0; index < m_moduleList->count(); index++){
51  int moduleIndex = 0;
52  for (auto const & result : *m_results) {
53  auto const * const m = result.module;
54  // the module color indicators
55  QPoint p1(S(rect().x()) + LEGEND_INNER_BORDER, S(rect().y()) + LEGEND_INNER_BORDER + moduleIndex*(LEGEND_DELTAY + ITEM_TEXT_SIZE));
56  #undef S
57  QPoint p2(p1.x() + ITEM_TEXT_SIZE, p1.y() + ITEM_TEXT_SIZE);
58  QRect r(p1, p2);
59  painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(moduleIndex)) );
60  r = r.normalized();
61  painter->drawRect(r);
62 
63  QPoint p3( p2.x() + LEGEND_INNER_BORDER, p2.y() );
64  painter->drawText(p3, m->name() );
65 
66  ++moduleIndex;
67  }
68  painter->restore();
69 }
70 
71 
72 }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
CSwordModuleSearch::Results const *const m_results
static QColor getColor(int index)
#define S(...)
QStringList r(content.left(bodyIndex))
const int ITEM_TEXT_SIZE
const int LEGEND_INNER_BORDER