VirtualBox

Changeset 9799 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 18, 2008 3:48:16 PM (17 years ago)
Author:
vboxsync
Message:

FE/Qt4: Use right text color if the label is selected & paint a focus rect if the label has the focus.

Location:
trunk/src/VBox/Frontends/VirtualBox4
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox4/include/QILabel_p.h

    r9779 r9799  
    9292    void focusInEvent (QFocusEvent *aEvent);
    9393    void focusOutEvent (QFocusEvent *aEvent);
     94    void paintEvent (QPaintEvent *aEvent);
    9495
    9596protected slots:
  • trunk/src/VBox/Frontends/VirtualBox4/src/QILabel.cpp

    r9779 r9799  
    3333#include <QClipboard>
    3434#include <QApplication>
     35#include <QPainter>
     36#include <QStyleOptionFocusRect>
    3537
    3638/* @todo: Compare the minimal size behavior in the qt3 & qt4 version. */
     
    244246QRegExp QILabelPrivate::mElideRegExp = QRegExp ("(<compact\\s+elipsis=\"(start|middle|end)\"?>([^<]+)</compact>)");
    245247
     248#define HOR_PADDING 1
     249
    246250bool QILabelPrivate::fullSizeSelection () const
    247251{
     
    258262        /* The label should be able to get the focus */
    259263        setFocusPolicy (Qt::StrongFocus);
    260         /* Change the appearance in focus state a little bit.
     264        /* Change the appearance in the focus state a little bit.
    261265         * Note: Unfortunately QLabel, precisely the text of a QLabel isn't
    262266         * styleable. The trolls have forgotten the simplest case ... So this
    263          * is done by changing the current used palette in the In/Out-focus
    264          * events below. */
     267         * is done by changing the currently used palette in the In/Out-focus
     268         * events below. Next broken feature is drawing a simple dotted line
     269         * around the label. So this is done manually in the paintEvent. Not
     270         * sure if the stylesheet stuff is ready for production environments. */
    265271        setStyleSheet (QString("QLabel::focus {\
    266272                               background-color: palette(highlight);\
    267                                }"));
    268 //                                 border: 1px dotted black;
     273                               }\
     274                               QLabel {\
     275                               padding: 0px %1px 0px %1px;\
     276                               }").arg (HOR_PADDING));
    269277    }
    270278    else
     
    348356        aEvent->reason() != Qt::PopupFocusReason) /* For right mouse click */
    349357        setPalette (qApp->palette());
     358}
     359
     360void QILabelPrivate::paintEvent (QPaintEvent *aEvent)
     361{
     362    QLabel::paintEvent (aEvent);
     363
     364    if (mFullSizeSeclection &&
     365        hasFocus())
     366    {
     367        QPainter painter(this);
     368        /* Paint a focus rect based on the current style. */
     369        QStyleOptionFocusRect option;
     370        option.initFrom(this);
     371        style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
     372    }
    350373}
    351374
     
    400423            int flatWidth = fm.width (flatStr);
    401424            /* Create the shortened text */
    402             QString newStr = fm.elidedText (elideStr, toTextElideMode (elideModeStr), width() - flatWidth);
     425            QString newStr = fm.elidedText (elideStr, toTextElideMode (elideModeStr), width() - (2 * HOR_PADDING) - flatWidth);
    403426            /* Replace the compact part with the shortened text in the initial
    404427             * string */
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