CdbSymbolPathListEditor::CdbSymbolPathListEditor(QWidget *parent) : Utils::PathListEditor(parent) { //! Add Microsoft Symbol server connection QAction *action = insertAction(lastAddActionIndex() + 1, tr("Symbol Server..."), this, SLOT(addSymbolServer())); action->setToolTip(tr("Adds the Microsoft symbol server providing symbols for operating system libraries." "Requires specifying a local cache directory.")); action = insertAction(lastAddActionIndex() + 1, tr("Symbol Cache..."), this, SLOT(addSymbolCache())); action->setToolTip(tr("Uses a directory to cache symbols used by the debugger.")); }
void RecentFileMenu::addRecentFile( QString filename ) { if ( mRecentFiles.contains( filename ) ) { removeRecentFile( filename ); } while ( mRecentFiles.size() >= MAX_RECENT_FILES ) { removeRecentFile( mRecentFiles.last() ); } mRecentFiles.prepend( filename ); QAction* action = new QAction( filename, this ); action->setData( QVariant( filename ) ); QObject::connect( action, SIGNAL( triggered() ), this, SLOT( onRecentFileTriggered() ) ); mRecentActions.emplace( filename, action ); if ( mRecentFiles.size() == 1 ) { addAction( action ); } else { QString firstFile = mRecentFiles[ 1 ]; qDebug() << "Recent file" << firstFile; insertAction( mRecentActions[ firstFile ], action ); } }
void NewTabMenuManager::InsertActionWParent (QAction *act, QObject *pObj, bool sub) { const auto& tabClasses = qobject_cast<IHaveTabs*> (pObj)->GetTabClasses (); const auto& tcCount = std::count_if (tabClasses.begin (), tabClasses.end (), [] (const TabClassInfo& tc) { return tc.Features_ & TFOpenableByRequest; }); const auto ii = qobject_cast<IInfo*> (pObj); const auto& name = ii->GetName (); auto rootMenu = NewTabMenu_; if (sub || tcCount > 1) { bool menuFound = false; for (auto menuAct : rootMenu->actions ()) if (menuAct->menu () && menuAct->text () == name) { rootMenu = menuAct->menu (); menuFound = true; break; } if (!menuFound) { auto menu = new QMenu (name, rootMenu); menu->setIcon (ii->GetIcon ()); rootMenu->insertMenu (FindActionBefore (name, rootMenu), menu); rootMenu = menu; } } rootMenu->insertAction (FindActionBefore (act->text (), rootMenu), act); }
void TtoolBar::addAction(QAction* a) { #if defined(Q_OS_ANDROID) a->setVisible(true); // No tool bar under mobile, just ensure that action is visible #else insertAction(actions()[actions().count() - 2], a); #endif }
void MenuBar::dropEvent(QDropEvent *event) { const MimeDataObject *mimeData = qobject_cast<const MimeDataObject *>(event->mimeData()); QAction *aAction = qobject_cast<QAction *>(mimeData->object()); if (aAction && isEdited()) { if (activeAction()) if (activeAction()->menu()) activeAction()->menu()->close(); if (aAction->menu()) if (aAction->objectName() == "actionNewMenu") { Menu *menu = new Menu(aAction->text()); menu->setEdited(true); aAction = menu->menuAction(); } QAction *eAction = this->actionAt(event->pos()); QRect rect = actionGeometry(eAction); eAction = this->actionAt(QPoint(event->pos().x()+rect.width()/2, event->pos().y())); if (eAction) { if (aAction->isSeparator()) insertSeparator(eAction); else insertAction(eAction,aAction); } else { if (aAction->isSeparator()) addSeparator(); else addAction(aAction); } event->acceptProposedAction(); } }
/* * Used to update a node object in the database. If no corresponding node is found one will be created. * The node is identified by node_id in the struct. * Returns the nodes struct. */ void DBLayer::updateNode( Node * new_node ) { if( DBLayer::getNodeByHWID( new_node->hw_id ) != NULL ) { // Entry already exists. Perform an update. // Create a new transaction. It gets automatically destroyed at the end of this funtion. work updateAction( *conn, "Update Transaction" ); // Perform the update updateAction.exec( ( "UPDATE nodes SET node_id=" + updateAction.esc( to_string( new_node->node_id ) ) + " WHERE hardware_uid='" + updateAction.esc( new_node->hw_id ) + "'" ) ); updateAction.commit(); } else { // Entry does not exists. Perform an insert. // Create a new transaction. It gets automatically destroyed at the end of this funtion. work insertAction( *conn, "Insert Transaction" ); // Perform the insert insertAction.exec( "INSERT INTO nodes (hardware_uid) VALUES ('" + insertAction.esc( new_node->hw_id ) + "')" ); insertAction.commit(); // Update the new_node reference to include the new node_id new_node = DBLayer::getNodeByHWID( new_node->hw_id ); } }
/* * Updates a Filesystem in the database. It is identified by its the unique identifier. * If the corresponding Filesystem does not exist it will be created. */ void DBLayer::updateFilesystem( Filesystem * new_Filesystem ) { if( DBLayer::getFilesystemByUID( new_Filesystem->unique_id ) != NULL ) { // Entry already exists. Perform an update. // Create a new transaction. It gets automatically destroyed at the end of this funtion. work updateAction( *conn, "Update Transaction" ); // Perform the update updateAction.exec( "UPDATE Filesystems SET fs_id=" + updateAction.esc( to_string( new_Filesystem->Filesystem_id ) ) + "WHERE uid='" + updateAction.esc( new_Filesystem->unique_id ) + "'" ); updateAction.commit(); } else { // Entry does not exists. Perform an insert. // Create a new transaction. It gets automatically destroyed at the end of this funtion. work insertAction( *conn, "Insert Transaction" ); // Perform the insert insertAction.exec( "INSERT INTO Filesystems (uid) VALUES ('" + insertAction.esc( new_Filesystem->unique_id ) + "')" ); insertAction.commit(); // Update new_Filesystem reference to include the new fs_id new_Filesystem->Filesystem_id = DBLayer::getFilesystemByUID( new_Filesystem->unique_id )->Filesystem_id; } }
void WindowMenu::onAboutToShow() { QWidget* win = QApplication::activeWindow(); pMinimize_->setEnabled(win); pZoom_->setEnabled(win && win->maximumSize() != win->minimumSize()); pBringAllToFront_->setEnabled(win); for (int i = windows_.size() - 1; i >= 0; i--) { QAction* pAction = windows_[i]; removeAction(pAction); windows_.removeAt(i); pAction->deleteLater(); } QWidgetList topLevels = QApplication::topLevelWidgets(); for (int i = 0; i < topLevels.size(); i++) { QWidget* pWindow = topLevels.at(i); if (!pWindow->isVisible()) continue; QAction* pAction = new QAction(pWindow->windowTitle(), pWindow); pAction->setData(QVariant::fromValue(pWindow)); pAction->setCheckable(true); if (pWindow->isActiveWindow()) pAction->setChecked(true); insertAction(pWindowPlaceholder_, pAction); connect(pAction, SIGNAL(triggered()), this, SLOT(showWindow())); windows_.append(pAction); } }
/******************* FUNCTION *********************/ ProjectActionOld& ProjectActionOld::addSubBlock ( string loopDescr, string parameter,CMRProjectCodeTreeInsert location ) { ProjectActionOld * tmpBlock = new ProjectActionOld("cmrSubBlock",loopDescr); tmpBlock->eq = new CMRProjectEquation(parameter,"cmrIndice",parameter); insertAction(tmpBlock,location); return *tmpBlock; }
/*! Inserts a separator into the toolbar in front of the toolbar item associated with the \a before action. \sa addSeparator() */ QAction *QToolBar::insertSeparator(QAction *before) { QAction *action = new QAction(this); action->setSeparator(true); insertAction(before, action); return action; }
/*! Inserts the given \a widget in front of the toolbar item associated with the \a before action. Note: You should use QAction::setVisible() to change the visibility of the widget. Using QWidget::setVisible(), QWidget::show() and QWidget::hide() does not work. \sa addWidget() */ QAction *QToolBar::insertWidget(QAction *before, QWidget *widget) { QWidgetAction *action = new QWidgetAction(this); action->setDefaultWidget(widget); action->d_func()->autoCreated = true; insertAction(before, action); return action; }
CommandLinkButtonTaskMenu::CommandLinkButtonTaskMenu(QCommandLinkButton *button, QObject *parent) : ButtonTaskMenu(button, parent) { TaskMenuInlineEditor *descriptonEditor = new LinkDescriptionTaskMenuInlineEditor(button, this); QAction *descriptionAction = new QAction(tr("Change description..."), this); connect(descriptionAction, SIGNAL(triggered()), descriptonEditor, SLOT(editText())); insertAction(1, descriptionAction); }
// Add a button "Import from 'Path'" void PathListEditor::addEnvVariableImportAction(const QString &var) { if (!d->envVarMapper) { d->envVarMapper = new QSignalMapper(this); connect(d->envVarMapper, SIGNAL(mapped(QString)), this, SLOT(setPathListFromEnvVariable(QString))); } QAction *a = insertAction(lastAddActionIndex() + 1, tr("From \"%1\"").arg(var), d->envVarMapper, SLOT(map())); d->envVarMapper->setMapping(a, var); }
/******************* FUNCTION *********************/ CMRProjectEquation& ProjectActionOld::addEquation ( const string& latexName, const string& longName, const string& compute,CMRProjectCodeTreeInsert location ) { ProjectActionOld * tmpBlock = new ProjectActionOld("cmrEquation",latexName); CMRProjectEquation * tmp = tmpBlock->eq = new CMRProjectEquation(latexName,longName,compute); insertAction(tmpBlock,location); if (context.find(tmp->latexEntity) == NULL) addContextEntry(tmp,location); return *tmp; }
bool ActionListView::qt_emit( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->signalOffset() ) { case 0: insertAction(); break; case 1: insertActionGroup(); break; case 2: insertDropDownActionGroup(); break; case 3: deleteAction(); break; case 4: connectAction(); break; default: return QListView::qt_emit(_id,_o); } return TRUE; }
void KlipperPopup::rebuild( const QString& filter ) { if (actions().isEmpty()) { buildFromScratch(); } else { for ( int i=0; i<m_nHistoryItems; i++ ) { Q_ASSERT(TOP_HISTORY_ITEM_INDEX < actions().count()); removeAction(actions().at(TOP_HISTORY_ITEM_INDEX)); } } // We search case insensitive until one uppercased character appears in the search term Qt::CaseSensitivity caseSens = (filter.toLower() == filter ? Qt::CaseInsensitive : Qt::CaseSensitive); QRegExp filterexp( filter, caseSens ); QPalette palette = m_filterWidget->palette(); if ( filterexp.isValid() ) { palette.setColor( m_filterWidget->foregroundRole(), palette.color(foregroundRole()) ); } else { palette.setColor( m_filterWidget->foregroundRole(), Qt::red ); } m_nHistoryItems = m_popupProxy->buildParent( TOP_HISTORY_ITEM_INDEX, filterexp ); if ( m_nHistoryItems == 0 ) { if ( m_history->empty() ) { insertAction(actions().at(TOP_HISTORY_ITEM_INDEX), new QAction(m_textForEmptyHistory, this)); } else { palette.setColor( m_filterWidget->foregroundRole(), Qt::red ); insertAction(actions().at(TOP_HISTORY_ITEM_INDEX), new QAction(m_textForNoMatch, this)); } m_nHistoryItems++; } else { if ( history()->topIsUserSelected() ) { actions().at(TOP_HISTORY_ITEM_INDEX)->setCheckable(true); actions().at(TOP_HISTORY_ITEM_INDEX)->setChecked(true); } } m_filterWidget->setPalette( palette ); m_dirty = false; }
/* 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; }
bool pActionsModel::addAction( const QString& _path, QAction* action ) { Q_ASSERT( action ); if ( !action || !path( action ).isEmpty() || this->action( _path ) ) { return false; } const QString path = cleanPath( _path ); const QString subPath = path.section( QL1C( '/' ), 0, -2 ); QAction* parentAction = createCompletePathNode( subPath ); if ( !parentAction ) { return false; } const int row = children( parentAction ).count(); insertAction( path, action, parentAction, row ); return true; }
ActionEditor::ActionEditor( QWidget* parent, const char* name, WFlags fl ) : ActionEditorBase( parent, name, fl ), currentAction( 0 ), formWindow( 0 ), explicitlyClosed(false) { listActions->addColumn( i18n( "Actions" ) ); setEnabled( FALSE ); buttonConnect->setEnabled( FALSE ); QPopupMenu *popup = new QPopupMenu( this ); popup->insertItem( i18n( "New &Action" ), this, SLOT( newAction() ) ); popup->insertItem( i18n( "New Action &Group" ), this, SLOT( newActionGroup() ) ); popup->insertItem( i18n( "New &Dropdown Action Group" ), this, SLOT( newDropDownActionGroup() ) ); buttonNewAction->setPopup( popup ); buttonNewAction->setPopupDelay( 0 ); connect( listActions, SIGNAL( insertAction() ), this, SLOT( newAction() ) ); connect( listActions, SIGNAL( insertActionGroup() ), this, SLOT( newActionGroup() ) ); connect( listActions, SIGNAL( insertDropDownActionGroup() ), this, SLOT( newDropDownActionGroup() ) ); connect( listActions, SIGNAL( deleteAction() ), this, SLOT( deleteAction() ) ); connect( listActions, SIGNAL( connectAction() ), this, SLOT( connectionsClicked() ) ); }
PanelTabBar::PanelTabBar(QWidget *parent, TabActions *actions): QTabBar(parent), _maxTabLength(0), _tabClicked(false), _draggingTab(false) { _panelActionMenu = new KActionMenu(i18n("Panel"), this); setAcceptDrops(true); insertAction(actions->actNewTab); insertAction(actions->actLockTab); insertAction(actions->actDupTab); insertAction(actions->actMoveTabToOtherSide); insertAction(actions->actCloseTab); insertAction(actions->actCloseInactiveTabs); insertAction(actions->actCloseDuplicatedTabs); setMovable(true); // enable drag'n'drop setShape(QTabBar::TriangularSouth); }
QAction* KMenu::addTitle(const QIcon &icon, const QString &text, QAction* before) { QAction *buttonAction = new QAction(this); QFont font = buttonAction->font(); font.setBold(true); buttonAction->setFont(font); buttonAction->setText(text); buttonAction->setIcon(icon); QWidgetAction *action = new QWidgetAction(this); action->setObjectName(KMENU_TITLE); QToolButton *titleButton = new QToolButton(this); titleButton->installEventFilter(d); // prevent clicks on the title of the menu titleButton->setDefaultAction(buttonAction); titleButton->setDown(true); // prevent hover style changes in some styles titleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); action->setDefaultWidget(titleButton); insertAction(before, action); return action; }
// Adds an action item to history set for the current targeted Scintilla Document at the // next Scintilla action index. Useful when working with SC_MOD_BEFORE... notifications. bool DocumentActionHistory::insert_at_NextActionIndex( HistoryAction* action, int referenceIndex ) { int actionIndex = ( npp_plugin::actionindex::getCurrActionIndex( _currDoc ) + 1 ); if ( actionIndex == _prevActionIndex ) { _actionEntryID++; } else { _prevActionIndex = actionIndex; _actionEntryID = 0; } std::pair<ActionHistory_set::iterator, bool> retVal = insertAction( actionIndex, _actionEntryID, referenceIndex, action ); if (! retVal.second ) { ActionHistory dbgAH = *(retVal.first); bool dbgStop = true; } return ( retVal.second ); }
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; }
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()); }
void run() { switch (routes[action]) { case LOAD: loadAction(); break; case INSERT: insertAction(); break; case FIND: findAction(); break; case REMOVE: removeAction(); break; case CLEAR: clearAction(); break; case DELETE: deleteAction(); break; case SHOW: showAction(); break; case TEST: testAction(); break; case HELP: helpAction(); break; case REPORT: reportAction(); break; default: usageAction(); break; } }
/* * Used to update a StorageDevice. * The device is identified by its node_id and device_id in the struct. * If the corresponding device does not exist in the database it will be created. */ void DBLayer::updateStorageDevice( StorageDevice * new_StorageDevice ) { if( DBLayer::getStorageDeviceByNodeAndDevice( new_StorageDevice->node_id, new_StorageDevice->device_id ) != NULL ) { // Entry already exists. Perform an update. // Create a new transaction. It gets automatically destroyed at the end of this funtion. work updateAction( *conn, "Update Transaction" ); // Perform the update updateAction.exec( "UPDATE StorageDevices SET model_name='" + updateAction.esc( to_string( new_StorageDevice->model_name ) ) + "', local_address='" + updateAction.esc( to_string( new_StorageDevice->local_address ) ) + "' WHERE node_id=" + updateAction.esc( to_string( new_StorageDevice->node_id ) ) + " AND device_id=" + updateAction.esc( to_string( new_StorageDevice->device_id ) ) + "" ); updateAction.commit(); } else { // Entry does not exists. Perform an insert.nschen, die auf Code starren. Es sind Frauen anwe // Create a new transaction. It gets automatically destroyed at the end of this funtion. work insertAction( *conn, "Insert Transaction" ); // Perform the insert insertAction.exec( "INSERT INTO StorageDevices (model_name, local_address, node_id) VALUES ('" + insertAction.esc( to_string( new_StorageDevice->model_name ) ) + "', '" + insertAction.esc( to_string( new_StorageDevice->local_address ) ) + "', '" + insertAction.esc( to_string( new_StorageDevice->node_id ) ) + "')" ); insertAction.commit(); // Update new_StorageDevice unsigned int id = 0; work selectAction( *conn, "Select Transaction" ); result resultSelect = selectAction.exec( "SELECT device_id FROM StorageDevices WHERE model_name='" + insertAction.esc( to_string( new_StorageDevice->model_name ) ) + "' AND local_address = '" + insertAction.esc( to_string( new_StorageDevice->local_address ) ) + "' AND node_id = '" + insertAction.esc( to_string( new_StorageDevice->node_id ) ) + "'" ); selectAction.commit(); // Check if there is only one result if( resultSelect.size() == 1 ) { // Check if results are sane (and convert them) if( !resultSelect[0]["device_id"].to( id ) ) throw integretyError; } else { // Something went wrong //throw integretyError; } new_StorageDevice->device_id = id; } }
void ActionListView::rmbMenu( QListViewItem *i, const QPoint &p ) { QPopupMenu *popup = new QPopupMenu( this ); popup->insertItem( tr( "New &Action" ), 0 ); popup->insertItem( tr( "New Action &Group" ), 1 ); popup->insertItem( tr( "New &Dropdown Action Group" ), 2 ); if ( i ) { popup->insertSeparator(); popup->insertItem( tr( "&Connect Action..." ), 3 ); popup->insertSeparator(); popup->insertItem( tr( "Delete Action" ), 4 ); } int res = popup->exec( p ); if ( res == 0 ) emit insertAction(); else if ( res == 1 ) emit insertActionGroup(); else if ( res == 2 ) emit insertDropDownActionGroup(); else if ( res == 3 ) emit connectAction(); else if ( res == 4 ) emit deleteAction(); }
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 TtoolBar::addScoreActions(TscoreActions* scoreBut) { m_scoreActs = scoreBut; insertAction(startExamAct, m_scoreActs->mainAction()); }
void LauncherContextualMenu::insertActionBeforeTitle(QAction* action) { insertAction(m_titleAction, action); }