00001 /*!@file GUI/QtImageStack.Q */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/GUI/QtImageStack.Q $ 00035 // $Id: QtImageStack.Q 12269 2009-12-17 01:23:34Z itti $ 00036 // 00037 00038 #ifndef GUI_QTIMAGESTACK_Q_DEFINED 00039 #define GUI_QTIMAGESTACK_Q_DEFINED 00040 00041 #ifdef INVT_HAVE_QT3 00042 00043 #include "GUI/QtImageStack.H" 00044 00045 #include "GUI/QtImageFrame.H" 00046 #include "Raster/GenericFrame.H" 00047 #include "Util/Pause.H" 00048 #include "Util/log.H" 00049 00050 #include <qcheckbox.h> 00051 #include <qlistbox.h> 00052 #include <qsplitter.h> 00053 #include <qwidgetstack.h> 00054 #include <vector> 00055 00056 /* TODO: 00057 00058 * change QtImageFrame to have toggles for resizing, zooming, etc. 00059 00060 */ 00061 00062 struct QtImageStack::Impl 00063 { 00064 Impl() 00065 : 00066 pausebutton(0), 00067 listbox(0), 00068 widgstack(0), 00069 isClosed(false), 00070 frameNumber(0), 00071 entries(), 00072 preferredDims(), 00073 preferredMaxDims() 00074 {} 00075 00076 struct Entry 00077 { 00078 Entry(QListBoxItem* listitem_, 00079 QtImageFrame* imageframe_, 00080 std::string name_) 00081 : 00082 listitem(listitem_), 00083 imageframe(imageframe_), 00084 name(name_) 00085 {} 00086 00087 QListBoxItem* listitem; 00088 QtImageFrame* imageframe; 00089 std::string name; 00090 }; 00091 00092 Entry* findOrMakeEntry(const std::string& name) 00093 { 00094 // do we already have an Entry for this name? 00095 for (unsigned int i = 0; i < this->entries.size(); ++i) 00096 if (this->entries[i].name.compare(name) == 0) 00097 // found it: 00098 return &(this->entries[i]); 00099 00100 // ok, no existing Entry, so let's set up a new one: 00101 00102 QListBoxText* t = new QListBoxText(this->listbox, QString(name)); 00103 this->listbox->sort(); 00104 00105 QtImageFrame* f = new QtImageFrame(this->widgstack, 00106 this->preferredDims, 00107 this->preferredMaxDims); 00108 this->widgstack->addWidget(f); 00109 00110 if (this->entries.size() == 0) 00111 { 00112 this->listbox->setCurrentItem(t); 00113 this->widgstack->raiseWidget(f); 00114 } 00115 00116 this->entries.push_back(Impl::Entry(t, f, name)); 00117 00118 return &(this->entries.back()); 00119 } 00120 00121 void removeEntry(const std::string& name) 00122 { 00123 for (unsigned int i = 0; i < this->entries.size(); ++i) 00124 if (this->entries[i].name.compare(name) == 0) 00125 // found it: 00126 { 00127 this->widgstack->removeWidget(this->entries[i].imageframe); 00128 delete this->entries[i].imageframe; 00129 delete this->entries[i].listitem; 00130 this->entries.erase(this->entries.begin() + i); 00131 return; 00132 } 00133 } 00134 00135 QCheckBox* pausebutton; 00136 QListBox* listbox; 00137 QWidgetStack* widgstack; 00138 bool isClosed; 00139 int frameNumber; 00140 std::vector<Entry> entries; 00141 Dims preferredDims; 00142 Dims preferredMaxDims; 00143 }; 00144 00145 QtImageStack::QtImageStack(QWidget* parent) 00146 : 00147 QVBox(parent, "QtImageStack", (WFlags) 0), 00148 rep(new Impl) 00149 { 00150 QHBox* buttons = new QHBox(this); 00151 rep->pausebutton = new QCheckBox(buttons); 00152 rep->pausebutton->setText("Pause (click to pause)"); 00153 rep->pausebutton->setPaletteForegroundColor(QColor(96, 96, 0)); 00154 QFrame* hspacer = new QFrame(buttons); 00155 buttons->setStretchFactor(rep->pausebutton, 0); 00156 buttons->setStretchFactor(hspacer, 1); 00157 00158 connect(rep->pausebutton, SIGNAL(toggled(bool)), 00159 this, SLOT(togglePause(bool))); 00160 00161 QSplitter* splitter = new QSplitter(this); 00162 #if QT_VERSION >= 0x030200 00163 // setChildrenCollapsible() is not present before qt 3.2.0 00164 splitter->setChildrenCollapsible(false); 00165 #endif 00166 rep->listbox = new QListBox(splitter); 00167 rep->widgstack = new QWidgetStack(splitter); 00168 00169 this->setStretchFactor(buttons, 0); 00170 this->setStretchFactor(splitter, 1); 00171 00172 connect(rep->listbox, SIGNAL(highlighted(QListBoxItem*)), 00173 this, SLOT(listSelection(QListBoxItem*))); 00174 } 00175 00176 QtImageStack::~QtImageStack() 00177 { 00178 delete rep; 00179 } 00180 00181 void QtImageStack::addFrame(const GenericFrame& frame, 00182 const std::string& name, 00183 const FrameInfo& auxinfo) 00184 { 00185 Impl::Entry* e = rep->findOrMakeEntry(name); 00186 00187 ASSERT(e != 0); 00188 00189 e->imageframe->setFrame(frame, name, rep->frameNumber, auxinfo); 00190 } 00191 00192 void QtImageStack::removeFrame(const std::string& name) 00193 { 00194 rep->removeEntry(name); 00195 } 00196 00197 bool QtImageStack::setFrameNumber(int n) 00198 { 00199 rep->frameNumber = n; 00200 00201 return true; 00202 } 00203 00204 bool QtImageStack::isClosed() const 00205 { 00206 return rep->isClosed; 00207 } 00208 00209 void QtImageStack::setPreferredDims(const Dims& dims) 00210 { 00211 rep->preferredDims = dims; 00212 } 00213 00214 void QtImageStack::setPreferredMaxDims(const Dims& dims) 00215 { 00216 rep->preferredMaxDims = dims; 00217 } 00218 00219 void QtImageStack::listSelection(QListBoxItem* item) 00220 { 00221 for (unsigned int i = 0; i < rep->entries.size(); ++i) 00222 if (rep->entries[i].listitem == item) 00223 rep->widgstack->raiseWidget(rep->entries[i].imageframe); 00224 } 00225 00226 void QtImageStack::togglePause(bool on) 00227 { 00228 if (on) 00229 { 00230 rep->pausebutton->setText("Paused (click to resume)"); 00231 rep->pausebutton->setPaletteForegroundColor(QColor(0, 96, 0)); 00232 setPause(true); 00233 } 00234 else 00235 { 00236 rep->pausebutton->setText("Pause (click to pause)"); 00237 rep->pausebutton->setPaletteForegroundColor(QColor(96, 96, 0)); 00238 setPause(false); 00239 } 00240 } 00241 00242 void QtImageStack::closeEvent(QCloseEvent* e) 00243 { 00244 QVBox::closeEvent(e); 00245 rep->isClosed = true; 00246 } 00247 00248 #endif // INVT_HAVE_QT3 00249 00250 // ###################################################################### 00251 /* So things look consistent in everyone's emacs... */ 00252 /* Local Variables: */ 00253 /* mode: c++ */ 00254 /* indent-tabs-mode: nil */ 00255 /* End: */ 00256 00257 #endif // GUI_QTIMAGESTACK_Q_DEFINED