Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
eff5451a
Commit
eff5451a
authored
Apr 04, 2011
by
Sebastian Eichelbaum
Browse files
[MERGE] - merged in GuiExperimental.
parents
a72df849
3ac7351e
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
292 additions
and
2 deletions
+292
-2
src/gui/qt4/CMakeLists.txt
src/gui/qt4/CMakeLists.txt
+1
-0
src/gui/qt4/WGuiConsts.h
src/gui/qt4/WGuiConsts.h
+35
-0
src/gui/qt4/controlPanel/WPropertyBoolWidget.cpp
src/gui/qt4/controlPanel/WPropertyBoolWidget.cpp
+5
-0
src/gui/qt4/controlPanel/WPropertyColorWidget.cpp
src/gui/qt4/controlPanel/WPropertyColorWidget.cpp
+5
-0
src/gui/qt4/controlPanel/WPropertyDoubleWidget.cpp
src/gui/qt4/controlPanel/WPropertyDoubleWidget.cpp
+7
-0
src/gui/qt4/controlPanel/WPropertyFilenameWidget.cpp
src/gui/qt4/controlPanel/WPropertyFilenameWidget.cpp
+5
-0
src/gui/qt4/controlPanel/WPropertyIntWidget.cpp
src/gui/qt4/controlPanel/WPropertyIntWidget.cpp
+9
-0
src/gui/qt4/controlPanel/WPropertyMatrix4X4Widget.cpp
src/gui/qt4/controlPanel/WPropertyMatrix4X4Widget.cpp
+6
-0
src/gui/qt4/controlPanel/WPropertyMatrix4X4Widget.h
src/gui/qt4/controlPanel/WPropertyMatrix4X4Widget.h
+3
-1
src/gui/qt4/controlPanel/WPropertyPositionWidget.cpp
src/gui/qt4/controlPanel/WPropertyPositionWidget.cpp
+5
-0
src/gui/qt4/controlPanel/WPropertySelectionWidget.cpp
src/gui/qt4/controlPanel/WPropertySelectionWidget.cpp
+4
-0
src/gui/qt4/controlPanel/WPropertyStringWidget.cpp
src/gui/qt4/controlPanel/WPropertyStringWidget.cpp
+5
-0
src/gui/qt4/controlPanel/WPropertyTriggerWidget.cpp
src/gui/qt4/controlPanel/WPropertyTriggerWidget.cpp
+5
-0
src/gui/qt4/controlPanel/WPropertyWidget.cpp
src/gui/qt4/controlPanel/WPropertyWidget.cpp
+2
-0
src/gui/qt4/controlPanel/WPropertyWidget.h
src/gui/qt4/controlPanel/WPropertyWidget.h
+3
-1
src/gui/qt4/controlPanel/WQtPropertyGroupWidget.cpp
src/gui/qt4/controlPanel/WQtPropertyGroupWidget.cpp
+17
-0
src/gui/qt4/guiElements/WScaleLabel.cpp
src/gui/qt4/guiElements/WScaleLabel.cpp
+82
-0
src/gui/qt4/guiElements/WScaleLabel.h
src/gui/qt4/guiElements/WScaleLabel.h
+93
-0
No files found.
src/gui/qt4/CMakeLists.txt
View file @
eff5451a
...
...
@@ -19,6 +19,7 @@ SET(GUI_QT4_MOC_HDRS
guiElements/WQtPushButton.h
guiElements/WQtModuleOneToOneCombinerAction.h
guiElements/WQtPropertyBoolAction.h
guiElements/WScaleLabel.h
controlPanel/WPropertyWidget.h
controlPanel/WPropertyBoolWidget.h
controlPanel/WPropertyIntWidget.h
...
...
src/gui/qt4/WGuiConsts.h
0 → 100644
View file @
eff5451a
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WGUICONSTS_H
#define WGUICONSTS_H
#define WGLOBAL_MARGIN 2
#define WGLOBAL_SPACING 5
#define WMIN_LABEL_LENGTH 10
#define WMIN_SLIDER_WIDTH 50
#endif // WGUICONSTS_H
src/gui/qt4/controlPanel/WPropertyBoolWidget.cpp
View file @
eff5451a
...
...
@@ -24,6 +24,7 @@
#include "WPropertyBoolWidget.h"
#include "../WGuiConsts.h"
#include "../../../common/WPropertyVariable.h"
WPropertyBoolWidget
::
WPropertyBoolWidget
(
WPropBool
property
,
QGridLayout
*
propertyGrid
,
QWidget
*
parent
)
:
...
...
@@ -39,10 +40,14 @@ WPropertyBoolWidget::WPropertyBoolWidget( WPropBool property, QGridLayout* prope
// layout both against each other
m_layout
.
addWidget
(
static_cast
<
QWidget
*
>
(
&
m_checkbox
)
);
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
m_parameterWidgets
.
setLayout
(
&
m_layout
);
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout
.
addWidget
(
&
m_asText
);
m_infoLayout
.
setMargin
(
WGLOBAL_MARGIN
);
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
// connect the modification signal of m_checkbox with our callback
...
...
src/gui/qt4/controlPanel/WPropertyColorWidget.cpp
View file @
eff5451a
...
...
@@ -31,6 +31,7 @@
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
#include "../WGuiConsts.h"
#include "WPropertyColorWidget.h"
...
...
@@ -47,9 +48,13 @@ WPropertyColorWidget::WPropertyColorWidget( WPropColor property, QGridLayout* pr
// layout both against each other
m_layout
.
addWidget
(
&
m_button
);
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout
.
addWidget
(
&
m_asText
);
m_infoLayout
.
setMargin
(
WGLOBAL_MARGIN
);
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
// set the initial values
...
...
src/gui/qt4/controlPanel/WPropertyDoubleWidget.cpp
View file @
eff5451a
...
...
@@ -30,6 +30,7 @@
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
#include "../WGuiConsts.h"
#include "WPropertyDoubleWidget.h"
WPropertyDoubleWidget
::
WPropertyDoubleWidget
(
WPropDouble
property
,
QGridLayout
*
propertyGrid
,
QWidget
*
parent
)
:
...
...
@@ -44,13 +45,19 @@ WPropertyDoubleWidget::WPropertyDoubleWidget( WPropDouble property, QGridLayout*
// layout both against each other
m_layout
.
addWidget
(
&
m_slider
);
m_layout
.
addWidget
(
&
m_edit
);
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
m_parameterWidgets
.
setLayout
(
&
m_layout
);
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout
.
addWidget
(
&
m_asText
);
m_infoLayout
.
setMargin
(
WGLOBAL_MARGIN
);
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
m_slider
.
setMinimumWidth
(
WMIN_SLIDER_WIDTH
);
update
();
// connect the modification signal of the edit and slider with our callback
...
...
src/gui/qt4/controlPanel/WPropertyFilenameWidget.cpp
View file @
eff5451a
...
...
@@ -32,6 +32,7 @@
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
#include "../../../common/constraints/WPropertyConstraintTypes.h"
#include "../WGuiConsts.h"
#include "WPropertyFilenameWidget.h"
...
...
@@ -48,9 +49,13 @@ WPropertyFilenameWidget::WPropertyFilenameWidget( WPropFilename property, QGridL
// layout both against each other
m_layout
.
addWidget
(
&
m_button
);
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout
.
addWidget
(
&
m_asText
);
m_infoLayout
.
setMargin
(
WGLOBAL_MARGIN
);
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
// set the initial values
...
...
src/gui/qt4/controlPanel/WPropertyIntWidget.cpp
View file @
eff5451a
...
...
@@ -29,6 +29,7 @@
#include <boost/lexical_cast.hpp>
#include "../WGuiConsts.h"
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
...
...
@@ -46,12 +47,18 @@ WPropertyIntWidget::WPropertyIntWidget( WPropInt property, QGridLayout* property
// layout both against each other
m_layout
.
addWidget
(
&
m_slider
);
m_layout
.
addWidget
(
&
m_edit
);
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
m_parameterWidgets
.
setLayout
(
&
m_layout
);
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout
.
addWidget
(
&
m_asText
);
m_infoLayout
.
setMargin
(
WGLOBAL_MARGIN
);
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
m_slider
.
setMinimumWidth
(
WMIN_SLIDER_WIDTH
);
update
();
// connect the modification signal of the edit and slider with our callback
...
...
@@ -85,6 +92,8 @@ void WPropertyIntWidget::update()
m_slider
.
setMinimum
(
minC
->
getMin
()
);
m_slider
.
setMaximum
(
maxC
->
getMax
()
);
m_slider
.
setValue
(
m_intProperty
->
get
()
);
m_edit
.
setMaximumWidth
(
fontMetrics
().
width
(
QString
::
number
(
-
(
maxC
->
getMax
()
-
minC
->
getMin
()
)
)
)
+
5
);
}
else
{
...
...
src/gui/qt4/controlPanel/WPropertyMatrix4X4Widget.cpp
View file @
eff5451a
...
...
@@ -30,6 +30,8 @@
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
#include "../WGuiConsts.h"
#include "../guiElements/WScaleLabel.h"
#include "WPropertyMatrix4X4Widget.h"
...
...
@@ -61,9 +63,13 @@ WPropertyMatrix4X4Widget::WPropertyMatrix4X4Widget( WPropMatrix4X4 property, QGr
}
m_parameterWidgets
.
setLayout
(
&
m_layout
);
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout
.
addWidget
(
&
m_asText
);
m_infoLayout
.
setMargin
(
WGLOBAL_MARGIN
);
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
update
();
...
...
src/gui/qt4/controlPanel/WPropertyMatrix4X4Widget.h
View file @
eff5451a
...
...
@@ -33,6 +33,8 @@
#include "WPropertyWidget.h"
class
WScaleLabel
;
/**
* Implements a property widget for MATRIX4X4.
*/
...
...
@@ -80,7 +82,7 @@ protected:
/**
* Used to show the property as text.
*/
Q
Label
m_asText
;
WScale
Label
m_asText
;
/**
* The layout used for the pure output (information properties)
...
...
src/gui/qt4/controlPanel/WPropertyPositionWidget.cpp
View file @
eff5451a
...
...
@@ -30,6 +30,7 @@
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
#include "../WGuiConsts.h"
#include "WPropertyPositionWidget.h"
...
...
@@ -55,11 +56,15 @@ WPropertyPositionWidget::WPropertyPositionWidget( WPropPosition property, QGridL
m_layout
.
addWidget
(
&
m_editX
);
m_layout
.
addWidget
(
&
m_editY
);
m_layout
.
addWidget
(
&
m_editZ
);
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
m_parameterWidgets
.
setLayout
(
&
m_layout
);
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout
.
addWidget
(
&
m_asText
);
m_infoLayout
.
setMargin
(
WGLOBAL_MARGIN
);
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
update
();
...
...
src/gui/qt4/controlPanel/WPropertySelectionWidget.cpp
View file @
eff5451a
...
...
@@ -36,6 +36,8 @@
#include "../../../common/WItemSelector.h"
#include "../../../common/WItemSelection.h"
#include "../WGuiConsts.h"
#include "WPropertySelectionWidget.h"
/**
...
...
@@ -69,6 +71,8 @@ WPropertySelectionWidget::WPropertySelectionWidget( WPropSelection property, QGr
// initialize members
m_combo
=
NULL
;
m_list
=
NULL
;
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
// initialize the proper widget
// Lists are used if the selection of multiple elements is allowed
...
...
src/gui/qt4/controlPanel/WPropertyStringWidget.cpp
View file @
eff5451a
...
...
@@ -29,6 +29,7 @@
#include "../../../common/WLogger.h"
#include "../../../common/WPropertyVariable.h"
#include "../WGuiConsts.h"
#include "WPropertyStringWidget.h"
...
...
@@ -45,9 +46,13 @@ WPropertyStringWidget::WPropertyStringWidget( WPropString property, QGridLayout*
// layout
m_layout
.
addWidget
(
&
m_edit
);
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout
.
addWidget
(
&
m_asText
);
m_infoLayout
.
setMargin
(
WGLOBAL_MARGIN
);
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
m_asText
.
setWordWrap
(
true
);
// To have word warp work correctly -> set size policy
...
...
src/gui/qt4/controlPanel/WPropertyTriggerWidget.cpp
View file @
eff5451a
...
...
@@ -24,6 +24,7 @@
#include "WPropertyTriggerWidget.h"
#include "../WGuiConsts.h"
#include "../../../common/WPropertyVariable.h"
WPropertyTriggerWidget
::
WPropertyTriggerWidget
(
WPropTrigger
property
,
QGridLayout
*
propertyGrid
,
QWidget
*
parent
)
:
...
...
@@ -40,12 +41,16 @@ WPropertyTriggerWidget::WPropertyTriggerWidget( WPropTrigger property, QGridLayo
// layout both against each other
m_layout
.
addWidget
(
&
m_button
);
m_layout
.
setMargin
(
WGLOBAL_MARGIN
);
m_layout
.
setSpacing
(
WGLOBAL_SPACING
);
m_button
.
setText
(
QString
::
fromStdString
(
property
->
getDescription
()
)
);
m_parameterWidgets
.
setLayout
(
&
m_layout
);
// Information Output ( Property Purpose = PV_PURPOSE_INFORMATION )
m_infoLayout
.
addWidget
(
&
m_asText
);
m_infoLayout
.
setMargin
(
WGLOBAL_MARGIN
);
m_infoLayout
.
setSpacing
(
WGLOBAL_SPACING
);
m_informationWidgets
.
setLayout
(
&
m_infoLayout
);
// connect the modification signal of m_checkbox with our callback
...
...
src/gui/qt4/controlPanel/WPropertyWidget.cpp
View file @
eff5451a
...
...
@@ -53,6 +53,8 @@ WPropertyWidget::WPropertyWidget( boost::shared_ptr< WPropertyBase > property,
int
row
=
m_propertyGrid
->
rowCount
();
m_propertyGrid
->
addWidget
(
&
m_label
,
row
,
0
);
m_propertyGrid
->
addWidget
(
this
,
row
,
1
);
m_propertyGrid
->
setColumnStretch
(
0
,
0.0
);
m_propertyGrid
->
setColumnStretch
(
1
,
10000.0
);
}
// add both widgets to the stacked widget, it then uses the first as default.
...
...
src/gui/qt4/controlPanel/WPropertyWidget.h
View file @
eff5451a
...
...
@@ -37,6 +37,8 @@
#include "../../../common/WPropertyBase.h"
#include "../../../common/WPropertyTypes.h"
#include "../guiElements/WScaleLabel.h"
/**
* Class building the base for all widgets representing properties. It simply contains the handled property object.
*/
...
...
@@ -101,7 +103,7 @@ protected:
/**
* The label used to name the property
*/
Q
Label
m_label
;
WScale
Label
m_label
;
/**
* If set to true, the widgets uses the control layout to combine the widget with a label
...
...
src/gui/qt4/controlPanel/WQtPropertyGroupWidget.cpp
View file @
eff5451a
...
...
@@ -34,6 +34,8 @@
#include "../../../common/WProperties.h"
#include "../WGuiConsts.h"
#include "WQtPropertyGroupWidget.h"
WQtPropertyGroupWidget
::
WQtPropertyGroupWidget
(
WPropGroup
group
,
QWidget
*
parent
)
...
...
@@ -45,7 +47,13 @@ WQtPropertyGroupWidget::WQtPropertyGroupWidget( WPropGroup group, QWidget* paren
// note: never do layouts as none pointers
// on destruction of a widget it will try to delete them which will cause crashes
m_pageLayout
=
new
QVBoxLayout
();
m_pageLayout
->
setMargin
(
WGLOBAL_MARGIN
);
m_pageLayout
->
setSpacing
(
WGLOBAL_SPACING
);
m_controlLayout
=
new
QGridLayout
();
m_controlLayout
->
setMargin
(
WGLOBAL_MARGIN
);
m_controlLayout
->
setSpacing
(
WGLOBAL_SPACING
);
m_pageLayout
->
addLayout
(
m_controlLayout
);
// empty groups are hidden too
...
...
@@ -72,7 +80,12 @@ WQtPropertyGroupWidget::WQtPropertyGroupWidget( std::string name, QWidget* paren
// note: never do layouts as none pointers
// on destruction of a widget it will try to delete them which will cause crashes
m_pageLayout
=
new
QVBoxLayout
();
m_pageLayout
->
setMargin
(
WGLOBAL_MARGIN
);
m_pageLayout
->
setSpacing
(
WGLOBAL_SPACING
);
m_controlLayout
=
new
QGridLayout
();
m_controlLayout
->
setMargin
(
WGLOBAL_MARGIN
);
m_controlLayout
->
setSpacing
(
WGLOBAL_SPACING
);
m_pageLayout
->
addLayout
(
m_controlLayout
);
}
...
...
@@ -181,6 +194,8 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
QScrollArea
*
scrollArea
=
0
;
QGridLayout
*
grid
=
new
QGridLayout
();
grid
->
addWidget
(
widget
,
0
,
0
);
grid
->
setMargin
(
WGLOBAL_MARGIN
);
grid
->
setSpacing
(
WGLOBAL_SPACING
);
group
->
setLayout
(
grid
);
if
(
asScrollArea
)
...
...
@@ -195,6 +210,8 @@ void WQtPropertyGroupWidget::addGroup( WQtPropertyGroupWidget* widget, bool asSc
box
->
setFrameShape
(
QFrame
::
StyledPanel
);
box
->
setFrameShadow
(
QFrame
::
Raised
);
QGridLayout
*
boxLayout
=
new
QGridLayout
(
box
);
boxLayout
->
setMargin
(
WGLOBAL_MARGIN
);
boxLayout
->
setSpacing
(
WGLOBAL_SPACING
);
// create a button as title
QPushButton
*
boxTitle
=
new
QPushButton
(
this
);
...
...
src/gui/qt4/guiElements/WScaleLabel.cpp
0 → 100644
View file @
eff5451a
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "../WGuiConsts.h"
#include "WScaleLabel.h"
WScaleLabel
::
WScaleLabel
(
QWidget
*
parent
/*= NULL */
)
:
QLabel
(
parent
)
{
setMinimumWidth
(
fontMetrics
().
width
(
m_orgText
.
left
(
WMIN_LABEL_LENGTH
)
+
tr
(
".."
)
)
);
setSizePolicy
(
QSizePolicy
::
MinimumExpanding
,
QSizePolicy
::
Expanding
);
}
WScaleLabel
::
WScaleLabel
(
const
QString
&
text
,
QWidget
*
parent
/*= NULL */
)
:
QLabel
(
text
,
parent
),
m_orgText
(
text
)
{
setMinimumWidth
(
fontMetrics
().
width
(
m_orgText
.
left
(
WMIN_LABEL_LENGTH
)
+
tr
(
".."
)
)
);
setSizePolicy
(
QSizePolicy
::
MinimumExpanding
,
QSizePolicy
::
Expanding
);
}
void
WScaleLabel
::
resizeEvent
(
QResizeEvent
*
/*event*/
)
{
fitTextToSize
();
}
QSize
WScaleLabel
::
sizeHint
()
const
{
return
QSize
(
fontMetrics
().
width
(
m_orgText
),
QLabel
::
sizeHint
().
height
()
);
}
QSize
WScaleLabel
::
minimumSizeHint
()
const
{
return
QSize
(
fontMetrics
().
width
(
m_orgText
.
left
(
WMIN_LABEL_LENGTH
)
+
tr
(
".."
)
),
QLabel
::
minimumSizeHint
().
height
()
);
}
void
WScaleLabel
::
setText
(
const
QString
&
text
)
{
m_orgText
=
text
;
setMinimumWidth
(
fontMetrics
().
width
(
m_orgText
.
left
(
WMIN_LABEL_LENGTH
)
+
tr
(
".."
)
)
);
fitTextToSize
();
}
void
WScaleLabel
::
fitTextToSize
()
{
int
newwidth
=
width
();
QFontMetrics
fn
=
fontMetrics
();
if
(
newwidth
<
fn
.
width
(
m_orgText
)
)
{
QString
useText
=
m_orgText
.
left
(
m_orgText
.
length
()
-
1
);
while
(
fn
.
width
(
useText
+
tr
(
".."
)
)
>
newwidth
||
useText
.
length
()
==
0
)
{
useText
=
useText
.
left
(
useText
.
length
()
-
1
);
}
QLabel
::
setText
(
useText
+
tr
(
".."
)
);
}
else
QLabel
::
setText
(
m_orgText
);
}
src/gui/qt4/guiElements/WScaleLabel.h
0 → 100644
View file @
eff5451a
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WSCALELABEL_H
#define WSCALELABEL_H
#include <QtGui/QLabel>
#include <QtCore/QString>
/**
* Special Label that can shrink and expand in a layout
*/
class
WScaleLabel
:
public
QLabel
{
Q_OBJECT
public:
/**
* Constructor
*
* \param parent the widgets parent
*/
explicit
WScaleLabel
(
QWidget
*
parent
=
NULL
);
/**
* Constructor. Creates the label with its original text
*
* \param text text of the label
* \param parent the widgets parent
*/
WScaleLabel
(
const
QString
&
text
,
QWidget
*
parent
=
NULL
);
/**
* overwritten from QLabel, returning the widgets prefered size
*
* \return prefered size of the label
*/
QSize
sizeHint
()
const
;
/**
* overwritten from QLabel, returning the widgets prefered size
*
* \return minimum size of the label
*/
QSize
minimumSizeHint
()
const
;
/**
* reimplemented function to setText
*
* \param text text of the label
*/
void
setText
(
const
QString
&
text
);
protected:
/**
* custom implementation of the resize event
* to fit the QString into the labels current size
*
* \param event resize event passed from the parent widgets event handling
*/
virtual
void
resizeEvent
(
QResizeEvent
*
event
);
private:
/**
* set the actual text which is shown on the QLabel
*/
void
fitTextToSize
();
/**
* QString to remember the original unshortend text of the widget
*/
QString
m_orgText
;
};
#endif // WSCALELABEL_H
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