VirtualBox

Changeset 75181 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 30, 2018 2:55:01 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9241: VirtualBox Manager: Chooser pane: Reworking group name editor.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.cpp

    r74942 r75181  
    5858    , m_pExitButton(0)
    5959    , m_pNameEditorWidget(0)
    60     , m_pNameEditor(0)
    6160{
    6261    /* Prepare: */
     
    9089    , m_pExitButton(0)
    9190    , m_pNameEditorWidget(0)
    92     , m_pNameEditor(0)
    9391{
    9492    /* Prepare: */
     
    125123    , m_pExitButton(0)
    126124    , m_pNameEditorWidget(0)
    127     , m_pNameEditor(0)
    128125{
    129126    /* Prepare: */
     
    171168    , m_pExitButton(0)
    172169    , m_pNameEditorWidget(0)
    173     , m_pNameEditor(0)
    174170{
    175171    /* Prepare: */
     
    389385        return;
    390386
    391     /* Unlock name-editor: */
    392     m_pNameEditor->show();
     387    /* Assign name-editor text: */
    393388    m_pNameEditorWidget->setText(name());
     389
     390    /* Layout name-editor: */
     391    const int iMargin = data(GroupItemData_VerticalMargin).toInt();
     392    const int iHeaderHeight = 2 * iMargin + m_minimumHeaderSize.height();
     393    const QSize headerSize = QSize(geometry().width(), iHeaderHeight);
     394    const QGraphicsView *pView = model()->scene()->views().first();
     395    const QPoint viewPoint = pView->mapFromScene(geometry().topLeft().toPoint());
     396    const QPoint globalPoint = pView->parentWidget()->mapToGlobal(viewPoint);
     397    m_pNameEditorWidget->move(globalPoint);
     398    m_pNameEditorWidget->resize(headerSize);
     399
     400    /* Show name-editor: */
     401    m_pNameEditorWidget->show();
    394402    m_pNameEditorWidget->setFocus();
    395403}
     
    812820                                iVerticalMargin + (iFullHeaderHeight - iEnterButtonHeight) / 2;
    813821            m_pEnterButton->setPos(iEnterButtonX, iEnterButtonY);
    814         }
    815 
    816         /* Name-editor: */
    817         if (m_pNameEditor && m_pNameEditorWidget)
    818         {
    819             /* Prepare variables: */
    820             int iHeaderSpacing = data(GroupItemData_HeaderSpacing).toInt();
    821             int iToggleButtonWidth = m_toggleButtonSize.width();
    822             /* Layout name-editor: */
    823             int iNameEditorX = iHorizontalMargin + iToggleButtonWidth + iHeaderSpacing;
    824             int iNameEditorY = 1;
    825             m_pNameEditor->setPos(iNameEditorX, iNameEditorY);
    826             m_pNameEditorWidget->resize((int)(geometry().width() - iNameEditorX - iHorizontalMargin), m_pNameEditorWidget->height());
    827822        }
    828823
     
    11061101        return;
    11071102
    1108     /* Lock name-editor: */
    1109     m_pNameEditor->hide();
     1103    /* Close name-editor: */
     1104    m_pNameEditorWidget->close();
    11101105
    11111106    /* Enumerate all the group names: */
     
    12261221
    12271222        /* Setup name-editor: */
    1228         m_pNameEditorWidget = new UIEditorGroupRename(name(), this);
     1223        m_pNameEditorWidget = new UIEditorGroupRename(name());
    12291224        m_pNameEditorWidget->setFont(m_nameFont);
    12301225        connect(m_pNameEditorWidget, &UIEditorGroupRename::sigEditingFinished,
    12311226                this, &UIChooserItemGroup::sltNameEditingFinished);
    1232         m_pNameEditor = new QGraphicsProxyWidget(this);
    1233         m_pNameEditor->setWidget(m_pNameEditorWidget);
    1234         m_pNameEditor->hide();
    12351227    }
    12361228    /* Items except main root: */
     
    18791871*********************************************************************************************************************************/
    18801872
    1881 UIEditorGroupRename::UIEditorGroupRename(const QString &strName, UIChooserItem *pParent)
    1882     : m_pParent(pParent)
     1873UIEditorGroupRename::UIEditorGroupRename(const QString &strName)
     1874    : QWidget(0, Qt::Popup)
    18831875    , m_pLineEdit(0)
    1884     , m_pTemporaryMenu(0)
    18851876{
    18861877    /* Create layout: */
     
    18951886        if (m_pLineEdit)
    18961887        {
     1888            setFocusProxy(m_pLineEdit);
     1889            m_pLineEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    18971890            m_pLineEdit->setTextMargins(0, 0, 0, 0);
    18981891            connect(m_pLineEdit, &QLineEdit::returnPressed,
     
    19031896        pLayout->addWidget(m_pLineEdit);
    19041897    }
    1905 
    1906     /* Install event-filter: */
    1907     m_pLineEdit->installEventFilter(this);
     1898}
     1899
     1900QString UIEditorGroupRename::text() const
     1901{
     1902    return m_pLineEdit->text();
    19081903}
    19091904
     
    19111906{
    19121907    m_pLineEdit->setText(strText);
    1913 }
    1914 
    1915 QString UIEditorGroupRename::text() const
    1916 {
    1917     return m_pLineEdit->text();
    19181908}
    19191909
     
    19231913    m_pLineEdit->setFont(font);
    19241914}
    1925 
    1926 void UIEditorGroupRename::setFocus()
    1927 {
    1928     m_pLineEdit->setFocus();
    1929 }
    1930 
    1931 bool UIEditorGroupRename::eventFilter(QObject *pWatched, QEvent *pEvent)
    1932 {
    1933     /* Process only events sent to line-edit: */
    1934     if (pWatched != m_pLineEdit)
    1935         return QWidget::eventFilter(pWatched, pEvent);
    1936 
    1937     /* Handle events: */
    1938     switch (pEvent->type())
    1939     {
    1940         case QEvent::ContextMenu:
    1941         {
    1942             /* Handle context-menu event: */
    1943             handleContextMenuEvent(static_cast<QContextMenuEvent*>(pEvent));
    1944             /* Filter out this event: */
    1945             return true;
    1946         }
    1947         case QEvent::FocusOut:
    1948         {
    1949             if (!m_pTemporaryMenu)
    1950                 emit sigEditingFinished();
    1951             break;
    1952         }
    1953         default:
    1954             break;
    1955     }
    1956 
    1957     /* Call to base-class: */
    1958     return QWidget::eventFilter(pWatched, pEvent);
    1959 }
    1960 
    1961 void UIEditorGroupRename::handleContextMenuEvent(QContextMenuEvent *pContextMenuEvent)
    1962 {
    1963     /* Prepare variables: */
    1964     QGraphicsView *pView = m_pParent->model()->scene()->views().first();
    1965 
    1966     /* Create context-menu: */
    1967     m_pTemporaryMenu = new QMenu(pView);
    1968     QMenu *pMenu = m_pLineEdit->createStandardContextMenu();
    1969     const QList<QAction*> &actions = pMenu->actions();
    1970     foreach (QAction *pAction, actions)
    1971         m_pTemporaryMenu->addAction(pAction);
    1972 
    1973     /* Determine global position: */
    1974     QPoint subItemPos = pContextMenuEvent->pos();
    1975     QPoint itemPos = mapToParent(subItemPos);
    1976     QPointF scenePos = m_pParent->mapToScene(itemPos);
    1977     QPoint viewPos = pView->mapFromScene(scenePos);
    1978     QPoint globalPos = pView->mapToGlobal(viewPos);
    1979 
    1980     /* Show context menu: */
    1981     m_pTemporaryMenu->exec(globalPos);
    1982 
    1983     /* Delete context menu: */
    1984     delete m_pTemporaryMenu;
    1985     m_pTemporaryMenu = 0;
    1986     delete pMenu;
    1987 }
    1988 
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h

    r74942 r75181  
    2828
    2929/* Forward declarations: */
    30 class QGraphicsProxyWidget;
    3130class QGraphicsScene;
    32 class QLineEdit;
    3331class QMenu;
    3432class QMimeData;
     
    346344
    347345        /** Holds the group name editor instance. */
    348         UIEditorGroupRename  *m_pNameEditorWidget;
    349         /** Holds the group name editor proxy instance. */
    350         QGraphicsProxyWidget *m_pNameEditor;
     346        UIEditorGroupRename *m_pNameEditorWidget;
    351347    /** @} */
    352348
     
    410406public:
    411407
    412     /** Constructs group editor with initial @a strName passing @a pParent to the base-class. */
    413     UIEditorGroupRename(const QString &strName, UIChooserItem *pParent);
    414 
     408    /** Constructs group editor with initial @a strName. */
     409    UIEditorGroupRename(const QString &strName);
     410
     411    /** Returns editor text. */
     412    QString text() const;
    415413    /** Defines editor @a strText. */
    416414    void setText(const QString &strText);
    417     /** Returns editor text. */
    418     QString text() const;
    419415
    420416    /** Defines editor @a font. */
    421417    void setFont(const QFont &font);
    422418
    423 public slots:
    424 
    425     /** ACquires keyboard focus. */
    426     void setFocus();
    427 
    428 protected:
    429 
    430     /** Preprocesses any Qt @a pEvent for passed @a pObject. */
    431     virtual bool eventFilter(QObject *pObject, QEvent *pEvent) /* override */;
    432 
    433419private:
    434 
    435     /** Handles context-menu @a pEvent. */
    436     void handleContextMenuEvent(QContextMenuEvent *pEvent);
    437 
    438     /** Holds the parent reference. */
    439     UIChooserItem *m_pParent;
    440420
    441421    /** Holds the line-edit instance. */
    442422    QLineEdit *m_pLineEdit;
    443     /** Holds the conect-menu instance. */
    444     QMenu     *m_pTemporaryMenu;
    445423};
    446424
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