OpenWalnut  1.5.0dev
WScaleToolButton.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WSCALETOOLBUTTON_H
26 #define WSCALETOOLBUTTON_H
27 
28 #include <QToolButton>
29 #include <QtCore/QString>
30 
31 #include "../WGuiConsts.h"
32 
33 /**
34  * Special Button that can shrink and expand in a layout
35  */
36 class WScaleToolButton: public QToolButton
37 {
38  Q_OBJECT
39 public:
40  /**
41  * Constructor
42  *
43  * \param parent the widgets parent
44  * \param length the minimal number of characters visible
45  */
46  WScaleToolButton( size_t length = WPREFERRED_LABEL_LENGTH, QWidget *parent = NULL );
47 
48  /**
49  * Constructor. Creates the button with its original text
50  *
51  * \param text text of the button
52  * \param parent the widgets parent
53  * \param length the minimal number of characters
54  */
55  WScaleToolButton( const QString &text, size_t length = WPREFERRED_LABEL_LENGTH, QWidget *parent = NULL );
56 
57  /**
58  * overwritten from QToolButton, returning the widgets prefered size
59  *
60  * \return prefered size of the button
61  */
62  virtual QSize sizeHint() const;
63 
64  /**
65  * overwritten from QToolButton, returning the widgets prefered size
66  *
67  * \return minimum size of the button
68  */
69  virtual QSize minimumSizeHint() const;
70 
71  /**
72  * reimplemented function to setText
73  *
74  * \param text text of the button
75  */
76  virtual void setText( const QString &text );
77 
78  /**
79  * Set this to reserve extra space for a margin. This function does not set the margin. This is still your task, using stylesheets. You will
80  * not need this when using QToolButton::setMargin().
81  *
82  * \param margin the margin to keep in mind for size calculations
83  */
84  virtual void addAdditionalWidth( int margin );
85 
86  /**
87  * How many characters should be visible all the time?
88  *
89  * \param chars the number of chars
90  */
91  virtual void setMinimalLength( size_t chars );
92 
93  /**
94  * Get the current minimal number of characters
95  *
96  * \return the number of chars visible all the time
97  */
98  virtual size_t getMinimalLength() const;
99 protected:
100  /**
101  * custom implementation of the resize event
102  * to fit the QString into the butons current size
103  *
104  * \param event resize event passed from the parent widgets event handling
105  */
106  virtual void resizeEvent( QResizeEvent * event );
107 private:
108  /**
109  * set the actual text which is shown on the QToolButton
110  */
111  void fitTextToSize();
112 
113  /**
114  * QString to remember the original unshortend text of the widget
115  */
116  QString m_orgText;
117 
118  /**
119  * The additional width we need to reserver (like for margins).
120  */
122 
123  /**
124  * Minimal character number
125  */
126  size_t m_minLength;
127 };
128 
129 #endif // WSCALETOOLBUTTON_H
Special Button that can shrink and expand in a layout.
virtual void resizeEvent(QResizeEvent *event)
custom implementation of the resize event to fit the QString into the butons current size
int m_additionalWidth
The additional width we need to reserver (like for margins).
WScaleToolButton(size_t length=WPREFERRED_LABEL_LENGTH, QWidget *parent=NULL)
Constructor.
virtual QSize sizeHint() const
overwritten from QToolButton, returning the widgets prefered size
virtual void setMinimalLength(size_t chars)
How many characters should be visible all the time?
virtual void addAdditionalWidth(int margin)
Set this to reserve extra space for a margin.
void fitTextToSize()
set the actual text which is shown on the QToolButton
QString m_orgText
QString to remember the original unshortend text of the widget.
virtual QSize minimumSizeHint() const
overwritten from QToolButton, returning the widgets prefered size
size_t m_minLength
Minimal character number.
virtual void setText(const QString &text)
reimplemented function to setText
virtual size_t getMinimalLength() const
Get the current minimal number of characters.