Changeset 75181 in vbox for trunk/src/VBox
- Timestamp:
- Oct 30, 2018 2:55:01 PM (6 years ago)
- 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 58 58 , m_pExitButton(0) 59 59 , m_pNameEditorWidget(0) 60 , m_pNameEditor(0)61 60 { 62 61 /* Prepare: */ … … 90 89 , m_pExitButton(0) 91 90 , m_pNameEditorWidget(0) 92 , m_pNameEditor(0)93 91 { 94 92 /* Prepare: */ … … 125 123 , m_pExitButton(0) 126 124 , m_pNameEditorWidget(0) 127 , m_pNameEditor(0)128 125 { 129 126 /* Prepare: */ … … 171 168 , m_pExitButton(0) 172 169 , m_pNameEditorWidget(0) 173 , m_pNameEditor(0)174 170 { 175 171 /* Prepare: */ … … 389 385 return; 390 386 391 /* Unlock name-editor: */ 392 m_pNameEditor->show(); 387 /* Assign name-editor text: */ 393 388 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(); 394 402 m_pNameEditorWidget->setFocus(); 395 403 } … … 812 820 iVerticalMargin + (iFullHeaderHeight - iEnterButtonHeight) / 2; 813 821 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());827 822 } 828 823 … … 1106 1101 return; 1107 1102 1108 /* Lockname-editor: */1109 m_pNameEditor ->hide();1103 /* Close name-editor: */ 1104 m_pNameEditorWidget->close(); 1110 1105 1111 1106 /* Enumerate all the group names: */ … … 1226 1221 1227 1222 /* Setup name-editor: */ 1228 m_pNameEditorWidget = new UIEditorGroupRename(name() , this);1223 m_pNameEditorWidget = new UIEditorGroupRename(name()); 1229 1224 m_pNameEditorWidget->setFont(m_nameFont); 1230 1225 connect(m_pNameEditorWidget, &UIEditorGroupRename::sigEditingFinished, 1231 1226 this, &UIChooserItemGroup::sltNameEditingFinished); 1232 m_pNameEditor = new QGraphicsProxyWidget(this);1233 m_pNameEditor->setWidget(m_pNameEditorWidget);1234 m_pNameEditor->hide();1235 1227 } 1236 1228 /* Items except main root: */ … … 1879 1871 *********************************************************************************************************************************/ 1880 1872 1881 UIEditorGroupRename::UIEditorGroupRename(const QString &strName , UIChooserItem *pParent)1882 : m_pParent(pParent)1873 UIEditorGroupRename::UIEditorGroupRename(const QString &strName) 1874 : QWidget(0, Qt::Popup) 1883 1875 , m_pLineEdit(0) 1884 , m_pTemporaryMenu(0)1885 1876 { 1886 1877 /* Create layout: */ … … 1895 1886 if (m_pLineEdit) 1896 1887 { 1888 setFocusProxy(m_pLineEdit); 1889 m_pLineEdit->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 1897 1890 m_pLineEdit->setTextMargins(0, 0, 0, 0); 1898 1891 connect(m_pLineEdit, &QLineEdit::returnPressed, … … 1903 1896 pLayout->addWidget(m_pLineEdit); 1904 1897 } 1905 1906 /* Install event-filter: */ 1907 m_pLineEdit->installEventFilter(this); 1898 } 1899 1900 QString UIEditorGroupRename::text() const 1901 { 1902 return m_pLineEdit->text(); 1908 1903 } 1909 1904 … … 1911 1906 { 1912 1907 m_pLineEdit->setText(strText); 1913 }1914 1915 QString UIEditorGroupRename::text() const1916 {1917 return m_pLineEdit->text();1918 1908 } 1919 1909 … … 1923 1913 m_pLineEdit->setFont(font); 1924 1914 } 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 28 28 29 29 /* Forward declarations: */ 30 class QGraphicsProxyWidget;31 30 class QGraphicsScene; 32 class QLineEdit;33 31 class QMenu; 34 32 class QMimeData; … … 346 344 347 345 /** 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; 351 347 /** @} */ 352 348 … … 410 406 public: 411 407 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; 415 413 /** Defines editor @a strText. */ 416 414 void setText(const QString &strText); 417 /** Returns editor text. */418 QString text() const;419 415 420 416 /** Defines editor @a font. */ 421 417 void setFont(const QFont &font); 422 418 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 433 419 private: 434 435 /** Handles context-menu @a pEvent. */436 void handleContextMenuEvent(QContextMenuEvent *pEvent);437 438 /** Holds the parent reference. */439 UIChooserItem *m_pParent;440 420 441 421 /** Holds the line-edit instance. */ 442 422 QLineEdit *m_pLineEdit; 443 /** Holds the conect-menu instance. */444 QMenu *m_pTemporaryMenu;445 423 }; 446 424
Note:
See TracChangeset
for help on using the changeset viewer.