Changeset 50553 in vbox
- Timestamp:
- Feb 24, 2014 10:33:21 AM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.cpp
r45889 r50553 28 28 #include "UIHostComboEditor.h" 29 29 #include "VBoxGlobal.h" 30 #include "QIToolButton.h" 31 #include "UIIconPool.h" 30 32 31 33 #ifdef Q_WS_WIN … … 314 316 315 317 UIHostComboEditor::UIHostComboEditor(QWidget *pParent) 316 : QLineEdit(pParent) 317 , m_pReleaseTimer(0) 318 : QIWithRetranslateUI<QWidget>(pParent) 319 { 320 /* Prepare: */ 321 prepare(); 322 } 323 324 void UIHostComboEditor::prepare() 325 { 326 /* Configure self: */ 327 setAutoFillBackground(true); 328 /* Create layout: */ 329 QHBoxLayout *pLayout = new QHBoxLayout(this); 330 { 331 /* Configure layout: */ 332 pLayout->setSpacing(4); 333 pLayout->setContentsMargins(0, 0, 0, 0); 334 /* Create UIHostComboEditorPrivate instance: */ 335 m_pEditor = new UIHostComboEditorPrivate; 336 { 337 /* Configure UIHostComboEditorPrivate instance: */ 338 setFocusProxy(m_pEditor); 339 } 340 /* Create 'clear' tool-button: */ 341 m_pButtonClear = new QIToolButton; 342 { 343 /* Configure 'clear' tool-button: */ 344 m_pButtonClear->removeBorder(); 345 m_pButtonClear->setIcon(UIIconPool::iconSet(":/eraser_16px.png")); 346 connect(m_pButtonClear, SIGNAL(clicked(bool)), m_pEditor, SLOT(sltClear())); 347 } 348 /* Add widgets to layout: */ 349 pLayout->addWidget(m_pEditor); 350 pLayout->addWidget(m_pButtonClear); 351 } 352 /* Translate finally: */ 353 retranslateUi(); 354 } 355 356 void UIHostComboEditor::retranslateUi() 357 { 358 /* Translate 'clear' tool-button: */ 359 m_pButtonClear->setToolTip(QApplication::translate("UIHotKeyEditor", "Unset shortcut")); 360 } 361 362 void UIHostComboEditor::setCombo(const UIHostComboWrapper &strCombo) 363 { 364 /* Pass combo to child: */ 365 m_pEditor->setCombo(strCombo); 366 } 367 368 UIHostComboWrapper UIHostComboEditor::combo() const 369 { 370 /* Acquire combo from child: */ 371 return m_pEditor->combo(); 372 } 373 374 375 UIHostComboEditorPrivate::UIHostComboEditorPrivate() 376 : m_pReleaseTimer(0) 318 377 , m_fStartNewSequence(true) 319 378 { … … 321 380 setAttribute(Qt::WA_NativeWindow); 322 381 setContextMenuPolicy(Qt::NoContextMenu); 382 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); 323 383 connect(this, SIGNAL(selectionChanged()), this, SLOT(sltDeselect())); 324 384 … … 335 395 #ifdef Q_WS_MAC 336 396 m_uDarwinKeyModifiers = 0; 337 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, UIHostComboEditor ::darwinEventHandlerProc, this);397 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this); 338 398 ::DarwinGrabKeyboard(false /* just modifiers */); 339 399 #endif /* Q_WS_MAC */ 340 400 } 341 401 342 UIHostComboEditor ::~UIHostComboEditor()402 UIHostComboEditorPrivate::~UIHostComboEditorPrivate() 343 403 { 344 404 #ifdef Q_WS_MAC 345 405 ::DarwinReleaseKeyboard(); 346 UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, UIHostComboEditor ::darwinEventHandlerProc, this);406 UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this); 347 407 #endif /* Q_WS_MAC */ 348 408 } 349 409 350 void UIHostComboEditor ::setCombo(const UIHostComboWrapper &strCombo)410 void UIHostComboEditorPrivate::setCombo(const UIHostComboWrapper &strCombo) 351 411 { 352 412 /* Cleanup old combo: */ … … 361 421 } 362 422 363 UIHostComboWrapper UIHostComboEditor ::combo() const423 UIHostComboWrapper UIHostComboEditorPrivate::combo() const 364 424 { 365 425 /* Compose current combination: */ … … 372 432 } 373 433 374 void UIHostComboEditor ::sltDeselect()434 void UIHostComboEditorPrivate::sltDeselect() 375 435 { 376 436 deselect(); 377 437 } 378 438 379 void UIHostComboEditor::sltClear() 380 { 439 void UIHostComboEditorPrivate::sltClear() 440 { 441 /* Cleanup combo: */ 381 442 m_shownKeys.clear(); 443 /* Update text: */ 382 444 updateText(); 445 /* Move the focus to text-field: */ 446 setFocus(); 383 447 } 384 448 … … 453 517 } 454 518 455 bool UIHostComboEditor ::winEvent(MSG *pMsg, long* /* pResult */)519 bool UIHostComboEditorPrivate::winEvent(MSG *pMsg, long* /* pResult */) 456 520 { 457 521 switch (pMsg->message) … … 484 548 #pragma GCC diagnostic push 485 549 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 486 bool UIHostComboEditor ::x11Event(XEvent *pEvent)550 bool UIHostComboEditorPrivate::x11Event(XEvent *pEvent) 487 551 { 488 552 switch (pEvent->type) … … 511 575 #ifdef Q_WS_MAC 512 576 /* static */ 513 bool UIHostComboEditor ::darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)514 { 515 UIHostComboEditor *pEditor = static_cast<UIHostComboEditor*>(pvUser);577 bool UIHostComboEditorPrivate::darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser) 578 { 579 UIHostComboEditorPrivate *pEditor = static_cast<UIHostComboEditorPrivate*>(pvUser); 516 580 EventRef inEvent = (EventRef)pvCarbonEvent; 517 581 UInt32 EventClass = ::GetEventClass(inEvent); … … 521 585 } 522 586 523 bool UIHostComboEditor ::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)587 bool UIHostComboEditorPrivate::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent) 524 588 { 525 589 /* Ignore key changes unless we're the focus widget: */ … … 567 631 #endif /* Q_WS_MAC */ 568 632 569 void UIHostComboEditor ::keyPressEvent(QKeyEvent *pEvent)633 void UIHostComboEditorPrivate::keyPressEvent(QKeyEvent *pEvent) 570 634 { 571 635 /* Ignore most of key presses... */ 572 636 switch (pEvent->key()) 573 637 { 638 case Qt::Key_Enter: 639 case Qt::Key_Return: 574 640 case Qt::Key_Tab: 575 641 case Qt::Key_Backtab: … … 587 653 } 588 654 589 void UIHostComboEditor ::keyReleaseEvent(QKeyEvent *pEvent)655 void UIHostComboEditorPrivate::keyReleaseEvent(QKeyEvent *pEvent) 590 656 { 591 657 /* Ignore most of key presses... */ … … 607 673 } 608 674 609 void UIHostComboEditor ::mousePressEvent(QMouseEvent *pEvent)675 void UIHostComboEditorPrivate::mousePressEvent(QMouseEvent *pEvent) 610 676 { 611 677 /* Handle like for usual QWidget: */ … … 613 679 } 614 680 615 void UIHostComboEditor ::mouseReleaseEvent(QMouseEvent *pEvent)681 void UIHostComboEditorPrivate::mouseReleaseEvent(QMouseEvent *pEvent) 616 682 { 617 683 /* Handle like for usual QWidget: */ … … 619 685 } 620 686 621 void UIHostComboEditor ::sltReleasePendingKeys()687 void UIHostComboEditorPrivate::sltReleasePendingKeys() 622 688 { 623 689 /* Stop the timer, we process all pending keys at once: */ … … 642 708 } 643 709 644 bool UIHostComboEditor ::processKeyEvent(int iKeyCode, bool fKeyPress)710 bool UIHostComboEditorPrivate::processKeyEvent(int iKeyCode, bool fKeyPress) 645 711 { 646 712 /* Check if symbol is valid else pass it to Qt: */ … … 695 761 } 696 762 697 void UIHostComboEditor ::updateText()763 void UIHostComboEditorPrivate::updateText() 698 764 { 699 765 QStringList shownKeyNames(m_shownKeys.values()); 700 setText(shownKeyNames.isEmpty() ? tr("None") : shownKeyNames.join(" + "));701 } 702 766 setText(shownKeyNames.isEmpty() ? UIHostComboEditor::tr("None") : shownKeyNames.join(" + ")); 767 } 768 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h
r44753 r50553 25 25 #include <QMap> 26 26 #include <QSet> 27 28 /* GUI includes: */ 29 #include "QIWithRetranslateUI.h" 30 31 /* Forward declarations: */ 32 class UIHostComboEditorPrivate; 33 class QIToolButton; 27 34 28 35 /* Native hot-key namespace to unify … … 69 76 Q_DECLARE_METATYPE(UIHostComboWrapper); 70 77 71 /* Host-combo editor widget:*/72 class UIHostComboEditor : public Q LineEdit78 /** Host-combo editor widget. */ 79 class UIHostComboEditor : public QIWithRetranslateUI<QWidget> 73 80 { 74 81 Q_OBJECT; … … 77 84 public: 78 85 86 /** Constructs host-combo editor for passed @a pParent. */ 79 87 UIHostComboEditor(QWidget *pParent); 80 ~UIHostComboEditor(); 88 89 private: 90 91 /** Prepares widget content. */ 92 void prepare(); 93 94 /** Translates widget content. */ 95 void retranslateUi(); 96 97 /** Defines host-combo sequence. */ 98 void setCombo(const UIHostComboWrapper &strCombo); 99 /** Returns host-combo sequence. */ 100 UIHostComboWrapper combo() const; 101 102 /** UIHostComboEditorPrivate instance. */ 103 UIHostComboEditorPrivate *m_pEditor; 104 /** <b>Clear</b> QIToolButton instance. */ 105 QIToolButton *m_pButtonClear; 106 }; 107 108 /* Host-combo editor widget private stuff: */ 109 class UIHostComboEditorPrivate : public QLineEdit 110 { 111 Q_OBJECT; 112 113 public: 114 115 UIHostComboEditorPrivate(); 116 ~UIHostComboEditorPrivate(); 81 117 82 118 void setCombo(const UIHostComboWrapper &strCombo);
Note:
See TracChangeset
for help on using the changeset viewer.