📄 ktoolbar.cpp
字号:
/* This file is part of the KDE libraries Copyright (C) 1997, 1998 Stephan Kulow (coolo@kde.org) (C) 1997, 1998 Mark Donohoe (donohoe@kde.org) (C) 1997, 1998 Sven Radej (radej@kde.org) (C) 1997, 1998 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.*/// $Id: ktoolbar.cpp,v 1.1 2003/09/08 19:42:11 jasonk Exp $// $Log: ktoolbar.cpp,v $// Revision 1.1 2003/09/08 19:42:11 jasonk// Addition of packages directory and associated files.//// Revision 1.1.1.1 2003/08/07 21:18:33 jasonk// Initial import of PIXIL into new cvs repository.//// Revision 1.1.1.1 2003/06/23 22:04:24 jasonk////// Revision 1.1.1.1 2000/07/07 16:11:00 jasonk// Initial import of ViewML//// Revision 1.96.4.2 1999/05/29 18:55:01 denis// Broken files repaired.// It looks like nothing has missed.//// Revision 1.96.4.1 1999/03/06 21:46:00 radej// sven: Flat/Unflat with LMB too. Arrows and animation to come.//// Revision 1.96 1999/01/18 10:57:11 kulow// .moc files are back in kdelibs. Built fine here using automake 1.3//// Revision 1.95 1999/01/15 09:31:30 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.94 1998/12/09 13:44:30 radej// sven: iconify() -> hide() even when floating. Commented out debug output.//// Revision 1.93 1998/12/02 16:08:26 radej// sven: hide toolbar items better when session management wants toolbar flat//// Revision 1.92 1998/11/21 19:27:19 radej// sven: doubleClicked signal for buttons.//// Revision 1.91 1998/11/18 01:00:02 radej// sven: set*BarPos(Flat) works now (I hope)//// Revision 1.90 1998/11/11 14:32:08 radej// sven: *Bars can be made flat by MMB (Like in Netscape, but this works)//// Revision 1.89 1998/11/10 14:12:46 radej// sven: windows-style handle smaller//// Revision 1.88 1998/11/09 17:58:34 radej// sven: Fix for IconText=3 (pixmap wider then text; kfm's wheel)//// Revision 1.87 1998/11/09 00:29:16 radej// sven: IconText 3 (text under pixmap)//// Revision 1.86 1998/11/06 16:48:20 radej// sven: nicer docking, some bugfixes//// Revision 1.85 1998/11/06 15:08:48 radej// sven: finished handles. Comments?//// Revision 1.84 1998/11/06 12:54:52 radej// sven: radioGroup is in. handle changed again (broken in vertical mode)//// Revision 1.83 1998/11/05 18:23:31 radej// sven: new look for *Bar handles (unfinished)//// Revision 1.82 1998/10/10 11:28:53 radej// sven: Fixed popup position (if too close to bottom of screen, pops above)//// Revision 1.81 1998/10/09 12:42:19 radej// sven: New: (un) highlight sugnals, Autorepeat buttons, button down when// pressed. kdetest/kwindowtest updated. This is Binary COMPATIBLE.//// Revision 1.80 1998/10/05 15:09:53 kulow// purify (and me) likes initialized members, so I choose one (like the compiler// would do :)//// Revision 1.79 1998/09/15 05:56:45 antlarr// I've added a setIconText function to change the state of a variable// in KToolBar//// Revision 1.78 1998/09/01 20:22:23 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.77 1998/08/30 21:04:33 radej// sven: Minor improvement for docking in KTM//// Revision 1.76 1998/08/09 17:49:28 radej// sven: fixed a bug - uninitialized toolbarHeight/Width - thanks to Harry Porten//// Revision 1.75 1998/08/09 14:01:17 radej// sven: reintroduced makeDisabledPixmap code, and dumped QIconSet. Fixed a bug// with paletteChange too.//// Revision 1.74 1998/08/06 15:39:01 radej// sven: Popups & delayedPopups. Uses QIconSet. Needs Qt-1.4x//// Revision 1.73 1998/07/29 12:48:29 ssk// Removed more warnings, possible portability problems and ANSI violations.//// Revision 1.72 1998/07/23 09:42:26 radej// sven: improved styles//// Revision 1.71 1998/06/18 13:41:42 radej// sven: fixed invisible disabled buttons (I already wanted to defend it as// a feature, like You don't have to see it, it's disabled!)//// Revision 1.70 1998/06/18 08:56:57 radej// sven: removed debug output.//// Revision 1.69 1998/06/17 12:58:30 radej// sven: Removed compiler warning.//// Revision 1.68 1998/06/16 17:20:46 radej// sven: Fixed Warnings when switching palettes (separators hav no pixmaps)//// Revision 1.67 1998/05/19 14:10:05 radej// Bugfixes: Unhighlighting a handle and catching the fast click//// Revision 1.66 1998/05/13 09:56:31 radej// Changelog order//// Revision 1.65 1998/05/12 10:47:31 radej// Fixed sizehint - returns more real width//// Revision 1.64 1998/05/07 23:12:30 radej// Fix for optional highlighting of handle//// Revision 1.63 1998/05/05 16:53:31 radej// This damned opaque moving...//// Revision 1.62 1998/05/04 16:38:19 radej// Bugfixes for moving + opaque moving//// Revision 1.60 1998/05/02 18:31:01 radej// Improved docking//// Revision 1.59 1998/04/28 09:17:28 radej// New moving and docking BINARY INCOMPATIBLE//// Revision 1.58 1998/04/27 19:22:41 ettrich// Matthias: the nifty feature that you can globally change the size of the// toolbars broke the nifty-as-well feature that a client can pass another// size than 26 to the toolbar磗 constructor.//// I hope I found a solution which allows both. If you pass an argument// to the constructor, than a new attribute fixed_size is set.//// Revision 1.57 1998/04/26 13:30:16 kulow// fixed typo//// Revision 1.56 1998/04/23 16:08:56 radej// Fixed a bug reported by Thomas Tanghus//// Revision 1.54 1998/04/21 20:37:03 radej// Added insertWidget and some reorganisation - BINARY INCOMPATIBLE//// Revision 1.53 1998/04/16 18:47:19 radej// Removed some debug text before beta4////-------------------------------------------------------------------------// OLD CHANGES:// Solved one-button problem and added handle-highlighting - sven 5.1.1998// Some fixes of yesterday fixes - sven 6.1. 1998// Fixing of fixes - one button, three buttons + separator,// Improved engine, no handles if not movable. - sven 22. 1. 1998.// Matthias - setting size of toolbar (bin incompat) 22.1.98// Merged sven's & Matthias' changes 23-25. 1.98// Fixed small KWM-close bug (reported by Coolo) sven 8.2.1998// boolett proofing by Marcin Dalecki 06.03.1998// BINARY INCOMPATIBLE CHANGES sven 19.3. 1998:// - optional icons+text, variable size with reading options from// from ~/.kderc// - Fixing of bug reported by Antonio Larrosa (Thanks!)// - Optional highlighting of buttons// - added sizeHint()// - sample (default) ~./kderc group for toolbar:// [Toolbar style]// IconText=0 0=icons, 1=icons+text// Highlighting=1 0=No, 1=yes// Size=26 height of one row in toolbar// Fixed white bg on disabled buttons in icontext mode and// positioning on signal appearanceChanged - sven 24.3.1998//-------------------------------------------------------------------------#include <qpainter.h>#include <qtooltip.h> #include <qdrawutil.h>#include <qpalette.h>#include <qbitmap.h>#include <qstring.h>#include <qframe.h>#include <qbutton.h>#include <qrect.h>//#include <qimage.h>#ifdef HAVE_CONFIG_H#include <config.h>#endif#include "ktoolbar.h"#include "klined.h"#include "kcombo.h"#include <ktopwidget.h>#include <klocale.h>#include <kapp.h>#include <kwm.h>#include <ktoolboxmgr.h>// Use enums instead of defines. We are C++ and NOT C !enum { CONTEXT_LEFT = 0, CONTEXT_RIGHT = 1, CONTEXT_TOP = 2, CONTEXT_BOTTOM = 3, CONTEXT_FLOAT = 4};// this should be adjustable (in faar future... )#define MIN_AUTOSIZE 150// delay im ms (microsoft seconds) before delayed popup pops up#define POPUP_DELAY 500static bool toggleFlatOnRelease = false;KToolBarItem::KToolBarItem (Item *_item, itemType _type, int _id, bool _myItem){ id = _id; right=false; autoSized=false; type=_type; item = _item; myItem = _myItem;}KToolBarItem::~KToolBarItem (){ // Delete this item if localy constructed if (myItem) delete item;}/*** A very important button which can be menuBarButton or toolBarButton ***/KToolBarButton::KToolBarButton( QWidget *parentWidget, const char *name ) : QButton( parentWidget , name){ resize(6,6); hide(); youreSeparator(); radio = false;}KToolBarButton::KToolBarButton( const QPixmap& pixmap, int _id, QWidget *_parent, const char *name, int item_size, const char *txt, bool _mb) : QButton( _parent, name ){ sep=false; delayPopup = false; parentWidget = (KToolBar *) _parent; raised = false; myPopup = 0L; radio = false; toolBarButton = !_mb; setFocusPolicy( NoFocus ); id = _id; if (txt) btext = txt; if ( ! pixmap.isNull() ) enabledPixmap = pixmap; else { // How about jumping to text mode if no pixmap? (sven) warning(klocale->translate("KToolBarButton: pixmap is empty, perhaps some missing file")); enabledPixmap.resize( item_size-4, item_size-4); } modeChange (); makeDisabledPixmap(); setPixmap(enabledPixmap); connect (parentWidget, SIGNAL( modechange() ), this, SLOT( modeChange() )); connect( this, SIGNAL( clicked() ), this, SLOT( ButtonClicked() ) ); connect(this, SIGNAL( pressed() ), this, SLOT( ButtonPressed() ) ); connect(this, SIGNAL( released() ), this, SLOT( ButtonReleased() ) ); installEventFilter(this);}void KToolBarButton::beToggle(bool flag){ setToggleButton(flag); if (flag == true) connect (this, SIGNAL(toggled(bool)), this, SLOT(ButtonToggled())); else disconnect (this, SIGNAL(toggled(bool)), this, SLOT(ButtonToggled()));}void KToolBarButton::on(bool flag){ if(isToggleButton() == true) setOn(flag); else { setDown(flag); leaveEvent((QEvent *) 0); } repaint();}void KToolBarButton::toggle(){ setOn(!isOn()); repaint();}void KToolBarButton::setText( const char *text){ btext = text; modeChange(); repaint (false);}void KToolBarButton::setPixmap( const QPixmap &pixmap ){ if ( ! pixmap.isNull() ) enabledPixmap = pixmap; else { warning(klocale->translate("KToolBarButton: pixmap is empty, perhaps some missing file")); enabledPixmap.resize(width()-4, height()-4); } QButton::setPixmap( enabledPixmap );}void KToolBarButton::setPopup (QPopupMenu *p){ myPopup = p; p->installEventFilter (this);}void KToolBarButton::setDelayedPopup (QPopupMenu *p){ delayPopup = true; delayTimer = new QTimer (this); connect (delayTimer, SIGNAL(timeout ()), this, SLOT(slotDelayTimeout())); setPopup(p);}void KToolBarButton::setEnabled( bool enabled ){ QButton::setPixmap( (enabled ? enabledPixmap : disabledPixmap) ); QButton::setEnabled( enabled );}void KToolBarButton::leaveEvent(QEvent *){ if (isToggleButton() == false) if( raised != false ) { raised = false; repaint(false); } if (delayPopup) delayTimer->stop(); emit highlighted (id, false);}void KToolBarButton::enterEvent(QEvent *){ if (highlight == 1) { if (isToggleButton() == false) if (isEnabled()) raised = true; repaint(false); } emit highlighted (id, true);}void KToolBarButton::setRadio (bool f){ /* if (f && !radio) // if was not and now is installEventFilter(this); else if (!f && radio) // if now isn't and was (man!) removeEventFilter(this); */ radio = f;}bool KToolBarButton::eventFilter (QObject *o, QEvent *ev){ // From Kai-Uwe Sattler <kus@iti.CS.Uni-Magdeburg.De> if ((KToolBarButton *)o == this && ev->type () == Event_MouseButtonDblClick) { //debug ("Doubleclick"); emit doubleClicked (id); return true; } if ((KToolBarButton *) o == this) if ((ev->type() == Event_MouseButtonPress || ev->type() == Event_MouseButtonRelease || ev->type() == Event_MouseButtonDblClick) && radio && isOn()) return true; if ((QPopupMenu *) o != myPopup) return false; // just in case switch (ev->type()) { case Event_MouseButtonDblClick: case Event_MouseButtonPress: //debug ("Got press | doubleclick"); // If I get this, it means that popup is visible { QRect r(geometry()); r.moveTopLeft(parentWidget->mapToGlobal(pos())); if (r.contains(QCursor::pos())) // on button return true; // ignore } break; case Event_MouseButtonRelease: //debug ("Got release"); if (!myPopup->geometry().contains(QCursor::pos())) // not in menu... { QRect r(geometry()); r.moveTopLeft(parentWidget->mapToGlobal(pos())); if (r.contains(QCursor::pos())) // but on button { myPopup->setActiveItem(0 /*myPopup->idAt(1)*/); // set first active return true; // ignore release } } break; case Event_Hide: //debug ("Got hide"); on(false); return false; break; } return false;}void KToolBarButton::drawButton( QPainter *_painter ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -