VirtualBox

Changeset 43177 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 4, 2012 5:56:30 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Group UI feature: Moving group-name-editor's context-menu out of the graphics-view.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.cpp

    r43158 r43177  
    2525#include <QGraphicsProxyWidget>
    2626#include <QGraphicsScene>
     27#include <QHBoxLayout>
     28#include <QMenu>
    2729
    2830/* GUI includes: */
     
    3234#include "UIIconPool.h"
    3335#include "UIGraphicsRotatorButton.h"
     36#include "UIGChooserView.h"
    3437
    3538/* static */
     
    14121415
    14131416        /* Setup name-editor: */
    1414         m_pNameEditorWidget = new QLineEdit(m_strName);
    1415         m_pNameEditorWidget->setTextMargins(0, 0, 0, 0);
     1417        m_pNameEditorWidget = new UIGroupRenameEditor(m_strName, this);
    14161418        m_pNameEditorWidget->setFont(data(GroupItemData_NameFont).value<QFont>());
    1417         connect(m_pNameEditorWidget, SIGNAL(editingFinished()), this, SLOT(sltNameEditingFinished()));
     1419        connect(m_pNameEditorWidget, SIGNAL(sigEditingFinished()), this, SLOT(sltNameEditingFinished()));
    14181420        m_pNameEditor = new QGraphicsProxyWidget(this);
    14191421        m_pNameEditor->setWidget(m_pNameEditorWidget);
     
    14441446}
    14451447
     1448UIGroupRenameEditor::UIGroupRenameEditor(const QString &strName, UIGChooserItem *pParent)
     1449    : m_pParent(pParent)
     1450    , m_pLineEdit(0)
     1451    , m_pTemporaryMenu(0)
     1452{
     1453    /* Create line-edit: */
     1454    m_pLineEdit = new QLineEdit(strName, this);
     1455    m_pLineEdit->setTextMargins(0, 0, 0, 0);
     1456    connect(m_pLineEdit, SIGNAL(returnPressed()), this, SIGNAL(sigEditingFinished()));
     1457    /* Create main-layout: */
     1458    QHBoxLayout *pLayout = new QHBoxLayout(this);
     1459    pLayout->setContentsMargins(0, 0, 0, 0);
     1460    /* Add line-edit into main-layout: */
     1461    pLayout->addWidget(m_pLineEdit);
     1462    /* Install event-filter: */
     1463    m_pLineEdit->installEventFilter(this);
     1464}
     1465
     1466QString UIGroupRenameEditor::text() const
     1467{
     1468    return m_pLineEdit->text();
     1469}
     1470
     1471void UIGroupRenameEditor::setText(const QString &strText)
     1472{
     1473    m_pLineEdit->setText(strText);
     1474}
     1475
     1476void UIGroupRenameEditor::setFont(const QFont &font)
     1477{
     1478    QWidget::setFont(font);
     1479    m_pLineEdit->setFont(font);
     1480}
     1481
     1482void UIGroupRenameEditor::setFocus()
     1483{
     1484    m_pLineEdit->setFocus();
     1485}
     1486
     1487bool UIGroupRenameEditor::eventFilter(QObject *pWatched, QEvent *pEvent)
     1488{
     1489    /* Process only events sent to line-edit: */
     1490    if (pWatched != m_pLineEdit)
     1491        return QWidget::eventFilter(pWatched, pEvent);
     1492
     1493    /* Handle events: */
     1494    switch (pEvent->type())
     1495    {
     1496        case QEvent::ContextMenu:
     1497        {
     1498            /* Handle context-menu event: */
     1499            handleContextMenuEvent(static_cast<QContextMenuEvent*>(pEvent));
     1500            /* Filter out this event: */
     1501            return true;
     1502        }
     1503        case QEvent::FocusOut:
     1504        {
     1505            if (!m_pTemporaryMenu)
     1506                emit sigEditingFinished();
     1507            break;
     1508        }
     1509        default:
     1510            break;
     1511    }
     1512
     1513    /* Call to base-class: */
     1514    return QWidget::eventFilter(pWatched, pEvent);
     1515}
     1516
     1517void UIGroupRenameEditor::handleContextMenuEvent(QContextMenuEvent *pContextMenuEvent)
     1518{
     1519    /* Prepare variables: */
     1520    QGraphicsView *pView = m_pParent->model()->scene()->views().first();
     1521
     1522    /* Create context-menu: */
     1523    m_pTemporaryMenu = new QMenu(pView);
     1524    QMenu *pMenu = m_pLineEdit->createStandardContextMenu();
     1525    const QList<QAction*> &actions = pMenu->actions();
     1526    foreach (QAction *pAction, actions)
     1527        m_pTemporaryMenu->addAction(pAction);
     1528
     1529    /* Determine global position: */
     1530    QPoint subItemPos = pContextMenuEvent->pos();
     1531    QPoint itemPos = mapToParent(subItemPos);
     1532    QPointF scenePos = m_pParent->mapToScene(itemPos);
     1533    QPoint viewPos = pView->mapFromScene(scenePos);
     1534    QPoint globalPos = pView->mapToGlobal(viewPos);
     1535
     1536    /* Show context menu: */
     1537    m_pTemporaryMenu->exec(globalPos);
     1538
     1539    /* Delete context menu: */
     1540    delete m_pTemporaryMenu;
     1541    m_pTemporaryMenu = 0;
     1542    delete pMenu;
     1543}
     1544
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.h

    r43153 r43177  
    2020#define __UIGChooserItemGroup_h__
    2121
     22/* Qt includes: */
     23#include <QWidget>
     24
    2225/* GUI includes: */
    2326#include "UIGChooserItem.h"
     
    2932class QLineEdit;
    3033class QGraphicsProxyWidget;
     34class UIGroupRenameEditor;
    3135
    3236/* Graphics group item
     
    183187    UIGraphicsButton *m_pEnterButton;
    184188    UIGraphicsButton *m_pExitButton;
    185     QLineEdit *m_pNameEditorWidget;
     189    UIGroupRenameEditor *m_pNameEditorWidget;
    186190    QGraphicsProxyWidget *m_pNameEditor;
    187191    QList<UIGChooserItem*> m_groupItems;
     
    193197};
    194198
     199class UIGroupRenameEditor : public QWidget
     200{
     201    Q_OBJECT;
     202
     203signals:
     204
     205    /* Notifier: Editing stuff: */
     206    void sigEditingFinished();
     207
     208public:
     209
     210    /* Constructor: */
     211    UIGroupRenameEditor(const QString &strName, UIGChooserItem *pParent);
     212
     213    /* API: Text stuff: */
     214    QString text() const;
     215    void setText(const QString &strText);
     216
     217    /* API: Font stuff: */
     218    void setFont(const QFont &font);
     219
     220public slots:
     221
     222    /* API/Handler: Focus stuff: */
     223    void setFocus();
     224
     225private:
     226
     227    /* Handler: Event-filter: */
     228    bool eventFilter(QObject *pWatched, QEvent *pEvent);
     229
     230    /* Helper: Context-menu stuff: */
     231    void handleContextMenuEvent(QContextMenuEvent *pContextMenuEvent);
     232
     233    /* Variables: */
     234    UIGChooserItem *m_pParent;
     235    QLineEdit *m_pLineEdit;
     236    QMenu *m_pTemporaryMenu;
     237};
     238
    195239#endif /* __UIGChooserItemGroup_h__ */
    196240
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