PeriDyno 1.0.0
Loading...
Searching...
No Matches
Page.cpp
Go to the documentation of this file.
1/*
2 TabToolbar - a small utility library for Qt, providing tabbed toolbars
3 Copyright (C) 2018 Oleksii Sierov
4
5 TabToolbar is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 TabToolbar is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TabToolbar. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include <QHBoxLayout>
19#include <QScrollArea>
20#include <QSpacerItem>
21#include <QFrame>
22#include <QVariant>
23#include <QWheelEvent>
24#include <QScrollBar>
25#include <QEvent>
26#include "TabToolbar.h"
27#include "Page.h"
28#include "Group.h"
29#include <stdexcept>
30
31using namespace tt;
32
33namespace
34{
35class TTScroller : public QObject
36{
37public:
38 TTScroller(QObject* parent) : QObject(parent) {}
39
40protected:
41 bool eventFilter(QObject* watched, QEvent* event) override
42 {
43 if(event->type() == QEvent::Wheel)
44 {
45 QScrollArea* scroll = static_cast<QScrollArea*>(watched);
46 QWheelEvent* wheel = static_cast<QWheelEvent*>(event);
47 QScrollBar* scrollbar = scroll->horizontalScrollBar();
48 scrollbar->setValue(scrollbar->value() - wheel->angleDelta().y()/5);
49 return true;
50 }
51 return QObject::eventFilter(watched, event);
52 }
53};
54}
55
56Page::Page(int index, const QString& pageName, QWidget* parent)
57 : QWidget(parent),
58 myIndex(index)
59{
60 setObjectName(pageName);
61 setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
62 setContentsMargins(0, 0, 0, 0);
63 QHBoxLayout* l = new QHBoxLayout(this);
64 l->setContentsMargins(0, 0, 0, 0);
65 l->setSpacing(0);
66 setLayout(l);
67
68 QScrollArea* scrollArea = new QScrollArea(this);
69 scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
70 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
71 scrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
72 scrollArea->setFrameShape(QFrame::NoFrame);
73 scrollArea->setFrameShadow(QFrame::Plain);
74 scrollArea->setLineWidth(0);
75 scrollArea->setWidgetResizable(true);
76 scrollArea->installEventFilter(new TTScroller(scrollArea));
77 innerArea = new QWidget();
78 innerArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
79 innerArea->setProperty("TTPage", QVariant(true));
80 innerLayout = new QHBoxLayout(innerArea);
81 innerLayout->setContentsMargins(0, 0, 0, 0);
82 innerLayout->setSpacing(2);
83
84 QSpacerItem* spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
85 innerLayout->addItem(spacer);
86
87 scrollArea->setWidget(innerArea);
88 l->addWidget(scrollArea);
89}
90
91Group* Page::AddGroup(const QString& name)
92{
93 Group* grp = new Group(name, innerArea);
94 innerLayout->insertWidget(innerLayout->count()-1, grp);
95
96 auto* parentTT = _FindTabToolbarParent(*this);
97 if (!parentTT)
98 throw std::runtime_error("Page should be constructed inside TabToolbar!");
99
100 parentTT->AdjustVerticalSize(grp->height());
101 return grp;
102}
103
105{
106 emit Hiding(myIndex);
107}
108
110{
111 emit Showing(myIndex);
112}
void show()
Definition Page.cpp:109
const int myIndex
Definition Page.h:49
QWidget * innerArea
Definition Page.h:51
Page(int index, const QString &pageName, QWidget *parent=nullptr)
Definition Page.cpp:56
void Hiding(int index)
Group * AddGroup(const QString &name)
Definition Page.cpp:91
void hide()
Definition Page.cpp:104
void Showing(int index)
QHBoxLayout * innerLayout
Definition Page.h:50
Definition Builder.h:33
TabToolbar * _FindTabToolbarParent(QWidget &startingWidget)