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-2025 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 "../../../backend/cswordmodulesearch.h"
22#include "../../../backend/drivers/cswordmoduleinfo.h"
24
25
26namespace Search {
27
28const int ITEM_TEXT_SIZE = 8;
29
30const int LEGEND_INNER_BORDER = 5;
31const int LEGEND_DELTAY = 4;
32
33
34void CSearchAnalysisLegendItem::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) {
35 painter->save();
36
37 //the outer rectangle
38 #define S(...) static_cast<int>(__VA_ARGS__)
39 QPoint p1(S(rect().x()), S(rect().y()));
40 QPoint p2(S(rect().x() + rect().width()), S(rect().y() + rect().height()));
41 QRect r(p1, p2);
42 r = r.normalized();
43 painter->drawRect(r);
44
45 QFont f = painter->font();
46 f.setPointSize(ITEM_TEXT_SIZE);
47 painter->setFont(f);
48
49 // for (unsigned int index=0; index < m_moduleList->count(); index++){
50 int moduleIndex = 0;
51 for (auto const & result : *m_results) {
52 auto const * const m = result.module;
53 // the module color indicators
54 QPoint p1(S(rect().x()) + LEGEND_INNER_BORDER, S(rect().y()) + LEGEND_INNER_BORDER + moduleIndex*(LEGEND_DELTAY + ITEM_TEXT_SIZE));
55 #undef S
56 QPoint p2(p1.x() + ITEM_TEXT_SIZE, p1.y() + ITEM_TEXT_SIZE);
57 QRect r(p1, p2);
58 painter->fillRect(r, QBrush(CSearchAnalysisScene::getColor(moduleIndex)) );
59 r = r.normalized();
60 painter->drawRect(r);
61
62 QPoint p3( p2.x() + LEGEND_INNER_BORDER, p2.y() );
63 painter->drawText(p3, m->name() );
64
65 ++moduleIndex;
66 }
67 painter->restore();
68}
69
70
71}
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