📄 kmenubar.cpp
字号:
/* Copyright (C) 1997, 1998 Sven Radej (sven@lisa.exp.univie.ac.at) Copyright (C) 1997 Matthias Ettrich (ettrich@kde.org) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/#include <qpainter.h>#include <qdrawutil.h>#include <qpalette.h>#include <qstring.h>#include <qframe.h>#include "qobjectlist.h"#include "ktopwidget.h"#include "kmenubar.h"#include <klocale.h>#include <kapp.h>#include <kwm.h>#include <ktoolboxmgr.h>#include <kwm.h>#define CONTEXT_TOP 1#define CONTEXT_BOTTOM 2#define CONTEXT_FLOAT 3// $Id: kmenubar.cpp,v 1.1 2003/09/08 19:42:09 jasonk Exp $// $Log: kmenubar.cpp,v $// Revision 1.1 2003/09/08 19:42:09 jasonk// Addition of packages directory and associated files.//// Revision 1.1.1.1 2003/08/07 21:18:32 jasonk// Initial import of PIXIL into new cvs repository.//// Revision 1.1.1.1 2003/06/23 22:04:23 jasonk////// Revision 1.1.1.1 2000/07/07 16:11:00 jasonk// Initial import of ViewML//// Revision 1.63.2.3 1999/06/02 09:21:02 radej// sven: From 1.1.1. release due to corruption//// Revision 1.63.2.2 1999/03/24 16:48:56 ettrich// workaround for qt-1.44 behaviour//// Revision 1.63.2.1 1999/03/06 21:45:58 radej// sven: Flat/Unflat with LMB too. Arrows and animation to come.//// Revision 1.63 1999/02/05 19:16:54 ettrich// fixed mac-style toggling for applications with multiple toplevel windows//// Revision 1.62 1999/01/18 10:56:49 kulow// .moc files are back in kdelibs. Built fine here using automake 1.3//// Revision 1.61 1999/01/15 09:31:08 kulow// it's official - kdelibs builds with srcdir != builddir. For this I// automocifized it, the generated rules are easier to maintain than// selfwritten rules. I have to fight with some bugs of this tool, but// generally it's better than keeping them updated by hand.//// Revision 1.60 1998/12/16 01:42:21 ettrich// last fix for today//// Revision 1.59 1998/12/16 01:40:22 ettrich// yet another bugfix (don't worry, didn't effect any yet-existing program)//// Revision 1.58 1998/12/16 01:27:12 ettrich// fixed slightly broken macstyle removal//// Revision 1.57 1998/12/16 00:01:38 ettrich// small fix for menubars//// Revision 1.56 1998/12/09 14:11:58 radej// sven: Bad geometry (vanishing last item) fixed. Debug output commented out.//// Revision 1.55 1998/12/07 21:47:26 tibirna// Endorsed by: Sven Radej <sven@kde.org>//// CT: 1) ~/.kderc#[Menubar]\TopOfScreen=yes|no// becomes ~/.kderc#[KDE]\macStyle=on|off// 2) GUI config for the macStyle// 3) krootwm supports "hot" switching of macStyle (still small problems,// a restart of krootwm fixes them)//// Revision 1.54 1998/12/02 16:22:21 radej// sven: Flat menubar looks like flat toolbars in Motif style//// Revision 1.53 1998/11/23 18:32:04 radej// sven: MACmode: runtime change works,//// Revision 1.52 1998/11/23 15:34:04 radej// sven: Nicer sysmenu button//// Revision 1.51 1998/11/23 11:57:17 radej// sven: Mac: Force show, if on top y= -2, take icon in showEvent.// Still doesn't gets hidden when it's window loses focus.// ToolBar does.//// Revision 1.50 1998/11/23 09:57:49 ettrich// small improvement, hope Sven likes it//// Revision 1.49 1998/11/23 00:12:27 radej// sven: MACMenu: doesn't show if app doesn't want it to (kvt) + icon size fix//// Revision 1.48 1998/11/22 13:35:46 radej// sven: IMPROVED Mac menubar: Accelerators, SystemMenu, look...//// Revision 1.47 1998/11/21 20:28:39 ettrich// yet another small fix//// Revision 1.46 1998/11/21 20:25:41 ettrich// small fix//// Revision 1.45 1998/11/18 01:00:03 radej// sven: set*BarPos(Flat) works now (I hope)//// Revision 1.44 1998/11/11 14:32:10 radej// sven: *Bars can be made flat by MMB (Like in Netscape, but this works)//// Revision 1.43 1998/11/10 14:12:47 radej// sven: windows-style handle smaller//// Revision 1.42 1998/11/07 22:39:13 radej// sven: Fixed QAccel too (unrepaired what repairEventFilter messed)//// Revision 1.41 1998/11/07 17:13:57 radej// sven: Fixed KAccel, for now//// Revision 1.40 1998/11/06 17:59:55 radej// sven: fixed dynamic style change (QMenuBar is buggy)//// Revision 1.39 1998/11/06 16:48:21 radej// sven: nicer docking, some bugfixes//// Revision 1.38 1998/11/06 15:08:49 radej// sven: finished handles. Comments?//// Revision 1.37 1998/11/06 12:55:53 radej// sven: handle changed again (still not perfect)//// Revision 1.36 1998/11/05 18:23:32 radej// sven: new look for *Bar handles (unfinished)//// Revision 1.35 1998/10/05 15:09:52 kulow// purify (and me) likes initialized members, so I choose one (like the compiler// would do :)//// Revision 1.34 1998/09/07 18:44:29 ettrich// Matthias: preparation for new features//// Revision 1.33 1998/09/07 13:46:58 ettrich// Matthias: removed some debug output...//// Revision 1.32 1998/09/07 13:45:19 ettrich// Matthias: removed old qt-1.2 compatibility hack//// Revision 1.31 1998/09/01 20:22:03 kulow// I renamed all old qt header files to the new versions. I think, this looks// nicer (and gives the change in configure a sense :)//// Revision 1.30 1998/08/31 00:52:11 torben// Torben: One new function and made others virtual// => binary incompatible. Sorry. Please use virtual whenever it is// not a performance problem.//// Revision 1.29 1998/07/23 09:43:38 radej// sven: Improved look under diff styles. Winlook is beetter now.//// Revision 1.28 1998/06/18 08:58:14 radej// sven: removed debug output//// Revision 1.27 1998/05/28 21:49:39 kulow// I thought, a little sync between my different acinclude.m4.ins. I've done much// to much to know, which version is where ;)//// Revision 1.26 1998/05/19 14:10:23 radej// Bugfixes: Unhighlighting a handle and catching the fast click//// Revision 1.25 1998/05/07 23:13:09 radej// Moving with KToolBoxManager//// This file was corrupted in KDE_1_1_BRANCHstatic bool standalone_menubar = FALSE;static bool toggleFlatOnRelease = false;static QPixmap* miniGo = 0;_menuBar::_menuBar (QWidget *parent, const char *name) : QMenuBar (parent, name){ // Menubar is raised in motif style //setFrameStyle(NoFrame); //MD (17-9-97) setLineWidth(1); }_menuBar::~_menuBar () { }// workaround for qt-1.44's slightly changed menu bar handlingvoid _menuBar::resizeEvent( QResizeEvent* e){ static bool inHere = FALSE; if (inHere) return; inHere = TRUE; QMenuBar::resizeEvent( e ); inHere = FALSE; // ignore;}/*************************************************************/KMenuBar::KMenuBar(QWidget *parent, const char *name) : QFrame( parent, name ){ Parent = parent; // our father title = 0; oldWFlags = getWFlags(); standalone_menubar = FALSE; frame = new QFrame (this); frame->setFrameStyle(NoFrame); menu = new _menuBar (frame); oldMenuFrameStyle = menu->frameStyle(); connect (menu, SIGNAL(activated(int)), this, SLOT(slotActivated(int))); connect (menu, SIGNAL(highlighted(int)), this, SLOT(slotHighlighted(int))); handle = new QFrame (this); handle->setMouseTracking( TRUE ); handle->setFrameStyle(NoFrame); handle->installEventFilter(this); handle->show(); handle->raise(); init();}int KMenuBar::idAt( int index ){ return menu->idAt( index );}int KMenuBar::heightForWidth ( int max_width ) const{ return menu->heightForWidth( max_width - 9);}void KMenuBar::resizeEvent (QResizeEvent *){ if (position == Flat) return; int hwidth = 9; if (standalone_menubar) hwidth = 20; frame->setGeometry(hwidth , 0, width()-hwidth, menu->heightForWidth(width()-hwidth)); menu->resize(frame->width(), frame->height()); handle->setGeometry(0,0,hwidth,height()); if (height() != heightForWidth(width())) { resize(width(), heightForWidth(width())); return; }}void KMenuBar::ContextCallback( int ){ int i; i = context->exec(); switch (i) { case CONTEXT_TOP: setMenuBarPos( Top ); break; case CONTEXT_BOTTOM: setMenuBarPos( Bottom ); break; case CONTEXT_FLOAT: if (position == Floating || position == FloatingSystem){ setMenuBarPos (lastPosition); } else { setMenuBarPos( Floating ); move(QCursor::pos()); show(); } break; } handle->repaint (false);}void KMenuBar::init(){ context = new QPopupMenu( 0, "context" ); context->insertItem( klocale->translate("Top"), CONTEXT_TOP ); context->insertItem( klocale->translate("Bottom"), CONTEXT_BOTTOM ); context->insertItem( klocale->translate("Floating"), CONTEXT_FLOAT ); position = Top; moving = TRUE; highlight = false; transparent = false; setLineWidth( 0 ); resize( Parent->width(), menu->height()); enableFloating (TRUE); connect (kapp, SIGNAL(appearanceChanged()), this, SLOT(slotReadConfig())); slotReadConfig(); mgr =0;}KMenuBar::~KMenuBar(){ if (!QApplication::closingDown()) delete context;}void KMenuBar::mousePressEvent ( QMouseEvent *e ){ QApplication::sendEvent(menu, e);}void KMenuBar::slotReadConfig (){ int _highlight; bool _transparent; KConfig *config = kapp->getConfig(); QString group = config->group(); config->setGroup("Toolbar style"); _highlight =config->readNumEntry("Highlighting", 1); _transparent = config->readBoolEntry("TransparentMoving", true); if (_highlight != highlight) highlight = _highlight; if (_transparent != transparent) transparent= _transparent; if (style() == MotifStyle) { menu->setStyle(style()); //Uh! menu->setMouseTracking(false); if (position != Floating || position == FloatingSystem) menu->setFrameStyle(Panel | Raised); } else { menu->setStyle(style()); //Uh! menu->setMouseTracking(true); if (position != Floating && position != FloatingSystem) menu->setFrameStyle(NoFrame); } config->setGroup("KDE");//CT as Sven asked bool macmode = false; if (config->readEntry("macStyle") == "on") //CT as Sven asked macmode = true; if ( menuBarPos() != FloatingSystem && macmode) //was not and now is { standalone_menubar = TRUE; if (Parent->isVisible()) setMenuBarPos( FloatingSystem ); else { Parent->installEventFilter(this); // to show menubar } } else if (menuBarPos() == FloatingSystem && !macmode) //was and now is not { standalone_menubar = FALSE; setMenuBarPos (lastPosition); } //else if was and now is - nothing; //else if was not and now is not - nothing; config->setGroup(group);}void KMenuBar::slotHotSpot (int hs){ if (mgr == 0) return; if (!transparent) // opaque { switch (hs) { case 0: //top setMenuBarPos(Top); break; case 1: //bottom setMenuBarPos(Bottom); break; case -1: // left all setMenuBarPos(Floating); break; } if (position != Floating) { QPoint p(Parent->mapToGlobal(pos())); // OH GOOOOODDDD!!!!! mgr->setGeometry(p.x(), p.y(), width(), height()); } if (!isVisible()) show(); } else // transparent { switch (hs) { case 0: //top mgr->setGeometry(0); movePosition=Top; break; case 1: //bottom mgr->setGeometry(1); movePosition=Bottom; break; case -1: // left all mgr->setGeometry(mgr->mouseX(), mgr->mouseY(), width(), height()); movePosition=Floating; break; } }}void KMenuBar::paintEvent(QPaintEvent *){ //QApplication::sendEvent(menu, e); menu->repaint();}void KMenuBar::closeEvent (QCloseEvent *e){ if (position == Floating) { position = lastPosition; recreate (Parent, oldWFlags, QPoint (oldX, oldY), TRUE); context->changeItem (klocale->translate("Float"), CONTEXT_FLOAT); emit moved (position); e->ignore(); return; } e->accept();}void KMenuBar::leaveEvent (QEvent *e){ QApplication::sendEvent(menu, e);}bool KMenuBar::eventFilter(QObject *ob, QEvent *ev){ if (ob == Parent && ev->type() == Event_Show && standalone_menubar)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -