1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "graphicalui.h"
23 #include "actioncollection.h"
24 #include "contextmenuactionprovider.h"
30 # include <KWindowInfo>
31 # include <KWindowSystem>
34 QWidget *GraphicalUi::_mainWidget = 0;
35 QHash<QString, ActionCollection *> GraphicalUi::_actionCollections;
36 ContextMenuActionProvider *GraphicalUi::_contextMenuActionProvider = 0;
37 ToolBarActionProvider *GraphicalUi::_toolBarActionProvider = 0;
38 UiStyle *GraphicalUi::_uiStyle = 0;
39 bool GraphicalUi::_onAllDesktops = false;
41 GraphicalUi::GraphicalUi(QObject *parent) : AbstractUi(parent)
46 ActionCollection *GraphicalUi::actionCollection(const QString &category) {
47 if(_actionCollections.contains(category))
48 return _actionCollections.value(category);
49 ActionCollection *coll = new ActionCollection(_mainWidget);
51 coll->addAssociatedWidget(_mainWidget);
52 _actionCollections.insert(category, coll);
56 void GraphicalUi::setMainWidget(QWidget *widget) {
60 void GraphicalUi::setContextMenuActionProvider(ContextMenuActionProvider *provider) {
61 _contextMenuActionProvider = provider;
64 void GraphicalUi::setToolBarActionProvider(ToolBarActionProvider *provider) {
65 _toolBarActionProvider = provider;
68 void GraphicalUi::setUiStyle(UiStyle *style) {
72 void GraphicalUi::activateMainWidget() {
75 KWindowInfo info = KWindowSystem::windowInfo(mainWidget()->winId(), NET::WMDesktop | NET::WMFrameExtents);
77 KWindowSystem::setOnAllDesktops(mainWidget()->winId(), true);
79 KWindowSystem::setCurrentDesktop(info.desktop());
82 mainWidget()->move(info.frameGeometry().topLeft()); // avoid placement policies
84 mainWidget()->raise();
85 KWindowSystem::raiseWindow(mainWidget()->winId());
86 KWindowSystem::activateWindow(mainWidget()->winId());
89 KWindowSystem::raiseWindow(mainWidget()->winId());
90 KWindowSystem::forceActiveWindow(mainWidget()->winId());
96 // Bypass focus stealing prevention
97 QX11Info::setAppUserTime(QX11Info::appTime());
100 if(mainWidget()->windowState() & Qt::WindowMinimized) {
102 mainWidget()->setWindowState((mainWidget()->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
105 // this does not actually work on all platforms... and causes more evil than good
106 // mainWidget()->move(mainWidget()->frameGeometry().topLeft()); // avoid placement policies
107 mainWidget()->show();
108 mainWidget()->raise();
109 mainWidget()->activateWindow();
111 #endif /* HAVE_KDE */
114 void GraphicalUi::hideMainWidget() {
116 #if defined(HAVE_KDE) && defined(Q_WS_X11)
117 KWindowInfo info = KWindowSystem::windowInfo(mainWidget()->winId(), NET::WMDesktop | NET::WMFrameExtents);
118 _onAllDesktops = info.onAllDesktops();
121 mainWidget()->hide();