toolchooser.h

Go to the documentation of this file.
00001 /*  -*- c++ -*-  (for Emacs)
00002  *
00003  *  toolchooser.h
00004  *  Digest
00005  * 
00006  *  Created by Aidan Lane on Wed Aug 24 2005.
00007  *  Copyright (c) 2005 Optimisation and Constraint Solving Group,
00008  *  Monash University. All rights reserved.
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00023  */
00024 
00025 // TODO: break me up into separate header and impl files!
00026 
00027 #ifndef TOOLCHOOSER_H
00028 #define TOOLCHOOSER_H
00029 
00030 
00031 #include <QWidget>
00032 
00033 #include "digest.h"
00034 
00035 #include <QIcon>
00036 #include <QLabel>
00037 #include <QVBoxLayout>
00038 
00039 
00040 // TODO: remove the need for the following class!
00041 // Reduces the size of the tabs to fit the tab icons without leaving room for text
00042 #include <QTabBar> // TODO: remove me!
00043 class ToolTabBar : public QTabBar {
00044 public:
00045   ToolTabBar( QWidget* parent = 0 ) : QTabBar(parent) {}
00046 protected:
00047   QSize tabSizeHint( int index ) const {
00048     // TODO: remove the need for the following hack!
00049     return QSize( (index==count()-1)
00050                   ? 31
00051                   : 29, QTabBar::tabSizeHint(index).height()+2 ); // +2 -> VCentre icons
00052   }
00053 };
00054 
00055 // TODO: add options for showing text and so forth like for QActions in toolbars!
00056 class ToolChooser : public QWidget {
00057 
00058   Q_OBJECT
00059 
00060 public:
00061   ToolChooser( QWidget* parent = 0 ) : QWidget(parent)
00062   {
00063     QVBoxLayout* layout = new QVBoxLayout( this );
00064     layout->setMargin( 3 );
00065 
00066     tabBar = new ToolTabBar( this );
00067     tabBar->addTab( QIcon(":images/tools/SelectionTool.png"), QString() );
00068     tabBar->addTab( QIcon(":images/tools/ZoomTool.png"), QString() );
00069     tabBar->addTab( QIcon(":images/tools/ShapeTool.png"), QString() );
00070     tabBar->addTab( QIcon(":images/tools/PolygonTool.png"), QString() );
00071     tabBar->addTab( QIcon(":images/tools/PolylineTool.png"), QString() );
00072     tabBar->addTab( QIcon(":images/tools/TextTool.png"), QString() );
00073     layout->addWidget( tabBar );
00074 
00075     connect( tabBar,
00076              SIGNAL(currentChanged(int)), SLOT(onTabBarCurrentChanged(int)) );
00077 
00078 #if 0 // TODO: make the following optional
00079     QLabel* label = new QLabel( this );
00080     QFont f = label->font();
00081     f.setPointSize( 11 ); // TODO: get this from QStyle!!!
00082     label->setFont( f );
00083     label->setAlignment( Qt::AlignHCenter );
00084     label->setText( tr("Tool Mode") ); // same string as what "Preview" on Mac OS X uses
00085     layout->addWidget( label );
00086 #endif
00087   }
00088 
00089   Digest::Tool currentTool() const {
00090     Q_ASSERT( tabBar != 0 );
00091     return (Digest::Tool )tabBar->currentIndex();
00092   }
00093 
00094 
00095 signals:
00096   void currentToolChanged( Digest::Tool tool );
00097 
00098 
00099 public slots:
00100   void setCurrentTool( Digest::Tool tool ) {
00101     Q_ASSERT( tabBar != 0 );
00102     tabBar->setCurrentIndex( (int)tool );
00103   }
00104 
00105 
00106 private slots:
00107   void onTabBarCurrentChanged( int index ) {
00108     emit currentToolChanged( (Digest::Tool)index );
00109   }
00110 
00111 
00112 private:
00113   ToolTabBar* tabBar;
00114 };
00115 
00116 
00117 
00118 #endif  // ! TOOLCHOOSER_H

Generated on Mon Jul 30 09:46:50 2007 for Digest by  doxygen 1.5.2