X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/23a4868deacf65edc4a0c6cec9dbd9b15f20e18a..fcef5f7721dbcb2fa5d672ff123edfed078c0006:/src/dolphincontextmenu.cpp diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp index 5f8b8cdeb..da76e56fe 100644 --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,8 @@ #include "views/dolphinview.h" #include "views/viewmodecontroller.h" +K_GLOBAL_STATIC(KModifierKeyInfo, m_keyInfo) + DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const KFileItem& fileInfo, const KUrl& baseUrl) : @@ -65,7 +68,6 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, m_customActions(), m_popup(new KMenu(m_mainWindow)), m_shiftPressed(false), - m_keyInfo(), m_removeAction(0) { // The context menu either accesses the URLs of the selected items @@ -74,13 +76,14 @@ DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, m_selectedUrls = view->selectedUrls(); m_selectedItems = view->selectedItems(); - if (m_keyInfo.isKeyPressed(Qt::Key_Shift) || m_keyInfo.isKeyLatched(Qt::Key_Shift)) { - m_shiftPressed = true; + if (m_keyInfo != 0) { + if (m_keyInfo->isKeyPressed(Qt::Key_Shift) || m_keyInfo->isKeyLatched(Qt::Key_Shift)) { + m_shiftPressed = true; + } + connect(m_keyInfo, SIGNAL(keyPressed(Qt::Key, bool)), + this, SLOT(slotKeyModifierPressed(Qt::Key, bool))); } - connect(&m_keyInfo, SIGNAL(keyPressed(Qt::Key, bool)), - this, SLOT(slotKeyModifierPressed(Qt::Key, bool))); - m_removeAction = new QAction(this); connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRemoveActionTriggered())); } @@ -123,6 +126,14 @@ void DolphinContextMenu::open() } } +void DolphinContextMenu::initializeModifierKeyInfo() +{ + // Access m_keyInfo, so that it gets instantiated by + // K_GLOBAL_STATIC + KModifierKeyInfo* keyInfo = m_keyInfo; + Q_UNUSED(keyInfo); +} + void DolphinContextMenu::slotKeyModifierPressed(Qt::Key key, bool pressed) { m_shiftPressed = (key == Qt::Key_Shift) && pressed; @@ -443,20 +454,12 @@ void DolphinContextMenu::addCustomActions() void DolphinContextMenu::updateRemoveAction() { - // Set the current size as fixed size so that the menu isn't flickering when pressing shift. - m_popup->setFixedSize(m_popup->size()); - const KActionCollection* collection = m_mainWindow->actionCollection(); const bool moveToTrash = capabilities().isLocal() && !m_shiftPressed; const QAction* action = moveToTrash ? collection->action("move_to_trash") : collection->action("delete"); m_removeAction->setText(action->text()); m_removeAction->setIcon(action->icon()); m_removeAction->setShortcuts(action->shortcuts()); - - // This sets the menu back to a dynamic size followed by a forced resize in case the - // newly made visible action has bigger text. - m_popup->setFixedSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); - m_popup->resize(m_popup->sizeHint()); } #include "dolphincontextmenu.moc"