#include "BaseWidget.h" #include "util.h" #include <QColorDialog> #include <QImageReader> #include <QMessageBox> BaseWidget::BaseWidget( char* l1, char* l2 ) { p1 = new MiniMap; p2 = new MiniMap; QImageReader r1( l1 ); leg1 = r1.read(); QImageReader r2( l2 ); leg2 = r2.read(); if ( leg1.isNull() ) QMessageBox::critical( this, "CALAMARI error", "Unable to load " + QString(l1) + "\n" + r1.errorString() ); if ( leg2.isNull() ) QMessageBox::critical( this, "CALAMARI error", "Unable to load " + QString(l2) + "\n" + r2.errorString() ); if ( leg1.isNull() || leg2.isNull() ) exit( 1 ); if ( leg1.size() != leg2.size() ) { QMessageBox::warning( this, "CALAMARI warning", "The dimensions of these images are different. For diff purposes, " + QString(l1) + " has been scaled to match " + QString(l2) + "." ); leg1 = leg1.scaled( leg2.size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); } p1->setImage( &leg1 ); p1->setInfo( imageInfo( l1, leg1.size() ) ); p2->setImage( &leg2 ); p2->setInfo( imageInfo( l2, leg2.size() ) ); initBaseWidget(); } BaseWidget::BaseWidget( QImage l1, QImage l2 ) { p1 = new MiniMap; p2 = new MiniMap; leg1 = l1; leg2 = l2; p1->setImage( &leg1 ); p2->setImage( &leg2 ); initBaseWidget(); } void BaseWidget::initBaseWidget() { QGridLayout* l = new QGridLayout( this ); l->addWidget( p1, 0, 0 ); l->addWidget( p2, 1, 0 ); p1->setMinimumSize( 100, 100 ); p2->setMinimumSize( 100, 100 ); connect( p1, SIGNAL(info(QString)), this, SLOT(message(QString)) ); connect( p2, SIGNAL(info(QString)), this, SLOT(message(QString)) ); slider = new QSlider( Qt::Vertical ); QVBoxLayout* sl = new QVBoxLayout; l->addLayout( sl, 0, 1, 2, 1 ); sl->addStretch( 1 ); sl->addWidget( slider ); sl->setStretchFactor( slider, 2 ); sl->addStretch( 1 ); connect( p1, SIGNAL(pressed()), this, SLOT(useLeg1()) ); connect( p2, SIGNAL(pressed()), this, SLOT(useLeg2()) ); main_l = new QHBoxLayout; l->addLayout( main_l, 0, 2, 2, 1 ); scroll = new HandyScrollArea; main_l->addWidget( scroll ); scroll->setBackgroundRole( QPalette::Dark ); scroll->hide(); l->setColumnStretch( 0, 1 ); l->setColumnStretch( 2, 2 ); main = 0x0; //must be filled in by subclass } BaseWidget::~BaseWidget(void) { } void BaseWidget::setMaskColor( QColor c ) { if ( !main ) return; main->setMaskColor( c ); } void BaseWidget::message( QString m ) { emit showMessage( m, 0 ); } void BaseWidget::setScale( double s ) { if ( !main ) return; if ( !s && scroll->isVisible() ) { scroll->takeWidget(); main_l->addWidget( main ); scroll->hide(); disconnect( scroll, SIGNAL( scrolledTo(double,double,double,double) ), p1, SLOT( setView(double,double,double,double) ) ); disconnect( scroll, SIGNAL( scrolledTo(double,double,double,double) ), p2, SLOT( setView(double,double,double,double) ) ); disconnect( p1, SIGNAL( mouseAt(double,double) ), scroll, SLOT( scrollTo(double,double) ) ); disconnect( p2, SIGNAL( mouseAt(double,double) ), scroll, SLOT( scrollTo(double,double) ) ); p1->setVeil( false ); p2->setVeil( false ); } else if ( s && !scroll->isVisible() ) { main_l->removeWidget( main ); scroll->setWidget( main ); scroll->show(); connect( scroll, SIGNAL( scrolledTo(double,double,double,double) ), p1, SLOT( setView(double,double,double,double) ) ); connect( scroll, SIGNAL( scrolledTo(double,double,double,double) ), p2, SLOT( setView(double,double,double,double) ) ); connect( p1, SIGNAL( mouseAt(double,double) ), scroll, SLOT( scrollTo(double,double) ) ); connect( p2, SIGNAL( mouseAt(double,double) ), scroll, SLOT( scrollTo(double,double) ) ); p1->setVeil( true ); p2->setVeil( true ); } main->setScale( s ); if ( s ) { scroll->refresh(); p1->update(); p2->update(); } } void BaseWidget::useLeg1() { slider->setValue( 255 ); } void BaseWidget::useLeg2() { slider->setValue( 0 ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 5552 | Sam Stafford |
Use a QImageReader when reading in the two "leg" images, and send errorString() to the user if the image fails to load. |
||
#3 | 5539 | Sam Stafford | Kick off another window to merge alpha channels, if present. | ||
#2 | 5512 | Sam Stafford | UI reshuffling - pushed stencil-related options into a dialog. | ||
#1 | 5508 | Sam Stafford | Infrastructure massaging to make way for Stage Two. |