1 //=========================================================
2 //  MusE
3 //  Linux Music Editor
4 //  Copyright (C) 1999-2011 by Werner Schweer and others
5 //
6 //  scroll_area.cpp
7 //  (C) Copyright 2015 Tim E. Real (terminator356 on sourceforge)
8 //
9 //  This program is free software; you can redistribute it and/or
10 //  modify it under the terms of the GNU General Public License
11 //  as published by the Free Software Foundation; version 2 of
12 //  the License, or (at your option) any later version.
13 //
14 //  This program is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 //  GNU General Public License for more details.
18 //
19 //  You should have received a copy of the GNU General Public License
20 //  along with this program; if not, write to the Free Software
21 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22 //
23 //=========================================================
24 
25 #include <QSize>
26 
27 #include "scroll_area.h"
28 #include "compact_slider.h"
29 
30 namespace MusEGui {
31 
32 //---------------------------------------------------------
33 //   CompactScrollArea
34 //---------------------------------------------------------
35 
CompactScrollArea(QWidget * parent)36 CompactScrollArea::CompactScrollArea(QWidget *parent)
37             : QScrollArea(parent)
38 {
39 }
40 
minimumSizeHint() const41 QSize CompactScrollArea::minimumSizeHint() const
42 {
43   if(widget())
44     return widget()->sizeHint();
45   return QSize(16, 16);
46 }
47 
48 //---------------------------------------------------------
49 //   CompactControllerRack
50 //---------------------------------------------------------
51 
CompactControllerRack(QWidget * parent,int minItems)52 CompactControllerRack::CompactControllerRack(QWidget *parent, int minItems)
53             : QScrollArea(parent), _minItems(minItems)
54 {
55   _xItemMargin = 0;
56   _yItemMargin = 0;
57   _minItemSize = defaultItemSizeHint();
58   _minSize = QSize(_minItemSize.width(), _minItems * _minItemSize.height()); // + 1; // TODO Instead of just +1, may need margins etc?
59 }
60 
minimumSizeHint() const61 QSize CompactControllerRack::minimumSizeHint() const
62 {
63   //return _minSize;
64   const QSize sz = CompactSlider::getMinimumSizeHint(fontMetrics(),
65                                                      Qt::Horizontal,
66                                                      CompactSlider::None,
67                                                      _xItemMargin,
68                                                      _yItemMargin);
69   return QSize(sz.width() + 2 * frameWidth(), _minItems * sz.height() + 2 * frameWidth());
70 }
71 
defaultItemSizeHint()72 QSize CompactControllerRack::defaultItemSizeHint()
73 {
74 //   // HACK: Get some idea of the height of each item - even with an empty scroll area.
75 //   CompactSlider* dummy_slider = new CompactSlider(this, 0, Qt::Horizontal, CompactSlider::None, "WWW");
76 //   dummy_slider->setValueDecimals(0);
77 //   dummy_slider->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum));
78 //   dummy_slider->setEnabled(true);
79 //
80 //   const QSize sz = dummy_slider->sizeHint();
81 //
82 //   delete dummy_slider;
83 //
84 //   return sz;
85 
86   // HACK: Get some idea of the height of each item - even with an empty scroll area.
87   return CompactSlider::getMinimumSizeHint(fontMetrics(), Qt::Horizontal, CompactSlider::None, _xItemMargin, _yItemMargin);
88 }
89 
updateDefaultItemSizeHint()90 void CompactControllerRack::updateDefaultItemSizeHint()
91 {
92   _minItemSize = defaultItemSizeHint();
93   update();
94 }
95 
updateMinimumSize()96 void CompactControllerRack::updateMinimumSize()
97 {
98   _minSize = QSize(_minItemSize.width(), _minItems * _minItemSize.height()); // + 1; // TODO Instead of just +1, may need margins etc?
99   update();
100 }
101 
setMinItems(int n)102 void CompactControllerRack::setMinItems(int n)
103 {
104   _minItems = n;
105   _minItemSize = defaultItemSizeHint();
106   _minSize = QSize(_minItemSize.width(), _minItems * _minItemSize.height()); // + 1; // TODO Instead of just +1, may need margins etc?
107   update();
108 }
109 
setItemMargins(int hor,int vert)110 void CompactControllerRack::setItemMargins(int hor, int vert)
111 {
112   _xItemMargin = hor;
113   _yItemMargin = vert;
114   _minItemSize = defaultItemSizeHint();
115   _minSize = QSize(_minItemSize.width(), _minItems * _minItemSize.height()); // + 1; // TODO Instead of just +1, may need margins etc?
116   //resize(this->size());  // FIXME Call something else like updateGeometry etc.
117   updateGeometry();
118 }
119 
120 } // namespace MusEGui
121