diff options
author | Marius Storm-Olsen <marius.storm-olsen@nokia.com> | 2009-11-05 12:13:26 (GMT) |
---|---|---|
committer | Marius Storm-Olsen <marius.storm-olsen@nokia.com> | 2009-11-06 14:39:40 (GMT) |
commit | 15a21652d178e4a298bb522d777602620cbd9938 (patch) | |
tree | 862636dae0389ab0e04d4f34a6a85544bae5e100 | |
parent | 4ad6343be52b757fd354cd92874bca944d2ede49 (diff) | |
download | Qt-15a21652d178e4a298bb522d777602620cbd9938.zip Qt-15a21652d178e4a298bb522d777602620cbd9938.tar.gz Qt-15a21652d178e4a298bb522d777602620cbd9938.tar.bz2 |
API review: Add convenience functions using QMargins
We added the class QMargins, so we should use it wherever we deal with
margins, as a convenience to the users.
Reviewed-by: Andreas Aardal Hanssen
-rw-r--r-- | src/gui/kernel/qlayout.cpp | 32 | ||||
-rw-r--r-- | src/gui/kernel/qlayout.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/qabstractscrollarea.cpp | 17 | ||||
-rw-r--r-- | src/gui/widgets/qabstractscrollarea.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/qlineedit.cpp | 23 | ||||
-rw-r--r-- | src/gui/widgets/qlineedit.h | 3 |
6 files changed, 80 insertions, 0 deletions
diff --git a/src/gui/kernel/qlayout.cpp b/src/gui/kernel/qlayout.cpp index 70cd5a5..5d44b3d 100644 --- a/src/gui/kernel/qlayout.cpp +++ b/src/gui/kernel/qlayout.cpp @@ -496,6 +496,21 @@ void QLayout::setContentsMargins(int left, int top, int right, int bottom) } /*! + \since 4.6 + + Sets the \a margins to use around the layout. + + By default, QLayout uses the values provided by the style. On + most platforms, the margin is 11 pixels in all directions. + + \sa contentsMargins() +*/ +void QLayout::setContentsMargins(const QMargins &margins) +{ + setContentsMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); +} + +/*! \since 4.3 Extracts the left, top, right, and bottom margins used around the @@ -521,6 +536,23 @@ void QLayout::getContentsMargins(int *left, int *top, int *right, int *bottom) c } /*! + \since 4.6 + + Returns the margins used around the layout. + + By default, QLayout uses the values provided by the style. On + most platforms, the margin is 11 pixels in all directions. + + \sa setContentsMargins() +*/ +QMargins QLayout::contentsMargins() const +{ + int left, top, right, bottom; + getContentsMargins(&left, &top, &right, &bottom); + return QMargins(left, top, right, bottom); +} + +/*! \since 4.3 Returns the layout's geometry() rectangle, but taking into account the diff --git a/src/gui/kernel/qlayout.h b/src/gui/kernel/qlayout.h index 83cbab6..2f30294 100644 --- a/src/gui/kernel/qlayout.h +++ b/src/gui/kernel/qlayout.h @@ -46,6 +46,7 @@ #include <QtGui/qlayoutitem.h> #include <QtGui/qsizepolicy.h> #include <QtCore/qrect.h> +#include <QtCore/qmargins.h> #include <limits.h> @@ -122,7 +123,9 @@ public: void setSpacing(int); void setContentsMargins(int left, int top, int right, int bottom); + void setContentsMargins(const QMargins &margins); void getContentsMargins(int *left, int *top, int *right, int *bottom) const; + QMargins contentsMargins() const; QRect contentsRect() const; bool setAlignment(QWidget *w, Qt::Alignment alignment); diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 7d81d5a..48099ef 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -51,6 +51,7 @@ #include "qdebug.h" #include "qboxlayout.h" #include "qpainter.h" +#include "qmargins.h" #include "qabstractscrollarea_p.h" #include <qwidget.h> @@ -868,6 +869,22 @@ void QAbstractScrollArea::setViewportMargins(int left, int top, int right, int b } /*! + \since 4.6 + Sets \a margins around the scrolling area. This is useful for + applications such as spreadsheets with "locked" rows and columns. + The marginal space is is left blank; put widgets in the unused + area. + + By default all margins are zero. + +*/ +void QAbstractScrollArea::setViewportMargins(const QMargins &margins) +{ + setViewportMargins(margins.left(), margins.top(), + margins.right(), margins.bottom()); +} + +/*! \fn bool QAbstractScrollArea::event(QEvent *event) \reimp diff --git a/src/gui/widgets/qabstractscrollarea.h b/src/gui/widgets/qabstractscrollarea.h index b3a1861..18d1e96 100644 --- a/src/gui/widgets/qabstractscrollarea.h +++ b/src/gui/widgets/qabstractscrollarea.h @@ -52,6 +52,7 @@ QT_MODULE(Gui) #ifndef QT_NO_SCROLLAREA +class QMargins; class QScrollBar; class QAbstractScrollAreaPrivate; @@ -95,6 +96,7 @@ protected Q_SLOTS: protected: QAbstractScrollArea(QAbstractScrollAreaPrivate &dd, QWidget *parent = 0); void setViewportMargins(int left, int top, int right, int bottom); + void setViewportMargins(const QMargins &margins); bool event(QEvent *); virtual bool viewportEvent(QEvent *); diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index e4252b5..f5dbe1c 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1102,6 +1102,17 @@ void QLineEdit::setTextMargins(int left, int top, int right, int bottom) } /*! + \since 4.6 + Sets the \a margins around the text inside the frame. + + See also textMargins(). +*/ +void QLineEdit::setTextMargins(const QMargins &margins) +{ + setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); +} + +/*! Returns the widget's text margins for \a left, \a top, \a right, and \a bottom. \since 4.5 @@ -1121,6 +1132,18 @@ void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) con } /*! + \since 4.6 + Returns the widget's text margins. + + \sa setTextMargins() +*/ +QMargins QLineEdit::textMargins() const +{ + Q_D(const QLineEdit); + return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin); +} + +/*! \property QLineEdit::inputMask \brief The validation input mask diff --git a/src/gui/widgets/qlineedit.h b/src/gui/widgets/qlineedit.h index 214509a..ac918c7 100644 --- a/src/gui/widgets/qlineedit.h +++ b/src/gui/widgets/qlineedit.h @@ -44,6 +44,7 @@ #include <QtGui/qframe.h> #include <QtCore/qstring.h> +#include <QtCore/qmargins.h> QT_BEGIN_HEADER @@ -158,7 +159,9 @@ public: bool hasAcceptableInput() const; void setTextMargins(int left, int top, int right, int bottom); + void setTextMargins(const QMargins &margins); void getTextMargins(int *left, int *top, int *right, int *bottom) const; + QMargins textMargins() const; public Q_SLOTS: void setText(const QString &); |