| 1 | /*
|
|---|
| 2 | * psitoolbar.cpp - the Psi toolbar class
|
|---|
| 3 | * Copyright (C) 2003, 2004 Michail Pishchagin
|
|---|
| 4 | *
|
|---|
| 5 | * This program is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU General Public License
|
|---|
| 7 | * as published by the Free Software Foundation; either version 2
|
|---|
| 8 | * of the License, or (at your option) any later version.
|
|---|
| 9 | *
|
|---|
| 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.
|
|---|
| 14 | *
|
|---|
| 15 | * You should have received a copy of the GNU General Public License
|
|---|
| 16 | * along with this library; if not, write to the Free Software
|
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 18 | *
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #include "common.h"
|
|---|
| 22 | #include "psitoolbar.h"
|
|---|
| 23 | #include <qpopupmenu.h>
|
|---|
| 24 | #include <qlabel.h>
|
|---|
| 25 | #include <qaction.h>
|
|---|
| 26 | #include "psicon.h"
|
|---|
| 27 | #include "mainwin.h"
|
|---|
| 28 | #include "psicon.h"
|
|---|
| 29 | #include "iconaction.h"
|
|---|
| 30 | #include "options/toolbardlg.h"
|
|---|
| 31 |
|
|---|
| 32 | //----------------------------------------------------------------------------
|
|---|
| 33 | // PsiToolBar::Private
|
|---|
| 34 | //----------------------------------------------------------------------------
|
|---|
| 35 |
|
|---|
| 36 | class PsiToolBar::Private
|
|---|
| 37 | {
|
|---|
| 38 | public:
|
|---|
| 39 | Private();
|
|---|
| 40 |
|
|---|
| 41 | bool customizeable, moveable;
|
|---|
| 42 | PsiActionList::ActionsType type;
|
|---|
| 43 | QString group;
|
|---|
| 44 | int groupIndex;
|
|---|
| 45 | PsiCon *psi;
|
|---|
| 46 | QPtrList<IconAction> uniqueActions;
|
|---|
| 47 | };
|
|---|
| 48 |
|
|---|
| 49 | PsiToolBar::Private::Private()
|
|---|
| 50 | {
|
|---|
| 51 | customizeable = true;
|
|---|
| 52 | moveable = true;
|
|---|
| 53 | psi = 0;
|
|---|
| 54 | uniqueActions.setAutoDelete( true );
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | //----------------------------------------------------------------------------
|
|---|
| 58 | // PsiToolBar
|
|---|
| 59 | //----------------------------------------------------------------------------
|
|---|
| 60 |
|
|---|
| 61 | PsiToolBar::PsiToolBar(const QString &label, QMainWindow *mainWindow, QWidget *parent, bool newLine, const char *name, WFlags f)
|
|---|
| 62 | : QToolBar(label, mainWindow, parent, newLine, name, f)
|
|---|
| 63 | {
|
|---|
| 64 | d = new Private();
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | PsiToolBar::PsiToolBar(QMainWindow *parent, const char *name)
|
|---|
| 68 | : QToolBar(parent, name)
|
|---|
| 69 | {
|
|---|
| 70 | d = new Private();
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | PsiToolBar::~PsiToolBar()
|
|---|
| 74 | {
|
|---|
| 75 | delete d;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | bool PsiToolBar::isCustomizeable() const
|
|---|
| 79 | {
|
|---|
| 80 | return d->customizeable;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | void PsiToolBar::setCustomizeable( bool b )
|
|---|
| 84 | {
|
|---|
| 85 | d->customizeable = b;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | bool PsiToolBar::isMoveable() const
|
|---|
| 89 | {
|
|---|
| 90 | return d->moveable;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | void PsiToolBar::setMoveable( bool b )
|
|---|
| 94 | {
|
|---|
| 95 | d->moveable = b;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | void PsiToolBar::contextMenuEvent(QContextMenuEvent *e)
|
|---|
| 99 | {
|
|---|
| 100 | e->accept();
|
|---|
| 101 | if(option.lockdown.options)
|
|---|
| 102 | return;
|
|---|
| 103 |
|
|---|
| 104 | if ( !d->customizeable )
|
|---|
| 105 | return;
|
|---|
| 106 |
|
|---|
| 107 | MainWin *mainWin = (MainWin *)mainWindow();
|
|---|
| 108 | QPopupMenu pm;
|
|---|
| 109 |
|
|---|
| 110 | pm.insertItem(IconsetFactory::icon("psi/toolbars"), tr("Configure &Toolbar..."), 0);
|
|---|
| 111 |
|
|---|
| 112 | int ret = pm.exec( e->globalPos() );
|
|---|
| 113 |
|
|---|
| 114 | if ( ret == 0 ) {
|
|---|
| 115 | QWidget *w = mainWin->psiCon()->doToolbars();
|
|---|
| 116 | if ( !w->inherits("ToolbarDlg") )
|
|---|
| 117 | return;
|
|---|
| 118 |
|
|---|
| 119 | ToolbarDlg *dlg = (ToolbarDlg *)w;
|
|---|
| 120 | dlg->setCurrentToolbar(this);
|
|---|
| 121 | }
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | PsiActionList::ActionsType PsiToolBar::type() const
|
|---|
| 125 | {
|
|---|
| 126 | return d->type;
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | QString PsiToolBar::group() const
|
|---|
| 130 | {
|
|---|
| 131 | return d->group;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | int PsiToolBar::groupIndex() const
|
|---|
| 135 | {
|
|---|
| 136 | return d->groupIndex;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | void PsiToolBar::setGroup( QString group, int index )
|
|---|
| 140 | {
|
|---|
| 141 | d->group = group;
|
|---|
| 142 | d->groupIndex = index;
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | void PsiToolBar::setType( PsiActionList::ActionsType type )
|
|---|
| 146 | {
|
|---|
| 147 | d->type = PsiActionList::ActionsType( PsiActionList::ActionsType( type ) | PsiActionList::Actions_Common );
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | void PsiToolBar::initialize( Options::ToolbarPrefs &tbPref, bool createUniqueActions )
|
|---|
| 151 | {
|
|---|
| 152 | d->uniqueActions.clear();
|
|---|
| 153 |
|
|---|
| 154 | setHorizontallyStretchable( tbPref.stretchable );
|
|---|
| 155 | setVerticallyStretchable( tbPref.stretchable );
|
|---|
| 156 |
|
|---|
| 157 | setMovingEnabled ( !tbPref.locked );
|
|---|
| 158 |
|
|---|
| 159 | if ( d->psi ) {
|
|---|
| 160 | ActionList actions = d->psi->actionList()->suitableActions( d->type );
|
|---|
| 161 | QStringList keys = tbPref.keys;
|
|---|
| 162 | for (uint j = 0; j < keys.size(); j++) {
|
|---|
| 163 | IconAction *action = actions.action( keys[j] );
|
|---|
| 164 |
|
|---|
| 165 | if ( action ) {
|
|---|
| 166 | if ( createUniqueActions ) {
|
|---|
| 167 | action = action->copy();
|
|---|
| 168 | d->uniqueActions.append( action );
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | action->addTo( this );
|
|---|
| 172 | emit registerAction( action );
|
|---|
| 173 | }
|
|---|
| 174 | else
|
|---|
| 175 | qWarning("PsiToolBar::initialize(): action %s not found!", keys[j].latin1());
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 | else
|
|---|
| 179 | qWarning("PsiToolBar::initialize(): psi is NULL!");
|
|---|
| 180 |
|
|---|
| 181 | if ( tbPref.on )
|
|---|
| 182 | show();
|
|---|
| 183 | else
|
|---|
| 184 | hide();
|
|---|
| 185 |
|
|---|
| 186 | tbPref.dirty = false;
|
|---|
| 187 | }
|
|---|
| 188 |
|
|---|
| 189 | void PsiToolBar::setPsiCon( PsiCon *psi )
|
|---|
| 190 | {
|
|---|
| 191 | d->psi = psi;
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|