Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

TrapperView Class Reference

The view to graphically present the reads and their features. The user will mainly interact with this window. More...

#include <trapperview.h>

Collaboration diagram for TrapperView:

Collaboration graph
[legend]
List of all members.

Public Slots

void slotSwitchToMode (int i)
void slotStartAlgo (int i)
void slotScrollToMouse ()
void slotScrollToPos ()
void slotSetCenter ()
void slotClearCenter ()

Signals

void createView (QString)
void message (const QString &)

Public Member Functions

 TrapperView (TrapperDoc *pDoc, QWidget *parent, const char *name, QString _viewMode=QString("everything"))
 ~TrapperView ()
TrapperDocgetDocument () const
void update (TrapperView *pSender)
void print (QPrinter *pPrinter)
QString mode ()
void zoomIn ()
void zoomInX ()
void zoomInY ()
void zoomOut ()
void zoomOutX ()
void zoomOutY ()
void selectAll ()
void selectBetween ()
void findRead ()
void enlarge ()
void shrink ()
void setDragMode (bool status)
void copy ()
void paste ()
void cut ()
void undo ()
TR_DNA mousePressedRow ()
TR_DNA mousePressedCol ()
void sendMsg (const QString &msg)

Protected Types

typedef std::set< db_recno_t > RecnoMap

Protected Member Functions

void contentsDragEnterEvent (QDragEnterEvent *event)
void contentsDropEvent (QDropEvent *event)
void contentsMouseMoveEvent (QMouseEvent *e)
void contentsMouseReleaseEvent (QMouseEvent *e)
void contentsContextMenuEvent (QContextMenuEvent *e)
void contentsMousePressEvent (QMouseEvent *e)
void contentsDragMoveEvent (QDragMoveEvent *)
virtual void closeEvent (QCloseEvent *)
void doZoom ()
void scrollTo (TR_PIX x, TR_PIX y)
void drawContents (QPainter *p, TR_PIX cx, TR_PIX cy, TR_PIX cw, TR_PIX ch)
void drawContents_helper (QPainter *p, QPainter *bitmapPainter, int cx, int cy, int cw, int ch, int dx, int dy)
 paint a rectangle of the window
void paintFeatures (QPainter *p, QPainter *bitmapPainter, db_recno_t readRecno, TR_PIX x_pix, TR_PIX y_pix, TR_DNA x_dna_relative, TR_DNA dna_len, double width, TR_PIX height, bool selected, int center_relative, bool overlap, TR_DNA bg, TR_DNA eg)
 paint border line around the read rectangle. Then divide the rectangle into layers and paint features of the read into these layers.
void paintGrid (QPainter *p, TR_PIX cx, TR_PIX cy, TR_PIX cw, TR_PIX ch)
 paint some extra dots in the background of the window. These will move along when the user scrolls. Nice to have some visual feedback of movement when there are no reads in the window
void convertToPixelCoordinates (TR_PIX &x_pix, TR_PIX &y_pix, TR_DNA x_dna, TR_DNA y_dna)
void convertToDnaCoordinates (TR_DNA &x_dna, TR_DNA &y_dna, const TR_PIX cx, const TR_PIX cy)
TR_PIX dnaCoordToPixel_X (TR_DNA cx)
TR_PIX dnaCoordToPixel_Y (TR_DNA cy)
TR_DNA pixelCoordToDna_X (TR_PIX x_dna)
TR_DNA pixelCoordToDna_Y (TR_PIX y_dna)
std::set< db_recno_t > & getSelectedReads ()
void select (db_recno_t recno, bool status)
bool isSelected (db_recno_t recno)
void clearSelected ()
std::vector< std::list< std::string > > getInfo (const QPoint &pos)
void runAlgo (const std::string &AlgoType, std::set< db_recno_t > &recnoList, AlgoParam *param=0)
void writeSelected (QDataStream &data_stream)
void readSelected (QDataStream &data_stream)
void moveData (TR_PIX dx, TR_PIX dy)
void fitContentsizeToData ()
void clearLastMove ()

Protected Attributes

TR_PIX basewidth
TR_PIX spaceBetweenRows
TR_PIX rowheight
TR_DNA globalRows
TR_DNA globalBases
TR_DNA center_point
TrapperDocdoc
QLabel * lab
double magnifyX
u_int16_t magnifyY
int zoomfactor
ViewModesviewModes
QPopupMenu * switchViewMenu
QPopupMenu * algoMenu
QPopupMenu * infoMenu
std::set< db_recno_t > selectedReads
std::map< std::string, int > zoom_cutoff
ReadsInRectreadsInRect
bool dragging
bool allow_dragging
bool moving
bool last_click_selected_read
bool last_click_changed_selection
db_recno_t last_selected_recno
QPoint curr_mouse_pos
TR_PIX y_delta
TR_PIX y_delta_previous
TR_DNA last_move_x
TR_DNA last_move_y

Private Member Functions

void drawRubber (QPainter *p)

Private Attributes

QPixmap dragPixmap
QBitmap dragBitmap
QPainter p3
QPoint mousePressedPoint
QPoint dragWindowPoint
QRect * rubber_band
QPoint RubberStart
QPoint RubberEnd
bool RubberOn
QPoint oldMovePoint
bool moveOn

Friends

class TrapperDoc

Detailed Description

The view to graphically present the reads and their features. The user will mainly interact with this window.

Functionality given to the user: Scrolling, zooming, drag and drop of the reads to move them around, selecting reads and start algorithms.

This software is designed to have totally decoupled view and data classes. The view is stateless ( it does not store any data ) and will for every update newly read in all data needed to paint up the view. In other words, the view does not cash anything.

This has some nice implications: Data algorithm classes will work directly with the data classes and will not be aware of any views. Any number of views can be opened up and they will be independent and will not be aware of each other.

For it to be possible to take this design approach the data classes must respond quickly to queries because any delay here will make the views appear sluggish. Scrolling will here be the toughest test for the speed of the data class queries. Because by scrolling, new data should be painted very fast to the view. The user would not like big delays here.

To make the data class queries very fast, the data is stored in the embedded database Berkeley Db.

About how the reads and features get shown in TrapperView: TrapperView is inherited from QScrollView. QScrollView gives us the scroll bars and also gives convertion methods between the coordinate system of the actual window ( the viewport ) and the coordinate system of the content window ( the big window the user has to scroll to see all of it ). QScrollView gives us the possibility to place out "static" widgets on the content window, and QScrollView would then handle the scrolling automatically. But we would like a totally stateless view so we take another approach. We reimplement the virtual method drawContents() that is called everytime some part of the window should be painted, e.g. when the user has dragged the scrollbars. The method drawContents() takes as arguments the "content" pixel coordinates of a rectangle to be painted. Some background pixels are painted to enhance the "movement feeling" when scrolling. Then drawContents_helper() is called ( which is also is reused when painting reads in a drag & drop ). In drawContents_helper() we first convert to DNA coordinates, i.e. the x-axis unit is a nucleotid-base and the y-axis unit is a row. We then use the class ReadsInRect that can tell us which reads are visible in our painting rectangle. Now paintFeatures() is called for each read. In paintFeatures(), features for the read are painted in different layers inside the read rectangle.

Definition at line 115 of file trapperview.h.


Member Typedef Documentation

typedef std::set<db_recno_t> TrapperView::RecnoMap [protected]
 

Definition at line 280 of file trapperview.h.


Constructor & Destructor Documentation

TrapperView::TrapperView TrapperDoc pDoc,
QWidget *  parent,
const char *  name,
QString  _viewMode = QString("everything")
 

Constructor for the view

Parameters:
pDoc your document instance that the view represents. Create a document before calling the constructor or connect an already existing document to a new MDI child widget.

Definition at line 71 of file trapperview.cpp.

References allow_dragging, basewidth, center_point, doc, dragging, fitContentsizeToData(), globalBases, globalRows, last_click_changed_selection, last_click_selected_read, GeneralMaker::listRegistered(), magnifyX, magnifyY, moving, rowheight, rubber_band, spaceBetweenRows, viewModes, zoom_cutoff, and zoomfactor.

00072   : QScrollView(parent, name,/** wflags**/ WResizeNoErase|WStaticContents|WDestructiveClose/*|WNoAutoErase*/), doc( pDoc )
00073 {
00074 //   cerr << "in TrapperView::TrapperView" << endl;
00075 //   cerr<<"doc: "<<doc<<endl;
00076   viewport()->setAcceptDrops( true );
00077   setDragAutoScroll( true );
00078   allow_dragging = true;
00079   dragging = false;
00080   moving = false;
00081   rubber_band = 0;
00082   last_click_selected_read = false;
00083   last_click_changed_selection = false;
00084   
00085   
00086   if ( _viewMode.isNull() )
00087     {
00088       _viewMode = "closeup";
00089     }
00090 
00091   viewModes = new ViewModes( _viewMode, doc );
00092   
00093   //Ugly business here...
00094   list<string> type_list = GeneralMaker::listRegistered();
00095   for( list<string>::iterator it = type_list.begin(); it != type_list.end(); ++it ) {
00096     zoom_cutoff[ *it ] = 0;
00097   }
00098   zoom_cutoff["DnaStrData"] = 4;
00099   zoom_cutoff["QualityData"] = 4;
00100   zoom_cutoff["ChromatData"] = 8;
00101 
00102 
00103 //   globalRows = 1000;
00104 //   globalBases = 50000;
00105   globalRows = 50;
00106   globalBases = 2000;
00107 //   rowheight = 20;
00108 //   basewidth = 10;
00109   rowheight = 5;
00110   basewidth = 1;
00111   magnifyX = magnifyY = 1;
00112   zoomfactor = 2;
00113   spaceBetweenRows = 0;
00114   center_point = 0;
00115   
00116   fitContentsizeToData();
00117   
00118 
00119   viewport()->setPaletteBackgroundColor(white);
00120   viewport()->setBackgroundMode( Qt::FixedColor );
00121   setCaption( "yes" );
00122   viewport()->setMouseTracking(TRUE);
00123 }

TrapperView::~TrapperView  ) 
 

Destructor for the main view

Definition at line 126 of file trapperview.cpp.

References viewModes.

00127 {
00128  
00129   if ( viewModes ) {
00130     delete viewModes;
00131     viewModes = NULL;
00132   }
00133 }


Member Function Documentation

void TrapperView::clearLastMove  )  [protected]
 

Definition at line 566 of file trapperview.cpp.

References last_move_x, and last_move_y.

Referenced by clearSelected(), readSelected(), select(), and slotStartAlgo().

00567 {
00568   last_move_x = last_move_y = 0;
00569 }

void TrapperView::clearSelected  )  [protected]
 

Definition at line 1139 of file trapperview.cpp.

References clearLastMove(), and selectedReads.

Referenced by contentsMousePressEvent(), contentsMouseReleaseEvent(), cut(), findRead(), readSelected(), selectAll(), and selectBetween().

01140 {
01141   selectedReads.clear();
01142   clearLastMove();
01143 }

void TrapperView::closeEvent QCloseEvent *   )  [protected, virtual]
 

Definition at line 190 of file trapperview.cpp.

00191 {
00192     // LEAVE THIS EMPTY: THE EVENT FILTER IN THE TrapperApp CLASS TAKES CARE FOR CLOSING
00193     // QWidget closeEvent must be prevented.
00194 }

void TrapperView::contentsContextMenuEvent QContextMenuEvent *  e  )  [protected]
 

Definition at line 907 of file trapperview.cpp.

References algoMenu, AlgoMaker::algosRegistered(), getInfo(), infoMenu, TrapperConf::instance(), last_click_changed_selection, last_click_selected_read, moving, slotClearCenter(), slotScrollToMouse(), slotScrollToPos(), slotSetCenter(), slotStartAlgo(), slotSwitchToMode(), switchViewMenu, and TrapperConf::viewModeNames().

00908 {
00909   if ( last_click_changed_selection ) {
00910     updateContents();
00911   }
00912   moving = false;
00913   last_click_selected_read = false;
00914   last_click_changed_selection = false;
00915   
00916   QPopupMenu* contextMenu = new QPopupMenu( this );
00917   Q_CHECK_PTR( contextMenu );
00918   QLabel *caption = new QLabel( "<font color=darkblue><u><b>"
00919                                 "Context Menu</b></u></font>", this );
00920   caption->setAlignment( Qt::AlignCenter );
00921   contextMenu->insertItem( caption );
00922   
00923 
00924   
00925 
00926   //Algo stuff
00927   algoMenu = new QPopupMenu( this );
00928   Q_CHECK_PTR( algoMenu );
00929   list<string> algos = AlgoMaker::algosRegistered();
00930   list<string>::iterator stIt;
00931   
00932   for (stIt = algos.begin() ; stIt != algos.end(); ++stIt )
00933     {
00934       algoMenu->insertItem (  stIt->c_str()  );
00935     }
00936   connect( algoMenu, SIGNAL( activated( int ) ),
00937            this, SLOT( slotStartAlgo( int ) ) );
00938   contextMenu->insertItem( "&Operations", algoMenu );
00939   
00940 
00941 
00942   //Info stuff
00943   infoMenu = new QPopupMenu(this);
00944 
00945   vector<list<string> > infos = getInfo( e->pos() );
00946   QPtrList<QPopupMenu> infolist;
00947   infolist.setAutoDelete( true );
00948   
00949   for( size_t i = 0; i < infos.size(); i++ ) {
00950     stIt = infos[i].begin();
00951     if ( stIt == infos[i].end() ) continue;
00952     infolist.append(new QPopupMenu(this));
00953     ++stIt;
00954 
00955     for ( ; stIt != infos[i].end(); ++stIt ) {
00956 //       infoMenu->insertItem (  stIt->c_str()  );
00957 
00958       infolist.last()->insertItem (  stIt->c_str()  );
00959     }
00960 
00961     
00962     infoMenu->insertItem(infos[i].begin()->c_str(), infolist.last());
00963   }
00964 
00965   //No connecting here, 'cause only info...
00966   contextMenu->insertItem( "&Info", infoMenu );
00967 
00968 
00969   //Viewmode stuff
00970   switchViewMenu = new QPopupMenu( this );
00971   Q_CHECK_PTR( switchViewMenu );
00972   TrapperConf * conf = TrapperConf::instance();
00973   QStringList names = conf->viewModeNames();
00974   
00975   QStringList::Iterator it = names.begin();
00976   for ( ; it != names.end(); ++it )
00977     {
00978       switchViewMenu->insertItem ( *it );
00979     }
00980   connect( switchViewMenu, SIGNAL( activated( int ) ),
00981            this, SLOT( slotSwitchToMode( int ) ) );
00982   contextMenu->insertItem( "&Switch to viewmode", switchViewMenu );
00983 
00984 
00985   contextMenu->insertSeparator();
00986   contextMenu->insertItem("Set chromat center", this, SLOT(slotSetCenter()));
00987   contextMenu->insertItem("Clear chromat center", this, SLOT(slotClearCenter()));
00988 
00989   contextMenu->insertSeparator();
00990   contextMenu->insertItem("Scroll Here", this, SLOT(slotScrollToMouse()) );
00991   contextMenu->insertItem("Scroll to pos", this, SLOT(slotScrollToPos()) );
00992 
00993   contextMenu->exec( QCursor::pos() );
00994   delete contextMenu;
00995   delete switchViewMenu;//Previous memory leak??
00996   delete algoMenu;
00997   delete infoMenu;
00998 }

void TrapperView::contentsDragEnterEvent QDragEnterEvent *  event  )  [protected]
 

Definition at line 1448 of file trapperview.cpp.

01449 {
01450 //   cerr << "in TrapperView::dragEnterEvent" << endl;
01451   event->accept(
01452                 TRUE
01453                 );
01454 }

void TrapperView::contentsDragMoveEvent QDragMoveEvent *   )  [protected]
 

Definition at line 1456 of file trapperview.cpp.

01457 {
01458   
01459 //   e->setPoint( QPoint( mousePressedPoint.x(), e->pos().y() ) );
01460 
01461 //   cerr << "in TrapperView::dragMoveEvent" << endl;  
01462 //   cerr<<"x(): "<<e->pos().x()<<endl;
01463 //   cerr<<"y(): "<<e->pos().y()<<endl;
01464  
01465 }

void TrapperView::contentsDropEvent QDropEvent *  event  )  [protected]
 

Definition at line 1467 of file trapperview.cpp.

References convertToDnaCoordinates(), getDocument(), mousePressedPoint, moveData(), readSelected(), and TR_DNA.

01468 {
01469 //   cerr << "in TrapperView::dropEvent" << endl;
01470 
01471  QPoint deltaMovement = event->pos() - mousePressedPoint;
01472  TR_DNA x_dna_movDelta;
01473  TR_DNA y_dna_movDelta;
01474 
01475  convertToDnaCoordinates( x_dna_movDelta, y_dna_movDelta, deltaMovement.x(), deltaMovement.y() );
01476 //  cerr << "dropped happened with delta x=" << x_dna_movDelta << " y=" << y_dna_movDelta << endl; 
01477  
01478  TrapperView* w = dynamic_cast<TrapperView*>( event->source() );
01479 
01480  if ( !w) {
01481    //Drop from another app...
01482    return;
01483  }
01484  
01485 
01486  assert(w);
01487  
01488  if ( w->getDocument() == this->getDocument() ) {
01489 
01490    moveData( deltaMovement.x(), deltaMovement.y() );
01491  }
01492  else {
01493    QByteArray ar( event->encodedData("min_mime_type") );
01494    QDataStream data_stream(ar, IO_ReadOnly);
01495    
01496    readSelected(data_stream);
01497    updateContents();
01498  }
01499  
01500 
01501 }

void TrapperView::contentsMouseMoveEvent QMouseEvent *  e  )  [protected]
 

Definition at line 720 of file trapperview.cpp.

References allow_dragging, curr_mouse_pos, dragging, dragPixmap, dragWindowPoint, drawContents_helper(), drawRubber(), last_click_selected_read, mousePressedPoint, moving, pixelCoordToDna_X(), pixelCoordToDna_Y(), rubber_band, RubberEnd, RubberOn, sendMsg(), writeSelected(), y_delta, and y_delta_previous.

00721 {
00722   QString msg = "Row: " + QString().setNum(pixelCoordToDna_Y(e->y())) + ", col: " + QString().setNum(pixelCoordToDna_X(e->x()));
00723   sendMsg( msg );
00724 
00725   bool nobutton = Qt::NoButton & e->state();
00726 
00727   if ( nobutton ) {
00728     moving = false;
00729     return;
00730   }
00731   
00732 
00733   if ( allow_dragging && dragging ) {
00734 //   if ( dragging ) {
00735 //     cerr<<"Dragging..."<<endl;
00736 
00737     ReadDrag *d = new ReadDrag( dragPixmap, dragWindowPoint, this );
00738 //     QCString ar("hej");
00739     QByteArray ar;
00740     QDataStream data_stream(ar, IO_WriteOnly);
00741     writeSelected(data_stream);
00742 
00743     d->setEncodedData(ar);
00744     d->dragCopy(); // do NOT delete d.
00745     dragging = FALSE;
00746     moving = false;
00747     last_click_selected_read = false;
00748 //     cerr<<"Stopped dragging"<<endl;
00749   }
00750   else if ( last_click_selected_read ) {
00751 //   else if ( !selectedReads.empty() ) {
00752     //"Normal" moving
00753     moving = true;
00754     
00755     curr_mouse_pos = e->pos();//Don't really need this??
00756 //     y_delta = pixelCoordToDna_Y( (curr_mouse_pos - mousePressedPoint).y() );
00757     y_delta = (curr_mouse_pos - mousePressedPoint).y();
00758 
00759     if ( pixelCoordToDna_Y( y_delta) == pixelCoordToDna_Y( y_delta_previous ) ) {
00760 //       moving = false;
00761       return;
00762     }
00763     
00764     y_delta_previous = y_delta;
00765 
00766     //MOVINGTEST
00767 
00768     QPainter p(viewport());
00769     drawContents_helper(&p, 0,0,0,0,0,0,0);
00770     return;
00771     //END MOVINGTEST
00772     
00773     updateContents();
00774   }
00775   else if ( rubber_band != 0 ) {
00776 
00777     //RUBBERTEST
00778     QPainter p(viewport());
00779     p.setPen(QColor(255,255,255));
00780     p.setRasterOp(NotROP);
00781     if(RubberOn) drawRubber(&p);
00782     RubberEnd= contentsToViewport(e->pos());
00783     drawRubber(&p);
00784     RubberOn=TRUE;
00785     return;
00786     //END RUBBERTEST
00787     
00788     curr_mouse_pos = e->pos();
00789     
00790     QRect oldband = rubber_band->normalize();
00791 
00792     rubber_band->setSize( QSize( curr_mouse_pos.x() - mousePressedPoint.x(),
00793                                  curr_mouse_pos.y() - mousePressedPoint.y() ) );
00794     
00795 //     updateContents();
00796     QPoint margin( 1, 1 );
00797     QRect norm = rubber_band->normalize();
00798     
00799     updateContents( QRect( norm.topLeft() - margin, norm.bottomRight() + margin ).unite( QRect(oldband.topLeft() - margin, oldband.bottomRight() + margin ) ) );
00800   }
00801   
00802 }

void TrapperView::contentsMousePressEvent QMouseEvent *  e  )  [protected]
 

Definition at line 572 of file trapperview.cpp.

References clearSelected(), convertToDnaCoordinates(), doc, dragBitmap, dragging, dragPixmap, dragWindowPoint, drawContents_helper(), ReadsInRect::first(), GeneralData::getRecno(), isSelected(), last_click_changed_selection, last_click_selected_read, last_selected_recno, mousePressedPoint, moveOn, moving, p3, pixelCoordToDna_X(), pixelCoordToDna_Y(), readsInRect, rubber_band, RubberEnd, RubberOn, RubberStart, select(), selectedReads, sendMsg(), ReadsInRect::setWindowCoord(), TR_DNA, y_delta, and y_delta_previous.

00573 {
00574   QString msg = "Row: " + QString().setNum(pixelCoordToDna_Y(e->y())) + ", col: " + QString().setNum(pixelCoordToDna_X(e->x()));
00575   sendMsg( msg );
00576 
00577   y_delta = 0;
00578   y_delta_previous = 0;
00579   
00580   bool ctrlclick = Qt::ControlButton & e->state();
00581   bool leftbutton = Qt::LeftButton & e->stateAfter();
00582 
00583 //   if ( ctrlclick )
00584 //     cerr<<"ctrlclick!!!!!!!!!!!!!! "<<endl;
00585   
00586   
00587   mousePressedPoint.setX( e->x() );
00588   mousePressedPoint.setY( e->y() );
00589 
00590   
00591   //RUBBERTEST
00592   RubberStart=contentsToViewport(e->pos());
00593   RubberEnd = RubberStart;
00594   RubberOn=FALSE;
00595   //END RUBBERTEST
00596 
00597   //MOVINGTEST
00598   moveOn = false;
00599   //END MOVINGTEST
00600 
00601   TR_DNA x_dna, y_dna;
00602   convertToDnaCoordinates( x_dna, y_dna, e->x(), e->y() );
00603   
00604   readsInRect = new ReadsInRect( doc );
00605 //   readsInRect->setWindowCoord( x_dna, y_dna, 1, 1 );  /* a rectangle with dimension 1x1 */
00606   readsInRect->setWindowCoord( x_dna, y_dna, 3, 3 );  /* a rectangle with dimension 3x3 */
00607   ReadData * r = readsInRect->first(); 
00608   if ( r ) {//hit read
00609     if ( ctrlclick ) {
00610       if ( isSelected( r->getRecno() ) ) {
00611         select( r->getRecno(), false );
00612         last_click_selected_read = false;
00613         last_click_changed_selection = true;
00614       }
00615       else {
00616         select( r->getRecno(), true);
00617         last_click_selected_read = true;
00618         last_selected_recno = r->getRecno();
00619         last_click_changed_selection = true;
00620       }
00621     }//end ctrlclick
00622     else {//no ctrlclick
00623       if ( isSelected( r->getRecno() ) ) {
00624         last_click_selected_read = true;
00625         last_selected_recno = r->getRecno();
00626         last_click_changed_selection = false;
00627       }
00628       else {
00629         clearSelected();
00630         select( r->getRecno(), true);       
00631         last_click_selected_read = true;        
00632         last_selected_recno = r->getRecno();
00633         last_click_changed_selection = true;
00634       }
00635       
00636     }//end no ctrlclick
00637     if ( last_click_selected_read )
00638       dragging = TRUE; 
00639   }// end hit read
00640   else {//didn't hit read
00641 //     if ( rubber_band != 0 ) {
00642 //       delete rubber_band;
00643 //     }
00644 //     rubber_band = new QRect( mousePressedPoint, mousePressedPoint );
00645     if ( ctrlclick ) {
00646       last_click_selected_read = false;
00647       last_click_changed_selection = false;
00648     }//end ctrlclick
00649     else {//no ctrlclick
00650       last_click_selected_read = false;
00651       if ( selectedReads.size() > 0 )
00652         last_click_changed_selection = true;
00653         
00654       clearSelected();
00655 
00656       //"Rubber band"
00657 //       if ( rubber_band != 0 ) {
00658 //         delete rubber_band;
00659 //       }
00660 //       if ( leftbutton )
00661 //         rubber_band = new QRect( mousePressedPoint, mousePressedPoint );
00662       
00663       
00664     }//end no ctrlclick
00665     if ( rubber_band != 0 ) {
00666       delete rubber_band;
00667     }
00668     if (leftbutton && !last_click_selected_read) {
00669       moving = false;
00670       rubber_band = new QRect( mousePressedPoint, mousePressedPoint );
00671     }
00672     
00673   }//end didn't hit read
00674 
00675 //   updateContents();//Removed this because of visual bug...
00676   delete readsInRect;
00677   
00678   // From here on: about Start a drag and painting
00679   {
00680     dragWindowPoint.setX( size().width()      );
00681     dragWindowPoint.setY( size().height() );
00682     QRect re( mousePressedPoint - dragWindowPoint, mousePressedPoint + dragWindowPoint );
00683     
00684     
00685     dragPixmap.resize( re.size() );
00686     QPainter p2;
00687     p2.begin(&dragPixmap, this);
00688     dragBitmap.resize( re.size()  );
00689     p3.begin(&dragBitmap, this);
00690     QBrush brush;
00691     brush.setStyle( Qt::SolidPattern );
00692     brush.setColor( Qt::white );
00693     p2.fillRect( 0  , 0 , re.width() , re.height() ,brush) ;
00694     brush.setColor( Qt::color0 );
00695     
00696     p3.fillRect( 0  , 0 , re.width() , re.height() ,brush) ;
00697     
00698     QPoint tl = re.topLeft() ;
00699     QPoint br = re.bottomRight() ;
00700     
00701     drawContents_helper(&p2, &p3, tl.x(), tl.y(), br.x() - tl.x() + 1, br.y() - tl.y() + 1, 
00702                         - ( mousePressedPoint.x() - dragWindowPoint.x() ),  - ( mousePressedPoint.y() - dragWindowPoint.y() ));
00703     
00704     //Test:
00705 //     QPen a_pen;
00706 //     p2.setPen(a_pen);
00707 //     p2.drawRect(dragPixmap.rect());
00708 //     a_pen.setColor(Qt::color1);
00709 //     p3.setPen(a_pen);
00710 //     p3.drawRect(dragPixmap.rect());
00711     //End test
00712     dragPixmap.setMask(dragBitmap);
00713 
00714     p2.end();
00715     p3.end();
00716   }
00717 }

void TrapperView::contentsMouseReleaseEvent QMouseEvent *  e  )  [protected]
 

Definition at line 804 of file trapperview.cpp.

References clearSelected(), convertToDnaCoordinates(), doc, dragging, drawRubber(), ReadsInRect::first(), last_click_changed_selection, last_click_selected_read, last_selected_recno, moveData(), moveOn, moving, ReadsInRect::next(), readsInRect, rubber_band, RubberEnd, RubberOn, RubberStart, select(), ReadsInRect::setWindowCoord(), TR_DNA, TR_PIX, and y_delta.

00805 {
00806   dragging = false;
00807   //Maybe dragging code here? NO!
00808   
00809   if ( moving ) {
00810     //Moving stuff...
00811     moveData(0, y_delta);
00812 
00813     
00814 
00815     //MOVINGTEST
00816     if(moveOn) 
00817       {
00818         updateContents();
00819         moveOn=FALSE;
00820       }    
00821     //END MOVINGTEST
00822 
00823     moving = false;
00824   }
00825   else { //not moving
00826     
00827     bool ctrlclick = Qt::ControlButton & e->state();
00828 
00829     if ( !ctrlclick && last_click_selected_read ) {
00830       clearSelected();
00831       select( last_selected_recno, true );
00832       last_click_changed_selection = true;
00833 //       updateContents();
00834     }
00835     if ( last_click_changed_selection ) {
00836       updateContents();
00837     }
00838     
00839 
00840     if ( rubber_band != 0 ) {
00841       
00842       readsInRect = new ReadsInRect( doc );
00843       
00844       TR_DNA x_dna, y_dna, w_dna, h_dna, x2_dna, y2_dna;
00845       TR_PIX x_pix, y_pix, w_pix, h_pix;
00846       
00847       QRect norm = rubber_band->normalize();
00848       //RUBBERTEST
00849       RubberStart = viewportToContents( RubberStart );
00850       RubberEnd = viewportToContents( RubberEnd );
00851       
00852       norm = QRect(
00853                 RubberStart.x(),
00854                 RubberStart.y(),
00855                 RubberEnd.x()-RubberStart.x(),
00856                 RubberEnd.y()-RubberStart.y()
00857                 ).normalize();
00858       //END RUBBERTEST
00859 
00860       rubber_band->setTopLeft( norm.topLeft() );      
00861       rubber_band->setBottomRight( norm.bottomRight() );      
00862 
00863       rubber_band->rect( &x_pix, &y_pix, &w_pix, &h_pix);
00864       convertToDnaCoordinates( x_dna, y_dna, x_pix, y_pix );
00865       convertToDnaCoordinates( x2_dna, y2_dna, x_pix + w_pix, y_pix + h_pix);
00866       
00867       w_dna = x2_dna - x_dna;
00868       h_dna = y2_dna - y_dna;
00869 
00870 
00871       readsInRect->setWindowCoord( x_dna, y_dna,  w_dna,h_dna );
00872       if ( !ctrlclick) 
00873         clearSelected();
00874       
00875       for ( ReadData * r = readsInRect->first(); r; r = readsInRect->next() ) {
00876         select( r->getRecno(), true);
00877       }
00878       //RUBBERTEST
00879       QPainter p(viewport());
00880       p.setPen(QColor(255,255,255));
00881       p.setRasterOp(NotROP);
00882       if(RubberOn) 
00883         {
00884           drawRubber(&p);
00885           RubberOn=FALSE;
00886         }
00887       else
00888         {
00889           RubberEnd=RubberStart;
00890         }
00891       //END RUBBERTEST
00892       
00893       delete rubber_band;
00894       rubber_band = 0;
00895       delete readsInRect;
00896       updateContents();
00897     }
00898 
00899   }
00900   moving = false;
00901   dragging = false;
00902   last_click_changed_selection = false;
00903   last_click_selected_read = false;
00904   
00905 }

void TrapperView::convertToDnaCoordinates TR_DNA &  x_dna,
TR_DNA &  y_dna,
const TR_PIX  cx,
const TR_PIX  cy
[protected]
 

Definition at line 196 of file trapperview.cpp.

References pixelCoordToDna_X(), and pixelCoordToDna_Y().

Referenced by contentsDropEvent(), contentsMousePressEvent(), contentsMouseReleaseEvent(), and drawContents_helper().

00197 {
00198     x_dna = pixelCoordToDna_X(cx);
00199     y_dna = pixelCoordToDna_Y(cy);
00200     return;
00201 }

void TrapperView::convertToPixelCoordinates TR_PIX &  x_pix,
TR_PIX &  y_pix,
TR_DNA  x_dna,
TR_DNA  y_dna
[protected]
 

Definition at line 219 of file trapperview.cpp.

References dnaCoordToPixel_X(), and dnaCoordToPixel_Y().

Referenced by drawContents_helper().

00220 {
00221     x_pix = dnaCoordToPixel_X(x_dna);
00222     y_pix = dnaCoordToPixel_Y(y_dna);
00223     return;
00224 }

void TrapperView::copy  ) 
 

copies selected data

Definition at line 1636 of file trapperview.cpp.

References writeSelected().

Referenced by cut(), and TrapperApp::slotEditCopy().

01637 {
01638   QByteArray ar;
01639   QDataStream str(ar, IO_WriteOnly);
01640   
01641   writeSelected(str);
01642   QClipboard* cb = QApplication::clipboard();
01643   ReadDrag* r = new ReadDrag(this);
01644   r->setEncodedData(ar);
01645   cb->setData(r, QClipboard::Clipboard);
01646   
01647 }

void TrapperView::createView QString   )  [signal]
 

void TrapperView::cut  ) 
 

cuts selected data

Definition at line 1662 of file trapperview.cpp.

References clearSelected(), copy(), Destroyer::destroy(), doc, and selectedReads.

Referenced by TrapperApp::slotEditCut().

01663 {
01664   copy();
01665   Destroyer d(doc);
01666   for( set<db_recno_t>::iterator it = selectedReads.begin(); it != selectedReads.end(); ++it ) {
01667     d.destroy(*it);
01668   }
01669   clearSelected();
01670   updateContents();
01671   
01672 }

TR_PIX TrapperView::dnaCoordToPixel_X TR_DNA  cx  )  [protected]
 

Definition at line 226 of file trapperview.cpp.

References basewidth, and magnifyX.

Referenced by convertToPixelCoordinates(), findRead(), paintGrid(), readSelected(), slotScrollToPos(), and undo().

00227 {
00228 //   if ( x_dna * basewidth * magnifyX < 1 ) {
00229 //     cerr<<"x_dna: "<<x_dna<<endl;
00230 //     cerr<<"basewidth: "<<basewidth<<endl;
00231 //     cerr<<"x_dna * basewidth * magnifyX: "<<x_dna * basewidth * magnifyX<<endl;
00232 //   }
00233   
00234 
00235   return x_dna * basewidth * magnifyX;
00236 }

TR_PIX TrapperView::dnaCoordToPixel_Y TR_DNA  cy  )  [protected]
 

Definition at line 238 of file trapperview.cpp.

References magnifyY, and rowheight.

Referenced by convertToPixelCoordinates(), drawContents_helper(), findRead(), paintGrid(), readSelected(), slotScrollToPos(), and undo().

00239 {
00240   return y_dna * rowheight * magnifyY;
00241 }

void TrapperView::doZoom  )  [protected]
 

Definition at line 1339 of file trapperview.cpp.

References basewidth, globalBases, globalRows, magnifyX, magnifyY, and rowheight.

01340 {
01341 //   QPoint p = viewportToContents(viewport()->rect().topLeft());
01342 
01343 //   if ( globalBases * magnifyX * basewidth < 1 ) {
01344 //     cerr<<"globalBases: "<<globalBases<<endl;
01345 //     cerr<<"globalBases * magnifyX * basewidth: "<<globalBases * magnifyX * basewidth<<endl;
01346 //   }
01347   resizeContents(globalBases * magnifyX * basewidth , globalRows * rowheight * magnifyY);
01348   //     QPoint p = viewportToContents(viewport()->rect().center());
01349   //     center( p.x()* factor , p.y()*factor );
01350 //   setContentsPos(p.x()*zoomfactor, p.y()*zoomfactor);
01351 //   setContentsPos(p.x(), p.y());
01352   updateContents();
01353   
01354 }

void TrapperView::drawContents QPainter *  p,
TR_PIX  cx,
TR_PIX  cy,
TR_PIX  cw,
TR_PIX  ch
[protected]
 

Definition at line 373 of file trapperview.cpp.

References drawContents_helper(), and paintGrid().

00374 {
00375 //   QPoint qp = viewportToContents(viewport()->rect().topLeft());
00376 //   cerr<<"qp.x(): "<<qp.x()<<endl;
00377 //   cerr<<"qp.y(): "<<qp.y()<<endl;
00378 
00379   drawContents_helper(p, NULL, cx, cy, cw, ch, 0, 0);
00380   paintGrid( p, cx, cy, cw, ch);
00381 }

void TrapperView::drawContents_helper QPainter *  p,
QPainter *  bitmapPainter,
int  cx,
int  cy,
int  cw,
int  ch,
int  dx,
int  dy
[protected]
 

paint a rectangle of the window

Parameters:
p where to paint to
bmp where to paint a bitmask, we paint to the bitmask on the same places as we paint to p.
cx x coordinate of rectangle in "content" coordinate system
cy y coordinate of rectangle in "content" coordinate system
cw width of rectangle in "content" coordinate system
ch height of rectangle in "content" coordinate system
dx displace painting with this
dy displace painting with this

Definition at line 383 of file trapperview.cpp.

References basewidth, center_point, convertToDnaCoordinates(), convertToPixelCoordinates(), dnaCoordToPixel_Y(), doc, dragPixmap, dragWindowPoint, ReadsInRect::first(), isSelected(), magnifyX, magnifyY, mousePressedPoint, moveOn, mov