- Timestamp:
- May 23, 2013 4:43:46 PM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp
r45736 r46244 402 402 /* Add machine-view into main-layout: */ 403 403 m_pMainLayout->addWidget(m_pMachineView, 1, 1, viewAlignment(visualStateType)); 404 405 /* Install focus-proxy: */ 406 setFocusProxy(m_pMachineView); 404 407 } 405 408 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.cpp
r46224 r46244 103 103 /* Get the mini-toolbar auto-hide feature availability: */ 104 104 bool fIsAutoHide = m.GetExtraData(GUI_MiniToolBarAutoHide) != "off"; 105 m_pMiniToolBar = new UIMiniToolBar(centralWidget(), 106 fIsAtTop ? UIMiniToolBar::AlignTop : UIMiniToolBar::AlignBottom, 107 true, fIsAutoHide); 108 m_pMiniToolBar->updateDisplay(true, true); 105 /* Create mini-toolbar: */ 106 m_pMiniToolBar = new UIRuntimeMiniToolBar(this, 107 fIsAtTop ? Qt::AlignTop : Qt::AlignBottom, 108 IntegrationMode_Embedded, 109 fIsAutoHide); 109 110 QList<QMenu*> menus; 110 111 QList<QAction*> actions = uisession()->newMenu()->actions(); 111 112 for (int i=0; i < actions.size(); ++i) 112 113 menus << actions.at(i)->menu(); 113 *m_pMiniToolBar << menus;114 connect(m_pMiniToolBar, SIGNAL( minimizeAction()), this, SLOT(showMinimized()));115 connect(m_pMiniToolBar, SIGNAL( exitAction()),114 m_pMiniToolBar->addMenus(menus); 115 connect(m_pMiniToolBar, SIGNAL(sigMinimizeAction()), this, SLOT(showMinimized())); 116 connect(m_pMiniToolBar, SIGNAL(sigExitAction()), 116 117 gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SLOT(trigger())); 117 connect(m_pMiniToolBar, SIGNAL( closeAction()),118 connect(m_pMiniToolBar, SIGNAL(sigCloseAction()), 118 119 gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger())); 119 120 } … … 126 127 127 128 /* Save mini-toolbar settings: */ 128 machine().SetExtraData(GUI_MiniToolBarAutoHide, m_pMiniToolBar-> isAutoHide() ? QString() : "off");129 machine().SetExtraData(GUI_MiniToolBarAutoHide, m_pMiniToolBar->autoHide() ? QString() : "off"); 129 130 /* Delete mini-toolbar: */ 130 131 delete m_pMiniToolBar; … … 161 162 /* Resize to the appropriate size: */ 162 163 resize(workingArea.size()); 164 /* Move mini-toolbar into appropriate place: */ 165 if (m_pMiniToolBar) 166 m_pMiniToolBar->adjustGeometry(); 163 167 /* Process pending move & resize events: */ 164 168 qApp->processEvents(); … … 232 236 } 233 237 /* Update mini-toolbar text: */ 234 m_pMiniToolBar->set DisplayText(m.GetName() + strSnapshotName);238 m_pMiniToolBar->setText(m.GetName() + strSnapshotName); 235 239 } 236 240 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.h
r46224 r46244 24 24 25 25 /* Forward declarations: */ 26 class UI MiniToolBar;26 class UIRuntimeMiniToolBar; 27 27 28 28 /* Fullscreen machine-window implementation: */ … … 68 68 /* Widgets: */ 69 69 QMenu *m_pMainMenu; 70 UI MiniToolBar *m_pMiniToolBar;70 UIRuntimeMiniToolBar *m_pMiniToolBar; 71 71 72 72 /* Factory support: */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineWindowSeamless.cpp
r46225 r46244 73 73 } 74 74 75 #ifndef Q_WS_MAC76 void UIMachineWindowSeamless::sltUpdateMiniToolBarMask()77 {78 if (m_pMiniToolBar && machineView())79 setMask(qobject_cast<UIMachineViewSeamless*>(machineView())->lastVisibleRegion());80 }81 #endif /* !Q_WS_MAC */82 83 75 void UIMachineWindowSeamless::prepareMenu() 84 76 { … … 127 119 /* Get the mini-toolbar auto-hide feature availability: */ 128 120 bool fIsAutoHide = m.GetExtraData(GUI_MiniToolBarAutoHide) != "off"; 129 m_pMiniToolBar = new UIMiniToolBar(centralWidget(), 130 fIsAtTop ? UIMiniToolBar::AlignTop : UIMiniToolBar::AlignBottom, 131 true, fIsAutoHide); 132 m_pMiniToolBar->setSeamlessMode(true); 133 m_pMiniToolBar->updateDisplay(true, true); 121 /* Create mini-toolbar: */ 122 m_pMiniToolBar = new UIRuntimeMiniToolBar(this, 123 fIsAtTop ? Qt::AlignTop : Qt::AlignBottom, 124 IntegrationMode_External, 125 fIsAutoHide); 126 m_pMiniToolBar->show(); 134 127 QList<QMenu*> menus; 135 128 QList<QAction*> actions = uisession()->newMenu()->actions(); 136 129 for (int i=0; i < actions.size(); ++i) 137 130 menus << actions.at(i)->menu(); 138 *m_pMiniToolBar << menus;139 connect(m_pMiniToolBar, SIGNAL( minimizeAction()), this, SLOT(showMinimized()));140 connect(m_pMiniToolBar, SIGNAL( exitAction()),131 m_pMiniToolBar->addMenus(menus); 132 connect(m_pMiniToolBar, SIGNAL(sigMinimizeAction()), this, SLOT(showMinimized())); 133 connect(m_pMiniToolBar, SIGNAL(sigExitAction()), 141 134 gActionPool->action(UIActionIndexRuntime_Toggle_Seamless), SLOT(trigger())); 142 connect(m_pMiniToolBar, SIGNAL( closeAction()),135 connect(m_pMiniToolBar, SIGNAL(sigCloseAction()), 143 136 gActionPool->action(UIActionIndexRuntime_Simple_Close), SLOT(trigger())); 144 connect(m_pMiniToolBar, SIGNAL(geometryUpdated()), this, SLOT(sltUpdateMiniToolBarMask()));145 137 } 146 138 #endif /* !Q_WS_MAC */ … … 154 146 155 147 /* Save mini-toolbar settings: */ 156 machine().SetExtraData(GUI_MiniToolBarAutoHide, m_pMiniToolBar-> isAutoHide() ? QString() : "off");148 machine().SetExtraData(GUI_MiniToolBarAutoHide, m_pMiniToolBar->autoHide() ? QString() : "off"); 157 149 /* Delete mini-toolbar: */ 158 150 delete m_pMiniToolBar; … … 192 184 /* Resize to the appropriate size: */ 193 185 resize(workingArea.size()); 186 #ifndef Q_WS_MAC 187 /* Move mini-toolbar into appropriate place: */ 188 if (m_pMiniToolBar) 189 m_pMiniToolBar->adjustGeometry(); 190 #endif /* !Q_WS_MAC */ 194 191 /* Process pending move & resize events: */ 195 192 qApp->processEvents(); … … 249 246 } 250 247 /* Update mini-toolbar text: */ 251 m_pMiniToolBar->set DisplayText(m.GetName() + strSnapshotName);248 m_pMiniToolBar->setText(m.GetName() + strSnapshotName); 252 249 } 253 250 } … … 282 279 if (m_pLeftSpacer->geometry().width() || m_pTopSpacer->geometry().height()) 283 280 region.translate(m_pLeftSpacer->geometry().width(), m_pTopSpacer->geometry().height()); 284 285 /* Take into account mini tool-bar region: */286 if (m_pMiniToolBar)287 {288 /* Move mini-toolbar region to mini-toolbar position: */289 QRegion toolBarRegion(m_pMiniToolBar->rect());290 toolBarRegion.translate(QPoint(m_pMiniToolBar->x(), m_pMiniToolBar->y()));291 /* Include mini-toolbar region into common one: */292 region += toolBarRegion;293 }294 281 #endif /* !Q_WS_MAC */ 295 282 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineWindowSeamless.h
r46225 r46244 24 24 25 25 /* Forward declarations: */ 26 class UI MiniToolBar;26 class UIRuntimeMiniToolBar; 27 27 28 28 /* Seamless machine-window implementation: */ … … 48 48 /* Popup main menu: */ 49 49 void sltPopupMainMenu(); 50 51 #ifndef RT_OS_DARWIN52 /* Current Qt on MAC has something broken in moc generation,53 * so we have to use RT_OS_DARWIN instead of Q_WS_MAC here. */54 /* Update mini tool-bar mask: */55 void sltUpdateMiniToolBarMask();56 #endif /* !RT_OS_DARWIN */57 50 58 51 private: … … 92 85 QMenu *m_pMainMenu; 93 86 #ifndef Q_WS_MAC 94 UI MiniToolBar *m_pMiniToolBar;87 UIRuntimeMiniToolBar *m_pMiniToolBar; 95 88 #endif /* !Q_WS_MAC */ 96 89 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMiniToolBar.cpp
r46224 r46244 3 3 * 4 4 * VBox frontends: Qt GUI ("VirtualBox"): 5 * UIMiniToolBar class declaration & implementation. This is the toolbar shown on fullscreen mode. 5 * UIMiniToolBar class implementation. 6 * This is the toolbar shown in fullscreen/seamless modes. 6 7 */ 7 8 8 9 /* 9 * Copyright (C) 2009-201 1Oracle Corporation10 * Copyright (C) 2009-2013 Oracle Corporation 10 11 * 11 12 * This file is part of VirtualBox Open Source Edition (OSE), as … … 18 19 */ 19 20 20 /* Local includes */ 21 #include "UIIconPool.h" 22 #include "VBoxGlobal.h" 23 #include "UIMiniToolBar.h" 24 25 /* Global includes */ 26 #include <QCursor> 21 /* Qt includes: */ 22 #include <QApplication> 23 #include <QTimer> 24 #include <QMdiArea> 25 #include <QMdiSubWindow> 27 26 #include <QDesktopWidget> 28 27 #include <QLabel> 29 28 #include <QMenu> 30 #include <QPaintEvent> 29 #include <QToolButton> 30 #include <QStateMachine> 31 31 #include <QPainter> 32 #include <QPolygon> 33 #include <QRect> 34 #include <QRegion> 35 #include <QTimer> 36 #include <QToolButton> 37 38 /* Mini-toolbar constructor */ 39 UIMiniToolBar::UIMiniToolBar(QWidget *pParent, Alignment alignment, bool fActive, bool fAutoHide) 40 : UIToolBar(pParent) 32 33 /* GUI includes: */ 34 #include "UIMiniToolBar.h" 35 #include "UIAnimationFramework.h" 36 #include "UIIconPool.h" 37 #include "VBoxGlobal.h" 38 39 #ifndef Q_WS_X11 40 # define VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR 41 #endif /* !Q_WS_X11 */ 42 43 UIRuntimeMiniToolBar::UIRuntimeMiniToolBar(QWidget *pParent, 44 Qt::Alignment alignment, 45 IntegrationMode integrationMode, 46 bool fAutoHide /*= true*/) 47 : QWidget(pParent) 48 /* Variables: General stuff: */ 49 , m_alignment(alignment) 50 , m_integrationMode(integrationMode) 51 , m_fAutoHide(fAutoHide) 52 /* Variables: Contents stuff: */ 53 , m_pMdiArea(0) 54 , m_pToolbar(0) 55 , m_pEmbeddedToolbar(0) 56 /* Variables: Hover stuff: */ 57 , m_fHovered(false) 58 , m_pHoverEnterTimer(0) 59 , m_pHoverLeaveTimer(0) 60 , m_pAnimation(0) 61 { 62 /* Prepare: */ 63 prepare(); 64 } 65 66 UIRuntimeMiniToolBar::~UIRuntimeMiniToolBar() 67 { 68 /* Cleanup: */ 69 cleanup(); 70 } 71 72 void UIRuntimeMiniToolBar::setAlignment(Qt::Alignment alignment) 73 { 74 /* Make sure alignment really changed: */ 75 if (m_alignment == alignment) 76 return; 77 78 /* Update alignment: */ 79 m_alignment = alignment; 80 81 /* Re-initialize: */ 82 adjustGeometry(); 83 84 /* Propagate to child to update shape: */ 85 m_pToolbar->setAlignment(m_alignment); 86 } 87 88 void UIRuntimeMiniToolBar::setIntegrationMode(IntegrationMode integrationMode) 89 { 90 /* Make sure integration-mode really changed: */ 91 if (m_integrationMode == integrationMode) 92 return; 93 94 /* Update integration-mode: */ 95 m_integrationMode = integrationMode; 96 97 /* Re-integrate: */ 98 integrate(); 99 100 /* Re-initialize: */ 101 adjustGeometry(); 102 103 /* Propagate to child to update shape: */ 104 m_pToolbar->setIntegrationMode(m_integrationMode); 105 } 106 107 void UIRuntimeMiniToolBar::setAutoHide(bool fAutoHide, bool fPropagateToChild /*= true*/) 108 { 109 /* Make sure auto-hide really changed: */ 110 if (m_fAutoHide == fAutoHide) 111 return; 112 113 /* Update auto-hide: */ 114 m_fAutoHide = fAutoHide; 115 116 /* Re-initialize: */ 117 adjustGeometry(); 118 119 /* Propagate to child to update action if necessary: */ 120 if (fPropagateToChild) 121 m_pToolbar->setAutoHide(m_fAutoHide); 122 } 123 124 void UIRuntimeMiniToolBar::setText(const QString &strText) 125 { 126 /* Propagate to child: */ 127 m_pToolbar->setText(strText); 128 } 129 130 void UIRuntimeMiniToolBar::addMenus(const QList<QMenu*> &menus) 131 { 132 /* Propagate to child: */ 133 m_pToolbar->addMenus(menus); 134 } 135 136 void UIRuntimeMiniToolBar::adjustGeometry() 137 { 138 /* This method could be called before parent-widget 139 * become visible, we should skip everything in that case: */ 140 if (QApplication::desktop()->screenNumber(parentWidget()) == -1) 141 return; 142 143 /* Reset toolbar geometry: */ 144 m_pEmbeddedToolbar->move(0, 0); 145 m_pEmbeddedToolbar->resize(m_pEmbeddedToolbar->sizeHint()); 146 147 /* Adjust window geometry: */ 148 resize(m_pEmbeddedToolbar->size()); 149 QRect screenRect; 150 int iX = 0, iY = 0; 151 switch (m_integrationMode) 152 { 153 case IntegrationMode_Embedded: 154 { 155 /* Screen geometry: */ 156 screenRect = QApplication::desktop()->screenGeometry(parentWidget()); 157 /* Local coordinates, tool-bar is a child of the parent-widget: */ 158 iX = screenRect.width() / 2 - width() / 2; 159 switch (m_alignment) 160 { 161 case Qt::AlignTop: 162 iY = 0; 163 break; 164 case Qt::AlignBottom: 165 iY = screenRect.height() - height(); 166 break; 167 } 168 break; 169 } 170 case IntegrationMode_External: 171 { 172 /* Available geometry: */ 173 screenRect = vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(parentWidget())); 174 /* Global coordinates, tool-bar is tool-window aligned according the parent-widget: */ 175 iX = screenRect.x() + screenRect.width() / 2 - width() / 2; 176 switch (m_alignment) 177 { 178 case Qt::AlignTop: 179 iY = screenRect.y(); 180 break; 181 case Qt::AlignBottom: 182 iY = screenRect.y() + screenRect.height() - height(); 183 break; 184 } 185 break; 186 } 187 } 188 move(iX, iY); 189 190 /* Recalculate auto-hide animation: */ 191 updateAutoHideAnimationBounds(); 192 193 /* Simulate toolbar auto-hiding: */ 194 simulateToolbarAutoHiding(); 195 196 /* Due to [probably] Qt bug QMdiSubWindow still 197 * can receive focus even if focus policy is Qt::NoFocus, 198 * We should return the focus to our parent: */ 199 parentWidget()->setFocus(); 200 } 201 202 void UIRuntimeMiniToolBar::sltHandleToolbarResize() 203 { 204 /* Re-initialize: */ 205 adjustGeometry(); 206 } 207 208 void UIRuntimeMiniToolBar::sltAutoHideToggled() 209 { 210 /* Propagate from child: */ 211 setAutoHide(m_pToolbar->autoHide(), false); 212 } 213 214 void UIRuntimeMiniToolBar::sltHoverEnter() 215 { 216 /* Mark as 'hovered' if necessary: */ 217 if (!m_fHovered) 218 { 219 m_fHovered = true; 220 emit sigHoverEnter(); 221 } 222 } 223 224 void UIRuntimeMiniToolBar::sltHoverLeave() 225 { 226 /* Mark as 'unhovered' if necessary: */ 227 if (m_fHovered) 228 { 229 m_fHovered = false; 230 emit sigHoverLeave(); 231 } 232 } 233 234 void UIRuntimeMiniToolBar::prepare() 235 { 236 /* Allow any size: */ 237 setMinimumSize(1, 1); 238 /* Make sure we have no focus: */ 239 setFocusPolicy(Qt::NoFocus); 240 241 /* Prepare mdi-area: */ 242 m_pMdiArea = new QMdiArea; 243 { 244 /* Configure own background: */ 245 QPalette pal = m_pMdiArea->palette(); 246 pal.setColor(QPalette::Window, QColor(Qt::transparent)); 247 m_pMdiArea->setPalette(pal); 248 /* Configure viewport background: */ 249 m_pMdiArea->setBackground(QColor(Qt::transparent)); 250 /* Layout mdi-area according parent-widget: */ 251 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 252 pMainLayout->setContentsMargins(0, 0, 0, 0); 253 pMainLayout->addWidget(m_pMdiArea); 254 /* Make sure we have no focus: */ 255 m_pMdiArea->setFocusPolicy(Qt::NoFocus); 256 m_pMdiArea->viewport()->setFocusPolicy(Qt::NoFocus); 257 } 258 259 /* Prepare mini-toolbar: */ 260 m_pToolbar = new UIMiniToolBar; 261 { 262 /* Propagate known options to child: */ 263 m_pToolbar->setAutoHide(m_fAutoHide); 264 m_pToolbar->setAlignment(m_alignment); 265 m_pToolbar->setIntegrationMode(m_integrationMode); 266 /* Configure own background: */ 267 QPalette pal = m_pToolbar->palette(); 268 pal.setColor(QPalette::Window, palette().color(QPalette::Window)); 269 m_pToolbar->setPalette(pal); 270 /* Configure child connections: */ 271 connect(m_pToolbar, SIGNAL(sigResized()), this, SLOT(sltHandleToolbarResize())); 272 connect(m_pToolbar, SIGNAL(sigAutoHideToggled()), this, SLOT(sltAutoHideToggled())); 273 connect(m_pToolbar, SIGNAL(sigMinimizeAction()), this, SIGNAL(sigMinimizeAction())); 274 connect(m_pToolbar, SIGNAL(sigExitAction()), this, SIGNAL(sigExitAction())); 275 connect(m_pToolbar, SIGNAL(sigCloseAction()), this, SIGNAL(sigCloseAction())); 276 /* Add child to mdi-area: */ 277 m_pEmbeddedToolbar = m_pMdiArea->addSubWindow(m_pToolbar, Qt::Window | Qt::FramelessWindowHint); 278 /* Make sure we have no focus: */ 279 m_pToolbar->setFocusPolicy(Qt::NoFocus); 280 m_pEmbeddedToolbar->setFocusPolicy(Qt::NoFocus); 281 } 282 283 /* Prepare hover-enter/leave timers: */ 284 m_pHoverEnterTimer = new QTimer(this); 285 { 286 m_pHoverEnterTimer->setSingleShot(true); 287 m_pHoverEnterTimer->setInterval(50); 288 connect(m_pHoverEnterTimer, SIGNAL(timeout()), this, SLOT(sltHoverEnter())); 289 } 290 m_pHoverLeaveTimer = new QTimer(this); 291 { 292 m_pHoverLeaveTimer->setSingleShot(true); 293 m_pHoverLeaveTimer->setInterval(500); 294 connect(m_pHoverLeaveTimer, SIGNAL(timeout()), this, SLOT(sltHoverLeave())); 295 } 296 297 /* Install 'auto-hide' animation to 'toolbarPosition' property: */ 298 m_pAnimation = UIAnimation::installPropertyAnimation(this, 299 "toolbarPosition", 300 "hiddenToolbarPosition", "shownToolbarPosition", 301 SIGNAL(sigHoverEnter()), SIGNAL(sigHoverLeave()), 302 true); 303 304 /* Integrate if necessary: */ 305 integrate(); 306 307 /* Adjust geometry finally: */ 308 adjustGeometry(); 309 } 310 311 void UIRuntimeMiniToolBar::cleanup() 312 { 313 /* Stop hover-enter/leave timers: */ 314 if (m_pHoverEnterTimer->isActive()) 315 m_pHoverEnterTimer->stop(); 316 if (m_pHoverLeaveTimer->isActive()) 317 m_pHoverLeaveTimer->stop(); 318 } 319 320 void UIRuntimeMiniToolBar::enterEvent(QEvent*) 321 { 322 /* Stop the hover-leave timer if necessary: */ 323 if (m_pHoverLeaveTimer->isActive()) 324 m_pHoverLeaveTimer->stop(); 325 326 /* Start the hover-enter timer: */ 327 if (m_fAutoHide) 328 m_pHoverEnterTimer->start(); 329 } 330 331 void UIRuntimeMiniToolBar::leaveEvent(QEvent*) 332 { 333 /* Stop the hover-enter timer if necessary: */ 334 if (m_pHoverEnterTimer->isActive()) 335 m_pHoverEnterTimer->stop(); 336 337 /* Start the hover-leave timer: */ 338 if (m_fAutoHide) 339 m_pHoverLeaveTimer->start(); 340 } 341 342 void UIRuntimeMiniToolBar::updateAutoHideAnimationBounds() 343 { 344 /* Update animation: */ 345 m_shownToolbarPosition = m_pEmbeddedToolbar->pos(); 346 switch (m_alignment) 347 { 348 case Qt::AlignTop: 349 m_hiddenToolbarPosition = m_shownToolbarPosition - QPoint(0, m_pEmbeddedToolbar->height() + 3); 350 break; 351 case Qt::AlignBottom: 352 m_hiddenToolbarPosition = m_shownToolbarPosition + QPoint(0, m_pEmbeddedToolbar->height() - 3); 353 break; 354 } 355 m_pAnimation->update(); 356 } 357 358 void UIRuntimeMiniToolBar::simulateToolbarAutoHiding() 359 { 360 /* This simulation helps user to notice 361 * toolbar location, so it will be used only 362 * 1. if toolbar unhovered and 363 * 2. auto-hide feature enabled: */ 364 if (m_fHovered || !m_fAutoHide) 365 return; 366 367 /* Simulate hover-leave event: */ 368 m_fHovered = true; 369 m_pHoverLeaveTimer->start(); 370 } 371 372 void UIRuntimeMiniToolBar::setToolbarPosition(QPoint point) 373 { 374 /* Make sure toolbar exists: */ 375 if (!m_pEmbeddedToolbar) 376 return; 377 378 /* Update position: */ 379 m_pEmbeddedToolbar->move(point); 380 381 #ifdef Q_WS_X11 382 /* The setMask functionality is excessive under Win/Mac hosts 383 * because there is a Qt composition works properly, 384 * Mac host has native translucency support, 385 * Win host allows to enable it through Qt::WA_TranslucentBackground: */ 386 setMask(m_pEmbeddedToolbar->geometry()); 387 #endif /* Q_WS_X11 */ 388 } 389 390 QPoint UIRuntimeMiniToolBar::toolbarPosition() const 391 { 392 /* Make sure toolbar exists: */ 393 if (!m_pEmbeddedToolbar) 394 return QPoint(); 395 396 /* Return position: */ 397 return m_pEmbeddedToolbar->pos(); 398 } 399 400 void UIRuntimeMiniToolBar::integrate() 401 { 402 /* Reintegrate if necessary: */ 403 if (m_integrationMode == IntegrationMode_Embedded && isWindow()) 404 { 405 setWindowFlags(Qt::Widget); 406 #ifdef VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR 407 setAttribute(Qt::WA_TranslucentBackground, false); 408 #endif /* VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR */ 409 show(); 410 } 411 else if (m_integrationMode == IntegrationMode_External && !isWindow()) 412 { 413 setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); 414 #ifdef VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR 415 setAttribute(Qt::WA_TranslucentBackground, true); 416 #endif /* VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR */ 417 show(); 418 } 419 } 420 421 422 UIMiniToolBar::UIMiniToolBar() 423 /* Variables: General stuff: */ 424 : m_fPolished(false) 425 , m_alignment(Qt::AlignBottom) 426 /* Variables: Contents stuff: */ 41 427 , m_pAutoHideAction(0) 42 , m_p DisplayLabel(0)428 , m_pLabel(0) 43 429 , m_pMinimizeAction(0) 44 430 , m_pRestoreAction(0) 45 431 , m_pCloseAction(0) 46 , m_fActive(fActive) 47 , m_fPolished(false) 48 , m_fSeamless(false) 49 , m_fAutoHide(fAutoHide) 50 , m_fSlideToScreen(true) 51 , m_fHideAfterSlide(false) 52 , m_iAutoHideCounter(0) 53 , m_iPositionX(0) 54 , m_iPositionY(0) 55 , m_pInsertPosition(0) 56 , m_alignment(alignment) 57 , m_fAnimated(true) 58 , m_iScrollDelay(10) 59 , m_iAutoScrollDelay(100) 60 , m_iAutoHideTotalCounter(10) 61 { 62 /* Check parent widget presence: */ 63 AssertMsg(parentWidget(), ("Parent widget must be set!\n")); 64 65 /* Toolbar options: */ 66 setIconSize(QSize(16, 16)); 67 setVisible(false); 68 69 /* Add pushpin: */ 70 m_pAutoHideAction = new QAction(this); 71 m_pAutoHideAction->setIcon(UIIconPool::iconSet(":/pin_16px.png")); 72 m_pAutoHideAction->setToolTip(tr("Always show the toolbar")); 73 m_pAutoHideAction->setCheckable(true); 74 m_pAutoHideAction->setChecked(!m_fAutoHide); 75 connect(m_pAutoHideAction, SIGNAL(toggled(bool)), this, SLOT(togglePushpin(bool))); 76 addAction(m_pAutoHideAction); 77 78 /* Left menu margin: */ 79 m_Spacings << widgetForAction(addWidget(new QWidget(this))); 80 81 /* Right menu margin: */ 82 m_pInsertPosition = addWidget(new QWidget(this)); 83 m_Spacings << widgetForAction(m_pInsertPosition); 84 85 /* Left label margin: */ 86 m_LabelMargins << widgetForAction(addWidget(new QWidget(this))); 87 88 /* Insert a label for VM Name: */ 89 m_pDisplayLabel = new QLabel(this); 90 m_pDisplayLabel->setAlignment(Qt::AlignCenter); 91 addWidget(m_pDisplayLabel); 92 93 /* Right label margin: */ 94 m_LabelMargins << widgetForAction(addWidget(new QWidget(this))); 95 96 /* Minimize action: */ 97 m_pMinimizeAction = new QAction(this); 98 m_pMinimizeAction->setIcon(UIIconPool::iconSet(":/minimize_16px.png")); 99 m_pMinimizeAction->setToolTip(tr("Minimize Window")); 100 connect(m_pMinimizeAction, SIGNAL(triggered()), this, SIGNAL(minimizeAction())); 101 addAction(m_pMinimizeAction); 102 103 /* Exit action: */ 104 m_pRestoreAction = new QAction(this); 105 m_pRestoreAction->setIcon(UIIconPool::iconSet(":/restore_16px.png")); 106 m_pRestoreAction->setToolTip(tr("Exit Full Screen or Seamless Mode")); 107 connect(m_pRestoreAction, SIGNAL(triggered()), this, SIGNAL(exitAction())); 108 addAction(m_pRestoreAction); 109 110 /* Close action: */ 111 m_pCloseAction = new QAction(this); 112 m_pCloseAction->setIcon(UIIconPool::iconSet(":/close_16px.png")); 113 m_pCloseAction->setToolTip(tr("Close VM")); 114 connect(m_pCloseAction, SIGNAL(triggered()), this, SIGNAL(closeAction())); 115 addAction(m_pCloseAction); 116 117 /* Event-filter for parent widget to control resize: */ 118 pParent->installEventFilter(this); 119 120 /* Enable mouse-tracking for this & children allowing to get mouse-move events: */ 121 setMouseTrackingEnabled(m_fAutoHide); 122 } 123 124 /* Appends passed menus into internal menu-list */ 125 UIMiniToolBar& UIMiniToolBar::operator<<(QList<QMenu*> menus) 126 { 432 /* Variables: Menu stuff: */ 433 , m_pMenuInsertPosition(0) 434 { 435 /* Prepare: */ 436 prepare(); 437 } 438 439 void UIMiniToolBar::setAlignment(Qt::Alignment alignment) 440 { 441 /* Make sure alignment really changed: */ 442 if (m_alignment == alignment) 443 return; 444 445 /* Update alignment: */ 446 m_alignment = alignment; 447 448 /* Rebuild shape: */ 449 rebuildShape(); 450 } 451 452 void UIMiniToolBar::setIntegrationMode(IntegrationMode integrationMode) 453 { 454 /* Make sure integration-mode really changed: */ 455 if (m_integrationMode == integrationMode) 456 return; 457 458 /* Update integration-mode: */ 459 m_integrationMode = integrationMode; 460 461 /* Rebuild shape: */ 462 rebuildShape(); 463 } 464 465 bool UIMiniToolBar::autoHide() const 466 { 467 /* Return auto-hide: */ 468 return !m_pAutoHideAction->isChecked(); 469 } 470 471 void UIMiniToolBar::setAutoHide(bool fAutoHide) 472 { 473 /* Make sure auto-hide really changed: */ 474 if (m_pAutoHideAction->isChecked() == !fAutoHide) 475 return; 476 477 /* Update auto-hide: */ 478 m_pAutoHideAction->setChecked(!fAutoHide); 479 } 480 481 void UIMiniToolBar::setText(const QString &strText) 482 { 483 /* Make sure text really changed: */ 484 if (m_pLabel->text() == strText) 485 return; 486 487 /* Update text: */ 488 m_pLabel->setText(strText); 489 490 /* Resize to sizehint: */ 491 resize(sizeHint()); 492 } 493 494 void UIMiniToolBar::addMenus(const QList<QMenu*> &menus) 495 { 496 /* For each of the passed menu items: */ 127 497 for (int i = 0; i < menus.size(); ++i) 128 498 { 499 /* Get corresponding menu-action: */ 129 500 QAction *pAction = menus[i]->menuAction(); 130 insertAction(m_pInsertPosition, pAction); 501 /* Insert it into corresponding place: */ 502 insertAction(m_pMenuInsertPosition, pAction); 503 /* Configure corresponding tool-button: */ 131 504 if (QToolButton *pButton = qobject_cast<QToolButton*>(widgetForAction(pAction))) 132 505 { … … 134 507 pButton->setAutoRaise(true); 135 508 } 509 /* Add some spacing: */ 136 510 if (i != menus.size() - 1) 137 m_Spacings << widgetForAction(insertWidget(m_pInsertPosition, new QWidget(this))); 138 } 139 return *this; 140 } 141 142 /* Seamless mode setter */ 143 void UIMiniToolBar::setSeamlessMode(bool fSeamless) 144 { 145 m_fSeamless = fSeamless; 146 } 147 148 /* Update the display text, usually the VM Name */ 149 void UIMiniToolBar::setDisplayText(const QString &strText) 150 { 151 /* If text was really changed: */ 152 if (m_pDisplayLabel->text() != strText) 153 { 154 /* Update toolbar label: */ 155 m_pDisplayLabel->setText(strText); 156 157 /* Reinitialize: */ 158 initialize(); 159 160 /* Update toolbar if its not hidden: */ 161 if (!isHidden()) 162 updateDisplay(!m_fAutoHide, false); 163 } 164 } 165 166 /* Is auto-hide feature enabled? */ 167 bool UIMiniToolBar::isAutoHide() const 168 { 169 return m_fAutoHide; 170 } 171 172 void UIMiniToolBar::updateDisplay(bool fShow, bool fSetHideFlag) 173 { 174 m_iAutoHideCounter = 0; 175 176 setMouseTrackingEnabled(m_fAutoHide); 177 178 if (fShow) 179 { 180 if (isHidden()) 181 moveToBase(); 182 183 if (m_fAnimated) 184 { 185 if (fSetHideFlag) 186 { 187 m_fHideAfterSlide = false; 188 m_fSlideToScreen = true; 189 } 190 if (m_fActive) 191 show(); 192 m_scrollTimer.start(m_iScrollDelay, this); 193 } 194 else if (m_fActive) 195 show(); 196 197 if (m_fAutoHide) 198 m_autoScrollTimer.start(m_iAutoScrollDelay, this); 199 else 200 m_autoScrollTimer.stop(); 201 } 202 else 203 { 204 if (m_fAnimated) 205 { 206 if (fSetHideFlag) 207 { 208 m_fHideAfterSlide = true; 209 m_fSlideToScreen = false; 210 } 211 m_scrollTimer.start(m_iScrollDelay, this); 212 } 213 else 214 hide(); 215 216 if (m_fAutoHide) 217 m_autoScrollTimer.start(m_iAutoScrollDelay, this); 218 else 219 m_autoScrollTimer.stop(); 220 } 221 } 222 223 /* Parent widget event-filter */ 224 bool UIMiniToolBar::eventFilter(QObject *pObject, QEvent *pEvent) 225 { 226 /* If parent widget was resized: */ 227 if (pObject == parent() && pEvent->type() == QEvent::Resize) 228 { 229 /* Update toolbar position: */ 230 moveToBase(); 231 return true; 232 } 233 /* Base-class event-filter: */ 234 return UIToolBar::eventFilter(pObject, pEvent); 235 } 236 237 /* Mouse-move event processor */ 238 void UIMiniToolBar::mouseMoveEvent(QMouseEvent *pEvent) 239 { 240 /* Activate sliding animation on mouse move: */ 241 if (!m_fHideAfterSlide) 242 { 243 m_fSlideToScreen = true; 244 m_scrollTimer.start(m_iScrollDelay, this); 245 } 246 /* Base-class mouse-move event processing: */ 247 UIToolBar::mouseMoveEvent(pEvent); 248 } 249 250 /* Timer event processor 251 * Handles auto hide feature of the toolbar */ 252 void UIMiniToolBar::timerEvent(QTimerEvent *pEvent) 253 { 254 if (pEvent->timerId() == m_scrollTimer.timerId()) 255 { 256 /* Due to X11 async nature, this timer-event could come before parent 257 * VM window become visible, we should ignore those timer-events: */ 258 if (QApplication::desktop()->screenNumber(window()) == -1) 259 return; 260 261 /* Update tool-bar position: */ 262 QRect screen = m_fSeamless ? vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(window())) : 263 QApplication::desktop()->screenGeometry(window()); 264 switch (m_alignment) 265 { 266 case AlignTop: 267 { 268 if (((m_iPositionY == screen.y()) && m_fSlideToScreen) || 269 ((m_iPositionY == screen.y() - height() + 1) && !m_fSlideToScreen)) 270 { 271 m_scrollTimer.stop(); 272 if (m_fHideAfterSlide) 273 { 274 m_fHideAfterSlide = false; 275 hide(); 276 } 277 return; 278 } 279 m_fSlideToScreen ? ++m_iPositionY : --m_iPositionY; 280 break; 281 } 282 case AlignBottom: 283 { 284 if (((m_iPositionY == screen.y() + screen.height() - height()) && m_fSlideToScreen) || 285 ((m_iPositionY == screen.y() + screen.height() - 1) && !m_fSlideToScreen)) 286 { 287 m_scrollTimer.stop(); 288 if (m_fHideAfterSlide) 289 { 290 m_fHideAfterSlide = false; 291 hide(); 292 } 293 return; 294 } 295 m_fSlideToScreen ? --m_iPositionY : ++m_iPositionY; 296 break; 297 } 298 default: 299 break; 300 } 301 move(parentWidget()->mapFromGlobal(QPoint(m_iPositionX, m_iPositionY))); 302 emit geometryUpdated(); 303 } 304 else if (pEvent->timerId() == m_autoScrollTimer.timerId()) 305 { 306 QRect rect = this->rect(); 307 QPoint p = mapFromGlobal(QCursor::pos()); 308 if (!rect.contains(p)) 309 { 310 ++m_iAutoHideCounter; 311 312 if (m_iAutoHideCounter == m_iAutoHideTotalCounter) 313 { 314 m_fSlideToScreen = false; 315 m_scrollTimer.start(m_iScrollDelay, this); 316 } 317 } 318 else 319 m_iAutoHideCounter = 0; 320 } 321 else 322 QWidget::timerEvent(pEvent); 323 } 324 325 /* Show event processor */ 326 void UIMiniToolBar::showEvent(QShowEvent *pEvent) 327 { 328 if (!m_fPolished) 329 { 330 /* Tool-bar spacings: */ 331 foreach(QWidget *pSpacing, m_Spacings) 332 pSpacing->setMinimumWidth(5); 333 334 /* Title spacings: */ 335 foreach(QWidget *pLableMargin, m_LabelMargins) 336 pLableMargin->setMinimumWidth(15); 337 338 /* Initialize: */ 339 initialize(); 340 341 m_fPolished = true; 342 } 343 /* Base-class show event processing: */ 344 UIToolBar::showEvent(pEvent); 345 } 346 347 /* Show event processor */ 348 void UIMiniToolBar::paintEvent(QPaintEvent *pEvent) 349 { 350 /* Paint background */ 351 QPainter painter; 352 painter.begin(this); 353 painter.fillRect(pEvent->rect(), QApplication::palette().color(QPalette::Active, QPalette::Window)); 354 painter.end(); 355 /* Base-class paint event processing: */ 356 UIToolBar::paintEvent(pEvent); 357 } 358 359 /* Toggle push-pin */ 360 void UIMiniToolBar::togglePushpin(bool fOn) 361 { 362 m_fAutoHide = !fOn; 363 updateDisplay(!m_fAutoHide, false); 364 } 365 366 /* Initialize mini-toolbar */ 367 void UIMiniToolBar::initialize() 368 { 511 m_spacings << widgetForAction(insertWidget(m_pMenuInsertPosition, new QWidget(this))); 512 } 513 369 514 /* Resize to sizehint: */ 370 515 resize(sizeHint()); 371 372 /* Update geometry: */ 373 moveToBase(); 374 } 375 376 /* Move mini-toolbar to the base location */ 377 void UIMiniToolBar::moveToBase() 378 { 379 QRect screen = m_fSeamless ? vboxGlobal().availableGeometry(QApplication::desktop()->screenNumber(window())) : 380 QApplication::desktop()->screenGeometry(window()); 381 m_iPositionX = screen.x() + (screen.width() / 2) - (width() / 2); 516 } 517 518 void UIMiniToolBar::showEvent(QShowEvent *pEvent) 519 { 520 /* Make sure we should polish dialog: */ 521 if (m_fPolished) 522 return; 523 524 /* Call to polish-event: */ 525 polishEvent(pEvent); 526 527 /* Mark dialog as polished: */ 528 m_fPolished = true; 529 } 530 531 void UIMiniToolBar::polishEvent(QShowEvent*) 532 { 533 /* Toolbar spacings: */ 534 foreach(QWidget *pSpacing, m_spacings) 535 pSpacing->setMinimumWidth(5); 536 537 /* Title spacings: */ 538 foreach(QWidget *pLableMargin, m_margins) 539 pLableMargin->setMinimumWidth(15); 540 541 /* Resize to sizehint: */ 542 resize(sizeHint()); 543 } 544 545 void UIMiniToolBar::resizeEvent(QResizeEvent*) 546 { 547 /* Rebuild shape: */ 548 rebuildShape(); 549 550 /* Notify listeners: */ 551 emit sigResized(); 552 } 553 554 void UIMiniToolBar::paintEvent(QPaintEvent*) 555 { 556 /* Prepare painter: */ 557 QPainter painter(this); 558 559 /* Fill background: */ 560 if (!m_shape.isEmpty()) 561 { 562 painter.setRenderHint(QPainter::Antialiasing); 563 painter.setClipPath(m_shape); 564 } 565 QRect backgroundRect = rect(); 566 QColor backgroundColor = palette().color(QPalette::Window); 567 QLinearGradient headerGradient(backgroundRect.bottomLeft(), backgroundRect.topLeft()); 568 headerGradient.setColorAt(0, backgroundColor.darker(120)); 569 headerGradient.setColorAt(1, backgroundColor.darker(90)); 570 painter.fillRect(backgroundRect, headerGradient); 571 } 572 573 void UIMiniToolBar::prepare() 574 { 575 /* Configure toolbar: */ 576 setIconSize(QSize(16, 16)); 577 578 #ifdef VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR 579 /* Left margin: */ 580 m_spacings << widgetForAction(addWidget(new QWidget)); 581 #endif /* VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR */ 582 583 /* Prepare push-pin: */ 584 m_pAutoHideAction = new QAction(this); 585 m_pAutoHideAction->setIcon(UIIconPool::iconSet(":/pin_16px.png")); 586 m_pAutoHideAction->setToolTip(tr("Always show the toolbar")); 587 m_pAutoHideAction->setCheckable(true); 588 connect(m_pAutoHideAction, SIGNAL(toggled(bool)), this, SIGNAL(sigAutoHideToggled())); 589 addAction(m_pAutoHideAction); 590 591 /* Left menu margin: */ 592 m_spacings << widgetForAction(addWidget(new QWidget)); 593 594 /* Right menu margin: */ 595 m_pMenuInsertPosition = addWidget(new QWidget); 596 m_spacings << widgetForAction(m_pMenuInsertPosition); 597 598 /* Left label margin: */ 599 m_margins << widgetForAction(addWidget(new QWidget)); 600 601 /* Insert a label for VM Name: */ 602 m_pLabel = new QLabel; 603 m_pLabel->setAlignment(Qt::AlignCenter); 604 addWidget(m_pLabel); 605 606 /* Right label margin: */ 607 m_margins << widgetForAction(addWidget(new QWidget)); 608 609 /* Minimize action: */ 610 m_pMinimizeAction = new QAction(this); 611 m_pMinimizeAction->setIcon(UIIconPool::iconSet(":/minimize_16px.png")); 612 m_pMinimizeAction->setToolTip(tr("Minimize Window")); 613 connect(m_pMinimizeAction, SIGNAL(triggered()), this, SIGNAL(sigMinimizeAction())); 614 addAction(m_pMinimizeAction); 615 616 /* Exit action: */ 617 m_pRestoreAction = new QAction(this); 618 m_pRestoreAction->setIcon(UIIconPool::iconSet(":/restore_16px.png")); 619 m_pRestoreAction->setToolTip(tr("Exit Full Screen or Seamless Mode")); 620 connect(m_pRestoreAction, SIGNAL(triggered()), this, SIGNAL(sigExitAction())); 621 addAction(m_pRestoreAction); 622 623 /* Close action: */ 624 m_pCloseAction = new QAction(this); 625 m_pCloseAction->setIcon(UIIconPool::iconSet(":/close_16px.png")); 626 m_pCloseAction->setToolTip(tr("Close VM")); 627 connect(m_pCloseAction, SIGNAL(triggered()), this, SIGNAL(sigCloseAction())); 628 addAction(m_pCloseAction); 629 630 #ifdef VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR 631 /* Right margin: */ 632 m_spacings << widgetForAction(addWidget(new QWidget)); 633 #endif /* VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR */ 634 635 /* Resize to sizehint: */ 636 resize(sizeHint()); 637 } 638 639 void UIMiniToolBar::rebuildShape() 640 { 641 #ifdef VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR 642 /* Rebuild shape: */ 643 QPainterPath shape; 382 644 switch (m_alignment) 383 645 { 384 case AlignTop:646 case Qt::AlignTop: 385 647 { 386 m_iPositionY = screen.y() - height() + 1; 648 shape.moveTo(0, 0); 649 shape.lineTo(shape.currentPosition().x(), height() - 10); 650 shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(0, -10), 180, 90); 651 shape.lineTo(width() - 10, shape.currentPosition().y()); 652 shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(-10, -20), 270, 90); 653 shape.lineTo(shape.currentPosition().x(), 0); 654 shape.closeSubpath(); 387 655 break; 388 656 } 389 case AlignBottom:657 case Qt::AlignBottom: 390 658 { 391 m_iPositionY = screen.y() + screen.height() - 1; 659 shape.moveTo(0, height()); 660 shape.lineTo(shape.currentPosition().x(), 10); 661 shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(0, -10), 180, -90); 662 shape.lineTo(width() - 10, shape.currentPosition().y()); 663 shape.arcTo(QRectF(shape.currentPosition(), QSizeF(20, 20)).translated(-10, 0), 90, -90); 664 shape.lineTo(shape.currentPosition().x(), height()); 665 shape.closeSubpath(); 392 666 break; 393 667 } 394 668 default: 395 {396 m_iPositionY = 0;397 669 break; 398 } 399 } 400 move(parentWidget()->mapFromGlobal(QPoint(m_iPositionX, m_iPositionY))); 401 } 402 403 /* Enable/disable mouse-tracking for required widgets */ 404 void UIMiniToolBar::setMouseTrackingEnabled(bool fEnabled) 405 { 406 setMouseTracking(fEnabled); 407 if (m_pDisplayLabel) 408 m_pDisplayLabel->setMouseTracking(fEnabled); 409 if (m_pAutoHideAction && widgetForAction(m_pAutoHideAction)) 410 widgetForAction(m_pAutoHideAction)->setMouseTracking(fEnabled); 411 if (m_pMinimizeAction && widgetForAction(m_pMinimizeAction)) 412 widgetForAction(m_pMinimizeAction)->setMouseTracking(fEnabled); 413 if (m_pRestoreAction && widgetForAction(m_pRestoreAction)) 414 widgetForAction(m_pRestoreAction)->setMouseTracking(fEnabled); 415 if (m_pCloseAction && widgetForAction(m_pCloseAction)) 416 widgetForAction(m_pCloseAction)->setMouseTracking(fEnabled); 417 } 418 670 } 671 m_shape = shape; 672 673 /* Update: */ 674 update(); 675 #endif /* VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR */ 676 } 677 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMiniToolBar.h
r46224 r46244 2 2 * 3 3 * VBox frontends: Qt GUI ("VirtualBox"): 4 * UIMiniToolBar class declaration & implementation. This is the toolbar shown on fullscreen mode. 4 * UIMiniToolBar class declaration. 5 * This is the toolbar shown in fullscreen/seamless modes. 5 6 */ 6 7 7 8 /* 8 * Copyright (C) 2009-201 1Oracle Corporation9 * Copyright (C) 2009-2013 Oracle Corporation 9 10 * 10 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 21 #define __UIMiniToolBar_h__ 21 22 22 /* Global includes*/23 #include <Q BasicTimer>24 25 /* Local includes*/23 /* Qt includes: */ 24 #include <QMainWindow> 25 26 /* GUI includes: */ 26 27 #include "UIToolBar.h" 27 28 28 /* Global forwards */ 29 /* Forward declarations: */ 30 class QTimer; 29 31 class QLabel; 30 32 class QMenu; 31 32 /** 33 * The UIMiniToolBar class is a toolbar shown inside full screen mode or seamless mode. 34 * It supports auto hiding and animated sliding up/down. 35 */ 33 class QMdiArea; 34 class UIMiniToolBar; 35 class QMdiSubWindow; 36 class UIAnimation; 37 38 /* IntegrationMode enum: */ 39 enum IntegrationMode 40 { 41 IntegrationMode_Embedded, 42 IntegrationMode_External 43 }; 44 45 /* Runtime mini-toolbar frameless-window prototype: */ 46 class UIRuntimeMiniToolBar : public QWidget 47 { 48 Q_OBJECT; 49 Q_PROPERTY(QPoint toolbarPosition READ toolbarPosition WRITE setToolbarPosition); 50 Q_PROPERTY(QPoint hiddenToolbarPosition READ hiddenToolbarPosition); 51 Q_PROPERTY(QPoint shownToolbarPosition READ shownToolbarPosition); 52 53 signals: 54 55 /* Notifiers: Action stuff: */ 56 void sigMinimizeAction(); 57 void sigExitAction(); 58 void sigCloseAction(); 59 60 /* Notifiers: Hover stuff: */ 61 void sigHoverEnter(); 62 void sigHoverLeave(); 63 64 public: 65 66 /* Constructor/destructor: */ 67 UIRuntimeMiniToolBar(QWidget *pParent, 68 Qt::Alignment alignment, 69 IntegrationMode integrationMode, 70 bool fAutoHide = true); 71 ~UIRuntimeMiniToolBar(); 72 73 /* API: Alignment stuff: */ 74 void setAlignment(Qt::Alignment alignment); 75 76 /* API: Integration mode stuff: */ 77 void setIntegrationMode(IntegrationMode integrationMode); 78 79 /* API: Auto-hide stuff: */ 80 bool autoHide() const { return m_fAutoHide; } 81 void setAutoHide(bool fAutoHide, bool fPropagateToChild = true); 82 83 /* API: Text stuff: */ 84 void setText(const QString &strText); 85 86 /* API: Menu stuff: */ 87 void addMenus(const QList<QMenu*> &menus); 88 89 /* API: Geometry stuff: */ 90 void adjustGeometry(); 91 92 private slots: 93 94 /* Handlers: Toolbar stuff: */ 95 void sltHandleToolbarResize(); 96 void sltAutoHideToggled(); 97 void sltHoverEnter(); 98 void sltHoverLeave(); 99 100 private: 101 102 /* Helpers: Prepare/cleanup stuff: */ 103 void prepare(); 104 void cleanup(); 105 106 /* Handlers: Event-processing stuff: */ 107 void enterEvent(QEvent *pEvent); 108 void leaveEvent(QEvent *pEvent); 109 110 /* Helper: Hover stuff: */ 111 void updateAutoHideAnimationBounds(); 112 void simulateToolbarAutoHiding(); 113 114 /* Property: Hover stuff: */ 115 void setToolbarPosition(QPoint point); 116 QPoint toolbarPosition() const; 117 QPoint hiddenToolbarPosition() const { return m_hiddenToolbarPosition; } 118 QPoint shownToolbarPosition() const { return m_shownToolbarPosition; } 119 120 /* Helper: Integration stuff: */ 121 void integrate(); 122 123 /* Variables: General stuff: */ 124 Qt::Alignment m_alignment; 125 IntegrationMode m_integrationMode; 126 bool m_fAutoHide; 127 128 /* Variables: Contents stuff: */ 129 QMdiArea *m_pMdiArea; 130 UIMiniToolBar *m_pToolbar; 131 QMdiSubWindow *m_pEmbeddedToolbar; 132 133 /* Variables: Hover stuff: */ 134 bool m_fHovered; 135 QTimer *m_pHoverEnterTimer; 136 QTimer *m_pHoverLeaveTimer; 137 QPoint m_hiddenToolbarPosition; 138 QPoint m_shownToolbarPosition; 139 UIAnimation *m_pAnimation; 140 }; 141 142 /* Mini-toolbar widget prototype: */ 36 143 class UIMiniToolBar : public UIToolBar 37 144 { 38 145 Q_OBJECT; 39 146 147 signals: 148 149 /* Notifier: Resize stuff: */ 150 void sigResized(); 151 152 /* Notifiers: Action stuff: */ 153 void sigAutoHideToggled(); 154 void sigMinimizeAction(); 155 void sigExitAction(); 156 void sigCloseAction(); 157 40 158 public: 41 159 42 enum Alignment 43 { 44 AlignTop, 45 AlignBottom 46 }; 47 48 UIMiniToolBar(QWidget *pParent, Alignment alignment, bool fActive, bool fAutoHide); 49 50 UIMiniToolBar& operator<<(QList<QMenu*> menus); 51 52 void setSeamlessMode(bool fSeamless); 53 void setDisplayText(const QString &strText); 54 55 bool isAutoHide() const; 56 57 void updateDisplay(bool fShow, bool fSetHideFlag); 58 59 signals: 60 61 void minimizeAction(); 62 void exitAction(); 63 void closeAction(); 64 void geometryUpdated(); 160 /* Constructor: */ 161 UIMiniToolBar(); 162 163 /* API: Alignment stuff: */ 164 void setAlignment(Qt::Alignment alignment); 165 166 /* API: Integration mode stuff: */ 167 void setIntegrationMode(IntegrationMode integrationMode); 168 169 /* API: Auto-hide stuff: */ 170 bool autoHide() const; 171 void setAutoHide(bool fAutoHide); 172 173 /* API: Text stuff: */ 174 void setText(const QString &strText); 175 176 /* API: Menu aggregator: */ 177 void addMenus(const QList<QMenu*> &menus); 65 178 66 179 protected: 67 180 68 bool eventFilter(QObject *pObj, QEvent *pEvent); 69 void mouseMoveEvent(QMouseEvent *pEvent); 70 void timerEvent(QTimerEvent *pEvent); 71 void showEvent(QShowEvent *pEvent); 72 void paintEvent(QPaintEvent *pEvent); 73 74 private slots: 75 76 void togglePushpin(bool fOn); 181 /* Handlers: Event-processing stuff: */ 182 virtual void showEvent(QShowEvent *pEvent); 183 virtual void polishEvent(QShowEvent *pEvent); 184 virtual void resizeEvent(QResizeEvent *pEvent); 185 virtual void paintEvent(QPaintEvent *pEvent); 77 186 78 187 private: 79 188 80 void initialize(); 81 void moveToBase(); 82 void setMouseTrackingEnabled(bool fEnabled); 83 189 /* Helper: Prepare stuff: */ 190 void prepare(); 191 192 /* Helper: Shape stuff: */ 193 void rebuildShape(); 194 195 /* Variables: General stuff: */ 196 bool m_fPolished; 197 Qt::Alignment m_alignment; 198 IntegrationMode m_integrationMode; 199 QPainterPath m_shape; 200 201 /* Variables: Contents stuff: */ 84 202 QAction *m_pAutoHideAction; 85 QLabel *m_p DisplayLabel;203 QLabel *m_pLabel; 86 204 QAction *m_pMinimizeAction; 87 205 QAction *m_pRestoreAction; 88 206 QAction *m_pCloseAction; 89 207 90 QBasicTimer m_scrollTimer; 91 QBasicTimer m_autoScrollTimer; 92 93 bool m_fActive; 94 bool m_fPolished; 95 bool m_fSeamless; 96 bool m_fAutoHide; 97 bool m_fSlideToScreen; 98 bool m_fHideAfterSlide; 99 100 int m_iAutoHideCounter; 101 int m_iPositionX; 102 int m_iPositionY; 103 104 /* Lists of used spacers */ 105 QList<QWidget*> m_Spacings; 106 QList<QWidget*> m_LabelMargins; 107 108 /* Menu insert position */ 109 QAction *m_pInsertPosition; 110 111 /* Tool-bar alignment */ 112 Alignment m_alignment; 113 114 /* Whether to animate showing/hiding the toolbar */ 115 bool m_fAnimated; 116 117 /* Interval (in milli seconds) for scrolling the toolbar, default is 20 msec */ 118 int m_iScrollDelay; 119 120 /* The wait time while the cursor is not over the window after this amount of time (in msec), 121 * the toolbar will auto hide if autohide is on. The default is 100msec. */ 122 int m_iAutoScrollDelay; 123 124 /* Number of total steps before hiding. If it is 10 then wait 10 (steps) * 100ms (m_iAutoScrollDelay) = 1000ms delay. 125 * The default is 10. */ 126 int m_iAutoHideTotalCounter; 208 /* Variables: Menu stuff: */ 209 QAction *m_pMenuInsertPosition; 210 211 /* Variables: Spacers stuff: */ 212 QList<QWidget*> m_spacings; 213 QList<QWidget*> m_margins; 127 214 }; 128 215
Note:
See TracChangeset
for help on using the changeset viewer.