Changeset 29083 in vbox
- Timestamp:
- May 5, 2010 1:55:28 PM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMiniToolBar.cpp
r29061 r29083 7 7 8 8 /* 9 * Copyright (C) 2009 Oracle Corporation9 * Copyright (C) 2009-2010 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 18 18 */ 19 19 20 /* VBox includes */ 21 #include "VBoxGlobal.h" 22 #include "VBoxMiniToolBar.h" 23 24 /* Qt includes */ 20 /* Global includes */ 25 21 #include <QCursor> 26 22 #include <QDesktopWidget> … … 35 31 #include <QToolButton> 36 32 37 VBoxMiniToolBar::VBoxMiniToolBar (QWidget *aParent, Alignment aAlignment, bool aActive, bool aAutoHide) 38 : VBoxToolBar (aParent) 39 , mActive (aActive) 40 , mPolished (false) 41 , mSeamless (false) 42 , mAutoHide (aAutoHide) 43 , mSlideToScreen (true) 44 , mHideAfterSlide (false) 45 , mAutoHideCounter (0) 46 , mAlignment (aAlignment) 47 , mAnimated (true) 48 , mScrollDelay (10) 49 , mAutoScrollDelay (100) 50 , mAutoHideTotalCounter (10) 51 { 52 AssertMsg (parentWidget(), ("Parent widget must be set!!!\n")); 53 54 /* Various options */ 55 setIconSize (QSize (16, 16)); 56 setMouseTracking (mAutoHide); 57 setVisible (false); 58 59 /* Left margin of tool-bar */ 60 mMargins << widgetForAction (addWidget (new QWidget (this))); 61 62 /* Add pushpin */ 63 mAutoHideAct = new QAction (this); 64 mAutoHideAct->setIcon (VBoxGlobal::iconSet (":/pin_16px.png")); 65 mAutoHideAct->setToolTip (tr ("Always show the toolbar")); 66 mAutoHideAct->setCheckable (true); 67 mAutoHideAct->setChecked (!mAutoHide); 68 connect (mAutoHideAct, SIGNAL (toggled (bool)), this, SLOT (togglePushpin (bool))); 69 addAction (mAutoHideAct); 70 71 /* Left menu margin */ 72 mSpacings << widgetForAction (addWidget (new QWidget (this))); 73 74 /* Right menu margin */ 75 mInsertPosition = addWidget (new QWidget (this)); 76 mSpacings << widgetForAction (mInsertPosition); 77 78 /* Left label margin */ 79 mLabelMargins << widgetForAction (addWidget (new QWidget (this))); 80 81 /* Insert a label for VM Name */ 82 mDisplayLabel = new QLabel (this); 83 mDisplayLabel->setAlignment (Qt::AlignCenter); 84 addWidget (mDisplayLabel); 85 86 /* Right label margin */ 87 mLabelMargins << widgetForAction (addWidget (new QWidget (this))); 88 89 /* Exit action */ 90 QAction *restoreAct = new QAction (this); 91 restoreAct->setIcon (VBoxGlobal::iconSet (":/restore_16px.png")); 92 restoreAct->setToolTip (tr ("Exit Full Screen or Seamless Mode")); 93 connect (restoreAct, SIGNAL (triggered()), this, SIGNAL (exitAction())); 94 addAction (restoreAct); 95 96 /* Close action */ 97 QAction *closeAct = new QAction (this); 98 closeAct->setIcon (VBoxGlobal::iconSet (":/close_16px.png")); 99 closeAct->setToolTip (tr ("Close VM")); 100 connect (closeAct, SIGNAL (triggered()), this, SIGNAL (closeAction())); 101 addAction (closeAct); 102 103 /* Right margin of tool-bar */ 104 mMargins << widgetForAction (addWidget (new QWidget (this))); 105 106 aParent->installEventFilter(this); 107 } 108 109 VBoxMiniToolBar& VBoxMiniToolBar::operator<< (QList <QMenu*> aMenus) 110 { 111 for (int i = 0; i < aMenus.size(); ++ i) 112 { 113 QAction *action = aMenus [i]->menuAction(); 114 insertAction (mInsertPosition, action); 115 if (QToolButton *button = qobject_cast <QToolButton*> (widgetForAction (action))) 116 { 117 button->setPopupMode (QToolButton::InstantPopup); 118 button->setAutoRaise (true); 119 } 120 if (i != aMenus.size() - 1) 121 mSpacings << widgetForAction (insertWidget (mInsertPosition, new QWidget (this))); 33 /* Local includes */ 34 #include "VBoxMiniToolBar.h" 35 #include "VBoxGlobal.h" 36 37 /* Mini-toolbar constructor */ 38 VBoxMiniToolBar::VBoxMiniToolBar(QWidget *pParent, Alignment alignment, bool fActive, bool fAutoHide) 39 : VBoxToolBar(pParent) 40 , m_pAutoHideAction(0) 41 , m_pDisplayLabel(0) 42 , m_pRestoreAction(0) 43 , m_pCloseAction(0) 44 , m_fActive(fActive) 45 , m_fPolished(false) 46 , m_fSeamless(false) 47 , m_fAutoHide(fAutoHide) 48 , m_fSlideToScreen(true) 49 , m_fHideAfterSlide(false) 50 , m_iAutoHideCounter(0) 51 , m_iPositionX(0) 52 , m_iPositionY(0) 53 , m_pInsertPosition(0) 54 , m_alignment(alignment) 55 , m_fAnimated(true) 56 , m_iScrollDelay(10) 57 , m_iAutoScrollDelay(100) 58 , m_iAutoHideTotalCounter(10) 59 { 60 /* Check parent widget presence: */ 61 AssertMsg(parentWidget(), ("Parent widget must be set!\n")); 62 63 /* Toolbar options: */ 64 setIconSize(QSize(16, 16)); 65 setVisible(false); 66 67 /* Left margin of tool-bar: */ 68 m_Margins << widgetForAction(addWidget(new QWidget(this))); 69 70 /* Add pushpin: */ 71 m_pAutoHideAction = new QAction(this); 72 m_pAutoHideAction->setIcon(VBoxGlobal::iconSet(":/pin_16px.png")); 73 m_pAutoHideAction->setToolTip(tr("Always show the toolbar")); 74 m_pAutoHideAction->setCheckable(true); 75 m_pAutoHideAction->setChecked(!m_fAutoHide); 76 connect(m_pAutoHideAction, SIGNAL(toggled(bool)), this, SLOT(togglePushpin(bool))); 77 addAction(m_pAutoHideAction); 78 79 /* Left menu margin: */ 80 m_Spacings << widgetForAction(addWidget(new QWidget(this))); 81 82 /* Right menu margin: */ 83 m_pInsertPosition = addWidget(new QWidget(this)); 84 m_Spacings << widgetForAction(m_pInsertPosition); 85 86 /* Left label margin: */ 87 m_LabelMargins << widgetForAction(addWidget(new QWidget(this))); 88 89 /* Insert a label for VM Name: */ 90 m_pDisplayLabel = new QLabel(this); 91 m_pDisplayLabel->setAlignment(Qt::AlignCenter); 92 addWidget(m_pDisplayLabel); 93 94 /* Right label margin: */ 95 m_LabelMargins << widgetForAction(addWidget(new QWidget(this))); 96 97 /* Exit action: */ 98 m_pRestoreAction = new QAction(this); 99 m_pRestoreAction->setIcon(VBoxGlobal::iconSet(":/restore_16px.png")); 100 m_pRestoreAction->setToolTip(tr("Exit Full Screen or Seamless Mode")); 101 connect(m_pRestoreAction, SIGNAL(triggered()), this, SIGNAL(exitAction())); 102 addAction(m_pRestoreAction); 103 104 /* Close action: */ 105 m_pCloseAction = new QAction(this); 106 m_pCloseAction->setIcon(VBoxGlobal::iconSet(":/close_16px.png")); 107 m_pCloseAction->setToolTip(tr("Close VM")); 108 connect(m_pCloseAction, SIGNAL(triggered()), this, SIGNAL(closeAction())); 109 addAction(m_pCloseAction); 110 111 /* Right margin of tool-bar: */ 112 m_Margins << widgetForAction(addWidget(new QWidget(this))); 113 114 /* Event-filter for parent widget to control resize: */ 115 pParent->installEventFilter(this); 116 117 /* Enable mouse-tracking for this & children allowing to get mouse-move events: */ 118 setMouseTrackingEnabled(m_fAutoHide); 119 } 120 121 /* Appends passed menus into internal menu-list */ 122 VBoxMiniToolBar& VBoxMiniToolBar::operator<<(QList<QMenu*> menus) 123 { 124 for (int i = 0; i < menus.size(); ++i) 125 { 126 QAction *pAction = menus[i]->menuAction(); 127 insertAction(m_pInsertPosition, pAction); 128 if (QToolButton *pButton = qobject_cast<QToolButton*>(widgetForAction(pAction))) 129 { 130 pButton->setPopupMode(QToolButton::InstantPopup); 131 pButton->setAutoRaise(true); 132 } 133 if (i != menus.size() - 1) 134 m_Spacings << widgetForAction(insertWidget(m_pInsertPosition, new QWidget(this))); 122 135 } 123 136 return *this; 124 137 } 125 138 126 void VBoxMiniToolBar::setSeamlessMode (bool aSeamless) 127 { 128 mSeamless = aSeamless; 139 /* Seamless mode setter */ 140 void VBoxMiniToolBar::setSeamlessMode(bool fSeamless) 141 { 142 m_fSeamless = fSeamless; 129 143 } 130 144 131 145 /* Update the display text, usually the VM Name */ 132 void VBoxMiniToolBar::setDisplayText (const QString &aText) 133 { 134 if (mDisplayLabel->text() != aText) 135 { 136 /* Update toolbar label */ 137 mDisplayLabel->setText (aText); 138 139 /* Reinitialize */ 146 void VBoxMiniToolBar::setDisplayText(const QString &strText) 147 { 148 /* If text was really changed: */ 149 if (m_pDisplayLabel->text() != strText) 150 { 151 /* Update toolbar label: */ 152 m_pDisplayLabel->setText(strText); 153 154 /* Reinitialize: */ 140 155 initialize(); 141 156 157 /* Update toolbar if its not hidden: */ 142 158 if (!isHidden()) 143 updateDisplay (!mAutoHide, false); 144 } 145 } 146 159 updateDisplay(!m_fAutoHide, false); 160 } 161 } 162 163 /* Is auto-hide feature enabled? */ 147 164 bool VBoxMiniToolBar::isAutoHide() const 148 165 { 149 return m AutoHide;150 } 151 152 void VBoxMiniToolBar::updateDisplay (bool aShow, bool aSetHideFlag)153 { 154 m AutoHideCounter = 0;155 156 setMouseTracking (mAutoHide);157 158 if ( aShow)166 return m_fAutoHide; 167 } 168 169 void VBoxMiniToolBar::updateDisplay(bool fShow, bool fSetHideFlag) 170 { 171 m_iAutoHideCounter = 0; 172 173 setMouseTrackingEnabled(m_fAutoHide); 174 175 if (fShow) 159 176 { 160 177 if (isHidden()) 161 178 moveToBase(); 162 179 163 if (m Animated)164 { 165 if ( aSetHideFlag)180 if (m_fAnimated) 181 { 182 if (fSetHideFlag) 166 183 { 167 m HideAfterSlide = false;168 m SlideToScreen = true;184 m_fHideAfterSlide = false; 185 m_fSlideToScreen = true; 169 186 } 170 if (mActive) show(); 171 mScrollTimer.start (mScrollDelay, this); 172 } 173 else if (mActive) show(); 174 175 if (mAutoHide) 176 mAutoScrollTimer.start (mAutoScrollDelay, this); 187 if (m_fActive) 188 show(); 189 m_scrollTimer.start(m_iScrollDelay, this); 190 } 191 else if (m_fActive) 192 show(); 193 194 if (m_fAutoHide) 195 m_autoScrollTimer.start(m_iAutoScrollDelay, this); 177 196 else 178 m AutoScrollTimer.stop();197 m_autoScrollTimer.stop(); 179 198 } 180 199 else 181 200 { 182 if (m Animated)183 { 184 if ( aSetHideFlag)201 if (m_fAnimated) 202 { 203 if (fSetHideFlag) 185 204 { 186 m HideAfterSlide = true;187 m SlideToScreen = false;205 m_fHideAfterSlide = true; 206 m_fSlideToScreen = false; 188 207 } 189 m ScrollTimer.start (mScrollDelay, this);208 m_scrollTimer.start(m_iScrollDelay, this); 190 209 } 191 210 else 192 211 hide(); 193 212 194 if (m AutoHide)195 m AutoScrollTimer.start (mAutoScrollDelay, this);213 if (m_fAutoHide) 214 m_autoScrollTimer.start(m_iAutoScrollDelay, this); 196 215 else 197 mAutoScrollTimer.stop(); 198 } 199 } 200 201 void VBoxMiniToolBar::mouseMoveEvent (QMouseEvent *aEvent) 202 { 203 if (!mHideAfterSlide) 204 { 205 mSlideToScreen = true; 206 mScrollTimer.start (mScrollDelay, this); 207 } 208 209 QToolBar::mouseMoveEvent (aEvent); 210 } 211 212 /* Handles auto hide feature of the toolbar */ 213 void VBoxMiniToolBar::timerEvent (QTimerEvent *aEvent) 214 { 215 if (aEvent->timerId() == mScrollTimer.timerId()) 216 { 217 QRect screen = mSeamless ? vboxGlobal().availableGeometry (QApplication::desktop()->screenNumber(window())) : 218 QApplication::desktop()->screenGeometry (window()); 219 switch (mAlignment) 216 m_autoScrollTimer.stop(); 217 } 218 } 219 220 /* Parent widget event-filter */ 221 bool VBoxMiniToolBar::eventFilter(QObject *pObject, QEvent *pEvent) 222 { 223 /* If parent widget was resized: */ 224 if (pObject == parent() && pEvent->type() == QEvent::Resize) 225 { 226 /* Update toolbar position: */ 227 moveToBase(); 228 return true; 229 } 230 /* Base-class event-filter: */ 231 return VBoxToolBar::eventFilter(pObject, pEvent); 232 } 233 234 /* Mouse-move event processor */ 235 void VBoxMiniToolBar::mouseMoveEvent(QMouseEvent *pEvent) 236 { 237 /* Activate sliding animation on mouse move: */ 238 if (!m_fHideAfterSlide) 239 { 240 m_fSlideToScreen = true; 241 m_scrollTimer.start(m_iScrollDelay, this); 242 } 243 /* Base-class mouse-move event processing: */ 244 VBoxToolBar::mouseMoveEvent(pEvent); 245 } 246 247 /* Timer event processor 248 * Handles auto hide feature of the toolbar */ 249 void VBoxMiniToolBar::timerEvent(QTimerEvent *pEvent) 250 { 251 if (pEvent->timerId() == m_scrollTimer.timerId()) 252 { 253 QRect screen = m_fSeamless ? vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(window())) : 254 QApplication::desktop()->screenGeometry(window()); 255 switch (m_alignment) 220 256 { 221 257 case AlignTop: 222 258 { 223 if (((m PositionY == screen.y()) && mSlideToScreen) ||224 ((m PositionY == screen.y() - height() + 1) && !mSlideToScreen))259 if (((m_iPositionY == screen.y()) && m_fSlideToScreen) || 260 ((m_iPositionY == screen.y() - height() + 1) && !m_fSlideToScreen)) 225 261 { 226 m ScrollTimer.stop();227 if (m HideAfterSlide)262 m_scrollTimer.stop(); 263 if (m_fHideAfterSlide) 228 264 { 229 m HideAfterSlide = false;265 m_fHideAfterSlide = false; 230 266 hide(); 231 267 } 232 268 return; 233 269 } 234 m SlideToScreen ? ++ mPositionY : -- mPositionY;270 m_fSlideToScreen ? ++m_iPositionY : --m_iPositionY; 235 271 break; 236 272 } 237 273 case AlignBottom: 238 274 { 239 if (((m PositionY == screen.y() + screen.height() - height()) && mSlideToScreen) ||240 ((m PositionY == screen.y() + screen.height() - 1) && !mSlideToScreen))275 if (((m_iPositionY == screen.y() + screen.height() - height()) && m_fSlideToScreen) || 276 ((m_iPositionY == screen.y() + screen.height() - 1) && !m_fSlideToScreen)) 241 277 { 242 m ScrollTimer.stop();243 if (m HideAfterSlide)278 m_scrollTimer.stop(); 279 if (m_fHideAfterSlide) 244 280 { 245 m HideAfterSlide = false;281 m_fHideAfterSlide = false; 246 282 hide(); 247 283 } 248 284 return; 249 285 } 250 m SlideToScreen ? -- mPositionY : ++ mPositionY;286 m_fSlideToScreen ? --m_iPositionY : ++m_iPositionY; 251 287 break; 252 288 } … … 254 290 break; 255 291 } 256 move (mapFromScreen (QPoint (mPositionX, mPositionY)));292 move(parentWidget()->mapFromGlobal(QPoint(m_iPositionX, m_iPositionY))); 257 293 emit geometryUpdated(); 258 294 } 259 else if ( aEvent->timerId() == mAutoScrollTimer.timerId())295 else if (pEvent->timerId() == m_autoScrollTimer.timerId()) 260 296 { 261 297 QRect rect = this->rect(); 262 QPoint cursor_pos = QCursor::pos(); 263 QPoint p = mapFromGlobal (cursor_pos); 264 265 if (!rect.contains (p)) 266 { 267 ++ mAutoHideCounter; 268 269 if (mAutoHideCounter == mAutoHideTotalCounter) 298 QPoint p = mapFromGlobal(QCursor::pos()); 299 if (!rect.contains(p)) 300 { 301 ++m_iAutoHideCounter; 302 303 if (m_iAutoHideCounter == m_iAutoHideTotalCounter) 270 304 { 271 m SlideToScreen = false;272 m ScrollTimer.start (mScrollDelay, this);305 m_fSlideToScreen = false; 306 m_scrollTimer.start(m_iScrollDelay, this); 273 307 } 274 308 } 275 309 else 276 m AutoHideCounter = 0;310 m_iAutoHideCounter = 0; 277 311 } 278 312 else 279 QWidget::timerEvent (aEvent); 280 } 281 282 void VBoxMiniToolBar::showEvent (QShowEvent *aEvent) 283 { 284 if (!mPolished) 285 { 286 /* Tool-bar margins */ 287 foreach (QWidget *margin, mMargins) 288 margin->setMinimumWidth (height()); 289 290 /* Tool-bar spacings */ 291 foreach (QWidget *spacing, mSpacings) 292 spacing->setMinimumWidth (5); 293 294 /* Title spacings */ 295 foreach (QWidget *lableMargin, mLabelMargins) 296 lableMargin->setMinimumWidth (15); 297 298 /* Initialize */ 313 QWidget::timerEvent(pEvent); 314 } 315 316 /* Show event processor */ 317 void VBoxMiniToolBar::showEvent(QShowEvent *pEvent) 318 { 319 if (!m_fPolished) 320 { 321 /* Tool-bar margins: */ 322 foreach(QWidget *pMargin, m_Margins) 323 pMargin->setMinimumWidth(height()); 324 325 /* Tool-bar spacings: */ 326 foreach(QWidget *pSpacing, m_Spacings) 327 pSpacing->setMinimumWidth(5); 328 329 /* Title spacings: */ 330 foreach(QWidget *pLableMargin, m_LabelMargins) 331 pLableMargin->setMinimumWidth(15); 332 333 /* Initialize: */ 299 334 initialize(); 300 335 301 mPolished = true; 302 } 303 304 VBoxToolBar::showEvent (aEvent); 305 } 306 307 void VBoxMiniToolBar::paintEvent (QPaintEvent *aEvent) 308 { 336 m_fPolished = true; 337 } 338 /* Base-class show event processing: */ 339 VBoxToolBar::showEvent(pEvent); 340 } 341 342 /* Show event processor */ 343 void VBoxMiniToolBar::paintEvent(QPaintEvent *pEvent) 344 { 345 /* Paint background */ 309 346 QPainter painter; 310 painter.begin 311 painter.fillRect (aEvent->rect(), palette().brush(QPalette::Window));347 painter.begin(this); 348 painter.fillRect(pEvent->rect(), palette().brush(QPalette::Window)); 312 349 painter.end(); 313 VBoxToolBar::paintEvent (aEvent); 314 } 315 316 void VBoxMiniToolBar::togglePushpin (bool aOn) 317 { 318 mAutoHide = !aOn; 319 updateDisplay (!mAutoHide, false); 320 } 321 350 /* Base-class paint event processing: */ 351 VBoxToolBar::paintEvent(pEvent); 352 } 353 354 /* Toggle push-pin */ 355 void VBoxMiniToolBar::togglePushpin(bool fOn) 356 { 357 m_fAutoHide = !fOn; 358 updateDisplay(!m_fAutoHide, false); 359 } 360 361 /* Initialize mini-toolbar */ 322 362 void VBoxMiniToolBar::initialize() 323 363 { 324 /* Resize to sizehint */325 resize 326 327 /* Update geometry */364 /* Resize to sizehint: */ 365 resize(sizeHint()); 366 367 /* Update geometry: */ 328 368 recreateMask(); 329 369 moveToBase(); 330 370 } 331 371 372 /* Recreate mini-toolbar mask */ 332 373 void VBoxMiniToolBar::recreateMask() 333 374 { 334 int edgeShift = height();335 int points[8];336 switch (m Alignment)375 int iEdgeShift = height(); 376 int iPoints[8]; 377 switch (m_alignment) 337 378 { 338 379 case AlignTop: 339 380 { 340 points[0] = 0;341 points[1] = 0;342 343 points [2] = edgeShift;344 points[3] = height();345 346 points [4] = width() - edgeShift;347 points[5] = height();348 349 points[6] = width();350 points[7] = 0;381 iPoints[0] = 0; 382 iPoints[1] = 0; 383 384 iPoints[2] = iEdgeShift; 385 iPoints[3] = height(); 386 387 iPoints[4] = width() - iEdgeShift; 388 iPoints[5] = height(); 389 390 iPoints[6] = width(); 391 iPoints[7] = 0; 351 392 352 393 break; … … 354 395 case AlignBottom: 355 396 { 356 points [0] = edgeShift;357 points[1] = 0;358 359 points[2] = 0;360 points[3] = height();361 362 points[4] = width();363 points[5] = height();364 365 points [6] = width() - edgeShift;366 points[7] = 0;397 iPoints[0] = iEdgeShift; 398 iPoints[1] = 0; 399 400 iPoints[2] = 0; 401 iPoints[3] = height(); 402 403 iPoints[4] = width(); 404 iPoints[5] = height(); 405 406 iPoints[6] = width() - iEdgeShift; 407 iPoints[7] = 0; 367 408 368 409 break; … … 371 412 break; 372 413 } 373 /* Make sure any old mask is removed first */414 /* Make sure any old mask is removed first: */ 374 415 clearMask(); 375 416 /* Set the new mask */ 376 417 QPolygon polygon; 377 polygon.setPoints (4, points); 378 setMask (polygon); 379 } 380 418 polygon.setPoints(4, iPoints); 419 setMask(polygon); 420 } 421 422 /* Move mini-toolbar to the base location */ 381 423 void VBoxMiniToolBar::moveToBase() 382 424 { 383 QRect screen = m Seamless ? vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(window())) :384 QApplication::desktop()->screenGeometry(window());385 m PositionX = screen.x() + screen.width() / 2 - width() / 2;386 switch (m Alignment)425 QRect screen = m_fSeamless ? vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(window())) : 426 QApplication::desktop()->screenGeometry(window()); 427 m_iPositionX = screen.x() + (screen.width() / 2) - (width() / 2); 428 switch (m_alignment) 387 429 { 388 430 case AlignTop: 389 431 { 390 m PositionY = screen.y() - height() + 1;432 m_iPositionY = screen.y() - height() + 1; 391 433 break; 392 434 } 393 435 case AlignBottom: 394 436 { 395 m PositionY = screen.y() + screen.height() - 1;437 m_iPositionY = screen.y() + screen.height() - 1; 396 438 break; 397 439 } 398 440 default: 399 441 { 400 mPositionY = 0; 401 break; 402 } 403 } 404 move(mapFromScreen (QPoint (mPositionX, mPositionY))); 405 } 406 407 QPoint VBoxMiniToolBar::mapFromScreen (const QPoint &aPoint) 408 { 409 QPoint globalPosition = parentWidget()->mapFromGlobal (aPoint); 410 QRect fullArea = QApplication::desktop()->screenGeometry (window()); 411 QRect realArea = mSeamless ? vboxGlobal().availableGeometry (QApplication::desktop()->screenNumber(window())) : 412 QApplication::desktop()->screenGeometry (window()); 413 QPoint shiftToReal (realArea.topLeft() - fullArea.topLeft()); 414 return globalPosition + shiftToReal; 415 } 416 417 bool VBoxMiniToolBar::eventFilter(QObject *pObj, QEvent *pEvent) 418 { 419 if (pEvent->type() == QEvent::Resize) 420 { 421 moveToBase(); 422 return true; 423 } 424 return VBoxToolBar::eventFilter(pObj, pEvent); 425 } 426 442 m_iPositionY = 0; 443 break; 444 } 445 } 446 move(parentWidget()->mapFromGlobal(QPoint(m_iPositionX, m_iPositionY))); 447 } 448 449 /* Enable/disable mouse-tracking for required widgets */ 450 void VBoxMiniToolBar::setMouseTrackingEnabled(bool fEnabled) 451 { 452 setMouseTracking(fEnabled); 453 if (m_pDisplayLabel) 454 m_pDisplayLabel->setMouseTracking(fEnabled); 455 if (m_pAutoHideAction && widgetForAction(m_pAutoHideAction)) 456 widgetForAction(m_pAutoHideAction)->setMouseTracking(fEnabled); 457 if (m_pRestoreAction && widgetForAction(m_pRestoreAction)) 458 widgetForAction(m_pRestoreAction)->setMouseTracking(fEnabled); 459 if (m_pCloseAction && widgetForAction(m_pCloseAction)) 460 widgetForAction(m_pCloseAction)->setMouseTracking(fEnabled); 461 } 462 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMiniToolBar.h
r28800 r29083 6 6 7 7 /* 8 * Copyright (C) 2009 Oracle Corporation8 * Copyright (C) 2009-2010 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #define __VBoxMiniToolBar_h__ 21 21 22 /* VBox includes */ 23 #include <VBoxToolBar.h> 24 25 /* Qt includes */ 22 /* Global includes */ 26 23 #include <QBasicTimer> 27 24 25 /* Local includes */ 26 #include "VBoxToolBar.h" 27 28 /* Global forwards */ 28 29 class QLabel; 29 30 class QMenu; … … 45 46 }; 46 47 47 VBoxMiniToolBar (QWidget *aParent, Alignment aAlignment, bool aIsActive, bool aAutoHide);48 VBoxMiniToolBar(QWidget *pParent, Alignment alignment, bool fActive, bool fAutoHide); 48 49 49 VBoxMiniToolBar& operator<< (QList <QMenu*> aMenus);50 VBoxMiniToolBar& operator<<(QList<QMenu*> menus); 50 51 51 void setSeamlessMode (bool aIsSeamless);52 void setDisplayText (const QString &aText);52 void setSeamlessMode(bool fSeamless); 53 void setDisplayText(const QString &strText); 53 54 54 55 bool isAutoHide() const; 55 56 56 void updateDisplay (bool aShow, bool aSetHideFlag);57 void updateDisplay(bool fShow, bool fSetHideFlag); 57 58 58 59 signals: … … 64 65 protected: 65 66 66 void mouseMoveEvent (QMouseEvent *aEvent);67 void timerEvent (QTimerEvent *aEvent);68 void showEvent (QShowEvent *aEvent);69 void paintEvent (QPaintEvent *aEvent);70 67 bool eventFilter(QObject *pObj, QEvent *pEvent); 68 void mouseMoveEvent(QMouseEvent *pEvent); 69 void timerEvent(QTimerEvent *pEvent); 70 void showEvent(QShowEvent *pEvent); 71 void paintEvent(QPaintEvent *pEvent); 71 72 72 73 private slots: 73 74 74 void togglePushpin (bool aOn);75 void togglePushpin(bool fOn); 75 76 76 77 private: … … 79 80 void recreateMask(); 80 81 void moveToBase(); 81 QPoint mapFromScreen (const QPoint &aPoint);82 void setMouseTrackingEnabled(bool fEnabled); 82 83 83 QAction *mAutoHideAct; 84 QLabel *mDisplayLabel; 84 QAction *m_pAutoHideAction; 85 QLabel *m_pDisplayLabel; 86 QAction *m_pRestoreAction; 87 QAction *m_pCloseAction; 85 88 86 QBasicTimer m ScrollTimer;87 QBasicTimer m AutoScrollTimer;89 QBasicTimer m_scrollTimer; 90 QBasicTimer m_autoScrollTimer; 88 91 89 bool m Active;90 bool m Polished;91 bool m Seamless;92 bool m AutoHide;93 bool m SlideToScreen;94 bool m HideAfterSlide;92 bool m_fActive; 93 bool m_fPolished; 94 bool m_fSeamless; 95 bool m_fAutoHide; 96 bool m_fSlideToScreen; 97 bool m_fHideAfterSlide; 95 98 96 int m AutoHideCounter;97 int m PositionX;98 int m PositionY;99 int m_iAutoHideCounter; 100 int m_iPositionX; 101 int m_iPositionY; 99 102 100 103 /* Lists of used spacers */ 101 QList <QWidget*> mMargins;102 QList <QWidget*> mSpacings;103 QList <QWidget*> mLabelMargins;104 QList<QWidget*> m_Margins; 105 QList<QWidget*> m_Spacings; 106 QList<QWidget*> m_LabelMargins; 104 107 105 108 /* Menu insert position */ 106 QAction *m InsertPosition;109 QAction *m_pInsertPosition; 107 110 108 111 /* Tool-bar alignment */ 109 Alignment m Alignment;112 Alignment m_alignment; 110 113 111 114 /* Wether to animate showing/hiding the toolbar */ 112 bool m Animated;115 bool m_fAnimated; 113 116 114 117 /* Interval (in milli seconds) for scrolling the toolbar, default is 20 msec */ 115 int m ScrollDelay;118 int m_iScrollDelay; 116 119 117 120 /* The wait time while the cursor is not over the window after this amount of time (in msec), 118 121 * the toolbar will auto hide if autohide is on. The default is 100msec. */ 119 int m AutoScrollDelay;122 int m_iAutoScrollDelay; 120 123 121 /* Number of total steps before hiding. If it is 10 then wait 10 (steps) * 100ms (m AutoScrollDelay) = 1000ms delay.124 /* Number of total steps before hiding. If it is 10 then wait 10 (steps) * 100ms (m_iAutoScrollDelay) = 1000ms delay. 122 125 * The default is 10. */ 123 int m AutoHideTotalCounter;126 int m_iAutoHideTotalCounter; 124 127 }; 125 128
Note:
See TracChangeset
for help on using the changeset viewer.