SILICON
Loading...
Searching...
No Matches
textItem.hpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2025. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#pragma once
19
20#include <string>
21#include <string_view>
22
23#include <QApplication>
24#include <QFontMetrics>
25#include <QGraphicsItem>
26#include <QPainter>
27#include <QPointF>
28#include <QRectF>
29
30
31namespace SILICON::ui {
32class TextItem : public QGraphicsItem {
33public:
34 explicit TextItem(std::string_view text, QGraphicsItem* parent = nullptr);
35
36 void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
37 QWidget* widget) override;
38
39 QRectF boundingRect() const override { return this->rect; }
40
41 void setText(std::string_view text);
42 void setCenterPos(const QPointF pos) { this->setPos(pos - this->rect.center()); }
43
44private:
45 QRectF rect;
46 QString text;
47};
48
49} // namespace SILICON::ui
void setCenterPos(const QPointF pos)
Definition textItem.hpp:42
void setText(std::string_view text)
Definition textItem.cpp:29
QRectF boundingRect() const override
Definition textItem.hpp:39
TextItem(std::string_view text, QGraphicsItem *parent=nullptr)
Definition textItem.cpp:24
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override