00001 #include "bandchooserdlg.h" 00002 #include "TraceLog.h" 00003 00004 00005 BandChooserDlg::BandChooserDlg( QWidget *parent, 00006 Image *img ) 00007 : QWidget( parent ), mImg( img ) { 00008 setCaption( "Band Chooser" ); // LABEL THE WINDOW 00009 00010 00011 // CREATE THE MAIN LAYOUT 00012 QVBoxLayout *vblMainLayout = new QVBoxLayout( this ); 00013 vblMainLayout->setAutoAdd( true ); 00014 00015 createIconSets(); 00016 00017 // CLEAR THE CURRENT COLOR 00018 mCurColor = -1; 00019 00020 // CLEAR THE SELECTED BAND SET 00021 mBandSel[0] = 0; 00022 mBandSel[1] = 0; 00023 mBandSel[2] = 0; 00024 00025 // CREATE AND ADD HEADER TO BAND LIST 00026 mList = new QListView( this ); 00027 mList->addColumn( "Color" ); 00028 mList->addColumn( "Name" ); 00029 mList->addColumn( "Dimension" ); 00030 mList->addColumn( "Datatype" ); 00031 mList->setSorting( -1 ); 00032 00033 00034 // ADD EVENT HANDLER FOR BAND SELECTION CHANGE 00035 /* 00036 connect( mList, 00037 SIGNAL( currentChanged( QListViewItem* ) ), 00038 this, 00039 SLOT( setColor( QListViewItem*) ) ); 00040 */ 00041 connect( mList, 00042 SIGNAL( clicked( QListViewItem* ) ), 00043 this, 00044 SLOT( setColor( QListViewItem*) ) ); 00045 00046 // CREATE COLOR SELECT SECTION 00047 QHGroupBox *grpbox = new QHGroupBox( this ); 00048 QButtonGroup *cgGroup = new QButtonGroup( NULL ); 00049 mRgbGroup = new QButtonGroup( NULL ); 00050 00051 mRgbGroup->setExclusive( true ); 00052 cgGroup->setExclusive( true ); 00053 00054 QHBox *hbox = new QHBox( grpbox ); 00055 hbox->setMaximumWidth( 150 ); 00056 mRadColor = new QRadioButton( "Color", hbox ); 00057 cgGroup->insert( mRadColor, 0 ); 00058 00059 mButRed = new QPushButton( "", hbox ); 00060 mButRed->setToggleButton( true ); 00061 mButRed->setMaximumSize( 25, 25 ); 00062 mButRed->setPixmap( mColorIcon[0] ); 00063 mRgbGroup->insert( mButRed, 0 ); 00064 00065 mButGreen = new QPushButton( "", hbox ); 00066 mButGreen->setToggleButton( true ); 00067 mButGreen->setPixmap( mColorIcon[1] ); 00068 mButGreen->setMaximumSize( 25, 25 ); 00069 mRgbGroup->insert( mButGreen, 1 ); 00070 00071 mButBlue = new QPushButton( "", hbox ); 00072 mButBlue->setToggleButton( true ); 00073 mButBlue->setPixmap( mColorIcon[2] ); 00074 mButBlue->setMaximumSize( 25, 25 ); 00075 mRgbGroup->insert( mButBlue, 2 ); 00076 00077 mRadGrey = new QRadioButton( "Greyscale", grpbox ); 00078 mRadGrey->setChecked( true ); 00079 cgGroup->insert( mRadGrey, 1 ); 00080 00081 00082 // ADD EVENT HANDLER FOR SHADE CHANGE 00083 connect( cgGroup, SIGNAL( clicked( int ) ), this, SLOT( toggleShade( int ) ) ); 00084 00085 // ADD EVENT HANDLER FOR COLOR CHANGE 00086 connect( mRgbGroup, SIGNAL( clicked( int ) ), this, SLOT( colorChanged( int ) ) ); 00087 00088 // CREATE BUTTONS TO DISPLAY IMAGE OR CLOSE BAND CHOOSER 00089 QPushButton *butDisplay = new QPushButton( "Load Bands", this ); 00090 connect( butDisplay, SIGNAL( clicked() ), this, SLOT( loadBands() ) ) ; 00091 00092 // INITIALIZE COLOR SELECTION TO GREYSCALE 00093 toggleShade( 1 ); 00094 } 00095 00096 00097 void BandChooserDlg::createIconSets( ) { 00098 int w = 16; 00099 int h = 16; 00100 00101 QPixmap *pix = new QPixmap( w, h ); 00102 QPainter p1( pix ); 00103 p1.fillRect( 0, 0, w, h, QBrush( red ) ); 00104 mColorIcon[0] = *pix; 00105 00106 pix = new QPixmap( w, h ); 00107 QPainter p2( pix ); 00108 p2.fillRect( 0, 0, w, h, QBrush( green ) ); 00109 mColorIcon[1] = *pix; 00110 00111 pix = new QPixmap( w, h ); 00112 QPainter p3( pix ); 00113 p3.fillRect( 0, 0, w, h, QBrush( blue ) ); 00114 mColorIcon[2] = *pix; 00115 00116 pix = new QPixmap( w, h ); 00117 QPainter p4( pix ); 00118 p4.fillRect( 0, 0, w, h, QBrush( QColor( 100, 100, 100 ) ) ); 00119 mColorIcon[3] = *pix; 00120 00121 } 00122 00123 void BandChooserDlg::loadBands( ) { 00124 bool validSet = true; 00125 char *errmsg = "Error: Please choose a valid set of bands to be displayed"; 00126 00127 // TEST FOR COLOR 00128 if ( mColor ) { 00129 errmsg = "Unable to display image. Please choose bands for RGB display."; 00130 00131 // TEST FOR VALID RGB SELECTION 00132 if ( mBandSel[0] == -1 || mBandSel[1] == -1 || mBandSel[2] == -1 ) { 00133 validSet = false; 00134 } 00135 } 00136 else { 00137 errmsg = "Can not display image. Please choose a band for greyscale display."; 00138 00139 // TEST FOR VALID GREYSCALE SELECTION 00140 if ( mBandSel[0] == -1 ) { 00141 validSet = false; 00142 } 00143 } 00144 00145 // DISPLAY ERROR MSG IF INVALID 00146 if ( !validSet ) { 00147 QMessageBox::information( NULL, "Display Error", errmsg ); 00148 return; 00149 } 00150 00151 ImageState is; 00152 is.mRed = mBandSel[0]; 00153 is.mGreen = mBandSel[1]; 00154 is.mBlue = mBandSel[2]; 00155 is.mColor = mColor; 00156 mImg->setBandSel( is ); 00157 00158 // SEND BAND SELECTION CHANGED SIGNAL 00159 emit selBandsChanged(); 00160 // mViewSet->redrawViews(); 00161 00162 } 00163 00164 00165 void BandChooserDlg::reloadList( ) { 00166 char buf[100]; // STRING BUFFER 00167 std::vector<ImageFormat::BandInf> &bandinf = mImg->getBandInfSet(); 00168 // CLEAR THE LIST 00169 mList->clear(); 00170 00171 // ---------------------------------------------------------- 00172 // LOAD ALL AVAILABLE BANDS 00173 for ( int iband=(int)bandinf.size()-1; iband > -1; iband-- ) { 00174 int w, h; 00175 std::string name; 00176 std::string dtype; 00177 std::string sdims; 00178 00179 // ---------------------------------------------------------- 00180 // GET DATA FROM BAND AND CREATE STRING 00181 w = bandinf[iband].width; 00182 h = bandinf[iband].height; 00183 name = bandinf[iband].name; 00184 dtype = ImageFormat::dtypeToString( bandinf[iband].type ); 00185 00186 sprintf( buf, "%d x %d", w, h ); 00187 sdims = buf; 00188 00189 // ---------------------------------------------------------- 00190 00191 // ---------------------------------------------------------- 00192 // CREATE NEW ITEM & INSERT INTO LIST 00193 QListViewItem *item = new QListViewItem( mList, 00194 "", 00195 name.c_str(), 00196 sdims.c_str(), 00197 dtype.c_str() ); 00198 00199 mList->insertItem( item ); 00200 // ---------------------------------------------------------- 00201 } 00202 // ---------------------------------------------------------- 00203 } 00204 00205 00206 00207 void BandChooserDlg::toggleShade( int col ) { 00208 QListViewItem* ili = NULL; // LIST ITEM INDEX 00209 00210 // ASSIGN TO LOCAL MEMBER 00211 mColor = !(bool)col; 00212 00213 // CLEAR IMAGE SELECTIONS 00214 mBandSel[0] = -1; 00215 mBandSel[1] = -1; 00216 mBandSel[2] = -1; 00217 00218 00219 // SET THE COLOR COLUMN OF THE LIST TO "" FOR ALL BANDS 00220 ili = mList->firstChild(); 00221 while ( ili ) { 00222 ili->setText( 0, "" ); 00223 ili = ili->nextSibling(); 00224 } 00225 00226 // TOGGLE ENABLED STATE OF RADIO BUTTON GROUP 00227 mButRed->setEnabled( mColor ); 00228 mButGreen->setEnabled( mColor ); 00229 mButBlue->setEnabled( mColor ); 00230 00231 00232 // SET RED RADIO BUTTON AS THE CHECKED BUTTON 00233 mRgbGroup->setButton( 0 ); 00234 00235 00236 // SET THE CURRENT SELECTED COLOR TO RED (NOT SURE IF THIS IS NECESSARY) 00237 if ( !mColor ) 00238 mCurColor = 0; 00239 00240 reloadList(); 00241 } 00242 00243 00244 00245 void BandChooserDlg::colorChanged( int color ) { 00246 // ASSIGN THE COLOR TO MEMBER 00247 mCurColor = color; 00248 } 00249 00250 void BandChooserDlg::setColor( QListViewItem* selItem ) { 00251 QListViewItem *ili = NULL; // LOOP INDEX 00252 int count = 0; 00253 00254 if ( mBlockSig ) { 00255 mBlockSig = false; 00256 } else { 00257 // GET THE CURRENT SELECTED ITEM 00258 if ( selItem == NULL ) 00259 return; 00260 00261 // ---------------------------------------------------------- 00262 // CLEAR COLOR COLUMN FOR SELECTED BAND 00263 QPixmap pix; 00264 ili = mList->firstChild(); 00265 while ( ili ) { 00266 if ( ili == selItem ) { 00267 if ( mColor ) { 00268 if ( mBandSel[0] == count ) 00269 mBandSel[0] = -1; 00270 else if ( mBandSel[1] == count ) 00271 mBandSel[1] = -1; 00272 else if ( mBandSel[2] == count ) 00273 mBandSel[2] = -1; 00274 00275 mBandSel[mCurColor] = count; 00276 } else 00277 mBandSel[0] = mBandSel[1] = mBandSel[2] = count; 00278 } 00279 00280 ili->setPixmap( 0, pix ); 00281 ili = ili->nextSibling(); 00282 count++; 00283 } 00284 00285 count = 0; 00286 ili = mList->firstChild(); 00287 while ( ili ) { 00288 if ( count == mBandSel[0] ) { 00289 if ( mColor ) { 00290 ili->setPixmap( 0, mColorIcon[0] ); 00291 } else { 00292 ili->setPixmap( 0, mColorIcon[3] ); 00293 break; 00294 } 00295 } else if ( count == mBandSel[1] ) { 00296 ili->setPixmap( 0, mColorIcon[1] ); 00297 } else if ( count == mBandSel[2] ) { 00298 ili->setPixmap( 0, mColorIcon[2] ); 00299 } 00300 count++; 00301 ili = ili->nextSibling(); 00302 } 00303 // ---------------------------------------------------------- 00304 00305 if ( mColor ) { 00306 00307 mCurColor++; 00308 if ( mCurColor > 2 ) 00309 mCurColor = 0; 00310 mRgbGroup->setButton( mCurColor ); 00311 } 00312 //mBlockSig = true; 00313 } 00314 mList->setSelected( selItem, false ); 00315 } 00316 00317 00318 00319 00320
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |