mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 18:32:55 +00:00
use QWidget as base class for QLabel
most use-cases do not need a frame and QLabel is already a document underneath plus a pixmap Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
53c17bb88a
commit
0a416102f2
6 changed files with 20 additions and 37 deletions
|
@ -554,7 +554,6 @@ class QColorPicker : public QFrame
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
QColorPicker(QWidget* parent);
|
QColorPicker(QWidget* parent);
|
||||||
~QColorPicker();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setCol(int h, int s);
|
void setCol(int h, int s);
|
||||||
|
@ -746,10 +745,6 @@ QColorPicker::QColorPicker(QWidget* parent)
|
||||||
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
|
setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed) );
|
||||||
}
|
}
|
||||||
|
|
||||||
QColorPicker::~QColorPicker()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
QSize QColorPicker::sizeHint() const
|
QSize QColorPicker::sizeHint() const
|
||||||
{
|
{
|
||||||
return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
|
return QSize(pWidth + 2*frameWidth(), pHeight + 2*frameWidth());
|
||||||
|
|
|
@ -354,7 +354,7 @@ public:
|
||||||
QSize minimumSizeHint() const {
|
QSize minimumSizeHint() const {
|
||||||
if (!pixmap() && !pixmap()->isNull())
|
if (!pixmap() && !pixmap()->isNull())
|
||||||
return pixmap()->size();
|
return pixmap()->size();
|
||||||
return QFrame::minimumSizeHint();
|
return QLabel::minimumSizeHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSideWidget(QWidget *widget) {
|
void setSideWidget(QWidget *widget) {
|
||||||
|
|
|
@ -133,7 +133,6 @@ QTipLabel::QTipLabel(const QString &text, QWidget *w)
|
||||||
setPalette(QToolTip::palette());
|
setPalette(QToolTip::palette());
|
||||||
ensurePolished();
|
ensurePolished();
|
||||||
setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this));
|
setMargin(1 + style()->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, 0, this));
|
||||||
setFrameStyle(QFrame::NoFrame);
|
|
||||||
setAlignment(Qt::AlignLeft);
|
setAlignment(Qt::AlignLeft);
|
||||||
setIndent(1);
|
setIndent(1);
|
||||||
qApp->installEventFilter(this);
|
qApp->installEventFilter(this);
|
||||||
|
|
|
@ -123,9 +123,6 @@ QLabelPrivate::QLabelPrivate()
|
||||||
|
|
||||||
\snippet doc/src/snippets/code/src_gui_widgets_qlabel.cpp 0
|
\snippet doc/src/snippets/code/src_gui_widgets_qlabel.cpp 0
|
||||||
|
|
||||||
The properties and functions QLabel inherits from QFrame can also
|
|
||||||
be used to specify the widget frame to be used for any given label.
|
|
||||||
|
|
||||||
A QLabel is often used as a label for an interactive widget. For
|
A QLabel is often used as a label for an interactive widget. For
|
||||||
this use QLabel provides a useful mechanism for adding an
|
this use QLabel provides a useful mechanism for adding an
|
||||||
mnemonic (see QKeySequence) that will set the keyboard focus to
|
mnemonic (see QKeySequence) that will set the keyboard focus to
|
||||||
|
@ -158,12 +155,12 @@ QLabelPrivate::QLabelPrivate()
|
||||||
Constructs an empty label.
|
Constructs an empty label.
|
||||||
|
|
||||||
The \a parent and widget flag \a f, arguments are passed
|
The \a parent and widget flag \a f, arguments are passed
|
||||||
to the QFrame constructor.
|
to the QWidget constructor.
|
||||||
|
|
||||||
\sa setAlignment(), setFrameStyle(), setIndent()
|
\sa setAlignment(), setFrameStyle(), setIndent()
|
||||||
*/
|
*/
|
||||||
QLabel::QLabel(QWidget *parent, Qt::WindowFlags f)
|
QLabel::QLabel(QWidget *parent, Qt::WindowFlags f)
|
||||||
: QFrame(*new QLabelPrivate(), parent, f)
|
: QWidget(*new QLabelPrivate(), parent, f)
|
||||||
{
|
{
|
||||||
Q_D(QLabel);
|
Q_D(QLabel);
|
||||||
d->init();
|
d->init();
|
||||||
|
@ -173,12 +170,12 @@ QLabel::QLabel(QWidget *parent, Qt::WindowFlags f)
|
||||||
Constructs a label that displays the text, \a text.
|
Constructs a label that displays the text, \a text.
|
||||||
|
|
||||||
The \a parent and widget flag \a f, arguments are passed
|
The \a parent and widget flag \a f, arguments are passed
|
||||||
to the QFrame constructor.
|
to the QWidget constructor.
|
||||||
|
|
||||||
\sa setText(), setAlignment(), setFrameStyle(), setIndent()
|
\sa setText(), setAlignment(), setFrameStyle(), setIndent()
|
||||||
*/
|
*/
|
||||||
QLabel::QLabel(const QString &text, QWidget *parent, Qt::WindowFlags f)
|
QLabel::QLabel(const QString &text, QWidget *parent, Qt::WindowFlags f)
|
||||||
: QFrame(*new QLabelPrivate(), parent, f)
|
: QWidget(*new QLabelPrivate(), parent, f)
|
||||||
{
|
{
|
||||||
Q_D(QLabel);
|
Q_D(QLabel);
|
||||||
d->init();
|
d->init();
|
||||||
|
@ -496,15 +493,11 @@ QSize QLabelPrivate::sizeForWidth(int w) const
|
||||||
else if (isTextLabel) {
|
else if (isTextLabel) {
|
||||||
int align = QStyle::visualAlignment(textDirection(), QFlag(this->align));
|
int align = QStyle::visualAlignment(textDirection(), QFlag(this->align));
|
||||||
// Add indentation
|
// Add indentation
|
||||||
int m = indent;
|
if (indent > 0) {
|
||||||
|
|
||||||
if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
|
|
||||||
m = fm.width(QLatin1Char('x')) - margin*2;
|
|
||||||
if (m > 0) {
|
|
||||||
if ((align & Qt::AlignLeft) || (align & Qt::AlignRight))
|
if ((align & Qt::AlignLeft) || (align & Qt::AlignRight))
|
||||||
hextra += m;
|
hextra += indent;
|
||||||
if ((align & Qt::AlignTop) || (align & Qt::AlignBottom))
|
if ((align & Qt::AlignTop) || (align & Qt::AlignBottom))
|
||||||
vextra += m;
|
vextra += indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (control) {
|
if (control) {
|
||||||
|
@ -828,7 +821,7 @@ void QLabel::focusInEvent(QFocusEvent *ev)
|
||||||
d->ensureTextControl();
|
d->ensureTextControl();
|
||||||
d->sendControlEvent(ev);
|
d->sendControlEvent(ev);
|
||||||
}
|
}
|
||||||
QFrame::focusInEvent(ev);
|
QWidget::focusInEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -849,7 +842,7 @@ void QLabel::focusOutEvent(QFocusEvent *ev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QFrame::focusOutEvent(ev);
|
QWidget::focusOutEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!\reimp
|
/*!\reimp
|
||||||
|
@ -859,7 +852,7 @@ bool QLabel::focusNextPrevChild(bool next)
|
||||||
Q_D(QLabel);
|
Q_D(QLabel);
|
||||||
if (d->control && d->control->setFocusToNextOrPreviousAnchor(next))
|
if (d->control && d->control->setFocusToNextOrPreviousAnchor(next))
|
||||||
return true;
|
return true;
|
||||||
return QFrame::focusNextPrevChild(next);
|
return QWidget::focusNextPrevChild(next);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!\reimp
|
/*!\reimp
|
||||||
|
@ -901,7 +894,7 @@ bool QLabel::event(QEvent *e)
|
||||||
d->updateLabel();
|
d->updateLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
return QFrame::event(e);
|
return QWidget::event(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!\reimp
|
/*!\reimp
|
||||||
|
@ -911,7 +904,6 @@ void QLabel::paintEvent(QPaintEvent *ev)
|
||||||
Q_D(QLabel);
|
Q_D(QLabel);
|
||||||
QStyle *style = QWidget::style();
|
QStyle *style = QWidget::style();
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
drawFrame(&painter);
|
|
||||||
QRect cr = contentsRect();
|
QRect cr = contentsRect();
|
||||||
cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
|
cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
|
||||||
int align = QStyle::visualAlignment(d->isTextLabel ? d->textDirection()
|
int align = QStyle::visualAlignment(d->isTextLabel ? d->textDirection()
|
||||||
|
@ -1267,7 +1259,7 @@ void QLabel::changeEvent(QEvent *ev)
|
||||||
} else if (ev->type() == QEvent::ContentsRectChange) {
|
} else if (ev->type() == QEvent::ContentsRectChange) {
|
||||||
d->updateLabel();
|
d->updateLabel();
|
||||||
}
|
}
|
||||||
QFrame::changeEvent(ev);
|
QWidget::changeEvent(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -1327,18 +1319,15 @@ QRect QLabelPrivate::documentRect() const
|
||||||
cr.adjust(margin, margin, -margin, -margin);
|
cr.adjust(margin, margin, -margin, -margin);
|
||||||
const int align = QStyle::visualAlignment(isTextLabel ? textDirection()
|
const int align = QStyle::visualAlignment(isTextLabel ? textDirection()
|
||||||
: q->layoutDirection(), QFlag(this->align));
|
: q->layoutDirection(), QFlag(this->align));
|
||||||
int m = indent;
|
if (indent > 0) {
|
||||||
if (m < 0 && q->frameWidth()) // no indent, but we do have a frame
|
|
||||||
m = q->fontMetrics().width(QLatin1Char('x')) / 2 - margin;
|
|
||||||
if (m > 0) {
|
|
||||||
if (align & Qt::AlignLeft)
|
if (align & Qt::AlignLeft)
|
||||||
cr.setLeft(cr.left() + m);
|
cr.setLeft(cr.left() + indent);
|
||||||
if (align & Qt::AlignRight)
|
if (align & Qt::AlignRight)
|
||||||
cr.setRight(cr.right() - m);
|
cr.setRight(cr.right() - indent);
|
||||||
if (align & Qt::AlignTop)
|
if (align & Qt::AlignTop)
|
||||||
cr.setTop(cr.top() + m);
|
cr.setTop(cr.top() + indent);
|
||||||
if (align & Qt::AlignBottom)
|
if (align & Qt::AlignBottom)
|
||||||
cr.setBottom(cr.bottom() - m);
|
cr.setBottom(cr.bottom() - indent);
|
||||||
}
|
}
|
||||||
return cr;
|
return cr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ QT_BEGIN_NAMESPACE
|
||||||
class QMovie;
|
class QMovie;
|
||||||
class QLabelPrivate;
|
class QLabelPrivate;
|
||||||
|
|
||||||
class Q_GUI_EXPORT QLabel : public QFrame
|
class Q_GUI_EXPORT QLabel : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString text READ text WRITE setText)
|
Q_PROPERTY(QString text READ text WRITE setText)
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QLabelPrivate : public QFramePrivate
|
class QLabelPrivate : public QWidgetPrivate
|
||||||
{
|
{
|
||||||
Q_DECLARE_PUBLIC(QLabel)
|
Q_DECLARE_PUBLIC(QLabel)
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue