Mantid
Loading...
Searching...
No Matches
qt
widgets
common
src
WidgetScrollbarDecorator.cpp
Go to the documentation of this file.
1
// Mantid Repository : https://github.com/mantidproject/mantid
2
//
3
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
// NScD Oak Ridge National Laboratory, European Spallation Source,
5
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
//----------------------------------
8
// Includes
9
//----------------------------------
10
#include "
MantidQtWidgets/Common/WidgetScrollbarDecorator.h
"
11
12
#include <QMainWindow>
13
14
using namespace
MantidQt::API
;
15
16
//-----------------------------------------------------------------------------
22
WidgetScrollbarDecorator::WidgetScrollbarDecorator
(QWidget *target) : m_target(target), m_enabled(false) {
23
// Off-screen widget to hold layout/widgets when scrolling disabled
24
m_offscreen
=
new
QWidget(
nullptr
);
25
26
// This layout replaces dialog's main layout when scrolling enabled
27
m_layout
=
new
QVBoxLayout(
m_offscreen
);
28
m_layout
->setSpacing(0);
29
m_layout
->setMargin(0);
30
31
// QScrollArea provides scrolling functionality
32
m_scrollarea
=
new
QScrollArea(
m_offscreen
);
33
m_scrollarea
->setFrameStyle(QFrame::NoFrame);
34
m_layout
->addWidget(
m_scrollarea
);
35
36
// Viewport represents the inside of QScrollArea
37
// It will take over parentship of the layout and widgets of the target
38
m_viewport
=
new
QWidget(
m_scrollarea
);
39
m_scrollarea
->setWidget(
m_viewport
);
40
m_scrollarea
->setWidgetResizable(
true
);
41
42
// With QMainWindows we must work on the centralWidget instead
43
auto
mainwindow =
dynamic_cast<
QMainWindow *
>
(
m_target
);
44
if
(mainwindow)
45
m_target
= mainwindow->centralWidget();
46
}
47
48
//-----------------------------------------------------------------------------
50
WidgetScrollbarDecorator::~WidgetScrollbarDecorator
() {
51
// Must be deleted manually since it has no parent
52
delete
m_offscreen
;
53
}
54
55
//-----------------------------------------------------------------------------
61
bool
WidgetScrollbarDecorator::enabled
()
const
{
return
m_enabled
; }
62
63
//-----------------------------------------------------------------------------
87
void
WidgetScrollbarDecorator::setEnabled
(
bool
enable) {
88
// Only enable if scrollbars were previously disabled
89
if
(enable && !
enabled
()) {
90
m_viewport
->setLayout(
m_target
->layout());
91
m_target
->setLayout(
m_layout
);
92
}
93
94
// Only disable if scrollbars were previously enabled
95
if
(!enable &&
enabled
()) {
96
m_offscreen
->setLayout(
m_target
->layout());
97
m_target
->setLayout(
m_viewport
->layout());
98
}
99
100
m_enabled
= enable;
101
}
102
103
//-----------------------------------------------------------------------------
116
void
WidgetScrollbarDecorator::setThresholdWidth
(
int
width) {
m_viewport
->setMinimumWidth(width); }
117
118
//-----------------------------------------------------------------------------
131
void
WidgetScrollbarDecorator::setThresholdHeight
(
int
height
) {
m_viewport
->setMinimumHeight(
height
); }
132
133
//-----------------------------------------------------------------------------
147
void
WidgetScrollbarDecorator::setThresholdSize
(
int
width,
int
height
) {
m_viewport
->setMinimumSize(width,
height
); }
height
double height
Definition:
GetAllEi.cpp:155
WidgetScrollbarDecorator.h
MantidQt::API::WidgetScrollbarDecorator::~WidgetScrollbarDecorator
virtual ~WidgetScrollbarDecorator()
Destructor.
Definition:
WidgetScrollbarDecorator.cpp:50
MantidQt::API::WidgetScrollbarDecorator::setThresholdSize
void setThresholdSize(int width, int height)
Set the size, in pixels, at which scrollbars should appear.
Definition:
WidgetScrollbarDecorator.cpp:147
MantidQt::API::WidgetScrollbarDecorator::m_target
QWidget * m_target
The target widget that is given scrollbars.
Definition:
WidgetScrollbarDecorator.h:106
MantidQt::API::WidgetScrollbarDecorator::m_offscreen
QWidget * m_offscreen
Used to hold above widgets when disabled.
Definition:
WidgetScrollbarDecorator.h:104
MantidQt::API::WidgetScrollbarDecorator::m_layout
QVBoxLayout * m_layout
Main layout used when scrollable.
Definition:
WidgetScrollbarDecorator.h:101
MantidQt::API::WidgetScrollbarDecorator::WidgetScrollbarDecorator
WidgetScrollbarDecorator(QWidget *target)
Constructor.
Definition:
WidgetScrollbarDecorator.cpp:22
MantidQt::API::WidgetScrollbarDecorator::m_viewport
QWidget * m_viewport
Single widget inside QScrollArea.
Definition:
WidgetScrollbarDecorator.h:103
MantidQt::API::WidgetScrollbarDecorator::enabled
bool enabled() const
Check whether the target is currently scrollable.
Definition:
WidgetScrollbarDecorator.cpp:61
MantidQt::API::WidgetScrollbarDecorator::m_enabled
bool m_enabled
Whether the target is currently scrollable.
Definition:
WidgetScrollbarDecorator.h:107
MantidQt::API::WidgetScrollbarDecorator::setEnabled
void setEnabled(bool enable)
Enable or disable scrollable behaviour.
Definition:
WidgetScrollbarDecorator.cpp:87
MantidQt::API::WidgetScrollbarDecorator::m_scrollarea
QScrollArea * m_scrollarea
Used to provide scrolling functionality.
Definition:
WidgetScrollbarDecorator.h:102
MantidQt::API::WidgetScrollbarDecorator::setThresholdHeight
void setThresholdHeight(int height)
Set the height, in pixels, at which scrollbars should appear.
Definition:
WidgetScrollbarDecorator.cpp:131
MantidQt::API::WidgetScrollbarDecorator::setThresholdWidth
void setThresholdWidth(int width)
Set the width, in pixels, at which scrollbars should appear.
Definition:
WidgetScrollbarDecorator.cpp:116
MantidQt::API
Definition:
AlgorithmDialog.h:62
Generated on Tue Jan 3 2023 11:58:02 for Mantid by
1.9.5