mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 22:35:27 +00:00
ui: create a RoundRectItem class
Factor out code from ProfileWidget's ToolTipItem, but make the radius of the corners dynamic. Move into backend-shared, though a new ui-shared might be preferred. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
9759d5b21a
commit
b188560ae5
6 changed files with 40 additions and 15 deletions
|
@ -126,6 +126,7 @@ SOURCES += subsurface-mobile-main.cpp \
|
||||||
core/subsurface-qt/divelistnotifier.cpp \
|
core/subsurface-qt/divelistnotifier.cpp \
|
||||||
backend-shared/exportfuncs.cpp \
|
backend-shared/exportfuncs.cpp \
|
||||||
backend-shared/plannershared.cpp \
|
backend-shared/plannershared.cpp \
|
||||||
|
backend-shared/roundrectitem.cpp \
|
||||||
mobile-widgets/qmlinterface.cpp \
|
mobile-widgets/qmlinterface.cpp \
|
||||||
mobile-widgets/qmlmanager.cpp \
|
mobile-widgets/qmlmanager.cpp \
|
||||||
mobile-widgets/themeinterface.cpp \
|
mobile-widgets/themeinterface.cpp \
|
||||||
|
@ -260,6 +261,7 @@ HEADERS += \
|
||||||
core/subsurface-qt/divelistnotifier.h \
|
core/subsurface-qt/divelistnotifier.h \
|
||||||
backend-shared/exportfuncs.h \
|
backend-shared/exportfuncs.h \
|
||||||
backend-shared/plannershared.h \
|
backend-shared/plannershared.h \
|
||||||
|
backend-shared/roundrectitem.h \
|
||||||
mobile-widgets/qmlinterface.h \
|
mobile-widgets/qmlinterface.h \
|
||||||
mobile-widgets/qmlmanager.h \
|
mobile-widgets/qmlmanager.h \
|
||||||
mobile-widgets/themeinterface.h \
|
mobile-widgets/themeinterface.h \
|
||||||
|
|
|
@ -5,6 +5,8 @@ set(BACKEND_SRCS
|
||||||
exportfuncs.h
|
exportfuncs.h
|
||||||
plannershared.cpp
|
plannershared.cpp
|
||||||
plannershared.h
|
plannershared.h
|
||||||
|
roundrectitem.cpp
|
||||||
|
roundrectitem.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(subsurface_backend_shared STATIC ${BACKEND_SRCS})
|
add_library(subsurface_backend_shared STATIC ${BACKEND_SRCS})
|
||||||
|
|
18
backend-shared/roundrectitem.cpp
Normal file
18
backend-shared/roundrectitem.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#include "roundrectitem.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
|
||||||
|
RoundRectItem::RoundRectItem(double radius, QGraphicsItem *parent) : QGraphicsRectItem(parent),
|
||||||
|
radius(radius)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
painter->setClipRect(option->rect);
|
||||||
|
painter->setPen(pen());
|
||||||
|
painter->setBrush(brush());
|
||||||
|
painter->drawRoundedRect(rect(), radius, radius, Qt::AbsoluteSize);
|
||||||
|
painter->restore();
|
||||||
|
}
|
15
backend-shared/roundrectitem.h
Normal file
15
backend-shared/roundrectitem.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#ifndef ROUNDRECTITEM_H
|
||||||
|
#define ROUNDRECTITEM_H
|
||||||
|
|
||||||
|
#include <QGraphicsRectItem>
|
||||||
|
|
||||||
|
class RoundRectItem : public QGraphicsRectItem {
|
||||||
|
public:
|
||||||
|
RoundRectItem(double radius, QGraphicsItem *parent);
|
||||||
|
private:
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
|
||||||
|
double radius;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -7,7 +7,6 @@
|
||||||
#include "core/settings/qPrefDisplay.h"
|
#include "core/settings/qPrefDisplay.h"
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QStyleOptionGraphicsItem>
|
|
||||||
#include "core/qthelper.h"
|
#include "core/qthelper.h"
|
||||||
|
|
||||||
void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap)
|
void ToolTipItem::addToolTip(const QString &toolTip, const QIcon &icon, const QPixmap& pixmap)
|
||||||
|
@ -133,7 +132,7 @@ void ToolTipItem::expand()
|
||||||
status = EXPANDED;
|
status = EXPANDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolTipItem::ToolTipItem(QGraphicsItem *parent) : QGraphicsRectItem(parent),
|
ToolTipItem::ToolTipItem(QGraphicsItem *parent) : RoundRectItem(parent),
|
||||||
title(new QGraphicsSimpleTextItem(tr("Information"), this)),
|
title(new QGraphicsSimpleTextItem(tr("Information"), this)),
|
||||||
status(COLLAPSED),
|
status(COLLAPSED),
|
||||||
timeAxis(0),
|
timeAxis(0),
|
||||||
|
@ -194,16 +193,6 @@ void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget*)
|
|
||||||
{
|
|
||||||
painter->save();
|
|
||||||
painter->setClipRect(option->rect);
|
|
||||||
painter->setPen(pen());
|
|
||||||
painter->setBrush(brush());
|
|
||||||
painter->drawRoundedRect(rect(), 8, 8, Qt::AbsoluteSize);
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTipItem::persistPos()
|
void ToolTipItem::persistPos()
|
||||||
{
|
{
|
||||||
qPrefDisplay::set_tooltip_position(pos());
|
qPrefDisplay::set_tooltip_position(pos());
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
#ifndef DIVETOOLTIPITEM_H
|
#ifndef DIVETOOLTIPITEM_H
|
||||||
#define DIVETOOLTIPITEM_H
|
#define DIVETOOLTIPITEM_H
|
||||||
|
|
||||||
#include <QGraphicsRectItem>
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
#include "backend-shared/roundrectitem.h"
|
||||||
#include "core/display.h"
|
#include "core/display.h"
|
||||||
|
|
||||||
class DiveCartesianAxis;
|
class DiveCartesianAxis;
|
||||||
|
@ -18,7 +18,7 @@ class QGraphicsPixmapItem;
|
||||||
/* To use a tooltip, simply ->setToolTip on the QGraphicsItem that you want
|
/* To use a tooltip, simply ->setToolTip on the QGraphicsItem that you want
|
||||||
* or, if it's a "global" tooltip, set it on the mouseMoveEvent of the ProfileGraphicsView.
|
* or, if it's a "global" tooltip, set it on the mouseMoveEvent of the ProfileGraphicsView.
|
||||||
*/
|
*/
|
||||||
class ToolTipItem : public QObject, public QGraphicsRectItem {
|
class ToolTipItem : public QObject, public RoundRectItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
void updateTitlePosition();
|
void updateTitlePosition();
|
||||||
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
|
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
|
||||||
|
@ -45,7 +45,6 @@ public:
|
||||||
void setTimeAxis(DiveCartesianAxis *axis);
|
void setTimeAxis(DiveCartesianAxis *axis);
|
||||||
void setPlotInfo(const plot_info &plot);
|
void setPlotInfo(const plot_info &plot);
|
||||||
void clearPlotInfo();
|
void clearPlotInfo();
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
void setRect(const QRectF &rect);
|
void setRect(const QRectF &rect);
|
||||||
|
|
Loading…
Add table
Reference in a new issue