void pDockWidgetTitleBar::updateStyleChange() { setIconSize( QSize( 13, 13 ) ); layout()->setSpacing( 0 ); layout()->setMargin( 2 ); QIcon icon; icon = style()->standardIcon( QStyle::SP_TitleBarShadeButton, 0, widgetForAction( aOrientation ) ); aOrientation->setIcon( icon ); icon = style()->standardIcon( QStyle::SP_TitleBarNormalButton, 0, widgetForAction( aFloat ) ); aFloat->setIcon( icon ); icon = style()->standardIcon( QStyle::SP_TitleBarCloseButton, 0, widgetForAction( aClose ) ); aClose->setIcon( icon ); if ( orientation() == Qt::Horizontal ) { tbOrientation->setDirection( QBoxLayout::LeftToRight ); tbFloat->setDirection( QBoxLayout::LeftToRight ); tbClose->setDirection( QBoxLayout::LeftToRight ); } else { tbOrientation->setDirection( QBoxLayout::BottomToTop ); tbFloat->setDirection( QBoxLayout::BottomToTop ); tbClose->setDirection( QBoxLayout::BottomToTop ); } }
void pDockWidgetTitleBar::updateStandardIcons() { const QSize size( 16, 16 ); QPixmap pixmap; QRect rect( QPoint(), iconSize() ); QTransform transform; transform.rotate( 90 ); pixmap = style()->standardIcon( QStyle::SP_ToolBarHorizontalExtensionButton, 0, widgetForAction( aOrientation ) ).pixmap( size ); rect.moveCenter( pixmap.rect().center() ); pixmap = pixmap.copy( rect ); pixmap = pixmap.transformed( transform, Qt::SmoothTransformation ); aOrientation->setIcon( pixmap ); pixmap = style()->standardIcon( QStyle::SP_TitleBarNormalButton, 0, widgetForAction( aFloat ) ).pixmap( size ); rect.moveCenter( pixmap.rect().center() ); pixmap = pixmap.copy( rect ); aFloat->setIcon( pixmap ); pixmap = style()->standardIcon( QStyle::SP_TitleBarCloseButton, 0, widgetForAction( aClose ) ).pixmap( size ); rect.moveCenter( pixmap.rect().center() ); pixmap = pixmap.copy( rect ); aClose->setIcon( pixmap ); }
/* Appends passed menus into internal menu-list */ VBoxMiniToolBar& VBoxMiniToolBar::operator<<(QList<QMenu*> menus) { for (int i = 0; i < menus.size(); ++i) { QAction *pAction = menus[i]->menuAction(); insertAction(m_pInsertPosition, pAction); if (QToolButton *pButton = qobject_cast<QToolButton*>(widgetForAction(pAction))) { pButton->setPopupMode(QToolButton::InstantPopup); pButton->setAutoRaise(true); } if (i != menus.size() - 1) m_Spacings << widgetForAction(insertWidget(m_pInsertPosition, new QWidget(this))); } return *this; }
void ToolBar::actionEvent(QActionEvent *event) { QToolBar::actionEvent(event); if (event->type() == QEvent::ActionAdded) if (event->action()) { QWidget *widget = widgetForAction(event->action()); if (widget) widget->installEventFilter(this); } }
void FileToolBar::rebuildRecentFileMenu() { QToolButton* tb = dynamic_cast<QToolButton*>(widgetForAction(parent->scrActions["fileOpen"])); QMenu *m=new QMenu(this); ScrAction *recentFileAction; foreach (recentFileAction, parent->scrRecentFileActions) m->addAction(recentFileAction); tb->setMenu(m); // tb->setPopupMode(QToolButton::MenuButtonPopup); tb->setPopupMode(QToolButton::DelayedPopup); }
/* Enable/disable mouse-tracking for required widgets */ void VBoxMiniToolBar::setMouseTrackingEnabled(bool fEnabled) { setMouseTracking(fEnabled); if (m_pDisplayLabel) m_pDisplayLabel->setMouseTracking(fEnabled); if (m_pAutoHideAction && widgetForAction(m_pAutoHideAction)) widgetForAction(m_pAutoHideAction)->setMouseTracking(fEnabled); if (m_pMinimizeAction && widgetForAction(m_pMinimizeAction)) widgetForAction(m_pMinimizeAction)->setMouseTracking(fEnabled); if (m_pRestoreAction && widgetForAction(m_pRestoreAction)) widgetForAction(m_pRestoreAction)->setMouseTracking(fEnabled); if (m_pCloseAction && widgetForAction(m_pCloseAction)) widgetForAction(m_pCloseAction)->setMouseTracking(fEnabled); }
void UIMiniToolBar::addMenus(const QList<QMenu*> &menus) { /* For each of the passed menu items: */ for (int i = 0; i < menus.size(); ++i) { /* Get corresponding menu-action: */ QAction *pAction = menus[i]->menuAction(); /* Insert it into corresponding place: */ insertAction(m_pMenuInsertPosition, pAction); /* Configure corresponding tool-button: */ if (QToolButton *pButton = qobject_cast<QToolButton*>(widgetForAction(pAction))) { pButton->setPopupMode(QToolButton::InstantPopup); pButton->setAutoRaise(true); } /* Add some spacing: */ if (i != menus.size() - 1) m_spacings << widgetForAction(insertWidget(m_pMenuInsertPosition, new QWidget(this))); } /* Resize to sizehint: */ resize(sizeHint()); }
FileToolBar::FileToolBar(ScribusMainWindow* p) : ScToolBar( tr("File"), "File", p) { parent=p; addAction(p->scrActions["fileNew"]); addAction(p->scrActions["fileOpen"]); addAction(p->scrActions["fileSave"]); addAction(p->scrActions["fileClose"]); addAction(p->scrActions["filePrint"]); addAction(p->scrActions["toolsPreflightVerifier"]); addAction(p->scrActions["fileExportAsPDF"]); fileOpenButtonMenu = new QMenu(); QToolButton* tb = dynamic_cast<QToolButton*>(widgetForAction(parent->scrActions["fileOpen"])); tb->setMenu(fileOpenButtonMenu); tb->setPopupMode(QToolButton::DelayedPopup); }
QWidget* pDockWidgetTitleBar::addAction( QAction* action, int index ) { if ( index != -1 ) { index++; } if ( index >= 0 && index < actions().count() ) { QToolBar::insertAction( actions().value( index ), action ); } else { QToolBar::addAction( action ); } return widgetForAction( action ); }
void ToolBar::dragMoveEvent(QDragMoveEvent *event) { const MimeDataObject *mimeData = qobject_cast<const MimeDataObject *>(event->mimeData()); QAction *eAction = this->actionAt(event->pos()); if (mimeData->hasFormat("application/x-qobject") && isEdited()) if (mimeData->object() != eAction && eAction) if (eAction->menu() && !eAction->menu()->isVisible()) { if (m_activeAction) m_activeAction->menu()->close(); QToolButton *toolButton = qobject_cast<QToolButton *>(widgetForAction(eAction)); QPoint point = QPoint(toolButton->x(), toolButton->y()+toolButton->height()); eAction->menu()->popup(mapToGlobal(point)); m_activeAction = eAction; } event->accept(); }
QToolButton * ToolBar::createPushButton(QAction *before, ToolBarAction &action) { if (!Actions::instance()->contains(action.actionName)) return nullptr; MainWindow *kaduMainWindow = qobject_cast<MainWindow *>(parentWidget()); if (!kaduMainWindow) return nullptr; auto actionByName = Actions::instance()->value(action.actionName); if (!actionByName) return nullptr; if (!kaduMainWindow->supportsActionType(actionByName->type())) return nullptr; action.action = Actions::instance()->createAction(action.actionName, kaduMainWindow->actionContext(), kaduMainWindow); insertAction(before, action.action); QToolButton *button = qobject_cast<QToolButton *>(widgetForAction(action.action)); action.widget = button; if (button) { connect(button, SIGNAL(pressed()), this, SLOT(widgetPressed())); button->installEventFilter(watcher); button->setToolButtonStyle(action.style); if (action.action->menu() && Actions::instance()->contains(action.actionName)) { ActionDescription *actionDescription = Actions::instance()->value(action.actionName); if (actionDescription) button->setPopupMode(actionDescription->buttonPopupMode()); } } return button; }
bool BookmarkToolBar::eventFilter(QObject *watched, QEvent *event) { if (m_currentMenu && m_currentMenu->isVisible() && !m_currentMenu->rect().contains(m_currentMenu->mapFromGlobal(QCursor::pos()))) { // To switch root folders as in a menubar KBookmarkActionMenu* act = dynamic_cast<KBookmarkActionMenu *>(actionAt(mapFromGlobal(QCursor::pos()))); if (event->type() == QEvent::MouseMove && act && act->menu() != m_currentMenu) { m_currentMenu->hide(); QPoint pos = mapToGlobal(widgetForAction(act)->pos()); act->menu()->popup(QPoint(pos.x(), pos.y() + widgetForAction(act)->height())); } else if (event->type() == QEvent::MouseButtonPress && act) { m_currentMenu->hide(); } return QObject::eventFilter(watched, event); } switch (event->type()) { case QEvent::Show: { if (!m_filled) { BookmarkManager::self()->fillBookmarkBar(this); m_filled = true; } } break; case QEvent::ActionRemoved: { QActionEvent *actionEvent = static_cast<QActionEvent*>(event); if (actionEvent && actionEvent->action() != m_dropAction) { QWidget *widget = widgetForAction(actionEvent->action()); if (widget) { widget->removeEventFilter(this); } } } break; case QEvent::ParentChange: { QActionEvent *actionEvent = static_cast<QActionEvent*>(event); if (actionEvent && actionEvent->action() != m_dropAction) { QWidget *widget = widgetForAction(actionEvent->action()); if (widget) { widget->removeEventFilter(this); } } } break; case QEvent::DragEnter: { QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event); if (dragEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type()) || dragEvent->mimeData()->hasFormat("text/uri-list") || dragEvent->mimeData()->hasFormat("text/plain")) { QFrame* dropIndicatorWidget = new QFrame(this); dropIndicatorWidget->setFrameShape(QFrame::VLine); m_dropAction = insertWidget(actionAt(dragEvent->pos()), dropIndicatorWidget); dragEvent->accept(); } } break; case QEvent::DragLeave: { QDragLeaveEvent *dragEvent = static_cast<QDragLeaveEvent*>(event); if (m_checkedAction) { m_checkedAction->setCheckable(false); m_checkedAction->setChecked(false); } delete m_dropAction; m_dropAction = 0; dragEvent->accept(); } break; case QEvent::DragMove: { QDragMoveEvent *dragEvent = static_cast<QDragMoveEvent*>(event); if (dragEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type()) || dragEvent->mimeData()->hasFormat("text/uri-list") || dragEvent->mimeData()->hasFormat("text/plain")) { QAction *overAction = actionAt(dragEvent->pos()); KBookmarkActionInterface *overActionBK = dynamic_cast<KBookmarkActionInterface*>(overAction); QWidget *widgetAction = widgetForAction(overAction); if (overAction != m_dropAction && overActionBK && widgetAction && m_dropAction) { removeAction(m_dropAction); if (m_checkedAction) { m_checkedAction->setCheckable(false); m_checkedAction->setChecked(false); } if (!overActionBK->bookmark().isGroup()) { if ((dragEvent->pos().x() - widgetAction->pos().x()) > (widgetAction->width() / 2)) { if (actions().count() > actions().indexOf(overAction) + 1) { insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction); } else { addAction(m_dropAction); } } else { insertAction(overAction, m_dropAction); } } else { if ((dragEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() * 0.75)) { if (actions().count() > actions().indexOf(overAction) + 1) { insertAction(actions().at(actions().indexOf(overAction) + 1), m_dropAction); } else { addAction(m_dropAction); } } else if ((dragEvent->pos().x() - widgetAction->pos().x()) <= (widgetAction->width() * 0.25)) { insertAction(overAction, m_dropAction); } else { overAction->setCheckable(true); overAction->setChecked(true); m_checkedAction = overAction; } } dragEvent->accept(); } } } break; case QEvent::Drop: { QDropEvent *dropEvent = static_cast<QDropEvent*>(event); KBookmark bookmark; KBookmarkGroup root = BookmarkManager::self()->manager()->toolbar(); if (m_checkedAction) { m_checkedAction->setCheckable(false); m_checkedAction->setChecked(false); } if (dropEvent->mimeData()->hasFormat(BookmarkManager::bookmark_mime_type())) { QByteArray addresses = dropEvent->mimeData()->data(BookmarkManager::bookmark_mime_type()); bookmark = BookmarkManager::self()->findByAddress(QString::fromLatin1(addresses.data())); if (bookmark.isNull()) return false; } else if (dropEvent->mimeData()->hasFormat("text/uri-list")) { // DROP is URL QString url = dropEvent->mimeData()->urls().at(0).toString(); WebWindow *w = qobject_cast<WebWindow *>(parent()); QString title = url.contains(w->url().url()) ? w->title() : url; bookmark = root.addBookmark(title, url); } else if (dropEvent->mimeData()->hasFormat("text/plain")) { // DROP is TEXT QString url = dropEvent->mimeData()->text(); KUrl u(url); if (u.isValid()) { WebWindow *w = qobject_cast<WebWindow *>(parent()); QString title = url.contains(w->url().url()) ? w->title() : url; bookmark = root.addBookmark(title, url); } } else { return false; } QAction *destAction = actionAt(dropEvent->pos()); if (destAction && destAction == m_dropAction) { if (actions().indexOf(m_dropAction) > 0) { destAction = actions().at(actions().indexOf(m_dropAction) - 1); } else { destAction = actions().at(1); } } if (destAction) { KBookmarkActionInterface *destBookmarkAction = dynamic_cast<KBookmarkActionInterface *>(destAction); QWidget *widgetAction = widgetForAction(destAction); if (destBookmarkAction && !destBookmarkAction->bookmark().isNull() && widgetAction && bookmark.address() != destBookmarkAction->bookmark().address()) { KBookmark destBookmark = destBookmarkAction->bookmark(); if (!destBookmark.isGroup()) { if ((dropEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() / 2)) { root.moveBookmark(bookmark, destBookmark); } else { root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark)); } } else { if ((dropEvent->pos().x() - widgetAction->pos().x()) >= (widgetAction->width() * 0.75)) { root.moveBookmark(bookmark, destBookmark); } else if ((dropEvent->pos().x() - widgetAction->pos().x()) <= (widgetAction->width() * 0.25)) { root.moveBookmark(bookmark, destBookmark.parentGroup().previous(destBookmark)); } else { destBookmark.toGroup().addBookmark(bookmark); } } BookmarkManager::self()->emitChanged(); } } else { root.deleteBookmark(bookmark); bookmark = root.addBookmark(bookmark); if (dropEvent->pos().x() < widgetForAction(actions().first())->pos().x()) { root.moveBookmark(bookmark, KBookmark()); } BookmarkManager::self()->emitChanged(); } dropEvent->accept(); } break; default: break; } QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); // These events need to be handled only for Bookmark actions and not the bar if (watched != this && mouseEvent) { switch (event->type()) { case QEvent::MouseButtonPress: // drag handling { QPoint pos = mapFromGlobal(QCursor::pos()); KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(pos)); if (action && mouseEvent->button() != Qt::MiddleButton) { m_dragAction = actionAt(pos); m_startDragPos = pos; // The menu is displayed only when the mouse button is released if (action->bookmark().isGroup()) return true; } } break; case QEvent::MouseMove: { int distance = (mapFromGlobal(QCursor::pos()) - m_startDragPos).manhattanLength(); if (!m_currentMenu && distance >= QApplication::startDragDistance()) { startDrag(); } } break; case QEvent::MouseButtonRelease: { QPoint destPos = mapFromGlobal(QCursor::pos()); int distance = (destPos - m_startDragPos).manhattanLength(); KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(actionAt(destPos)); if (action) { if (action->bookmark().isGroup()) { if (mouseEvent->button() == Qt::MiddleButton) { BookmarkManager::self()->owner()->loadBookmarkFolder(action->bookmark()); } else if (distance < QApplication::startDragDistance()) { KBookmarkActionMenu *menu = dynamic_cast<KBookmarkActionMenu *>(actionAt(m_startDragPos)); QPoint actionPos = mapToGlobal(widgetForAction(menu)->pos()); menu->menu()->popup(QPoint(actionPos.x(), actionPos.y() + widgetForAction(menu)->height())); } } else { if (!action->bookmark().isNull() && !action->bookmark().isSeparator()) { if (mouseEvent->button() == Qt::MiddleButton) { BookmarkManager::self()->owner()->loadBookmarkInNewTab(action->bookmark()); } } } } } break; default: break; } } return QObject::eventFilter(watched, event); }
void UIMiniToolBar::prepare() { /* Configure toolbar: */ setIconSize(QSize(16, 16)); #ifdef VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR /* Left margin: */ m_spacings << widgetForAction(addWidget(new QWidget)); #endif /* VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR */ /* Prepare push-pin: */ m_pAutoHideAction = new QAction(this); m_pAutoHideAction->setIcon(UIIconPool::iconSet(":/pin_16px.png")); m_pAutoHideAction->setToolTip(tr("Always show the toolbar")); m_pAutoHideAction->setCheckable(true); connect(m_pAutoHideAction, SIGNAL(toggled(bool)), this, SIGNAL(sigAutoHideToggled())); addAction(m_pAutoHideAction); /* Left menu margin: */ m_spacings << widgetForAction(addWidget(new QWidget)); /* Right menu margin: */ m_pMenuInsertPosition = addWidget(new QWidget); m_spacings << widgetForAction(m_pMenuInsertPosition); /* Left label margin: */ m_margins << widgetForAction(addWidget(new QWidget)); /* Insert a label for VM Name: */ m_pLabel = new QLabel; m_pLabel->setAlignment(Qt::AlignCenter); addWidget(m_pLabel); /* Right label margin: */ m_margins << widgetForAction(addWidget(new QWidget)); /* Minimize action: */ m_pMinimizeAction = new QAction(this); m_pMinimizeAction->setIcon(UIIconPool::iconSet(":/minimize_16px.png")); m_pMinimizeAction->setToolTip(tr("Minimize Window")); connect(m_pMinimizeAction, SIGNAL(triggered()), this, SIGNAL(sigMinimizeAction())); addAction(m_pMinimizeAction); /* Exit action: */ m_pRestoreAction = new QAction(this); m_pRestoreAction->setIcon(UIIconPool::iconSet(":/restore_16px.png")); m_pRestoreAction->setToolTip(tr("Exit Full Screen or Seamless Mode")); connect(m_pRestoreAction, SIGNAL(triggered()), this, SIGNAL(sigExitAction())); addAction(m_pRestoreAction); /* Close action: */ m_pCloseAction = new QAction(this); m_pCloseAction->setIcon(UIIconPool::iconSet(":/close_16px.png")); m_pCloseAction->setToolTip(tr("Close VM")); connect(m_pCloseAction, SIGNAL(triggered()), this, SIGNAL(sigCloseAction())); addAction(m_pCloseAction); #ifdef VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR /* Right margin: */ m_spacings << widgetForAction(addWidget(new QWidget)); #endif /* VBOX_RUNTIME_UI_WITH_SHAPED_MINI_TOOLBAR */ /* Resize to sizehint: */ resize(sizeHint()); }
/* Mini-toolbar constructor */ VBoxMiniToolBar::VBoxMiniToolBar(QWidget *pParent, Alignment alignment, bool fActive, bool fAutoHide) : UIToolBar(pParent) , m_pAutoHideAction(0) , m_pDisplayLabel(0) , m_pMinimizeAction(0) , m_pRestoreAction(0) , m_pCloseAction(0) , m_fActive(fActive) , m_fPolished(false) , m_fSeamless(false) , m_fAutoHide(fAutoHide) , m_fSlideToScreen(true) , m_fHideAfterSlide(false) , m_iAutoHideCounter(0) , m_iPositionX(0) , m_iPositionY(0) , m_pInsertPosition(0) , m_alignment(alignment) , m_fAnimated(true) , m_iScrollDelay(10) , m_iAutoScrollDelay(100) , m_iAutoHideTotalCounter(10) { /* Check parent widget presence: */ AssertMsg(parentWidget(), ("Parent widget must be set!\n")); /* Toolbar options: */ setIconSize(QSize(16, 16)); setVisible(false); /* Add pushpin: */ m_pAutoHideAction = new QAction(this); m_pAutoHideAction->setIcon(UIIconPool::iconSet(":/pin_16px.png")); m_pAutoHideAction->setToolTip(tr("Always show the toolbar")); m_pAutoHideAction->setCheckable(true); m_pAutoHideAction->setChecked(!m_fAutoHide); connect(m_pAutoHideAction, SIGNAL(toggled(bool)), this, SLOT(togglePushpin(bool))); addAction(m_pAutoHideAction); /* Left menu margin: */ m_Spacings << widgetForAction(addWidget(new QWidget(this))); /* Right menu margin: */ m_pInsertPosition = addWidget(new QWidget(this)); m_Spacings << widgetForAction(m_pInsertPosition); /* Left label margin: */ m_LabelMargins << widgetForAction(addWidget(new QWidget(this))); /* Insert a label for VM Name: */ m_pDisplayLabel = new QLabel(this); m_pDisplayLabel->setAlignment(Qt::AlignCenter); addWidget(m_pDisplayLabel); /* Right label margin: */ m_LabelMargins << widgetForAction(addWidget(new QWidget(this))); /* Minimize action: */ m_pMinimizeAction = new QAction(this); m_pMinimizeAction->setIcon(UIIconPool::iconSet(":/minimize_16px.png")); m_pMinimizeAction->setToolTip(tr("Minimize Window")); connect(m_pMinimizeAction, SIGNAL(triggered()), this, SIGNAL(minimizeAction())); addAction(m_pMinimizeAction); /* Exit action: */ m_pRestoreAction = new QAction(this); m_pRestoreAction->setIcon(UIIconPool::iconSet(":/restore_16px.png")); m_pRestoreAction->setToolTip(tr("Exit Full Screen or Seamless Mode")); connect(m_pRestoreAction, SIGNAL(triggered()), this, SIGNAL(exitAction())); addAction(m_pRestoreAction); /* Close action: */ m_pCloseAction = new QAction(this); m_pCloseAction->setIcon(UIIconPool::iconSet(":/close_16px.png")); m_pCloseAction->setToolTip(tr("Close VM")); connect(m_pCloseAction, SIGNAL(triggered()), this, SIGNAL(closeAction())); addAction(m_pCloseAction); /* Event-filter for parent widget to control resize: */ pParent->installEventFilter(this); /* Enable mouse-tracking for this & children allowing to get mouse-move events: */ setMouseTrackingEnabled(m_fAutoHide); }
void LocalToolbar::addAction(QAction* a) { QToolBar::addAction(a); QToolButton* button = qobject_cast<QToolButton*>(widgetForAction(a)); button->setFixedSize(TOOLBAR_BUTTON_SIZE, TOOLBAR_BUTTON_SIZE); }