File indexing completed on 2024-05-19 04:36:39

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2013-2014 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef TIKZ_UI_RULER_H
0021 #define TIKZ_UI_RULER_H
0022 
0023 #include "tikzui_export.h"
0024 
0025 #include <tikz/core/Value.h>
0026 #include <tikz/core/tikz.h>
0027 
0028 #include <QWidget>
0029 #include <QMouseEvent>
0030 #include <QPainter>
0031 
0032 namespace tikz {
0033 namespace ui {
0034 
0035 class TIKZKITUI_EXPORT Ruler : public QWidget
0036 {
0037     Q_OBJECT
0038     Q_PROPERTY(qreal origin READ origin WRITE setOrigin)
0039     Q_PROPERTY(tikz::Unit unit READ unit WRITE setUnit)
0040     Q_PROPERTY(qreal zoom READ zoom WRITE setZoom)
0041 
0042 public:
0043     Ruler(Qt::Orientation orientation, QWidget* parent = nullptr);
0044 
0045     QSize minimumSizeHint() const override;
0046 
0047     Qt::Orientation orientation() const;
0048 
0049     qreal origin() const;
0050 
0051     tikz::Unit unit() const;
0052 
0053     qreal zoom() const;
0054 
0055 public Q_SLOTS:
0056 
0057     void setOrigin(qreal origin);
0058 
0059     void setUnit(tikz::Unit unit);
0060 
0061     void setZoom(qreal zoom);
0062 
0063     void setMousePos(const QPoint & cursorPos);
0064 
0065 protected:
0066     /**
0067      * Reimplement to update mouse position.
0068      */
0069     void mouseMoveEvent(QMouseEvent* event) override;
0070 
0071     /**
0072      * Implement painting of the ruler.
0073      */
0074     void paintEvent(QPaintEvent* event) override;
0075 
0076 private:
0077     /**
0078      * Draw indicator for the current mouse position.
0079      */
0080     void drawMouseTick(QPainter* painter);
0081 
0082     /**
0083      * Returns physical dpi depending on the orientation.
0084      */
0085     qreal physicalDpi() const;
0086 
0087 private:
0088     Qt::Orientation m_orientation;
0089     qreal m_origin;
0090     tikz::Unit m_unit;
0091     qreal m_zoom;
0092     QPoint m_mousePos;
0093 };
0094 
0095 }
0096 }
0097 
0098 #endif // TIKZ_UI_RULER_H
0099 
0100 // kate: indent-width 4; replace-tabs on;