// SquidMainWindow.cpp: implementation of the SquidMainWindow class. // ////////////////////////////////////////////////////////////////////// #include <qapplication.h> #include <qimage.h> #include <qlayout.h> #include <qmainwindow.h> #include <qmenubar.h> #include <qmessagebox.h> #include <qpainter.h> #include <qscrollview.h> #include <qsettings.h> #include <qsizegrip.h> #include <qsplitter.h> #include <qtoolbutton.h> #include <qwmatrix.h> #include "SquidPortrait.h" #include "SquidStaticPane.h" #include "SquidDynamicPane.h" #include "SquidDiffBlocker.h" #include "SquidPrefsDialog.h" #include "SquidAbout.h" #include "img/qembed_images.h" #define SQUIDMAINWINDOW_H #include "SquidMainWindow.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// SquidMainWindow::SquidMainWindow ( QImage* file1, QImage* file2, QString n1, QString n2 ) : QMainWindow( NULL ), zoom ( 1.0 ), dblocks( NULL ) { setCaption( n1 + " <-> " + n2 + " - SQUID" ); setIcon( QPixmap( qembed_findImage( "squid" ) ) ); if ( file1->depth() < 32 ) *file1 = file1->convertDepth( 32 ); if ( file2->depth() < 32 ) *file2 = file2->convertDepth( 32 ); QWidget* mainwidget = new QWidget( this ); setCentralWidget( mainwidget ); QGridLayout* layout = new QGridLayout( mainwidget, 3, 2 ); layout->setRowStretch( 1, 1 ); layout->setColStretch( 0, 1 ); sp = new QSplitter( mainwidget ); layout->addWidget( sp, 1, 0 ); hscroll = new QScrollBar( 0, 99, 10, 10, 0, Horizontal, mainwidget ); vscroll = new QScrollBar( 0, 99, 10, 10, 0, Vertical, mainwidget ); hscroll->show(); vscroll->show(); layout->addWidget( hscroll, 2, 0 ); layout->addWidget( vscroll, 1, 1 ); QSizeGrip* grip = new QSizeGrip( mainwidget ); layout->addWidget( grip, 2, 1 ); f1 = new SquidStaticPane( sp, file1, n1 ); di = new SquidDynamicPane( sp, file1, file2 ); f2 = new SquidStaticPane( sp, file2, n2 ); if ( f1->maximumHeight() < f2->maximumHeight() ) f1->setMaximumHeight( f2->maximumHeight() ); if ( f2->maximumHeight() < f1->maximumHeight() ) f2->setMaximumHeight( f1->maximumHeight() ); sp->setResizeMode( f1, QSplitter::Stretch ); sp->setResizeMode( f2, QSplitter::Stretch ); sp->setResizeMode( di, QSplitter::Stretch ); connect( hscroll, SIGNAL( valueChanged( int ) ), this, SLOT( HScroll( int ) ) ); connect( vscroll, SIGNAL( valueChanged( int ) ), this, SLOT( VScroll( int ) ) ); while ( di->maximumWidth() < 99 || di->maximumHeight() < 99 ) ZoomIn(); InitToolBar(); connect( qApp, SIGNAL( aboutToQuit() ), this, SLOT( SaveSettings() ) ); show(); LoadSettings(); SetMaxSize(); if ( maximumWidth() < 1200 && maximumHeight() < 1000 ) resize( maximumSize() ); else showMaximized(); } SquidMainWindow::~SquidMainWindow() { } void SquidMainWindow::LoadSettings() { QSettings settings; settings.insertSearchPath( QSettings::Windows, "/Perforce" ); QRgb bkcol = settings.readNumEntry ( "/SQUID/bkcol", f1->scroll->viewport()->backgroundColor().rgb() ); SetBGColor( bkcol ); dtolnc = settings.readNumEntry( "/SQUID/dtolnc", 0 ); minblocksize = settings.readNumEntry( "/SQUID/mbs", 10 ); int bsize = settings.readNumEntry( "/SQUID/bsize", 100000 ); di->SetBlendSize( bsize ); di->GenDiffMask( dtolnc ); bool fb1, fb2, dbi; fb1 = settings.readBoolEntry( "/SQUID/f1", true ); fb2 = settings.readBoolEntry( "/SQUID/f2", true ); dbi = settings.readBoolEntry( "/SQUID/di", true ); if ( !fb1 ) ToggleF1( false ); if ( !fb2 ) ToggleF2( false ); if ( !dbi ) ToggleDiff( false ); } void SquidMainWindow::SaveSettings() { QSettings settings; settings.insertSearchPath( QSettings::Windows, "/Perforce" ); settings.writeEntry ( "/SQUID/bkcol", (int)f1->scroll->viewport()->backgroundColor().rgb() ); settings.writeEntry( "/SQUID/dtolnc", dtolnc ); settings.writeEntry( "/SQUID/mbs", minblocksize ); settings.writeEntry( "/SQUID/bsize", di->blendsize ); settings.writeEntry( "/SQUID/f1", f1b->isOn() ); settings.writeEntry( "/SQUID/f2", f2b->isOn() ); settings.writeEntry( "/SQUID/di", dib->isOn() ); } void SquidMainWindow::resizeEvent( QResizeEvent* e ) { QMainWindow::resizeEvent( e ); int mw1 = f1->maximumWidth(); int mw2 = f2->maximumWidth(); int mwd = di->maximumWidth(); int dw1 = mw1 - f1->width(); int dw2 = mw2 - f2->width(); int dwd = mwd - di->width(); if ( !f1->isVisible() ) dw1 = 0; if ( !f2->isVisible() ) dw2 = 0; if ( !di->isVisible() ) dwd = 0; int dw = dwd; int mw = mwd; if ( dw1 > dw ) { dw = dw1; mw = mw1; } if ( dw2 > dw ) { dw = dw2; mw = mw2; } int dh = di->maximumHeight() - di->height(); hscroll->setRange( 0, dw ); hscroll->setPageStep( mw - dw ); if ( !dw ) hscroll->hide(); else hscroll->show(); vscroll->setRange( 0, dh ); vscroll->setPageStep( di->height() ); if ( !dh ) vscroll->hide(); else vscroll->show(); } void SquidMainWindow::HScroll( int x ) { //Convert x into a percent and pass to each pane. if ( !hscroll->maxValue() ) return; x *= 100; x /= hscroll->maxValue(); f1->HScroll( x ); f2->HScroll( x ); di->HScroll( x ); } void SquidMainWindow::VScroll( int y ) { //Convert y into a percent and pass to each pane. if ( !vscroll->maxValue() ) return; y *= 100; y /= vscroll->maxValue(); f1->VScroll( y ); f2->VScroll( y ); di->VScroll( y ); } void SquidMainWindow::SetMaxSize() { sp->refresh(); int w = sp->maximumWidth() + 20; int h = sp->maximumHeight() + 50; setMaximumSize( w, h ); resizeEvent( NULL ); } void SquidMainWindow::InitToolBar() { toolbar = new QToolBar( this ); toolbar->show(); QIconSet f1is; f1is.setPixmap ( QPixmap( qembed_findImage( "f1on" ) ), QIconSet::Large, QIconSet::Normal, QIconSet::On ); f1is.setPixmap ( QPixmap( qembed_findImage( "f1off" ) ), QIconSet::Large, QIconSet::Normal, QIconSet::Off ); f1b = new QToolButton ( f1is, f1->name, QString::null, this, "ToggleF1", toolbar, "file1" ); QIconSet diis; diis.setPixmap ( QPixmap( qembed_findImage( "dion" ) ), QIconSet::Large, QIconSet::Normal, QIconSet::On ); diis.setPixmap ( QPixmap( qembed_findImage( "dioff" ) ), QIconSet::Large, QIconSet::Normal, QIconSet::Off ); dib = new QToolButton ( diis, "Diff View", QString::null, this, "ToggleDiff", toolbar, "diff" ); QIconSet f2is; f2is.setPixmap ( QPixmap( qembed_findImage( "f2on" ) ), QIconSet::Large, QIconSet::Normal, QIconSet::On ); f2is.setPixmap ( QPixmap( qembed_findImage( "f2off" ) ), QIconSet::Large, QIconSet::Normal, QIconSet::Off ); f2b = new QToolButton ( f2is, f2->name, QString::null, NULL, "", toolbar, "file2" ); f1b->setToggleButton( true ); f2b->setToggleButton( true ); dib->setToggleButton( true ); f1b->setOn( true ); f2b->setOn( true ); dib->setOn( true ); connect ( f1b, SIGNAL( toggled( bool ) ), this, SLOT( ToggleF1( bool ) ) ); connect ( f2b, SIGNAL( toggled( bool ) ), this, SLOT( ToggleF2( bool ) ) ); connect ( dib, SIGNAL( toggled( bool ) ), this, SLOT( ToggleDiff( bool ) ) ); dib->setTextLabel( "Diff View" ); toolbar->addSeparator(); QIconSet subis; subis.setPixmap ( QPixmap( qembed_findImage( "sub" ) ), QIconSet::Large, QIconSet::Normal ); mask = new QToolButton ( subis, "Subtract Identical", QString::null, NULL, "", toolbar ); mask->setToggleButton( true ); connect( mask, SIGNAL( toggled( bool ) ), this, SLOT( ToggleMask( bool ) ) ); QIconSet blis; blis.setPixmap ( QPixmap( qembed_findImage( "block" ) ), QIconSet::Large, QIconSet::Normal ); QToolButton* blocks = new QToolButton ( blis, "Highlight Diffs", QString::null, NULL, "", toolbar ); blocks->setToggleButton( true ); connect( blocks, SIGNAL( toggled( bool ) ), this, SLOT( ToggleBlocks( bool ) ) ); if ( f1->pic->image->size() != f2->pic->image->size() ) blocks->setEnabled( false ); toolbar->addSeparator(); QIconSet zinis; zinis.setPixmap ( QPixmap( qembed_findImage( "zin" ) ), QIconSet::Large, QIconSet::Normal ); QToolButton* zin = new QToolButton ( zinis, "Zoom In", QString::null, NULL, "", toolbar ); connect( zin, SIGNAL( clicked() ), this, SLOT( ZoomIn() ) ); QIconSet zoutis; zoutis.setPixmap ( QPixmap( qembed_findImage( "zout" ) ), QIconSet::Large, QIconSet::Normal ); QToolButton* zout = new QToolButton ( zoutis, "Zoom Out", QString::null, NULL, "", toolbar ); connect( zout, SIGNAL( clicked() ), this, SLOT( ZoomOut() ) ); toolbar->addSeparator(); QIconSet pris; pris.setPixmap ( QPixmap( qembed_findImage( "prefs" ) ), QIconSet::Large, QIconSet::Normal ); QToolButton* prefs = new QToolButton ( pris, "Settings", QString::null, NULL, "", toolbar ); connect( prefs, SIGNAL( clicked() ), this, SLOT( Prefs() ) ); QIconSet sidis; sidis.setPixmap ( QPixmap( qembed_findImage( "squid" ) ), QIconSet::Large, QIconSet::Normal ); QToolButton* about = new QToolButton ( sidis, "About SQUID", QString::null, NULL, "", toolbar ); connect( about, SIGNAL( clicked() ), this, SLOT( About() ) ); } void SquidMainWindow::ToggleDiff( bool toggle ) { dib->setOn( toggle ); mask->setEnabled( toggle ); if ( toggle ) di->show(); else di->hide(); if ( !( di->isVisible() || f1->isVisible() || f2->isVisible() ) ) { dib->setOn( true ); di->show(); mask->setEnabled( true ); } SetMaxSize(); } void SquidMainWindow::ToggleF1( bool toggle ) { f1b->setOn( toggle ); if ( toggle ) f1->show(); else f1->hide(); if ( !( di->isVisible() || f1->isVisible() || f2->isVisible() ) ) { f1b->setOn( true ); f1->show(); } SetMaxSize(); } void SquidMainWindow::ToggleF2( bool toggle ) { f2b->setOn( toggle ); if ( toggle ) f2->show(); else f2->hide(); if ( !( di->isVisible() || f1->isVisible() || f2->isVisible() ) ) { f2b->setOn( true ); f2->show(); } SetMaxSize(); } void SquidMainWindow::ToggleBlocks( bool blocks ) { if ( !blocks ) { f1->pic->diffs = NULL; f2->pic->diffs = NULL; di->pic->diffs = NULL; QPainter p; f1->pic->drawContents( &p ); f2->pic->drawContents( &p ); di->pic->drawContents( &p ); return; } if ( !dblocks ) { dblocks = new SquidDiffBlocker( 100 ); //arbitrary for ( int x = 0 ; x < di->pic->image->width() ; x++ ) for ( int y = 0; y < di->pic->image->height() ; y++ ) if ( di->diffmask[x][y] ) dblocks->AddPixel( x, y ); dblocks->CleanUp(); } f1->pic->diffs = &(dblocks->list); f2->pic->diffs = &(dblocks->list); di->pic->diffs = &(dblocks->list); QPainter p; f1->pic->drawContents( &p ); f2->pic->drawContents( &p ); di->pic->drawContents( &p ); } void SquidMainWindow::ZoomIn() { zoom *= 2.0; f1->pic->Zoom( zoom ); f2->pic->Zoom( zoom ); di->pic->Zoom( zoom ); di->setMaximumSize( di->pic->maximumWidth() + 4, di->pic->maximumHeight() + 24 ); f1->setMaximumSize( f1->pic->maximumWidth() + 4, f1->pic->maximumHeight() + 24 ); f2->setMaximumSize( f2->pic->maximumWidth() + 4, f2->pic->maximumHeight() + 24 ); SetMaxSize(); } void SquidMainWindow::ZoomOut() { zoom *= 0.5; f1->pic->Zoom( zoom ); f2->pic->Zoom( zoom ); di->pic->Zoom( zoom ); di->setMaximumSize( di->pic->maximumWidth() + 4, di->pic->maximumHeight() + 24 ); f1->setMaximumSize( f1->pic->maximumWidth() + 4, f1->pic->maximumHeight() + 24 ); f2->setMaximumSize( f2->pic->maximumWidth() + 4, f2->pic->maximumHeight() + 24 ); SetMaxSize(); } void SquidMainWindow::Prefs() { QDialog* dia = new SquidPrefsDialog( this ); dia->setIcon( QPixmap( qembed_findImage( "prefs" ) ) ); dia->exec(); delete dia; } void SquidMainWindow::About() { SQUID_ABOUT QMessageBox::about( this, "About SQUID", about ); } void SquidMainWindow::SetBGColor( QRgb col ) { f1->scroll->viewport()->setBackgroundColor( col ); f2->scroll->viewport()->setBackgroundColor( col ); di->scroll->viewport()->setBackgroundColor( col ); } void SquidMainWindow::SetBlendSize( int area ) { di->SetBlendSize( area ); } void SquidMainWindow::SetDiffTol( int rms ) { dtolnc = rms; di->GenDiffMask( rms ); if ( dblocks ) { SquidDiffBlocker* sdb = new SquidDiffBlocker( minblocksize ); for ( int x = 0; x < di->pic->image->width() ; x++ ) { for ( int y = 0; y < di->pic->image->height() ; y++ ) { if ( di->diffmask[x][y] ) sdb->AddPixel( x, y ); } } sdb->CleanUp(); if ( f1->pic->diffs ) { f1->pic->diffs = &( sdb->list ); f2->pic->diffs = &( sdb->list ); di->pic->diffs = &( sdb->list ); } delete dblocks; dblocks = sdb; } } void SquidMainWindow::SetMinBlock( int min ) { minblocksize = min; if ( dblocks ) { SquidDiffBlocker* sdb = new SquidDiffBlocker( minblocksize ); for ( int x = 0; x < di->pic->image->width() ; x++ ) { for ( int y = 0; y < di->pic->image->height() ; y++ ) { if ( di->diffmask[x][y] ) sdb->AddPixel( x, y ); } } sdb->CleanUp(); if ( f1->pic->diffs ) { f1->pic->diffs = &( sdb->list ); f2->pic->diffs = &( sdb->list ); di->pic->diffs = &( sdb->list ); } delete dblocks; dblocks = sdb; } QPainter p; f1->drawContents( &p ); f2->drawContents( &p ); di->pic->drawContents( &p ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 2401 | Sam Stafford |
Rename SID to SQUID - avoids conflicts with another program. Also lets me use cool squid icon. |
||
//guest/sam_stafford/sid/src/SidMainWindow.cpp | |||||
#13 | 2052 | Sam Stafford | An About Box. | ||
#12 | 2050 | Sam Stafford | Settings. | ||
#11 | 2039 | Sam Stafford | Add an ugly window icon. | ||
#10 | 2038 | Sam Stafford |
Fix crashing resulting from invalid image files, and set a good caption on the main window. |
||
#9 | 2037 | Sam Stafford | New icons! | ||
#8 | 2036 | Sam Stafford |
Uber-L33T "highlight" feature. Has to be seen to be believed. |
||
#7 | 2035 | Sam Stafford |
Fix the 32-bit conversion - it wasn't actually happening before (as I found out when I went to go look at a 1-bit image). Also automatically zoom small images to be at least 64 pixels on the screen - anything smaller than that tends to confuse Qt. |
||
#6 | 2034 | Sam Stafford |
Working "subtraction" diff and zooming. Definitely need to make some decent toolbutton icons. |
||
#5 | 2033 | Sam Stafford | Add a toolbar that allows you to turn panes on and off at will. | ||
#4 | 2030 | Sam Stafford |
Scrolling. It's not perfect, but I'm happy enough with it to move on with my life. |
||
#3 | 2028 | Sam Stafford |
Make the "diff" image as large as need be to accomodate both images, in the event of different-sized images. |
||
#2 | 2027 | Sam Stafford | Change SidMainWindow's layout to QGridLayout, in preparation for scrollbars. | ||
#1 | 2016 | Sam Stafford |
Barely-functional Sid (about three hours worth of code). "Sid" = "Sam's Image Differ", for those who were curious. |