File indexing completed on 2024-04-14 14:32:05

0001 //
0002 // C++ Implementation: cbuttonlist
0003 //
0004 // Description: 
0005 //
0006 /*
0007 Copyright 2008-2011 Tomas Mecir <kmuddy@kmuddy.com>
0008 
0009 This program is free software; you can redistribute it and/or
0010 modify it under the terms of the GNU General Public License as
0011 published by the Free Software Foundation; either version 2 of 
0012 the License, or (at your option) any later version.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #include "cbuttonlist.h"
0024 
0025 #include "cbutton.h"
0026 #include "cbuttoneditor.h"
0027 #include "kmuddy.h"
0028 
0029 #include <ktoolbar.h>
0030 
0031 cButtonList::cButtonList () :
0032     cList ("buttons")
0033 {
0034   loaded = false;
0035 
0036   addStringProperty ("caption", "Caption of the button");
0037   addStringProperty ("command", "Command sent upon pressing/enabling the button.");
0038   addStringProperty ("command-released", "Command sent upon disabling the button.");
0039   addStringProperty ("icon", "Icon associated with the button.");
0040   addBoolProperty ("pushdown", "Use a push-down button.", false);
0041   // script
0042   addStringProperty ("script", "Script to execute");
0043   addStringProperty ("script-release", "Script to execute when released");
0044 }
0045 
0046 cButtonList::~cButtonList()
0047 {
0048 }
0049 
0050 cListObject *cButtonList::newObject ()
0051 {
0052   return new cButton (this);
0053 }
0054 
0055 cListEditor *cButtonList::editor (QWidget *parent)
0056 {
0057   return new cButtonEditor (parent);
0058 }
0059 
0060 void cButtonList::listLoaded ()
0061 {
0062   loaded = true;
0063   updateButtons ();
0064 }
0065 
0066 void cButtonList::updateButtons ()
0067 {
0068   if (!loaded) return;  // not loaded yet - nothing to do
0069   cActionManager *am = cActionManager::self();
0070   // nothing if our session isn't the active one
0071   if (am->activeSession() != session()) return;
0072   KToolBar *bar = KMuddy::self()->buttonBar();
0073 
0074   // hide any old buttons
0075   bar->clear ();
0076 
0077   // then update/show what has to be shown
0078   // doing it this way ensures that disabling a group hides all child elements
0079   traverse (BUTTON_UPDATE);
0080 
0081   // show or hide the buttonbar depending on whether it has any buttons
0082   bar->actions().empty() ? bar->hide() : bar->show();
0083 }
0084