Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
b731b302
Commit
b731b302
authored
Jan 05, 2012
by
Claudio Valerio
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed UBWidgetList resize issue
parent
ca29e0d5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
67 deletions
+54
-67
UBApplicationController.cpp
src/core/UBApplicationController.cpp
+0
-1
UBWidgetList.cpp
src/customWidgets/UBWidgetList.cpp
+49
-63
UBWidgetList.h
src/customWidgets/UBWidgetList.h
+5
-3
No files found.
src/core/UBApplicationController.cpp
View file @
b731b302
...
...
@@ -722,7 +722,6 @@ void UBApplicationController::importFile(const QString& pFilePath)
void
UBApplicationController
::
useMultiScreen
(
bool
use
)
{
mDisplayManager
->
setUseMultiScreen
(
use
);
}
...
...
src/customWidgets/UBWidgetList.cpp
View file @
b731b302
...
...
@@ -10,7 +10,6 @@ UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation,
setObjectName
(
name
);
mOrientation
=
orientation
;
mpContainer
=
new
QWidget
(
this
);
mWidgets
.
clear
();
mpEmptyLabel
=
new
QLabel
(
this
);
mpEmptyLabel
->
setObjectName
(
"emptyString"
);
...
...
@@ -18,12 +17,13 @@ UBWidgetList::UBWidgetList(QWidget* parent, eWidgetListOrientation orientation,
setVerticalScrollBarPolicy
(
Qt
::
ScrollBarAsNeeded
);
setHorizontalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOff
);
mpLayout
=
new
QVBoxLayout
(
mpContainer
);
mpContainer
->
resize
(
width
(),
mpContainer
->
height
());
}
else
{
mpContainer
->
resize
(
mpContainer
->
width
(),
mpContainer
->
height
());
}
else
{
setHorizontalScrollBarPolicy
(
Qt
::
ScrollBarAsNeeded
);
setVerticalScrollBarPolicy
(
Qt
::
ScrollBarAlwaysOff
);
mpLayout
=
new
QHBoxLayout
(
mpContainer
);
mpContainer
->
resize
(
mpContainer
->
width
(),
height
());
mpContainer
->
resize
(
mpContainer
->
width
(),
mpContainer
->
height
());
}
mpLayout
->
setContentsMargins
(
margin
(),
margin
(),
margin
(),
margin
());
mpContainer
->
setLayout
(
mpLayout
);
...
...
@@ -50,8 +50,8 @@ void UBWidgetList::addWidget(QWidget *widget)
{
if
(
NULL
!=
mpLayout
){
mpEmptyLabel
->
setVisible
(
false
);
mWidget
s
<<
widget
;
update
Size
(
true
,
widget
);
mWidget
Info
[
widget
]
=
widget
->
size
()
;
update
View
(
size
()
);
mpLayout
->
addWidget
(
widget
);
}
}
...
...
@@ -60,82 +60,68 @@ void UBWidgetList::removeWidget(QWidget *widget)
{
if
(
NULL
!=
mpLayout
){
mpLayout
->
removeWidget
(
widget
);
mWidgets
.
remove
(
mWidgets
.
indexOf
(
widget
));
updateSize
(
false
,
widget
);
mWidgetInfo
.
remove
(
widget
);
widget
->
setVisible
(
false
);
updateView
(
size
());
if
(
0
==
mpLayout
->
count
()){
mpEmptyLabel
->
setVisible
(
true
);
}
}
}
void
UBWidgetList
::
updateSize
(
bool
widgetAdded
,
QWidget
*
widget
)
{
float
scaleFactor
;
int
newWidgetWidth
;
int
newWidgetHeight
;
if
(
eWidgetListOrientation_Vertical
==
mOrientation
){
scaleFactor
=
(
float
)
widget
->
width
()
/
(
float
)
mpContainer
->
width
();
}
else
{
scaleFactor
=
(
float
)
widget
->
height
()
/
(
float
)
mpContainer
->
height
();
}
newWidgetWidth
=
widget
->
width
()
/
scaleFactor
;
newWidgetHeight
=
widget
->
height
()
/
scaleFactor
;
widget
->
resize
(
newWidgetWidth
,
newWidgetHeight
);
// Now we have to update the container
int
UBWidgetList
::
scaleWidgets
(
QSize
pSize
)
{
int
result
=
0
;
foreach
(
QWidget
*
eachWidget
,
mWidgetInfo
.
keys
()){
qDebug
()
<<
__FUNCTION__
<<
"eachWidget : "
<<
eachWidget
;
qreal
scaleFactor
=
0
;
int
newWidgetWidth
=
pSize
.
width
();
int
newWidgetHeight
=
pSize
.
height
();
if
(
eWidgetListOrientation_Vertical
==
mOrientation
){
if
(
widgetAdded
){
mpContainer
->
resize
(
mpContainer
->
width
(),
mpContainer
->
height
()
+
newWidgetHeight
);
scaleFactor
=
(
float
)
mWidgetInfo
[
eachWidget
].
width
()
/
(
float
)
pSize
.
width
();
qDebug
()
<<
__FUNCTION__
<<
"scale factor: "
<<
scaleFactor
;
newWidgetHeight
=
mWidgetInfo
[
eachWidget
].
height
()
/
scaleFactor
;
result
+=
newWidgetHeight
;
}
else
{
mpContainer
->
resize
(
mpContainer
->
width
(),
mpContainer
->
height
()
-
newWidgetHeight
);
}
}
else
{
if
(
widgetAdded
){
mpContainer
->
resize
(
mpContainer
->
width
()
+
newWidgetWidth
,
mpContainer
->
height
());
}
else
{
mpContainer
->
resize
(
mpContainer
->
width
()
-
newWidgetWidth
,
mpContainer
->
height
());
scaleFactor
=
(
float
)
mWidgetInfo
[
eachWidget
].
height
()
/
(
float
)
pSize
.
height
();
newWidgetWidth
=
mWidgetInfo
[
eachWidget
].
width
()
/
scaleFactor
;
result
+=
newWidgetWidth
;
}
}
return
result
;
}
void
UBWidgetList
::
scaleContainer
(
QSize
pSize
,
int
updateValue
)
{
if
(
eWidgetListOrientation_Vertical
==
mOrientation
)
mpContainer
->
resize
(
pSize
.
width
(),
updateValue
);
else
mpContainer
->
resize
(
updateValue
,
pSize
.
height
());
}
void
UBWidgetList
::
updateView
(
QSize
pSize
)
{
// Widgets on list are resized automatically to fit the mpcontainer.
// so if you want to keep the aspect ratio you have to calculate
// the sum of the new widget height and give it to the mpContainer.
// The container resize will trig the widgets resize and the good
// height permits to respect the aspect ratio.
int
updatedValue
=
scaleWidgets
(
pSize
);
scaleContainer
(
pSize
,
updatedValue
);
}
void
UBWidgetList
::
resizeEvent
(
QResizeEvent
*
ev
)
{
mpEmptyLabel
->
setGeometry
((
width
()
-
mpEmptyLabel
->
width
())
/
2
,
(
height
()
-
mpEmptyLabel
->
height
())
/
2
,
mpEmptyLabel
->
width
(),
mpEmptyLabel
->
height
());
if
(
ev
->
oldSize
().
width
()
>=
0
&&
ev
->
oldSize
().
height
()
>=
0
){
float
scale
;
if
(
eWidgetListOrientation_Vertical
==
mOrientation
){
scale
=
(
float
)
ev
->
size
().
width
()
/
(
float
)
ev
->
oldSize
().
width
();
if
(
scale
!=
0
&&
scale
<
10
){
updateAllWidgetsize
(
scale
);
mpContainer
->
resize
(
width
()
-
2
,
mpContainer
->
height
()
*
scale
);
}
}
else
{
scale
=
(
float
)
ev
->
size
().
height
()
/
(
float
)
ev
->
oldSize
().
height
();
if
(
scale
!=
0
&&
scale
<
10
){
updateAllWidgetsize
(
scale
);
mpContainer
->
resize
(
mpContainer
->
width
()
*
scale
,
height
()
-
2
);
}
}
}
}
void
UBWidgetList
::
updateAllWidgetsize
(
float
scale
)
{
for
(
int
i
=
0
;
i
<
mWidgets
.
size
();
i
++
){
mWidgets
.
at
(
i
)
->
resize
(
mWidgets
.
at
(
i
)
->
width
()
*
scale
,
mWidgets
.
at
(
i
)
->
height
()
*
scale
);
}
updateView
(
size
());
}
void
UBWidgetList
::
setMargin
(
int
margin
)
...
...
@@ -157,7 +143,7 @@ void UBWidgetList::setEmptyText(const QString &text)
bool
UBWidgetList
::
empty
()
{
return
mWidget
s
.
empty
();
return
mWidget
Info
.
empty
();
}
// TODO : - add onHover 'delete' button
...
...
src/customWidgets/UBWidgetList.h
View file @
b731b302
...
...
@@ -15,6 +15,7 @@ typedef enum{
eWidgetListOrientation_Horizontal
}
eWidgetListOrientation
;
class
UBWidgetList
:
public
QScrollArea
{
Q_OBJECT
...
...
@@ -33,13 +34,14 @@ protected:
void
resizeEvent
(
QResizeEvent
*
ev
);
private
:
void
updateSize
(
bool
widgetAdded
,
QWidget
*
widget
);
void
updateAllWidgetsize
(
float
scale
);
int
scaleWidgets
(
QSize
pSize
);
void
scaleContainer
(
QSize
pSize
,
int
updateValue
);
void
updateView
(
QSize
pSize
);
QLayout
*
mpLayout
;
QWidget
*
mpContainer
;
eWidgetListOrientation
mOrientation
;
int
mMargin
;
Q
Vector
<
QWidget
*>
mWidgets
;
Q
Map
<
QWidget
*
,
QSize
>
mWidgetInfo
;
QLabel
*
mpEmptyLabel
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment