Ticket #44944: correct-PreferencesAndSysTray-Menu.patch
File correct-PreferencesAndSysTray-Menu.patch, 7.3 KB (added by RJVB (René Bertin), 10 years ago) |
---|
-
kdelibs-git/kdeui/actions/kaction.cpp
diff --git kdeui/actions/kaction.cpp kdeui/actions/kaction.cpp index 9e8f7fb..d09aeac 100644
KAction::KAction(QObject *parent) 142 142 d->init(this); 143 143 } 144 144 145 #ifdef Q_OS_MAC 146 147 #include <kaboutdata.h> 148 149 static void setTextWithCorrectMenuRole( KAction *action, const QString &text ) 150 { 151 // texts containing "config, options, setup, settings or preferences" will get PreferencesRole 152 // from Qt unless they have a role set. We prevent that, because KDE has its own way of 153 // defining a the application preferences menu ("Configure <appName>") which should go under the OS X Preferences menu. 154 // But when a KAction is created with the standard preferences title ("Configure <appName>..."), this action 155 // is set to PreferencesRole . 156 action->setText(text); 157 if( text.contains("config", Qt::CaseInsensitive) 158 || text.contains("options", Qt::CaseInsensitive) 159 || text.contains("setup", Qt::CaseInsensitive) 160 || text.contains("settings", Qt::CaseInsensitive) 161 || text.contains("preferences", Qt::CaseInsensitive) 162 ){ 163 const KAboutData *aboutData = KGlobal::mainComponent().aboutData(); 164 QString prefsText = i18n( "Configure %1...", (aboutData) ? aboutData->programName() : qApp->applicationName() ); 165 if( text == prefsText || text == "&" % prefsText ){ 166 kDebug() << "### Setting QAction::PreferencesRole from" << action->menuRole() << "for menuAction with text" << text; 167 action->setMenuRole(QAction::PreferencesRole); 168 } 169 else{ 170 kDebug() << "### Setting QAction::NoRole from" << action->menuRole() << "for menuAction with text" << text; 171 action->setMenuRole(QAction::NoRole); 172 } 173 } 174 } 175 #endif //Q_OS_MAC 176 145 177 KAction::KAction(const QString &text, QObject *parent) 146 178 : QWidgetAction(parent), d(new KActionPrivate) 147 179 { 148 180 d->init(this); 181 #ifdef Q_OS_MAC 182 setTextWithCorrectMenuRole(this, text); 183 #else 149 184 setText(text); 185 #endif 150 186 } 151 187 152 188 KAction::KAction(const KIcon &icon, const QString &text, QObject *parent) … … KAction::KAction(const KIcon &icon, const QString &text, QObject *parent) 154 190 { 155 191 d->init(this); 156 192 setIcon(icon); 193 #ifdef Q_OS_MAC 194 setTextWithCorrectMenuRole(this, text); 195 #else 157 196 setText(text); 197 #endif 158 198 } 159 199 160 200 KAction::~KAction() -
kdelibs-git/kdeui/actions/kstandardaction.cpp
diff --git kdeui/actions/kstandardaction.cpp kdeui/actions/kstandardaction.cpp index 7de0c6f..df61bff 100644
KAction *create(StandardAction id, const QObject *recvr, const char *slot, QObje 170 170 break; 171 171 } 172 172 173 // Set the text before setting the MenuRole, as on OS X setText will do some heuristic setting of itself, 174 // to prevent user menu items to get promoted to one of the following special roles. 175 pAction->setText(sLabel); 176 173 177 switch ( id ) { 174 178 case Quit: 175 179 pAction->setMenuRole(QAction::QuitRole); … … KAction *create(StandardAction id, const QObject *recvr, const char *slot, QObje 188 192 break; 189 193 } 190 194 191 pAction->setText(sLabel);192 195 if (pInfo->psToolTip) { 193 196 pAction->setToolTip(i18n(pInfo->psToolTip)); 194 197 } -
kdelibs-git/kdeui/notifications/kstatusnotifieritem.cpp
diff --git kdeui/notifications/kstatusnotifieritem.cpp kdeui/notifications/kstatusnotifieritem.cpp index 1b15d40..920ba27 100644
bool KStatusNotifierItemPrivate::checkVisibility(QPoint pos, bool perform) 683 683 684 684 return false; 685 685 } 686 #else 687 Q_UNUSED(pos); 688 Q_UNUSED(perform); 686 689 #endif 687 690 688 691 return true; … … KStatusNotifierItemPrivate::KStatusNotifierItemPrivate(KStatusNotifierItem *item 722 725 { 723 726 } 724 727 728 #ifdef Q_OS_MAC 729 # include <kconfiggroup.h> 730 #endif 731 725 732 void KStatusNotifierItemPrivate::init(const QString &extraId) 726 733 { 727 734 // Ensure that closing the last KMainWindow doesn't exit the application … … void KStatusNotifierItemPrivate::init(const QString &extraId) 745 752 746 753 //create a default menu, just like in KSystemtrayIcon 747 754 KMenu *m = new KMenu(associatedWidget); 755 #ifdef Q_OS_MAC 756 // emulate addTitle/setTitle by adding an inactive menu item. 757 titleAction = new QAction( KGlobal::mainComponent().aboutData()->programName(), NULL ); 758 titleAction->setEnabled(false); 759 titleAction->setIcon(qApp->windowIcon()); 760 titleAction->setIconVisibleInMenu(true); 761 m->addAction( titleAction ); 762 m->addSeparator(); 763 // qDebug() << "### Added SystemTray titleAction=" << titleAction; 764 // qDebug() << "### SystemTray for app" << qApp << "=" << KGlobal::mainComponent().aboutData()->programName() 765 // << "/" << KGlobal::caption() << "with icon" << qApp->windowIcon().name(); 766 #else 748 767 titleAction = m->addTitle(qApp->windowIcon(), KGlobal::caption()); 749 768 m->setTitle(KGlobal::mainComponent().aboutData()->programName()); 769 #endif 750 770 q->setContextMenu(m); 751 771 752 772 KStandardAction::quit(q, SLOT(maybeQuit()), actionCollection); -
kdelibs-git/kdeui/widgets/kmenu.cpp
diff --git kdeui/widgets/kmenu.cpp kdeui/widgets/kmenu.cpp index 7dab149..94a7751 100644
KMenu::~KMenu() 167 167 delete d; 168 168 } 169 169 170 #ifdef Q_OS_MAC 171 void KMenu::addAction(QAction *action) 172 { 173 if( action ){ 174 if( !action->isIconVisibleInMenu() ){ 175 action->setIcon(QIcon()); 176 } 177 QMenu::addAction(action); 178 } 179 } 180 181 # ifdef Q_NO_USING_KEYWORD 182 QAction *KMenu::addAction(const QString &text) 183 { 184 return QMenu::addAction(text); 185 } 186 187 QAction *KMenu::addAction(const QIcon &icon, const QString &text) 188 { 189 return QMenu::addAction(icon,text); 190 } 191 192 QAction *KMenu::addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut) 193 { 194 return QMenu::addAction(text, receiver, member, shortcut); 195 } 196 197 QAction *KMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut) 198 { 199 return QMenu::addAction(icon, text, receiver, member, shortcut); 200 } 201 # endif // Q_NO_USING_KEYWORD 202 #endif // Q_OS_MAC 203 170 204 QAction* KMenu::addTitle(const QString &text, QAction* before) 171 205 { 172 206 return addTitle(QIcon(), text, before); -
kdelibs-git/kdeui/widgets/kmenu.h
diff --git kdeui/widgets/kmenu.h kdeui/widgets/kmenu.h index f96e263..79be594 100644
public: 60 60 */ 61 61 ~KMenu(); 62 62 63 #ifdef Q_OS_MAC 64 # ifndef Q_NO_USING_KEYWORD 65 using QMenu::addAction; 66 # endif 67 /** 68 * Appends the action action to the menu's list of actions. 69 * Overloaded from QMenu to force Qt to honour action->isIconVisibleInMenu(). 70 */ 71 void addAction(QAction *action); 72 # ifdef Q_NO_USING_KEYWORD 73 QAction *addAction(const QString &text); 74 QAction *addAction(const QIcon &icon, const QString &text); 75 QAction *addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); 76 QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0); 77 # endif //Q_NO_USING_KEYWORD 78 #endif //Q_OS_MAC 63 79 /** 64 80 * Inserts a title item with no icon. 65 81 */