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 connect( qApp->desktop(), SIGNAL( resized( int )), SLOT( updateKMenubarSize()));
00074 slotReadConfig();
00075 }
00076
00077 KMenuBar::~KMenuBar()
00078 {
00079 delete d;
00080 }
00081
00082 void KMenuBar::setTopLevelMenu(bool top_level)
00083 {
00084 d->forcedTopLevel = top_level;
00085 setTopLevelMenuInternal( top_level );
00086 }
00087
00088 #if QT_VERSION < 0x030100
00089 namespace
00090 {
00091 class QWidgetHack
00092 : public QWidget
00093 {
00094 public:
00095 bool isFullScreen() { return isTopLevel() && topData()->fullscreen; }
00096 };
00097 }
00098 #endif
00099
00100 void KMenuBar::setTopLevelMenuInternal(bool top_level)
00101 {
00102 if (d->forcedTopLevel)
00103 top_level = true;
00104
00105 if( parentWidget()
00106 #if QT_VERSION >= 0x030100
00107 && parentWidget()->topLevelWidget()->isFullScreen()) {
00108 #else
00109 && static_cast<QWidgetHack*>(parentWidget()->topLevelWidget())->isFullScreen()) {
00110 #endif
00111 d->wasTopLevel = top_level;
00112 top_level = false;
00113 }
00114
00115 if ( isTopLevelMenu() == top_level )
00116 return;
00117 d->topLevel = top_level;
00118 if ( isTopLevelMenu() ) {
00119 bool wasVisible = !isHidden();
00120 d->frameStyle = frameStyle();
00121 removeEventFilter( topLevelWidget() );
00122 reparent( parentWidget(), WType_TopLevel | WType_Dialog | WStyle_NoBorder, QPoint(0,0), false );
00123 #ifndef Q_WS_QWS //FIXME
00124 KWin::setType( winId(), NET::TopMenu );
00125 #endif
00126 setFrameStyle( MenuBarPanel );
00127 installEventFilter( parentWidget()->topLevelWidget() );
00128 if ( wasVisible )
00129 show();
00130 } else {
00131 if ( parentWidget() ) {
00132 reparent( parentWidget(), QPoint(0,0), !isHidden());
00133 setBackgroundMode( PaletteButton );
00134 installEventFilter( topLevelWidget() );
00135 setFrameStyle( d->frameStyle );
00136 }
00137 }
00138 }
00139
00140 bool KMenuBar::isTopLevelMenu() const
00141 {
00142 return d->topLevel;
00143 }
00144
00145 void KMenuBar::show()
00146 {
00147
00148
00149 if ( d->topLevel && isVisible() )
00150 return;
00151
00152 QMenuBar::show();
00153 }
00154
00155 void KMenuBar::slotReadConfig()
00156 {
00157 KConfig *config = KGlobal::config();
00158 KConfigGroupSaver saver( config, "KDE" );
00159 setTopLevelMenuInternal( config->readBoolEntry( "macStyle", false ) );
00160 }
00161
00162 bool KMenuBar::eventFilter(QObject *obj, QEvent *ev)
00163 {
00164
00165 if ( d->topLevel ) {
00166 if ( ev->type() == QEvent::Resize )
00167 return FALSE;
00168 if ( parentWidget() && obj == parentWidget()->topLevelWidget() ) {
00169
00170 if ( ev->type() == QEvent::Accel || ev->type() == QEvent::AccelAvailable ) {
00171 if ( QApplication::sendEvent( topLevelWidget(), ev ) )
00172 return TRUE;
00173 }
00174
00175
00176
00177
00178 if ( ev->type() == QEvent::WindowActivate )
00179 raise();
00180 else if(ev->type() == QEvent::ShowFullScreen )
00181
00182 setTopLevelMenuInternal( d->topLevel );
00183 }
00184 } else {
00185 if( topLevelWidget() && obj == topLevelWidget()) {
00186 if( ev->type() == QEvent::ShowNormal )
00187 setTopLevelMenuInternal( d->wasTopLevel );
00188 }
00189 }
00190 return QMenuBar::eventFilter( obj, ev );
00191 }
00192
00193 void KMenuBar::showEvent( QShowEvent *e )
00194 {
00195 updateKMenubarSize();
00196 QMenuBar::showEvent(e);
00197 }
00198
00199 void KMenuBar::resizeEvent( QResizeEvent *e )
00200 {
00201 updateKMenubarSize();
00202 QMenuBar::resizeEvent(e);
00203 }
00204
00205 void KMenuBar::updateKMenubarSize()
00206 {
00207 if ( d->topLevel ) {
00208 KConfigGroup xineramaConfig(KGlobal::config(),"Xinerama");
00209 int screen = xineramaConfig.readNumEntry("MenubarScreen",
00210 QApplication::desktop()->screenNumber(QPoint(0,0)) );
00211 QRect area = QApplication::desktop()->screenGeometry(screen);
00212 QMenuBar::setGeometry(area.left(), area.top()-frameWidth()-2, area.width(), heightForWidth( area.width() ) );
00213 #ifndef Q_WS_QWS //FIXME
00214 int strut_height = height()-frameWidth()-2;
00215 if( strut_height < 0 )
00216 strut_height = 0;
00217 KWin::setStrut( winId(), 0, 0, strut_height, 0 );
00218 #endif
00219 }
00220 }
00221
00222 void KMenuBar::setGeometry( int x, int y, int w, int h )
00223 {
00224
00225
00226
00227 if ( !d->topLevel )
00228 QMenuBar::setGeometry(x,y,w,h);
00229 }
00230
00231 void KMenuBar::virtual_hook( int, void* )
00232 { }
00233
00234
00235
00236
00237 #include "kmenubar.moc"
This file is part of the documentation for kdelibs Version 3.1.4.