File indexing completed on 2024-05-19 05:42:21

0001 // ct_lvtqtw_graphicsview.h                                     -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #ifndef INCLUDED_LVTQTC_MINIMAP
0021 #define INCLUDED_LVTQTC_MINIMAP
0022 
0023 #include <lvtqtc_export.h>
0024 
0025 #include <QGraphicsView>
0026 #include <memory>
0027 
0028 namespace Codethink::lvtqtc {
0029 
0030 class LVTQTC_EXPORT Minimap : public QGraphicsView
0031 // Visualizes a Tree model and reacts to changes
0032 {
0033     Q_OBJECT
0034   public:
0035     enum MinimapSize {
0036         MINIMAP_SMALL = 10, // 10% of the screen size.
0037         MINIMAP_MEDIUM = 7, // ~15% 0f the screen size
0038         MINIMAP_LARGE = 5 // 20% of the screen size
0039     };
0040 
0041     Minimap(QGraphicsScene *mainScene, QWidget *parent);
0042     ~Minimap() override;
0043 
0044     Q_SIGNAL void focusSceneAt(const QPointF& pos);
0045     void setSceneRect(const QRectF& rect);
0046     void setMapSize(MinimapSize size);
0047     void calculateGeometry();
0048 
0049   protected:
0050     void contextMenuEvent(QContextMenuEvent *ev) override;
0051     void mousePressEvent(QMouseEvent *ev) override;
0052     void mouseMoveEvent(QMouseEvent *ev) override;
0053     void mouseReleaseEvent(QMouseEvent *ev) override;
0054     void drawForeground(QPainter *painter, const QRectF& rect) override;
0055 
0056   private:
0057     struct Private;
0058     std::unique_ptr<Private> d;
0059 };
0060 
0061 } // namespace Codethink::lvtqtc
0062 
0063 #endif