TaskView.cpp
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 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <boost/bind.hpp>
00028 #endif
00029
00030 #include "TaskView.h"
00031 #include "TaskDialog.h"
00032 #include "TaskAppearance.h"
00033 #include "TaskEditControl.h"
00034 #include <Gui/Document.h>
00035 #include <Gui/Application.h>
00036 #include <Gui/ViewProvider.h>
00037 #include <Gui/Control.h>
00038
00039 using namespace Gui::TaskView;
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 TaskWidget::TaskWidget( QWidget *parent)
00055 : QWidget(parent)
00056 {
00057
00058 }
00059
00060 TaskWidget::~TaskWidget()
00061 {
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071 TaskBox::TaskBox(const QPixmap &icon, const QString &title, bool expandable, QWidget *parent)
00072 : iisTaskBox(icon, title, expandable, parent), wasShown(false)
00073 {
00074 setScheme(iisFreeCADTaskPanelScheme::defaultScheme());
00075 }
00076
00077 TaskBox::~TaskBox()
00078 {
00079 }
00080
00081 void TaskBox::showEvent(QShowEvent*)
00082 {
00083 wasShown = true;
00084 }
00085
00086 void TaskBox::hideGroupBox()
00087 {
00088 if (!wasShown) {
00089
00090 int h=0;
00091 int ct = groupLayout()->count();
00092 for (int i=0; i<ct; i++) {
00093 QLayoutItem* item = groupLayout()->itemAt(i);
00094 if (item && item->widget()) {
00095 QWidget* w = item->widget();
00096 h += w->height();
00097 }
00098 }
00099
00100 m_tempHeight = m_fullHeight = h;
00101
00102
00103
00104 m_foldDelta = 0;
00105 }
00106 else {
00107 m_tempHeight = m_fullHeight = myGroup->height();
00108 m_foldDelta = m_fullHeight / myScheme->groupFoldSteps;
00109 }
00110
00111 m_foldStep = 0.0;
00112 m_foldDirection = -1;
00113
00114
00115 bool block = myHeader->blockSignals(true);
00116 myHeader->fold();
00117 myHeader->blockSignals(block);
00118
00119 myDummy->setFixedHeight(0);
00120 myDummy->hide();
00121 myGroup->hide();
00122
00123 m_foldPixmap = QPixmap();
00124 setFixedHeight(myHeader->height());
00125 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
00126 }
00127
00128 namespace Gui { namespace TaskView {
00129 class TaskIconLabel : public iisIconLabel {
00130 public:
00131 TaskIconLabel(const QIcon &icon,
00132 const QString &title,
00133 QWidget *parent = 0)
00134 : iisIconLabel(icon, title, parent) {
00135 }
00136 void setTitle(const QString &text) {
00137 myText = text;
00138 update();
00139 }
00140 };
00141 }
00142 }
00143
00144 void TaskBox::actionEvent (QActionEvent* e)
00145 {
00146 QAction *action = e->action();
00147 switch (e->type()) {
00148 case QEvent::ActionAdded:
00149 {
00150 TaskIconLabel *label = new TaskIconLabel(
00151 action->icon(), action->text(), this);
00152 this->addIconLabel(label);
00153 connect(label,SIGNAL(clicked()),action,SIGNAL(triggered()));
00154 break;
00155 }
00156 case QEvent::ActionChanged:
00157 {
00158
00159 QBoxLayout* bl = myGroup->groupLayout();
00160 int index = this->actions().indexOf(action);
00161 if (index < 0) break;
00162 QWidgetItem* item = static_cast<QWidgetItem*>(bl->itemAt(index));
00163 TaskIconLabel* label = static_cast<TaskIconLabel*>(item->widget());
00164 label->setTitle(action->text());
00165 break;
00166 }
00167 case QEvent::ActionRemoved:
00168 {
00169
00170 break;
00171 }
00172 default:
00173 break;
00174 }
00175 }
00176
00177
00178
00179
00180
00181
00182
00183 TaskView::TaskView(QWidget *parent)
00184 : QScrollArea(parent),ActiveDialog(0),ActiveCtrl(0)
00185 {
00186
00187
00188
00189 taskPanel = new iisTaskPanel(this);
00190 taskPanel->setScheme(iisFreeCADTaskPanelScheme::defaultScheme());
00191 this->setWidget(taskPanel);
00192 setWidgetResizable(true);
00193 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00194 this->setMinimumWidth(200);
00195
00196 Gui::Selection().Attach(this);
00197
00198 connectApplicationActiveDocument =
00199 App::GetApplication().signalActiveDocument.connect
00200 (boost::bind(&Gui::TaskView::TaskView::slotActiveDocument, this, _1));
00201 connectApplicationDeleteDocument =
00202 App::GetApplication().signalDeletedDocument.connect
00203 (boost::bind(&Gui::TaskView::TaskView::slotDeletedDocument, this));
00204 }
00205
00206 TaskView::~TaskView()
00207 {
00208 connectApplicationActiveDocument.disconnect();
00209 connectApplicationDeleteDocument.disconnect();
00210 Gui::Selection().Detach(this);
00211 }
00212
00213 void TaskView::keyPressEvent(QKeyEvent* ke)
00214 {
00215 if (ActiveCtrl && ActiveDialog) {
00216 if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) {
00217
00218 QList<QPushButton*> list = this->findChildren<QPushButton*>();
00219 for (int i=0; i<list.size(); ++i) {
00220 QPushButton *pb = list.at(i);
00221 if (pb->isDefault() && pb->isVisible()) {
00222 if (pb->isEnabled())
00223 pb->click();
00224 return;
00225 }
00226 }
00227 }
00228 else if (ke->key() == Qt::Key_Escape) {
00229
00230 QDialogButtonBox* box = ActiveCtrl->standardButtons();
00231 QList<QAbstractButton*> list = box->buttons();
00232 for (int i=0; i<list.size(); ++i) {
00233 QAbstractButton *pb = list.at(i);
00234 if (box->buttonRole(pb) == QDialogButtonBox::RejectRole) {
00235 if (pb->isEnabled())
00236 pb->click();
00237 return;
00238 }
00239 }
00240 }
00241 }
00242 else {
00243 QScrollArea::keyPressEvent(ke);
00244 }
00245 }
00246
00247 void TaskView::slotActiveDocument(const App::Document& doc)
00248 {
00249 if (!ActiveDialog)
00250 updateWatcher();
00251 }
00252
00253 void TaskView::slotDeletedDocument()
00254 {
00255 if (!ActiveDialog)
00256 updateWatcher();
00257 }
00258
00259
00261 void TaskView::OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
00262 Gui::SelectionSingleton::MessageType Reason)
00263 {
00264 std::string temp;
00265
00266 if (Reason.Type == SelectionChanges::AddSelection ||
00267 Reason.Type == SelectionChanges::ClrSelection ||
00268 Reason.Type == SelectionChanges::SetSelection ||
00269 Reason.Type == SelectionChanges::RmvSelection) {
00270
00271 if (!ActiveDialog)
00272 updateWatcher();
00273 }
00274
00275 }
00277
00278 void TaskView::showDialog(TaskDialog *dlg)
00279 {
00280
00281 if (ActiveDialog == dlg)
00282 return;
00283 assert(!ActiveDialog);
00284 assert(!ActiveCtrl);
00285
00286
00287 removeTaskWatcher();
00288
00289
00290 ActiveCtrl = new TaskEditControl(this);
00291 ActiveCtrl->buttonBox->setStandardButtons(dlg->getStandardButtons());
00292
00293
00294 connect(ActiveCtrl->buttonBox,SIGNAL(accepted()),
00295 this,SLOT(accept()));
00296 connect(ActiveCtrl->buttonBox,SIGNAL(rejected()),
00297 this,SLOT(reject()));
00298 connect(ActiveCtrl->buttonBox,SIGNAL(helpRequested()),
00299 this,SLOT(helpRequested()));
00300 connect(ActiveCtrl->buttonBox,SIGNAL(clicked(QAbstractButton *)),
00301 this,SLOT(clicked(QAbstractButton *)));
00302
00303 const std::vector<QWidget*>& cont = dlg->getDialogContent();
00304
00305
00306 dlg->modifyStandardButtons(ActiveCtrl->buttonBox);
00307
00308 if (dlg->buttonPosition() == TaskDialog::North) {
00309 taskPanel->addWidget(ActiveCtrl);
00310 for (std::vector<QWidget*>::const_iterator it=cont.begin();it!=cont.end();++it){
00311 taskPanel->addWidget(*it);
00312 }
00313 }
00314 else {
00315 for (std::vector<QWidget*>::const_iterator it=cont.begin();it!=cont.end();++it){
00316 taskPanel->addWidget(*it);
00317 }
00318 taskPanel->addWidget(ActiveCtrl);
00319 }
00320
00321 if (!dlg->needsFullSpace())
00322 taskPanel->addStretch();
00323
00324
00325 ActiveDialog = dlg;
00326
00327 ActiveDialog->open();
00328 }
00329
00330 void TaskView::removeDialog(void)
00331 {
00332 if (ActiveCtrl) {
00333 taskPanel->removeWidget(ActiveCtrl);
00334 delete ActiveCtrl;
00335 ActiveCtrl = 0;
00336 }
00337
00338 if (ActiveDialog) {
00339 const std::vector<QWidget*> &cont = ActiveDialog->getDialogContent();
00340 for(std::vector<QWidget*>::const_iterator it=cont.begin();it!=cont.end();++it){
00341 taskPanel->removeWidget(*it);
00342 }
00343 delete ActiveDialog;
00344 ActiveDialog = 0;
00345 }
00346
00347 taskPanel->removeStretch();
00348
00349
00350 addTaskWatcher();
00351 }
00352
00353 void TaskView::updateWatcher(void)
00354 {
00355
00356 for (std::vector<TaskWatcher*>::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it) {
00357 bool match = (*it)->shouldShow();
00358 std::vector<QWidget*> &cont = (*it)->getWatcherContent();
00359 for (std::vector<QWidget*>::iterator it2=cont.begin();it2!=cont.end();++it2) {
00360 if (match)
00361 (*it2)->show();
00362 else
00363 (*it2)->hide();
00364 }
00365 }
00366 }
00367
00368 void TaskView::addTaskWatcher(const std::vector<TaskWatcher*> &Watcher)
00369 {
00370
00371 for (std::vector<TaskWatcher*>::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it)
00372 delete *it;
00373
00374 ActiveWatcher = Watcher;
00375 addTaskWatcher();
00376 }
00377
00378 void TaskView::clearTaskWatcher(void)
00379 {
00380 std::vector<TaskWatcher*> watcher;
00381 removeTaskWatcher();
00382
00383 addTaskWatcher(watcher);
00384 }
00385
00386 void TaskView::addTaskWatcher(void)
00387 {
00388
00389 for (std::vector<TaskWatcher*>::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it){
00390 std::vector<QWidget*> &cont = (*it)->getWatcherContent();
00391 for (std::vector<QWidget*>::iterator it2=cont.begin();it2!=cont.end();++it2){
00392 taskPanel->addWidget(*it2);
00393 (*it2)->show();
00394 }
00395 }
00396
00397 if (!ActiveWatcher.empty())
00398 taskPanel->addStretch();
00399 updateWatcher();
00400 }
00401
00402 void TaskView::removeTaskWatcher(void)
00403 {
00404
00405 for (std::vector<TaskWatcher*>::iterator it=ActiveWatcher.begin();it!=ActiveWatcher.end();++it) {
00406 std::vector<QWidget*> &cont = (*it)->getWatcherContent();
00407 for (std::vector<QWidget*>::iterator it2=cont.begin();it2!=cont.end();++it2) {
00408 (*it2)->hide();
00409 taskPanel->removeWidget(*it2);
00410 }
00411 }
00412
00413 taskPanel->removeStretch();
00414 }
00415
00416 void TaskView::accept()
00417 {
00418 if (ActiveDialog->accept())
00419 removeDialog();
00420 }
00421
00422 void TaskView::reject()
00423 {
00424 if (ActiveDialog->reject())
00425 removeDialog();
00426 }
00427
00428 void TaskView::helpRequested()
00429 {
00430 ActiveDialog->helpRequested();
00431 }
00432
00433 void TaskView::clicked (QAbstractButton * button)
00434 {
00435 int id = ActiveCtrl->buttonBox->standardButton(button);
00436 ActiveDialog->clicked(id);
00437 }
00438
00439
00440 #include "moc_TaskView.cpp"