| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2007 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
#ifndef GUI_FLAG_H |
| 25 |
#define GUI_FLAG_H |
| 26 |
|
| 27 |
#include <QLayout> |
| 28 |
#include <QOpenGLWidget> |
| 29 |
#include <QRect> |
| 30 |
#include <QWidgetItem> |
| 31 |
#include <Inventor/SbVec3f.h> |
| 32 |
#include <Gui/GLPainter.h> |
| 33 |
|
| 34 |
namespace Gui |
| 35 |
{ |
| 36 |
class View3DInventorViewer; |
| 37 |
|
| 38 |
/** |
| 39 |
* @author Werner Mayer |
| 40 |
*/ |
| 41 |
class GuiExport Flag: public QOpenGLWidget |
| 42 |
{ |
| 43 |
Q_OBJECT |
| 44 |
|
| 45 |
public: |
| 46 |
Flag(QWidget* parent = nullptr); |
| 47 |
~Flag() override; |
| 48 |
|
| 49 |
QSize sizeHint() const override; |
| 50 |
void setOrigin(const SbVec3f&); |
| 51 |
const SbVec3f& getOrigin() const; |
| 52 |
void drawLine(Gui::View3DInventorViewer*, int tox, int toy); |
| 53 |
void setText(const QString&); |
| 54 |
|
| 55 |
protected: |
| 56 |
void initializeGL() override; |
| 57 |
void resizeGL(int width, int height) override; |
| 58 |
void paintGL() override; |
| 59 |
|
| 60 |
void paintEvent(QPaintEvent*) override; |
| 61 |
void mouseMoveEvent(QMouseEvent*) override; |
| 62 |
void mousePressEvent(QMouseEvent*) override; |
| 63 |
void resizeEvent(QResizeEvent*) override; |
| 64 |
void contextMenuEvent(QContextMenuEvent*) override; |
| 65 |
|
| 66 |
private: |
| 67 |
QString text; |
| 68 |
SbVec3f coord; |
| 69 |
QPoint dragPosition; |
| 70 |
}; |
| 71 |
|
| 72 |
|
| 73 |
class FlagLayout: public QLayout |
| 74 |
{ |
| 75 |
Q_OBJECT |
| 76 |
|
| 77 |
public: |
| 78 |
enum Position |
| 79 |
{ |
| 80 |
TopLeft, |
| 81 |
TopRight, |
| 82 |
BottomLeft, |
| 83 |
BottomRight |
| 84 |
}; |
| 85 |
|
| 86 |
FlagLayout(QWidget* parent, int margin = 0, int spacing = -1); |
| 87 |
FlagLayout(int spacing = -1); |
| 88 |
~FlagLayout() override; |
| 89 |
|
| 90 |
void addItem(QLayoutItem* item) override; |
| 91 |
void addWidget(QWidget* widget, Position position); |
| 92 |
Qt::Orientations expandingDirections() const override; |
| 93 |
bool hasHeightForWidth() const override; |
| 94 |
int count() const override; |
| 95 |
QLayoutItem* itemAt(int index) const override; |
| 96 |
QSize minimumSize() const override; |
| 97 |
void setGeometry(const QRect& rect) override; |
| 98 |
QSize sizeHint() const override; |
| 99 |
QLayoutItem* takeAt(int index) override; |
| 100 |
|
| 101 |
void add(QLayoutItem* item, Position position); |
| 102 |
|
| 103 |
private: |
| 104 |
struct ItemWrapper |
| 105 |
{ |
| 106 |
ItemWrapper(QLayoutItem* i, Position p) |
| 107 |
{ |
| 108 |
item = i; |
| 109 |
position = p; |
| 110 |
} |
| 111 |
|
| 112 |
QLayoutItem* item; |
| 113 |
Position position; |
| 114 |
}; |
| 115 |
|
| 116 |
enum SizeType |
| 117 |
{ |
| 118 |
MinimumSize, |
| 119 |
SizeHint |
| 120 |
}; |
| 121 |
QSize calculateSize(SizeType sizeType) const; |
| 122 |
|
| 123 |
QList<ItemWrapper*> list; |
| 124 |
}; |
| 125 |
|
| 126 |
class GuiExport GLFlagWindow: public Gui::GLGraphicsItem |
| 127 |
{ |
| 128 |
TYPESYSTEM_HEADER_WITH_OVERRIDE(); |
| 129 |
|
| 130 |
public: |
| 131 |
GLFlagWindow(View3DInventorViewer*); |
| 132 |
~GLFlagWindow() override; |
| 133 |
void addFlag(Flag* item, FlagLayout::Position pos); |
| 134 |
void removeFlag(Flag* item); |
| 135 |
void deleteFlags(); |
| 136 |
Flag* getFlag(int) const; |
| 137 |
int countFlags() const; |
| 138 |
|
| 139 |
void paintGL() override; |
| 140 |
|
| 141 |
private: |
| 142 |
View3DInventorViewer* _viewer; |
| 143 |
FlagLayout* _flagLayout; |
| 144 |
}; |
| 145 |
|
| 146 |
} // namespace Gui |
| 147 |
|
| 148 |
|
| 149 |
#endif // GUI_FLAG_H |