Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make overlay FPS and clock positionable
* Implement #1068, making the FPS and clock in the overlay positionable like our user-block * Introduce class OverlayPositionableItem to generalize our red draggable anchor to set the position in the overlay settings ** Has a configuration and a display mode; with and without the anchor ** Receives a pointer to the position setting The fps position was already set up to save, the timer not. Use storage names according to the show flags ("time" rather than "clock"). The anchor ("handle") and text-item are added to the scene as independant objects to allow moving the anchor to the bottom/right, at which point the item is prevented from bleeding over the edge (so a linked movement of individual items with custom behavior at the right/bottom edge case). Additional Notes: Using relative values for positioning, the default values are best-effort values. The space between the items (the top value of the FPS) will differ between different screen/scene sizes. The position is saved as a rectangle, even though a point would be enough. Handling of visibility is sub-optimal, but works. (As we use two independent, linked items, we have to implement our own setVisible method, and currently only call in OverlayConfig (when using config mode). It looks like the overlaytext used to create a text pixmap could be replaced by QGraphicsTextItem.
- Loading branch information
Showing
8 changed files
with
152 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
#include "mumble_pch.hpp" | ||
|
||
#include "OverlayPositionableItem.h" | ||
|
||
OverlayPositionableItem::OverlayPositionableItem(QRectF *posPtr, const bool isPositionable) | ||
: m_position(posPtr) | ||
, m_isPositionEditable(isPositionable) | ||
, m_qgeiHandle(NULL) { | ||
} | ||
|
||
OverlayPositionableItem::~OverlayPositionableItem() { | ||
delete m_qgeiHandle; | ||
m_qgeiHandle = NULL; | ||
} | ||
|
||
void OverlayPositionableItem::createPositioningHandle() { | ||
m_qgeiHandle = new QGraphicsEllipseItem(QRectF(-4.0f, -4.0f, 8.0f, 8.0f)); | ||
m_qgeiHandle->setPen(QPen(Qt::darkRed, 0.0f)); | ||
m_qgeiHandle->setBrush(Qt::red); | ||
m_qgeiHandle->setZValue(0.5f); | ||
m_qgeiHandle->setFlag(QGraphicsItem::ItemIsMovable); | ||
m_qgeiHandle->setFlag(QGraphicsItem::ItemIsSelectable); | ||
scene()->addItem(m_qgeiHandle); | ||
m_qgeiHandle->installSceneEventFilter(this); | ||
} | ||
|
||
bool OverlayPositionableItem::sceneEventFilter(QGraphicsItem *watched, QEvent *event ) { | ||
switch (event->type()) { | ||
case QEvent::GraphicsSceneMouseMove: | ||
case QEvent::GraphicsSceneMouseRelease: | ||
QMetaObject::invokeMethod(this, "onMove", Qt::QueuedConnection); | ||
break; | ||
default: | ||
break; | ||
} | ||
return QGraphicsItem::sceneEventFilter(watched, event); | ||
} | ||
|
||
void OverlayPositionableItem::onMove() { | ||
if (m_qgeiHandle == NULL) { | ||
return; | ||
} | ||
|
||
const QRectF &sr = scene()->sceneRect(); | ||
const QPointF &p = m_qgeiHandle->pos(); | ||
|
||
m_position->setX(qBound<qreal>(0.0f, p.x() / sr.width(), 1.0f)); | ||
m_position->setY(qBound<qreal>(0.0f, p.y() / sr.height(), 1.0f)); | ||
|
||
m_qgeiHandle->setPos(m_position->x() * sr.width(), m_position->y() * sr.height()); | ||
|
||
updateRender(); | ||
} | ||
|
||
void OverlayPositionableItem::updateRender() { | ||
const QRectF &sr = scene()->sceneRect(); | ||
// Translate the 0..1 float position to the real scene coordinates (relative to absolute position) | ||
QPoint absPos(iroundf(sr.width() * m_position->x() + 0.5f), iroundf(sr.height() * m_position->y() + 0.5f)); | ||
|
||
if (m_isPositionEditable) { | ||
if (m_qgeiHandle == NULL) { | ||
createPositioningHandle(); | ||
} | ||
m_qgeiHandle->setPos(absPos.x(), absPos.y()); | ||
} | ||
|
||
QRectF br = boundingRect(); | ||
// Limit the position by the elements width (to make sure it is right-/bottom-bound rather than outside of the scene | ||
QPoint maxPos(iroundf(sr.width() - br.width() + 0.5f), iroundf(sr.height() - br.height() + 0.5f)); | ||
int basex = qBound<int>(0, absPos.x(), maxPos.x()); | ||
int basey = qBound<int>(0, absPos.y(), maxPos.y()); | ||
setPos(basex, basey); | ||
} | ||
|
||
void OverlayPositionableItem::setItemVisible(const bool &visible) { | ||
setVisible(visible); | ||
if (m_qgeiHandle != NULL) { | ||
m_qgeiHandle->setVisible(visible); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef MUMBLE_MUMBLE_OVERLAYPOSITIONABLEITEM_H | ||
#define MUMBLE_MUMBLE_OVERLAYPOSITIONABLEITEM_H | ||
|
||
#if QT_VERSION >= 0x050000 | ||
# include <QtWidgets/QGraphicsItem> | ||
#else | ||
# include <QtGui/QGraphicsItem> | ||
#endif | ||
|
||
class OverlayPositionableItem : public QObject, public QGraphicsPixmapItem { | ||
Q_OBJECT | ||
Q_DISABLE_COPY(OverlayPositionableItem); | ||
public: | ||
OverlayPositionableItem(QRectF *posPtr, const bool isPositionable=false); | ||
virtual ~OverlayPositionableItem(); | ||
void updateRender(); | ||
void setItemVisible(const bool &visible); | ||
private: | ||
const bool m_isPositionEditable; | ||
/// Float value between 0 and 1 where 0,0 is top left, and 1,1 is bottom right | ||
QRectF *m_position; | ||
QGraphicsEllipseItem *m_qgeiHandle; | ||
void createPositioningHandle(); | ||
bool sceneEventFilter(QGraphicsItem *, QEvent *) Q_DECL_OVERRIDE; | ||
private slots: | ||
void onMove(); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters