285 |
andreas |
1 |
/*
|
|
|
2 |
* Copyright (C) 2023 by Andreas Theofilu <andreas@theosys.at>
|
|
|
3 |
*
|
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
|
6 |
* the Free Software Foundation; either version 3 of the License, or
|
|
|
7 |
* (at your option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
* GNU General Public License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
|
15 |
* along with this program; if not, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#ifndef __TQSCROLLAREA_H__
|
|
|
20 |
#define __TQSCROLLAREA_H__
|
|
|
21 |
|
|
|
22 |
#include <QScrollArea>
|
|
|
23 |
|
|
|
24 |
#include <vector>
|
|
|
25 |
|
|
|
26 |
#include "tpagemanager.h"
|
|
|
27 |
|
|
|
28 |
QT_BEGIN_NAMESPACE
|
|
|
29 |
class QWidget;
|
300 |
andreas |
30 |
class QLabel;
|
285 |
andreas |
31 |
class QSize;
|
|
|
32 |
class QPixmap;
|
|
|
33 |
class QColor;
|
|
|
34 |
class QVBoxLayout;
|
|
|
35 |
class QHBoxLayout;
|
|
|
36 |
class QPoint;
|
|
|
37 |
QT_END_NAMESPACE
|
|
|
38 |
|
|
|
39 |
class TQScrollArea : public QScrollArea
|
|
|
40 |
{
|
289 |
andreas |
41 |
Q_OBJECT
|
|
|
42 |
|
285 |
andreas |
43 |
public:
|
|
|
44 |
TQScrollArea();
|
|
|
45 |
TQScrollArea(QWidget *parent);
|
|
|
46 |
TQScrollArea(QWidget *parent, int w, int h, bool vertical = false);
|
|
|
47 |
TQScrollArea(QWidget *parent, const QSize& size, bool vertical = false);
|
|
|
48 |
~TQScrollArea();
|
|
|
49 |
|
|
|
50 |
void setObjectName(const QString& name);
|
|
|
51 |
void setSize(int w, int h);
|
|
|
52 |
void setSize(QSize size);
|
|
|
53 |
QSize getSize();
|
300 |
andreas |
54 |
void setScrollbar(bool sb);
|
|
|
55 |
void setScrollbarOffset(int offset);
|
|
|
56 |
void setAnchor(Button::SUBVIEW_POSITION_t position);
|
297 |
andreas |
57 |
void show();
|
285 |
andreas |
58 |
void setBackgroundImage(const QPixmap& pix);
|
|
|
59 |
void setBackGroundColor(QColor color);
|
|
|
60 |
void setSpace(int s);
|
|
|
61 |
int getSpace() { return mSpace; }
|
|
|
62 |
void addItem(PGSUBVIEWITEM_T& item);
|
|
|
63 |
void addItems(std::vector<PGSUBVIEWITEM_T>& items);
|
300 |
andreas |
64 |
void updateItem(PGSUBVIEWITEM_T& item);
|
|
|
65 |
void showItem(ulong handle, int position);
|
318 |
andreas |
66 |
void toggleItem(ulong handle, int position);
|
|
|
67 |
void hideAllItems();
|
|
|
68 |
void hideItem(ulong handle);
|
285 |
andreas |
69 |
|
|
|
70 |
int getWidth() { return mWidth; }
|
|
|
71 |
int getHeight() { return mHeight; }
|
|
|
72 |
void setTotalWidth(int w);
|
|
|
73 |
int getTotalWidth() { return mTotalWidth; }
|
|
|
74 |
void setTotalHeight(int h);
|
|
|
75 |
int getTotalHeight() { return mTotalHeight; }
|
|
|
76 |
void setTotalSize(int w, int h);
|
|
|
77 |
void setTotalSize(QSize& size);
|
287 |
andreas |
78 |
void setScaleFactor(const double& factor);
|
302 |
andreas |
79 |
void setWrapItems(bool wrap) { mWrapItems = wrap; }
|
285 |
andreas |
80 |
|
289 |
andreas |
81 |
signals:
|
|
|
82 |
void objectClicked(ulong handle, bool pressed);
|
|
|
83 |
|
285 |
andreas |
84 |
protected:
|
300 |
andreas |
85 |
void mouseMoveEvent(QMouseEvent* event) override;
|
285 |
andreas |
86 |
void mousePressEvent(QMouseEvent* event) override;
|
|
|
87 |
void mouseReleaseEvent(QMouseEvent* event) override;
|
289 |
andreas |
88 |
void scrollContentsBy(int dx, int dy) override;
|
285 |
andreas |
89 |
|
|
|
90 |
private:
|
318 |
andreas |
91 |
typedef struct _ITEMS_T
|
|
|
92 |
{
|
|
|
93 |
ulong handle{0};
|
|
|
94 |
ulong parent{0};
|
|
|
95 |
int width{0};
|
|
|
96 |
int height{0};
|
|
|
97 |
bool scrollbar{false};
|
|
|
98 |
int scrollbarOffset{0};
|
|
|
99 |
Button::SUBVIEW_POSITION_t position{Button::SVP_CENTER};
|
|
|
100 |
bool wrap{false};
|
|
|
101 |
TColor::COLOR_T bgcolor;
|
|
|
102 |
TBitmap image;
|
|
|
103 |
std::string bounding;
|
|
|
104 |
QWidget *item{nullptr};
|
|
|
105 |
std::vector<PGSUBVIEWATOM_T> atoms;
|
|
|
106 |
|
|
|
107 |
void clear()
|
|
|
108 |
{
|
|
|
109 |
handle = parent = 0;
|
|
|
110 |
width = height = 0;
|
|
|
111 |
bgcolor.alpha = bgcolor.blue = bgcolor.green = bgcolor.red = 0;
|
|
|
112 |
scrollbar = wrap = false;
|
|
|
113 |
scrollbarOffset = 0;
|
|
|
114 |
position = Button::SVP_CENTER;
|
|
|
115 |
image.clear();
|
|
|
116 |
bounding.clear();
|
|
|
117 |
atoms.clear();
|
|
|
118 |
|
|
|
119 |
if (item)
|
|
|
120 |
item->close();
|
|
|
121 |
|
|
|
122 |
item = nullptr;
|
|
|
123 |
}
|
|
|
124 |
}_ITEMS_T;
|
|
|
125 |
|
285 |
andreas |
126 |
void init();
|
287 |
andreas |
127 |
int scale(int value);
|
300 |
andreas |
128 |
void setAtom(PGSUBVIEWATOM_T& atom, QLabel *label);
|
318 |
andreas |
129 |
void refresh();
|
319 |
andreas |
130 |
void setPosition();
|
318 |
andreas |
131 |
void setPosition(QWidget *w, int position);
|
289 |
andreas |
132 |
void mouseTimerEvent();
|
318 |
andreas |
133 |
void _addItems(std::vector<_ITEMS_T>& items, bool intern=false);
|
319 |
andreas |
134 |
void _clearAllItems();
|
318 |
andreas |
135 |
_ITEMS_T subViewItemToItem(PGSUBVIEWITEM_T& item);
|
319 |
andreas |
136 |
void resetSlider(int position=0);
|
320 |
andreas |
137 |
void doMouseEvent();
|
285 |
andreas |
138 |
|
319 |
andreas |
139 |
QWidget *mParent{nullptr}; //!< The parent of this object. This is set to QScrollArea.
|
|
|
140 |
QWidget *mMain{nullptr}; //!< The widget containing the items. This is the whole scroll area
|
|
|
141 |
QHBoxLayout *mHLayout{nullptr}; //!< If mVertical == FALSE then this layout is used
|
|
|
142 |
QVBoxLayout *mVLayout{nullptr}; //!< If mVertical == TRUE then this layout is used
|
|
|
143 |
int mWidth{0}; //!< Width of visible part of scroll area (QScrollArea)
|
|
|
144 |
int mHeight{0}; //!< Height of visible part of scroll area (QScrollArea)
|
|
|
145 |
int mTotalWidth{0}; //!< Total width of scroll area (mMain)
|
|
|
146 |
int mTotalHeight{0}; //!< Total height of of scroll area (mMain)
|
|
|
147 |
bool mVertical{false}; //!< Direction
|
|
|
148 |
int mSpace{0}; //!< Optional: The space between the items in percent
|
|
|
149 |
bool mMousePress{false}; //!< Internal: TRUE when the mouse was pressed
|
|
|
150 |
bool mClick{false}; //!< TRUE on mouse press, FALSE on mouse release
|
|
|
151 |
bool mMouseScroll{false}; //!< Internal: TRUE if scrolling was detected. This prevents a button press from beeing one.
|
|
|
152 |
QPointF mOldPoint; //!< Internal: The last point where the mouse was pressed
|
|
|
153 |
double mScaleFactor{1.0}; //!< If != 1.0 and > 0.0 then mTotalHeight and mTotalWidth are scaled as well as the size of each item
|
|
|
154 |
std::vector<_ITEMS_T> mItems; //!< The list of items
|
|
|
155 |
int mActPosition{0}; //!< The absolute top/left (depends on mVertical) position in the scrolling area.
|
|
|
156 |
int mOldActPosition{0}; //!< Used to store the actual slider position temporary.
|
|
|
157 |
QTimer *mMousePressTimer{nullptr}; //!< Internal: Used to distinguish between a real mouse click and a mouse move.
|
|
|
158 |
QPoint mLastMousePress; //!< Internal: The absolute point of the last mouse press.
|
|
|
159 |
Button::SUBVIEW_POSITION_t mPosition{Button::SVP_CENTER}; //!< Defines where the anchor should snap in
|
|
|
160 |
bool mScrollbar{false}; //!< TRUE = scrollbar is visible
|
|
|
161 |
int mScrollbarOffset{0}; //!< Defines the offset of the scrollbar. Only valid if \b mScrollbar is TRUE.
|
|
|
162 |
bool mWrapItems{false}; //!< TRUE = The scroll area behaves like a wheel (not supported) and the item according to the anchor position is displayed.
|
320 |
andreas |
163 |
bool mMouseTmEventActive{false}; //!< TRUE = the mouse timer event is still running and will not accept calls.
|
|
|
164 |
bool mDoMouseEvent{false}; //!< TRUE = The mouse timer event is valid.
|
285 |
andreas |
165 |
};
|
|
|
166 |
|
|
|
167 |
#endif
|