Changeset 43177 in vbox for trunk/src/VBox
- Timestamp:
- Sep 4, 2012 5:56:30 PM (12 years ago)
- 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 25 25 #include <QGraphicsProxyWidget> 26 26 #include <QGraphicsScene> 27 #include <QHBoxLayout> 28 #include <QMenu> 27 29 28 30 /* GUI includes: */ … … 32 34 #include "UIIconPool.h" 33 35 #include "UIGraphicsRotatorButton.h" 36 #include "UIGChooserView.h" 34 37 35 38 /* static */ … … 1412 1415 1413 1416 /* 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); 1416 1418 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())); 1418 1420 m_pNameEditor = new QGraphicsProxyWidget(this); 1419 1421 m_pNameEditor->setWidget(m_pNameEditorWidget); … … 1444 1446 } 1445 1447 1448 UIGroupRenameEditor::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 1466 QString UIGroupRenameEditor::text() const 1467 { 1468 return m_pLineEdit->text(); 1469 } 1470 1471 void UIGroupRenameEditor::setText(const QString &strText) 1472 { 1473 m_pLineEdit->setText(strText); 1474 } 1475 1476 void UIGroupRenameEditor::setFont(const QFont &font) 1477 { 1478 QWidget::setFont(font); 1479 m_pLineEdit->setFont(font); 1480 } 1481 1482 void UIGroupRenameEditor::setFocus() 1483 { 1484 m_pLineEdit->setFocus(); 1485 } 1486 1487 bool 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 1517 void 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 20 20 #define __UIGChooserItemGroup_h__ 21 21 22 /* Qt includes: */ 23 #include <QWidget> 24 22 25 /* GUI includes: */ 23 26 #include "UIGChooserItem.h" … … 29 32 class QLineEdit; 30 33 class QGraphicsProxyWidget; 34 class UIGroupRenameEditor; 31 35 32 36 /* Graphics group item … … 183 187 UIGraphicsButton *m_pEnterButton; 184 188 UIGraphicsButton *m_pExitButton; 185 QLineEdit*m_pNameEditorWidget;189 UIGroupRenameEditor *m_pNameEditorWidget; 186 190 QGraphicsProxyWidget *m_pNameEditor; 187 191 QList<UIGChooserItem*> m_groupItems; … … 193 197 }; 194 198 199 class UIGroupRenameEditor : public QWidget 200 { 201 Q_OBJECT; 202 203 signals: 204 205 /* Notifier: Editing stuff: */ 206 void sigEditingFinished(); 207 208 public: 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 220 public slots: 221 222 /* API/Handler: Focus stuff: */ 223 void setFocus(); 224 225 private: 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 195 239 #endif /* __UIGChooserItemGroup_h__ */ 196 240
Note:
See TracChangeset
for help on using the changeset viewer.