Changeset 72026 in vbox
- Timestamp:
- Apr 25, 2018 5:17:52 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 122289
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r72025 r72026 466 466 src/runtime/UISession.h \ 467 467 src/runtime/UISlidingToolBar.h \ 468 src/runtime/UIStatusBarEditorWindow.h \469 468 src/runtime/UIVMCloseDialog.h \ 470 469 src/runtime/fullscreen/UIKeyboardHandlerFullscreen.h \ … … 688 687 src/widgets/UIProgressDialog.h \ 689 688 src/widgets/UISpecialControls.h \ 689 src/widgets/UIStatusBarEditorWindow.h \ 690 690 src/widgets/UIToolBar.h \ 691 691 src/widgets/UIWarningPane.h \ … … 796 796 src/widgets/UIProgressDialog.h \ 797 797 src/widgets/UISpecialControls.h \ 798 src/widgets/UIStatusBarEditorWindow.h \ 798 799 src/widgets/UIToolBar.h \ 799 800 src/widgets/UIWarningPane.h \ … … 838 839 src/runtime/UIFrameBuffer.cpp \ 839 840 src/runtime/UIIndicatorsPool.cpp \ 840 src/runtime/UIStatusBarEditorWindow.cpp \841 841 src/runtime/guestctrl/UIGuestControlFileManager.cpp \ 842 842 src/runtime/guestctrl/UIGuestControlFileTable.cpp \ … … 876 876 src/widgets/UIHotKeyEditor.cpp \ 877 877 src/widgets/UIPortForwardingTable.cpp \ 878 src/widgets/UIProgressDialog.cpp 878 src/widgets/UIProgressDialog.cpp \ 879 src/widgets/UIStatusBarEditorWindow.cpp 879 880 880 881 VirtualBox_QT_MOCSRCS.linux += \ … … 917 918 src/widgets/UIHotKeyEditor.cpp \ 918 919 src/widgets/UIPortForwardingTable.cpp \ 919 src/widgets/UIProgressDialog.cpp 920 src/widgets/UIProgressDialog.cpp \ 921 src/widgets/UIStatusBarEditorWindow.cpp 920 922 921 923 VBoxGlobal_QT_MOCSRCS.linux += \ … … 974 976 src/runtime/UISession.cpp \ 975 977 src/runtime/UISlidingToolBar.cpp \ 976 src/runtime/UIStatusBarEditorWindow.cpp \977 978 src/runtime/UIVMCloseDialog.cpp \ 978 979 src/runtime/fullscreen/UIKeyboardHandlerFullscreen.cpp \ … … 1235 1236 src/widgets/UIProgressDialog.cpp \ 1236 1237 src/widgets/UISpecialControls.cpp \ 1238 src/widgets/UIStatusBarEditorWindow.cpp \ 1237 1239 src/widgets/UIToolBar.cpp \ 1238 1240 src/widgets/UIWarningPane.cpp \ … … 1369 1371 src/widgets/UIProgressDialog.cpp \ 1370 1372 src/widgets/UISpecialControls.cpp \ 1373 src/widgets/UIStatusBarEditorWindow.cpp \ 1371 1374 src/widgets/UIToolBar.cpp \ 1372 1375 src/widgets/UIWarningPane.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIStatusBarEditorWindow.cpp
r72025 r72026 5 5 6 6 /* 7 * Copyright (C) 2014-201 7Oracle Corporation7 * Copyright (C) 2014-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 22 22 /* Qt includes: */ 23 23 # include <QAccessibleWidget> 24 # include <QCheckBox> 25 # include <QDrag> 26 # include <QHBoxLayout> 27 # include <QMimeData> 28 # include <QMouseEvent> 29 # include <QPainter> 30 # include <QPaintEvent> 31 # include <QPixmap> 32 # include <QStatusBar> 33 # include <QStyleOption> 24 34 # include <QStylePainter> 25 # include <QStyleOption>26 # include <QHBoxLayout>27 # include <QPaintEvent>28 # include <QMouseEvent>29 # include <QStatusBar>30 # include <QCheckBox>31 # include <QMimeData>32 # include <QPainter>33 # include <QPixmap>34 # include <QDrag>35 35 36 36 /* GUI includes: */ 37 # include "UIStatusBarEditorWindow.h"38 # include "UIExtraDataManager.h"39 # include "UIMachineWindow.h"40 # include "UIConverter.h"41 # include "UIIconPool.h"42 37 # include "QIToolButton.h" 43 38 # include "VBoxGlobal.h" 39 # include "UIConverter.h" 40 # include "UIExtraDataManager.h" 41 # include "UIIconPool.h" 42 # include "UIMachineWindow.h" 43 # include "UIStatusBarEditorWindow.h" 44 44 45 45 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 46 46 47 48 /** QWidget extension 49 * used as status-bar editor button. */ 47 /* Forward declarations: */ 48 class QAccessibleInterface; 49 class QMouseEvent; 50 class QObject; 51 class QPixmap; 52 class QPoint; 53 class QSize; 54 55 56 /** QWidget subclass used as status-bar editor button. */ 50 57 class UIStatusBarEditorButton : public QIWithRetranslateUI<QWidget> 51 58 { … … 65 72 static const QString MimeType; 66 73 67 /** Construct or for the button of passed @a type. */68 UIStatusBarEditorButton(IndicatorType type);74 /** Constructs the button of passed @a enmType. */ 75 UIStatusBarEditorButton(IndicatorType enmType); 69 76 70 77 /** Returns button type. */ 71 IndicatorType type() const { return m_ type; }78 IndicatorType type() const { return m_enmType; } 72 79 73 80 /** Returns button size-hint. */ … … 79 86 void setChecked(bool fChecked); 80 87 88 protected: 89 90 /** Handles translation event. */ 91 virtual void retranslateUi() /* override */; 92 93 /** Handles paint @a pEvent. */ 94 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 95 96 /** Handles mouse-press @a pEvent. */ 97 virtual void mousePressEvent(QMouseEvent *pEvent); 98 /** Handles mouse-release @a pEvent. */ 99 virtual void mouseReleaseEvent(QMouseEvent *pEvent); 100 /** Handles mouse-enter @a pEvent. */ 101 virtual void enterEvent(QEvent *pEvent); 102 /** Handles mouse-leave @a pEvent. */ 103 virtual void leaveEvent(QEvent *pEvent); 104 /** Handles mouse-move @a pEvent. */ 105 virtual void mouseMoveEvent(QMouseEvent *pEvent); 106 81 107 private: 82 108 83 /** Retranslation routine. */84 virtual void retranslateUi();85 86 /** Paint-event handler. */87 virtual void paintEvent(QPaintEvent *pEvent);88 89 /** Mouse-press event handler. */90 virtual void mousePressEvent(QMouseEvent *pEvent);91 /** Mouse-release event handler. */92 virtual void mouseReleaseEvent(QMouseEvent *pEvent);93 /** Mouse-enter event handler. */94 virtual void enterEvent(QEvent *pEvent);95 /** Mouse-leave event handler. */96 virtual void leaveEvent(QEvent *pEvent);97 /** Mouse-move event handler. */98 virtual void mouseMoveEvent(QMouseEvent *pEvent);99 100 109 /** Holds the button type. */ 101 IndicatorType m_type;110 IndicatorType m_enmType; 102 111 /** Holds the button size. */ 103 QSize m_size;112 QSize m_size; 104 113 /** Holds the button pixmap. */ 105 QPixmap m_pixmap;114 QPixmap m_pixmap; 106 115 /** Holds the button pixmap size. */ 107 QSize m_pixmapSize;116 QSize m_pixmapSize; 108 117 /** Holds whether button is checked. */ 109 bool m_fChecked;118 bool m_fChecked; 110 119 /** Holds whether button is hovered. */ 111 bool m_fHovered;120 bool m_fHovered; 112 121 /** Holds the last mouse-press position. */ 113 QPoint m_mousePressPosition;122 QPoint m_mousePressPosition; 114 123 }; 115 124 … … 186 195 187 196 188 189 197 /********************************************************************************************************************************* 190 198 * Class UIStatusBarEditorButton implementation. * … … 194 202 const QString UIStatusBarEditorButton::MimeType = QString("application/virtualbox;value=IndicatorType"); 195 203 196 UIStatusBarEditorButton::UIStatusBarEditorButton(IndicatorType type)197 : m_ type(type)204 UIStatusBarEditorButton::UIStatusBarEditorButton(IndicatorType enmType) 205 : m_enmType(enmType) 198 206 , m_fChecked(false) 199 207 , m_fHovered(false) … … 203 211 204 212 /* Prepare icon for assigned type: */ 205 const QIcon icon = gpConverter->toIcon(m_ type);213 const QIcon icon = gpConverter->toIcon(m_enmType); 206 214 const QStyle *pStyle = QApplication::style(); 207 215 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize); … … 239 247 } 240 248 241 void UIStatusBarEditorButton::paintEvent(QPaintEvent *)249 void UIStatusBarEditorButton::paintEvent(QPaintEvent *) 242 250 { 243 251 /* Create style-painter: */ … … 290 298 } 291 299 292 void UIStatusBarEditorButton::enterEvent(QEvent *)300 void UIStatusBarEditorButton::enterEvent(QEvent *) 293 301 { 294 302 /* Make sure button isn't hovered: */ … … 302 310 } 303 311 304 void UIStatusBarEditorButton::leaveEvent(QEvent *)312 void UIStatusBarEditorButton::leaveEvent(QEvent *) 305 313 { 306 314 /* Make sure button is hovered: */ … … 335 343 connect(pDrag, SIGNAL(destroyed(QObject*)), this, SIGNAL(sigDragObjectDestroy())); 336 344 QMimeData *pMimeData = new QMimeData; 337 pMimeData->setData(MimeType, gpConverter->toInternalString(m_ type).toLatin1());345 pMimeData->setData(MimeType, gpConverter->toInternalString(m_enmType).toLatin1()); 338 346 pDrag->setMimeData(pMimeData); 339 347 pDrag->setPixmap(m_pixmap); … … 341 349 } 342 350 351 352 /********************************************************************************************************************************* 353 * Class UIStatusBarEditorWindow implementation. * 354 *********************************************************************************************************************************/ 355 356 UIStatusBarEditorWindow::UIStatusBarEditorWindow(UIMachineWindow *pParent) 357 : UISlidingToolBar(pParent, pParent->statusBar(), new UIStatusBarEditorWidget(0, false, vboxGlobal().managedVMUuid()), UISlidingToolBar::Position_Bottom) 358 { 359 } 360 361 362 /********************************************************************************************************************************* 363 * Class UIStatusBarEditorWidget implementation. * 364 *********************************************************************************************************************************/ 343 365 344 366 UIStatusBarEditorWidget::UIStatusBarEditorWidget(QWidget *pParent, … … 402 424 403 425 /* Update configuration for all existing buttons: */ 404 foreach (const IndicatorType & type, m_order)426 foreach (const IndicatorType &enmType, m_order) 405 427 { 406 428 /* Get button: */ 407 UIStatusBarEditorButton *pButton = m_buttons.value( type);429 UIStatusBarEditorButton *pButton = m_buttons.value(enmType); 408 430 /* Make sure button exists: */ 409 431 if (!pButton) 410 432 continue; 411 433 /* Update button 'checked' state: */ 412 pButton->setChecked(!m_restrictions.contains( type));434 pButton->setChecked(!m_restrictions.contains(enmType)); 413 435 /* Make sure it have valid position: */ 414 const int iWantedIndex = position( type);436 const int iWantedIndex = position(enmType); 415 437 const int iActualIndex = m_pButtonLayout->indexOf(pButton); 416 438 if (iActualIndex != iWantedIndex) … … 423 445 } 424 446 447 void UIStatusBarEditorWidget::retranslateUi() 448 { 449 /* Translate close-button if necessary: */ 450 if (!m_fStartedFromVMSettings && m_pButtonClose) 451 m_pButtonClose->setToolTip(tr("Close")); 452 /* Translate enable-checkbox if necessary: */ 453 if (m_fStartedFromVMSettings && m_pCheckBoxEnable) 454 m_pCheckBoxEnable->setToolTip(tr("Enable Status Bar")); 455 } 456 457 void UIStatusBarEditorWidget::paintEvent(QPaintEvent *) 458 { 459 /* Prepare painter: */ 460 QPainter painter(this); 461 462 /* Prepare palette colors: */ 463 const QPalette pal = palette(); 464 QColor color0 = pal.color(QPalette::Window); 465 QColor color1 = pal.color(QPalette::Window).lighter(110); 466 color1.setAlpha(0); 467 QColor color2 = pal.color(QPalette::Window).darker(200); 468 #if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11) 469 QColor color3 = pal.color(QPalette::Window).darker(120); 470 #endif /* VBOX_WS_WIN || VBOX_WS_X11 */ 471 472 /* Acquire metric: */ 473 const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4; 474 475 /* Left corner: */ 476 QRadialGradient grad1(QPointF(iMetric, iMetric), iMetric); 477 { 478 grad1.setColorAt(0, color2); 479 grad1.setColorAt(1, color1); 480 } 481 /* Right corner: */ 482 QRadialGradient grad2(QPointF(width() - iMetric, iMetric), iMetric); 483 { 484 grad2.setColorAt(0, color2); 485 grad2.setColorAt(1, color1); 486 } 487 /* Top line: */ 488 QLinearGradient grad3(QPointF(iMetric, 0), QPointF(iMetric, iMetric)); 489 { 490 grad3.setColorAt(0, color1); 491 grad3.setColorAt(1, color2); 492 } 493 /* Left line: */ 494 QLinearGradient grad4(QPointF(0, iMetric), QPointF(iMetric, iMetric)); 495 { 496 grad4.setColorAt(0, color1); 497 grad4.setColorAt(1, color2); 498 } 499 /* Right line: */ 500 QLinearGradient grad5(QPointF(width(), iMetric), QPointF(width() - iMetric, iMetric)); 501 { 502 grad5.setColorAt(0, color1); 503 grad5.setColorAt(1, color2); 504 } 505 506 /* Paint shape/shadow: */ 507 painter.fillRect(QRect(iMetric, iMetric, width() - iMetric * 2, height() - iMetric), color0); // background 508 painter.fillRect(QRect(0, 0, iMetric, iMetric), grad1); // left corner 509 painter.fillRect(QRect(width() - iMetric, 0, iMetric, iMetric), grad2); // right corner 510 painter.fillRect(QRect(iMetric, 0, width() - iMetric * 2, iMetric), grad3); // bottom line 511 painter.fillRect(QRect(0, iMetric, iMetric, height() - iMetric), grad4); // left line 512 painter.fillRect(QRect(width() - iMetric, iMetric, iMetric, height() - iMetric), grad5); // right line 513 514 #if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11) 515 /* Paint frames: */ 516 painter.save(); 517 painter.setPen(color3); 518 painter.drawLine(QLine(QPoint(iMetric + 1, iMetric + 1), 519 QPoint(width() - 1 - iMetric - 1, iMetric + 1))); 520 painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, iMetric + 1), 521 QPoint(width() - 1 - iMetric - 1, height() - 1))); 522 painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, height() - 1), 523 QPoint(iMetric + 1, height() - 1))); 524 painter.drawLine(QLine(QPoint(iMetric + 1, height() - 1), 525 QPoint(iMetric + 1, iMetric + 1))); 526 painter.restore(); 527 #endif /* VBOX_WS_WIN || VBOX_WS_X11 */ 528 529 /* Paint drop token: */ 530 if (m_pButtonDropToken) 531 { 532 QStyleOption option; 533 option.state |= QStyle::State_Horizontal; 534 const QRect geo = m_pButtonDropToken->geometry(); 535 option.rect = !m_fDropAfterTokenButton ? 536 QRect(geo.topLeft() - QPoint(iMetric, iMetric), 537 geo.bottomLeft() + QPoint(0, iMetric)) : 538 QRect(geo.topRight() - QPoint(0, iMetric), 539 geo.bottomRight() + QPoint(iMetric, iMetric)); 540 QApplication::style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, 541 &option, &painter); 542 } 543 } 544 545 void UIStatusBarEditorWidget::dragEnterEvent(QDragEnterEvent *pEvent) 546 { 547 /* Make sure event is valid: */ 548 AssertPtrReturnVoid(pEvent); 549 /* And mime-data is set: */ 550 const QMimeData *pMimeData = pEvent->mimeData(); 551 AssertPtrReturnVoid(pMimeData); 552 /* Make sure mime-data format is valid: */ 553 if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType)) 554 return; 555 556 /* Accept drag-enter event: */ 557 pEvent->acceptProposedAction(); 558 } 559 560 void UIStatusBarEditorWidget::dragMoveEvent(QDragMoveEvent *pEvent) 561 { 562 /* Make sure event is valid: */ 563 AssertPtrReturnVoid(pEvent); 564 /* And mime-data is set: */ 565 const QMimeData *pMimeData = pEvent->mimeData(); 566 AssertPtrReturnVoid(pMimeData); 567 /* Make sure mime-data format is valid: */ 568 if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType)) 569 return; 570 571 /* Reset token: */ 572 m_pButtonDropToken = 0; 573 m_fDropAfterTokenButton = true; 574 575 /* Get event position: */ 576 const QPoint pos = pEvent->pos(); 577 /* Search for most suitable button: */ 578 foreach (const IndicatorType &enmType, m_order) 579 { 580 m_pButtonDropToken = m_buttons.value(enmType); 581 const QRect geo = m_pButtonDropToken->geometry(); 582 if (pos.x() < geo.center().x()) 583 { 584 m_fDropAfterTokenButton = false; 585 break; 586 } 587 } 588 /* Update: */ 589 update(); 590 } 591 592 void UIStatusBarEditorWidget::dragLeaveEvent(QDragLeaveEvent *) 593 { 594 /* Reset token: */ 595 m_pButtonDropToken = 0; 596 m_fDropAfterTokenButton = true; 597 /* Update: */ 598 update(); 599 } 600 601 void UIStatusBarEditorWidget::dropEvent(QDropEvent *pEvent) 602 { 603 /* Make sure event is valid: */ 604 AssertPtrReturnVoid(pEvent); 605 /* And mime-data is set: */ 606 const QMimeData *pMimeData = pEvent->mimeData(); 607 AssertPtrReturnVoid(pMimeData); 608 /* Make sure mime-data format is valid: */ 609 if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType)) 610 return; 611 612 /* Make sure token-button set: */ 613 if (!m_pButtonDropToken) 614 return; 615 616 /* Determine type of token-button: */ 617 const IndicatorType tokenType = m_pButtonDropToken->type(); 618 /* Determine type of dropped-button: */ 619 const QString strDroppedType = 620 QString::fromLatin1(pMimeData->data(UIStatusBarEditorButton::MimeType)); 621 const IndicatorType droppedType = 622 gpConverter->fromInternalString<IndicatorType>(strDroppedType); 623 624 /* Make sure these types are different: */ 625 if (droppedType == tokenType) 626 return; 627 628 /* Remove type of dropped-button: */ 629 m_order.removeAll(droppedType); 630 /* Insert type of dropped-button into position of token-button: */ 631 int iPosition = m_order.indexOf(tokenType); 632 if (m_fDropAfterTokenButton) 633 ++iPosition; 634 m_order.insert(iPosition, droppedType); 635 636 if (m_fStartedFromVMSettings) 637 { 638 /* Reapply status-bar configuration from cache: */ 639 setStatusBarConfiguration(m_restrictions, m_order); 640 } 641 else 642 { 643 /* Save updated status-bar indicator order: */ 644 gEDataManager->setStatusBarIndicatorOrder(m_order, machineID()); 645 } 646 } 647 425 648 void UIStatusBarEditorWidget::sltHandleConfigurationChange(const QString &strMachineID) 426 649 { … … 441 664 442 665 /* Get sender type: */ 443 const IndicatorType type = pButton->type();666 const IndicatorType enmType = pButton->type(); 444 667 445 668 /* Invert restriction for sender type: */ 446 if (m_restrictions.contains( type))447 m_restrictions.removeAll( type);669 if (m_restrictions.contains(enmType)) 670 m_restrictions.removeAll(enmType); 448 671 else 449 m_restrictions.append( type);672 m_restrictions.append(enmType); 450 673 451 674 if (m_fStartedFromVMSettings) … … 570 793 { 571 794 /* Get current type: */ 572 const IndicatorType type = (IndicatorType)i;795 const IndicatorType enmType = (IndicatorType)i; 573 796 /* Skip inappropriate types: */ 574 if ( type == IndicatorType_Invalid || type == IndicatorType_KeyboardExtension)797 if (enmType == IndicatorType_Invalid || enmType == IndicatorType_KeyboardExtension) 575 798 continue; 576 799 /* Create status button: */ 577 prepareStatusButton( type);800 prepareStatusButton(enmType); 578 801 } 579 802 … … 589 812 } 590 813 591 void UIStatusBarEditorWidget::prepareStatusButton(IndicatorType type)814 void UIStatusBarEditorWidget::prepareStatusButton(IndicatorType enmType) 592 815 { 593 816 /* Create status button: */ 594 UIStatusBarEditorButton *pButton = new UIStatusBarEditorButton( type);817 UIStatusBarEditorButton *pButton = new UIStatusBarEditorButton(enmType); 595 818 AssertPtrReturnVoid(pButton); 596 819 { … … 601 824 m_pButtonLayout->addWidget(pButton); 602 825 /* Insert status button into map: */ 603 m_buttons.insert(type, pButton); 604 } 605 } 606 607 void UIStatusBarEditorWidget::retranslateUi() 608 { 609 /* Translate close-button if necessary: */ 610 if (!m_fStartedFromVMSettings && m_pButtonClose) 611 m_pButtonClose->setToolTip(tr("Close")); 612 /* Translate enable-checkbox if necessary: */ 613 if (m_fStartedFromVMSettings && m_pCheckBoxEnable) 614 m_pCheckBoxEnable->setToolTip(tr("Enable Status Bar")); 615 } 616 617 void UIStatusBarEditorWidget::paintEvent(QPaintEvent*) 618 { 619 /* Prepare painter: */ 620 QPainter painter(this); 621 622 /* Prepare palette colors: */ 623 const QPalette pal = palette(); 624 QColor color0 = pal.color(QPalette::Window); 625 QColor color1 = pal.color(QPalette::Window).lighter(110); 626 color1.setAlpha(0); 627 QColor color2 = pal.color(QPalette::Window).darker(200); 628 #if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11) 629 QColor color3 = pal.color(QPalette::Window).darker(120); 630 #endif /* VBOX_WS_WIN || VBOX_WS_X11 */ 631 632 /* Acquire metric: */ 633 const int iMetric = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize) / 4; 634 635 /* Left corner: */ 636 QRadialGradient grad1(QPointF(iMetric, iMetric), iMetric); 637 { 638 grad1.setColorAt(0, color2); 639 grad1.setColorAt(1, color1); 640 } 641 /* Right corner: */ 642 QRadialGradient grad2(QPointF(width() - iMetric, iMetric), iMetric); 643 { 644 grad2.setColorAt(0, color2); 645 grad2.setColorAt(1, color1); 646 } 647 /* Top line: */ 648 QLinearGradient grad3(QPointF(iMetric, 0), QPointF(iMetric, iMetric)); 649 { 650 grad3.setColorAt(0, color1); 651 grad3.setColorAt(1, color2); 652 } 653 /* Left line: */ 654 QLinearGradient grad4(QPointF(0, iMetric), QPointF(iMetric, iMetric)); 655 { 656 grad4.setColorAt(0, color1); 657 grad4.setColorAt(1, color2); 658 } 659 /* Right line: */ 660 QLinearGradient grad5(QPointF(width(), iMetric), QPointF(width() - iMetric, iMetric)); 661 { 662 grad5.setColorAt(0, color1); 663 grad5.setColorAt(1, color2); 664 } 665 666 /* Paint shape/shadow: */ 667 painter.fillRect(QRect(iMetric, iMetric, width() - iMetric * 2, height() - iMetric), color0); // background 668 painter.fillRect(QRect(0, 0, iMetric, iMetric), grad1); // left corner 669 painter.fillRect(QRect(width() - iMetric, 0, iMetric, iMetric), grad2); // right corner 670 painter.fillRect(QRect(iMetric, 0, width() - iMetric * 2, iMetric), grad3); // bottom line 671 painter.fillRect(QRect(0, iMetric, iMetric, height() - iMetric), grad4); // left line 672 painter.fillRect(QRect(width() - iMetric, iMetric, iMetric, height() - iMetric), grad5); // right line 673 674 #if defined(VBOX_WS_WIN) || defined(VBOX_WS_X11) 675 /* Paint frames: */ 676 painter.save(); 677 painter.setPen(color3); 678 painter.drawLine(QLine(QPoint(iMetric + 1, iMetric + 1), 679 QPoint(width() - 1 - iMetric - 1, iMetric + 1))); 680 painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, iMetric + 1), 681 QPoint(width() - 1 - iMetric - 1, height() - 1))); 682 painter.drawLine(QLine(QPoint(width() - 1 - iMetric - 1, height() - 1), 683 QPoint(iMetric + 1, height() - 1))); 684 painter.drawLine(QLine(QPoint(iMetric + 1, height() - 1), 685 QPoint(iMetric + 1, iMetric + 1))); 686 painter.restore(); 687 #endif /* VBOX_WS_WIN || VBOX_WS_X11 */ 688 689 /* Paint drop token: */ 690 if (m_pButtonDropToken) 691 { 692 QStyleOption option; 693 option.state |= QStyle::State_Horizontal; 694 const QRect geo = m_pButtonDropToken->geometry(); 695 option.rect = !m_fDropAfterTokenButton ? 696 QRect(geo.topLeft() - QPoint(iMetric, iMetric), 697 geo.bottomLeft() + QPoint(0, iMetric)) : 698 QRect(geo.topRight() - QPoint(0, iMetric), 699 geo.bottomRight() + QPoint(iMetric, iMetric)); 700 QApplication::style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, 701 &option, &painter); 702 } 703 } 704 705 void UIStatusBarEditorWidget::dragEnterEvent(QDragEnterEvent *pEvent) 706 { 707 /* Make sure event is valid: */ 708 AssertPtrReturnVoid(pEvent); 709 /* And mime-data is set: */ 710 const QMimeData *pMimeData = pEvent->mimeData(); 711 AssertPtrReturnVoid(pMimeData); 712 /* Make sure mime-data format is valid: */ 713 if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType)) 714 return; 715 716 /* Accept drag-enter event: */ 717 pEvent->acceptProposedAction(); 718 } 719 720 void UIStatusBarEditorWidget::dragMoveEvent(QDragMoveEvent *pEvent) 721 { 722 /* Make sure event is valid: */ 723 AssertPtrReturnVoid(pEvent); 724 /* And mime-data is set: */ 725 const QMimeData *pMimeData = pEvent->mimeData(); 726 AssertPtrReturnVoid(pMimeData); 727 /* Make sure mime-data format is valid: */ 728 if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType)) 729 return; 730 731 /* Reset token: */ 732 m_pButtonDropToken = 0; 733 m_fDropAfterTokenButton = true; 734 735 /* Get event position: */ 736 const QPoint pos = pEvent->pos(); 737 /* Search for most suitable button: */ 738 foreach (const IndicatorType &type, m_order) 739 { 740 m_pButtonDropToken = m_buttons.value(type); 741 const QRect geo = m_pButtonDropToken->geometry(); 742 if (pos.x() < geo.center().x()) 743 { 744 m_fDropAfterTokenButton = false; 745 break; 746 } 747 } 748 /* Update: */ 749 update(); 750 } 751 752 void UIStatusBarEditorWidget::dragLeaveEvent(QDragLeaveEvent*) 753 { 754 /* Reset token: */ 755 m_pButtonDropToken = 0; 756 m_fDropAfterTokenButton = true; 757 /* Update: */ 758 update(); 759 } 760 761 void UIStatusBarEditorWidget::dropEvent(QDropEvent *pEvent) 762 { 763 /* Make sure event is valid: */ 764 AssertPtrReturnVoid(pEvent); 765 /* And mime-data is set: */ 766 const QMimeData *pMimeData = pEvent->mimeData(); 767 AssertPtrReturnVoid(pMimeData); 768 /* Make sure mime-data format is valid: */ 769 if (!pMimeData->hasFormat(UIStatusBarEditorButton::MimeType)) 770 return; 771 772 /* Make sure token-button set: */ 773 if (!m_pButtonDropToken) 774 return; 775 776 /* Determine type of token-button: */ 777 const IndicatorType tokenType = m_pButtonDropToken->type(); 778 /* Determine type of dropped-button: */ 779 const QString strDroppedType = 780 QString::fromLatin1(pMimeData->data(UIStatusBarEditorButton::MimeType)); 781 const IndicatorType droppedType = 782 gpConverter->fromInternalString<IndicatorType>(strDroppedType); 783 784 /* Make sure these types are different: */ 785 if (droppedType == tokenType) 786 return; 787 788 /* Remove type of dropped-button: */ 789 m_order.removeAll(droppedType); 790 /* Insert type of dropped-button into position of token-button: */ 791 int iPosition = m_order.indexOf(tokenType); 792 if (m_fDropAfterTokenButton) 793 ++iPosition; 794 m_order.insert(iPosition, droppedType); 795 796 if (m_fStartedFromVMSettings) 797 { 798 /* Reapply status-bar configuration from cache: */ 799 setStatusBarConfiguration(m_restrictions, m_order); 800 } 801 else 802 { 803 /* Save updated status-bar indicator order: */ 804 gEDataManager->setStatusBarIndicatorOrder(m_order, machineID()); 805 } 806 } 807 808 int UIStatusBarEditorWidget::position(IndicatorType type) const 826 m_buttons.insert(enmType, pButton); 827 } 828 } 829 830 int UIStatusBarEditorWidget::position(IndicatorType enmType) const 809 831 { 810 832 int iPosition = 0; 811 833 foreach (const IndicatorType &iteratedType, m_order) 812 if (iteratedType == type)834 if (iteratedType == enmType) 813 835 return iPosition; 814 836 else … … 818 840 819 841 820 UIStatusBarEditorWindow::UIStatusBarEditorWindow(UIMachineWindow *pParent)821 : UISlidingToolBar(pParent, pParent->statusBar(), new UIStatusBarEditorWidget(0, false, vboxGlobal().managedVMUuid()), UISlidingToolBar::Position_Bottom)822 {823 }824 825 842 #include "UIStatusBarEditorWindow.moc" 826 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIStatusBarEditorWindow.h
r72025 r72026 5 5 6 6 /* 7 * Copyright (C) 2014-201 7Oracle Corporation7 * Copyright (C) 2014-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 21 21 /* Qt includes: */ 22 #include <QList> 22 23 #include <QMap> 23 #include <QList>24 24 25 25 /* GUI includes: */ 26 #include "QIWithRetranslateUI.h" 26 27 #include "UIExtraDataDefs.h" 28 #include "UILibraryDefs.h" 27 29 #include "UISlidingToolBar.h" 28 #include "QIWithRetranslateUI.h"29 30 30 31 /* Forward declarations: */ 32 class QCheckBox; 33 class QDragEnterEvent; 34 class QDragLeaveEvent; 35 class QDragMoveEvent; 36 class QDropEvent; 37 class QHBoxLayout; 38 class QPaintEvent; 39 class QString; 40 class QWidget; 41 class QIToolButton; 42 class UIMachineWindow; 31 43 class UIStatusBarEditorButton; 32 class UIMachineWindow;33 class QIToolButton;34 class QHBoxLayout;35 class QCheckBox;36 44 37 /** UISlidingToolBar wrapper 45 46 /** UISlidingToolBar subclass 38 47 * providing user with possibility to edit status-bar layout. */ 39 class UIStatusBarEditorWindow : public UISlidingToolBar48 class SHARED_LIBRARY_STUFF UIStatusBarEditorWindow : public UISlidingToolBar 40 49 { 41 50 Q_OBJECT; … … 43 52 public: 44 53 45 /** Construct or, passes @a pParent to the UISlidingToolBar constructor. */54 /** Constructs sliding toolbar passing @a pParent to the base-class. */ 46 55 UIStatusBarEditorWindow(UIMachineWindow *pParent); 47 56 }; 48 57 49 /** QWidget reimplementation 58 59 /** QWidget subclass 50 60 * used as status-bar editor widget. */ 51 class UIStatusBarEditorWidget : public QIWithRetranslateUI2<QWidget>61 class SHARED_LIBRARY_STUFF UIStatusBarEditorWidget : public QIWithRetranslateUI2<QWidget> 52 62 { 53 63 Q_OBJECT; … … 60 70 public: 61 71 62 /** Constructor, 63 * @param pParent is passed to QWidget constructor, 64 * @param fStartedFromVMSettings determines whether 'this' is a part of VM settings, 65 * @param strMachineID brings the machine ID to be used by the editor. */ 72 /** Constructs status-bar editor widget passing @a pParent to the base-class. 73 * @param fStartedFromVMSettings Brings whether 'this' is a part of VM settings. 74 * @param strMachineID Brings the machine ID to be used by the editor. */ 66 75 UIStatusBarEditorWidget(QWidget *pParent, 67 76 bool fStartedFromVMSettings = true, … … 69 78 70 79 /** Returns the machine ID instance. */ 71 const QString &machineID() const { return m_strMachineID; }80 const QString &machineID() const { return m_strMachineID; } 72 81 /** Defines the @a strMachineID instance. */ 73 82 void setMachineID(const QString &strMachineID); … … 79 88 80 89 /** Returns status-bar indicator restrictions. */ 81 const QList<IndicatorType> &statusBarIndicatorRestrictions() const { return m_restrictions; }90 const QList<IndicatorType> &statusBarIndicatorRestrictions() const { return m_restrictions; } 82 91 /** Returns status-bar indicator order. */ 83 const QList<IndicatorType> &statusBarIndicatorOrder() const { return m_order; }92 const QList<IndicatorType> &statusBarIndicatorOrder() const { return m_order; } 84 93 /** Defines status-bar indicator @a restrictions and @a order. */ 85 94 void setStatusBarConfiguration(const QList<IndicatorType> &restrictions, const QList<IndicatorType> &order); 95 96 protected: 97 98 /** Handles translation event. */ 99 virtual void retranslateUi() /* override */; 100 101 /** Handles paint @a pEvent. */ 102 virtual void paintEvent(QPaintEvent *pEvent) /* override */; 103 104 /** Handles drag-enter @a pEvent. */ 105 virtual void dragEnterEvent(QDragEnterEvent *pEvent) /* override */; 106 /** Handles drag-move @a pEvent. */ 107 virtual void dragMoveEvent(QDragMoveEvent *pEvent) /* override */; 108 /** Handles drag-leave @a pEvent. */ 109 virtual void dragLeaveEvent(QDragLeaveEvent *pEvent) /* override */; 110 /** Handles drop @a pEvent. */ 111 virtual void dropEvent(QDropEvent *pEvent) /* override */; 86 112 87 113 private slots: … … 98 124 private: 99 125 100 /** Prepare routine. */126 /** Prepares all. */ 101 127 void prepare(); 102 /** Prepare status buttons routine. */128 /** Prepares status-buttons. */ 103 129 void prepareStatusButtons(); 104 /** Prepare status button routine. */105 void prepareStatusButton(IndicatorType type);130 /** Prepares status-button of certain @a enmType. */ 131 void prepareStatusButton(IndicatorType enmType); 106 132 107 /** Retranslation routine. */ 108 virtual void retranslateUi(); 109 110 /** Paint event handler. */ 111 virtual void paintEvent(QPaintEvent *pEvent); 112 113 /** Drag-enter event handler. */ 114 virtual void dragEnterEvent(QDragEnterEvent *pEvent); 115 /** Drag-move event handler. */ 116 virtual void dragMoveEvent(QDragMoveEvent *pEvent); 117 /** Drag-leave event handler. */ 118 virtual void dragLeaveEvent(QDragLeaveEvent *pEvent); 119 /** Drop event handler. */ 120 virtual void dropEvent(QDropEvent *pEvent); 121 122 /** Returns position for passed @a type. */ 123 int position(IndicatorType type) const; 133 /** Returns position for passed @a enmType. */ 134 int position(IndicatorType enmType) const; 124 135 125 136 /** @name General 126 137 * @{ */ 127 138 /** Holds whether 'this' is prepared. */ 128 bool m_fPrepared;139 bool m_fPrepared; 129 140 /** Holds whether 'this' is a part of VM settings. */ 130 bool m_fStartedFromVMSettings;141 bool m_fStartedFromVMSettings; 131 142 /** Holds the machine ID instance. */ 132 QString m_strMachineID;143 QString m_strMachineID; 133 144 /** @} */ 134 145 … … 136 147 * @{ */ 137 148 /** Holds the main-layout instance. */ 138 QHBoxLayout *m_pMainLayout;149 QHBoxLayout *m_pMainLayout; 139 150 /** Holds the button-layout instance. */ 140 QHBoxLayout *m_pButtonLayout;151 QHBoxLayout *m_pButtonLayout; 141 152 /** Holds the close-button instance. */ 142 QIToolButton *m_pButtonClose;153 QIToolButton *m_pButtonClose; 143 154 /** Holds the enable-checkbox instance. */ 144 QCheckBox *m_pCheckBoxEnable;155 QCheckBox *m_pCheckBoxEnable; 145 156 /** Holds status-bar buttons. */ 146 QMap<IndicatorType, UIStatusBarEditorButton*> m_buttons;157 QMap<IndicatorType, UIStatusBarEditorButton*> m_buttons; 147 158 /** @} */ 148 159 … … 150 161 * @{ */ 151 162 /** Holds the cached status-bar button restrictions. */ 152 QList<IndicatorType> m_restrictions;163 QList<IndicatorType> m_restrictions; 153 164 /** @} */ 154 165 … … 156 167 * @{ */ 157 168 /** Holds the cached status-bar button order. */ 158 QList<IndicatorType> m_order;169 QList<IndicatorType> m_order; 159 170 /** Holds the token-button to drop dragged-button nearby. */ 160 171 UIStatusBarEditorButton *m_pButtonDropToken; 161 172 /** Holds whether dragged-button should be dropped <b>after</b> the token-button. */ 162 bool m_fDropAfterTokenButton;173 bool m_fDropAfterTokenButton; 163 174 /** @} */ 164 175 }; 165 176 177 166 178 #endif /* !___UIStatusBarEditorWindow_h___ */
Note:
See TracChangeset
for help on using the changeset viewer.