VirtualBox

Changeset 40043 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Feb 9, 2012 8:32:22 AM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: 6072: Create rich-text QLabel analog: Initial implementation.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r39932 r40043  
    250250        src/extensions/QIMainDialog.h \
    251251        src/extensions/QIMessageBox.h \
     252        src/extensions/QIRichTextLabel.h \
    252253        src/extensions/QIRichToolButton.h \
    253254        src/extensions/QISplitter.h \
     
    417418        src/extensions/QIMainDialog.cpp \
    418419        src/extensions/QIMessageBox.cpp \
     420        src/extensions/QIRichTextLabel.cpp \
    419421        src/extensions/QIRichToolButton.cpp \
    420422        src/extensions/QISplitter.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIRichTextLabel.cpp

    r40042 r40043  
    33 *
    44 * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VirtualBox Qt extensions: QITextEdit class implementation
     5 * VirtualBox Qt extensions: QIRichTextLabel class implementation
    66 */
    77
    88/*
    9  * Copyright (C) 2011 Oracle Corporation
     9 * Copyright (C) 2012 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818 */
    1919
     20/* Global includes: */
     21#include <QVBoxLayout>
     22
    2023/* Local includes: */
    21 #include "QITextEdit.h"
     24#include "QIRichTextLabel.h"
    2225
    2326/* Constructor: */
    24 QITextEdit::QITextEdit(QWidget *pParent)
    25     : QTextEdit(pParent)
     27QIRichTextLabel::QIRichTextLabel(QWidget *pParent)
     28    : QWidget(pParent)
     29    , m_pTextEdit(new QTextEdit(this))
    2630{
     31    /* Setup text-edit: */
     32    m_pTextEdit->setReadOnly(true);
     33    m_pTextEdit->setFrameShape(QFrame::NoFrame);
     34    m_pTextEdit->viewport()->setAutoFillBackground(false);
     35    m_pTextEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     36    m_pTextEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
     37    /* Add into parent: */
     38    QVBoxLayout *pMainLayout = new QVBoxLayout(this);
     39    pMainLayout->setMargin(0);
     40    pMainLayout->addWidget(m_pTextEdit);
    2741}
    2842
    29 QSize QITextEdit::sizeHint() const
     43/* Minimum text-width setter: */
     44void QIRichTextLabel::setMinimumTextWidth(int iMinimumTextWidth)
    3045{
    31     return document()->size().toSize();
     46    /* Get corresponding QTextDocument: */
     47    QTextDocument *pTextDocument = m_pTextEdit->document();
     48    /* Bug in QTextDocument (?) : setTextWidth doesn't work from the first time. */
     49    for (int iTry = 0; pTextDocument->textWidth() != iMinimumTextWidth && iTry < 3; ++iTry)
     50        pTextDocument->setTextWidth(iMinimumTextWidth);
    3251}
    3352
     53/* Text setter: */
     54void QIRichTextLabel::setText(const QString &strText)
     55{
     56    /* Set text: */
     57    m_pTextEdit->setText(strText);
     58    /* Get corresponding QTextDocument: */
     59    QTextDocument *pTextDocument = m_pTextEdit->document();
     60    /* Get corresponding QTextDocument size: */
     61    QSize size = pTextDocument->size().toSize();
     62    /* Check if current size is valid, otherwise adjust it: */
     63    if (!size.isValid())
     64    {
     65        pTextDocument->adjustSize();
     66        size = pTextDocument->size().toSize();
     67    }
     68    /* Resize to content size: */
     69    m_pTextEdit->setMinimumSize(size);
     70}
     71
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIRichTextLabel.h

    r40042 r40043  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VirtualBox Qt extensions: QITextEdit class declaration
     4 * VirtualBox Qt extensions: QIRichTextLabel class declaration
    55 */
    66
    77/*
    8  * Copyright (C) 2011 Oracle Corporation
     8 * Copyright (C) 2012 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1717 */
    1818
    19 #ifndef __QITextEdit_h__
    20 #define __QITextEdit_h__
     19#ifndef __QIRichTextLabel_h__
     20#define __QIRichTextLabel_h__
    2121
    2222/* Global includes: */
    2323#include <QTextEdit>
    2424
    25 /* QTextEdit class extension: */
    26 class QITextEdit : public QTextEdit
     25/* QLabel analog to reflect rich-text,
     26 * Based on private QTextEdit functionality: */
     27class QIRichTextLabel : public QWidget
    2728{
    2829    Q_OBJECT;
     
    3132
    3233    /* Constructor: */
    33     QITextEdit(QWidget *pParent = 0);
     34    QIRichTextLabel(QWidget *pParent = 0);
    3435
    35     /* Size hint: */
    36     QSize sizeHint() const;
     36public slots:
     37
     38    /* Minimum text-width setter: */
     39    void setMinimumTextWidth(int iMinimumTextWidth);
     40
     41    /* Text setter: */
     42    void setText(const QString &strText);
     43
     44private:
     45
     46    /* QTextEdit private member: */
     47    QTextEdit *m_pTextEdit;
    3748};
    3849
    39 #endif // __QITextEdit_h__
     50#endif // __QIRichTextLabel_h__
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette