QtImageStack.Q
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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
00057
00058
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
00095 for (unsigned int i = 0; i < this->entries.size(); ++i)
00096 if (this->entries[i].name.compare(name) == 0)
00097
00098 return &(this->entries[i]);
00099
00100
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
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
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
00252
00253
00254
00255
00256
00257 #endif // GUI_QTIMAGESTACK_Q_DEFINED