1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
|
/*
remoteviewwidget.h
This file is part of GammaRay, the Qt application inspection and manipulation tool.
SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Anton Kreuzkamp <anton.kreuzkamp@kdab.com>
SPDX-License-Identifier: GPL-2.0-or-later
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#ifndef GAMMARAY_REMOTEVIEWWIDGET_H
#define GAMMARAY_REMOTEVIEWWIDGET_H
#include "gammaray_ui_export.h"
#include <common/objectid.h>
#include <common/remoteviewframe.h>
#include <QElapsedTimer>
#include <QPointer>
#include <QTouchEvent>
#include <QWidget>
QT_BEGIN_NAMESPACE
class QAbstractItemModel;
class QActionGroup;
class QStandardItemModel;
class QModelIndex;
class QEvent;
class QTouchEvent;
QT_END_NAMESPACE
namespace GammaRay {
class RemoteViewInterface;
class ObjectIdsFilterProxyModel;
class VisibilityFilterProxyModel;
class TrailingColorLabel;
/** Widget showing remote screen content and providing both visual inspection
* capabilities as well as input redirection.
*
* Can be sub-classed to support e.g. custom element decoration.
*/
class GAMMARAY_UI_EXPORT RemoteViewWidget : public QWidget
{
Q_OBJECT
public:
explicit RemoteViewWidget(QWidget *parent = nullptr);
~RemoteViewWidget() override;
/// Set the object name for connecting to the server.
void setName(const QString &name);
enum InteractionMode
{
NoInteraction = 0, ///< disable all
ViewInteraction = 1, ///< panning, zooming, etc
Measuring = 2,
InputRedirection = 4,
ElementPicking = 8,
ColorPicking = 16
};
InteractionMode interactionMode() const;
void setInteractionMode(InteractionMode mode);
Q_DECLARE_FLAGS(InteractionModes, InteractionMode)
InteractionModes supportedInteractionModes() const;
void setSupportedInteractionModes(InteractionModes modes);
/// Returns the current zoom level
double zoom() const;
/// Returns the index of the current zoom level, useful for updating a combo box using the zoomLevelModel.
int zoomLevelIndex() const;
/// Model containing the supported zoom levels, for use with a combo box
QAbstractItemModel *zoomLevelModel() const;
/// Set the message that is shown when remote view is unavailable.
void setUnavailableText(const QString &msg);
/// Action group containing all interaction mode switch actions
QActionGroup *interactionModeActions() const;
QAction *zoomOutAction() const;
QAction *zoomInAction() const;
QAbstractItemModel *pickSourceModel() const;
void setPickSourceModel(QAbstractItemModel *sourceModel);
Q_INVOKABLE virtual void restoreState(const QByteArray &state);
virtual QByteArray saveState() const;
int flagRole() const;
void setFlagRole(int flagRole);
int invisibleMask() const;
void setInvisibleMask(int invisibleMask);
bool hasValidFrame() const;
bool hasValidCompleteFrame() const;
public slots:
/// Clears the current view content.
void reset();
/// Sets the zoom level to the closest level to @p zoom.
void setZoom(double zoom);
/// Sets the zoom level to the level at @p index in the zoom level model.
void setZoomLevel(int index);
void zoomIn();
void zoomOut();
void fitToView();
void centerView();
signals:
void zoomChanged();
void zoomLevelChanged(int zoomLevelIndex);
void interactionModeChanged();
void stateChanged();
void frameChanged();
protected:
/** Current frame data. */
const RemoteViewFrame &frame() const;
RemoteViewInterface *remoteViewInterface() const;
/** Override this to draw element decorations.
* @P p is translated to that 0,0 is the top left corner of the source image, but not scaled
*/
virtual void drawDecoration(QPainter *p);
// translate from view coordinates to source coordinates
QPoint mapToSource(QPoint pos) const;
QPointF mapToSource(QPointF pos) const;
QRectF mapToSource(const QRectF &r) const;
// translates from source coordinates to view coordinates
QPoint mapFromSource(QPoint pos) const;
QPointF mapFromSource(QPointF pos) const;
QRectF mapFromSource(const QRect &rect) const;
// translate from view to source coordinates
QTouchEvent::TouchPoint mapToSource(const QTouchEvent::TouchPoint &point);
void restoreState(QDataStream &stream);
void saveState(QDataStream &stream) const;
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
void enterEvent(QEnterEvent *event) override;
void leaveEvent(QEvent *event) override;
bool eventFilter(QObject *receiver, QEvent *event) override;
bool event(QEvent *event) override;
private:
void setupActions();
void updateActions();
void drawBackground(QPainter *p);
void drawRuler(QPainter *p);
void drawFPS(QPainter *p);
int sourceTickLabelDistance(int viewDistance);
int viewTickLabelDistance() const;
void drawMeasureOverlay(QPainter *p);
void drawMeasurementLabel(QPainter *p, QPoint pos, QPoint dir, const QString &text);
void clampPanPosition();
void sendMouseEvent(QMouseEvent *event);
void sendKeyEvent(QKeyEvent *event);
void sendWheelEvent(QWheelEvent *event);
void sendTouchEvent(QTouchEvent *event);
// size of the content area, ie. excluding the rulers
int contentWidth() const;
int contentHeight() const;
// size of the rulers
int horizontalRulerHeight() const;
int verticalRulerWidth() const;
void updatePickerVisibility() const;
void pickColor() const;
private slots:
void interactionActionTriggered(QAction *action);
void pickElementId(const QModelIndex &index);
void elementsAtReceived(const GammaRay::ObjectIds &ids, int bestCandidate);
void frameUpdated(const GammaRay::RemoteViewFrame &frame);
void enableFPS(const bool showFPS);
void updateUserViewport();
private:
RemoteViewFrame m_frame;
QBrush m_activeBackgroundBrush;
QBrush m_inactiveBackgroundBrush;
QVector<double> m_zoomLevels;
QStandardItemModel *m_zoomLevelModel;
QString m_unavailableText;
QVector<int> m_tickLabelDists;
QActionGroup *m_interactionModeActions;
QAction *m_zoomInAction;
QAction *m_zoomOutAction;
QAction *m_toggleFPSAction;
QPointer<RemoteViewInterface> m_interface;
TrailingColorLabel *m_trailingColorLabel;
double m_zoom;
int m_x; // view translation before zoom
int m_y;
InteractionMode m_interactionMode;
InteractionModes m_supportedInteractionModes;
QPoint m_mouseDownPosition; // semantics depend on interaction mode
QPointF m_currentMousePosition; // in view coordinates
QPoint m_measurementStartPosition; // in source coordinates
QPoint m_measurementEndPosition; // in source coordinates
bool m_hasMeasurement;
ObjectIdsFilterProxyModel *m_pickProxyModel;
VisibilityFilterProxyModel *m_invisibleItemsProxyModel;
bool m_initialZoomDone;
bool m_extraViewportUpdateNeeded;
int m_flagRole;
int m_invisibleMask;
QElapsedTimer m_fpsTimer;
bool m_showFps;
qreal m_fps;
};
}
Q_DECLARE_OPERATORS_FOR_FLAGS(GammaRay::RemoteViewWidget::InteractionModes)
#endif // GAMMARAY_REMOTEVIEWWIDGET_H
|