Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Examples  

timinghandler.h

Go to the documentation of this file.
00001 
00002 //
00003 // YASA timing handler declarations
00004 //
00005 // Project: Yasa 2
00006 // Author : Jan Blumenthal
00007 // Start  : 2002/02/28
00008 // $Header: /sources/yasa/yasagui/timinghandler.h,v 1.4 2003/01/24 15:47:43 bj Exp $
00009 //
00011 //
00012 // This program is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU General Public License as published by
00014 // the Free Software Foundation; either version 2 of the License, or
00015 // (at your option) any later version.
00016 //
00017 // This program is distributed in the hope that it will be useful,
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU General Public License
00023 // along with this program (See the included file COPYING);
00024 // if not, write to the Free Software Foundation, Inc.,
00025 // 675 Mass Ave, Cambridge, MA 02139, USA.
00026 //
00028 #ifndef YASAGUI_TIMING_HANDLER_INCLUDE
00029 #define YASAGUI_TIMING_HANDLER_INCLUDE
00030 
00031 
00033 #include <qscrollview.h>
00034 #include <qsplitter.h>
00035 #include "timingsettings.h"
00036 #include "timingpainter.h"
00037 #include "settings.h"
00038 #include "resulthandler.h"
00039 
00041 class YTimings;
00042 class YTimingHandler;
00043 
00044 
00048 class YTimingInfo
00049 {   
00050     QPoint              position;
00052     YTimings            *timings;
00053 public:                 YTimingInfo() : timings(0)
00054                         {}
00055                         ~YTimingInfo();
00056     YTimings *          GetTimings()                                {   return timings;             }
00057     const QPoint &      GetPosition() const                         {   return position;            }
00058     void                SetTimings(YTimings *t)                     {   timings=t;                  }
00059     void                SetPosition(const QPoint &p)                {   position=p;                 }
00060 };
00061 
00064 class YTimingScrollView : public QScrollView
00065 {   Q_OBJECT
00066     YTimingHandler      *timinghandler;
00067 protected:
00068     QSize               size;                                       // current max. size of widgets, depends on inserted widgets
00069 public:                 YTimingScrollView(QWidget *parent) : QScrollView(parent), timinghandler(0)
00070                         {
00071                             setResizePolicy(QScrollView::AutoOneFit);
00072                         }
00073     void                SetTimingHandler(YTimingHandler *th)        {   timinghandler=th;               }
00074     YTimingHandler*     GetTimingHandler() const                    {   return timinghandler;           }
00075     virtual void        Resize()                                    {                                   }
00076     const QSize &       GetSize() const                             {   return size;                    }
00077 protected:
00078     virtual void        drawContents(QPainter* p, int cx, int cy, int cw, int ch)=0;
00079 public slots:
00080     virtual void        NewTimingInserted(YTimingInfo *ti)=0;
00081     virtual void        ViewScrolled(int posx, int posy);
00082 };
00083 
00084 
00087 class YTimingDiagramScrollView : public YTimingScrollView
00088 {   Q_OBJECT
00089     QPoint              currentmousepos;
00091     bool                leftbuttonpressed;
00093     QPoint              leftbuttonpos;
00094 public:                 YTimingDiagramScrollView(QWidget *parent) : YTimingScrollView(parent),
00095                         leftbuttonpressed(false)
00096                         {
00097                             QCursor     *cursor;
00098                             setHScrollBarMode( QScrollView::AlwaysOn );
00099                             if ( ! YApplicationFigures::CreateCursor(&cursor, YApplicationFigures::POINTER_HAND) && cursor )
00100                             {
00101                                 setCursor( *cursor );
00102                             }
00103                             setFocusPolicy( QWidget::WheelFocus );
00104                             setFocus();
00105 //                          setMouseTracking(true);
00106                         }
00107     virtual void        Resize();
00108 protected:
00109     virtual void        keyPressEvent(QKeyEvent *event );
00110     virtual void        drawContents(QPainter* p, int cx, int cy, int cw, int ch);
00111     virtual void        contentsMousePressEvent ( QMouseEvent *event )
00112                         {
00113                             QCursor     *cursor;
00114                             setFocus();
00115                             if ( event->button() == Qt::LeftButton )
00116                             {
00117                                 leftbuttonpressed=true;
00118                                 leftbuttonpos=event->globalPos();
00119                                 if ( ! YApplicationFigures::CreateCursor(&cursor, YApplicationFigures::POINTER_HAND_PUSHED) && cursor )
00120                                 {
00121                                     setCursor( *cursor );
00122                                 }
00123                             }
00124                         }
00125     virtual void        contentsMouseReleaseEvent ( QMouseEvent *event )
00126                         {
00127                             if ( event->button() == Qt::LeftButton )
00128                             {
00129                                 QCursor         *cursor;
00130                                 leftbuttonpressed=false;
00131                                 if ( ! YApplicationFigures::CreateCursor(&cursor, YApplicationFigures::POINTER_HAND) && cursor )
00132                                 {
00133                                     setCursor( *cursor );
00134                                 }
00135                             }
00136                         }
00137     virtual void        contentsMouseMoveEvent( QMouseEvent *event )
00138                         {
00139                         //  currentmousepos=event->pos();
00140                             if ( leftbuttonpressed )
00141                             {
00142                                 scrollBy( leftbuttonpos.x()-event->globalX(), leftbuttonpos.y()-event->globalY() );
00143                                 leftbuttonpos = event->globalPos();
00144                             }
00145 
00146                         }
00147 public slots:
00148     virtual void        NewTimingInserted(YTimingInfo *ti);
00149 };
00150 
00153 class YTimingNameScrollView : public YTimingScrollView
00154 {   Q_OBJECT
00155 public:                 YTimingNameScrollView(QWidget *parent) : YTimingScrollView(parent)
00156                         {
00157                             setVScrollBarMode( QScrollView::AlwaysOff );
00158                             setHScrollBarMode( QScrollView::AlwaysOn );
00159                         }
00160 protected:
00161     virtual void        drawContents(QPainter* p, int cx, int cy, int cw, int ch);
00162 public slots:
00163     virtual void        NewTimingInserted(YTimingInfo *ti);
00164 };
00165 
00166 
00170 class YTimingHandler : public YResultHandler
00171 {   Q_OBJECT
00172     QWidget             *parent;
00173     YPainter            ypainter;
00174     QList<YTimingInfo>  timinginfos;
00176     unsigned int        scrollcount;
00177     void                UpdateTimings();
00178     YASA_TIME           absmaxtime;                         // abs max time of all diagrams
00179 public:                 YTimingHandler(QWidget *p) : parent(p), scrollcount(0), absmaxtime(0)
00180                         {
00181                             timinginfos.setAutoDelete(true);
00182                         }
00184     int                 InsertTiming(YTimings *t);
00185     virtual void        ClearResults()                                  {   timinginfos.clear();    }
00187     virtual int         PostCreate();
00188     YPainter*           GetPainter()                                    {   return &ypainter;       }
00189     QList<YTimingInfo>* GetTimingInfos()                                {   return &timinginfos;    }
00190     void                ViewScrolled(YTimingScrollView *tsc, int posx, int posy);
00191     void                ZoomIn();
00192     void                ZoomOut();
00194     virtual void        UpdateViews() =0;
00195 signals:
00196     void                NewTimingInserted(YTimingInfo *ti);
00197 };
00198 
00202 class YDiagramNameTimingHandler : public YTimingHandler
00203 {   Q_OBJECT
00204     YTimingNameScrollView   namescrollview;
00205     YTimingDiagramScrollView diagramscrollview;
00206 public:                 YDiagramNameTimingHandler(QSplitter *parent) : YTimingHandler(parent),
00207                         namescrollview(parent),
00208                         diagramscrollview(parent)
00209                         {
00210                             namescrollview.SetTimingHandler(this);
00211                             diagramscrollview.SetTimingHandler(this);
00212                             connect(this, SIGNAL( NewTimingInserted(YTimingInfo *) ), &namescrollview, SLOT( NewTimingInserted(YTimingInfo *) ) );
00213                             connect(this, SIGNAL( NewTimingInserted(YTimingInfo *) ), &diagramscrollview, SLOT( NewTimingInserted(YTimingInfo *) ) );
00214                             connect( &namescrollview, SIGNAL( contentsMoving(int, int) ), &diagramscrollview, SLOT( ViewScrolled(int, int ) ) );
00215                             connect( &diagramscrollview, SIGNAL( contentsMoving(int, int) ), &namescrollview, SLOT( ViewScrolled(int, int ) ) );
00216                             // correct size of splitters
00217                             QValueList<int> widthlist=parent->sizes();
00218                             int             w=widthlist[0]+widthlist[1];
00219                             widthlist[0]=w*1/5;
00220                             widthlist[1]=w*4/5;
00221                             parent->setSizes( widthlist );
00222                         }
00224     virtual void        UpdateViews();
00225 };
00226 
00227 
00228 
00230 #endif                                                                          // ifndef YASAGUI_TIMING_HANDLER_INCLUDE

Generated on Thu Feb 13 23:43:56 2003 for Yasa by doxygen1.3-rc3