Add overlay visibility toggle

This commit is contained in:
GriffinR 2021-11-30 13:38:06 -05:00 committed by huderlem
parent af4c99537f
commit 5a5d16bdc6
6 changed files with 36 additions and 2 deletions

View file

@ -68,6 +68,9 @@ public:
Q_INVOKABLE void setWidth(int width);
Q_INVOKABLE void setHeight(int height);
Q_INVOKABLE void clearOverlay(int layer = INT_MAX);
Q_INVOKABLE void hideOverlay(int layer = INT_MAX);
Q_INVOKABLE void showOverlay(int layer = INT_MAX);
Q_INVOKABLE void setOverlayVisibility(bool visible, int layer = INT_MAX);
Q_INVOKABLE void addText(QString text, int x, int y, QString color = "#000000", int fontSize = 12, int layer = 0);
Q_INVOKABLE void addRect(int x, int y, int width, int height, QString color = "#000000", int layer = 0);
Q_INVOKABLE void addFilledRect(int x, int y, int width, int height, QString color = "#000000", int layer = 0);

View file

@ -14,6 +14,7 @@ public:
GraphicsView(QWidget *parent) : QGraphicsView(parent) {}
Overlay * getOverlay(int layer);
void clearOverlays();
void setOverlaysHidden(bool hidden);
public:
// GraphicsView_Object object;

View file

@ -75,6 +75,7 @@ public:
~Overlay() {
this->clearItems();
}
void setHidden(bool hidden);
void renderItems(QPainter *painter);
QList<OverlayItem*> getItems();
void clearItems();
@ -83,6 +84,7 @@ public:
bool addImage(int x, int y, QString filepath, int width = -1, int height = -1, unsigned offset = 0, bool hflip = false, bool vflip = false, bool setTransparency = false);
private:
QList<OverlayItem*> items;
bool hidden;
};
#endif // OVERLAY_H

View file

@ -238,6 +238,24 @@ void MainWindow::clearOverlay(int layer) {
this->ui->graphicsView_Map->scene()->update();
}
void MainWindow::hideOverlay(int layer) {
this->setOverlayVisibility(false, layer);
}
void MainWindow::showOverlay(int layer) {
this->setOverlayVisibility(true, layer);
}
void MainWindow::setOverlayVisibility(bool visible, int layer) {
if (!this->ui || !this->ui->graphicsView_Map)
return;
if (layer == INT_MAX)
this->ui->graphicsView_Map->setOverlaysHidden(!visible);
else
this->ui->graphicsView_Map->getOverlay(layer)->setHidden(!visible);
this->ui->graphicsView_Map->scene()->update();
}
void MainWindow::addText(QString text, int x, int y, QString color, int fontSize, int layer) {
if (!this->ui || !this->ui->graphicsView_Map || layer == INT_MAX)
return;

View file

@ -26,6 +26,11 @@ void GraphicsView::clearOverlays() {
overlay->clearItems();
}
void GraphicsView::setOverlaysHidden(bool hidden) {
foreach (Overlay * overlay, this->overlayMap)
overlay->setHidden(hidden);
}
Overlay * GraphicsView::getOverlay(int layer) {
Overlay * overlay = this->overlayMap.value(layer, nullptr);
if (!overlay) {

View file

@ -23,9 +23,10 @@ void OverlayImage::render(QPainter *painter) {
}
void Overlay::renderItems(QPainter *painter) {
for (auto item : this->items) {
if (this->hidden) return;
for (auto item : this->items)
item->render(painter);
}
}
void Overlay::clearItems() {
@ -39,6 +40,10 @@ QList<OverlayItem*> Overlay::getItems() {
return this->items;
}
void Overlay::setHidden(bool hidden) {
this->hidden = hidden;
}
void Overlay::addText(QString text, int x, int y, QString color, int fontSize) {
this->items.append(new OverlayText(text, x, y, QColor(color), fontSize));
}