Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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);
285 andreas 66
 
67
        int getWidth() { return mWidth; }
68
        int getHeight() { return mHeight; }
69
        void setTotalWidth(int w);
70
        int getTotalWidth() { return mTotalWidth; }
71
        void setTotalHeight(int h);
72
        int getTotalHeight() { return mTotalHeight; }
73
        void setTotalSize(int w, int h);
74
        void setTotalSize(QSize& size);
287 andreas 75
        void setScaleFactor(const double& factor);
302 andreas 76
        void setWrapItems(bool wrap) { mWrapItems = wrap; }
285 andreas 77
 
289 andreas 78
    signals:
79
        void objectClicked(ulong handle, bool pressed);
80
 
285 andreas 81
    protected:
300 andreas 82
        void mouseMoveEvent(QMouseEvent* event) override;
285 andreas 83
        void mousePressEvent(QMouseEvent* event) override;
84
        void mouseReleaseEvent(QMouseEvent* event) override;
289 andreas 85
        void scrollContentsBy(int dx, int dy) override;
285 andreas 86
 
87
    private:
88
        void init();
287 andreas 89
        int scale(int value);
300 andreas 90
        void setAtom(PGSUBVIEWATOM_T& atom, QLabel *label);
289 andreas 91
        void mouseTimerEvent();
285 andreas 92
 
289 andreas 93
        QWidget *mParent{nullptr};              //>! The parent of this object. This is set to QScrollArea.
94
        QWidget *mMain{nullptr};                //>! The widget containing the items. This is the whole scroll area
95
        QHBoxLayout *mHLayout{nullptr};         //>! If mVertical == FALSE then this layout is used
96
        QVBoxLayout *mVLayout{nullptr};         //>! If mVertical == TRUE then this layout is used
97
        int mWidth{0};                          //>! Width of visible part of scroll area (QScrollArea)
98
        int mHeight{0};                         //>! Height of visible part of scroll area (QScrollArea)
99
        int mTotalWidth{0};                     //>! Total width of scroll area (mMain)
100
        int mTotalHeight{0};                    //>! Total height of of scroll area (mMain)
101
        bool mVertical{false};                  //>! Direction
102
        int mSpace{0};                          //>! Optional: The space between the items in percent
103
        bool mMousePress{false};                //>! Internal: TRUE when the mouse was pressed
104
        bool mClick{false};                     //>! TRUE on mouse press, FALSE on mouse release
105
        bool mMouseScroll{false};               //>! Internal: TRUE if scrolling was detected. This prevents a button press from beeing one.
106
        QPointF mOldPoint;                      //>! Internal: The last point where the mouse was pressed
107
        double mScaleFactor{1.0};               //>! If != 1.0 and > 0.0 then mTotalHeight and mTotalWidth are scaled as well as the size of each item
108
        std::vector<PGSUBVIEWITEM_T> mItems;    //>! The list of items
109
        std::vector<QWidget *> mMainWidgets;    //>! The QWidget for each item.
110
        int mActPosition{0};                    //>! The absolute top/left (depends on mVertical) position in the scrolling area.
111
        QTimer *mMousePressTimer{nullptr};      //>! Internal: Used to distinguish between a real mouse click and a mouse move.
112
        QPoint mLastMousePress;                 //>! Internal: The absolute point of the last mouse press.
300 andreas 113
        Button::SUBVIEW_POSITION_t mPosition{Button::SVP_CENTER};   //>! Defines where the anchor should snap in
114
        bool mScrollbar{false};                 //>! TRUE = scrollbar is visible
115
        int mScrollbarOffset{0};                //>! Defines the offset of the scrollbar. Only valid if \b mScrollbar is TRUE.
302 andreas 116
        bool mWrapItems{false};                 //>! TRUE = The scroll area behaves like a wheel (not supported) and the item according to the anchor position is displayed.
285 andreas 117
};
118
 
119
#endif