lib/Toolbar.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  * 
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
00019  *  USA.
00020  */
00021 
00022 #include "Toolbar.h"
00023 #include <qtooltip.h>
00024 
00025 //Toolbar::Toolbar (QWidget *w, int h, int wi, bool f) : QFrame (w)
00026 Toolbar::Toolbar (QWidget *w, Bias b) : QFrame (w)
00027 {
00028 //  height = h;
00029 //  width = wi;
00030 //  pflag = f;
00031   bias = b;
00032   list.setAutoDelete(TRUE);
00033 /*  because it looks bad, cut out
00034   setFrameShape(Box);
00035   setFrameShadow(Sunken);
00036 // don't work, why ever ->  setFrameStyle(ToolBarPanel);
00037   setLineWidth(1);
00038 */
00039 
00040   QHBoxLayout *hbox = 0;
00041   QVBoxLayout *vbox = 0;
00042   
00043   if (bias == Vertical)
00044   {
00045 // seems to be obsolete
00046 //    setMinimumWidth(ToolBarBtn::btnMinWidth + 3);
00047 //    setMaximumWidth(ToolBarBtn::btnMaxWidth + 3);
00048     vbox = new QVBoxLayout(this);  
00049     vbox->setSpacing(0);
00050     vbox->setMargin(0);
00051     grid = new QGridLayout(vbox, 1, 1);  
00052   }
00053   else
00054   {
00055 //    setMinimumHeight(ToolBarBtn::btnMinHeight + 3);
00056 //    setMaximumHeight(ToolBarBtn::btnMaxHeight + 3);
00057     hbox = new QHBoxLayout(this);  
00058     hbox->setSpacing(0);
00059     hbox->setMargin(0);
00060     grid = new QGridLayout(hbox, 1, 1);  
00061   }
00062   
00063   grid->setSpacing(2); // space between each button
00064   grid->setMargin(4);  // ...the button row to its environment
00065   
00066   if (bias == Vertical)
00067     vbox->addStretch(1);
00068   else
00069     hbox->addStretch(1);
00070 }
00071 
00072 Toolbar::~Toolbar ()
00073 {
00074 }
00075 
00076 void Toolbar::addButton (QString &name, QPixmap pix, QString &tt)
00077 {
00078   ToolBarBtn *button = new ToolBarBtn (this);
00079   QToolTip::add(button, tt);
00080   button->setPixmap(pix);
00081 
00082   //button->setMaximumWidth(width);
00083   //button->setMaximumHeight(height);
00084   if (bias == Vertical)
00085     grid->addWidget(button, list.count(), 0);
00086   else
00087     grid->addWidget(button, 0, list.count());
00088   list.replace(name, button);
00089 }
00090 
00091 ToolBarBtn * Toolbar::getButton (QString &name)
00092 {
00093   return list[name];
00094 }
00095 
00096 void Toolbar::setButtonStatus (QString &name, bool d)
00097 {
00098   ToolBarBtn *button = list[name];
00099   if (button)
00100     button->setEnabled(d);
00101 }
00102 
00103 void Toolbar::addSeparator ()
00104 {
00105   QFrame *vline = new QFrame(this);
00106   vline->setFrameStyle(QFrame::VLine | QFrame::Sunken);
00107   if (bias == Vertical)
00108     grid->addWidget(vline, -1, 0);
00109   else
00110     grid->addWidget(vline, 0, -1);
00111 }
00112