QWidget/QLineEdit: deprecate get{Contents,Text}Margins()
We have contentsMargins() and textMargins() methods since 4.6 which are much more efficient and easier to use. [ChangeLog][QtWidgets][QLineEdit] The getTextMargins() member function has been deprecated in favor of textMargins(). [ChangeLog][QtWidgets][QWidget] The getContentsMargins() member function has been deprecated in favor of contentsMargins(). Change-Id: Ifdb890af6198fc682b94701786c67a5b945a4b4c Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
76be819345
commit
130fd22d39
@ -779,8 +779,7 @@ int QAccessibleLineEdit::cursorPosition() const
|
|||||||
QRect QAccessibleLineEdit::characterRect(int offset) const
|
QRect QAccessibleLineEdit::characterRect(int offset) const
|
||||||
{
|
{
|
||||||
int x = lineEdit()->d_func()->control->cursorToX(offset);
|
int x = lineEdit()->d_func()->control->cursorToX(offset);
|
||||||
int y;
|
int y = lineEdit()->textMargins().top();
|
||||||
lineEdit()->getTextMargins(0, &y, 0, 0);
|
|
||||||
QFontMetrics fm(lineEdit()->font());
|
QFontMetrics fm(lineEdit()->font());
|
||||||
const QString ch = text(offset, offset + 1);
|
const QString ch = text(offset, offset + 1);
|
||||||
if (ch.isEmpty())
|
if (ch.isEmpty())
|
||||||
|
@ -697,9 +697,7 @@ void QGraphicsProxyWidgetPrivate::setWidget_helper(QWidget *newWidget, bool auto
|
|||||||
if (!newWidget->testAttribute(Qt::WA_Resized))
|
if (!newWidget->testAttribute(Qt::WA_Resized))
|
||||||
newWidget->adjustSize();
|
newWidget->adjustSize();
|
||||||
|
|
||||||
int left, top, right, bottom;
|
q->setContentsMargins(newWidget->contentsMargins());
|
||||||
newWidget->getContentsMargins(&left, &top, &right, &bottom);
|
|
||||||
q->setContentsMargins(left, top, right, bottom);
|
|
||||||
q->setWindowTitle(newWidget->windowTitle());
|
q->setWindowTitle(newWidget->windowTitle());
|
||||||
|
|
||||||
// size policies and constraints..
|
// size policies and constraints..
|
||||||
|
@ -570,11 +570,9 @@ void QExpandingLineEdit::changeEvent(QEvent *e)
|
|||||||
|
|
||||||
void QExpandingLineEdit::updateMinimumWidth()
|
void QExpandingLineEdit::updateMinimumWidth()
|
||||||
{
|
{
|
||||||
int left, right;
|
const QMargins tm = textMargins();
|
||||||
getTextMargins(&left, 0, &right, 0);
|
const QMargins cm = contentsMargins();
|
||||||
int width = left + right + 4 /*horizontalMargin in qlineedit.cpp*/;
|
const int width = tm.left() + tm.right() + cm.left() + cm.right() + 4 /*horizontalMargin in qlineedit.cpp*/;
|
||||||
getContentsMargins(&left, 0, &right, 0);
|
|
||||||
width += left + right;
|
|
||||||
|
|
||||||
QStyleOptionFrame opt;
|
QStyleOptionFrame opt;
|
||||||
initStyleOption(&opt);
|
initStyleOption(&opt);
|
||||||
|
@ -7634,7 +7634,7 @@ bool QWidget::restoreGeometry(const QByteArray &geometry)
|
|||||||
|
|
||||||
Changing the margins will trigger a resizeEvent().
|
Changing the margins will trigger a resizeEvent().
|
||||||
|
|
||||||
\sa contentsRect(), getContentsMargins()
|
\sa contentsRect(), contentsMargins()
|
||||||
*/
|
*/
|
||||||
void QWidget::setContentsMargins(int left, int top, int right, int bottom)
|
void QWidget::setContentsMargins(int left, int top, int right, int bottom)
|
||||||
{
|
{
|
||||||
@ -7664,7 +7664,7 @@ void QWidget::setContentsMargins(int left, int top, int right, int bottom)
|
|||||||
|
|
||||||
Changing the margins will trigger a resizeEvent().
|
Changing the margins will trigger a resizeEvent().
|
||||||
|
|
||||||
\sa contentsRect(), getContentsMargins()
|
\sa contentsRect(), contentsMargins()
|
||||||
*/
|
*/
|
||||||
void QWidget::setContentsMargins(const QMargins &margins)
|
void QWidget::setContentsMargins(const QMargins &margins)
|
||||||
{
|
{
|
||||||
@ -7693,7 +7693,11 @@ void QWidgetPrivate::updateContentsRect()
|
|||||||
QCoreApplication::sendEvent(q, &e);
|
QCoreApplication::sendEvent(q, &e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 14)
|
||||||
/*!
|
/*!
|
||||||
|
\obsolete
|
||||||
|
Use contentsMargins().
|
||||||
|
|
||||||
Returns the widget's contents margins for \a left, \a top, \a
|
Returns the widget's contents margins for \a left, \a top, \a
|
||||||
right, and \a bottom.
|
right, and \a bottom.
|
||||||
|
|
||||||
@ -7711,6 +7715,7 @@ void QWidget::getContentsMargins(int *left, int *top, int *right, int *bottom) c
|
|||||||
if (bottom)
|
if (bottom)
|
||||||
*bottom = m.bottom();
|
*bottom = m.bottom();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// FIXME: Move to qmargins.h for next minor Qt release
|
// FIXME: Move to qmargins.h for next minor Qt release
|
||||||
QMargins operator|(const QMargins &m1, const QMargins &m2)
|
QMargins operator|(const QMargins &m1, const QMargins &m2)
|
||||||
@ -7724,7 +7729,7 @@ QMargins operator|(const QMargins &m1, const QMargins &m2)
|
|||||||
|
|
||||||
\brief The contentsMargins function returns the widget's contents margins.
|
\brief The contentsMargins function returns the widget's contents margins.
|
||||||
|
|
||||||
\sa getContentsMargins(), setContentsMargins(), contentsRect()
|
\sa setContentsMargins(), contentsRect()
|
||||||
*/
|
*/
|
||||||
QMargins QWidget::contentsMargins() const
|
QMargins QWidget::contentsMargins() const
|
||||||
{
|
{
|
||||||
@ -7737,7 +7742,7 @@ QMargins QWidget::contentsMargins() const
|
|||||||
/*!
|
/*!
|
||||||
Returns the area inside the widget's margins.
|
Returns the area inside the widget's margins.
|
||||||
|
|
||||||
\sa setContentsMargins(), getContentsMargins()
|
\sa setContentsMargins(), contentsMargins()
|
||||||
*/
|
*/
|
||||||
QRect QWidget::contentsRect() const
|
QRect QWidget::contentsRect() const
|
||||||
{
|
{
|
||||||
|
@ -524,7 +524,10 @@ public:
|
|||||||
|
|
||||||
void setContentsMargins(int left, int top, int right, int bottom);
|
void setContentsMargins(int left, int top, int right, int bottom);
|
||||||
void setContentsMargins(const QMargins &margins);
|
void setContentsMargins(const QMargins &margins);
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 14)
|
||||||
|
QT_DEPRECATED_X("use contentsMargins()")
|
||||||
void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
|
void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
|
||||||
|
#endif
|
||||||
QMargins contentsMargins() const;
|
QMargins contentsMargins() const;
|
||||||
|
|
||||||
QRect contentsRect() const;
|
QRect contentsRect() const;
|
||||||
|
@ -2714,15 +2714,14 @@ void QComboBox::showPopup()
|
|||||||
int heightMargin = container->topMargin() + container->bottomMargin();
|
int heightMargin = container->topMargin() + container->bottomMargin();
|
||||||
|
|
||||||
// add the frame of the container
|
// add the frame of the container
|
||||||
int marginTop, marginBottom;
|
const QMargins cm = container->contentsMargins();
|
||||||
container->getContentsMargins(0, &marginTop, 0, &marginBottom);
|
heightMargin += cm.top() + cm.bottom();
|
||||||
heightMargin += marginTop + marginBottom;
|
|
||||||
|
|
||||||
//add the frame of the view
|
//add the frame of the view
|
||||||
view()->getContentsMargins(0, &marginTop, 0, &marginBottom);
|
const QMargins vm = view()->contentsMargins();
|
||||||
marginTop += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;
|
heightMargin += vm.top() + vm.bottom();
|
||||||
marginBottom += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;
|
heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->top;
|
||||||
heightMargin += marginTop + marginBottom;
|
heightMargin += static_cast<QAbstractScrollAreaPrivate *>(QObjectPrivate::get(view()))->bottom;
|
||||||
|
|
||||||
listRect.setHeight(listRect.height() + heightMargin);
|
listRect.setHeight(listRect.height() + heightMargin);
|
||||||
}
|
}
|
||||||
|
@ -1129,7 +1129,7 @@ bool QLineEdit::hasAcceptableInput() const
|
|||||||
sizes \a left, \a top, \a right, and \a bottom.
|
sizes \a left, \a top, \a right, and \a bottom.
|
||||||
\since 4.5
|
\since 4.5
|
||||||
|
|
||||||
See also getTextMargins().
|
See also textMargins().
|
||||||
*/
|
*/
|
||||||
void QLineEdit::setTextMargins(int left, int top, int right, int bottom)
|
void QLineEdit::setTextMargins(int left, int top, int right, int bottom)
|
||||||
{
|
{
|
||||||
@ -1150,7 +1150,11 @@ void QLineEdit::setTextMargins(const QMargins &margins)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 14)
|
||||||
/*!
|
/*!
|
||||||
|
\obsolete
|
||||||
|
Use textMargins()
|
||||||
|
|
||||||
Returns the widget's text margins for \a left, \a top, \a right, and \a bottom.
|
Returns the widget's text margins for \a left, \a top, \a right, and \a bottom.
|
||||||
\since 4.5
|
\since 4.5
|
||||||
|
|
||||||
@ -1168,6 +1172,7 @@ void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) con
|
|||||||
if (bottom)
|
if (bottom)
|
||||||
*bottom = m.bottom();
|
*bottom = m.bottom();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\since 4.6
|
\since 4.6
|
||||||
|
@ -172,7 +172,10 @@ public:
|
|||||||
|
|
||||||
void setTextMargins(int left, int top, int right, int bottom);
|
void setTextMargins(int left, int top, int right, int bottom);
|
||||||
void setTextMargins(const QMargins &margins);
|
void setTextMargins(const QMargins &margins);
|
||||||
|
#if QT_DEPRECATED_SINCE(5, 14)
|
||||||
|
QT_DEPRECATED_X("use textMargins()")
|
||||||
void getTextMargins(int *left, int *top, int *right, int *bottom) const;
|
void getTextMargins(int *left, int *top, int *right, int *bottom) const;
|
||||||
|
#endif
|
||||||
QMargins textMargins() const;
|
QMargins textMargins() const;
|
||||||
|
|
||||||
#if QT_CONFIG(action)
|
#if QT_CONFIG(action)
|
||||||
|
@ -142,9 +142,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
if (style() != p->style())
|
if (style() != p->style())
|
||||||
setStyle(p->style());
|
setStyle(p->style());
|
||||||
int leftMargin, topMargin, rightMargin, bottomMargin;
|
setContentsMargins(p->contentsMargins());
|
||||||
p->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin);
|
|
||||||
setContentsMargins(leftMargin, topMargin, rightMargin, bottomMargin);
|
|
||||||
setLayoutDirection(p->layoutDirection());
|
setLayoutDirection(p->layoutDirection());
|
||||||
//QObject::connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onTrigger(QAction*)));
|
//QObject::connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onTrigger(QAction*)));
|
||||||
//QObject::connect(this, SIGNAL(hovered(QAction*)), this, SLOT(onHovered(QAction*)));
|
//QObject::connect(this, SIGNAL(hovered(QAction*)), this, SLOT(onHovered(QAction*)));
|
||||||
|
@ -771,14 +771,13 @@ void QSplitterPrivate::setGeo(QSplitterLayoutStruct *sls, int p, int s, bool all
|
|||||||
if (!sls->handle->isHidden()) {
|
if (!sls->handle->isHidden()) {
|
||||||
QSplitterHandle *h = sls->handle;
|
QSplitterHandle *h = sls->handle;
|
||||||
QSize hs = h->sizeHint();
|
QSize hs = h->sizeHint();
|
||||||
int left, top, right, bottom;
|
const QMargins m = h->contentsMargins();
|
||||||
h->getContentsMargins(&left, &top, &right, &bottom);
|
|
||||||
if (orient==Qt::Horizontal) {
|
if (orient==Qt::Horizontal) {
|
||||||
if (q->isRightToLeft())
|
if (q->isRightToLeft())
|
||||||
p = contents.width() - p + hs.width();
|
p = contents.width() - p + hs.width();
|
||||||
h->setGeometry(p-hs.width() - left, contents.y(), hs.width() + left + right, contents.height());
|
h->setGeometry(p-hs.width() - m.left(), contents.y(), hs.width() + m.left() + m.right(), contents.height());
|
||||||
} else {
|
} else {
|
||||||
h->setGeometry(contents.x(), p-hs.height() - top, contents.width(), hs.height() + top + bottom);
|
h->setGeometry(contents.x(), p-hs.height() - m.top(), contents.width(), hs.height() + m.top() + m.bottom());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user