kmenubar.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef INCLUDE_MENUITEM_DEF
00025 #define INCLUDE_MENUITEM_DEF
00026 #endif
00027
00028 #include <qevent.h>
00029 #include <qobjectlist.h>
00030 #include <qaccel.h>
00031
00032 #include <kconfig.h>
00033 #include <kglobalsettings.h>
00034 #include <kmenubar.h>
00035 #include <kapplication.h>
00036 #include <kwin.h>
00037 #include <kwinmodule.h>
00038 #include <kglobal.h>
00039
00040 #ifndef Q_WS_QWS
00041 #include <X11/Xlib.h>
00042 #include <X11/Xutil.h>
00043 #include <X11/Xatom.h>
00044 #endif
00045
00046
00047 class KMenuBar::KMenuBarPrivate
00048 {
00049 public:
00050 KMenuBarPrivate()
00051 {
00052 topLevel = false;
00053 forcedTopLevel = false;
00054 wasTopLevel = false;
00055 }
00056 bool forcedTopLevel;
00057 bool topLevel;
00058 int frameStyle;
00059 bool wasTopLevel;
00060 };
00061
00062 KMenuBar::KMenuBar(QWidget *parent, const char *name)
00063 : QMenuBar(parent, name)
00064 {
00065 d = new KMenuBarPrivate;
00066 d->frameStyle = frameStyle();
00067
00068 if ( kapp )
00069
00070 connect( kapp, SIGNAL(toolbarAppearanceChanged(int)),
00071 this, SLOT(slotReadConfig()));
00072
00073 slotReadConfig();
00074 }
00075
00076 KMenuBar::~KMenuBar()
00077 {
00078 delete d;
00079 }
00080
00081 void KMenuBar::setTopLevelMenu(bool top_level)
00082 {
00083 d->forcedTopLevel = top_level;
00084 setTopLevelMenuInternal( top_level );
00085 }
00086
00087 #if QT_VERSION < 0x030100
00088 namespace
00089 {
00090 class QWidgetHack
00091 : public QWidget
00092 {
00093 public:
00094 bool isFullScreen() { return isTopLevel() && topData()->fullscreen; }
00095 };
00096 }
00097 #endif
00098
00099 void KMenuBar::setTopLevelMenuInternal(bool top_level)
00100 {
00101 if (d->forcedTopLevel)
00102 top_level = true;
00103
00104 if( parentWidget()
00105 #if QT_VERSION >= 0x030100
00106 && parentWidget()->topLevelWidget()->isFullScreen()) {
00107 #else
00108 && static_cast<QWidgetHack*>(parentWidget()->topLevelWidget())->isFullScreen()) {
00109 #endif
00110 d->wasTopLevel = top_level;
00111 top_level = false;
00112 }
00113
00114 if ( isTopLevelMenu() == top_level )
00115 return;
00116 d->topLevel = top_level;
00117 if ( isTopLevelMenu() ) {
00118 bool wasVisible = !isHidden();
00119 d->frameStyle = frameStyle();
00120 removeEventFilter( topLevelWidget() );
00121 reparent( parentWidget(), WType_TopLevel | WType_Dialog | WStyle_NoBorder, QPoint(0,0), false );
00122 #ifndef Q_WS_QWS //FIXME
00123 KWin::setType( winId(), NET::TopMenu );
00124 #endif
00125 setFrameStyle( MenuBarPanel );
00126 installEventFilter( parentWidget()->topLevelWidget() );
00127 if ( wasVisible )
00128 show();
00129 } else {
00130 if ( parentWidget() ) {
00131 reparent( parentWidget(), QPoint(0,0), !isHidden());
00132 setBackgroundMode( PaletteButton );
00133 installEventFilter( topLevelWidget() );
00134 setFrameStyle( d->frameStyle );
00135 }
00136 }
00137 }
00138
00139 bool KMenuBar::isTopLevelMenu() const
00140 {
00141 return d->topLevel;
00142 }
00143
00144 void KMenuBar::show()
00145 {
00146
00147
00148 if ( d->topLevel && isVisible() )
00149 return;
00150
00151 QMenuBar::show();
00152 }
00153
00154 void KMenuBar::slotReadConfig()
00155 {
00156 KConfig *config = KGlobal::config();
00157 KConfigGroupSaver saver( config, "KDE" );
00158 setTopLevelMenuInternal( config->readBoolEntry( "macStyle", false ) );
00159 }
00160
00161 bool KMenuBar::eventFilter(QObject *obj, QEvent *ev)
00162 {
00163
00164 if ( d->topLevel ) {
00165 if ( ev->type() == QEvent::Resize )
00166 return FALSE;
00167 if ( parentWidget() && obj == parentWidget()->topLevelWidget() ) {
00168
00169 if ( ev->type() == QEvent::Accel || ev->type() == QEvent::AccelAvailable ) {
00170 if ( QApplication::sendEvent( topLevelWidget(), ev ) )
00171 return TRUE;
00172 }
00173
00174
00175
00176
00177 if ( ev->type() == QEvent::WindowActivate )
00178 raise();
00179 else if(ev->type() == QEvent::ShowFullScreen )
00180
00181 setTopLevelMenuInternal( d->topLevel );
00182 }
00183 } else {
00184 if( topLevelWidget() && obj == topLevelWidget()) {
00185 if( ev->type() == QEvent::ShowNormal )
00186 setTopLevelMenuInternal( d->wasTopLevel );
00187 }
00188 }
00189 return QMenuBar::eventFilter( obj, ev );
00190 }
00191
00192 void KMenuBar::showEvent( QShowEvent *e )
00193 {
00194 updateKMenubarSize();
00195 QMenuBar::showEvent(e);
00196 }
00197
00198 void KMenuBar::resizeEvent( QResizeEvent *e )
00199 {
00200 updateKMenubarSize();
00201 QMenuBar::resizeEvent(e);
00202 }
00203
00204 void KMenuBar::updateKMenubarSize()
00205 {
00206 if ( d->topLevel ) {
00207 KConfigGroup xineramaConfig(KGlobal::config(),"Xinerama");
00208 int screen = xineramaConfig.readNumEntry("MenubarScreen",
00209 QApplication::desktop()->screenNumber(QPoint(0,0)) );
00210 QRect area = QApplication::desktop()->screenGeometry(screen);
00211 QMenuBar::setGeometry(area.left(), area.top()-frameWidth()-2, area.width(), heightForWidth( area.width() ) );
00212 #ifndef Q_WS_QWS //FIXME
00213 int strut_height = height()-frameWidth()-2;
00214 if( strut_height < 0 )
00215 strut_height = 0;
00216 KWin::setStrut( winId(), 0, 0, strut_height, 0 );
00217 #endif
00218 }
00219 }
00220
00221 void KMenuBar::setGeometry( int x, int y, int w, int h )
00222 {
00223
00224
00225
00226 if ( !d->topLevel )
00227 QMenuBar::setGeometry(x,y,w,h);
00228 }
00229
00230 void KMenuBar::virtual_hook( int, void* )
00231 { }
00232
00233
00234
00235
00236 #include "kmenubar.moc"
This file is part of the documentation for kdelibs Version 3.1.0.