#include <splitViewInterface.h>
Inheritance diagram for SplitViewInterface:
Definition at line 43 of file splitViewInterface.h.
Public Member Functions | |
SplitViewInterface (QWidget *parent=0, const char *name=0) | |
Creates layout. | |
void | setPreviewMode (PREVIEW_MODE mode, bool forceDrawLabel=false) |
Sets preview mode. | |
virtual QSize | sizeHint () const=0 |
virtual QSize | minimumSizeHint () const |
void | setImages (QImage origImage, QImage adjustedImage) |
void | setAdjustedImage (QImage adjustedImage) |
sets adjusted image and repaints | |
QImage & | getOrigImage () |
returns orig image object | |
Protected Member Functions | |
void | paintEvent (QPaintEvent *e) |
void | mousePressEvent (QMouseEvent *e) |
void | mouseReleaseEvent (QMouseEvent *) |
void | mouseMoveEvent (QMouseEvent *e) |
virtual void | resizeEvent (QResizeEvent *)=0 |
Private Member Functions | |
double | displayToWorld (int coordinate) |
convert display coordinates to world coordinates (double from 0.0 - 1.0) | |
int | worldToDisplay (double coordinate) |
convert world coordinates to display coordinates (int from 0 to origImage width-1) | |
bool | nearSplitPoint (QPoint p) |
determines if mouse is near split point | |
Private Attributes | |
PREVIEW_MODE | previewMode |
Current display setting (adjusted or split screen). | |
bool | forceDrawLabel |
Draw original/adjusted lables outside of split view mode? | |
QString | originalString |
Original and adjusted strings. | |
QString | adjustedString |
QFont | textFont |
Larger font used for drawing text. | |
double | dragOffset |
x (or y) coordinate of split between drawn adjusted and original images | |
PREVIEW_MOUSE_MODE | mouseMode |
current mouse move mode | |
PREVIEW_MOUSE_MODE | currentMouseShape |
current mouse shape. | |
QImage | origImage |
Scaled original image. | |
QImage | adjustedImage |
Scaled adjusted image. |
SplitViewInterface::SplitViewInterface | ( | QWidget * | parent = 0 , |
|
const char * | name = 0 | |||
) |
Creates layout.
Definition at line 27 of file splitViewInterface.cpp.
References adjustedString, currentMouseShape, dragOffset, forceDrawLabel, mouseMode, NO_EFFECT_ON_SPLIT, originalString, previewMode, SPLIT_VIEW, and textFont.
00027 : 00028 QWidget (parent, name ) 00029 { 00030 //setup split point 00031 dragOffset = 0.5; 00032 mouseMode = NO_EFFECT_ON_SPLIT; 00033 currentMouseShape = NO_EFFECT_ON_SPLIT; 00034 00035 //set default mode to adjusted image 00036 previewMode = SPLIT_VIEW; 00037 00038 //don't force draw labels by default. this is useful when 00039 //the user pressed the Ctrl button or other key to toggle between opposite views 00040 //and drop down menu for choosing display type disagrees with actuall image being shown. 00041 forceDrawLabel = false; 00042 00043 //setup strings and fonts 00044 originalString = QString( tr("Original") ); 00045 adjustedString = QString( tr("Adjusted") ); 00046 00047 textFont = this->font(); 00048 textFont.setPointSize( textFont.pointSize() + 7 ); 00049 00050 //watch mouse movements in order to drag selection 00051 //watch mouse movements in order to move split point between adjusted and original image 00052 setMouseTracking(true); 00053 00054 //accept focus when clicked on 00055 setFocusPolicy( QWidget::ClickFocus ); 00056 }
void SplitViewInterface::setPreviewMode | ( | PREVIEW_MODE | mode, | |
bool | forceDrawLabel = false | |||
) |
Sets preview mode.
Definition at line 279 of file splitViewInterface.cpp.
References previewMode.
Referenced by HistogramEditor::keyPressEvent(), GrainEditor::keyPressEvent(), HistogramEditor::keyReleaseEvent(), GrainEditor::keyReleaseEvent(), HistogramEditor::selectPreviewImageType(), and GrainEditor::selectPreviewImageType().
00280 { 00281 //set mode and repaint 00282 previewMode = mode; 00283 this->forceDrawLabel = forceDrawLabel; 00284 repaint(false); 00285 }
virtual QSize SplitViewInterface::sizeHint | ( | ) | const [pure virtual] |
Implemented in PanningPreviewInterface, and ScaledPreviewInterface.
QSize SplitViewInterface::minimumSizeHint | ( | ) | const [virtual] |
Reimplemented in ScaledPreviewInterface.
Definition at line 404 of file splitViewInterface.cpp.
References adjustedString, originalString, TEXT_BACKGROUND_MARGIN, and textFont.
Referenced by ScaledPreviewInterface::minimumSizeHint().
00405 { 00406 QFontMetrics fm( textFont ); 00407 int w = 5*TEXT_BACKGROUND_MARGIN + fm.width(originalString) + fm.width(adjustedString); 00408 int h = 2*TEXT_BACKGROUND_MARGIN + fm.height(); 00409 return QSize( w, h ); 00410 }
void SplitViewInterface::setImages | ( | QImage | origImage, | |
QImage | adjustedImage | |||
) |
Definition at line 415 of file splitViewInterface.cpp.
Referenced by PanningPreviewInterface::generateOrigImage(), and ScaledPreviewInterface::resizeEvent().
00417 { 00418 this->origImage = origImage; 00419 this->adjustedImage = adjustedImage; 00420 repaint(false); 00421 }
void SplitViewInterface::setAdjustedImage | ( | QImage | adjustedImage | ) |
sets adjusted image and repaints
Definition at line 423 of file splitViewInterface.cpp.
Referenced by HistogramEditor::generateAdjustedPreviewImage(), and GrainEditor::generateAdjustedPreviewImage().
00424 { 00425 this->adjustedImage = adjustedImage; 00426 repaint(false); 00427 }
QImage & SplitViewInterface::getOrigImage | ( | ) |
returns orig image object
Definition at line 412 of file splitViewInterface.cpp.
References origImage.
Referenced by HistogramEditor::generateAdjustedPreviewImage(), and GrainEditor::generateAdjustedPreviewImage().
00413 { return origImage; }
void SplitViewInterface::paintEvent | ( | QPaintEvent * | e | ) | [protected] |
Definition at line 58 of file splitViewInterface.cpp.
References ADJUSTED_IMAGE, adjustedImage, adjustedString, buffer, dragOffset, forceDrawLabel, height, INV_SPLIT_VIEW, origImage, ORIGINAL_IMAGE, originalString, previewMode, SPLIT_VIEW, TEXT_BACKGROUND_MARGIN, TEXT_INSET, textFont, width, and worldToDisplay().
00059 { 00060 //if orig image not setup yet then return immediately 00061 if(origImage.isNull()) { return; } 00062 00063 //if viewing adjusted or split view and adjusted image is null bail 00064 if( 00065 (previewMode == ADJUSTED_IMAGE || previewMode == SPLIT_VIEW ) && 00066 adjustedImage.isNull() 00067 ) 00068 { return; } 00069 00070 //create buffer to draw in 00071 QPixmap buffer( size() ); 00072 00073 //create a painter pointing to the buffer 00074 QPainter bufferPainter( &buffer ); 00075 00076 //turn off clipping to make painting operations faster 00077 bufferPainter.setClipping(false); 00078 00079 //initialize buffer with background brush 00080 bufferPainter.fillRect( buffer.rect(), backgroundBrush() ); 00081 00082 //setup pen color 00083 QPen pen; 00084 pen.setStyle( Qt::SolidLine ); 00085 pen.setColor( white ); 00086 pen.setWidth( 2 ); 00087 bufferPainter.setPen( pen); 00088 00089 int xOffset = (width() - origImage.width()) / 2; 00090 int yOffset = (height() - origImage.height()) / 2; 00091 00092 //setup font metrics 00093 bufferPainter.setFont( textFont ); 00094 QFontMetrics fm( textFont ); 00095 00096 //paint the adjusted image 00097 if(previewMode == ADJUSTED_IMAGE) 00098 { 00099 bufferPainter.drawImage( QPoint(xOffset, yOffset), adjustedImage ); 00100 00101 //"Adjusted" label 00102 if(forceDrawLabel) 00103 { 00104 int x = xOffset + (origImage.width()-fm.width(adjustedString))/2; 00105 int y = yOffset + fm.ascent() + TEXT_INSET; 00106 00107 bufferPainter.fillRect( QRect(x - TEXT_BACKGROUND_MARGIN, 00108 y - TEXT_BACKGROUND_MARGIN - fm.ascent(), 00109 fm.width(adjustedString) + 2*TEXT_BACKGROUND_MARGIN, 00110 fm.height() + 2*TEXT_BACKGROUND_MARGIN), 00111 QBrush(darkGray) ); 00112 bufferPainter.drawText( x, y, 00113 adjustedString ); 00114 } 00115 } 00116 //paint the original image 00117 else if(previewMode == ORIGINAL_IMAGE) 00118 { 00119 bufferPainter.drawImage( QPoint(xOffset, yOffset), origImage ); 00120 00121 //"Original" label 00122 if(forceDrawLabel) 00123 { 00124 int x = xOffset + (origImage.width()-fm.width(originalString))/2; 00125 int y = yOffset + fm.ascent() + TEXT_INSET; 00126 00127 bufferPainter.fillRect( QRect(x - TEXT_BACKGROUND_MARGIN, 00128 y - TEXT_BACKGROUND_MARGIN - fm.ascent(), 00129 fm.width(originalString) + 2*TEXT_BACKGROUND_MARGIN, 00130 fm.height() + 2*TEXT_BACKGROUND_MARGIN), 00131 QBrush(darkGray) ); 00132 bufferPainter.drawText( x, y, 00133 originalString ); 00134 } 00135 } 00136 //if using split view also draw line down center and original image on left 00137 else if(previewMode == SPLIT_VIEW || 00138 previewMode == INV_SPLIT_VIEW ) 00139 { 00140 //determine what left/right or top/bottom strings are 00141 QString label1, label2; 00142 if(previewMode == SPLIT_VIEW) 00143 { 00144 label1 = originalString; 00145 label2 = adjustedString; 00146 } 00147 else 00148 { 00149 label2 = originalString; 00150 label1 = adjustedString; 00151 } 00152 00153 //find split point in screen coordinates 00154 int halfWay = worldToDisplay( dragOffset ); 00155 00156 //paint the original image 00157 bufferPainter.drawImage( QPoint(xOffset, yOffset), origImage ); 00158 00159 //------- 00160 if(origImage.width() > origImage.height() ) 00161 { 00162 //paint the adjusted image 00163 if(previewMode == SPLIT_VIEW) 00164 { 00165 bufferPainter.drawImage( xOffset + halfWay, 00166 yOffset, 00167 adjustedImage, 00168 halfWay,0, 00169 origImage.width() - halfWay, 00170 origImage.height() ); 00171 } 00172 else 00173 { 00174 bufferPainter.drawImage( xOffset, 00175 yOffset, 00176 adjustedImage, 00177 0,0, 00178 halfWay, 00179 origImage.height() ); 00180 } 00181 00182 00183 //paint white line 00184 bufferPainter.drawLine( xOffset + halfWay, 00185 yOffset, 00186 xOffset + halfWay, 00187 yOffset + origImage.height() ); 00188 00189 //Left label 00190 int x = xOffset + (halfWay-fm.width(label1))/2; 00191 int y = yOffset + fm.ascent() + TEXT_INSET; 00192 00193 bufferPainter.fillRect( QRect(x - TEXT_BACKGROUND_MARGIN, 00194 y - TEXT_BACKGROUND_MARGIN - fm.ascent(), 00195 fm.width(label1) + 2*TEXT_BACKGROUND_MARGIN, 00196 fm.height() + 2*TEXT_BACKGROUND_MARGIN), 00197 QBrush(darkGray) ); 00198 bufferPainter.drawText( x, y, 00199 label1 ); 00200 00201 //Right label 00202 x = xOffset + halfWay + (origImage.width() - halfWay - fm.width(label2))/2; 00203 00204 bufferPainter.fillRect( QRect(x - TEXT_BACKGROUND_MARGIN, 00205 y - TEXT_BACKGROUND_MARGIN - fm.ascent(), 00206 fm.width(label2) + 2*TEXT_BACKGROUND_MARGIN, 00207 fm.height() + 2*TEXT_BACKGROUND_MARGIN), 00208 QBrush(darkGray) ); 00209 bufferPainter.drawText( x, y, 00210 label2 ); 00211 } 00212 //------- 00213 else 00214 { 00215 //paint the adjusted image 00216 if(previewMode == SPLIT_VIEW) 00217 { 00218 bufferPainter.drawImage( xOffset, 00219 yOffset + halfWay, 00220 adjustedImage, 00221 0,halfWay, 00222 origImage.width(), 00223 origImage.height()-halfWay ); 00224 } 00225 else 00226 { 00227 bufferPainter.drawImage( xOffset, 00228 yOffset, 00229 adjustedImage, 00230 0,0, 00231 origImage.width(), 00232 halfWay ); 00233 } 00234 00235 //paint white line 00236 bufferPainter.drawLine( xOffset, 00237 yOffset + halfWay, 00238 xOffset + origImage.width(), 00239 yOffset + halfWay ); 00240 00241 //Top label 00242 int x = xOffset + (origImage.width()-fm.width(label1))/2; 00243 int y = yOffset + fm.ascent() + TEXT_INSET; 00244 00245 bufferPainter.fillRect( QRect(x - TEXT_BACKGROUND_MARGIN, 00246 y - TEXT_BACKGROUND_MARGIN - fm.ascent(), 00247 fm.width(label1) + 2*TEXT_BACKGROUND_MARGIN, 00248 fm.height() + 2*TEXT_BACKGROUND_MARGIN), 00249 QBrush(darkGray) ); 00250 bufferPainter.drawText( x, y, 00251 label1 ); 00252 00253 //Bottom label 00254 x = xOffset + (origImage.width()-fm.width(label2))/2; 00255 y = yOffset + halfWay + fm.height(); 00256 00257 bufferPainter.fillRect( QRect(x - TEXT_BACKGROUND_MARGIN, 00258 y - TEXT_BACKGROUND_MARGIN - fm.ascent(), 00259 fm.width(label2) + 2*TEXT_BACKGROUND_MARGIN, 00260 fm.height() + 2*TEXT_BACKGROUND_MARGIN), 00261 QBrush(darkGray) ); 00262 bufferPainter.drawText( x, y, 00263 label2 ); 00264 } 00265 //------- 00266 } 00267 00268 //end painter 00269 bufferPainter.end(); 00270 00271 //blit buffer to screen 00272 bitBlt( this, 00273 e->rect().x(), e->rect().y(), 00274 &buffer, 00275 e->rect().x(), e->rect().y(), 00276 e->rect().width(), e->rect().height() ); 00277 }
void SplitViewInterface::mousePressEvent | ( | QMouseEvent * | e | ) | [protected] |
Definition at line 315 of file splitViewInterface.cpp.
References DRAG_SPLIT, mouseMode, and nearSplitPoint().
00316 { 00317 //if within threshold of split point enter drag split mode 00318 if( nearSplitPoint(e->pos()) ) 00319 mouseMode = DRAG_SPLIT; 00320 }
void SplitViewInterface::mouseReleaseEvent | ( | QMouseEvent * | ) | [protected] |
Definition at line 375 of file splitViewInterface.cpp.
References currentMouseShape, DRAG_SPLIT, mouseMode, nearSplitPoint(), and NO_EFFECT_ON_SPLIT.
00376 { 00377 //disable dragging 00378 mouseMode = NO_EFFECT_ON_SPLIT; 00379 00380 //update mouse cursor if necessary 00381 if( !nearSplitPoint(e->pos()) && currentMouseShape == DRAG_SPLIT ) 00382 { 00383 currentMouseShape = NO_EFFECT_ON_SPLIT; 00384 setCursor( Qt::ArrowCursor ); 00385 } 00386 }
void SplitViewInterface::mouseMoveEvent | ( | QMouseEvent * | e | ) | [protected] |
Definition at line 322 of file splitViewInterface.cpp.
References adjustedString, currentMouseShape, displayToWorld(), DRAG_SPLIT, dragOffset, getCursor(), height, mouseMode, MOVE_HOR_CURSOR, MOVE_VERT_CURSOR, nearSplitPoint(), NO_EFFECT_ON_SPLIT, origImage, originalString, TEXT_BACKGROUND_MARGIN, TEXT_INSET, textFont, and width.
00323 { 00324 //if not dragging split point update mosue cursor 00325 if(mouseMode == NO_EFFECT_ON_SPLIT) 00326 { 00327 if( !nearSplitPoint(e->pos()) && currentMouseShape == DRAG_SPLIT ) 00328 { 00329 currentMouseShape = NO_EFFECT_ON_SPLIT; 00330 setCursor( Qt::ArrowCursor ); 00331 } 00332 else if( nearSplitPoint(e->pos()) && currentMouseShape == NO_EFFECT_ON_SPLIT ) 00333 { 00334 currentMouseShape = DRAG_SPLIT; 00335 if( origImage.width() > origImage.height() ) 00336 { 00337 setCursor( getCursor(MOVE_HOR_CURSOR) ); 00338 } 00339 else 00340 { 00341 setCursor( getCursor(MOVE_VERT_CURSOR) ); 00342 } 00343 } 00344 00345 return; 00346 } 00347 00348 //compute painting offset, get important mouse 00349 //coordinate and clamp to valid range 00350 QFontMetrics fm( textFont ); 00351 int paintingOffset; 00352 int mousePos; 00353 if(origImage.width() > origImage.height()) 00354 { 00355 paintingOffset = (width() - origImage.width()) / 2; 00356 mousePos = e->pos().x(); 00357 mousePos = QMAX( mousePos, paintingOffset + 4*TEXT_BACKGROUND_MARGIN + fm.width(originalString) ); 00358 mousePos = QMIN( mousePos, paintingOffset + origImage.width() - 00359 fm.width(adjustedString) - 2*TEXT_BACKGROUND_MARGIN - 2*TEXT_INSET); 00360 } 00361 else 00362 { 00363 paintingOffset = (height() - origImage.height()) / 2; 00364 mousePos = e->pos().y(); 00365 mousePos = QMAX( mousePos, paintingOffset + 4*TEXT_BACKGROUND_MARGIN + fm.height() ); 00366 mousePos = QMIN( mousePos, paintingOffset + origImage.height() - 00367 fm.height() - 2*TEXT_BACKGROUND_MARGIN - 2*TEXT_INSET); 00368 } 00369 00370 //update location of split point and repaint 00371 dragOffset = displayToWorld(mousePos - paintingOffset); 00372 repaint(false); 00373 }
virtual void SplitViewInterface::resizeEvent | ( | QResizeEvent * | ) | [protected, pure virtual] |
Implemented in PanningPreviewInterface, and ScaledPreviewInterface.
double SplitViewInterface::displayToWorld | ( | int | coordinate | ) | [private] |
convert display coordinates to world coordinates (double from 0.0 - 1.0)
Definition at line 388 of file splitViewInterface.cpp.
References origImage.
Referenced by mouseMoveEvent().
00389 { 00390 if( origImage.width() > origImage.height() ) 00391 { return ((double) (coordinate+1))/origImage.width(); } 00392 else 00393 { return ((double) (coordinate+1))/origImage.height(); } 00394 }
int SplitViewInterface::worldToDisplay | ( | double | coordinate | ) | [private] |
convert world coordinates to display coordinates (int from 0 to origImage width-1)
Definition at line 396 of file splitViewInterface.cpp.
References origImage.
Referenced by nearSplitPoint(), and paintEvent().
00397 { 00398 if( origImage.width() > origImage.height() ) 00399 { return (int) (coordinate*(origImage.width() -1) ); } 00400 else 00401 { return (int) (coordinate*(origImage.height()-1) ); } 00402 }
bool SplitViewInterface::nearSplitPoint | ( | QPoint | p | ) | [private] |
determines if mouse is near split point
Definition at line 287 of file splitViewInterface.cpp.
References DRAG_THRESHOLD, dragOffset, height, origImage, previewMode, SPLIT_VIEW, width, and worldToDisplay().
Referenced by mouseMoveEvent(), mousePressEvent(), and mouseReleaseEvent().
00288 { 00289 //always false if not in split view mode 00290 if( previewMode != SPLIT_VIEW ) 00291 return false; 00292 00293 //compute painting offset and get important mouse coordinate 00294 int paintingOffset; 00295 int mousePos; 00296 if(origImage.width() > origImage.height()) 00297 { 00298 paintingOffset = (width() - origImage.width()) / 2; 00299 mousePos = p.x(); 00300 } 00301 else 00302 { 00303 paintingOffset = (height() - origImage.height()) / 2; 00304 mousePos = p.y(); 00305 } 00306 00307 //convert drag offset to display coordinates 00308 int displayCoor = worldToDisplay( dragOffset) + paintingOffset; 00309 00310 //check if within threshold of split point 00311 return ( mousePos > displayCoor - DRAG_THRESHOLD && 00312 mousePos < displayCoor + DRAG_THRESHOLD); 00313 }
PREVIEW_MODE SplitViewInterface::previewMode [private] |
Current display setting (adjusted or split screen).
Definition at line 86 of file splitViewInterface.h.
Referenced by nearSplitPoint(), paintEvent(), setPreviewMode(), and SplitViewInterface().
bool SplitViewInterface::forceDrawLabel [private] |
Draw original/adjusted lables outside of split view mode?
Definition at line 89 of file splitViewInterface.h.
Referenced by paintEvent(), and SplitViewInterface().
QString SplitViewInterface::originalString [private] |
Original and adjusted strings.
Definition at line 92 of file splitViewInterface.h.
Referenced by minimumSizeHint(), mouseMoveEvent(), paintEvent(), and SplitViewInterface().
QString SplitViewInterface::adjustedString [private] |
Definition at line 93 of file splitViewInterface.h.
Referenced by minimumSizeHint(), mouseMoveEvent(), paintEvent(), and SplitViewInterface().
QFont SplitViewInterface::textFont [private] |
Larger font used for drawing text.
Definition at line 96 of file splitViewInterface.h.
Referenced by minimumSizeHint(), mouseMoveEvent(), paintEvent(), and SplitViewInterface().
double SplitViewInterface::dragOffset [private] |
x (or y) coordinate of split between drawn adjusted and original images
Definition at line 99 of file splitViewInterface.h.
Referenced by mouseMoveEvent(), nearSplitPoint(), paintEvent(), and SplitViewInterface().
current mouse move mode
Definition at line 102 of file splitViewInterface.h.
Referenced by mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and SplitViewInterface().
current mouse shape.
by caching this value we avoid resetting the mouse cursor every time it moves etc.
Definition at line 106 of file splitViewInterface.h.
Referenced by mouseMoveEvent(), mouseReleaseEvent(), and SplitViewInterface().
QImage SplitViewInterface::origImage [private] |
Scaled original image.
Definition at line 109 of file splitViewInterface.h.
Referenced by displayToWorld(), getOrigImage(), mouseMoveEvent(), nearSplitPoint(), paintEvent(), and worldToDisplay().
QImage SplitViewInterface::adjustedImage [private] |
Scaled adjusted image.
Definition at line 112 of file splitViewInterface.h.
Referenced by paintEvent().